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