2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include "accessibility-manager-impl.h"
23 #include <dali/public-api/dali-core.h>
24 #include <dali/integration-api/debug.h>
25 #include <dali/integration-api/events/touch-event-integ.h>
26 #include <dali/integration-api/events/hover-event-integ.h>
27 #include <dali/integration-api/events/gesture-requests.h>
30 #include <singleton-service-impl.h>
31 #include "system-settings.h"
44 #if defined(DEBUG_ENABLED)
45 Debug::Filter* gAccessibilityManagerLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_ACCESSIBILITY_MANAGER");
50 BaseHandle handle( AccessibilityManager::Get() );
54 Dali::SingletonService service( SingletonService::Get() );
57 Dali::AccessibilityManager manager = Dali::AccessibilityManager( new AccessibilityManager() );
58 service.Register( typeid( manager ), manager );
65 TypeRegistration ACCESSIBILITY_MANAGER_TYPE( typeid(Dali::AccessibilityManager), typeid(Dali::BaseHandle), Create, true /* Create Instance At Startup */ );
67 } // unnamed namespace
69 Dali::AccessibilityManager AccessibilityManager::Get()
71 Dali::AccessibilityManager manager;
73 Dali::SingletonService service( SingletonService::Get() );
76 // Check whether the singleton is already created
77 Dali::BaseHandle handle = service.GetSingleton( typeid( Dali::AccessibilityManager ) );
80 // If so, downcast the handle
81 manager = Dali::AccessibilityManager( dynamic_cast< AccessibilityManager* >( handle.GetObjectPtr() ) );
88 Vector2 AccessibilityManager::GetReadPosition() const
93 void AccessibilityManager::SetActionHandler(AccessibilityActionHandler& handler)
95 mActionHandler = &handler;
98 void AccessibilityManager::SetGestureHandler(AccessibilityGestureHandler& handler)
100 if( mAccessibilityGestureDetector )
102 mAccessibilityGestureDetector->SetGestureHandler(handler);
106 bool AccessibilityManager::HandleActionClearFocusEvent()
110 Dali::AccessibilityManager handle( this );
113 * In order to application decide reading action first,
114 * emit ActionClearFocus signal in first, ClearAccessibilityFocus for handler in next
116 if ( !mIndicatorFocused )
118 if( !mActionClearFocusSignalV2.Empty() )
120 mActionClearFocusSignalV2.Emit( handle );
126 ret = mActionHandler->ClearAccessibilityFocus();
129 DALI_LOG_INFO(gAccessibilityManagerLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
134 bool AccessibilityManager::HandleActionScrollEvent(const TouchPoint& point, unsigned long timeStamp)
138 Dali::AccessibilityManager handle( this );
140 Dali::TouchEvent event(timeStamp);
141 event.points.push_back(point);
144 * In order to application decide touch action first,
145 * emit ActionScroll signal in first, AccessibilityActionScroll for handler in next
147 if ( !mIndicatorFocused )
149 if( !mActionScrollSignalV2.Empty() )
151 mActionScrollSignalV2.Emit( handle, event );
155 Integration::TouchEvent touchEvent;
156 Integration::HoverEvent hoverEvent;
157 Integration::TouchEventCombiner::EventDispatchType type = mCombiner.GetNextTouchEvent(point, timeStamp, touchEvent, hoverEvent);
158 if(type == Integration::TouchEventCombiner::DispatchTouch || type == Integration::TouchEventCombiner::DispatchBoth) // hover event is ignored
160 // Process the touch event in accessibility gesture detector
161 if( mAccessibilityGestureDetector )
163 mAccessibilityGestureDetector->SendEvent(touchEvent);
171 bool AccessibilityManager::HandleActionTouchEvent(const TouchPoint& point, unsigned long timeStamp)
175 Dali::TouchEvent touchEvent(timeStamp);
176 touchEvent.points.push_back(point);
180 ret = mActionHandler->AccessibilityActionTouch(touchEvent);
185 bool AccessibilityManager::HandleActionBackEvent()
189 Dali::AccessibilityManager handle( this );
192 * In order to application decide reading action first,
193 * emit ActionBack signal in first, AccessibilityActionBack for handler in next
195 if ( !mIndicatorFocused )
197 if( !mActionBackSignalV2.Empty() )
199 mActionBackSignalV2.Emit( handle );
205 ret = mActionHandler->AccessibilityActionBack();
208 DALI_LOG_INFO(gAccessibilityManagerLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
213 void AccessibilityManager::HandleActionEnableEvent()
215 EnableAccessibility();
218 void AccessibilityManager::HandleActionDisableEvent()
220 DisableAccessibility();
223 void AccessibilityManager::EnableAccessibility()
225 if(mIsEnabled == false)
231 mActionHandler->ChangeAccessibilityStatus();
234 //emit status changed signal
235 Dali::AccessibilityManager handle( this );
236 mStatusChangedSignalV2.Emit( handle );
240 void AccessibilityManager::DisableAccessibility()
242 if(mIsEnabled == true)
248 mActionHandler->ChangeAccessibilityStatus();
251 //emit status changed signal
252 Dali::AccessibilityManager handle( this );
253 mStatusChangedSignalV2.Emit( handle );
255 // Destroy the TtsPlayer if exists.
256 if ( Adaptor::IsAvailable() )
258 Dali::Adaptor& adaptor = Dali::Adaptor::Get();
259 Adaptor::GetImplementation( adaptor ).DestroyTtsPlayer( Dali::TtsPlayer::SCREEN_READER );
264 bool AccessibilityManager::IsEnabled() const
269 void AccessibilityManager::SetIndicator(Indicator* indicator)
271 mIndicator = indicator;
274 AccessibilityManager::AccessibilityManager()
276 mActionHandler(NULL),
278 mIndicatorFocused(false)
281 DALI_LOG_INFO(gAccessibilityManagerLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, isEnabled?"ENABLED":"DISABLED");
292 mAccessibilityGestureDetector = new AccessibilityGestureDetector();
295 AccessibilityManager::~AccessibilityManager()
299 bool AccessibilityManager::HandleActionNextEvent(bool allowEndFeedback)
302 Dali::AccessibilityManager handle( this );
305 * In order to application decide reading action first,
306 * emit ActionNext signal in first, AccessibilityActionNext for handler in next
308 if( !mIndicatorFocused )
310 if( !mActionNextSignalV2.Empty() )
312 mActionNextSignalV2.Emit( handle );
318 ret = mActionHandler->AccessibilityActionNext(allowEndFeedback);
321 DALI_LOG_INFO(gAccessibilityManagerLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
326 bool AccessibilityManager::HandleActionPreviousEvent(bool allowEndFeedback)
330 Dali::AccessibilityManager handle( this );
333 * In order to application decide reading action first,
334 * emit ActionPrevious signal in first, AccessibilityActionPrevious for handler in next
336 if ( !mIndicatorFocused )
338 if( !mActionPreviousSignalV2.Empty() )
340 mActionPreviousSignalV2.Emit( handle );
346 ret = mActionHandler->AccessibilityActionPrevious(allowEndFeedback);
349 DALI_LOG_INFO(gAccessibilityManagerLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
354 bool AccessibilityManager::HandleActionActivateEvent()
358 Dali::AccessibilityManager handle( this );
361 * In order to application decide reading action first,
362 * emit ActionActivate signal in first, AccessibilityActionActivate for handler in next
364 if ( !mIndicatorFocused )
366 if( !mActionActivateSignalV2.Empty() )
368 mActionActivateSignalV2.Emit( handle );
374 ret = mActionHandler->AccessibilityActionActivate();
377 DALI_LOG_INFO(gAccessibilityManagerLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
382 bool AccessibilityManager::HandleActionReadEvent(unsigned int x, unsigned int y, bool allowReadAgain)
386 DALI_LOG_INFO(gAccessibilityManagerLogFilter, Debug::General, "[%s:%d] %d , %d\n", __FUNCTION__, __LINE__, x, y);
391 Dali::AccessibilityManager handle( this );
393 bool indicatorFocused = false;
395 // Check whether the Indicator is focused
396 if( mIndicator && mIndicator->IsConnected() )
398 // Check the position and size of Indicator actor
399 Dali::Actor indicatorActor = mIndicator->GetActor();
400 Vector3 position = Vector3(0.0f, 0.0f, 0.0f);
401 Vector3 size = indicatorActor.GetCurrentSize();
403 if(mReadPosition.x >= position.x &&
404 mReadPosition.x <= position.x + size.width &&
405 mReadPosition.y >= position.y &&
406 mReadPosition.y <= position.y + size.height)
408 indicatorFocused = true;
409 DALI_LOG_INFO(gAccessibilityManagerLogFilter, Debug::General, "[%s:%d] Indicator area!!!!\n", __FUNCTION__, __LINE__);
415 if( !mIndicatorFocused && indicatorFocused )
417 // If Indicator is focused, the focus should be cleared in Dali focus chain.
420 mActionHandler->ClearAccessibilityFocus();
424 mIndicatorFocused = indicatorFocused;
426 // Send accessibility READ action information to Indicator
427 if( mIndicatorFocused )
429 DALI_LOG_INFO(gAccessibilityManagerLogFilter, Debug::General, "[%s:%d] Send READ message to indicator!!!!\n", __FUNCTION__, __LINE__);
436 * In order to application decide reading action first,
437 * emit ActionRead signal in first, AccessibilityActionRead for handler in next
439 if( !mIndicatorFocused )
441 if ( !mActionReadSignalV2.Empty() )
443 mActionReadSignalV2.Emit( handle );
450 * In order to application decide reading action first,
451 * emit ActionRead signal in first, AccessibilityActionRead for handler in next
453 if( !mIndicatorFocused )
455 if ( !mActionOverSignalV2.Empty() )
457 mActionOverSignalV2.Emit( handle );
462 if( mActionHandler && !mIndicatorFocused)
464 // If Indicator is not focused, the accessibility actions should be handled by the registered
465 // accessibility action handler (e.g. focus manager)
466 ret = mActionHandler->AccessibilityActionRead(allowReadAgain);
467 DALI_LOG_INFO(gAccessibilityManagerLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
473 bool AccessibilityManager::HandleActionReadNextEvent(bool allowEndFeedback)
477 Dali::AccessibilityManager handle( this );
480 * In order to application decide reading action first,
481 * emit ActionReadNext signal in first, AccessibilityActionReadNext for handler in next
483 if ( !mIndicatorFocused )
485 if( !mActionReadNextSignalV2.Empty() )
487 mActionReadNextSignalV2.Emit( handle );
493 ret = mActionHandler->AccessibilityActionReadNext(allowEndFeedback);
496 DALI_LOG_INFO(gAccessibilityManagerLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
501 bool AccessibilityManager::HandleActionReadPreviousEvent(bool allowEndFeedback)
505 Dali::AccessibilityManager handle( this );
508 * In order to application decide reading action first,
509 * emit ActionReadPrevious signal in first, AccessibilityActionReadPrevious for handler in next
511 if ( !mIndicatorFocused )
513 if( !mActionReadPreviousSignalV2.Empty() )
515 mActionReadPreviousSignalV2.Emit( handle );
521 ret = mActionHandler->AccessibilityActionReadPrevious(allowEndFeedback);
524 DALI_LOG_INFO(gAccessibilityManagerLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
529 bool AccessibilityManager::HandleActionUpEvent()
533 Dali::AccessibilityManager handle( this );
536 * In order to application decide reading action first,
537 * emit ActionUp signal in first, AccessibilityActionUp for handler in next
539 if ( !mIndicatorFocused )
541 if( !mActionUpSignalV2.Empty() )
543 mActionUpSignalV2.Emit( handle );
549 ret = mActionHandler->AccessibilityActionUp();
552 DALI_LOG_INFO(gAccessibilityManagerLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
557 bool AccessibilityManager::HandleActionDownEvent()
561 Dali::AccessibilityManager handle( this );
564 * In order to application decide reading action first,
565 * emit ActionDown signal in first, AccessibilityActionDown for handler in next
567 if ( !mIndicatorFocused )
569 if( !mActionDownSignalV2.Empty() )
571 mActionDownSignalV2.Emit( handle );
577 ret = mActionHandler->AccessibilityActionDown();
580 DALI_LOG_INFO(gAccessibilityManagerLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
585 } // namespace Adaptor
587 } // namespace Internal