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"
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>
29 #include <singleton-service-impl.h>
30 #include "system-settings.h"
43 #if defined(DEBUG_ENABLED)
44 Debug::Filter* gAccessibilityManagerLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_ACCESSIBILITY_MANAGER");
49 BaseHandle handle( AccessibilityManager::Get() );
53 Dali::SingletonService service( SingletonService::Get() );
56 Dali::AccessibilityManager manager = Dali::AccessibilityManager( new AccessibilityManager() );
57 service.Register( typeid( manager ), manager );
64 TypeRegistration ACCESSIBILITY_MANAGER_TYPE( typeid(Dali::AccessibilityManager), typeid(Dali::BaseHandle), Create, true /* Create Instance At Startup */ );
66 } // unnamed namespace
68 Dali::AccessibilityManager AccessibilityManager::Get()
70 Dali::AccessibilityManager manager;
72 Dali::SingletonService service( SingletonService::Get() );
75 // Check whether the singleton is already created
76 Dali::BaseHandle handle = service.GetSingleton( typeid( Dali::AccessibilityManager ) );
79 // If so, downcast the handle
80 manager = Dali::AccessibilityManager( dynamic_cast< AccessibilityManager* >( handle.GetObjectPtr() ) );
87 Vector2 AccessibilityManager::GetReadPosition() const
92 void AccessibilityManager::SetActionHandler(AccessibilityActionHandler& handler)
94 mActionHandler = &handler;
97 void AccessibilityManager::SetGestureHandler(AccessibilityGestureHandler& handler)
99 if( mAccessibilityGestureDetector )
101 mAccessibilityGestureDetector->SetGestureHandler(handler);
105 bool AccessibilityManager::HandleActionClearFocusEvent()
109 Dali::AccessibilityManager handle( this );
112 * In order to application decide reading action first,
113 * emit ActionClearFocus signal in first, ClearAccessibilityFocus for handler in next
115 if ( !mIndicatorFocused )
117 if( !mActionClearFocusSignal.Empty() )
119 mActionClearFocusSignal.Emit( handle );
125 ret = mActionHandler->ClearAccessibilityFocus();
128 DALI_LOG_INFO(gAccessibilityManagerLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
133 bool AccessibilityManager::HandleActionScrollEvent(const TouchPoint& point, unsigned long timeStamp)
137 Dali::AccessibilityManager handle( this );
139 Dali::TouchEvent event(timeStamp);
140 event.points.push_back(point);
143 * In order to application decide touch action first,
144 * emit ActionScroll signal in first, AccessibilityActionScroll for handler in next
146 if ( !mIndicatorFocused )
148 if( !mActionScrollSignal.Empty() )
150 mActionScrollSignal.Emit( handle, event );
154 Integration::TouchEvent touchEvent;
155 Integration::HoverEvent hoverEvent;
156 Integration::TouchEventCombiner::EventDispatchType type = mCombiner.GetNextTouchEvent(point, timeStamp, touchEvent, hoverEvent);
157 if(type == Integration::TouchEventCombiner::DispatchTouch || type == Integration::TouchEventCombiner::DispatchBoth) // hover event is ignored
159 // Process the touch event in accessibility gesture detector
160 if( mAccessibilityGestureDetector )
162 mAccessibilityGestureDetector->SendEvent(touchEvent);
170 bool AccessibilityManager::HandleActionTouchEvent(const TouchPoint& point, unsigned long timeStamp)
174 Dali::TouchEvent touchEvent(timeStamp);
175 touchEvent.points.push_back(point);
179 ret = mActionHandler->AccessibilityActionTouch(touchEvent);
184 bool AccessibilityManager::HandleActionBackEvent()
188 Dali::AccessibilityManager handle( this );
191 * In order to application decide reading action first,
192 * emit ActionBack signal in first, AccessibilityActionBack for handler in next
194 if ( !mIndicatorFocused )
196 if( !mActionBackSignal.Empty() )
198 mActionBackSignal.Emit( handle );
204 ret = mActionHandler->AccessibilityActionBack();
207 DALI_LOG_INFO(gAccessibilityManagerLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
212 void AccessibilityManager::HandleActionEnableEvent()
214 EnableAccessibility();
217 void AccessibilityManager::HandleActionDisableEvent()
219 DisableAccessibility();
222 void AccessibilityManager::EnableAccessibility()
224 if(mIsEnabled == false)
230 mActionHandler->ChangeAccessibilityStatus();
233 //emit status changed signal
234 Dali::AccessibilityManager handle( this );
235 mStatusChangedSignal.Emit( handle );
239 void AccessibilityManager::DisableAccessibility()
241 if(mIsEnabled == true)
247 mActionHandler->ChangeAccessibilityStatus();
250 //emit status changed signal
251 Dali::AccessibilityManager handle( this );
252 mStatusChangedSignal.Emit( handle );
254 // Destroy the TtsPlayer if exists.
255 if ( Adaptor::IsAvailable() )
257 Dali::Adaptor& adaptor = Dali::Adaptor::Get();
258 Adaptor::GetImplementation( adaptor ).DestroyTtsPlayer( Dali::TtsPlayer::SCREEN_READER );
263 bool AccessibilityManager::IsEnabled() const
268 void AccessibilityManager::SetIndicator(Indicator* indicator)
270 mIndicator = indicator;
273 AccessibilityManager::AccessibilityManager()
275 mActionHandler(NULL),
277 mIndicatorFocused(false)
280 DALI_LOG_INFO(gAccessibilityManagerLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, isEnabled?"ENABLED":"DISABLED");
291 mAccessibilityGestureDetector = new AccessibilityGestureDetector();
294 AccessibilityManager::~AccessibilityManager()
298 bool AccessibilityManager::HandleActionNextEvent(bool allowEndFeedback)
301 Dali::AccessibilityManager handle( this );
304 * In order to application decide reading action first,
305 * emit ActionNext signal in first, AccessibilityActionNext for handler in next
307 if( !mIndicatorFocused )
309 if( !mActionNextSignal.Empty() )
311 mActionNextSignal.Emit( handle );
317 ret = mActionHandler->AccessibilityActionNext(allowEndFeedback);
320 DALI_LOG_INFO(gAccessibilityManagerLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
325 bool AccessibilityManager::HandleActionPreviousEvent(bool allowEndFeedback)
329 Dali::AccessibilityManager handle( this );
332 * In order to application decide reading action first,
333 * emit ActionPrevious signal in first, AccessibilityActionPrevious for handler in next
335 if ( !mIndicatorFocused )
337 if( !mActionPreviousSignal.Empty() )
339 mActionPreviousSignal.Emit( handle );
345 ret = mActionHandler->AccessibilityActionPrevious(allowEndFeedback);
348 DALI_LOG_INFO(gAccessibilityManagerLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
353 bool AccessibilityManager::HandleActionActivateEvent()
357 Dali::AccessibilityManager handle( this );
360 * In order to application decide reading action first,
361 * emit ActionActivate signal in first, AccessibilityActionActivate for handler in next
363 if ( !mIndicatorFocused )
365 if( !mActionActivateSignal.Empty() )
367 mActionActivateSignal.Emit( handle );
373 ret = mActionHandler->AccessibilityActionActivate();
376 DALI_LOG_INFO(gAccessibilityManagerLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
381 bool AccessibilityManager::HandleActionReadEvent(unsigned int x, unsigned int y, bool allowReadAgain)
385 DALI_LOG_INFO(gAccessibilityManagerLogFilter, Debug::General, "[%s:%d] %d , %d\n", __FUNCTION__, __LINE__, x, y);
390 Dali::AccessibilityManager handle( this );
392 bool indicatorFocused = false;
394 // Check whether the Indicator is focused
395 if( mIndicator && mIndicator->IsConnected() )
397 // Check the position and size of Indicator actor
398 Dali::Actor indicatorActor = mIndicator->GetActor();
399 Vector3 position = Vector3(0.0f, 0.0f, 0.0f);
400 Vector3 size = indicatorActor.GetCurrentSize();
402 if(mReadPosition.x >= position.x &&
403 mReadPosition.x <= position.x + size.width &&
404 mReadPosition.y >= position.y &&
405 mReadPosition.y <= position.y + size.height)
407 indicatorFocused = true;
408 DALI_LOG_INFO(gAccessibilityManagerLogFilter, Debug::General, "[%s:%d] Indicator area!!!!\n", __FUNCTION__, __LINE__);
414 if( !mIndicatorFocused && indicatorFocused )
416 // If Indicator is focused, the focus should be cleared in Dali focus chain.
419 mActionHandler->ClearAccessibilityFocus();
423 mIndicatorFocused = indicatorFocused;
425 // Send accessibility READ action information to Indicator
426 if( mIndicatorFocused )
428 DALI_LOG_INFO(gAccessibilityManagerLogFilter, Debug::General, "[%s:%d] Send READ message to indicator!!!!\n", __FUNCTION__, __LINE__);
435 * In order to application decide reading action first,
436 * emit ActionRead signal in first, AccessibilityActionRead for handler in next
438 if( !mIndicatorFocused )
440 if ( !mActionReadSignal.Empty() )
442 mActionReadSignal.Emit( handle );
449 * In order to application decide reading action first,
450 * emit ActionRead signal in first, AccessibilityActionRead for handler in next
452 if( !mIndicatorFocused )
454 if ( !mActionOverSignal.Empty() )
456 mActionOverSignal.Emit( handle );
461 if( mActionHandler && !mIndicatorFocused)
463 // If Indicator is not focused, the accessibility actions should be handled by the registered
464 // accessibility action handler (e.g. focus manager)
465 ret = mActionHandler->AccessibilityActionRead(allowReadAgain);
466 DALI_LOG_INFO(gAccessibilityManagerLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
472 bool AccessibilityManager::HandleActionReadNextEvent(bool allowEndFeedback)
476 Dali::AccessibilityManager handle( this );
479 * In order to application decide reading action first,
480 * emit ActionReadNext signal in first, AccessibilityActionReadNext for handler in next
482 if ( !mIndicatorFocused )
484 if( !mActionReadNextSignal.Empty() )
486 mActionReadNextSignal.Emit( handle );
492 ret = mActionHandler->AccessibilityActionReadNext(allowEndFeedback);
495 DALI_LOG_INFO(gAccessibilityManagerLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
500 bool AccessibilityManager::HandleActionReadPreviousEvent(bool allowEndFeedback)
504 Dali::AccessibilityManager handle( this );
507 * In order to application decide reading action first,
508 * emit ActionReadPrevious signal in first, AccessibilityActionReadPrevious for handler in next
510 if ( !mIndicatorFocused )
512 if( !mActionReadPreviousSignal.Empty() )
514 mActionReadPreviousSignal.Emit( handle );
520 ret = mActionHandler->AccessibilityActionReadPrevious(allowEndFeedback);
523 DALI_LOG_INFO(gAccessibilityManagerLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
528 bool AccessibilityManager::HandleActionUpEvent()
532 Dali::AccessibilityManager handle( this );
535 * In order to application decide reading action first,
536 * emit ActionUp signal in first, AccessibilityActionUp for handler in next
538 if ( !mIndicatorFocused )
540 if( !mActionUpSignal.Empty() )
542 mActionUpSignal.Emit( handle );
548 ret = mActionHandler->AccessibilityActionUp();
551 DALI_LOG_INFO(gAccessibilityManagerLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
556 bool AccessibilityManager::HandleActionDownEvent()
560 Dali::AccessibilityManager handle( this );
563 * In order to application decide reading action first,
564 * emit ActionDown signal in first, AccessibilityActionDown for handler in next
566 if ( !mIndicatorFocused )
568 if( !mActionDownSignal.Empty() )
570 mActionDownSignal.Emit( handle );
576 ret = mActionHandler->AccessibilityActionDown();
579 DALI_LOG_INFO(gAccessibilityManagerLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
584 } // namespace Adaptor
586 } // namespace Internal