[Tizen](ATSPI) Fix Native TC fails
[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/hover-event-integ.h>
26
27 // INTERNAL INCLUDES
28 #include <dali/internal/adaptor/common/adaptor-impl.h>
29 #include <dali/internal/system/common/system-settings.h>
30
31 namespace Dali
32 {
33
34 namespace Internal
35 {
36
37 namespace Adaptor
38 {
39
40 namespace // unnamed namespace
41 {
42
43 #if defined(DEBUG_ENABLED)
44 Debug::Filter* gAccessibilityAdaptorLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_ACCESSIBILITY_ADAPTOR");
45 #endif
46
47 } // unnamed namespace
48
49 AccessibilityAdaptor::AccessibilityAdaptor()
50 : mReadPosition(),
51   mActionHandler( NULL ),
52   mIsEnabled( false )
53 {
54   mAccessibilityGestureDetector = new AccessibilityGestureDetector();
55 }
56
57 void AccessibilityAdaptor::EnableAccessibility()
58 {
59   if(mIsEnabled == false)
60   {
61     mIsEnabled = true;
62
63     if( mActionHandler )
64     {
65       mActionHandler->ChangeAccessibilityStatus();
66     }
67   }
68 }
69
70 void AccessibilityAdaptor::DisableAccessibility()
71 {
72   if(mIsEnabled == true)
73   {
74     mIsEnabled = false;
75
76     if( mActionHandler )
77     {
78       mActionHandler->ChangeAccessibilityStatus();
79     }
80
81     // Destroy the TtsPlayer if exists.
82     if ( Adaptor::IsAvailable() )
83     {
84       Dali::Adaptor& adaptor = Dali::Adaptor::Get();
85       Adaptor& adaptorImpl = Adaptor::GetImplementation( adaptor );
86       adaptorImpl.DestroyTtsPlayer( Dali::TtsPlayer::SCREEN_READER );
87     }
88   }
89 }
90
91 bool AccessibilityAdaptor::IsEnabled() const
92 {
93   return mIsEnabled;
94 }
95
96 Vector2 AccessibilityAdaptor::GetReadPosition() const
97 {
98   return mReadPosition;
99 }
100
101 void AccessibilityAdaptor::SetActionHandler(AccessibilityActionHandler& handler)
102 {
103   mActionHandler = &handler;
104 }
105
106 void AccessibilityAdaptor::SetGestureHandler(AccessibilityGestureHandler& handler)
107 {
108   if( mAccessibilityGestureDetector )
109   {
110     mAccessibilityGestureDetector->SetGestureHandler(handler);
111   }
112 }
113
114 bool AccessibilityAdaptor::HandleActionNextEvent(bool allowEndFeedback)
115 {
116   bool ret = false;
117
118   if( mActionHandler )
119   {
120     ret = mActionHandler->AccessibilityActionNext(allowEndFeedback);
121   }
122
123   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
124
125   return ret;
126 }
127
128 bool AccessibilityAdaptor::HandleActionPreviousEvent(bool allowEndFeedback)
129 {
130   bool ret = false;
131
132   if( mActionHandler )
133   {
134     ret = mActionHandler->AccessibilityActionPrevious(allowEndFeedback);
135   }
136
137   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
138
139   return ret;
140 }
141
142 bool AccessibilityAdaptor::HandleActionActivateEvent()
143 {
144   bool ret = false;
145
146   if( mActionHandler )
147   {
148     ret = mActionHandler->AccessibilityActionActivate();
149   }
150
151   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
152
153   return ret;
154 }
155
156 bool AccessibilityAdaptor::HandleActionReadEvent(unsigned int x, unsigned int y, bool allowReadAgain)
157 {
158   bool ret = false;
159
160   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %d , %d\n", __FUNCTION__, __LINE__, x, y);
161
162   mReadPosition.x = static_cast< float > (x);
163   mReadPosition.y = static_cast< float > (y);
164
165   if( mActionHandler )
166   {
167     ret = mActionHandler->AccessibilityActionRead( allowReadAgain );
168     DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
169   }
170
171   return ret;
172 }
173
174 bool AccessibilityAdaptor::HandleActionReadNextEvent(bool allowEndFeedback)
175 {
176   bool ret = false;
177
178   if( mActionHandler )
179   {
180     ret = mActionHandler->AccessibilityActionReadNext(allowEndFeedback);
181   }
182
183   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
184
185   return ret;
186 }
187
188 bool AccessibilityAdaptor::HandleActionReadPreviousEvent(bool allowEndFeedback)
189 {
190   bool ret = false;
191
192   if( mActionHandler )
193   {
194     ret = mActionHandler->AccessibilityActionReadPrevious(allowEndFeedback);
195   }
196
197   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
198
199   return ret;
200 }
201
202 bool AccessibilityAdaptor::HandleActionUpEvent()
203 {
204   bool ret = false;
205
206   if( mActionHandler )
207   {
208     ret = mActionHandler->AccessibilityActionUp();
209   }
210
211   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
212
213   return ret;
214 }
215
216 bool AccessibilityAdaptor::HandleActionDownEvent()
217 {
218   bool ret = false;
219
220   if( mActionHandler )
221   {
222     ret = mActionHandler->AccessibilityActionDown();
223   }
224
225   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
226
227   return ret;
228 }
229
230 bool AccessibilityAdaptor::HandleActionClearFocusEvent()
231 {
232   bool ret = false;
233
234   if( mActionHandler )
235   {
236     ret = mActionHandler->ClearAccessibilityFocus();
237   }
238
239   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
240
241   return ret;
242 }
243
244 bool AccessibilityAdaptor::HandleActionScrollEvent(const TouchPoint& point, uint32_t timeStamp)
245 {
246   bool ret = false;
247
248   // We always need to emit a scroll signal, whether it's only a hover or not,
249   // so always send the action to the action handler.
250   if( mActionHandler )
251   {
252     Dali::TouchEvent event(timeStamp);
253     event.points.push_back(point);
254     ret = mActionHandler->AccessibilityActionScroll( event );
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::TouchEvent touchEvent(timeStamp);
278   touchEvent.points.push_back(point);
279
280   if( mActionHandler )
281   {
282     ret = mActionHandler->AccessibilityActionTouch(touchEvent);
283   }
284   return ret;
285 }
286
287 bool AccessibilityAdaptor::HandleActionBackEvent()
288 {
289   bool ret = false;
290
291   if( mActionHandler )
292   {
293     ret = mActionHandler->AccessibilityActionBack();
294   }
295
296   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
297
298   return ret;
299 }
300
301 void AccessibilityAdaptor::HandleActionEnableEvent()
302 {
303   EnableAccessibility();
304 }
305
306 void AccessibilityAdaptor::HandleActionDisableEvent()
307 {
308   DisableAccessibility();
309 }
310
311 bool AccessibilityAdaptor::HandleActionScrollUpEvent()
312 {
313   bool ret = false;
314
315   if( mActionHandler )
316   {
317     ret = mActionHandler->AccessibilityActionScrollUp();
318   }
319
320   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
321
322   return ret;
323 }
324
325
326 bool AccessibilityAdaptor::HandleActionScrollDownEvent()
327 {
328   bool ret = false;
329
330   if( mActionHandler )
331   {
332     ret = mActionHandler->AccessibilityActionScrollDown();
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::HandleActionPageLeftEvent()
341 {
342   bool ret = false;
343
344   if( mActionHandler )
345   {
346     ret = mActionHandler->AccessibilityActionPageLeft();
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::HandleActionPageRightEvent()
355 {
356   bool ret = false;
357
358   if( mActionHandler )
359   {
360     ret = mActionHandler->AccessibilityActionPageRight();
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::HandleActionPageUpEvent()
369 {
370   bool ret = false;
371
372   if( mActionHandler )
373   {
374     ret = mActionHandler->AccessibilityActionPageUp();
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::HandleActionPageDownEvent()
383 {
384   bool ret = false;
385
386   if( mActionHandler )
387   {
388     ret = mActionHandler->AccessibilityActionPageDown();
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::HandleActionMoveToFirstEvent()
397 {
398   bool ret = false;
399
400   if( mActionHandler )
401   {
402     ret = mActionHandler->AccessibilityActionMoveToFirst();
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::HandleActionMoveToLastEvent()
411 {
412   bool ret = false;
413
414   if( mActionHandler )
415   {
416     ret = mActionHandler->AccessibilityActionMoveToLast();
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::HandleActionReadFromTopEvent()
425 {
426   bool ret = false;
427
428   if( mActionHandler )
429   {
430     ret = mActionHandler->AccessibilityActionReadFromTop();
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::HandleActionReadFromNextEvent()
439 {
440   bool ret = false;
441
442   if( mActionHandler )
443   {
444     ret = mActionHandler->AccessibilityActionReadFromNext();
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::HandleActionZoomEvent()
453 {
454   bool ret = false;
455
456   if( mActionHandler )
457   {
458     ret = mActionHandler->AccessibilityActionZoom();
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::HandleActionReadPauseResumeEvent()
467 {
468   bool ret = false;
469
470   if( mActionHandler )
471   {
472     ret = mActionHandler->AccessibilityActionReadPauseResume();
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 bool AccessibilityAdaptor::HandleActionStartStopEvent()
481 {
482   bool ret = false;
483
484   if( mActionHandler )
485   {
486     ret = mActionHandler->AccessibilityActionStartStop();
487   }
488
489   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
490
491   return ret;
492 }
493
494 AccessibilityAdaptor::~AccessibilityAdaptor()
495 {
496   // Do any platform specific clean-up in OnDestroy()
497   OnDestroy();
498 }
499
500 } // namespace Adaptor
501
502 } // namespace Internal
503
504 } // namespace Dali