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