Add event handling support for multiple windows.
[platform/core/uifw/dali-adaptor.git] / dali / internal / accessibility / common / accessibility-adaptor-impl.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/common/accessibility-adaptor-impl.h>
20
21 // EXTERNAL INCLUDES
22 #include <dali/public-api/object/type-registry.h>
23 #include <dali/integration-api/debug.h>
24 #include <dali/integration-api/events/touch-event-integ.h>
25 #include <dali/integration-api/events/hover-event-integ.h>
26 #include <dali/integration-api/events/gesture-requests.h>
27
28 // INTERNAL INCLUDES
29 #include <dali/internal/adaptor/common/adaptor-impl.h>
30 #include <dali/internal/system/common/system-settings.h>
31
32 namespace Dali
33 {
34
35 namespace Internal
36 {
37
38 namespace Adaptor
39 {
40
41 namespace // unnamed namespace
42 {
43
44 #if defined(DEBUG_ENABLED)
45 Debug::Filter* gAccessibilityAdaptorLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_ACCESSIBILITY_ADAPTOR");
46 #endif
47
48 } // unnamed namespace
49
50 AccessibilityAdaptor::AccessibilityAdaptor()
51 : mReadPosition(),
52   mActionHandler( NULL ),
53   mIsEnabled( false )
54 {
55   mAccessibilityGestureDetector = new AccessibilityGestureDetector();
56 }
57
58 void AccessibilityAdaptor::EnableAccessibility()
59 {
60   if(mIsEnabled == false)
61   {
62     mIsEnabled = true;
63
64     if( mActionHandler )
65     {
66       mActionHandler->ChangeAccessibilityStatus();
67     }
68   }
69 }
70
71 void AccessibilityAdaptor::DisableAccessibility()
72 {
73   if(mIsEnabled == true)
74   {
75     mIsEnabled = false;
76
77     if( mActionHandler )
78     {
79       mActionHandler->ChangeAccessibilityStatus();
80     }
81
82     // Destroy the TtsPlayer if exists.
83     if ( Adaptor::IsAvailable() )
84     {
85       Dali::Adaptor& adaptor = Dali::Adaptor::Get();
86       Adaptor& adaptorImpl = Adaptor::GetImplementation( adaptor );
87       adaptorImpl.DestroyTtsPlayer( Dali::TtsPlayer::SCREEN_READER );
88     }
89   }
90 }
91
92 bool AccessibilityAdaptor::IsEnabled() const
93 {
94   return mIsEnabled;
95 }
96
97 Vector2 AccessibilityAdaptor::GetReadPosition() const
98 {
99   return mReadPosition;
100 }
101
102 void AccessibilityAdaptor::SetActionHandler(AccessibilityActionHandler& handler)
103 {
104   mActionHandler = &handler;
105 }
106
107 void AccessibilityAdaptor::SetGestureHandler(AccessibilityGestureHandler& handler)
108 {
109   if( mAccessibilityGestureDetector )
110   {
111     mAccessibilityGestureDetector->SetGestureHandler(handler);
112   }
113 }
114
115 bool AccessibilityAdaptor::HandleActionNextEvent(bool allowEndFeedback)
116 {
117   bool ret = false;
118
119   if( mActionHandler )
120   {
121     ret = mActionHandler->AccessibilityActionNext(allowEndFeedback);
122   }
123
124   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
125
126   return ret;
127 }
128
129 bool AccessibilityAdaptor::HandleActionPreviousEvent(bool allowEndFeedback)
130 {
131   bool ret = false;
132
133   if( mActionHandler )
134   {
135     ret = mActionHandler->AccessibilityActionPrevious(allowEndFeedback);
136   }
137
138   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
139
140   return ret;
141 }
142
143 bool AccessibilityAdaptor::HandleActionActivateEvent()
144 {
145   bool ret = false;
146
147   if( mActionHandler )
148   {
149     ret = mActionHandler->AccessibilityActionActivate();
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 AccessibilityAdaptor::HandleActionReadEvent(unsigned int x, unsigned int y, bool allowReadAgain)
158 {
159   bool ret = false;
160
161   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %d , %d\n", __FUNCTION__, __LINE__, x, y);
162
163   mReadPosition.x = x;
164   mReadPosition.y = y;
165
166   if( mActionHandler )
167   {
168     ret = mActionHandler->AccessibilityActionRead( allowReadAgain );
169     DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
170   }
171
172   return ret;
173 }
174
175 bool AccessibilityAdaptor::HandleActionReadNextEvent(bool allowEndFeedback)
176 {
177   bool ret = false;
178
179   if( mActionHandler )
180   {
181     ret = mActionHandler->AccessibilityActionReadNext(allowEndFeedback);
182   }
183
184   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
185
186   return ret;
187 }
188
189 bool AccessibilityAdaptor::HandleActionReadPreviousEvent(bool allowEndFeedback)
190 {
191   bool ret = false;
192
193   if( mActionHandler )
194   {
195     ret = mActionHandler->AccessibilityActionReadPrevious(allowEndFeedback);
196   }
197
198   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
199
200   return ret;
201 }
202
203 bool AccessibilityAdaptor::HandleActionUpEvent()
204 {
205   bool ret = false;
206
207   if( mActionHandler )
208   {
209     ret = mActionHandler->AccessibilityActionUp();
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 AccessibilityAdaptor::HandleActionDownEvent()
218 {
219   bool ret = false;
220
221   if( mActionHandler )
222   {
223     ret = mActionHandler->AccessibilityActionDown();
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 AccessibilityAdaptor::HandleActionClearFocusEvent()
232 {
233   bool ret = false;
234
235   if( mActionHandler )
236   {
237     ret = mActionHandler->ClearAccessibilityFocus();
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 AccessibilityAdaptor::HandleActionScrollEvent(const TouchPoint& point, unsigned long timeStamp)
246 {
247   bool ret = false;
248
249   // We always need to emit a scroll signal, whether it's only a hover or not,
250   // so always send the action to the action handler.
251   if( mActionHandler )
252   {
253     Dali::TouchEvent event(timeStamp);
254     event.points.push_back(point);
255     ret = mActionHandler->AccessibilityActionScroll( event );
256   }
257
258   Integration::TouchEvent touchEvent;
259   Integration::HoverEvent hoverEvent;
260   Integration::TouchEventCombiner::EventDispatchType type = mCombiner.GetNextTouchEvent( Integration::Point( point ), timeStamp, touchEvent, hoverEvent );
261   if( type == Integration::TouchEventCombiner::DispatchTouch || type == Integration::TouchEventCombiner::DispatchBoth ) // hover event is ignored
262   {
263     // Process the touch event in accessibility gesture detector
264     if( mAccessibilityGestureDetector )
265     {
266       mAccessibilityGestureDetector->SendEvent( touchEvent );
267       ret = true;
268     }
269   }
270
271   return ret;
272 }
273
274 bool AccessibilityAdaptor::HandleActionTouchEvent(const TouchPoint& point, unsigned long timeStamp)
275 {
276   bool ret = false;
277
278   Dali::TouchEvent touchEvent(timeStamp);
279   touchEvent.points.push_back(point);
280
281   if( mActionHandler )
282   {
283     ret = mActionHandler->AccessibilityActionTouch(touchEvent);
284   }
285   return ret;
286 }
287
288 bool AccessibilityAdaptor::HandleActionBackEvent()
289 {
290   bool ret = false;
291
292   if( mActionHandler )
293   {
294     ret = mActionHandler->AccessibilityActionBack();
295   }
296
297   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
298
299   return ret;
300 }
301
302 void AccessibilityAdaptor::HandleActionEnableEvent()
303 {
304   EnableAccessibility();
305 }
306
307 void AccessibilityAdaptor::HandleActionDisableEvent()
308 {
309   DisableAccessibility();
310 }
311
312 bool AccessibilityAdaptor::HandleActionScrollUpEvent()
313 {
314   bool ret = false;
315
316   if( mActionHandler )
317   {
318     ret = mActionHandler->AccessibilityActionScrollUp();
319   }
320
321   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
322
323   return ret;
324 }
325
326
327 bool AccessibilityAdaptor::HandleActionScrollDownEvent()
328 {
329   bool ret = false;
330
331   if( mActionHandler )
332   {
333     ret = mActionHandler->AccessibilityActionScrollDown();
334   }
335
336   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
337
338   return ret;
339 }
340
341 bool AccessibilityAdaptor::HandleActionPageLeftEvent()
342 {
343   bool ret = false;
344
345   if( mActionHandler )
346   {
347     ret = mActionHandler->AccessibilityActionPageLeft();
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::HandleActionPageRightEvent()
356 {
357   bool ret = false;
358
359   if( mActionHandler )
360   {
361     ret = mActionHandler->AccessibilityActionPageRight();
362   }
363
364   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
365
366   return ret;
367 }
368
369 bool AccessibilityAdaptor::HandleActionPageUpEvent()
370 {
371   bool ret = false;
372
373   if( mActionHandler )
374   {
375     ret = mActionHandler->AccessibilityActionPageUp();
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 AccessibilityAdaptor::HandleActionPageDownEvent()
384 {
385   bool ret = false;
386
387   if( mActionHandler )
388   {
389     ret = mActionHandler->AccessibilityActionPageDown();
390   }
391
392   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
393
394   return ret;
395 }
396
397 bool AccessibilityAdaptor::HandleActionMoveToFirstEvent()
398 {
399   bool ret = false;
400
401   if( mActionHandler )
402   {
403     ret = mActionHandler->AccessibilityActionMoveToFirst();
404   }
405
406   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
407
408   return ret;
409 }
410
411 bool AccessibilityAdaptor::HandleActionMoveToLastEvent()
412 {
413   bool ret = false;
414
415   if( mActionHandler )
416   {
417     ret = mActionHandler->AccessibilityActionMoveToLast();
418   }
419
420   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
421
422   return ret;
423 }
424
425 bool AccessibilityAdaptor::HandleActionReadFromTopEvent()
426 {
427   bool ret = false;
428
429   if( mActionHandler )
430   {
431     ret = mActionHandler->AccessibilityActionReadFromTop();
432   }
433
434   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
435
436   return ret;
437 }
438
439 bool AccessibilityAdaptor::HandleActionReadFromNextEvent()
440 {
441   bool ret = false;
442
443   if( mActionHandler )
444   {
445     ret = mActionHandler->AccessibilityActionReadFromNext();
446   }
447
448   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
449
450   return ret;
451 }
452
453 bool AccessibilityAdaptor::HandleActionZoomEvent()
454 {
455   bool ret = false;
456
457   if( mActionHandler )
458   {
459     ret = mActionHandler->AccessibilityActionZoom();
460   }
461
462   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
463
464   return ret;
465 }
466
467 bool AccessibilityAdaptor::HandleActionReadPauseResumeEvent()
468 {
469   bool ret = false;
470
471   if( mActionHandler )
472   {
473     ret = mActionHandler->AccessibilityActionReadPauseResume();
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::HandleActionStartStopEvent()
482 {
483   bool ret = false;
484
485   if( mActionHandler )
486   {
487     ret = mActionHandler->AccessibilityActionStartStop();
488   }
489
490   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
491
492   return ret;
493 }
494
495 AccessibilityAdaptor::~AccessibilityAdaptor()
496 {
497   // Do any platform specific clean-up in OnDestroy()
498   OnDestroy();
499 }
500
501 } // namespace Adaptor
502
503 } // namespace Internal
504
505 } // namespace Dali