DALi Version 1.9.35
[platform/core/uifw/dali-adaptor.git] / dali / internal / accessibility / tizen-wayland / tizen-ivi / accessibility-adaptor-impl-ivi.cpp
1 /*
2  * Copyright (c) 2019 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali/internal/accessibility/tizen-wayland/tizen-mobile/accessibility-adaptor-impl-mobile.h>
20
21 // EXTERNAL INCLUDES
22 #include <vconf.h>
23
24 #ifndef WAYLAND
25 #include <dali/internal/system/linux/dali-ecore-x.h>
26 #include <dali/internal/system/linux/dali-elementary.h>
27 #endif
28
29 #include <vconf.h>
30
31 #include <dali/public-api/object/type-registry.h>
32 #include <dali/devel-api/common/singleton-service.h>
33 #include <dali/integration-api/debug.h>
34
35 // INTERNAL INCLUDES
36 #include <dali/internal/system/common/system-settings.h>
37
38 #ifndef WAYLAND
39 #define MSG_DOMAIN_CONTROL_ACCESS static_cast< int >( ECORE_X_ATOM_E_ILLUME_ACCESS_CONTROL )
40 #endif
41
42 namespace Dali
43 {
44
45 namespace Internal
46 {
47
48 namespace Adaptor
49 {
50
51 namespace // unnamed namespace
52 {
53
54 #if defined(DEBUG_ENABLED)
55 Debug::Filter* gAccessibilityAdaptorLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_ACCESSIBILITY_ADAPTOR");
56 #endif
57
58 const char * DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_DBUS_TTS = "db/setting/accessibility/atspi";
59
60 bool GetEnabledVConf()
61 {
62   int isEnabled = 0;
63   vconf_get_bool( DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_DBUS_TTS, &isEnabled );
64
65   if( isEnabled == 0 )
66   {
67     vconf_get_bool( VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, &isEnabled );
68   }
69
70   return bool( isEnabled );
71 }
72
73
74 void AccessibilityOnOffNotification(keynode_t* node, void* data)
75 {
76   AccessibilityAdaptor* adaptor = static_cast<AccessibilityAdaptor*>( data );
77
78   bool isEnabled = GetEnabledVConf();
79
80   DALI_LOG_INFO( gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, isEnabled ? "ENABLED" : "DISABLED" );
81
82   if( isEnabled )
83   {
84     adaptor->EnableAccessibility();
85   }
86   else
87   {
88     adaptor->DisableAccessibility();
89   }
90 }
91
92 } // unnamed namespace
93
94 Dali::AccessibilityAdaptor AccessibilityAdaptor::Get()
95 {
96   Dali::AccessibilityAdaptor adaptor;
97
98   Dali::SingletonService service( SingletonService::Get() );
99   if ( service )
100   {
101     // Check whether the singleton is already created
102     Dali::BaseHandle handle = service.GetSingleton( typeid( Dali::AccessibilityAdaptor ) );
103     if(handle)
104     {
105       // If so, downcast the handle
106       adaptor = Dali::AccessibilityAdaptor( dynamic_cast< AccessibilityAdaptor* >( handle.GetObjectPtr() ) );
107     }
108     else
109     {
110       adaptor = Dali::AccessibilityAdaptor( new AccessibilityAdaptorMobile() );
111       AccessibilityAdaptorMobile& adaptorImpl = AccessibilityAdaptorMobile::GetImplementation( adaptor );
112
113       bool isEnabled = GetEnabledVConf();
114
115       if( isEnabled )
116       {
117         adaptorImpl.EnableAccessibility();
118       }
119       DALI_LOG_INFO( gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, isEnabled ? "ENABLED" : "DISABLED" );
120
121       vconf_notify_key_changed( DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_DBUS_TTS, AccessibilityOnOffNotification, &adaptorImpl );
122       vconf_notify_key_changed( VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, AccessibilityOnOffNotification, &adaptorImpl );
123
124       service.Register( typeid( adaptor ), adaptor );
125     }
126   }
127
128   return adaptor;
129 }
130
131 void AccessibilityAdaptor::OnDestroy()
132 {
133   vconf_ignore_key_changed( VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, AccessibilityOnOffNotification );
134   vconf_ignore_key_changed( DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_DBUS_TTS, AccessibilityOnOffNotification );
135 }
136
137 AccessibilityAdaptorMobile::AccessibilityAdaptorMobile()
138 {
139 }
140
141 bool AccessibilityAdaptorMobile::HandleActionNextEvent(bool allowEndFeedback)
142 {
143   bool ret = false;
144
145   if( mActionHandler )
146   {
147     ret = mActionHandler->AccessibilityActionNext(allowEndFeedback);
148   }
149
150   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
151
152   return ret;
153 }
154
155 bool AccessibilityAdaptorMobile::HandleActionPreviousEvent(bool allowEndFeedback)
156 {
157   bool ret = false;
158
159   if( mActionHandler )
160   {
161     ret = mActionHandler->AccessibilityActionPrevious(allowEndFeedback);
162   }
163
164   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
165
166   return ret;
167 }
168
169 bool AccessibilityAdaptorMobile::HandleActionActivateEvent()
170 {
171   bool ret = false;
172
173   if( mActionHandler )
174   {
175     ret = mActionHandler->AccessibilityActionActivate();
176   }
177
178   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
179
180   return ret;
181 }
182
183 bool AccessibilityAdaptorMobile::HandleActionReadEvent(unsigned int x, unsigned int y, bool allowReadAgain)
184 {
185   bool ret = false;
186
187   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %d , %d\n", __FUNCTION__, __LINE__, x, y);
188
189   mReadPosition.x = x;
190   mReadPosition.y = y;
191
192   if( mActionHandler )
193   {
194     // The accessibility actions should be handled by the registered accessibility action handler (e.g. focus manager)
195     ret = mActionHandler->AccessibilityActionRead(allowReadAgain);
196     DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
197   }
198
199   return ret;
200 }
201
202 bool AccessibilityAdaptorMobile::HandleActionReadNextEvent(bool allowEndFeedback)
203 {
204   bool ret = false;
205
206   if( mActionHandler )
207   {
208     ret = mActionHandler->AccessibilityActionReadNext(allowEndFeedback);
209   }
210
211   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
212
213   return ret;
214 }
215
216 bool AccessibilityAdaptorMobile::HandleActionReadPreviousEvent(bool allowEndFeedback)
217 {
218   bool ret = false;
219
220   if( mActionHandler )
221   {
222     ret = mActionHandler->AccessibilityActionReadPrevious(allowEndFeedback);
223   }
224
225   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
226
227   return ret;
228 }
229
230 bool AccessibilityAdaptorMobile::HandleActionUpEvent()
231 {
232   bool ret = false;
233
234   if( mActionHandler )
235   {
236     ret = mActionHandler->AccessibilityActionUp();
237   }
238
239   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
240
241   return ret;
242 }
243
244 bool AccessibilityAdaptorMobile::HandleActionDownEvent()
245 {
246   bool ret = false;
247
248   if( mActionHandler )
249   {
250     ret = mActionHandler->AccessibilityActionDown();
251   }
252
253   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
254
255   return ret;
256 }
257
258 AccessibilityAdaptorMobile::~AccessibilityAdaptorMobile()
259 {
260 }
261
262 } // namespace Adaptor
263
264 } // namespace Internal
265
266 } // namespace Dali