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