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-adaptor-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* gAccessibilityAdaptorLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_ACCESSIBILITY_ADAPTOR");
49 BaseHandle handle( AccessibilityAdaptor::Get() );
53 Dali::SingletonService service( SingletonService::Get() );
56 Dali::AccessibilityAdaptor adaptor = Dali::AccessibilityAdaptor( new AccessibilityAdaptor() );
57 service.Register( typeid( adaptor ), adaptor );
64 TypeRegistration ACCESSIBILITY_ADAPTOR_TYPE( typeid(Dali::AccessibilityAdaptor), typeid(Dali::BaseHandle), Create, true /* Create Instance At Startup */ );
66 } // unnamed namespace
68 Dali::AccessibilityAdaptor AccessibilityAdaptor::Get()
70 Dali::AccessibilityAdaptor adaptor;
72 Dali::SingletonService service( SingletonService::Get() );
75 // Check whether the singleton is already created
76 Dali::BaseHandle handle = service.GetSingleton( typeid( Dali::AccessibilityAdaptor ) );
79 // If so, downcast the handle
80 adaptor = Dali::AccessibilityAdaptor( dynamic_cast< AccessibilityAdaptor* >( handle.GetObjectPtr() ) );
87 Vector2 AccessibilityAdaptor::GetReadPosition() const
92 void AccessibilityAdaptor::SetActionHandler(AccessibilityActionHandler& handler)
94 mActionHandler = &handler;
97 void AccessibilityAdaptor::SetGestureHandler(AccessibilityGestureHandler& handler)
99 if( mAccessibilityGestureDetector )
101 mAccessibilityGestureDetector->SetGestureHandler(handler);
105 bool AccessibilityAdaptor::HandleActionClearFocusEvent()
111 ret = mActionHandler->ClearAccessibilityFocus();
114 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
119 bool AccessibilityAdaptor::HandleActionScrollEvent(const TouchPoint& point, unsigned long timeStamp)
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.
127 Dali::TouchEvent event(timeStamp);
128 event.points.push_back(point);
129 ret = mActionHandler->AccessibilityActionScroll( event );
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
137 // Process the touch event in accessibility gesture detector
138 if( mAccessibilityGestureDetector )
140 mAccessibilityGestureDetector->SendEvent( touchEvent );
148 bool AccessibilityAdaptor::HandleActionTouchEvent(const TouchPoint& point, unsigned long timeStamp)
152 Dali::TouchEvent touchEvent(timeStamp);
153 touchEvent.points.push_back(point);
157 ret = mActionHandler->AccessibilityActionTouch(touchEvent);
162 bool AccessibilityAdaptor::HandleActionBackEvent()
168 ret = mActionHandler->AccessibilityActionBack();
171 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
176 void AccessibilityAdaptor::HandleActionEnableEvent()
178 EnableAccessibility();
181 void AccessibilityAdaptor::HandleActionDisableEvent()
183 DisableAccessibility();
186 void AccessibilityAdaptor::EnableAccessibility()
188 if(mIsEnabled == false)
194 mActionHandler->ChangeAccessibilityStatus();
199 void AccessibilityAdaptor::DisableAccessibility()
201 if(mIsEnabled == true)
207 mActionHandler->ChangeAccessibilityStatus();
210 // Destroy the TtsPlayer if exists.
211 if ( Adaptor::IsAvailable() )
213 Dali::Adaptor& adaptor = Dali::Adaptor::Get();
214 Adaptor::GetImplementation( adaptor ).DestroyTtsPlayer( Dali::TtsPlayer::SCREEN_READER );
219 bool AccessibilityAdaptor::IsEnabled() const
224 void AccessibilityAdaptor::SetIndicator(IndicatorInterface* indicator)
226 mIndicator = indicator;
229 AccessibilityAdaptor::AccessibilityAdaptor()
230 : mIsEnabled( false ),
232 mActionHandler( NULL ),
234 mIndicatorFocused( false )
236 mAccessibilityGestureDetector = new AccessibilityGestureDetector();
239 AccessibilityAdaptor::~AccessibilityAdaptor()
243 bool AccessibilityAdaptor::HandleActionNextEvent(bool allowEndFeedback)
249 ret = mActionHandler->AccessibilityActionNext(allowEndFeedback);
252 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
257 bool AccessibilityAdaptor::HandleActionPreviousEvent(bool allowEndFeedback)
263 ret = mActionHandler->AccessibilityActionPrevious(allowEndFeedback);
266 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
271 bool AccessibilityAdaptor::HandleActionActivateEvent()
277 ret = mActionHandler->AccessibilityActionActivate();
280 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
285 bool AccessibilityAdaptor::HandleActionReadEvent(unsigned int x, unsigned int y, bool allowReadAgain)
289 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %d , %d\n", __FUNCTION__, __LINE__, x, y);
294 bool indicatorFocused = false;
296 // Check whether the Indicator is focused
297 if( mIndicator && mIndicator->IsConnected() )
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();
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)
309 indicatorFocused = true;
310 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] Indicator area!!!!\n", __FUNCTION__, __LINE__);
316 if( !mIndicatorFocused && indicatorFocused )
318 // If Indicator is focused, the focus should be cleared in Dali focus chain.
321 mActionHandler->ClearAccessibilityFocus();
325 mIndicatorFocused = indicatorFocused;
327 // Send accessibility READ action information to Indicator
328 if( mIndicatorFocused )
330 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] Send READ message to indicator!!!!\n", __FUNCTION__, __LINE__);
334 if( mActionHandler && !mIndicatorFocused)
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");
345 bool AccessibilityAdaptor::HandleActionReadNextEvent(bool allowEndFeedback)
351 ret = mActionHandler->AccessibilityActionReadNext(allowEndFeedback);
354 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
359 bool AccessibilityAdaptor::HandleActionReadPreviousEvent(bool allowEndFeedback)
365 ret = mActionHandler->AccessibilityActionReadPrevious(allowEndFeedback);
368 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
373 bool AccessibilityAdaptor::HandleActionUpEvent()
379 ret = mActionHandler->AccessibilityActionUp();
382 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
387 bool AccessibilityAdaptor::HandleActionDownEvent()
393 ret = mActionHandler->AccessibilityActionDown();
396 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
401 bool AccessibilityAdaptor::HandleActionScrollUpEvent()
407 ret = mActionHandler->AccessibilityActionScrollUp();
410 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
416 bool AccessibilityAdaptor::HandleActionScrollDownEvent()
422 ret = mActionHandler->AccessibilityActionScrollDown();
425 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
430 bool AccessibilityAdaptor::HandleActionPageLeftEvent()
436 ret = mActionHandler->AccessibilityActionPageLeft();
439 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
444 bool AccessibilityAdaptor::HandleActionPageRightEvent()
450 ret = mActionHandler->AccessibilityActionPageRight();
453 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
458 bool AccessibilityAdaptor::HandleActionPageUpEvent()
464 ret = mActionHandler->AccessibilityActionPageUp();
467 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
472 bool AccessibilityAdaptor::HandleActionPageDownEvent()
478 ret = mActionHandler->AccessibilityActionPageDown();
481 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
486 bool AccessibilityAdaptor::HandleActionMoveToFirstEvent()
492 ret = mActionHandler->AccessibilityActionMoveToFirst();
495 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
500 bool AccessibilityAdaptor::HandleActionMoveToLastEvent()
506 ret = mActionHandler->AccessibilityActionMoveToLast();
509 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
514 bool AccessibilityAdaptor::HandleActionReadFromTopEvent()
520 ret = mActionHandler->AccessibilityActionReadFromTop();
523 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
528 bool AccessibilityAdaptor::HandleActionReadFromNextEvent()
534 ret = mActionHandler->AccessibilityActionReadFromNext();
537 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
542 bool AccessibilityAdaptor::HandleActionZoomEvent()
548 ret = mActionHandler->AccessibilityActionZoom();
551 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
556 bool AccessibilityAdaptor::HandleActionReadIndicatorInformationEvent()
562 ret = mActionHandler->AccessibilityActionReadIndicatorInformation();
565 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
570 bool AccessibilityAdaptor::HandleActionReadPauseResumeEvent()
576 ret = mActionHandler->AccessibilityActionReadPauseResume();
579 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
584 bool AccessibilityAdaptor::HandleActionStartStopEvent()
590 ret = mActionHandler->AccessibilityActionStartStop();
593 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
598 } // namespace Adaptor
600 } // namespace Internal