Remove the indicator
[platform/core/uifw/dali-adaptor.git] / dali / internal / accessibility / tizen-wayland / tizen-wearable / accessibility-adaptor-impl-wearable.cpp
1 /*
2  * Copyright (c) 2018 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 <Ecore_X.h>
26 #include <Elementary.h>
27 #endif
28
29 #include <vconf.h>
30
31 #include <dali/public-api/object/type-registry.h>
32 #include <dali/integration-api/debug.h>
33 #include <dali/integration-api/debug.h>
34 #include <dali/integration-api/events/gesture-requests.h>
35
36 // INTERNAL INCLUDES
37 #include <dali/internal/system/common/singleton-service-impl.h>
38 #include <dali/internal/system/common/system-settings.h>
39
40 #ifndef WAYLAND
41 #define MSG_DOMAIN_CONTROL_ACCESS static_cast< int >( ECORE_X_ATOM_E_ILLUME_ACCESS_CONTROL )
42 #endif
43
44 namespace Dali
45 {
46
47 namespace Internal
48 {
49
50 namespace Adaptor
51 {
52
53 namespace // unnamed namespace
54 {
55
56 #if defined(DEBUG_ENABLED)
57 Debug::Filter* gAccessibilityAdaptorLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_ACCESSIBILITY_ADAPTOR");
58 #endif
59
60 const char * DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_DBUS_TTS = "db/setting/accessibility/atspi";
61
62 bool GetEnabledVConf()
63 {
64   int isEnabled = 0;
65   vconf_get_bool( DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_DBUS_TTS, &isEnabled );
66
67   if( isEnabled == 0 )
68   {
69     vconf_get_bool( VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, &isEnabled );
70   }
71
72   return bool( isEnabled );
73 }
74
75
76 void AccessibilityOnOffNotification(keynode_t* node, void* data)
77 {
78   AccessibilityAdaptor* adaptor = static_cast<AccessibilityAdaptor*>( data );
79
80   bool isEnabled = GetEnabledVConf();
81
82   DALI_LOG_INFO( gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, isEnabled ? "ENABLED" : "DISABLED" );
83
84   if( isEnabled )
85   {
86     adaptor->EnableAccessibility();
87   }
88   else
89   {
90     adaptor->DisableAccessibility();
91   }
92 }
93
94 } // unnamed namespace
95
96 Dali::AccessibilityAdaptor AccessibilityAdaptor::Get()
97 {
98   Dali::AccessibilityAdaptor adaptor;
99
100   Dali::SingletonService service( SingletonService::Get() );
101   if ( service )
102   {
103     // Check whether the singleton is already created
104     Dali::BaseHandle handle = service.GetSingleton( typeid( Dali::AccessibilityAdaptor ) );
105     if(handle)
106     {
107       // If so, downcast the handle
108       adaptor = Dali::AccessibilityAdaptor( dynamic_cast< AccessibilityAdaptor* >( handle.GetObjectPtr() ) );
109     }
110     else
111     {
112       adaptor = Dali::AccessibilityAdaptor( new AccessibilityAdaptorMobile() );
113       AccessibilityAdaptorMobile& adaptorImpl = AccessibilityAdaptorMobile::GetImplementation( adaptor );
114
115       bool isEnabled = GetEnabledVConf();
116
117       if( isEnabled )
118       {
119         adaptorImpl.EnableAccessibility();
120       }
121       DALI_LOG_INFO( gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, isEnabled ? "ENABLED" : "DISABLED" );
122
123       vconf_notify_key_changed( DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_DBUS_TTS, AccessibilityOnOffNotification, &adaptorImpl );
124       vconf_notify_key_changed( VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, AccessibilityOnOffNotification, &adaptorImpl );
125
126       service.Register( typeid( adaptor ), adaptor );
127     }
128   }
129
130   return adaptor;
131 }
132
133 void AccessibilityAdaptor::OnDestroy()
134 {
135   vconf_ignore_key_changed( VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, AccessibilityOnOffNotification );
136   vconf_ignore_key_changed( DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_DBUS_TTS, AccessibilityOnOffNotification );
137 }
138
139 AccessibilityAdaptorMobile::AccessibilityAdaptorMobile()
140 {
141 }
142
143 bool AccessibilityAdaptorMobile::HandleActionNextEvent(bool allowEndFeedback)
144 {
145   bool ret = false;
146
147   if( mActionHandler )
148   {
149     ret = mActionHandler->AccessibilityActionNext(allowEndFeedback);
150   }
151
152   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
153
154   return ret;
155 }
156
157 bool AccessibilityAdaptorMobile::HandleActionPreviousEvent(bool allowEndFeedback)
158 {
159   bool ret = false;
160
161   if( mActionHandler )
162   {
163     ret = mActionHandler->AccessibilityActionPrevious(allowEndFeedback);
164   }
165
166   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
167
168   return ret;
169 }
170
171 bool AccessibilityAdaptorMobile::HandleActionActivateEvent()
172 {
173   bool ret = false;
174
175   if( mActionHandler )
176   {
177     ret = mActionHandler->AccessibilityActionActivate();
178   }
179
180   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
181
182   return ret;
183 }
184
185 bool AccessibilityAdaptorMobile::HandleActionReadEvent(unsigned int x, unsigned int y, bool allowReadAgain)
186 {
187   bool ret = false;
188
189   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %d , %d\n", __FUNCTION__, __LINE__, x, y);
190
191   mReadPosition.x = x;
192   mReadPosition.y = y;
193
194   if( mActionHandler)
195   {
196     // The accessibility actions should be handled by the registered accessibility action handler (e.g. focus manager)
197     ret = mActionHandler->AccessibilityActionRead(allowReadAgain);
198     DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
199   }
200
201   return ret;
202 }
203
204 bool AccessibilityAdaptorMobile::HandleActionReadNextEvent(bool allowEndFeedback)
205 {
206   bool ret = false;
207
208   if( mActionHandler )
209   {
210     ret = mActionHandler->AccessibilityActionReadNext(allowEndFeedback);
211   }
212
213   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
214
215   return ret;
216 }
217
218 bool AccessibilityAdaptorMobile::HandleActionReadPreviousEvent(bool allowEndFeedback)
219 {
220   bool ret = false;
221
222   if( mActionHandler )
223   {
224     ret = mActionHandler->AccessibilityActionReadPrevious(allowEndFeedback);
225   }
226
227   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
228
229   return ret;
230 }
231
232 bool AccessibilityAdaptorMobile::HandleActionUpEvent()
233 {
234   bool ret = false;
235
236   if( mActionHandler )
237   {
238     ret = mActionHandler->AccessibilityActionUp();
239   }
240
241   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
242
243   return ret;
244 }
245
246 bool AccessibilityAdaptorMobile::HandleActionDownEvent()
247 {
248   bool ret = false;
249
250   if( mActionHandler )
251   {
252     ret = mActionHandler->AccessibilityActionDown();
253   }
254
255   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
256
257   return ret;
258 }
259
260 AccessibilityAdaptorMobile::~AccessibilityAdaptorMobile()
261 {
262 }
263
264 } // namespace Adaptor
265
266 } // namespace Internal
267
268 } // namespace Dali