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-manager-impl.h"
24 #include <dali/public-api/dali-core.h>
25 #include <dali/integration-api/debug.h>
26 #include <dali/integration-api/events/touch-event-integ.h>
27 #include <dali/integration-api/events/gesture-requests.h>
30 #include <singleton-service-impl.h>
31 #include <system-settings.h>
44 #if defined(DEBUG_ENABLED)
45 Debug::Filter* gAccessibilityManagerLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_ACCESSIBILITY_MANAGER");
48 void AccessibilityOnOffNotification(keynode_t* node, void* data)
50 AccessibilityManager* manager = static_cast<AccessibilityManager*>(data);
52 vconf_get_bool(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, &isEnabled);
54 DALI_LOG_INFO(gAccessibilityManagerLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, isEnabled?"ENABLED":"DISABLED");
58 manager->EnableAccessibility();
62 manager->DisableAccessibility();
68 BaseHandle handle( AccessibilityManager::Get() );
72 Dali::SingletonService service( SingletonService::Get() );
75 Dali::AccessibilityManager manager = Dali::AccessibilityManager( new AccessibilityManager() );
76 service.Register( typeid( manager ), manager );
83 TypeRegistration ACCESSIBILITY_MANAGER_TYPE( typeid(Dali::AccessibilityManager), typeid(Dali::BaseHandle), Create, true /* Create Instance At Startup */ );
85 } // unnamed namespace
87 Dali::AccessibilityManager AccessibilityManager::Get()
89 Dali::AccessibilityManager manager;
91 Dali::SingletonService service( SingletonService::Get() );
94 // Check whether the singleton is already created
95 Dali::BaseHandle handle = service.GetSingleton( typeid( Dali::AccessibilityManager ) );
98 // If so, downcast the handle
99 manager = Dali::AccessibilityManager( dynamic_cast< AccessibilityManager* >( handle.GetObjectPtr() ) );
106 Vector2 AccessibilityManager::GetReadPosition() const
108 return mReadPosition;
111 void AccessibilityManager::SetActionHandler(AccessibilityActionHandler& handler)
113 mActionHandler = &handler;
116 void AccessibilityManager::SetGestureHandler(AccessibilityGestureHandler& handler)
118 if( mAccessibilityGestureDetector )
120 mAccessibilityGestureDetector->SetGestureHandler(handler);
124 bool AccessibilityManager::HandleActionClearFocusEvent()
128 Dali::AccessibilityManager handle( this );
131 * In order to application decide reading action first,
132 * emit ActionClearFocus signal in first, ClearAccessibilityFocus for handler in next
134 if ( !mIndicatorFocused )
136 if( !mActionClearFocusSignalV2.Empty() )
138 mActionClearFocusSignalV2.Emit( handle );
144 ret = mActionHandler->ClearAccessibilityFocus();
147 DALI_LOG_INFO(gAccessibilityManagerLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
152 bool AccessibilityManager::HandleActionScrollEvent(const TouchPoint& point, unsigned long timeStamp)
156 Dali::AccessibilityManager handle( this );
158 Dali::TouchEvent touchEvent(timeStamp);
159 touchEvent.points.push_back(point);
162 * In order to application decide touch action first,
163 * emit ActionScroll signal in first, AccessibilityActionScroll for handler in next
165 if ( !mIndicatorFocused )
167 if( !mActionScrollSignalV2.Empty() )
169 mActionScrollSignalV2.Emit( handle, touchEvent );
173 Integration::TouchEvent event;
174 if (mCombiner.GetNextTouchEvent(point, timeStamp, event))
176 // Process the touch event in accessibility gesture detector
177 if( mAccessibilityGestureDetector )
179 mAccessibilityGestureDetector->SendEvent(event);
187 bool AccessibilityManager::HandleActionTouchEvent(const TouchPoint& point, unsigned long timeStamp)
191 Dali::TouchEvent touchEvent(timeStamp);
192 touchEvent.points.push_back(point);
196 ret = mActionHandler->AccessibilityActionTouch(touchEvent);
201 bool AccessibilityManager::HandleActionBackEvent()
205 Dali::AccessibilityManager handle( this );
208 * In order to application decide reading action first,
209 * emit ActionBack signal in first, AccessibilityActionBack for handler in next
211 if ( !mIndicatorFocused )
213 if( !mActionBackSignalV2.Empty() )
215 mActionBackSignalV2.Emit( handle );
221 ret = mActionHandler->AccessibilityActionBack();
224 DALI_LOG_INFO(gAccessibilityManagerLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
229 void AccessibilityManager::HandleActionEnableEvent()
231 EnableAccessibility();
234 void AccessibilityManager::HandleActionDisableEvent()
236 DisableAccessibility();
239 void AccessibilityManager::EnableAccessibility()
241 if(mIsEnabled == false)
247 mActionHandler->ChangeAccessibilityStatus();
250 //emit status changed signal
251 Dali::AccessibilityManager handle( this );
252 mStatusChangedSignalV2.Emit( handle );
256 void AccessibilityManager::DisableAccessibility()
258 if(mIsEnabled == true)
264 mActionHandler->ChangeAccessibilityStatus();
267 //emit status changed signal
268 Dali::AccessibilityManager handle( this );
269 mStatusChangedSignalV2.Emit( handle );
271 // Destroy the TtsPlayer if exists.
272 if ( Adaptor::IsAvailable() )
274 Dali::Adaptor& adaptor = Dali::Adaptor::Get();
275 Adaptor::GetImplementation( adaptor ).DestroyTtsPlayer( Dali::TtsPlayer::SCREEN_READER );
280 bool AccessibilityManager::IsEnabled() const
285 void AccessibilityManager::SetIndicator(Indicator* indicator)
287 mIndicator = indicator;
290 AccessibilityManager::AccessibilityManager()
292 mActionHandler(NULL),
294 mIndicatorFocused(false)
297 vconf_get_bool(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, &isEnabled);
298 DALI_LOG_INFO(gAccessibilityManagerLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, isEnabled?"ENABLED":"DISABLED");
309 vconf_notify_key_changed( VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, AccessibilityOnOffNotification, this );
311 mAccessibilityGestureDetector = new AccessibilityGestureDetector();
314 AccessibilityManager::~AccessibilityManager()
316 vconf_ignore_key_changed( VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, AccessibilityOnOffNotification );
319 } // namespace Adaptor
321 } // namespace Internal