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-adaptor-impl.h"
24 #include <dali/public-api/object/type-registry.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>
46 // TODO: Update vconf-key.h ?
47 const char * DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_DBUS_TTS = "db/setting/accessibility/atspi";
49 bool GetEnabledVConf()
52 vconf_get_bool( DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_DBUS_TTS, &isEnabled );
56 vconf_get_bool( VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, &isEnabled );
59 return (bool)isEnabled;
62 #if defined(DEBUG_ENABLED)
63 Debug::Filter* gAccessibilityAdaptorLogFilter = Debug::Filter::New( Debug::NoLogging, false, "LOG_ACCESSIBILITY_ADAPTOR" );
66 void AccessibilityOnOffNotification(keynode_t* node, void* data)
68 AccessibilityAdaptor* adaptor = static_cast<AccessibilityAdaptor*>( data );
70 bool isEnabled = GetEnabledVConf();
72 DALI_LOG_INFO( gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, isEnabled ? "ENABLED" : "DISABLED" );
76 adaptor->EnableAccessibility();
80 adaptor->DisableAccessibility();
86 BaseHandle handle( AccessibilityAdaptor::Get() );
90 Dali::SingletonService service( SingletonService::Get() );
93 Dali::AccessibilityAdaptor adaptor = Dali::AccessibilityAdaptor( new AccessibilityAdaptor() );
94 service.Register( typeid( adaptor ), adaptor );
101 TypeRegistration ACCESSIBILITY_ADAPTOR_TYPE( typeid(Dali::AccessibilityAdaptor), typeid(Dali::BaseHandle), Create, true /* Create Instance At Startup */ );
103 } // unnamed namespace
105 Dali::AccessibilityAdaptor AccessibilityAdaptor::Get()
107 Dali::AccessibilityAdaptor adaptor;
109 Dali::SingletonService service( SingletonService::Get() );
112 // Check whether the singleton is already created
113 Dali::BaseHandle handle = service.GetSingleton( typeid( Dali::AccessibilityAdaptor ) );
116 // If so, downcast the handle
117 adaptor = Dali::AccessibilityAdaptor( dynamic_cast< AccessibilityAdaptor* >( handle.GetObjectPtr() ) );
124 Vector2 AccessibilityAdaptor::GetReadPosition() const
126 return mReadPosition;
129 void AccessibilityAdaptor::SetActionHandler(AccessibilityActionHandler& handler)
131 mActionHandler = &handler;
134 void AccessibilityAdaptor::SetGestureHandler(AccessibilityGestureHandler& handler)
136 if( mAccessibilityGestureDetector )
138 mAccessibilityGestureDetector->SetGestureHandler(handler);
142 bool AccessibilityAdaptor::HandleActionClearFocusEvent()
148 ret = mActionHandler->ClearAccessibilityFocus();
151 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
156 bool AccessibilityAdaptor::HandleActionScrollEvent(const TouchPoint& point, unsigned long timeStamp)
160 // We always need to emit a scroll signal, whether it's only a hover or not,
161 // so always send the action to the action handler.
164 Dali::TouchEvent event(timeStamp);
165 event.points.push_back(point);
166 ret = mActionHandler->AccessibilityActionScroll( event );
169 Integration::TouchEvent touchEvent;
170 Integration::HoverEvent hoverEvent;
171 Integration::TouchEventCombiner::EventDispatchType type = mCombiner.GetNextTouchEvent(point, timeStamp, touchEvent, hoverEvent);
172 if(type == Integration::TouchEventCombiner::DispatchTouch || type == Integration::TouchEventCombiner::DispatchBoth) // hover event is ignored
174 // Process the touch event in accessibility gesture detector
175 if( mAccessibilityGestureDetector )
177 mAccessibilityGestureDetector->SendEvent(touchEvent);
185 bool AccessibilityAdaptor::HandleActionTouchEvent(const TouchPoint& point, unsigned long timeStamp)
189 Dali::TouchEvent touchEvent(timeStamp);
190 touchEvent.points.push_back(point);
194 ret = mActionHandler->AccessibilityActionTouch(touchEvent);
199 bool AccessibilityAdaptor::HandleActionBackEvent()
205 ret = mActionHandler->AccessibilityActionBack();
208 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
213 void AccessibilityAdaptor::HandleActionEnableEvent()
215 EnableAccessibility();
218 void AccessibilityAdaptor::HandleActionDisableEvent()
220 DisableAccessibility();
223 void AccessibilityAdaptor::EnableAccessibility()
225 if(mIsEnabled == false)
231 mActionHandler->ChangeAccessibilityStatus();
236 void AccessibilityAdaptor::DisableAccessibility()
238 if(mIsEnabled == true)
244 mActionHandler->ChangeAccessibilityStatus();
247 // Destroy the TtsPlayer if exists.
248 if ( Adaptor::IsAvailable() )
250 Dali::Adaptor& adaptor = Dali::Adaptor::Get();
251 Adaptor& adaptorIpml = Adaptor::GetImplementation( adaptor );
252 adaptorIpml.DestroyTtsPlayer( Dali::TtsPlayer::SCREEN_READER );
257 bool AccessibilityAdaptor::IsEnabled() const
262 void AccessibilityAdaptor::SetIndicator(Indicator* indicator)
264 mIndicator = indicator;
267 AccessibilityAdaptor::AccessibilityAdaptor()
269 mActionHandler(NULL),
271 mIndicatorFocused(false)
273 mIsEnabled = GetEnabledVConf();
274 DALI_LOG_INFO( gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, mIsEnabled ? "ENABLED" : "DISABLED" );
276 vconf_notify_key_changed( DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_DBUS_TTS, AccessibilityOnOffNotification, this );
277 vconf_notify_key_changed( VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, AccessibilityOnOffNotification, this );
279 mAccessibilityGestureDetector = new AccessibilityGestureDetector();
282 AccessibilityAdaptor::~AccessibilityAdaptor()
284 vconf_ignore_key_changed( VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, AccessibilityOnOffNotification );
285 vconf_ignore_key_changed( DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_DBUS_TTS, AccessibilityOnOffNotification );
288 } // namespace Adaptor
290 } // namespace Internal