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 #ifndef DALI_PROFILE_UBUNTU
23 #include <system_settings.h>
25 #include <dali/public-api/object/type-registry.h>
26 #include <dali/integration-api/debug.h>
27 #include <dali/integration-api/events/touch-event-integ.h>
28 #include <dali/integration-api/events/touch-integ.h>
29 #include <dali/integration-api/events/hover-event-integ.h>
32 #include <dali/internal/adaptor/common/adaptor-impl.h>
33 #include <dali/internal/system/common/system-settings.h>
44 namespace // unnamed namespace
47 #if defined(DEBUG_ENABLED)
48 Debug::Filter* gAccessibilityAdaptorLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_ACCESSIBILITY_ADAPTOR");
51 } // unnamed namespace
53 AccessibilityAdaptor::AccessibilityAdaptor()
55 mFocusedActorPosition(),
56 mActionHandler( NULL ),
60 mAccessibilityGestureDetector = new AccessibilityGestureDetector();
63 void AccessibilityAdaptor::EnableAccessibility()
65 bool accessibilityState = false;
66 #ifndef DALI_PROFILE_UBUNTU
67 system_settings_get_value_bool( SYSTEM_SETTINGS_KEY_ACCESSIBILITY_TTS, &accessibilityState );
69 if(accessibilityState == false)
71 DALI_LOG_ERROR("The Current Accessibility system cannot run. \n");
75 if(mIsEnabled == false)
81 mActionHandler->ChangeAccessibilityStatus();
86 void AccessibilityAdaptor::DisableAccessibility()
88 if(mIsEnabled == true)
94 mActionHandler->ChangeAccessibilityStatus();
97 // Destroy the TtsPlayer if exists.
98 if ( Adaptor::IsAvailable() )
100 Dali::Adaptor& adaptor = Dali::Adaptor::Get();
101 Adaptor& adaptorImpl = Adaptor::GetImplementation( adaptor );
102 adaptorImpl.DestroyTtsPlayer( Dali::TtsPlayer::SCREEN_READER );
107 bool AccessibilityAdaptor::IsEnabled() const
112 void AccessibilityAdaptor::SetForcedEnable( bool forced )
117 bool AccessibilityAdaptor::IsForcedEnable() const
122 Vector2 AccessibilityAdaptor::GetReadPosition() const
124 return mReadPosition;
127 void AccessibilityAdaptor::SetActionHandler(AccessibilityActionHandler& handler)
129 mActionHandler = &handler;
132 void AccessibilityAdaptor::SetGestureHandler(AccessibilityGestureHandler& handler)
134 if( mAccessibilityGestureDetector )
136 mAccessibilityGestureDetector->SetGestureHandler(handler);
140 void AccessibilityAdaptor::SetFocusedActorPosition(Vector2 currentPosition)
142 mFocusedActorPosition = currentPosition;
145 Vector2 AccessibilityAdaptor::GetFocusedActorPosition() const
147 return mFocusedActorPosition;
150 bool AccessibilityAdaptor::HandleActionNextEvent(bool allowEndFeedback)
156 ret = mActionHandler->AccessibilityActionNext(allowEndFeedback);
159 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
164 bool AccessibilityAdaptor::HandleActionPreviousEvent(bool allowEndFeedback)
170 ret = mActionHandler->AccessibilityActionPrevious(allowEndFeedback);
173 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
178 bool AccessibilityAdaptor::HandleActionActivateEvent()
184 ret = mActionHandler->AccessibilityActionActivate();
187 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
192 bool AccessibilityAdaptor::HandleActionReadEvent(unsigned int x, unsigned int y, bool allowReadAgain)
196 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %d , %d\n", __FUNCTION__, __LINE__, x, y);
198 mReadPosition.x = static_cast< float > (x);
199 mReadPosition.y = static_cast< float > (y);
203 ret = mActionHandler->AccessibilityActionRead( allowReadAgain );
204 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
210 bool AccessibilityAdaptor::HandleActionReadNextEvent(bool allowEndFeedback)
216 ret = mActionHandler->AccessibilityActionReadNext(allowEndFeedback);
219 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
224 bool AccessibilityAdaptor::HandleActionReadPreviousEvent(bool allowEndFeedback)
230 ret = mActionHandler->AccessibilityActionReadPrevious(allowEndFeedback);
233 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
238 bool AccessibilityAdaptor::HandleActionUpEvent()
244 ret = mActionHandler->AccessibilityActionUp();
247 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
252 bool AccessibilityAdaptor::HandleActionDownEvent()
258 ret = mActionHandler->AccessibilityActionDown();
261 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
266 bool AccessibilityAdaptor::HandleActionClearFocusEvent()
272 ret = mActionHandler->ClearAccessibilityFocus();
275 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
280 bool AccessibilityAdaptor::HandleActionScrollEvent(const TouchPoint& point, uint32_t timeStamp)
284 // We always need to emit a scroll signal, whether it's only a hover or not,
285 // so always send the action to the action handler.
288 Dali::TouchEvent touch = Integration::NewTouchEvent( timeStamp, point );
289 ret = mActionHandler->AccessibilityActionScroll( touch );
292 Integration::TouchEvent touchEvent;
293 Integration::HoverEvent hoverEvent;
294 Integration::TouchEventCombiner::EventDispatchType type = mCombiner.GetNextTouchEvent( Integration::Point( point ), timeStamp, touchEvent, hoverEvent );
295 if( type == Integration::TouchEventCombiner::DISPATCH_TOUCH || type == Integration::TouchEventCombiner::DISPATCH_BOTH ) // hover event is ignored
297 // Process the touch event in accessibility gesture detector
298 if( mAccessibilityGestureDetector )
300 mAccessibilityGestureDetector->SendEvent( touchEvent );
308 bool AccessibilityAdaptor::HandleActionBackEvent()
314 ret = mActionHandler->AccessibilityActionBack();
317 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
322 void AccessibilityAdaptor::HandleActionEnableEvent()
324 EnableAccessibility();
327 void AccessibilityAdaptor::HandleActionDisableEvent()
329 DisableAccessibility();
332 bool AccessibilityAdaptor::HandleActionScrollUpEvent()
338 ret = mActionHandler->AccessibilityActionScrollUp();
341 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
347 bool AccessibilityAdaptor::HandleActionScrollDownEvent()
353 ret = mActionHandler->AccessibilityActionScrollDown();
356 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
361 bool AccessibilityAdaptor::HandleActionPageLeftEvent()
367 ret = mActionHandler->AccessibilityActionPageLeft();
370 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
375 bool AccessibilityAdaptor::HandleActionPageRightEvent()
381 ret = mActionHandler->AccessibilityActionPageRight();
384 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
389 bool AccessibilityAdaptor::HandleActionPageUpEvent()
395 ret = mActionHandler->AccessibilityActionPageUp();
398 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
403 bool AccessibilityAdaptor::HandleActionPageDownEvent()
409 ret = mActionHandler->AccessibilityActionPageDown();
412 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
417 bool AccessibilityAdaptor::HandleActionMoveToFirstEvent()
423 ret = mActionHandler->AccessibilityActionMoveToFirst();
426 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
431 bool AccessibilityAdaptor::HandleActionMoveToLastEvent()
437 ret = mActionHandler->AccessibilityActionMoveToLast();
440 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
445 bool AccessibilityAdaptor::HandleActionReadFromTopEvent()
451 ret = mActionHandler->AccessibilityActionReadFromTop();
454 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
459 bool AccessibilityAdaptor::HandleActionReadFromNextEvent()
465 ret = mActionHandler->AccessibilityActionReadFromNext();
468 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
473 bool AccessibilityAdaptor::HandleActionZoomEvent()
479 ret = mActionHandler->AccessibilityActionZoom();
482 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
487 bool AccessibilityAdaptor::HandleActionReadPauseResumeEvent()
493 ret = mActionHandler->AccessibilityActionReadPauseResume();
496 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
501 bool AccessibilityAdaptor::HandleActionStartStopEvent()
507 ret = mActionHandler->AccessibilityActionStartStop();
510 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
515 AccessibilityAdaptor::~AccessibilityAdaptor()
517 // Do any platform specific clean-up in OnDestroy()
521 } // namespace Adaptor
523 } // namespace Internal