Merge branch 'devel/master' into devel/new_mesh
[platform/core/uifw/dali-adaptor.git] / adaptors / x11 / accessibility-adaptor-impl-x.cpp
1 /*
2  * Copyright (c) 2015 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 "accessibility-adaptor-impl.h"
20
21 // EXTERNAL INCLUDES
22 #include <vconf.h>
23 #include <Ecore_X.h>
24 #include <Elementary.h>
25
26 #include <dali/integration-api/debug.h>
27 #include <dali/integration-api/events/gesture-requests.h>
28
29 // INTERNAL INCLUDES
30 #include "system-settings.h"
31
32 #define MSG_DOMAIN_CONTROL_ACCESS (int)ECORE_X_ATOM_E_ILLUME_ACCESS_CONTROL
33
34 namespace Dali
35 {
36
37 namespace Internal
38 {
39
40 namespace Adaptor
41 {
42
43 namespace {
44 #if defined(DEBUG_ENABLED)
45 Debug::Filter* gAccessibilityAdaptorLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_ACCESSIBILITY_ADAPTOR");
46 #endif
47 } // unnamed namespace
48
49 bool AccessibilityAdaptor::HandleActionNextEvent(bool allowEndFeedback)
50 {
51   bool ret = false;
52
53   if( mIndicator && mIndicatorFocused )
54   {
55     Elm_Access_Action_Info actionInfo;
56     actionInfo.action_type = ELM_ACCESS_ACTION_HIGHLIGHT_NEXT;
57
58     ret = mIndicator->SendMessage(MSG_DOMAIN_CONTROL_ACCESS, actionInfo.action_type, &actionInfo, sizeof(actionInfo));
59   }
60   else if( mActionHandler )
61   {
62     ret = mActionHandler->AccessibilityActionNext(allowEndFeedback);
63   }
64
65   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
66
67   return ret;
68 }
69
70 bool AccessibilityAdaptor::HandleActionPreviousEvent(bool allowEndFeedback)
71 {
72   bool ret = false;
73
74   if( mIndicator && mIndicatorFocused )
75   {
76     Elm_Access_Action_Info actionInfo;
77     actionInfo.action_type = ELM_ACCESS_ACTION_HIGHLIGHT_PREV;
78
79     ret = mIndicator->SendMessage(MSG_DOMAIN_CONTROL_ACCESS, actionInfo.action_type, &actionInfo, sizeof(actionInfo));
80   }
81   else if( mActionHandler )
82   {
83     ret = mActionHandler->AccessibilityActionPrevious(allowEndFeedback);
84   }
85
86   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
87
88   return ret;
89 }
90
91 bool AccessibilityAdaptor::HandleActionActivateEvent()
92 {
93   bool ret = false;
94
95   if( mIndicator && mIndicatorFocused )
96   {
97     Elm_Access_Action_Info actionInfo;
98     actionInfo.action_type = ELM_ACCESS_ACTION_ACTIVATE;
99
100     ret = mIndicator->SendMessage(MSG_DOMAIN_CONTROL_ACCESS, actionInfo.action_type, &actionInfo, sizeof(actionInfo));
101   }
102   else if( mActionHandler )
103   {
104     ret = mActionHandler->AccessibilityActionActivate();
105   }
106
107   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
108
109   return ret;
110 }
111
112 bool AccessibilityAdaptor::HandleActionReadEvent(unsigned int x, unsigned int y, bool allowReadAgain)
113 {
114   bool ret = false;
115
116   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %d , %d\n", __FUNCTION__, __LINE__, x, y);
117
118   mReadPosition.x = x;
119   mReadPosition.y = y;
120
121   Dali::AccessibilityAdaptor handle( this );
122
123   bool indicatorFocused = false;
124
125   // Check whether the Indicator is focused
126   if( mIndicator && mIndicator->IsConnected() )
127   {
128     // Check the position and size of Indicator actor
129     Dali::Actor indicatorActor = mIndicator->GetActor();
130     Vector3 position = Vector3(0.0f, 0.0f, 0.0f);
131     Vector3 size = indicatorActor.GetCurrentSize();
132
133     if(mReadPosition.x >= position.x &&
134        mReadPosition.x <= position.x + size.width &&
135        mReadPosition.y >= position.y &&
136        mReadPosition.y <= position.y + size.height)
137     {
138       indicatorFocused = true;
139       DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] Indicator area!!!!\n", __FUNCTION__, __LINE__);
140     }
141   }
142
143   if( mIndicator )
144   {
145     if( !mIndicatorFocused && indicatorFocused )
146     {
147       // If Indicator is focused, the focus should be cleared in Dali focus chain.
148       if( mActionHandler )
149       {
150         mActionHandler->ClearAccessibilityFocus();
151       }
152     }
153     else if( mIndicatorFocused && !indicatorFocused )
154     {
155       Elm_Access_Action_Info actionInfo;
156       actionInfo.action_type = ELM_ACCESS_ACTION_UNHIGHLIGHT;
157
158       // Indicator should be unhighlighted
159       ret = mIndicator->SendMessage(MSG_DOMAIN_CONTROL_ACCESS, actionInfo.action_type, &actionInfo, sizeof(actionInfo));
160       DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] Send unhighlight message to indicator!!!!\n", __FUNCTION__, __LINE__);
161     }
162
163     mIndicatorFocused = indicatorFocused;
164
165     // Send accessibility READ action information to Indicator
166     if( mIndicatorFocused )
167     {
168       Elm_Access_Action_Info actionInfo;
169       actionInfo.x = mReadPosition.x;
170       actionInfo.y = mReadPosition.y;
171
172       if(allowReadAgain)
173       {
174         actionInfo.action_type = ELM_ACCESS_ACTION_READ;
175       }
176       else
177       {
178         actionInfo.action_type = static_cast<Elm_Access_Action_Type>( GetElmAccessActionOver() );
179       }
180
181       ret = mIndicator->SendMessage(MSG_DOMAIN_CONTROL_ACCESS, actionInfo.action_type, &actionInfo, sizeof(actionInfo));
182
183       DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] Send READ message to indicator!!!!\n", __FUNCTION__, __LINE__);
184     }
185   }
186
187   if( mActionHandler && !mIndicatorFocused)
188   {
189     // If Indicator is not focused, the accessibility actions should be handled by the registered
190     // accessibility action handler (e.g. focus manager)
191     ret = mActionHandler->AccessibilityActionRead(allowReadAgain);
192     DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
193   }
194
195   return ret;
196 }
197
198 bool AccessibilityAdaptor::HandleActionReadNextEvent(bool allowEndFeedback)
199 {
200   bool ret = false;
201
202   if( mIndicator && mIndicatorFocused )
203   {
204     Elm_Access_Action_Info actionInfo;
205     actionInfo.action_type = ELM_ACCESS_ACTION_HIGHLIGHT_NEXT;
206
207     ret = mIndicator->SendMessage(MSG_DOMAIN_CONTROL_ACCESS, actionInfo.action_type, &actionInfo, sizeof(actionInfo));
208   }
209   else if( mActionHandler )
210   {
211     ret = mActionHandler->AccessibilityActionReadNext(allowEndFeedback);
212   }
213
214   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
215
216   return ret;
217 }
218
219 bool AccessibilityAdaptor::HandleActionReadPreviousEvent(bool allowEndFeedback)
220 {
221   bool ret = false;
222
223   if( mIndicator && mIndicatorFocused )
224   {
225     Elm_Access_Action_Info actionInfo;
226     actionInfo.action_type = ELM_ACCESS_ACTION_HIGHLIGHT_PREV;
227
228     ret = mIndicator->SendMessage(MSG_DOMAIN_CONTROL_ACCESS, actionInfo.action_type, &actionInfo, sizeof(actionInfo));
229   }
230   else if( mActionHandler )
231   {
232     ret = mActionHandler->AccessibilityActionReadPrevious(allowEndFeedback);
233   }
234
235   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
236
237   return ret;
238 }
239
240 bool AccessibilityAdaptor::HandleActionUpEvent()
241 {
242   bool ret = false;
243
244   if( mIndicator && mIndicatorFocused )
245   {
246     Elm_Access_Action_Info actionInfo;
247     actionInfo.action_type = ELM_ACCESS_ACTION_UP;
248
249     ret = mIndicator->SendMessage(MSG_DOMAIN_CONTROL_ACCESS, actionInfo.action_type, &actionInfo, sizeof(actionInfo));
250   }
251   else if( mActionHandler )
252   {
253     ret = mActionHandler->AccessibilityActionUp();
254   }
255
256   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
257
258   return ret;
259 }
260
261 bool AccessibilityAdaptor::HandleActionDownEvent()
262 {
263   bool ret = false;
264
265   if( mIndicator && mIndicatorFocused )
266   {
267     Elm_Access_Action_Info actionInfo;
268     actionInfo.action_type = ELM_ACCESS_ACTION_DOWN;
269
270     ret = mIndicator->SendMessage(MSG_DOMAIN_CONTROL_ACCESS, actionInfo.action_type, &actionInfo, sizeof(actionInfo));
271   }
272   else if( mActionHandler )
273   {
274     ret = mActionHandler->AccessibilityActionDown();
275   }
276
277   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
278
279   return ret;
280 }
281
282 bool AccessibilityAdaptor::HandleActionScrollUpEvent()
283 {
284   bool ret = false;
285
286   if( mIndicator && mIndicatorFocused )
287   {
288     // TODO: Send message to indicator with the correct action type
289   }
290   else if( mActionHandler )
291   {
292     ret = mActionHandler->AccessibilityActionScrollUp();
293   }
294
295   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
296
297   return ret;
298 }
299
300
301 bool AccessibilityAdaptor::HandleActionScrollDownEvent()
302 {
303   bool ret = false;
304
305   if( mIndicator && mIndicatorFocused )
306   {
307     // TODO: Send message to indicator with the correct action type
308   }
309   else if( mActionHandler )
310   {
311     ret = mActionHandler->AccessibilityActionScrollDown();
312   }
313
314   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
315
316   return ret;
317 }
318
319 bool AccessibilityAdaptor::HandleActionPageLeftEvent()
320 {
321   bool ret = false;
322
323   if( mIndicator && mIndicatorFocused )
324   {
325     // TODO: Send message to indicator with the correct action type
326   }
327   else if( mActionHandler )
328   {
329     ret = mActionHandler->AccessibilityActionPageLeft();
330   }
331
332   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
333
334   return ret;
335 }
336
337 bool AccessibilityAdaptor::HandleActionPageRightEvent()
338 {
339   bool ret = false;
340
341   if( mIndicator && mIndicatorFocused )
342   {
343     // TODO: Send message to indicator with the correct action type
344   }
345   else if( mActionHandler )
346   {
347     ret = mActionHandler->AccessibilityActionPageRight();
348   }
349
350   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
351
352   return ret;
353 }
354
355 bool AccessibilityAdaptor::HandleActionPageUpEvent()
356 {
357   bool ret = false;
358
359   if( mIndicator && mIndicatorFocused )
360   {
361     // TODO: Send message to indicator with the correct action type
362   }
363   else if( mActionHandler )
364   {
365     ret = mActionHandler->AccessibilityActionPageUp();
366   }
367
368   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
369
370   return ret;
371 }
372
373 bool AccessibilityAdaptor::HandleActionPageDownEvent()
374 {
375   bool ret = false;
376
377   if( mIndicator && mIndicatorFocused )
378   {
379     // TODO: Send message to indicator with the correct action type
380   }
381   else if( mActionHandler )
382   {
383     ret = mActionHandler->AccessibilityActionPageDown();
384   }
385
386   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
387
388   return ret;
389 }
390
391 bool AccessibilityAdaptor::HandleActionMoveToFirstEvent()
392 {
393   bool ret = false;
394
395   if( mIndicator && mIndicatorFocused )
396   {
397     // TODO: Send message to indicator with the correct action type
398   }
399   else if( mActionHandler )
400   {
401     ret = mActionHandler->AccessibilityActionMoveToFirst();
402   }
403
404   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
405
406   return ret;
407 }
408
409 bool AccessibilityAdaptor::HandleActionMoveToLastEvent()
410 {
411   bool ret = false;
412
413   if( mIndicator && mIndicatorFocused )
414   {
415     // TODO: Send message to indicator with the correct action type
416   }
417   else if( mActionHandler )
418   {
419     ret = mActionHandler->AccessibilityActionMoveToLast();
420   }
421
422   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
423
424   return ret;
425 }
426
427 bool AccessibilityAdaptor::HandleActionReadFromTopEvent()
428 {
429   bool ret = false;
430
431   if( mIndicator && mIndicatorFocused )
432   {
433     // TODO: Send message to indicator with the correct action type
434   }
435   else if( mActionHandler )
436   {
437     ret = mActionHandler->AccessibilityActionReadFromTop();
438   }
439
440   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
441
442   return ret;
443 }
444
445 bool AccessibilityAdaptor::HandleActionReadFromNextEvent()
446 {
447   bool ret = false;
448
449   if( mIndicator && mIndicatorFocused )
450   {
451     // TODO: Send message to indicator with the correct action type
452   }
453   else if( mActionHandler )
454   {
455     ret = mActionHandler->AccessibilityActionReadFromNext();
456   }
457
458   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
459
460   return ret;
461 }
462
463 bool AccessibilityAdaptor::HandleActionZoomEvent()
464 {
465   bool ret = false;
466
467   if( mIndicator && mIndicatorFocused )
468   {
469     // TODO: Send message to indicator with the correct action type
470   }
471   else if( mActionHandler )
472   {
473     ret = mActionHandler->AccessibilityActionZoom();
474   }
475
476   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
477
478   return ret;
479 }
480
481 bool AccessibilityAdaptor::HandleActionReadIndicatorInformationEvent()
482 {
483   bool ret = false;
484
485   if( mIndicator && mIndicatorFocused )
486   {
487     // TODO: Send message to indicator with the correct action type
488   }
489   else if( mActionHandler )
490   {
491     ret = mActionHandler->AccessibilityActionReadIndicatorInformation();
492   }
493
494   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
495
496   return ret;
497 }
498
499 bool AccessibilityAdaptor::HandleActionReadPauseResumeEvent()
500 {
501   bool ret = false;
502
503   if( mIndicator && mIndicatorFocused )
504   {
505     // TODO: Send message to indicator with the correct action type
506   }
507   else if( mActionHandler )
508   {
509     ret = mActionHandler->AccessibilityActionReadPauseResume();
510   }
511
512   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
513
514   return ret;
515 }
516
517 bool AccessibilityAdaptor::HandleActionStartStopEvent()
518 {
519   bool ret = false;
520
521   if( mIndicator && mIndicatorFocused )
522   {
523     // TODO: Send message to indicator with the correct action type
524   }
525   else if( mActionHandler )
526   {
527     ret = mActionHandler->AccessibilityActionStartStop();
528   }
529
530   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
531
532   return ret;
533 }
534
535 } // namespace Adaptor
536
537 } // namespace Internal
538
539 } // namespace Dali