Removing Dali::TouchEvent
[platform/core/uifw/dali-adaptor.git] / dali / internal / accessibility / common / accessibility-adaptor-impl.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/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/touch-data-integ.h>
26 #include <dali/integration-api/events/hover-event-integ.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 = static_cast< float > (x);
164   mReadPosition.y = static_cast< float > (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, uint32_t 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::TouchData touchData = Integration::NewTouchData( timeStamp, point );
254     ret = mActionHandler->AccessibilityActionScroll( touchData );
255   }
256
257   Integration::TouchEvent touchEvent;
258   Integration::HoverEvent hoverEvent;
259   Integration::TouchEventCombiner::EventDispatchType type = mCombiner.GetNextTouchEvent( Integration::Point( point ), timeStamp, touchEvent, hoverEvent );
260   if( type == Integration::TouchEventCombiner::DispatchTouch || type == Integration::TouchEventCombiner::DispatchBoth ) // hover event is ignored
261   {
262     // Process the touch event in accessibility gesture detector
263     if( mAccessibilityGestureDetector )
264     {
265       mAccessibilityGestureDetector->SendEvent( touchEvent );
266       ret = true;
267     }
268   }
269
270   return ret;
271 }
272
273 bool AccessibilityAdaptor::HandleActionTouchEvent(const TouchPoint& point, uint32_t timeStamp)
274 {
275   bool ret = false;
276
277   Dali::TouchData touchData = Integration::NewTouchData( timeStamp, point );
278
279   if( mActionHandler )
280   {
281     ret = mActionHandler->AccessibilityActionTouch( touchData );
282   }
283   return ret;
284 }
285
286 bool AccessibilityAdaptor::HandleActionBackEvent()
287 {
288   bool ret = false;
289
290   if( mActionHandler )
291   {
292     ret = mActionHandler->AccessibilityActionBack();
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 void AccessibilityAdaptor::HandleActionEnableEvent()
301 {
302   EnableAccessibility();
303 }
304
305 void AccessibilityAdaptor::HandleActionDisableEvent()
306 {
307   DisableAccessibility();
308 }
309
310 bool AccessibilityAdaptor::HandleActionScrollUpEvent()
311 {
312   bool ret = false;
313
314   if( mActionHandler )
315   {
316     ret = mActionHandler->AccessibilityActionScrollUp();
317   }
318
319   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
320
321   return ret;
322 }
323
324
325 bool AccessibilityAdaptor::HandleActionScrollDownEvent()
326 {
327   bool ret = false;
328
329   if( mActionHandler )
330   {
331     ret = mActionHandler->AccessibilityActionScrollDown();
332   }
333
334   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
335
336   return ret;
337 }
338
339 bool AccessibilityAdaptor::HandleActionPageLeftEvent()
340 {
341   bool ret = false;
342
343   if( mActionHandler )
344   {
345     ret = mActionHandler->AccessibilityActionPageLeft();
346   }
347
348   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
349
350   return ret;
351 }
352
353 bool AccessibilityAdaptor::HandleActionPageRightEvent()
354 {
355   bool ret = false;
356
357   if( mActionHandler )
358   {
359     ret = mActionHandler->AccessibilityActionPageRight();
360   }
361
362   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
363
364   return ret;
365 }
366
367 bool AccessibilityAdaptor::HandleActionPageUpEvent()
368 {
369   bool ret = false;
370
371   if( mActionHandler )
372   {
373     ret = mActionHandler->AccessibilityActionPageUp();
374   }
375
376   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
377
378   return ret;
379 }
380
381 bool AccessibilityAdaptor::HandleActionPageDownEvent()
382 {
383   bool ret = false;
384
385   if( mActionHandler )
386   {
387     ret = mActionHandler->AccessibilityActionPageDown();
388   }
389
390   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
391
392   return ret;
393 }
394
395 bool AccessibilityAdaptor::HandleActionMoveToFirstEvent()
396 {
397   bool ret = false;
398
399   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( mActionHandler )
414   {
415     ret = mActionHandler->AccessibilityActionMoveToLast();
416   }
417
418   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
419
420   return ret;
421 }
422
423 bool AccessibilityAdaptor::HandleActionReadFromTopEvent()
424 {
425   bool ret = false;
426
427   if( mActionHandler )
428   {
429     ret = mActionHandler->AccessibilityActionReadFromTop();
430   }
431
432   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
433
434   return ret;
435 }
436
437 bool AccessibilityAdaptor::HandleActionReadFromNextEvent()
438 {
439   bool ret = false;
440
441   if( mActionHandler )
442   {
443     ret = mActionHandler->AccessibilityActionReadFromNext();
444   }
445
446   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
447
448   return ret;
449 }
450
451 bool AccessibilityAdaptor::HandleActionZoomEvent()
452 {
453   bool ret = false;
454
455   if( mActionHandler )
456   {
457     ret = mActionHandler->AccessibilityActionZoom();
458   }
459
460   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
461
462   return ret;
463 }
464
465 bool AccessibilityAdaptor::HandleActionReadPauseResumeEvent()
466 {
467   bool ret = false;
468
469   if( mActionHandler )
470   {
471     ret = mActionHandler->AccessibilityActionReadPauseResume();
472   }
473
474   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
475
476   return ret;
477 }
478
479 bool AccessibilityAdaptor::HandleActionStartStopEvent()
480 {
481   bool ret = false;
482
483   if( mActionHandler )
484   {
485     ret = mActionHandler->AccessibilityActionStartStop();
486   }
487
488   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
489
490   return ret;
491 }
492
493 AccessibilityAdaptor::~AccessibilityAdaptor()
494 {
495   // Do any platform specific clean-up in OnDestroy()
496   OnDestroy();
497 }
498
499 } // namespace Adaptor
500
501 } // namespace Internal
502
503 } // namespace Dali