Follow the include-order coding conventions
[platform/core/uifw/dali-adaptor.git] / adaptors / x11 / accessibility-manager-impl-x.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 // CLASS HEADER
19 #include "accessibility-manager-impl.h"
20
21 // EXTERNAL INCLUDES
22 #include <vconf.h>
23 #include <Ecore_X.h>
24 #include <Elementary.h>
25
26 #include <dali/public-api/dali-core.h>
27 #include <dali/integration-api/debug.h>
28 #include <dali/integration-api/events/gesture-requests.h>
29
30 // INTERNAL INCLUDES
31 #include "system-settings.h"
32
33 #define MSG_DOMAIN_CONTROL_ACCESS (int)ECORE_X_ATOM_E_ILLUME_ACCESS_CONTROL
34
35 namespace Dali
36 {
37
38 namespace Internal
39 {
40
41 namespace Adaptor
42 {
43
44 namespace {
45 #if defined(DEBUG_ENABLED)
46 Debug::Filter* gAccessibilityManagerLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_ACCESSIBILITY_MANAGER");
47 #endif
48 } // unnamed namespace
49
50 bool AccessibilityManager::HandleActionNextEvent(bool allowEndFeedback)
51 {
52   bool ret = false;
53   Dali::AccessibilityManager handle( this );
54
55   /*
56    * In order to application decide reading action first,
57    * emit ActionNext signal in first, AccessibilityActionNext for handler in next
58    */
59   if( !mIndicatorFocused )
60   {
61     if( !mActionNextSignal.Empty() )
62     {
63       mActionNextSignal.Emit( handle );
64     }
65   }
66
67   if( mIndicator && mIndicatorFocused )
68   {
69     Elm_Access_Action_Info actionInfo;
70     actionInfo.action_type = ELM_ACCESS_ACTION_HIGHLIGHT_NEXT;
71
72     ret = mIndicator->SendMessage(MSG_DOMAIN_CONTROL_ACCESS, actionInfo.action_type, &actionInfo, sizeof(actionInfo));
73   }
74   else if( mActionHandler )
75   {
76     ret = mActionHandler->AccessibilityActionNext(allowEndFeedback);
77   }
78
79   DALI_LOG_INFO(gAccessibilityManagerLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
80
81   return ret;
82 }
83
84 bool AccessibilityManager::HandleActionPreviousEvent(bool allowEndFeedback)
85 {
86   bool ret = false;
87
88   Dali::AccessibilityManager handle( this );
89
90    /*
91    * In order to application decide reading action first,
92    * emit ActionPrevious signal in first, AccessibilityActionPrevious for handler in next
93    */
94  if ( !mIndicatorFocused )
95   {
96     if( !mActionPreviousSignal.Empty() )
97     {
98       mActionPreviousSignal.Emit( handle );
99     }
100   }
101
102   if( mIndicator && mIndicatorFocused )
103   {
104     Elm_Access_Action_Info actionInfo;
105     actionInfo.action_type = ELM_ACCESS_ACTION_HIGHLIGHT_PREV;
106
107     ret = mIndicator->SendMessage(MSG_DOMAIN_CONTROL_ACCESS, actionInfo.action_type, &actionInfo, sizeof(actionInfo));
108   }
109   else if( mActionHandler )
110   {
111     ret = mActionHandler->AccessibilityActionPrevious(allowEndFeedback);
112   }
113
114   DALI_LOG_INFO(gAccessibilityManagerLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
115
116   return ret;
117 }
118
119 bool AccessibilityManager::HandleActionActivateEvent()
120 {
121   bool ret = false;
122
123   Dali::AccessibilityManager handle( this );
124
125   /*
126    * In order to application decide reading action first,
127    * emit ActionActivate signal in first, AccessibilityActionActivate for handler in next
128    */
129   if ( !mIndicatorFocused )
130   {
131     if( !mActionActivateSignal.Empty() )
132     {
133       mActionActivateSignal.Emit( handle );
134     }
135   }
136
137   if( mIndicator && mIndicatorFocused )
138   {
139     Elm_Access_Action_Info actionInfo;
140     actionInfo.action_type = ELM_ACCESS_ACTION_ACTIVATE;
141
142     ret = mIndicator->SendMessage(MSG_DOMAIN_CONTROL_ACCESS, actionInfo.action_type, &actionInfo, sizeof(actionInfo));
143   }
144   else if( mActionHandler )
145   {
146     ret = mActionHandler->AccessibilityActionActivate();
147   }
148
149   DALI_LOG_INFO(gAccessibilityManagerLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
150
151   return ret;
152 }
153
154 bool AccessibilityManager::HandleActionReadEvent(unsigned int x, unsigned int y, bool allowReadAgain)
155 {
156   bool ret = false;
157
158   DALI_LOG_INFO(gAccessibilityManagerLogFilter, Debug::General, "[%s:%d] %d , %d\n", __FUNCTION__, __LINE__, x, y);
159
160   mReadPosition.x = x;
161   mReadPosition.y = y;
162
163   Dali::AccessibilityManager handle( this );
164
165   bool indicatorFocused = false;
166
167   // Check whether the Indicator is focused
168   if( mIndicator && mIndicator->IsConnected() )
169   {
170     // Check the position and size of Indicator actor
171     Dali::Actor indicatorActor = mIndicator->GetActor();
172     Vector3 position = Vector3(0.0f, 0.0f, 0.0f);
173     Vector3 size = indicatorActor.GetCurrentSize();
174
175     if(mReadPosition.x >= position.x &&
176        mReadPosition.x <= position.x + size.width &&
177        mReadPosition.y >= position.y &&
178        mReadPosition.y <= position.y + size.height)
179     {
180       indicatorFocused = true;
181       DALI_LOG_INFO(gAccessibilityManagerLogFilter, Debug::General, "[%s:%d] Indicator area!!!!\n", __FUNCTION__, __LINE__);
182     }
183   }
184
185   if( mIndicator )
186   {
187     if( !mIndicatorFocused && indicatorFocused )
188     {
189       // If Indicator is focused, the focus should be cleared in Dali focus chain.
190       if( mActionHandler )
191       {
192         mActionHandler->ClearAccessibilityFocus();
193       }
194     }
195     else if( mIndicatorFocused && !indicatorFocused )
196     {
197       Elm_Access_Action_Info actionInfo;
198       actionInfo.action_type = ELM_ACCESS_ACTION_UNHIGHLIGHT;
199
200       // Indicator should be unhighlighted
201       ret = mIndicator->SendMessage(MSG_DOMAIN_CONTROL_ACCESS, actionInfo.action_type, &actionInfo, sizeof(actionInfo));
202       DALI_LOG_INFO(gAccessibilityManagerLogFilter, Debug::General, "[%s:%d] Send unhighlight message to indicator!!!!\n", __FUNCTION__, __LINE__);
203     }
204
205     mIndicatorFocused = indicatorFocused;
206
207     // Send accessibility READ action information to Indicator
208     if( mIndicatorFocused )
209     {
210       Elm_Access_Action_Info actionInfo;
211       actionInfo.x = mReadPosition.x;
212       actionInfo.y = mReadPosition.y;
213
214       if(allowReadAgain)
215       {
216         actionInfo.action_type = ELM_ACCESS_ACTION_READ;
217       }
218       else
219       {
220         actionInfo.action_type = static_cast<Elm_Access_Action_Type>( GetElmAccessActionOver() );
221       }
222
223       ret = mIndicator->SendMessage(MSG_DOMAIN_CONTROL_ACCESS, actionInfo.action_type, &actionInfo, sizeof(actionInfo));
224
225       DALI_LOG_INFO(gAccessibilityManagerLogFilter, Debug::General, "[%s:%d] Send READ message to indicator!!!!\n", __FUNCTION__, __LINE__);
226     }
227   }
228
229   if(allowReadAgain)
230   {
231     /*
232      * In order to application decide reading action first,
233      * emit ActionRead signal in first, AccessibilityActionRead for handler in next
234      */
235     if( !mIndicatorFocused )
236     {
237       if ( !mActionReadSignal.Empty() )
238       {
239         mActionReadSignal.Emit( handle );
240       }
241     }
242   }
243   else
244   {
245     /*
246      * In order to application decide reading action first,
247      * emit ActionRead signal in first, AccessibilityActionRead for handler in next
248      */
249     if( !mIndicatorFocused )
250     {
251       if ( !mActionOverSignal.Empty() )
252       {
253         mActionOverSignal.Emit( handle );
254       }
255     }
256   }
257
258   if( mActionHandler && !mIndicatorFocused)
259   {
260     // If Indicator is not focused, the accessibility actions should be handled by the registered
261     // accessibility action handler (e.g. focus manager)
262     ret = mActionHandler->AccessibilityActionRead(allowReadAgain);
263     DALI_LOG_INFO(gAccessibilityManagerLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
264   }
265
266   return ret;
267 }
268
269 bool AccessibilityManager::HandleActionReadNextEvent(bool allowEndFeedback)
270 {
271   bool ret = false;
272
273   Dali::AccessibilityManager handle( this );
274
275   /*
276    * In order to application decide reading action first,
277    * emit ActionReadNext signal in first, AccessibilityActionReadNext for handler in next
278    */
279   if ( !mIndicatorFocused )
280   {
281     if( !mActionReadNextSignal.Empty() )
282     {
283       mActionReadNextSignal.Emit( handle );
284     }
285   }
286
287   if( mIndicator && mIndicatorFocused )
288   {
289     Elm_Access_Action_Info actionInfo;
290     actionInfo.action_type = ELM_ACCESS_ACTION_HIGHLIGHT_NEXT;
291
292     ret = mIndicator->SendMessage(MSG_DOMAIN_CONTROL_ACCESS, actionInfo.action_type, &actionInfo, sizeof(actionInfo));
293   }
294   else if( mActionHandler )
295   {
296     ret = mActionHandler->AccessibilityActionReadNext(allowEndFeedback);
297   }
298
299   DALI_LOG_INFO(gAccessibilityManagerLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
300
301   return ret;
302 }
303
304 bool AccessibilityManager::HandleActionReadPreviousEvent(bool allowEndFeedback)
305 {
306   bool ret = false;
307
308   Dali::AccessibilityManager handle( this );
309
310   /*
311    * In order to application decide reading action first,
312    * emit ActionReadPrevious signal in first, AccessibilityActionReadPrevious for handler in next
313    */
314   if ( !mIndicatorFocused )
315   {
316     if( !mActionReadPreviousSignal.Empty() )
317     {
318       mActionReadPreviousSignal.Emit( handle );
319     }
320   }
321
322   if( mIndicator && mIndicatorFocused )
323   {
324     Elm_Access_Action_Info actionInfo;
325     actionInfo.action_type = ELM_ACCESS_ACTION_HIGHLIGHT_PREV;
326
327     ret = mIndicator->SendMessage(MSG_DOMAIN_CONTROL_ACCESS, actionInfo.action_type, &actionInfo, sizeof(actionInfo));
328   }
329   else if( mActionHandler )
330   {
331     ret = mActionHandler->AccessibilityActionReadPrevious(allowEndFeedback);
332   }
333
334   DALI_LOG_INFO(gAccessibilityManagerLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
335
336   return ret;
337 }
338
339 bool AccessibilityManager::HandleActionUpEvent()
340 {
341   bool ret = false;
342
343   Dali::AccessibilityManager handle( this );
344
345   /*
346    * In order to application decide reading action first,
347    * emit ActionUp signal in first, AccessibilityActionUp for handler in next
348    */
349   if ( !mIndicatorFocused )
350   {
351     if( !mActionUpSignal.Empty() )
352     {
353       mActionUpSignal.Emit( handle );
354     }
355   }
356
357   if( mIndicator && mIndicatorFocused )
358   {
359     Elm_Access_Action_Info actionInfo;
360     actionInfo.action_type = ELM_ACCESS_ACTION_UP;
361
362     ret = mIndicator->SendMessage(MSG_DOMAIN_CONTROL_ACCESS, actionInfo.action_type, &actionInfo, sizeof(actionInfo));
363   }
364   else if( mActionHandler )
365   {
366     ret = mActionHandler->AccessibilityActionUp();
367   }
368
369   DALI_LOG_INFO(gAccessibilityManagerLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
370
371   return ret;
372 }
373
374 bool AccessibilityManager::HandleActionDownEvent()
375 {
376   bool ret = false;
377
378   Dali::AccessibilityManager handle( this );
379
380   /*
381    * In order to application decide reading action first,
382    * emit ActionDown signal in first, AccessibilityActionDown for handler in next
383    */
384   if ( !mIndicatorFocused )
385   {
386     if( !mActionDownSignal.Empty() )
387     {
388       mActionDownSignal.Emit( handle );
389     }
390   }
391
392   if( mIndicator && mIndicatorFocused )
393   {
394     Elm_Access_Action_Info actionInfo;
395     actionInfo.action_type = ELM_ACCESS_ACTION_DOWN;
396
397     ret = mIndicator->SendMessage(MSG_DOMAIN_CONTROL_ACCESS, actionInfo.action_type, &actionInfo, sizeof(actionInfo));
398   }
399   else if( mActionHandler )
400   {
401     ret = mActionHandler->AccessibilityActionDown();
402   }
403
404   DALI_LOG_INFO(gAccessibilityManagerLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, ret?"TRUE":"FALSE");
405
406   return ret;
407 }
408
409 } // namespace Adaptor
410
411 } // namespace Internal
412
413 } // namespace Dali