2 * Copyright (c) 2020 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 <dali/internal/accessibility/common/accessibility-adaptor-impl.h>
22 #include <system_settings.h>
23 #include <dali/public-api/object/type-registry.h>
24 #include <dali/integration-api/debug.h>
25 #include <dali/integration-api/events/touch-event-integ.h>
26 #include <dali/integration-api/events/touch-integ.h>
27 #include <dali/integration-api/events/hover-event-integ.h>
30 #include <dali/internal/adaptor/common/adaptor-impl.h>
31 #include <dali/internal/system/common/system-settings.h>
42 namespace // unnamed namespace
45 #if defined(DEBUG_ENABLED)
46 Debug::Filter* gAccessibilityAdaptorLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_ACCESSIBILITY_ADAPTOR");
49 } // unnamed namespace
51 AccessibilityAdaptor::AccessibilityAdaptor()
53 mFocusedActorPosition(),
54 mActionHandler( NULL ),
58 mAccessibilityGestureDetector = new AccessibilityGestureDetector();
61 void AccessibilityAdaptor::EnableAccessibility()
63 bool accessibilityState = false;
64 system_settings_get_value_bool( SYSTEM_SETTINGS_KEY_ACCESSIBILITY_TTS, &accessibilityState );
65 if(accessibilityState == false)
67 DALI_LOG_ERROR("The Current Accessibility system cannot run. \n");
71 if(mIsEnabled == false)
77 mActionHandler->ChangeAccessibilityStatus();
82 void AccessibilityAdaptor::DisableAccessibility()
84 if(mIsEnabled == true)
90 mActionHandler->ChangeAccessibilityStatus();
93 // Destroy the TtsPlayer if exists.
94 if ( Adaptor::IsAvailable() )
96 Dali::Adaptor& adaptor = Dali::Adaptor::Get();
97 Adaptor& adaptorImpl = Adaptor::GetImplementation( adaptor );
98 adaptorImpl.DestroyTtsPlayer( Dali::TtsPlayer::SCREEN_READER );
103 bool AccessibilityAdaptor::IsEnabled() const
108 void AccessibilityAdaptor::SetForcedEnable( bool forced )
113 bool AccessibilityAdaptor::IsForcedEnable() const
118 Vector2 AccessibilityAdaptor::GetReadPosition() const
120 return mReadPosition;
123 void AccessibilityAdaptor::SetActionHandler(AccessibilityActionHandler& handler)
125 mActionHandler = &handler;
128 void AccessibilityAdaptor::SetGestureHandler(AccessibilityGestureHandler& handler)
130 if( mAccessibilityGestureDetector )
132 mAccessibilityGestureDetector->SetGestureHandler(handler);
136 void AccessibilityAdaptor::SetFocusedActorPosition(Vector2 currentPosition)
138 mFocusedActorPosition = currentPosition;
141 Vector2 AccessibilityAdaptor::GetFocusedActorPosition() const
143 return mFocusedActorPosition;
146 bool AccessibilityAdaptor::HandleActionNextEvent(bool allowEndFeedback)
152 ret = mActionHandler->AccessibilityActionNext(allowEndFeedback);
155 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
160 bool AccessibilityAdaptor::HandleActionPreviousEvent(bool allowEndFeedback)
166 ret = mActionHandler->AccessibilityActionPrevious(allowEndFeedback);
169 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
174 bool AccessibilityAdaptor::HandleActionActivateEvent()
180 ret = mActionHandler->AccessibilityActionActivate();
183 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
188 bool AccessibilityAdaptor::HandleActionReadEvent(unsigned int x, unsigned int y, bool allowReadAgain)
192 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %d , %d\n", __FUNCTION__, __LINE__, x, y);
194 mReadPosition.x = static_cast< float > (x);
195 mReadPosition.y = static_cast< float > (y);
199 ret = mActionHandler->AccessibilityActionRead( allowReadAgain );
200 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
206 bool AccessibilityAdaptor::HandleActionReadNextEvent(bool allowEndFeedback)
212 ret = mActionHandler->AccessibilityActionReadNext(allowEndFeedback);
215 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
220 bool AccessibilityAdaptor::HandleActionReadPreviousEvent(bool allowEndFeedback)
226 ret = mActionHandler->AccessibilityActionReadPrevious(allowEndFeedback);
229 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
234 bool AccessibilityAdaptor::HandleActionUpEvent()
240 ret = mActionHandler->AccessibilityActionUp();
243 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
248 bool AccessibilityAdaptor::HandleActionDownEvent()
254 ret = mActionHandler->AccessibilityActionDown();
257 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
262 bool AccessibilityAdaptor::HandleActionClearFocusEvent()
268 ret = mActionHandler->ClearAccessibilityFocus();
271 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
276 bool AccessibilityAdaptor::HandleActionScrollEvent(const TouchPoint& point, uint32_t timeStamp)
280 // We always need to emit a scroll signal, whether it's only a hover or not,
281 // so always send the action to the action handler.
284 Dali::TouchEvent touch = Integration::NewTouchEvent( timeStamp, point );
285 ret = mActionHandler->AccessibilityActionScroll( touch );
288 Integration::TouchEvent touchEvent;
289 Integration::HoverEvent hoverEvent;
290 Integration::TouchEventCombiner::EventDispatchType type = mCombiner.GetNextTouchEvent( Integration::Point( point ), timeStamp, touchEvent, hoverEvent );
291 if( type == Integration::TouchEventCombiner::DISPATCH_TOUCH || type == Integration::TouchEventCombiner::DISPATCH_BOTH ) // hover event is ignored
293 // Process the touch event in accessibility gesture detector
294 if( mAccessibilityGestureDetector )
296 mAccessibilityGestureDetector->SendEvent( touchEvent );
304 bool AccessibilityAdaptor::HandleActionBackEvent()
310 ret = mActionHandler->AccessibilityActionBack();
313 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
318 void AccessibilityAdaptor::HandleActionEnableEvent()
320 EnableAccessibility();
323 void AccessibilityAdaptor::HandleActionDisableEvent()
325 DisableAccessibility();
328 bool AccessibilityAdaptor::HandleActionScrollUpEvent()
334 ret = mActionHandler->AccessibilityActionScrollUp();
337 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
343 bool AccessibilityAdaptor::HandleActionScrollDownEvent()
349 ret = mActionHandler->AccessibilityActionScrollDown();
352 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
357 bool AccessibilityAdaptor::HandleActionPageLeftEvent()
363 ret = mActionHandler->AccessibilityActionPageLeft();
366 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
371 bool AccessibilityAdaptor::HandleActionPageRightEvent()
377 ret = mActionHandler->AccessibilityActionPageRight();
380 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
385 bool AccessibilityAdaptor::HandleActionPageUpEvent()
391 ret = mActionHandler->AccessibilityActionPageUp();
394 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
399 bool AccessibilityAdaptor::HandleActionPageDownEvent()
405 ret = mActionHandler->AccessibilityActionPageDown();
408 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
413 bool AccessibilityAdaptor::HandleActionMoveToFirstEvent()
419 ret = mActionHandler->AccessibilityActionMoveToFirst();
422 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
427 bool AccessibilityAdaptor::HandleActionMoveToLastEvent()
433 ret = mActionHandler->AccessibilityActionMoveToLast();
436 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
441 bool AccessibilityAdaptor::HandleActionReadFromTopEvent()
447 ret = mActionHandler->AccessibilityActionReadFromTop();
450 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
455 bool AccessibilityAdaptor::HandleActionReadFromNextEvent()
461 ret = mActionHandler->AccessibilityActionReadFromNext();
464 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
469 bool AccessibilityAdaptor::HandleActionZoomEvent()
475 ret = mActionHandler->AccessibilityActionZoom();
478 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
483 bool AccessibilityAdaptor::HandleActionReadPauseResumeEvent()
489 ret = mActionHandler->AccessibilityActionReadPauseResume();
492 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
497 bool AccessibilityAdaptor::HandleActionStartStopEvent()
503 ret = mActionHandler->AccessibilityActionStartStop();
506 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
511 AccessibilityAdaptor::~AccessibilityAdaptor()
513 // Do any platform specific clean-up in OnDestroy()
517 } // namespace Adaptor
519 } // namespace Internal