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