UTC test fix and Adaptors initialising accessibility correctly
[platform/core/uifw/dali-adaptor.git] / adaptors / ubuntu / accessibility-adaptor-impl-ubuntu.cpp
1 /*
2  * Copyright (c) 2014 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 "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 #include <dali/integration-api/events/gesture-requests.h>
27
28 // INTERNAL INCLUDES
29 #include <singleton-service-impl.h>
30 #include "system-settings.h"
31
32 namespace Dali
33 {
34
35 namespace Internal
36 {
37
38 namespace Adaptor
39 {
40
41 namespace
42 {
43 #if defined(DEBUG_ENABLED)
44 Debug::Filter* gAccessibilityAdaptorLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_ACCESSIBILITY_ADAPTOR");
45 #endif
46
47 BaseHandle Create()
48 {
49   BaseHandle handle( AccessibilityAdaptor::Get() );
50
51   if ( !handle )
52   {
53     Dali::SingletonService service( SingletonService::Get() );
54     if ( service )
55     {
56       Dali::AccessibilityAdaptor adaptor = Dali::AccessibilityAdaptor( new AccessibilityAdaptor() );
57       service.Register( typeid( adaptor ), adaptor );
58       handle = adaptor;
59     }
60   }
61
62   return handle;
63 }
64 TypeRegistration ACCESSIBILITY_ADAPTOR_TYPE( typeid(Dali::AccessibilityAdaptor), typeid(Dali::BaseHandle), Create, true /* Create Instance At Startup */ );
65
66 } // unnamed namespace
67
68 Dali::AccessibilityAdaptor AccessibilityAdaptor::Get()
69 {
70   Dali::AccessibilityAdaptor adaptor;
71
72   Dali::SingletonService service( SingletonService::Get() );
73   if ( service )
74   {
75     // Check whether the singleton is already created
76     Dali::BaseHandle handle = service.GetSingleton( typeid( Dali::AccessibilityAdaptor ) );
77     if(handle)
78     {
79       // If so, downcast the handle
80       adaptor = Dali::AccessibilityAdaptor( dynamic_cast< AccessibilityAdaptor* >( handle.GetObjectPtr() ) );
81     }
82   }
83
84   return adaptor;
85 }
86
87 Vector2 AccessibilityAdaptor::GetReadPosition() const
88 {
89   return mReadPosition;
90 }
91
92 void AccessibilityAdaptor::SetActionHandler(AccessibilityActionHandler& handler)
93 {
94   mActionHandler = &handler;
95 }
96
97 void AccessibilityAdaptor::SetGestureHandler(AccessibilityGestureHandler& handler)
98 {
99   if( mAccessibilityGestureDetector )
100   {
101     mAccessibilityGestureDetector->SetGestureHandler(handler);
102   }
103 }
104
105 bool AccessibilityAdaptor::HandleActionClearFocusEvent()
106 {
107   bool ret = false;
108
109   if( mActionHandler )
110   {
111     ret = mActionHandler->ClearAccessibilityFocus();
112   }
113
114   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
115
116   return ret;
117 }
118
119 bool AccessibilityAdaptor::HandleActionScrollEvent(const TouchPoint& point, unsigned long timeStamp)
120 {
121   bool ret = false;
122
123   // We always need to emit a scroll signal, whether it's only a hover or not,
124   // so always send the action to the action handler.
125   if( mActionHandler )
126   {
127     Dali::TouchEvent event(timeStamp);
128     event.points.push_back(point);
129     ret = mActionHandler->AccessibilityActionScroll( event );
130   }
131
132   Integration::TouchEvent touchEvent;
133   Integration::HoverEvent hoverEvent;
134   Integration::TouchEventCombiner::EventDispatchType type = mCombiner.GetNextTouchEvent(point, timeStamp, touchEvent, hoverEvent);
135   if( type == Integration::TouchEventCombiner::DispatchTouch || type == Integration::TouchEventCombiner::DispatchBoth ) // hover event is ignored
136   {
137     // Process the touch event in accessibility gesture detector
138     if( mAccessibilityGestureDetector )
139     {
140       mAccessibilityGestureDetector->SendEvent( touchEvent );
141       ret = true;
142     }
143   }
144
145   return ret;
146 }
147
148 bool AccessibilityAdaptor::HandleActionTouchEvent(const TouchPoint& point, unsigned long timeStamp)
149 {
150   bool ret = false;
151
152   Dali::TouchEvent touchEvent(timeStamp);
153   touchEvent.points.push_back(point);
154
155   if( mActionHandler )
156   {
157     ret = mActionHandler->AccessibilityActionTouch(touchEvent);
158   }
159   return ret;
160 }
161
162 bool AccessibilityAdaptor::HandleActionBackEvent()
163 {
164   bool ret = false;
165
166   if( mActionHandler )
167   {
168     ret = mActionHandler->AccessibilityActionBack();
169   }
170
171   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
172
173   return ret;
174 }
175
176 void AccessibilityAdaptor::HandleActionEnableEvent()
177 {
178   EnableAccessibility();
179 }
180
181 void AccessibilityAdaptor::HandleActionDisableEvent()
182 {
183   DisableAccessibility();
184 }
185
186 void AccessibilityAdaptor::EnableAccessibility()
187 {
188   if(mIsEnabled == false)
189   {
190     mIsEnabled = true;
191
192     if( mActionHandler )
193     {
194       mActionHandler->ChangeAccessibilityStatus();
195     }
196   }
197 }
198
199 void AccessibilityAdaptor::DisableAccessibility()
200 {
201   if(mIsEnabled == true)
202   {
203     mIsEnabled = false;
204
205     if( mActionHandler )
206     {
207       mActionHandler->ChangeAccessibilityStatus();
208     }
209
210     // Destroy the TtsPlayer if exists.
211     if ( Adaptor::IsAvailable() )
212     {
213       Dali::Adaptor& adaptor = Dali::Adaptor::Get();
214       Adaptor::GetImplementation( adaptor ).DestroyTtsPlayer( Dali::TtsPlayer::SCREEN_READER );
215     }
216   }
217 }
218
219 bool AccessibilityAdaptor::IsEnabled() const
220 {
221   return mIsEnabled;
222 }
223
224 void AccessibilityAdaptor::SetIndicator(Indicator* indicator)
225 {
226   mIndicator = indicator;
227 }
228
229 AccessibilityAdaptor::AccessibilityAdaptor()
230 : mIsEnabled( false ),
231   mReadPosition(),
232   mActionHandler( NULL ),
233   mIndicator( NULL ),
234   mIndicatorFocused( false )
235 {
236   int isEnabled = 0;
237   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, isEnabled?"ENABLED":"DISABLED");
238
239   if(isEnabled == 1)
240   {
241     mIsEnabled = true;
242   }
243   else
244   {
245     mIsEnabled = false;
246   }
247
248   mAccessibilityGestureDetector = new AccessibilityGestureDetector();
249 }
250
251 AccessibilityAdaptor::~AccessibilityAdaptor()
252 {
253 }
254
255 bool AccessibilityAdaptor::HandleActionNextEvent(bool allowEndFeedback)
256 {
257   bool ret = false;
258
259   if( mActionHandler )
260   {
261     ret = mActionHandler->AccessibilityActionNext(allowEndFeedback);
262   }
263
264   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
265
266   return ret;
267 }
268
269 bool AccessibilityAdaptor::HandleActionPreviousEvent(bool allowEndFeedback)
270 {
271   bool ret = false;
272
273   if( mActionHandler )
274   {
275     ret = mActionHandler->AccessibilityActionPrevious(allowEndFeedback);
276   }
277
278   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
279
280   return ret;
281 }
282
283 bool AccessibilityAdaptor::HandleActionActivateEvent()
284 {
285   bool ret = false;
286
287   if( mActionHandler )
288   {
289     ret = mActionHandler->AccessibilityActionActivate();
290   }
291
292   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
293
294   return ret;
295 }
296
297 bool AccessibilityAdaptor::HandleActionReadEvent(unsigned int x, unsigned int y, bool allowReadAgain)
298 {
299   bool ret = false;
300
301   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %d , %d\n", __FUNCTION__, __LINE__, x, y);
302
303   mReadPosition.x = x;
304   mReadPosition.y = y;
305
306   bool indicatorFocused = false;
307
308   // Check whether the Indicator is focused
309   if( mIndicator && mIndicator->IsConnected() )
310   {
311     // Check the position and size of Indicator actor
312     Dali::Actor indicatorActor = mIndicator->GetActor();
313     Vector3 position = Vector3(0.0f, 0.0f, 0.0f);
314     Vector3 size = indicatorActor.GetCurrentSize();
315
316     if(mReadPosition.x >= position.x &&
317        mReadPosition.x <= position.x + size.width &&
318        mReadPosition.y >= position.y &&
319        mReadPosition.y <= position.y + size.height)
320     {
321       indicatorFocused = true;
322       DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] Indicator area!!!!\n", __FUNCTION__, __LINE__);
323     }
324   }
325
326   if( mIndicator )
327   {
328     if( !mIndicatorFocused && indicatorFocused )
329     {
330       // If Indicator is focused, the focus should be cleared in Dali focus chain.
331       if( mActionHandler )
332       {
333         mActionHandler->ClearAccessibilityFocus();
334       }
335     }
336
337     mIndicatorFocused = indicatorFocused;
338
339     // Send accessibility READ action information to Indicator
340     if( mIndicatorFocused )
341     {
342       DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] Send READ message to indicator!!!!\n", __FUNCTION__, __LINE__);
343     }
344   }
345
346   if( mActionHandler && !mIndicatorFocused)
347   {
348     // If Indicator is not focused, the accessibility actions should be handled by the registered
349     // accessibility action handler (e.g. focus manager)
350     ret = mActionHandler->AccessibilityActionRead( allowReadAgain );
351     DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
352   }
353
354   return ret;
355 }
356
357 bool AccessibilityAdaptor::HandleActionReadNextEvent(bool allowEndFeedback)
358 {
359   bool ret = false;
360
361   if( mActionHandler )
362   {
363     ret = mActionHandler->AccessibilityActionReadNext(allowEndFeedback);
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::HandleActionReadPreviousEvent(bool allowEndFeedback)
372 {
373   bool ret = false;
374
375   if( mActionHandler )
376   {
377     ret = mActionHandler->AccessibilityActionReadPrevious(allowEndFeedback);
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::HandleActionUpEvent()
386 {
387   bool ret = false;
388
389   if( mActionHandler )
390   {
391     ret = mActionHandler->AccessibilityActionUp();
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::HandleActionDownEvent()
400 {
401   bool ret = false;
402
403   if( mActionHandler )
404   {
405     ret = mActionHandler->AccessibilityActionDown();
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::HandleActionScrollUpEvent()
414 {
415   bool ret = false;
416
417   if( mActionHandler )
418   {
419     ret = mActionHandler->AccessibilityActionScrollUp();
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
428 bool AccessibilityAdaptor::HandleActionScrollDownEvent()
429 {
430   bool ret = false;
431
432   if( mActionHandler )
433   {
434     ret = mActionHandler->AccessibilityActionScrollDown();
435   }
436
437   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
438
439   return ret;
440 }
441
442 bool AccessibilityAdaptor::HandleActionPageLeftEvent()
443 {
444   bool ret = false;
445
446   if( mActionHandler )
447   {
448     ret = mActionHandler->AccessibilityActionPageLeft();
449   }
450
451   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
452
453   return ret;
454 }
455
456 bool AccessibilityAdaptor::HandleActionPageRightEvent()
457 {
458   bool ret = false;
459
460   if( mActionHandler )
461   {
462     ret = mActionHandler->AccessibilityActionPageRight();
463   }
464
465   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
466
467   return ret;
468 }
469
470 bool AccessibilityAdaptor::HandleActionPageUpEvent()
471 {
472   bool ret = false;
473
474   if( mActionHandler )
475   {
476     ret = mActionHandler->AccessibilityActionPageUp();
477   }
478
479   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
480
481   return ret;
482 }
483
484 bool AccessibilityAdaptor::HandleActionPageDownEvent()
485 {
486   bool ret = false;
487
488   if( mActionHandler )
489   {
490     ret = mActionHandler->AccessibilityActionPageDown();
491   }
492
493   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
494
495   return ret;
496 }
497
498 bool AccessibilityAdaptor::HandleActionMoveToFirstEvent()
499 {
500   bool ret = false;
501
502   if( mActionHandler )
503   {
504     ret = mActionHandler->AccessibilityActionMoveToFirst();
505   }
506
507   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
508
509   return ret;
510 }
511
512 bool AccessibilityAdaptor::HandleActionMoveToLastEvent()
513 {
514   bool ret = false;
515
516   if( mActionHandler )
517   {
518     ret = mActionHandler->AccessibilityActionMoveToLast();
519   }
520
521   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
522
523   return ret;
524 }
525
526 bool AccessibilityAdaptor::HandleActionReadFromTopEvent()
527 {
528   bool ret = false;
529
530   if( mActionHandler )
531   {
532     ret = mActionHandler->AccessibilityActionReadFromTop();
533   }
534
535   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
536
537   return ret;
538 }
539
540 bool AccessibilityAdaptor::HandleActionReadFromNextEvent()
541 {
542   bool ret = false;
543
544   if( mActionHandler )
545   {
546     ret = mActionHandler->AccessibilityActionReadFromNext();
547   }
548
549   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
550
551   return ret;
552 }
553
554 bool AccessibilityAdaptor::HandleActionZoomEvent()
555 {
556   bool ret = false;
557
558   if( mActionHandler )
559   {
560     ret = mActionHandler->AccessibilityActionZoom();
561   }
562
563   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
564
565   return ret;
566 }
567
568 bool AccessibilityAdaptor::HandleActionReadIndicatorInformationEvent()
569 {
570   bool ret = false;
571
572   if( mActionHandler )
573   {
574     ret = mActionHandler->AccessibilityActionReadIndicatorInformation();
575   }
576
577   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
578
579   return ret;
580 }
581
582 bool AccessibilityAdaptor::HandleActionReadPauseResumeEvent()
583 {
584   bool ret = false;
585
586   if( mActionHandler )
587   {
588     ret = mActionHandler->AccessibilityActionReadPauseResume();
589   }
590
591   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
592
593   return ret;
594 }
595
596 bool AccessibilityAdaptor::HandleActionStartStopEvent()
597 {
598   bool ret = false;
599
600   if( mActionHandler )
601   {
602     ret = mActionHandler->AccessibilityActionStartStop();
603   }
604
605   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
606
607   return ret;
608 }
609
610 } // namespace Adaptor
611
612 } // namespace Internal
613
614 } // namespace Dali