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