2 * Copyright (c) 2015 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-mobile.h"
24 #include <Elementary.h>
27 #include <dali/public-api/object/type-registry.h>
28 #include <dali/integration-api/debug.h>
29 #include <dali/integration-api/debug.h>
30 #include <dali/integration-api/events/gesture-requests.h>
33 #include <singleton-service-impl.h>
34 #include "system-settings.h"
36 #define MSG_DOMAIN_CONTROL_ACCESS (int)ECORE_X_ATOM_E_ILLUME_ACCESS_CONTROL
47 namespace // unnamed namespace
50 #if defined(DEBUG_ENABLED)
51 Debug::Filter* gAccessibilityAdaptorLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_ACCESSIBILITY_ADAPTOR");
54 const char * DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_DBUS_TTS = "db/setting/accessibility/atspi";
56 bool GetEnabledVConf()
59 vconf_get_bool( DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_DBUS_TTS, &isEnabled );
63 vconf_get_bool( VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, &isEnabled );
66 return (bool)isEnabled;
70 void AccessibilityOnOffNotification(keynode_t* node, void* data)
72 AccessibilityAdaptor* adaptor = static_cast<AccessibilityAdaptor*>( data );
74 bool isEnabled = GetEnabledVConf();
76 DALI_LOG_INFO( gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, isEnabled ? "ENABLED" : "DISABLED" );
80 adaptor->EnableAccessibility();
84 adaptor->DisableAccessibility();
90 BaseHandle handle( AccessibilityAdaptor::Get() );
94 Dali::SingletonService service( SingletonService::Get() );
97 Dali::AccessibilityAdaptor adaptor = Dali::AccessibilityAdaptor( new AccessibilityAdaptorMobile() );
98 AccessibilityAdaptorMobile& adaptorImpl = AccessibilityAdaptorMobile::GetImplementation( adaptor );
100 bool isEnabled = GetEnabledVConf();
104 adaptorImpl.EnableAccessibility();
106 DALI_LOG_INFO( gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, isEnabled ? "ENABLED" : "DISABLED" );
108 vconf_notify_key_changed( DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_DBUS_TTS, AccessibilityOnOffNotification, &adaptorImpl );
109 vconf_notify_key_changed( VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, AccessibilityOnOffNotification, &adaptorImpl );
111 service.Register( typeid( adaptor ), adaptor );
119 TypeRegistration ACCESSIBILITY_ADAPTOR_TYPE( typeid(Dali::AccessibilityAdaptor), typeid(Dali::BaseHandle), Create, true /* Create Instance At Startup */ );
121 } // unnamed namespace
123 Dali::AccessibilityAdaptor AccessibilityAdaptor::Get()
125 Dali::AccessibilityAdaptor adaptor;
127 Dali::SingletonService service( SingletonService::Get() );
130 // Check whether the singleton is already created
131 Dali::BaseHandle handle = service.GetSingleton( typeid( Dali::AccessibilityAdaptor ) );
134 // If so, downcast the handle
135 adaptor = Dali::AccessibilityAdaptor( dynamic_cast< AccessibilityAdaptor* >( handle.GetObjectPtr() ) );
142 void AccessibilityAdaptor::OnDestroy()
144 vconf_ignore_key_changed( VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, AccessibilityOnOffNotification );
145 vconf_ignore_key_changed( DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_DBUS_TTS, AccessibilityOnOffNotification );
148 AccessibilityAdaptorMobile::AccessibilityAdaptorMobile()
152 bool AccessibilityAdaptorMobile::HandleActionNextEvent(bool allowEndFeedback)
156 if( mIndicator && mIndicatorFocused )
158 Elm_Access_Action_Info actionInfo;
159 actionInfo.action_type = ELM_ACCESS_ACTION_HIGHLIGHT_NEXT;
161 ret = mIndicator->SendMessage(MSG_DOMAIN_CONTROL_ACCESS, actionInfo.action_type, &actionInfo, sizeof(actionInfo));
163 else if( mActionHandler )
165 ret = mActionHandler->AccessibilityActionNext(allowEndFeedback);
168 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
173 bool AccessibilityAdaptorMobile::HandleActionPreviousEvent(bool allowEndFeedback)
177 if( mIndicator && mIndicatorFocused )
179 Elm_Access_Action_Info actionInfo;
180 actionInfo.action_type = ELM_ACCESS_ACTION_HIGHLIGHT_PREV;
182 ret = mIndicator->SendMessage(MSG_DOMAIN_CONTROL_ACCESS, actionInfo.action_type, &actionInfo, sizeof(actionInfo));
184 else if( mActionHandler )
186 ret = mActionHandler->AccessibilityActionPrevious(allowEndFeedback);
189 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
194 bool AccessibilityAdaptorMobile::HandleActionActivateEvent()
198 if( mIndicator && mIndicatorFocused )
200 Elm_Access_Action_Info actionInfo;
201 actionInfo.action_type = ELM_ACCESS_ACTION_ACTIVATE;
203 ret = mIndicator->SendMessage(MSG_DOMAIN_CONTROL_ACCESS, actionInfo.action_type, &actionInfo, sizeof(actionInfo));
205 else if( mActionHandler )
207 ret = mActionHandler->AccessibilityActionActivate();
210 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
215 bool AccessibilityAdaptorMobile::HandleActionReadEvent(unsigned int x, unsigned int y, bool allowReadAgain)
219 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %d , %d\n", __FUNCTION__, __LINE__, x, y);
224 Dali::AccessibilityAdaptor handle( this );
226 bool indicatorFocused = false;
228 // Check whether the Indicator is focused
229 if( mIndicator && mIndicator->IsConnected() )
231 // Check the position and size of Indicator actor
232 Dali::Actor indicatorActor = mIndicator->GetActor();
233 Vector3 position = Vector3(0.0f, 0.0f, 0.0f);
234 Vector3 size = indicatorActor.GetCurrentSize();
236 if(mReadPosition.x >= position.x &&
237 mReadPosition.x <= position.x + size.width &&
238 mReadPosition.y >= position.y &&
239 mReadPosition.y <= position.y + size.height)
241 indicatorFocused = true;
242 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] Indicator area!!!!\n", __FUNCTION__, __LINE__);
248 if( !mIndicatorFocused && indicatorFocused )
250 // If Indicator is focused, the focus should be cleared in Dali focus chain.
253 mActionHandler->ClearAccessibilityFocus();
256 else if( mIndicatorFocused && !indicatorFocused )
258 Elm_Access_Action_Info actionInfo;
259 actionInfo.action_type = ELM_ACCESS_ACTION_UNHIGHLIGHT;
261 // Indicator should be unhighlighted
262 ret = mIndicator->SendMessage(MSG_DOMAIN_CONTROL_ACCESS, actionInfo.action_type, &actionInfo, sizeof(actionInfo));
263 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] Send unhighlight message to indicator!!!!\n", __FUNCTION__, __LINE__);
266 mIndicatorFocused = indicatorFocused;
268 // Send accessibility READ action information to Indicator
269 if( mIndicatorFocused )
271 Elm_Access_Action_Info actionInfo;
272 actionInfo.x = mReadPosition.x;
273 actionInfo.y = mReadPosition.y;
277 actionInfo.action_type = ELM_ACCESS_ACTION_READ;
281 actionInfo.action_type = static_cast<Elm_Access_Action_Type>( GetElmAccessActionOver() );
284 ret = mIndicator->SendMessage(MSG_DOMAIN_CONTROL_ACCESS, actionInfo.action_type, &actionInfo, sizeof(actionInfo));
286 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] Send READ message to indicator!!!!\n", __FUNCTION__, __LINE__);
290 if( mActionHandler && !mIndicatorFocused)
292 // If Indicator is not focused, the accessibility actions should be handled by the registered
293 // accessibility action handler (e.g. focus manager)
294 ret = mActionHandler->AccessibilityActionRead(allowReadAgain);
295 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
301 bool AccessibilityAdaptorMobile::HandleActionReadNextEvent(bool allowEndFeedback)
305 if( mIndicator && mIndicatorFocused )
307 Elm_Access_Action_Info actionInfo;
308 actionInfo.action_type = ELM_ACCESS_ACTION_HIGHLIGHT_NEXT;
310 ret = mIndicator->SendMessage(MSG_DOMAIN_CONTROL_ACCESS, actionInfo.action_type, &actionInfo, sizeof(actionInfo));
312 else if( mActionHandler )
314 ret = mActionHandler->AccessibilityActionReadNext(allowEndFeedback);
317 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
322 bool AccessibilityAdaptorMobile::HandleActionReadPreviousEvent(bool allowEndFeedback)
326 if( mIndicator && mIndicatorFocused )
328 Elm_Access_Action_Info actionInfo;
329 actionInfo.action_type = ELM_ACCESS_ACTION_HIGHLIGHT_PREV;
331 ret = mIndicator->SendMessage(MSG_DOMAIN_CONTROL_ACCESS, actionInfo.action_type, &actionInfo, sizeof(actionInfo));
333 else if( mActionHandler )
335 ret = mActionHandler->AccessibilityActionReadPrevious(allowEndFeedback);
338 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
343 bool AccessibilityAdaptorMobile::HandleActionUpEvent()
347 if( mIndicator && mIndicatorFocused )
349 Elm_Access_Action_Info actionInfo;
350 actionInfo.action_type = ELM_ACCESS_ACTION_UP;
352 ret = mIndicator->SendMessage(MSG_DOMAIN_CONTROL_ACCESS, actionInfo.action_type, &actionInfo, sizeof(actionInfo));
354 else if( mActionHandler )
356 ret = mActionHandler->AccessibilityActionUp();
359 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
364 bool AccessibilityAdaptorMobile::HandleActionDownEvent()
368 if( mIndicator && mIndicatorFocused )
370 Elm_Access_Action_Info actionInfo;
371 actionInfo.action_type = ELM_ACCESS_ACTION_DOWN;
373 ret = mIndicator->SendMessage(MSG_DOMAIN_CONTROL_ACCESS, actionInfo.action_type, &actionInfo, sizeof(actionInfo));
375 else if( mActionHandler )
377 ret = mActionHandler->AccessibilityActionDown();
380 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
385 AccessibilityAdaptorMobile::~AccessibilityAdaptorMobile()
389 } // namespace Adaptor
391 } // namespace Internal