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"
26 #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();
94 } // unnamed namespace
96 Dali::AccessibilityAdaptor AccessibilityAdaptor::Get()
98 Dali::AccessibilityAdaptor adaptor;
100 Dali::SingletonService service( SingletonService::Get() );
103 // Check whether the singleton is already created
104 Dali::BaseHandle handle = service.GetSingleton( typeid( Dali::AccessibilityAdaptor ) );
107 // If so, downcast the handle
108 adaptor = Dali::AccessibilityAdaptor( dynamic_cast< AccessibilityAdaptor* >( handle.GetObjectPtr() ) );
112 adaptor = Dali::AccessibilityAdaptor( new AccessibilityAdaptorMobile() );
113 AccessibilityAdaptorMobile& adaptorImpl = AccessibilityAdaptorMobile::GetImplementation( adaptor );
115 bool isEnabled = GetEnabledVConf();
119 adaptorImpl.EnableAccessibility();
121 DALI_LOG_INFO( gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, isEnabled ? "ENABLED" : "DISABLED" );
123 vconf_notify_key_changed( DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_DBUS_TTS, AccessibilityOnOffNotification, &adaptorImpl );
124 vconf_notify_key_changed( VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, AccessibilityOnOffNotification, &adaptorImpl );
126 service.Register( typeid( adaptor ), adaptor );
133 void AccessibilityAdaptor::OnDestroy()
135 vconf_ignore_key_changed( VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, AccessibilityOnOffNotification );
136 vconf_ignore_key_changed( DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_DBUS_TTS, AccessibilityOnOffNotification );
139 AccessibilityAdaptorMobile::AccessibilityAdaptorMobile()
143 bool AccessibilityAdaptorMobile::HandleActionNextEvent(bool allowEndFeedback)
148 if( mIndicator && mIndicatorFocused )
150 Elm_Access_Action_Info actionInfo;
151 actionInfo.action_type = ELM_ACCESS_ACTION_HIGHLIGHT_NEXT;
153 ret = mIndicator->SendMessage(MSG_DOMAIN_CONTROL_ACCESS, actionInfo.action_type, &actionInfo, sizeof(actionInfo));
155 else if( mActionHandler )
160 ret = mActionHandler->AccessibilityActionNext(allowEndFeedback);
163 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
168 bool AccessibilityAdaptorMobile::HandleActionPreviousEvent(bool allowEndFeedback)
173 if( mIndicator && mIndicatorFocused )
175 Elm_Access_Action_Info actionInfo;
176 actionInfo.action_type = ELM_ACCESS_ACTION_HIGHLIGHT_PREV;
178 ret = mIndicator->SendMessage(MSG_DOMAIN_CONTROL_ACCESS, actionInfo.action_type, &actionInfo, sizeof(actionInfo));
180 else if( mActionHandler )
185 ret = mActionHandler->AccessibilityActionPrevious(allowEndFeedback);
188 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
193 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 )
210 ret = mActionHandler->AccessibilityActionActivate();
213 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
218 bool AccessibilityAdaptorMobile::HandleActionReadEvent(unsigned int x, unsigned int y, bool allowReadAgain)
222 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %d , %d\n", __FUNCTION__, __LINE__, x, y);
227 Dali::AccessibilityAdaptor handle( this );
229 bool indicatorFocused = false;
231 // Check whether the Indicator is focused
232 if( mIndicator && mIndicator->IsConnected() )
234 // Check the position and size of Indicator actor
235 Dali::Actor indicatorActor = mIndicator->GetActor();
236 Vector3 position = Vector3(0.0f, 0.0f, 0.0f);
237 Vector3 size = indicatorActor.GetCurrentSize();
239 if(mReadPosition.x >= position.x &&
240 mReadPosition.x <= position.x + size.width &&
241 mReadPosition.y >= position.y &&
242 mReadPosition.y <= position.y + size.height)
244 indicatorFocused = true;
245 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] Indicator area!!!!\n", __FUNCTION__, __LINE__);
251 if( !mIndicatorFocused && indicatorFocused )
253 // If Indicator is focused, the focus should be cleared in Dali focus chain.
256 mActionHandler->ClearAccessibilityFocus();
259 else if( mIndicatorFocused && !indicatorFocused )
262 Elm_Access_Action_Info actionInfo;
263 actionInfo.action_type = ELM_ACCESS_ACTION_UNHIGHLIGHT;
265 // Indicator should be unhighlighted
266 ret = mIndicator->SendMessage(MSG_DOMAIN_CONTROL_ACCESS, actionInfo.action_type, &actionInfo, sizeof(actionInfo));
267 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] Send unhighlight message to indicator!!!!\n", __FUNCTION__, __LINE__);
271 mIndicatorFocused = indicatorFocused;
273 // Send accessibility READ action information to Indicator
274 if( mIndicatorFocused )
277 Elm_Access_Action_Info actionInfo;
278 actionInfo.x = mReadPosition.x;
279 actionInfo.y = mReadPosition.y;
283 actionInfo.action_type = ELM_ACCESS_ACTION_READ;
287 actionInfo.action_type = static_cast<Elm_Access_Action_Type>( GetElmAccessActionOver() );
290 ret = mIndicator->SendMessage(MSG_DOMAIN_CONTROL_ACCESS, actionInfo.action_type, &actionInfo, sizeof(actionInfo));
292 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] Send READ message to indicator!!!!\n", __FUNCTION__, __LINE__);
297 if( mActionHandler && !mIndicatorFocused)
299 // If Indicator is not focused, the accessibility actions should be handled by the registered
300 // accessibility action handler (e.g. focus manager)
301 ret = mActionHandler->AccessibilityActionRead(allowReadAgain);
302 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
308 bool AccessibilityAdaptorMobile::HandleActionReadNextEvent(bool allowEndFeedback)
313 if( mIndicator && mIndicatorFocused )
315 Elm_Access_Action_Info actionInfo;
316 actionInfo.action_type = ELM_ACCESS_ACTION_HIGHLIGHT_NEXT;
318 ret = mIndicator->SendMessage(MSG_DOMAIN_CONTROL_ACCESS, actionInfo.action_type, &actionInfo, sizeof(actionInfo));
320 else if( mActionHandler )
325 ret = mActionHandler->AccessibilityActionReadNext(allowEndFeedback);
328 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
333 bool AccessibilityAdaptorMobile::HandleActionReadPreviousEvent(bool allowEndFeedback)
338 if( mIndicator && mIndicatorFocused )
340 Elm_Access_Action_Info actionInfo;
341 actionInfo.action_type = ELM_ACCESS_ACTION_HIGHLIGHT_PREV;
343 ret = mIndicator->SendMessage(MSG_DOMAIN_CONTROL_ACCESS, actionInfo.action_type, &actionInfo, sizeof(actionInfo));
345 else if( mActionHandler )
350 ret = mActionHandler->AccessibilityActionReadPrevious(allowEndFeedback);
353 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
358 bool AccessibilityAdaptorMobile::HandleActionUpEvent()
363 if( mIndicator && mIndicatorFocused )
365 Elm_Access_Action_Info actionInfo;
366 actionInfo.action_type = ELM_ACCESS_ACTION_UP;
368 ret = mIndicator->SendMessage(MSG_DOMAIN_CONTROL_ACCESS, actionInfo.action_type, &actionInfo, sizeof(actionInfo));
370 else if( mActionHandler )
375 ret = mActionHandler->AccessibilityActionUp();
378 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
383 bool AccessibilityAdaptorMobile::HandleActionDownEvent()
388 if( mIndicator && mIndicatorFocused )
390 Elm_Access_Action_Info actionInfo;
391 actionInfo.action_type = ELM_ACCESS_ACTION_DOWN;
393 ret = mIndicator->SendMessage(MSG_DOMAIN_CONTROL_ACCESS, actionInfo.action_type, &actionInfo, sizeof(actionInfo));
395 else if( mActionHandler )
400 ret = mActionHandler->AccessibilityActionDown();
403 DALI_LOG_INFO(gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
408 AccessibilityAdaptorMobile::~AccessibilityAdaptorMobile()
412 } // namespace Adaptor
414 } // namespace Internal