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/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( !mActionClearFocusSignalV2.Empty() )
119 mActionClearFocusSignalV2.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 touchEvent(timeStamp);
140 touchEvent.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( !mActionScrollSignalV2.Empty() )
150 mActionScrollSignalV2.Emit( handle, touchEvent );
154 Integration::TouchEvent event;
155 if (mCombiner.GetNextTouchEvent(point, timeStamp, event))
157 // Process the touch event in accessibility gesture detector
158 if( mAccessibilityGestureDetector )
160 mAccessibilityGestureDetector->SendEvent(event);
168 bool AccessibilityManager::HandleActionTouchEvent(const TouchPoint& point, unsigned long timeStamp)
172 Dali::TouchEvent touchEvent(timeStamp);
173 touchEvent.points.push_back(point);
177 ret = mActionHandler->AccessibilityActionTouch(touchEvent);
182 bool AccessibilityManager::HandleActionBackEvent()
186 Dali::AccessibilityManager handle( this );
189 * In order to application decide reading action first,
190 * emit ActionBack signal in first, AccessibilityActionBack for handler in next
192 if ( !mIndicatorFocused )
194 if( !mActionBackSignalV2.Empty() )
196 mActionBackSignalV2.Emit( handle );
202 ret = mActionHandler->AccessibilityActionBack();
205 DALI_LOG_INFO(gAccessibilityManagerLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
210 void AccessibilityManager::HandleActionEnableEvent()
212 EnableAccessibility();
215 void AccessibilityManager::HandleActionDisableEvent()
217 DisableAccessibility();
220 void AccessibilityManager::EnableAccessibility()
222 if(mIsEnabled == false)
228 mActionHandler->ChangeAccessibilityStatus();
231 //emit status changed signal
232 Dali::AccessibilityManager handle( this );
233 mStatusChangedSignalV2.Emit( handle );
237 void AccessibilityManager::DisableAccessibility()
239 if(mIsEnabled == true)
245 mActionHandler->ChangeAccessibilityStatus();
248 //emit status changed signal
249 Dali::AccessibilityManager handle( this );
250 mStatusChangedSignalV2.Emit( handle );
252 // Destroy the TtsPlayer if exists.
253 if ( Adaptor::IsAvailable() )
255 Dali::Adaptor& adaptor = Dali::Adaptor::Get();
256 Adaptor::GetImplementation( adaptor ).DestroyTtsPlayer( Dali::TtsPlayer::SCREEN_READER );
261 bool AccessibilityManager::IsEnabled() const
266 void AccessibilityManager::SetIndicator(Indicator* indicator)
268 mIndicator = indicator;
271 AccessibilityManager::AccessibilityManager()
273 mActionHandler(NULL),
275 mIndicatorFocused(false)
278 DALI_LOG_INFO(gAccessibilityManagerLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, isEnabled?"ENABLED":"DISABLED");
289 mAccessibilityGestureDetector = new AccessibilityGestureDetector();
292 AccessibilityManager::~AccessibilityManager()
296 bool AccessibilityManager::HandleActionNextEvent(bool allowEndFeedback)
299 Dali::AccessibilityManager handle( this );
302 * In order to application decide reading action first,
303 * emit ActionNext signal in first, AccessibilityActionNext for handler in next
305 if( !mIndicatorFocused )
307 if( !mActionNextSignalV2.Empty() )
309 mActionNextSignalV2.Emit( handle );
315 ret = mActionHandler->AccessibilityActionNext(allowEndFeedback);
318 DALI_LOG_INFO(gAccessibilityManagerLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
323 bool AccessibilityManager::HandleActionPreviousEvent(bool allowEndFeedback)
327 Dali::AccessibilityManager handle( this );
330 * In order to application decide reading action first,
331 * emit ActionPrevious signal in first, AccessibilityActionPrevious for handler in next
333 if ( !mIndicatorFocused )
335 if( !mActionPreviousSignalV2.Empty() )
337 mActionPreviousSignalV2.Emit( handle );
343 ret = mActionHandler->AccessibilityActionPrevious(allowEndFeedback);
346 DALI_LOG_INFO(gAccessibilityManagerLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
351 bool AccessibilityManager::HandleActionActivateEvent()
355 Dali::AccessibilityManager handle( this );
358 * In order to application decide reading action first,
359 * emit ActionActivate signal in first, AccessibilityActionActivate for handler in next
361 if ( !mIndicatorFocused )
363 if( !mActionActivateSignalV2.Empty() )
365 mActionActivateSignalV2.Emit( handle );
371 ret = mActionHandler->AccessibilityActionActivate();
374 DALI_LOG_INFO(gAccessibilityManagerLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
379 bool AccessibilityManager::HandleActionReadEvent(unsigned int x, unsigned int y, bool allowReadAgain)
383 DALI_LOG_INFO(gAccessibilityManagerLogFilter, Debug::General, "[%s:%d] %d , %d\n", __FUNCTION__, __LINE__, x, y);
388 Dali::AccessibilityManager handle( this );
390 bool indicatorFocused = false;
392 // Check whether the Indicator is focused
393 if( mIndicator && mIndicator->IsConnected() )
395 // Check the position and size of Indicator actor
396 Dali::Actor indicatorActor = mIndicator->GetActor();
397 Vector3 position = Vector3(0.0f, 0.0f, 0.0f);
398 Vector3 size = indicatorActor.GetCurrentSize();
400 if(mReadPosition.x >= position.x &&
401 mReadPosition.x <= position.x + size.width &&
402 mReadPosition.y >= position.y &&
403 mReadPosition.y <= position.y + size.height)
405 indicatorFocused = true;
406 DALI_LOG_INFO(gAccessibilityManagerLogFilter, Debug::General, "[%s:%d] Indicator area!!!!\n", __FUNCTION__, __LINE__);
412 if( !mIndicatorFocused && indicatorFocused )
414 // If Indicator is focused, the focus should be cleared in Dali focus chain.
417 mActionHandler->ClearAccessibilityFocus();
421 mIndicatorFocused = indicatorFocused;
423 // Send accessibility READ action information to Indicator
424 if( mIndicatorFocused )
426 DALI_LOG_INFO(gAccessibilityManagerLogFilter, Debug::General, "[%s:%d] Send READ message to indicator!!!!\n", __FUNCTION__, __LINE__);
433 * In order to application decide reading action first,
434 * emit ActionRead signal in first, AccessibilityActionRead for handler in next
436 if( !mIndicatorFocused )
438 if ( !mActionReadSignalV2.Empty() )
440 mActionReadSignalV2.Emit( handle );
447 * In order to application decide reading action first,
448 * emit ActionRead signal in first, AccessibilityActionRead for handler in next
450 if( !mIndicatorFocused )
452 if ( !mActionOverSignalV2.Empty() )
454 mActionOverSignalV2.Emit( handle );
459 if( mActionHandler && !mIndicatorFocused)
461 // If Indicator is not focused, the accessibility actions should be handled by the registered
462 // accessibility action handler (e.g. focus manager)
463 ret = mActionHandler->AccessibilityActionRead(allowReadAgain);
464 DALI_LOG_INFO(gAccessibilityManagerLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
470 bool AccessibilityManager::HandleActionReadNextEvent(bool allowEndFeedback)
474 Dali::AccessibilityManager handle( this );
477 * In order to application decide reading action first,
478 * emit ActionReadNext signal in first, AccessibilityActionReadNext for handler in next
480 if ( !mIndicatorFocused )
482 if( !mActionReadNextSignalV2.Empty() )
484 mActionReadNextSignalV2.Emit( handle );
490 ret = mActionHandler->AccessibilityActionReadNext(allowEndFeedback);
493 DALI_LOG_INFO(gAccessibilityManagerLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
498 bool AccessibilityManager::HandleActionReadPreviousEvent(bool allowEndFeedback)
502 Dali::AccessibilityManager handle( this );
505 * In order to application decide reading action first,
506 * emit ActionReadPrevious signal in first, AccessibilityActionReadPrevious for handler in next
508 if ( !mIndicatorFocused )
510 if( !mActionReadPreviousSignalV2.Empty() )
512 mActionReadPreviousSignalV2.Emit( handle );
518 ret = mActionHandler->AccessibilityActionReadPrevious(allowEndFeedback);
521 DALI_LOG_INFO(gAccessibilityManagerLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
526 bool AccessibilityManager::HandleActionUpEvent()
530 Dali::AccessibilityManager handle( this );
533 * In order to application decide reading action first,
534 * emit ActionUp signal in first, AccessibilityActionUp for handler in next
536 if ( !mIndicatorFocused )
538 if( !mActionUpSignalV2.Empty() )
540 mActionUpSignalV2.Emit( handle );
546 ret = mActionHandler->AccessibilityActionUp();
549 DALI_LOG_INFO(gAccessibilityManagerLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
554 bool AccessibilityManager::HandleActionDownEvent()
558 Dali::AccessibilityManager handle( this );
561 * In order to application decide reading action first,
562 * emit ActionDown signal in first, AccessibilityActionDown for handler in next
564 if ( !mIndicatorFocused )
566 if( !mActionDownSignalV2.Empty() )
568 mActionDownSignalV2.Emit( handle );
574 ret = mActionHandler->AccessibilityActionDown();
577 DALI_LOG_INFO(gAccessibilityManagerLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
582 } // namespace Adaptor
584 } // namespace Internal