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