d85e6a9cecf2004b606ac7a4ae89c40342fe6903
[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(IndicatorInterface* 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   mAccessibilityGestureDetector = new AccessibilityGestureDetector();
237 }
238
239 AccessibilityAdaptor::~AccessibilityAdaptor()
240 {
241 }
242
243 bool AccessibilityAdaptor::HandleActionNextEvent(bool allowEndFeedback)
244 {
245   bool ret = false;
246
247   if( mActionHandler )
248   {
249     ret = mActionHandler->AccessibilityActionNext(allowEndFeedback);
250   }
251
252   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
253
254   return ret;
255 }
256
257 bool AccessibilityAdaptor::HandleActionPreviousEvent(bool allowEndFeedback)
258 {
259   bool ret = false;
260
261   if( mActionHandler )
262   {
263     ret = mActionHandler->AccessibilityActionPrevious(allowEndFeedback);
264   }
265
266   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
267
268   return ret;
269 }
270
271 bool AccessibilityAdaptor::HandleActionActivateEvent()
272 {
273   bool ret = false;
274
275   if( mActionHandler )
276   {
277     ret = mActionHandler->AccessibilityActionActivate();
278   }
279
280   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
281
282   return ret;
283 }
284
285 bool AccessibilityAdaptor::HandleActionReadEvent(unsigned int x, unsigned int y, bool allowReadAgain)
286 {
287   bool ret = false;
288
289   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %d , %d\n", __FUNCTION__, __LINE__, x, y);
290
291   mReadPosition.x = x;
292   mReadPosition.y = y;
293
294   bool indicatorFocused = false;
295
296   // Check whether the Indicator is focused
297   if( mIndicator && mIndicator->IsConnected() )
298   {
299     // Check the position and size of Indicator actor
300     Dali::Actor indicatorActor = mIndicator->GetActor();
301     Vector3 position = Vector3(0.0f, 0.0f, 0.0f);
302     Vector3 size = indicatorActor.GetCurrentSize();
303
304     if(mReadPosition.x >= position.x &&
305        mReadPosition.x <= position.x + size.width &&
306        mReadPosition.y >= position.y &&
307        mReadPosition.y <= position.y + size.height)
308     {
309       indicatorFocused = true;
310       DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] Indicator area!!!!\n", __FUNCTION__, __LINE__);
311     }
312   }
313
314   if( mIndicator )
315   {
316     if( !mIndicatorFocused && indicatorFocused )
317     {
318       // If Indicator is focused, the focus should be cleared in Dali focus chain.
319       if( mActionHandler )
320       {
321         mActionHandler->ClearAccessibilityFocus();
322       }
323     }
324
325     mIndicatorFocused = indicatorFocused;
326
327     // Send accessibility READ action information to Indicator
328     if( mIndicatorFocused )
329     {
330       DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] Send READ message to indicator!!!!\n", __FUNCTION__, __LINE__);
331     }
332   }
333
334   if( mActionHandler && !mIndicatorFocused)
335   {
336     // If Indicator is not focused, the accessibility actions should be handled by the registered
337     // accessibility action handler (e.g. focus manager)
338     ret = mActionHandler->AccessibilityActionRead( allowReadAgain );
339     DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
340   }
341
342   return ret;
343 }
344
345 bool AccessibilityAdaptor::HandleActionReadNextEvent(bool allowEndFeedback)
346 {
347   bool ret = false;
348
349   if( mActionHandler )
350   {
351     ret = mActionHandler->AccessibilityActionReadNext(allowEndFeedback);
352   }
353
354   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
355
356   return ret;
357 }
358
359 bool AccessibilityAdaptor::HandleActionReadPreviousEvent(bool allowEndFeedback)
360 {
361   bool ret = false;
362
363   if( mActionHandler )
364   {
365     ret = mActionHandler->AccessibilityActionReadPrevious(allowEndFeedback);
366   }
367
368   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
369
370   return ret;
371 }
372
373 bool AccessibilityAdaptor::HandleActionUpEvent()
374 {
375   bool ret = false;
376
377   if( mActionHandler )
378   {
379     ret = mActionHandler->AccessibilityActionUp();
380   }
381
382   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
383
384   return ret;
385 }
386
387 bool AccessibilityAdaptor::HandleActionDownEvent()
388 {
389   bool ret = false;
390
391   if( mActionHandler )
392   {
393     ret = mActionHandler->AccessibilityActionDown();
394   }
395
396   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
397
398   return ret;
399 }
400
401 bool AccessibilityAdaptor::HandleActionScrollUpEvent()
402 {
403   bool ret = false;
404
405   if( mActionHandler )
406   {
407     ret = mActionHandler->AccessibilityActionScrollUp();
408   }
409
410   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
411
412   return ret;
413 }
414
415
416 bool AccessibilityAdaptor::HandleActionScrollDownEvent()
417 {
418   bool ret = false;
419
420   if( mActionHandler )
421   {
422     ret = mActionHandler->AccessibilityActionScrollDown();
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::HandleActionPageLeftEvent()
431 {
432   bool ret = false;
433
434   if( mActionHandler )
435   {
436     ret = mActionHandler->AccessibilityActionPageLeft();
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::HandleActionPageRightEvent()
445 {
446   bool ret = false;
447
448   if( mActionHandler )
449   {
450     ret = mActionHandler->AccessibilityActionPageRight();
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::HandleActionPageUpEvent()
459 {
460   bool ret = false;
461
462   if( mActionHandler )
463   {
464     ret = mActionHandler->AccessibilityActionPageUp();
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::HandleActionPageDownEvent()
473 {
474   bool ret = false;
475
476   if( mActionHandler )
477   {
478     ret = mActionHandler->AccessibilityActionPageDown();
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::HandleActionMoveToFirstEvent()
487 {
488   bool ret = false;
489
490   if( mActionHandler )
491   {
492     ret = mActionHandler->AccessibilityActionMoveToFirst();
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 bool AccessibilityAdaptor::HandleActionMoveToLastEvent()
501 {
502   bool ret = false;
503
504   if( mActionHandler )
505   {
506     ret = mActionHandler->AccessibilityActionMoveToLast();
507   }
508
509   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
510
511   return ret;
512 }
513
514 bool AccessibilityAdaptor::HandleActionReadFromTopEvent()
515 {
516   bool ret = false;
517
518   if( mActionHandler )
519   {
520     ret = mActionHandler->AccessibilityActionReadFromTop();
521   }
522
523   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
524
525   return ret;
526 }
527
528 bool AccessibilityAdaptor::HandleActionReadFromNextEvent()
529 {
530   bool ret = false;
531
532   if( mActionHandler )
533   {
534     ret = mActionHandler->AccessibilityActionReadFromNext();
535   }
536
537   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
538
539   return ret;
540 }
541
542 bool AccessibilityAdaptor::HandleActionZoomEvent()
543 {
544   bool ret = false;
545
546   if( mActionHandler )
547   {
548     ret = mActionHandler->AccessibilityActionZoom();
549   }
550
551   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
552
553   return ret;
554 }
555
556 bool AccessibilityAdaptor::HandleActionReadIndicatorInformationEvent()
557 {
558   bool ret = false;
559
560   if( mActionHandler )
561   {
562     ret = mActionHandler->AccessibilityActionReadIndicatorInformation();
563   }
564
565   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
566
567   return ret;
568 }
569
570 bool AccessibilityAdaptor::HandleActionReadPauseResumeEvent()
571 {
572   bool ret = false;
573
574   if( mActionHandler )
575   {
576     ret = mActionHandler->AccessibilityActionReadPauseResume();
577   }
578
579   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
580
581   return ret;
582 }
583
584 bool AccessibilityAdaptor::HandleActionStartStopEvent()
585 {
586   bool ret = false;
587
588   if( mActionHandler )
589   {
590     ret = mActionHandler->AccessibilityActionStartStop();
591   }
592
593   DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
594
595   return ret;
596 }
597
598 } // namespace Adaptor
599
600 } // namespace Internal
601
602 } // namespace Dali