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/hover-event-integ.h>
28 #include <dali/integration-api/events/gesture-requests.h>
31 #include <singleton-service-impl.h>
32 #include <system-settings.h>
45 #if defined(DEBUG_ENABLED)
46 Debug::Filter* gAccessibilityManagerLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_ACCESSIBILITY_MANAGER");
49 void AccessibilityOnOffNotification(keynode_t* node, void* data)
51 AccessibilityManager* manager = static_cast<AccessibilityManager*>(data);
53 vconf_get_bool(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, &isEnabled);
55 DALI_LOG_INFO(gAccessibilityManagerLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, isEnabled?"ENABLED":"DISABLED");
59 manager->EnableAccessibility();
63 manager->DisableAccessibility();
69 BaseHandle handle( AccessibilityManager::Get() );
73 Dali::SingletonService service( SingletonService::Get() );
76 Dali::AccessibilityManager manager = Dali::AccessibilityManager( new AccessibilityManager() );
77 service.Register( typeid( manager ), manager );
84 TypeRegistration ACCESSIBILITY_MANAGER_TYPE( typeid(Dali::AccessibilityManager), typeid(Dali::BaseHandle), Create, true /* Create Instance At Startup */ );
86 } // unnamed namespace
88 Dali::AccessibilityManager AccessibilityManager::Get()
90 Dali::AccessibilityManager manager;
92 Dali::SingletonService service( SingletonService::Get() );
95 // Check whether the singleton is already created
96 Dali::BaseHandle handle = service.GetSingleton( typeid( Dali::AccessibilityManager ) );
99 // If so, downcast the handle
100 manager = Dali::AccessibilityManager( dynamic_cast< AccessibilityManager* >( handle.GetObjectPtr() ) );
107 Vector2 AccessibilityManager::GetReadPosition() const
109 return mReadPosition;
112 void AccessibilityManager::SetActionHandler(AccessibilityActionHandler& handler)
114 mActionHandler = &handler;
117 void AccessibilityManager::SetGestureHandler(AccessibilityGestureHandler& handler)
119 if( mAccessibilityGestureDetector )
121 mAccessibilityGestureDetector->SetGestureHandler(handler);
125 bool AccessibilityManager::HandleActionClearFocusEvent()
129 Dali::AccessibilityManager handle( this );
132 * In order to application decide reading action first,
133 * emit ActionClearFocus signal in first, ClearAccessibilityFocus for handler in next
135 if ( !mIndicatorFocused )
137 if( !mActionClearFocusSignalV2.Empty() )
139 mActionClearFocusSignalV2.Emit( handle );
145 ret = mActionHandler->ClearAccessibilityFocus();
148 DALI_LOG_INFO(gAccessibilityManagerLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
153 bool AccessibilityManager::HandleActionScrollEvent(const TouchPoint& point, unsigned long timeStamp)
157 Dali::AccessibilityManager handle( this );
159 Dali::TouchEvent event(timeStamp);
160 event.points.push_back(point);
163 * In order to application decide touch action first,
164 * emit ActionScroll signal in first, AccessibilityActionScroll for handler in next
166 if ( !mIndicatorFocused )
168 if( !mActionScrollSignalV2.Empty() )
170 mActionScrollSignalV2.Emit( handle, event );
174 Integration::TouchEvent touchEvent;
175 Integration::HoverEvent hoverEvent;
176 Integration::TouchEventCombiner::EventDispatchType type = mCombiner.GetNextTouchEvent(point, timeStamp, touchEvent, hoverEvent);
177 if(type == Integration::TouchEventCombiner::DispatchTouch || type == Integration::TouchEventCombiner::DispatchBoth) // hover event is ignored
179 // Process the touch event in accessibility gesture detector
180 if( mAccessibilityGestureDetector )
182 mAccessibilityGestureDetector->SendEvent(touchEvent);
190 bool AccessibilityManager::HandleActionTouchEvent(const TouchPoint& point, unsigned long timeStamp)
194 Dali::TouchEvent touchEvent(timeStamp);
195 touchEvent.points.push_back(point);
199 ret = mActionHandler->AccessibilityActionTouch(touchEvent);
204 bool AccessibilityManager::HandleActionBackEvent()
208 Dali::AccessibilityManager handle( this );
211 * In order to application decide reading action first,
212 * emit ActionBack signal in first, AccessibilityActionBack for handler in next
214 if ( !mIndicatorFocused )
216 if( !mActionBackSignalV2.Empty() )
218 mActionBackSignalV2.Emit( handle );
224 ret = mActionHandler->AccessibilityActionBack();
227 DALI_LOG_INFO(gAccessibilityManagerLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
232 void AccessibilityManager::HandleActionEnableEvent()
234 EnableAccessibility();
237 void AccessibilityManager::HandleActionDisableEvent()
239 DisableAccessibility();
242 void AccessibilityManager::EnableAccessibility()
244 if(mIsEnabled == false)
250 mActionHandler->ChangeAccessibilityStatus();
253 //emit status changed signal
254 Dali::AccessibilityManager handle( this );
255 mStatusChangedSignalV2.Emit( handle );
259 void AccessibilityManager::DisableAccessibility()
261 if(mIsEnabled == true)
267 mActionHandler->ChangeAccessibilityStatus();
270 //emit status changed signal
271 Dali::AccessibilityManager handle( this );
272 mStatusChangedSignalV2.Emit( handle );
274 // Destroy the TtsPlayer if exists.
275 if ( Adaptor::IsAvailable() )
277 Dali::Adaptor& adaptor = Dali::Adaptor::Get();
278 Adaptor& adaptorIpml = Adaptor::GetImplementation( adaptor );
279 adaptorIpml.DestroyTtsPlayer( Dali::TtsPlayer::SCREEN_READER );
284 bool AccessibilityManager::IsEnabled() const
289 void AccessibilityManager::SetIndicator(Indicator* indicator)
291 mIndicator = indicator;
294 AccessibilityManager::AccessibilityManager()
296 mActionHandler(NULL),
298 mIndicatorFocused(false)
301 vconf_get_bool(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, &isEnabled);
302 DALI_LOG_INFO(gAccessibilityManagerLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, isEnabled?"ENABLED":"DISABLED");
313 vconf_notify_key_changed( VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, AccessibilityOnOffNotification, this );
315 mAccessibilityGestureDetector = new AccessibilityGestureDetector();
318 AccessibilityManager::~AccessibilityManager()
320 vconf_ignore_key_changed( VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, AccessibilityOnOffNotification );
323 } // namespace Adaptor
325 } // namespace Internal