dali-adaptor internal folder refactoring
[platform/core/uifw/dali-adaptor.git] / dali / internal / accessibility / tizen-wayland / tizen-ivi / accessibility-adaptor-impl-ivi.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 #ifndef WAYLAND
148   if( mIndicator && mIndicatorFocused )
149   {
150     Elm_Access_Action_Info actionInfo;
151     actionInfo.action_type = ELM_ACCESS_ACTION_HIGHLIGHT_NEXT;
152
153     ret = mIndicator->SendMessage(MSG_DOMAIN_CONTROL_ACCESS, actionInfo.action_type, &actionInfo, sizeof(actionInfo));
154   }
155   else if( mActionHandler )
156 #else
157   if( mActionHandler )
158 #endif
159   {
160     ret = mActionHandler->AccessibilityActionNext(allowEndFeedback);
161   }
162
163   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
164
165   return ret;
166 }
167
168 bool AccessibilityAdaptorMobile::HandleActionPreviousEvent(bool allowEndFeedback)
169 {
170   bool ret = false;
171
172 #ifndef WAYLAND
173   if( mIndicator && mIndicatorFocused )
174   {
175     Elm_Access_Action_Info actionInfo;
176     actionInfo.action_type = ELM_ACCESS_ACTION_HIGHLIGHT_PREV;
177
178     ret = mIndicator->SendMessage(MSG_DOMAIN_CONTROL_ACCESS, actionInfo.action_type, &actionInfo, sizeof(actionInfo));
179   }
180   else if( mActionHandler )
181 #else
182   if( mActionHandler )
183 #endif
184   {
185     ret = mActionHandler->AccessibilityActionPrevious(allowEndFeedback);
186   }
187
188   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
189
190   return ret;
191 }
192
193 bool AccessibilityAdaptorMobile::HandleActionActivateEvent()
194 {
195   bool ret = false;
196
197 #ifndef WAYLAND
198   if( mIndicator && mIndicatorFocused )
199   {
200     Elm_Access_Action_Info actionInfo;
201     actionInfo.action_type = ELM_ACCESS_ACTION_ACTIVATE;
202
203     ret = mIndicator->SendMessage(MSG_DOMAIN_CONTROL_ACCESS, actionInfo.action_type, &actionInfo, sizeof(actionInfo));
204   }
205   else if( mActionHandler )
206 #else
207   if( mActionHandler )
208 #endif
209   {
210     ret = mActionHandler->AccessibilityActionActivate();
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::HandleActionReadEvent(unsigned int x, unsigned int y, bool allowReadAgain)
219 {
220   bool ret = false;
221
222   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %d , %d\n", __FUNCTION__, __LINE__, x, y);
223
224   mReadPosition.x = x;
225   mReadPosition.y = y;
226
227   Dali::AccessibilityAdaptor handle( this );
228
229   bool indicatorFocused = false;
230
231   // Check whether the Indicator is focused
232   if( mIndicator && mIndicator->IsConnected() )
233   {
234     // Check the position and size of Indicator actor
235     Dali::Actor indicatorActor = mIndicator->GetActor();
236     Vector3 position = Vector3(0.0f, 0.0f, 0.0f);
237     Vector3 size = indicatorActor.GetCurrentSize();
238
239     if(mReadPosition.x >= position.x &&
240        mReadPosition.x <= position.x + size.width &&
241        mReadPosition.y >= position.y &&
242        mReadPosition.y <= position.y + size.height)
243     {
244       indicatorFocused = true;
245       DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] Indicator area!!!!\n", __FUNCTION__, __LINE__);
246     }
247   }
248
249   if( mIndicator )
250   {
251     if( !mIndicatorFocused && indicatorFocused )
252     {
253       // If Indicator is focused, the focus should be cleared in Dali focus chain.
254       if( mActionHandler )
255       {
256         mActionHandler->ClearAccessibilityFocus();
257       }
258     }
259     else if( mIndicatorFocused && !indicatorFocused )
260     {
261 #ifndef WAYLAND
262       Elm_Access_Action_Info actionInfo;
263       actionInfo.action_type = ELM_ACCESS_ACTION_UNHIGHLIGHT;
264
265       // Indicator should be unhighlighted
266       ret = mIndicator->SendMessage(MSG_DOMAIN_CONTROL_ACCESS, actionInfo.action_type, &actionInfo, sizeof(actionInfo));
267       DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] Send unhighlight message to indicator!!!!\n", __FUNCTION__, __LINE__);
268 #endif
269     }
270
271     mIndicatorFocused = indicatorFocused;
272
273     // Send accessibility READ action information to Indicator
274     if( mIndicatorFocused )
275     {
276 #ifndef WAYLAND
277       Elm_Access_Action_Info actionInfo;
278       actionInfo.x = mReadPosition.x;
279       actionInfo.y = mReadPosition.y;
280
281       if(allowReadAgain)
282       {
283         actionInfo.action_type = ELM_ACCESS_ACTION_READ;
284       }
285       else
286       {
287         actionInfo.action_type = static_cast<Elm_Access_Action_Type>( GetElmAccessActionOver() );
288       }
289
290       ret = mIndicator->SendMessage(MSG_DOMAIN_CONTROL_ACCESS, actionInfo.action_type, &actionInfo, sizeof(actionInfo));
291
292       DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] Send READ message to indicator!!!!\n", __FUNCTION__, __LINE__);
293 #endif
294     }
295   }
296
297   if( mActionHandler && !mIndicatorFocused)
298   {
299     // If Indicator is not focused, the accessibility actions should be handled by the registered
300     // accessibility action handler (e.g. focus manager)
301     ret = mActionHandler->AccessibilityActionRead(allowReadAgain);
302     DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
303   }
304
305   return ret;
306 }
307
308 bool AccessibilityAdaptorMobile::HandleActionReadNextEvent(bool allowEndFeedback)
309 {
310   bool ret = false;
311
312 #ifndef WAYLAND
313   if( mIndicator && mIndicatorFocused )
314   {
315     Elm_Access_Action_Info actionInfo;
316     actionInfo.action_type = ELM_ACCESS_ACTION_HIGHLIGHT_NEXT;
317
318     ret = mIndicator->SendMessage(MSG_DOMAIN_CONTROL_ACCESS, actionInfo.action_type, &actionInfo, sizeof(actionInfo));
319   }
320   else if( mActionHandler )
321 #else
322   if( mActionHandler )
323 #endif
324   {
325     ret = mActionHandler->AccessibilityActionReadNext(allowEndFeedback);
326   }
327
328   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
329
330   return ret;
331 }
332
333 bool AccessibilityAdaptorMobile::HandleActionReadPreviousEvent(bool allowEndFeedback)
334 {
335   bool ret = false;
336
337 #ifndef WAYLAND
338   if( mIndicator && mIndicatorFocused )
339   {
340     Elm_Access_Action_Info actionInfo;
341     actionInfo.action_type = ELM_ACCESS_ACTION_HIGHLIGHT_PREV;
342
343     ret = mIndicator->SendMessage(MSG_DOMAIN_CONTROL_ACCESS, actionInfo.action_type, &actionInfo, sizeof(actionInfo));
344   }
345   else if( mActionHandler )
346 #else
347   if( mActionHandler )
348 #endif
349   {
350     ret = mActionHandler->AccessibilityActionReadPrevious(allowEndFeedback);
351   }
352
353   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
354
355   return ret;
356 }
357
358 bool AccessibilityAdaptorMobile::HandleActionUpEvent()
359 {
360   bool ret = false;
361
362 #ifndef WAYLAND
363   if( mIndicator && mIndicatorFocused )
364   {
365     Elm_Access_Action_Info actionInfo;
366     actionInfo.action_type = ELM_ACCESS_ACTION_UP;
367
368     ret = mIndicator->SendMessage(MSG_DOMAIN_CONTROL_ACCESS, actionInfo.action_type, &actionInfo, sizeof(actionInfo));
369   }
370   else if( mActionHandler )
371 #else
372   if( mActionHandler )
373 #endif
374   {
375     ret = mActionHandler->AccessibilityActionUp();
376   }
377
378   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
379
380   return ret;
381 }
382
383 bool AccessibilityAdaptorMobile::HandleActionDownEvent()
384 {
385   bool ret = false;
386
387 #ifndef WAYLAND
388   if( mIndicator && mIndicatorFocused )
389   {
390     Elm_Access_Action_Info actionInfo;
391     actionInfo.action_type = ELM_ACCESS_ACTION_DOWN;
392
393     ret = mIndicator->SendMessage(MSG_DOMAIN_CONTROL_ACCESS, actionInfo.action_type, &actionInfo, sizeof(actionInfo));
394   }
395   else if( mActionHandler )
396 #else
397   if( mActionHandler )
398 #endif
399   {
400     ret = mActionHandler->AccessibilityActionDown();
401   }
402
403   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
404
405   return ret;
406 }
407
408 AccessibilityAdaptorMobile::~AccessibilityAdaptorMobile()
409 {
410 }
411
412 } // namespace Adaptor
413
414 } // namespace Internal
415
416 } // namespace Dali