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()
230 : mIsEnabled( false ),
232 mActionHandler( NULL ),
234 mIndicatorFocused( false )
237 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, isEnabled?"ENABLED":"DISABLED");
248 mAccessibilityGestureDetector = new AccessibilityGestureDetector();
251 AccessibilityAdaptor::~AccessibilityAdaptor()
255 bool AccessibilityAdaptor::HandleActionNextEvent(bool allowEndFeedback)
261 ret = mActionHandler->AccessibilityActionNext(allowEndFeedback);
264 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
269 bool AccessibilityAdaptor::HandleActionPreviousEvent(bool allowEndFeedback)
275 ret = mActionHandler->AccessibilityActionPrevious(allowEndFeedback);
278 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
283 bool AccessibilityAdaptor::HandleActionActivateEvent()
289 ret = mActionHandler->AccessibilityActionActivate();
292 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
297 bool AccessibilityAdaptor::HandleActionReadEvent(unsigned int x, unsigned int y, bool allowReadAgain)
301 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %d , %d\n", __FUNCTION__, __LINE__, x, y);
306 bool indicatorFocused = false;
308 // Check whether the Indicator is focused
309 if( mIndicator && mIndicator->IsConnected() )
311 // Check the position and size of Indicator actor
312 Dali::Actor indicatorActor = mIndicator->GetActor();
313 Vector3 position = Vector3(0.0f, 0.0f, 0.0f);
314 Vector3 size = indicatorActor.GetCurrentSize();
316 if(mReadPosition.x >= position.x &&
317 mReadPosition.x <= position.x + size.width &&
318 mReadPosition.y >= position.y &&
319 mReadPosition.y <= position.y + size.height)
321 indicatorFocused = true;
322 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] Indicator area!!!!\n", __FUNCTION__, __LINE__);
328 if( !mIndicatorFocused && indicatorFocused )
330 // If Indicator is focused, the focus should be cleared in Dali focus chain.
333 mActionHandler->ClearAccessibilityFocus();
337 mIndicatorFocused = indicatorFocused;
339 // Send accessibility READ action information to Indicator
340 if( mIndicatorFocused )
342 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] Send READ message to indicator!!!!\n", __FUNCTION__, __LINE__);
346 if( mActionHandler && !mIndicatorFocused)
348 // If Indicator is not focused, the accessibility actions should be handled by the registered
349 // accessibility action handler (e.g. focus manager)
350 ret = mActionHandler->AccessibilityActionRead( allowReadAgain );
351 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
357 bool AccessibilityAdaptor::HandleActionReadNextEvent(bool allowEndFeedback)
363 ret = mActionHandler->AccessibilityActionReadNext(allowEndFeedback);
366 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
371 bool AccessibilityAdaptor::HandleActionReadPreviousEvent(bool allowEndFeedback)
377 ret = mActionHandler->AccessibilityActionReadPrevious(allowEndFeedback);
380 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
385 bool AccessibilityAdaptor::HandleActionUpEvent()
391 ret = mActionHandler->AccessibilityActionUp();
394 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
399 bool AccessibilityAdaptor::HandleActionDownEvent()
405 ret = mActionHandler->AccessibilityActionDown();
408 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
413 bool AccessibilityAdaptor::HandleActionScrollUpEvent()
419 ret = mActionHandler->AccessibilityActionScrollUp();
422 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
428 bool AccessibilityAdaptor::HandleActionScrollDownEvent()
434 ret = mActionHandler->AccessibilityActionScrollDown();
437 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
442 bool AccessibilityAdaptor::HandleActionPageLeftEvent()
448 ret = mActionHandler->AccessibilityActionPageLeft();
451 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
456 bool AccessibilityAdaptor::HandleActionPageRightEvent()
462 ret = mActionHandler->AccessibilityActionPageRight();
465 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
470 bool AccessibilityAdaptor::HandleActionPageUpEvent()
476 ret = mActionHandler->AccessibilityActionPageUp();
479 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
484 bool AccessibilityAdaptor::HandleActionPageDownEvent()
490 ret = mActionHandler->AccessibilityActionPageDown();
493 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
498 bool AccessibilityAdaptor::HandleActionMoveToFirstEvent()
504 ret = mActionHandler->AccessibilityActionMoveToFirst();
507 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
512 bool AccessibilityAdaptor::HandleActionMoveToLastEvent()
518 ret = mActionHandler->AccessibilityActionMoveToLast();
521 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
526 bool AccessibilityAdaptor::HandleActionReadFromTopEvent()
532 ret = mActionHandler->AccessibilityActionReadFromTop();
535 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
540 bool AccessibilityAdaptor::HandleActionReadFromNextEvent()
546 ret = mActionHandler->AccessibilityActionReadFromNext();
549 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
554 bool AccessibilityAdaptor::HandleActionZoomEvent()
560 ret = mActionHandler->AccessibilityActionZoom();
563 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
568 bool AccessibilityAdaptor::HandleActionReadIndicatorInformationEvent()
574 ret = mActionHandler->AccessibilityActionReadIndicatorInformation();
577 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
582 bool AccessibilityAdaptor::HandleActionReadPauseResumeEvent()
588 ret = mActionHandler->AccessibilityActionReadPauseResume();
591 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
596 bool AccessibilityAdaptor::HandleActionStartStopEvent()
602 ret = mActionHandler->AccessibilityActionStartStop();
605 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
610 } // namespace Adaptor
612 } // namespace Internal