1685cac261676c76732af32cfed130d2b9ca86ca
[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   mIsForced( false )
55 {
56   mAccessibilityGestureDetector = new AccessibilityGestureDetector();
57 }
58
59 void AccessibilityAdaptor::EnableAccessibility()
60 {
61   if(mIsEnabled == false)
62   {
63     mIsEnabled = true;
64
65     if( mActionHandler )
66     {
67       mActionHandler->ChangeAccessibilityStatus();
68     }
69   }
70 }
71
72 void AccessibilityAdaptor::DisableAccessibility()
73 {
74   if(mIsEnabled == true)
75   {
76     mIsEnabled = false;
77
78     if( mActionHandler )
79     {
80       mActionHandler->ChangeAccessibilityStatus();
81     }
82
83     // Destroy the TtsPlayer if exists.
84     if ( Adaptor::IsAvailable() )
85     {
86       Dali::Adaptor& adaptor = Dali::Adaptor::Get();
87       Adaptor& adaptorImpl = Adaptor::GetImplementation( adaptor );
88       adaptorImpl.DestroyTtsPlayer( Dali::TtsPlayer::SCREEN_READER );
89     }
90   }
91 }
92
93 bool AccessibilityAdaptor::IsEnabled() const
94 {
95   return mIsEnabled;
96 }
97
98 void AccessibilityAdaptor::SetForcedEnable( bool forced )
99 {
100   mIsForced = forced;
101 }
102
103 bool AccessibilityAdaptor::IsForcedEnable() const
104 {
105   return mIsForced;
106 }
107
108 Vector2 AccessibilityAdaptor::GetReadPosition() const
109 {
110   return mReadPosition;
111 }
112
113 void AccessibilityAdaptor::SetActionHandler(AccessibilityActionHandler& handler)
114 {
115   mActionHandler = &handler;
116 }
117
118 void AccessibilityAdaptor::SetGestureHandler(AccessibilityGestureHandler& handler)
119 {
120   if( mAccessibilityGestureDetector )
121   {
122     mAccessibilityGestureDetector->SetGestureHandler(handler);
123   }
124 }
125
126 bool AccessibilityAdaptor::HandleActionNextEvent(bool allowEndFeedback)
127 {
128   bool ret = false;
129
130   if( mActionHandler )
131   {
132     ret = mActionHandler->AccessibilityActionNext(allowEndFeedback);
133   }
134
135   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
136
137   return ret;
138 }
139
140 bool AccessibilityAdaptor::HandleActionPreviousEvent(bool allowEndFeedback)
141 {
142   bool ret = false;
143
144   if( mActionHandler )
145   {
146     ret = mActionHandler->AccessibilityActionPrevious(allowEndFeedback);
147   }
148
149   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
150
151   return ret;
152 }
153
154 bool AccessibilityAdaptor::HandleActionActivateEvent()
155 {
156   bool ret = false;
157
158   if( mActionHandler )
159   {
160     ret = mActionHandler->AccessibilityActionActivate();
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 AccessibilityAdaptor::HandleActionReadEvent(unsigned int x, unsigned int y, bool allowReadAgain)
169 {
170   bool ret = false;
171
172   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %d , %d\n", __FUNCTION__, __LINE__, x, y);
173
174   mReadPosition.x = static_cast< float > (x);
175   mReadPosition.y = static_cast< float > (y);
176
177   if( mActionHandler )
178   {
179     ret = mActionHandler->AccessibilityActionRead( allowReadAgain );
180     DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
181   }
182
183   return ret;
184 }
185
186 bool AccessibilityAdaptor::HandleActionReadNextEvent(bool allowEndFeedback)
187 {
188   bool ret = false;
189
190   if( mActionHandler )
191   {
192     ret = mActionHandler->AccessibilityActionReadNext(allowEndFeedback);
193   }
194
195   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
196
197   return ret;
198 }
199
200 bool AccessibilityAdaptor::HandleActionReadPreviousEvent(bool allowEndFeedback)
201 {
202   bool ret = false;
203
204   if( mActionHandler )
205   {
206     ret = mActionHandler->AccessibilityActionReadPrevious(allowEndFeedback);
207   }
208
209   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
210
211   return ret;
212 }
213
214 bool AccessibilityAdaptor::HandleActionUpEvent()
215 {
216   bool ret = false;
217
218   if( mActionHandler )
219   {
220     ret = mActionHandler->AccessibilityActionUp();
221   }
222
223   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
224
225   return ret;
226 }
227
228 bool AccessibilityAdaptor::HandleActionDownEvent()
229 {
230   bool ret = false;
231
232   if( mActionHandler )
233   {
234     ret = mActionHandler->AccessibilityActionDown();
235   }
236
237   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
238
239   return ret;
240 }
241
242 bool AccessibilityAdaptor::HandleActionClearFocusEvent()
243 {
244   bool ret = false;
245
246   if( mActionHandler )
247   {
248     ret = mActionHandler->ClearAccessibilityFocus();
249   }
250
251   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
252
253   return ret;
254 }
255
256 bool AccessibilityAdaptor::HandleActionScrollEvent(const TouchPoint& point, uint32_t timeStamp)
257 {
258   bool ret = false;
259
260   // We always need to emit a scroll signal, whether it's only a hover or not,
261   // so always send the action to the action handler.
262   if( mActionHandler )
263   {
264     Dali::TouchEvent touch = Integration::NewTouchEvent( timeStamp, point );
265     ret = mActionHandler->AccessibilityActionScroll( touch );
266   }
267
268   Integration::TouchEvent touchEvent;
269   Integration::HoverEvent hoverEvent;
270   Integration::TouchEventCombiner::EventDispatchType type = mCombiner.GetNextTouchEvent( Integration::Point( point ), timeStamp, touchEvent, hoverEvent );
271   if( type == Integration::TouchEventCombiner::DISPATCH_TOUCH || type == Integration::TouchEventCombiner::DISPATCH_BOTH ) // hover event is ignored
272   {
273     // Process the touch event in accessibility gesture detector
274     if( mAccessibilityGestureDetector )
275     {
276       mAccessibilityGestureDetector->SendEvent( touchEvent );
277       ret = true;
278     }
279   }
280
281   return ret;
282 }
283
284 bool AccessibilityAdaptor::HandleActionBackEvent()
285 {
286   bool ret = false;
287
288   if( mActionHandler )
289   {
290     ret = mActionHandler->AccessibilityActionBack();
291   }
292
293   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
294
295   return ret;
296 }
297
298 void AccessibilityAdaptor::HandleActionEnableEvent()
299 {
300   EnableAccessibility();
301 }
302
303 void AccessibilityAdaptor::HandleActionDisableEvent()
304 {
305   DisableAccessibility();
306 }
307
308 bool AccessibilityAdaptor::HandleActionScrollUpEvent()
309 {
310   bool ret = false;
311
312   if( mActionHandler )
313   {
314     ret = mActionHandler->AccessibilityActionScrollUp();
315   }
316
317   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
318
319   return ret;
320 }
321
322
323 bool AccessibilityAdaptor::HandleActionScrollDownEvent()
324 {
325   bool ret = false;
326
327   if( mActionHandler )
328   {
329     ret = mActionHandler->AccessibilityActionScrollDown();
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::HandleActionPageLeftEvent()
338 {
339   bool ret = false;
340
341   if( mActionHandler )
342   {
343     ret = mActionHandler->AccessibilityActionPageLeft();
344   }
345
346   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
347
348   return ret;
349 }
350
351 bool AccessibilityAdaptor::HandleActionPageRightEvent()
352 {
353   bool ret = false;
354
355   if( mActionHandler )
356   {
357     ret = mActionHandler->AccessibilityActionPageRight();
358   }
359
360   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
361
362   return ret;
363 }
364
365 bool AccessibilityAdaptor::HandleActionPageUpEvent()
366 {
367   bool ret = false;
368
369   if( mActionHandler )
370   {
371     ret = mActionHandler->AccessibilityActionPageUp();
372   }
373
374   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
375
376   return ret;
377 }
378
379 bool AccessibilityAdaptor::HandleActionPageDownEvent()
380 {
381   bool ret = false;
382
383   if( mActionHandler )
384   {
385     ret = mActionHandler->AccessibilityActionPageDown();
386   }
387
388   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
389
390   return ret;
391 }
392
393 bool AccessibilityAdaptor::HandleActionMoveToFirstEvent()
394 {
395   bool ret = false;
396
397   if( mActionHandler )
398   {
399     ret = mActionHandler->AccessibilityActionMoveToFirst();
400   }
401
402   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
403
404   return ret;
405 }
406
407 bool AccessibilityAdaptor::HandleActionMoveToLastEvent()
408 {
409   bool ret = false;
410
411   if( mActionHandler )
412   {
413     ret = mActionHandler->AccessibilityActionMoveToLast();
414   }
415
416   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
417
418   return ret;
419 }
420
421 bool AccessibilityAdaptor::HandleActionReadFromTopEvent()
422 {
423   bool ret = false;
424
425   if( mActionHandler )
426   {
427     ret = mActionHandler->AccessibilityActionReadFromTop();
428   }
429
430   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
431
432   return ret;
433 }
434
435 bool AccessibilityAdaptor::HandleActionReadFromNextEvent()
436 {
437   bool ret = false;
438
439   if( mActionHandler )
440   {
441     ret = mActionHandler->AccessibilityActionReadFromNext();
442   }
443
444   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
445
446   return ret;
447 }
448
449 bool AccessibilityAdaptor::HandleActionZoomEvent()
450 {
451   bool ret = false;
452
453   if( mActionHandler )
454   {
455     ret = mActionHandler->AccessibilityActionZoom();
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::HandleActionReadPauseResumeEvent()
464 {
465   bool ret = false;
466
467   if( mActionHandler )
468   {
469     ret = mActionHandler->AccessibilityActionReadPauseResume();
470   }
471
472   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
473
474   return ret;
475 }
476
477 bool AccessibilityAdaptor::HandleActionStartStopEvent()
478 {
479   bool ret = false;
480
481   if( mActionHandler )
482   {
483     ret = mActionHandler->AccessibilityActionStartStop();
484   }
485
486   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
487
488   return ret;
489 }
490
491 AccessibilityAdaptor::~AccessibilityAdaptor()
492 {
493   // Do any platform specific clean-up in OnDestroy()
494   OnDestroy();
495 }
496
497 } // namespace Adaptor
498
499 } // namespace Internal
500
501 } // namespace Dali