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"
28 #include <Elementary.h>
31 #include <dali/public-api/object/type-registry.h>
32 #include <dali/integration-api/debug.h>
33 #include <dali/integration-api/debug.h>
34 #include <dali/integration-api/events/gesture-requests.h>
37 #include <singleton-service-impl.h>
38 #include "system-settings.h"
41 #define MSG_DOMAIN_CONTROL_ACCESS (int)ECORE_X_ATOM_E_ILLUME_ACCESS_CONTROL
53 namespace // unnamed namespace
56 #if defined(DEBUG_ENABLED)
57 Debug::Filter* gAccessibilityAdaptorLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_ACCESSIBILITY_ADAPTOR");
60 const char * DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_DBUS_TTS = "db/setting/accessibility/atspi";
62 bool GetEnabledVConf()
65 vconf_get_bool( DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_DBUS_TTS, &isEnabled );
69 vconf_get_bool( VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, &isEnabled );
72 return (bool)isEnabled;
76 void AccessibilityOnOffNotification(keynode_t* node, void* data)
78 AccessibilityAdaptor* adaptor = static_cast<AccessibilityAdaptor*>( data );
80 bool isEnabled = GetEnabledVConf();
82 DALI_LOG_INFO( gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, isEnabled ? "ENABLED" : "DISABLED" );
86 adaptor->EnableAccessibility();
90 adaptor->DisableAccessibility();
96 BaseHandle handle( AccessibilityAdaptor::Get() );
100 Dali::SingletonService service( SingletonService::Get() );
103 Dali::AccessibilityAdaptor adaptor = Dali::AccessibilityAdaptor( new AccessibilityAdaptorMobile() );
104 AccessibilityAdaptorMobile& adaptorImpl = AccessibilityAdaptorMobile::GetImplementation( adaptor );
106 bool isEnabled = GetEnabledVConf();
110 adaptorImpl.EnableAccessibility();
112 DALI_LOG_INFO( gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, isEnabled ? "ENABLED" : "DISABLED" );
114 vconf_notify_key_changed( DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_DBUS_TTS, AccessibilityOnOffNotification, &adaptorImpl );
115 vconf_notify_key_changed( VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, AccessibilityOnOffNotification, &adaptorImpl );
117 service.Register( typeid( adaptor ), adaptor );
125 TypeRegistration ACCESSIBILITY_ADAPTOR_TYPE( typeid(Dali::AccessibilityAdaptor), typeid(Dali::BaseHandle), Create, true /* Create Instance At Startup */ );
127 } // unnamed namespace
129 Dali::AccessibilityAdaptor AccessibilityAdaptor::Get()
131 Dali::AccessibilityAdaptor adaptor;
133 Dali::SingletonService service( SingletonService::Get() );
136 // Check whether the singleton is already created
137 Dali::BaseHandle handle = service.GetSingleton( typeid( Dali::AccessibilityAdaptor ) );
140 // If so, downcast the handle
141 adaptor = Dali::AccessibilityAdaptor( dynamic_cast< AccessibilityAdaptor* >( handle.GetObjectPtr() ) );
148 void AccessibilityAdaptor::OnDestroy()
150 vconf_ignore_key_changed( VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, AccessibilityOnOffNotification );
151 vconf_ignore_key_changed( DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_DBUS_TTS, AccessibilityOnOffNotification );
154 AccessibilityAdaptorMobile::AccessibilityAdaptorMobile()
158 bool AccessibilityAdaptorMobile::HandleActionNextEvent(bool allowEndFeedback)
163 if( mIndicator && mIndicatorFocused )
165 Elm_Access_Action_Info actionInfo;
166 actionInfo.action_type = ELM_ACCESS_ACTION_HIGHLIGHT_NEXT;
168 ret = mIndicator->SendMessage(MSG_DOMAIN_CONTROL_ACCESS, actionInfo.action_type, &actionInfo, sizeof(actionInfo));
170 else if( mActionHandler )
175 ret = mActionHandler->AccessibilityActionNext(allowEndFeedback);
178 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
183 bool AccessibilityAdaptorMobile::HandleActionPreviousEvent(bool allowEndFeedback)
188 if( mIndicator && mIndicatorFocused )
190 Elm_Access_Action_Info actionInfo;
191 actionInfo.action_type = ELM_ACCESS_ACTION_HIGHLIGHT_PREV;
193 ret = mIndicator->SendMessage(MSG_DOMAIN_CONTROL_ACCESS, actionInfo.action_type, &actionInfo, sizeof(actionInfo));
195 else if( mActionHandler )
200 ret = mActionHandler->AccessibilityActionPrevious(allowEndFeedback);
203 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
208 bool AccessibilityAdaptorMobile::HandleActionActivateEvent()
213 if( mIndicator && mIndicatorFocused )
215 Elm_Access_Action_Info actionInfo;
216 actionInfo.action_type = ELM_ACCESS_ACTION_ACTIVATE;
218 ret = mIndicator->SendMessage(MSG_DOMAIN_CONTROL_ACCESS, actionInfo.action_type, &actionInfo, sizeof(actionInfo));
220 else if( mActionHandler )
225 ret = mActionHandler->AccessibilityActionActivate();
228 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
233 bool AccessibilityAdaptorMobile::HandleActionReadEvent(unsigned int x, unsigned int y, bool allowReadAgain)
237 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %d , %d\n", __FUNCTION__, __LINE__, x, y);
242 Dali::AccessibilityAdaptor handle( this );
244 bool indicatorFocused = false;
246 // Check whether the Indicator is focused
247 if( mIndicator && mIndicator->IsConnected() )
249 // Check the position and size of Indicator actor
250 Dali::Actor indicatorActor = mIndicator->GetActor();
251 Vector3 position = Vector3(0.0f, 0.0f, 0.0f);
252 Vector3 size = indicatorActor.GetCurrentSize();
254 if(mReadPosition.x >= position.x &&
255 mReadPosition.x <= position.x + size.width &&
256 mReadPosition.y >= position.y &&
257 mReadPosition.y <= position.y + size.height)
259 indicatorFocused = true;
260 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] Indicator area!!!!\n", __FUNCTION__, __LINE__);
266 if( !mIndicatorFocused && indicatorFocused )
268 // If Indicator is focused, the focus should be cleared in Dali focus chain.
271 mActionHandler->ClearAccessibilityFocus();
274 else if( mIndicatorFocused && !indicatorFocused )
277 Elm_Access_Action_Info actionInfo;
278 actionInfo.action_type = ELM_ACCESS_ACTION_UNHIGHLIGHT;
280 // Indicator should be unhighlighted
281 ret = mIndicator->SendMessage(MSG_DOMAIN_CONTROL_ACCESS, actionInfo.action_type, &actionInfo, sizeof(actionInfo));
282 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] Send unhighlight message to indicator!!!!\n", __FUNCTION__, __LINE__);
286 mIndicatorFocused = indicatorFocused;
288 // Send accessibility READ action information to Indicator
289 if( mIndicatorFocused )
292 Elm_Access_Action_Info actionInfo;
293 actionInfo.x = mReadPosition.x;
294 actionInfo.y = mReadPosition.y;
298 actionInfo.action_type = ELM_ACCESS_ACTION_READ;
302 actionInfo.action_type = static_cast<Elm_Access_Action_Type>( GetElmAccessActionOver() );
305 ret = mIndicator->SendMessage(MSG_DOMAIN_CONTROL_ACCESS, actionInfo.action_type, &actionInfo, sizeof(actionInfo));
307 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] Send READ message to indicator!!!!\n", __FUNCTION__, __LINE__);
312 if( mActionHandler && !mIndicatorFocused)
314 // If Indicator is not focused, the accessibility actions should be handled by the registered
315 // accessibility action handler (e.g. focus manager)
316 ret = mActionHandler->AccessibilityActionRead(allowReadAgain);
317 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
323 bool AccessibilityAdaptorMobile::HandleActionReadNextEvent(bool allowEndFeedback)
328 if( mIndicator && mIndicatorFocused )
330 Elm_Access_Action_Info actionInfo;
331 actionInfo.action_type = ELM_ACCESS_ACTION_HIGHLIGHT_NEXT;
333 ret = mIndicator->SendMessage(MSG_DOMAIN_CONTROL_ACCESS, actionInfo.action_type, &actionInfo, sizeof(actionInfo));
335 else if( mActionHandler )
340 ret = mActionHandler->AccessibilityActionReadNext(allowEndFeedback);
343 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
348 bool AccessibilityAdaptorMobile::HandleActionReadPreviousEvent(bool allowEndFeedback)
353 if( mIndicator && mIndicatorFocused )
355 Elm_Access_Action_Info actionInfo;
356 actionInfo.action_type = ELM_ACCESS_ACTION_HIGHLIGHT_PREV;
358 ret = mIndicator->SendMessage(MSG_DOMAIN_CONTROL_ACCESS, actionInfo.action_type, &actionInfo, sizeof(actionInfo));
360 else if( mActionHandler )
365 ret = mActionHandler->AccessibilityActionReadPrevious(allowEndFeedback);
368 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
373 bool AccessibilityAdaptorMobile::HandleActionUpEvent()
378 if( mIndicator && mIndicatorFocused )
380 Elm_Access_Action_Info actionInfo;
381 actionInfo.action_type = ELM_ACCESS_ACTION_UP;
383 ret = mIndicator->SendMessage(MSG_DOMAIN_CONTROL_ACCESS, actionInfo.action_type, &actionInfo, sizeof(actionInfo));
385 else if( mActionHandler )
390 ret = mActionHandler->AccessibilityActionUp();
393 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
398 bool AccessibilityAdaptorMobile::HandleActionDownEvent()
403 if( mIndicator && mIndicatorFocused )
405 Elm_Access_Action_Info actionInfo;
406 actionInfo.action_type = ELM_ACCESS_ACTION_DOWN;
408 ret = mIndicator->SendMessage(MSG_DOMAIN_CONTROL_ACCESS, actionInfo.action_type, &actionInfo, sizeof(actionInfo));
410 else if( mActionHandler )
415 ret = mActionHandler->AccessibilityActionDown();
418 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
423 AccessibilityAdaptorMobile::~AccessibilityAdaptorMobile()
427 } // namespace Adaptor
429 } // namespace Internal