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 mActionHandler( NULL ),
57 mAccessibilityGestureDetector = new AccessibilityGestureDetector();
60 void AccessibilityAdaptor::EnableAccessibility()
62 bool accessibilityState = false;
63 system_settings_get_value_bool( SYSTEM_SETTINGS_KEY_ACCESSIBILITY_TTS, &accessibilityState );
64 if(accessibilityState == false)
66 DALI_LOG_ERROR("The Current Accessibility system cannot run. \n");
70 if(mIsEnabled == false)
76 mActionHandler->ChangeAccessibilityStatus();
81 void AccessibilityAdaptor::DisableAccessibility()
83 if(mIsEnabled == true)
89 mActionHandler->ChangeAccessibilityStatus();
92 // Destroy the TtsPlayer if exists.
93 if ( Adaptor::IsAvailable() )
95 Dali::Adaptor& adaptor = Dali::Adaptor::Get();
96 Adaptor& adaptorImpl = Adaptor::GetImplementation( adaptor );
97 adaptorImpl.DestroyTtsPlayer( Dali::TtsPlayer::SCREEN_READER );
102 bool AccessibilityAdaptor::IsEnabled() const
107 void AccessibilityAdaptor::SetForcedEnable( bool forced )
112 bool AccessibilityAdaptor::IsForcedEnable() const
117 Vector2 AccessibilityAdaptor::GetReadPosition() const
119 return mReadPosition;
122 void AccessibilityAdaptor::SetActionHandler(AccessibilityActionHandler& handler)
124 mActionHandler = &handler;
127 void AccessibilityAdaptor::SetGestureHandler(AccessibilityGestureHandler& handler)
129 if( mAccessibilityGestureDetector )
131 mAccessibilityGestureDetector->SetGestureHandler(handler);
135 bool AccessibilityAdaptor::HandleActionNextEvent(bool allowEndFeedback)
141 ret = mActionHandler->AccessibilityActionNext(allowEndFeedback);
144 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
149 bool AccessibilityAdaptor::HandleActionPreviousEvent(bool allowEndFeedback)
155 ret = mActionHandler->AccessibilityActionPrevious(allowEndFeedback);
158 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
163 bool AccessibilityAdaptor::HandleActionActivateEvent()
169 ret = mActionHandler->AccessibilityActionActivate();
172 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
177 bool AccessibilityAdaptor::HandleActionReadEvent(unsigned int x, unsigned int y, bool allowReadAgain)
181 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %d , %d\n", __FUNCTION__, __LINE__, x, y);
183 mReadPosition.x = static_cast< float > (x);
184 mReadPosition.y = static_cast< float > (y);
188 ret = mActionHandler->AccessibilityActionRead( allowReadAgain );
189 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
195 bool AccessibilityAdaptor::HandleActionReadNextEvent(bool allowEndFeedback)
201 ret = mActionHandler->AccessibilityActionReadNext(allowEndFeedback);
204 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
209 bool AccessibilityAdaptor::HandleActionReadPreviousEvent(bool allowEndFeedback)
215 ret = mActionHandler->AccessibilityActionReadPrevious(allowEndFeedback);
218 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
223 bool AccessibilityAdaptor::HandleActionUpEvent()
229 ret = mActionHandler->AccessibilityActionUp();
232 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
237 bool AccessibilityAdaptor::HandleActionDownEvent()
243 ret = mActionHandler->AccessibilityActionDown();
246 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
251 bool AccessibilityAdaptor::HandleActionClearFocusEvent()
257 ret = mActionHandler->ClearAccessibilityFocus();
260 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
265 bool AccessibilityAdaptor::HandleActionScrollEvent(const TouchPoint& point, uint32_t timeStamp)
269 // We always need to emit a scroll signal, whether it's only a hover or not,
270 // so always send the action to the action handler.
273 Dali::TouchEvent touch = Integration::NewTouchEvent( timeStamp, point );
274 ret = mActionHandler->AccessibilityActionScroll( touch );
277 Integration::TouchEvent touchEvent;
278 Integration::HoverEvent hoverEvent;
279 Integration::TouchEventCombiner::EventDispatchType type = mCombiner.GetNextTouchEvent( Integration::Point( point ), timeStamp, touchEvent, hoverEvent );
280 if( type == Integration::TouchEventCombiner::DISPATCH_TOUCH || type == Integration::TouchEventCombiner::DISPATCH_BOTH ) // hover event is ignored
282 // Process the touch event in accessibility gesture detector
283 if( mAccessibilityGestureDetector )
285 mAccessibilityGestureDetector->SendEvent( touchEvent );
293 bool AccessibilityAdaptor::HandleActionBackEvent()
299 ret = mActionHandler->AccessibilityActionBack();
302 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
307 void AccessibilityAdaptor::HandleActionEnableEvent()
309 EnableAccessibility();
312 void AccessibilityAdaptor::HandleActionDisableEvent()
314 DisableAccessibility();
317 bool AccessibilityAdaptor::HandleActionScrollUpEvent()
323 ret = mActionHandler->AccessibilityActionScrollUp();
326 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
332 bool AccessibilityAdaptor::HandleActionScrollDownEvent()
338 ret = mActionHandler->AccessibilityActionScrollDown();
341 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
346 bool AccessibilityAdaptor::HandleActionPageLeftEvent()
352 ret = mActionHandler->AccessibilityActionPageLeft();
355 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
360 bool AccessibilityAdaptor::HandleActionPageRightEvent()
366 ret = mActionHandler->AccessibilityActionPageRight();
369 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
374 bool AccessibilityAdaptor::HandleActionPageUpEvent()
380 ret = mActionHandler->AccessibilityActionPageUp();
383 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
388 bool AccessibilityAdaptor::HandleActionPageDownEvent()
394 ret = mActionHandler->AccessibilityActionPageDown();
397 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
402 bool AccessibilityAdaptor::HandleActionMoveToFirstEvent()
408 ret = mActionHandler->AccessibilityActionMoveToFirst();
411 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
416 bool AccessibilityAdaptor::HandleActionMoveToLastEvent()
422 ret = mActionHandler->AccessibilityActionMoveToLast();
425 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
430 bool AccessibilityAdaptor::HandleActionReadFromTopEvent()
436 ret = mActionHandler->AccessibilityActionReadFromTop();
439 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
444 bool AccessibilityAdaptor::HandleActionReadFromNextEvent()
450 ret = mActionHandler->AccessibilityActionReadFromNext();
453 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
458 bool AccessibilityAdaptor::HandleActionZoomEvent()
464 ret = mActionHandler->AccessibilityActionZoom();
467 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
472 bool AccessibilityAdaptor::HandleActionReadPauseResumeEvent()
478 ret = mActionHandler->AccessibilityActionReadPauseResume();
481 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
486 bool AccessibilityAdaptor::HandleActionStartStopEvent()
492 ret = mActionHandler->AccessibilityActionStartStop();
495 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
500 AccessibilityAdaptor::~AccessibilityAdaptor()
502 // Do any platform specific clean-up in OnDestroy()
506 } // namespace Adaptor
508 } // namespace Internal