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