Use existing callback ID for recurring callbacks
[platform/core/uifw/dali-adaptor.git] / dali / internal / accessibility / common / accessibility-adaptor-impl.cpp
1 /*
2  * Copyright (c) 2020 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-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::TouchEvent touch = Integration::NewTouchEvent( timeStamp, point );
254     ret = mActionHandler->AccessibilityActionScroll( touch );
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::DISPATCH_TOUCH || type == Integration::TouchEventCombiner::DISPATCH_BOTH ) // 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::HandleActionBackEvent()
274 {
275   bool ret = false;
276
277   if( mActionHandler )
278   {
279     ret = mActionHandler->AccessibilityActionBack();
280   }
281
282   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
283
284   return ret;
285 }
286
287 void AccessibilityAdaptor::HandleActionEnableEvent()
288 {
289   EnableAccessibility();
290 }
291
292 void AccessibilityAdaptor::HandleActionDisableEvent()
293 {
294   DisableAccessibility();
295 }
296
297 bool AccessibilityAdaptor::HandleActionScrollUpEvent()
298 {
299   bool ret = false;
300
301   if( mActionHandler )
302   {
303     ret = mActionHandler->AccessibilityActionScrollUp();
304   }
305
306   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
307
308   return ret;
309 }
310
311
312 bool AccessibilityAdaptor::HandleActionScrollDownEvent()
313 {
314   bool ret = false;
315
316   if( mActionHandler )
317   {
318     ret = mActionHandler->AccessibilityActionScrollDown();
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 bool AccessibilityAdaptor::HandleActionPageLeftEvent()
327 {
328   bool ret = false;
329
330   if( mActionHandler )
331   {
332     ret = mActionHandler->AccessibilityActionPageLeft();
333   }
334
335   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
336
337   return ret;
338 }
339
340 bool AccessibilityAdaptor::HandleActionPageRightEvent()
341 {
342   bool ret = false;
343
344   if( mActionHandler )
345   {
346     ret = mActionHandler->AccessibilityActionPageRight();
347   }
348
349   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
350
351   return ret;
352 }
353
354 bool AccessibilityAdaptor::HandleActionPageUpEvent()
355 {
356   bool ret = false;
357
358   if( mActionHandler )
359   {
360     ret = mActionHandler->AccessibilityActionPageUp();
361   }
362
363   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
364
365   return ret;
366 }
367
368 bool AccessibilityAdaptor::HandleActionPageDownEvent()
369 {
370   bool ret = false;
371
372   if( mActionHandler )
373   {
374     ret = mActionHandler->AccessibilityActionPageDown();
375   }
376
377   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
378
379   return ret;
380 }
381
382 bool AccessibilityAdaptor::HandleActionMoveToFirstEvent()
383 {
384   bool ret = false;
385
386   if( mActionHandler )
387   {
388     ret = mActionHandler->AccessibilityActionMoveToFirst();
389   }
390
391   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
392
393   return ret;
394 }
395
396 bool AccessibilityAdaptor::HandleActionMoveToLastEvent()
397 {
398   bool ret = false;
399
400   if( mActionHandler )
401   {
402     ret = mActionHandler->AccessibilityActionMoveToLast();
403   }
404
405   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
406
407   return ret;
408 }
409
410 bool AccessibilityAdaptor::HandleActionReadFromTopEvent()
411 {
412   bool ret = false;
413
414   if( mActionHandler )
415   {
416     ret = mActionHandler->AccessibilityActionReadFromTop();
417   }
418
419   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
420
421   return ret;
422 }
423
424 bool AccessibilityAdaptor::HandleActionReadFromNextEvent()
425 {
426   bool ret = false;
427
428   if( mActionHandler )
429   {
430     ret = mActionHandler->AccessibilityActionReadFromNext();
431   }
432
433   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
434
435   return ret;
436 }
437
438 bool AccessibilityAdaptor::HandleActionZoomEvent()
439 {
440   bool ret = false;
441
442   if( mActionHandler )
443   {
444     ret = mActionHandler->AccessibilityActionZoom();
445   }
446
447   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
448
449   return ret;
450 }
451
452 bool AccessibilityAdaptor::HandleActionReadPauseResumeEvent()
453 {
454   bool ret = false;
455
456   if( mActionHandler )
457   {
458     ret = mActionHandler->AccessibilityActionReadPauseResume();
459   }
460
461   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
462
463   return ret;
464 }
465
466 bool AccessibilityAdaptor::HandleActionStartStopEvent()
467 {
468   bool ret = false;
469
470   if( mActionHandler )
471   {
472     ret = mActionHandler->AccessibilityActionStartStop();
473   }
474
475   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
476
477   return ret;
478 }
479
480 AccessibilityAdaptor::~AccessibilityAdaptor()
481 {
482   // Do any platform specific clean-up in OnDestroy()
483   OnDestroy();
484 }
485
486 } // namespace Adaptor
487
488 } // namespace Internal
489
490 } // namespace Dali