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(Indicator* indicator)
226 mIndicator = indicator;
229 AccessibilityAdaptor::AccessibilityAdaptor()
231 mActionHandler(NULL),
233 mIndicatorFocused(false)
236 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, isEnabled?"ENABLED":"DISABLED");
247 mAccessibilityGestureDetector = new AccessibilityGestureDetector();
250 AccessibilityAdaptor::~AccessibilityAdaptor()
254 bool AccessibilityAdaptor::HandleActionNextEvent(bool allowEndFeedback)
260 ret = mActionHandler->AccessibilityActionNext(allowEndFeedback);
263 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
268 bool AccessibilityAdaptor::HandleActionPreviousEvent(bool allowEndFeedback)
274 ret = mActionHandler->AccessibilityActionPrevious(allowEndFeedback);
277 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
282 bool AccessibilityAdaptor::HandleActionActivateEvent()
288 ret = mActionHandler->AccessibilityActionActivate();
291 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
296 bool AccessibilityAdaptor::HandleActionReadEvent(unsigned int x, unsigned int y, bool allowReadAgain)
300 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %d , %d\n", __FUNCTION__, __LINE__, x, y);
305 bool indicatorFocused = false;
307 // Check whether the Indicator is focused
308 if( mIndicator && mIndicator->IsConnected() )
310 // Check the position and size of Indicator actor
311 Dali::Actor indicatorActor = mIndicator->GetActor();
312 Vector3 position = Vector3(0.0f, 0.0f, 0.0f);
313 Vector3 size = indicatorActor.GetCurrentSize();
315 if(mReadPosition.x >= position.x &&
316 mReadPosition.x <= position.x + size.width &&
317 mReadPosition.y >= position.y &&
318 mReadPosition.y <= position.y + size.height)
320 indicatorFocused = true;
321 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] Indicator area!!!!\n", __FUNCTION__, __LINE__);
327 if( !mIndicatorFocused && indicatorFocused )
329 // If Indicator is focused, the focus should be cleared in Dali focus chain.
332 mActionHandler->ClearAccessibilityFocus();
336 mIndicatorFocused = indicatorFocused;
338 // Send accessibility READ action information to Indicator
339 if( mIndicatorFocused )
341 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] Send READ message to indicator!!!!\n", __FUNCTION__, __LINE__);
345 if( mActionHandler && !mIndicatorFocused)
347 // If Indicator is not focused, the accessibility actions should be handled by the registered
348 // accessibility action handler (e.g. focus manager)
349 ret = mActionHandler->AccessibilityActionRead( allowReadAgain );
350 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
356 bool AccessibilityAdaptor::HandleActionReadNextEvent(bool allowEndFeedback)
362 ret = mActionHandler->AccessibilityActionReadNext(allowEndFeedback);
365 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
370 bool AccessibilityAdaptor::HandleActionReadPreviousEvent(bool allowEndFeedback)
376 ret = mActionHandler->AccessibilityActionReadPrevious(allowEndFeedback);
379 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
384 bool AccessibilityAdaptor::HandleActionUpEvent()
390 ret = mActionHandler->AccessibilityActionUp();
393 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
398 bool AccessibilityAdaptor::HandleActionDownEvent()
404 ret = mActionHandler->AccessibilityActionDown();
407 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
412 bool AccessibilityAdaptor::HandleActionScrollUpEvent()
418 ret = mActionHandler->AccessibilityActionScrollUp();
421 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
427 bool AccessibilityAdaptor::HandleActionScrollDownEvent()
433 ret = mActionHandler->AccessibilityActionScrollDown();
436 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
441 bool AccessibilityAdaptor::HandleActionPageLeftEvent()
447 ret = mActionHandler->AccessibilityActionPageLeft();
450 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
455 bool AccessibilityAdaptor::HandleActionPageRightEvent()
461 ret = mActionHandler->AccessibilityActionPageRight();
464 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
469 bool AccessibilityAdaptor::HandleActionPageUpEvent()
475 ret = mActionHandler->AccessibilityActionPageUp();
478 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
483 bool AccessibilityAdaptor::HandleActionPageDownEvent()
489 ret = mActionHandler->AccessibilityActionPageDown();
492 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
497 bool AccessibilityAdaptor::HandleActionMoveToFirstEvent()
503 ret = mActionHandler->AccessibilityActionMoveToFirst();
506 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
511 bool AccessibilityAdaptor::HandleActionMoveToLastEvent()
517 ret = mActionHandler->AccessibilityActionMoveToLast();
520 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
525 bool AccessibilityAdaptor::HandleActionReadFromTopEvent()
531 ret = mActionHandler->AccessibilityActionReadFromTop();
534 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
539 bool AccessibilityAdaptor::HandleActionReadFromNextEvent()
545 ret = mActionHandler->AccessibilityActionReadFromNext();
548 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
553 bool AccessibilityAdaptor::HandleActionZoomEvent()
559 ret = mActionHandler->AccessibilityActionZoom();
562 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
567 bool AccessibilityAdaptor::HandleActionReadIndicatorInformationEvent()
573 ret = mActionHandler->AccessibilityActionReadIndicatorInformation();
576 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
581 bool AccessibilityAdaptor::HandleActionReadPauseResumeEvent()
587 ret = mActionHandler->AccessibilityActionReadPauseResume();
590 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
595 bool AccessibilityAdaptor::HandleActionStartStopEvent()
601 ret = mActionHandler->AccessibilityActionStartStop();
604 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
609 } // namespace Adaptor
611 } // namespace Internal