Revert "[Tizen] ecore-wl2: applying ecore-wl2"
[platform/core/uifw/dali-adaptor.git] / dali / internal / window-system / tizen-wayland / event-handler-ecore-wl.cpp
1 /*
2  * Copyright (c) 2017 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 <dali/internal/window-system/common/event-handler.h>
20
21 // EXTERNAL INCLUDES
22 // Ecore is littered with C style cast
23 #pragma GCC diagnostic push
24 #pragma GCC diagnostic ignored "-Wold-style-cast"
25 #include <Ecore.h>
26 #include <Ecore_Input.h>
27 #include <Ecore_IMF.h>
28 #include <dali/integration-api/wayland/ecore-wl-render-surface.h>
29 //#include <dali/window-system/tizen-wayland/window-render-surface-ecore-wl.h>
30 #include <cstring>
31
32 #include <sys/time.h>
33
34 #ifndef DALI_PROFILE_UBUNTU
35 #include <vconf.h>
36 #include <vconf-keys.h>
37 #endif // DALI_PROFILE_UBUNTU
38
39 #ifdef DALI_ELDBUS_AVAILABLE
40 #include <Eldbus.h>
41 #endif // DALI_ELDBUS_AVAILABLE
42
43 #include <dali/public-api/common/vector-wrapper.h>
44 #include <dali/public-api/events/device.h>
45 #include <dali/public-api/events/touch-point.h>
46 #include <dali/public-api/events/key-event.h>
47 #include <dali/public-api/events/wheel-event.h>
48 #include <dali/integration-api/debug.h>
49 #include <dali/integration-api/events/key-event-integ.h>
50 #include <dali/integration-api/events/touch-event-integ.h>
51 #include <dali/integration-api/events/hover-event-integ.h>
52 #include <dali/integration-api/events/wheel-event-integ.h>
53
54 // INTERNAL INCLUDES
55 #include <dali/internal/input/common/gesture-manager.h>
56 #include <dali/internal/window-system/tizen-wayland/window-render-surface-ecore-wl.h>
57 #include <dali/internal/clipboard/common/clipboard-impl.h>
58 #include <dali/internal/input/common/key-impl.h>
59 #include <dali/internal/input/common/physical-keyboard-impl.h>
60 #include <dali/internal/styling/common/style-monitor-impl.h>
61 #include <dali/internal/system/common/core-event-interface.h>
62 #include <dali/devel-api/adaptor-framework/virtual-keyboard.h>
63
64 namespace Dali
65 {
66
67 namespace Internal
68 {
69
70 namespace Adaptor
71 {
72
73 #if defined(DEBUG_ENABLED)
74 namespace
75 {
76 Integration::Log::Filter* gTouchEventLogFilter  = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_TOUCH");
77 Integration::Log::Filter* gDragAndDropLogFilter = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_DND");
78 Integration::Log::Filter* gImfLogging  = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_IMF");
79 Integration::Log::Filter* gSelectionEventLogFilter = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_SELECTION");
80 } // unnamed namespace
81 #endif
82
83
84 namespace
85 {
86
87 // DBUS accessibility
88 const char* BUS = "org.enlightenment.wm-screen-reader";
89 const char* INTERFACE = "org.tizen.GestureNavigation";
90 const char* PATH = "/org/tizen/GestureNavigation";
91
92 const unsigned int PRIMARY_TOUCH_BUTTON_ID( 1 );
93
94 const unsigned int BYTES_PER_CHARACTER_FOR_ATTRIBUTES = 3;
95
96 #ifdef DALI_ELDBUS_AVAILABLE
97 // DBus gesture string matching lists.
98 // TODO: This needs moving to its own module.
99 const char * ElDBusAccessibilityFingerCountStrings[] =
100 {
101   "OneFinger",
102   "TwoFingers",
103   "ThreeFingers"
104 };
105 const unsigned int FingerCountStringsTotal = sizeof( ElDBusAccessibilityFingerCountStrings ) / sizeof( ElDBusAccessibilityFingerCountStrings[0] );
106 enum GestureType
107 {
108   GESTURE_TYPE_NONE,
109   GESTURE_TYPE_HOVER,
110   GESTURE_TYPE_SINGLE_TAP,
111   GESTURE_TYPE_DOUBLE_TAP,
112   GESTURE_TYPE_TRIPLE_TAP
113 };
114 struct GestureTypeTable
115 {
116   const char* name;
117   const GestureType type;
118 };
119 GestureTypeTable ElDBusAccessibilityFullEventTypeStrings[] =
120 {
121   { "Hover",     GESTURE_TYPE_HOVER      },
122   { "SingleTap", GESTURE_TYPE_SINGLE_TAP },
123   { "DoubleTap", GESTURE_TYPE_DOUBLE_TAP },
124   { "TripleTap", GESTURE_TYPE_TRIPLE_TAP }
125 };
126 const unsigned int FullEventTypeStringsTotal = sizeof( ElDBusAccessibilityFullEventTypeStrings ) / sizeof( ElDBusAccessibilityFullEventTypeStrings[0] );
127 enum SubGestureType
128 {
129   SUB_GESTURE_TYPE_NONE,
130   SUB_GESTURE_TYPE_FLICK
131 };
132 struct SubGestureTypeTable
133 {
134   const char* name;
135   const SubGestureType type;
136 };
137 SubGestureTypeTable ElDBusAccessibilityDirectionalEventTypeStrings[] =
138 {
139   { "Flick", SUB_GESTURE_TYPE_FLICK }
140 };
141 const unsigned int DirectionalEventTypeStringsTotal = sizeof( ElDBusAccessibilityDirectionalEventTypeStrings ) / sizeof( ElDBusAccessibilityDirectionalEventTypeStrings[0] );
142 enum GestureDirection
143 {
144   GESTURE_DIRECTION_NONE,
145   GESTURE_DIRECTION_UP,
146   GESTURE_DIRECTION_DOWN,
147   GESTURE_DIRECTION_LEFT,
148   GESTURE_DIRECTION_RIGHT,
149   GESTURE_DIRECTION_UP_RETURN,
150   GESTURE_DIRECTION_DOWN_RETURN,
151   GESTURE_DIRECTION_LEFT_RETURN,
152   GESTURE_DIRECTION_RIGHT_RETURN
153 };
154 struct GestureDirectionTable
155 {
156     const char* name;
157     const GestureDirection direction;
158 };
159 GestureDirectionTable ElDBusAccessibilityDirectionStrings[] =
160 {
161   { "Up",           GESTURE_DIRECTION_UP           },
162   { "Down",         GESTURE_DIRECTION_DOWN         },
163   { "Left",         GESTURE_DIRECTION_LEFT         },
164   { "Right",        GESTURE_DIRECTION_RIGHT        },
165   { "UpReturn",     GESTURE_DIRECTION_UP_RETURN    },
166   { "DownReturn",   GESTURE_DIRECTION_DOWN_RETURN  },
167   { "LeftReturn",   GESTURE_DIRECTION_LEFT_RETURN  },
168   { "RightReturn",  GESTURE_DIRECTION_RIGHT_RETURN }
169 };
170 const unsigned int DirectionStringsTotal = sizeof( ElDBusAccessibilityDirectionStrings ) / sizeof( ElDBusAccessibilityDirectionStrings[0] );
171 #endif // DALI_ELDBUS_AVAILABLE
172
173 /**
174  * EcoreInputModifierToEcoreIMFLock function converts from Ecore_Event_Modifier to Ecore_IMF_Keyboard_Locks enums.
175  * @param[in] modifier the Ecore_Event_Modifier input.
176  * @return the Ecore_IMF_Keyboard_Locks output.
177  */
178 Ecore_IMF_Keyboard_Locks EcoreInputModifierToEcoreIMFLock( unsigned int modifier )
179 {
180     unsigned int lock( ECORE_IMF_KEYBOARD_LOCK_NONE ); // If no other matches, returns NONE.
181
182     if( modifier & ECORE_EVENT_LOCK_NUM )
183     {
184       lock |= ECORE_IMF_KEYBOARD_LOCK_NUM; // Num lock is active.
185     }
186
187     if( modifier & ECORE_EVENT_LOCK_CAPS )
188     {
189       lock |= ECORE_IMF_KEYBOARD_LOCK_CAPS; // Caps lock is active.
190     }
191
192     if( modifier & ECORE_EVENT_LOCK_SCROLL )
193     {
194       lock |= ECORE_IMF_KEYBOARD_LOCK_SCROLL; // Scroll lock is active.
195     }
196
197     return static_cast<Ecore_IMF_Keyboard_Locks>( lock );
198 }
199
200 /**
201  * Ecore_Event_Modifier enums in Ecore_Input.h do not match Ecore_IMF_Keyboard_Modifiers in Ecore_IMF.h.
202  * This function converts from Ecore_Event_Modifier to Ecore_IMF_Keyboard_Modifiers enums.
203  * @param[in] ecoreModifier the Ecore_Event_Modifier input.
204  * @return the Ecore_IMF_Keyboard_Modifiers output.
205  */
206 Ecore_IMF_Keyboard_Modifiers EcoreInputModifierToEcoreIMFModifier(unsigned int ecoreModifier)
207 {
208    unsigned int modifier( ECORE_IMF_KEYBOARD_MODIFIER_NONE );  // If no other matches returns NONE.
209
210
211    if ( ecoreModifier & ECORE_EVENT_MODIFIER_SHIFT )  // enums from ecore_input/Ecore_Input.h
212    {
213      modifier |= ECORE_IMF_KEYBOARD_MODIFIER_SHIFT;  // enums from ecore_imf/ecore_imf.h
214    }
215
216    if ( ecoreModifier & ECORE_EVENT_MODIFIER_ALT )
217    {
218      modifier |= ECORE_IMF_KEYBOARD_MODIFIER_ALT;
219    }
220
221    if ( ecoreModifier & ECORE_EVENT_MODIFIER_CTRL )
222    {
223      modifier |= ECORE_IMF_KEYBOARD_MODIFIER_CTRL;
224    }
225
226    if ( ecoreModifier & ECORE_EVENT_MODIFIER_WIN )
227    {
228      modifier |= ECORE_IMF_KEYBOARD_MODIFIER_WIN;
229    }
230
231    if ( ecoreModifier & ECORE_EVENT_MODIFIER_ALTGR )
232    {
233      modifier |= ECORE_IMF_KEYBOARD_MODIFIER_ALTGR;
234    }
235
236    return static_cast<Ecore_IMF_Keyboard_Modifiers>( modifier );
237 }
238
239
240 // Copied from x server
241 static unsigned int GetCurrentMilliSeconds(void)
242 {
243   struct timeval tv;
244
245   struct timespec tp;
246   static clockid_t clockid;
247
248   if (!clockid)
249   {
250 #ifdef CLOCK_MONOTONIC_COARSE
251     if (clock_getres(CLOCK_MONOTONIC_COARSE, &tp) == 0 &&
252       (tp.tv_nsec / 1000) <= 1000 && clock_gettime(CLOCK_MONOTONIC_COARSE, &tp) == 0)
253     {
254       clockid = CLOCK_MONOTONIC_COARSE;
255     }
256     else
257 #endif
258     if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0)
259     {
260       clockid = CLOCK_MONOTONIC;
261     }
262     else
263     {
264       clockid = ~0L;
265     }
266   }
267   if (clockid != ~0L && clock_gettime(clockid, &tp) == 0)
268   {
269     return (tp.tv_sec * 1000) + (tp.tv_nsec / 1000000L);
270   }
271
272   gettimeofday(&tv, NULL);
273   return (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
274 }
275
276 #ifndef DALI_PROFILE_UBUNTU
277 const char * DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE = "db/setting/accessibility/font_name";  // It will be update at vconf-key.h and replaced.
278 #endif // DALI_PROFILE_UBUNTU
279
280 /**
281  * Get the device name from the provided ecore key event
282  */
283 void GetDeviceName( Ecore_Event_Key* keyEvent, std::string& result )
284 {
285   const char* ecoreDeviceName = ecore_device_name_get( keyEvent->dev );
286
287   if ( ecoreDeviceName )
288   {
289     result = ecoreDeviceName;
290   }
291 }
292
293 /**
294  * Get the device class from the provided ecore event
295  */
296 void GetDeviceClass( Ecore_Device_Class ecoreDeviceClass, Device::Class::Type& deviceClass )
297 {
298   switch( ecoreDeviceClass )
299   {
300     case ECORE_DEVICE_CLASS_SEAT:
301     {
302       deviceClass = Device::Class::USER;
303       break;
304     }
305     case ECORE_DEVICE_CLASS_KEYBOARD:
306     {
307       deviceClass = Device::Class::KEYBOARD;
308       break;
309     }
310     case ECORE_DEVICE_CLASS_MOUSE:
311     {
312       deviceClass = Device::Class::MOUSE;
313       break;
314     }
315     case ECORE_DEVICE_CLASS_TOUCH:
316     {
317       deviceClass = Device::Class::TOUCH;
318       break;
319     }
320     case ECORE_DEVICE_CLASS_PEN:
321     {
322       deviceClass = Device::Class::PEN;
323       break;
324     }
325     case ECORE_DEVICE_CLASS_POINTER:
326     {
327       deviceClass = Device::Class::POINTER;
328       break;
329     }
330     case ECORE_DEVICE_CLASS_GAMEPAD:
331     {
332       deviceClass = Device::Class::GAMEPAD;
333       break;
334     }
335     default:
336     {
337       deviceClass = Device::Class::NONE;
338       break;
339     }
340   }
341 }
342
343 void GetDeviceSubclass( Ecore_Device_Subclass ecoreDeviceSubclass, Device::Subclass::Type& deviceSubclass )
344 {
345   switch( ecoreDeviceSubclass )
346   {
347     case ECORE_DEVICE_SUBCLASS_FINGER:
348     {
349       deviceSubclass = Device::Subclass::FINGER;
350       break;
351     }
352     case ECORE_DEVICE_SUBCLASS_FINGERNAIL:
353     {
354       deviceSubclass = Device::Subclass::FINGERNAIL;
355       break;
356     }
357     case ECORE_DEVICE_SUBCLASS_KNUCKLE:
358     {
359       deviceSubclass = Device::Subclass::KNUCKLE;
360       break;
361     }
362     case ECORE_DEVICE_SUBCLASS_PALM:
363     {
364       deviceSubclass = Device::Subclass::PALM;
365       break;
366     }
367     case ECORE_DEVICE_SUBCLASS_HAND_SIZE:
368     {
369       deviceSubclass = Device::Subclass::HAND_SIDE;
370       break;
371     }
372     case ECORE_DEVICE_SUBCLASS_HAND_FLAT:
373     {
374       deviceSubclass = Device::Subclass::HAND_FLAT;
375       break;
376     }
377     case ECORE_DEVICE_SUBCLASS_PEN_TIP:
378     {
379       deviceSubclass = Device::Subclass::PEN_TIP;
380       break;
381     }
382     case ECORE_DEVICE_SUBCLASS_TRACKPAD:
383     {
384       deviceSubclass = Device::Subclass::TRACKPAD;
385       break;
386     }
387     case ECORE_DEVICE_SUBCLASS_TRACKPOINT:
388     {
389       deviceSubclass = Device::Subclass::TRACKPOINT;
390       break;
391     }
392     case ECORE_DEVICE_SUBCLASS_TRACKBALL:
393     {
394       deviceSubclass = Device::Subclass::TRACKBALL;
395       break;
396     }
397 #ifdef OVER_TIZEN_VERSION_4
398     case ECORE_DEVICE_SUBCLASS_REMOCON:
399     {
400       deviceSubclass = Device::Subclass::REMOCON;
401       break;
402     }
403     case ECORE_DEVICE_SUBCLASS_VIRTUAL_KEYBOARD:
404     {
405       deviceSubclass = Device::Subclass::VIRTUAL_KEYBOARD;
406       break;
407     }
408 #endif
409     default:
410     {
411       deviceSubclass = Device::Subclass::NONE;
412       break;
413     }
414   }
415 }
416
417 } // unnamed namespace
418
419 // Impl to hide EFL implementation.
420 struct EventHandler::Impl
421 {
422   // Construction & Destruction
423
424   /**
425    * Constructor
426    */
427   Impl( EventHandler* handler, Ecore_Wl_Window* window )
428   : mHandler( handler ),
429     mEcoreEventHandler(),
430     mWindow( window ),
431     mRotationAngle( 0 ),
432     mWindowWidth( 0 ),
433     mWindowHeight( 0 )
434 #ifdef DALI_ELDBUS_AVAILABLE
435   , mSystemConnection( NULL )
436 #endif // DALI_ELDBUS_AVAILABLE
437   {
438     // Only register for touch and key events if we have a window
439     if ( window != 0 )
440     {
441       // Register Touch events
442       mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_BUTTON_DOWN,   EcoreEventMouseButtonDown,   handler ) );
443       mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_BUTTON_UP,     EcoreEventMouseButtonUp,     handler ) );
444       mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_MOVE,          EcoreEventMouseButtonMove,   handler ) );
445       mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_BUTTON_CANCEL, EcoreEventMouseButtonCancel, handler ) );
446
447       // Register Mouse wheel events
448       mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_WHEEL,        EcoreEventMouseWheel,      handler ) );
449
450       // Register Focus events
451       mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_WL_EVENT_FOCUS_IN,  EcoreEventWindowFocusIn,   handler ) );
452       mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_WL_EVENT_FOCUS_OUT, EcoreEventWindowFocusOut,  handler ) );
453
454       // Register Key events
455       mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_KEY_DOWN,           EcoreEventKeyDown,         handler ) );
456       mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_KEY_UP,             EcoreEventKeyUp,           handler ) );
457
458       // Register Selection event - clipboard selection
459       mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_WL_EVENT_DATA_SOURCE_SEND, EcoreEventDataSend, handler ) );
460       mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_WL_EVENT_SELECTION_DATA_READY, EcoreEventDataReceive, handler ) );
461
462       // Register Rotate event
463       mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_WL_EVENT_WINDOW_ROTATE, EcoreEventRotate, handler) );
464
465       // Register Detent event
466       mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_DETENT_ROTATE, EcoreEventDetent, handler) );
467
468 #ifndef DALI_PROFILE_UBUNTU
469       // Register Vconf notify - font name and size
470       vconf_notify_key_changed( DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontNameChanged, handler );
471       vconf_notify_key_changed( VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontSizeChanged, handler );
472 #endif // DALI_PROFILE_UBUNTU
473
474 #ifdef DALI_ELDBUS_AVAILABLE
475       // Initialize ElDBus.
476       DALI_LOG_INFO( gImfLogging, Debug::General, "Starting DBus Initialization\n" );
477
478       // Pass in handler.
479       EcoreElDBusInitialisation( handler );
480
481       DALI_LOG_INFO( gImfLogging, Debug::General, "Finished DBus Initialization\n" );
482 #endif // DALI_ELDBUS_AVAILABLE
483     }
484   }
485
486   /**
487    * Destructor
488    */
489   ~Impl()
490   {
491 #ifndef DALI_PROFILE_UBUNTU
492     vconf_ignore_key_changed( VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontSizeChanged );
493     vconf_ignore_key_changed( DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontNameChanged );
494 #endif // DALI_PROFILE_UBUNTU
495
496     for( std::vector<Ecore_Event_Handler*>::iterator iter = mEcoreEventHandler.begin(), endIter = mEcoreEventHandler.end(); iter != endIter; ++iter )
497     {
498       ecore_event_handler_del( *iter );
499     }
500
501 #ifdef DALI_ELDBUS_AVAILABLE
502     // Close down ElDBus connections.
503     if( mSystemConnection )
504     {
505       eldbus_connection_unref( mSystemConnection );
506     }
507 #endif // DALI_ELDBUS_AVAILABLE
508   }
509
510   // Static methods
511
512   /////////////////////////////////////////////////////////////////////////////////////////////////
513   // Touch Callbacks
514   /////////////////////////////////////////////////////////////////////////////////////////////////
515
516   /**
517    * Called when a touch down is received.
518    */
519   static Eina_Bool EcoreEventMouseButtonDown( void* data, int type, void* event )
520   {
521     Ecore_Event_Mouse_Button *touchEvent( (Ecore_Event_Mouse_Button*)event );
522     EventHandler* handler( (EventHandler*)data );
523
524     if ( touchEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
525     {
526       PointState::Type state ( PointState::DOWN );
527
528       // Check if the buttons field is set and ensure it's the primary touch button.
529       // If this event was triggered by buttons other than the primary button (used for touch), then
530       // just send an interrupted event to Core.
531       if ( touchEvent->buttons && (touchEvent->buttons != PRIMARY_TOUCH_BUTTON_ID ) )
532       {
533         state = PointState::INTERRUPTED;
534       }
535
536       Device::Class::Type deviceClass;
537       Device::Subclass::Type deviceSubclass;
538
539       GetDeviceClass( ecore_device_class_get( touchEvent->dev ), deviceClass );
540       GetDeviceSubclass( ecore_device_subclass_get( touchEvent->dev ), deviceSubclass );
541
542       Integration::Point point;
543       point.SetDeviceId( touchEvent->multi.device );
544       point.SetState( state );
545       point.SetScreenPosition( Vector2( touchEvent->x, touchEvent->y ) );
546       point.SetRadius( touchEvent->multi.radius, Vector2( touchEvent->multi.radius_x, touchEvent->multi.radius_y ) );
547       point.SetPressure( touchEvent->multi.pressure );
548       point.SetAngle( Degree( touchEvent->multi.angle ) );
549       point.SetDeviceClass( deviceClass );
550       point.SetDeviceSubclass( deviceSubclass );
551
552       handler->SendEvent( point, touchEvent->timestamp );
553     }
554
555     return ECORE_CALLBACK_PASS_ON;
556   }
557
558   /**
559    * Called when a touch up is received.
560    */
561   static Eina_Bool EcoreEventMouseButtonUp( void* data, int type, void* event )
562   {
563     Ecore_Event_Mouse_Button *touchEvent( (Ecore_Event_Mouse_Button*)event );
564     EventHandler* handler( (EventHandler*)data );
565
566     if ( touchEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
567     {
568       Device::Class::Type deviceClass;
569       Device::Subclass::Type deviceSubclass;
570
571       GetDeviceClass( ecore_device_class_get( touchEvent->dev ), deviceClass );
572       GetDeviceSubclass( ecore_device_subclass_get( touchEvent->dev ), deviceSubclass );
573
574       Integration::Point point;
575       point.SetDeviceId( touchEvent->multi.device );
576       point.SetState( PointState::UP );
577       point.SetScreenPosition( Vector2( touchEvent->x, touchEvent->y ) );
578       point.SetRadius( touchEvent->multi.radius, Vector2( touchEvent->multi.radius_x, touchEvent->multi.radius_y ) );
579       point.SetPressure( touchEvent->multi.pressure );
580       point.SetAngle( Degree( touchEvent->multi.angle ) );
581       point.SetDeviceClass( deviceClass );
582       point.SetDeviceSubclass( deviceSubclass );
583
584       handler->SendEvent( point, touchEvent->timestamp );
585     }
586
587     return ECORE_CALLBACK_PASS_ON;
588   }
589
590   /**
591    * Called when a touch motion is received.
592    */
593   static Eina_Bool EcoreEventMouseButtonMove( void* data, int type, void* event )
594   {
595     Ecore_Event_Mouse_Move *touchEvent( (Ecore_Event_Mouse_Move*)event );
596     EventHandler* handler( (EventHandler*)data );
597
598     if ( touchEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
599     {
600       Device::Class::Type deviceClass;
601       Device::Subclass::Type deviceSubclass;
602
603       GetDeviceClass( ecore_device_class_get( touchEvent->dev ), deviceClass );
604       GetDeviceSubclass( ecore_device_subclass_get( touchEvent->dev ), deviceSubclass );
605
606       Integration::Point point;
607       point.SetDeviceId( touchEvent->multi.device );
608       point.SetState( PointState::MOTION );
609       point.SetScreenPosition( Vector2( touchEvent->x, touchEvent->y ) );
610       point.SetRadius( touchEvent->multi.radius, Vector2( touchEvent->multi.radius_x, touchEvent->multi.radius_y ) );
611       point.SetPressure( touchEvent->multi.pressure );
612       point.SetAngle( Degree( touchEvent->multi.angle ) );
613       point.SetDeviceClass( deviceClass );
614       point.SetDeviceSubclass( deviceSubclass );
615
616       handler->SendEvent( point, touchEvent->timestamp );
617     }
618
619     return ECORE_CALLBACK_PASS_ON;
620   }
621
622   /**
623    * Called when a touch is canceled.
624    */
625   static Eina_Bool EcoreEventMouseButtonCancel( void* data, int type, void* event )
626   {
627     Ecore_Event_Mouse_Button *touchEvent( (Ecore_Event_Mouse_Button*)event );
628     EventHandler* handler( (EventHandler*)data );
629
630     if( touchEvent->window == (unsigned int)ecore_wl_window_id_get( handler->mImpl->mWindow ) )
631     {
632       Integration::Point point;
633       point.SetDeviceId( touchEvent->multi.device );
634       point.SetState( PointState::INTERRUPTED );
635       point.SetScreenPosition( Vector2( 0.0f, 0.0f ) );
636       handler->SendEvent( point, touchEvent->timestamp );
637
638       DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT EcoreEventMouseButtonCancel\n" );
639     }
640
641     return ECORE_CALLBACK_PASS_ON;
642   }
643
644   /**
645    * Called when a mouse wheel is received.
646    */
647   static Eina_Bool EcoreEventMouseWheel( void* data, int type, void* event )
648   {
649     Ecore_Event_Mouse_Wheel *mouseWheelEvent( (Ecore_Event_Mouse_Wheel*)event );
650
651     DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT Ecore_Event_Mouse_Wheel: direction: %d, modifiers: %d, x: %d, y: %d, z: %d\n", mouseWheelEvent->direction, mouseWheelEvent->modifiers, mouseWheelEvent->x, mouseWheelEvent->y, mouseWheelEvent->z);
652
653     EventHandler* handler( (EventHandler*)data );
654     if ( mouseWheelEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
655     {
656       WheelEvent wheelEvent( WheelEvent::MOUSE_WHEEL, mouseWheelEvent->direction, mouseWheelEvent->modifiers, Vector2(mouseWheelEvent->x, mouseWheelEvent->y), mouseWheelEvent->z, mouseWheelEvent->timestamp );
657       handler->SendWheelEvent( wheelEvent );
658     }
659     return ECORE_CALLBACK_PASS_ON;
660   }
661
662   /////////////////////////////////////////////////////////////////////////////////////////////////
663   // Key Callbacks
664   /////////////////////////////////////////////////////////////////////////////////////////////////
665
666   /**
667    * Called when a key down is received.
668    */
669   static Eina_Bool EcoreEventKeyDown( void* data, int type, void* event )
670   {
671     DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventKeyDown \n" );
672
673     EventHandler* handler( (EventHandler*)data );
674     Ecore_Event_Key *keyEvent( (Ecore_Event_Key*)event );
675     bool eventHandled( false );
676
677     // If a device key then skip ecore_imf_context_filter_event.
678     if ( ! KeyLookup::IsDeviceButton( keyEvent->keyname ) )
679     {
680       Ecore_IMF_Context* imfContext = NULL;
681       Dali::ImfManager imfManager( ImfManager::Get() );
682       if ( imfManager )
683       {
684         imfContext = reinterpret_cast<Ecore_IMF_Context*>(ImfManager::GetImplementation( imfManager ).GetContext());
685       }
686
687       if ( imfContext )
688       {
689         // We're consuming key down event so we have to pass to IMF so that it can parse it as well.
690         Ecore_IMF_Event_Key_Down ecoreKeyDownEvent;
691         ecoreKeyDownEvent.keyname   = keyEvent->keyname;
692         ecoreKeyDownEvent.key       = keyEvent->key;
693         ecoreKeyDownEvent.string    = keyEvent->string;
694         ecoreKeyDownEvent.compose   = keyEvent->compose;
695         ecoreKeyDownEvent.timestamp = keyEvent->timestamp;
696         ecoreKeyDownEvent.modifiers = EcoreInputModifierToEcoreIMFModifier ( keyEvent->modifiers );
697         ecoreKeyDownEvent.locks     = EcoreInputModifierToEcoreIMFLock( keyEvent->modifiers );
698         ecoreKeyDownEvent.dev_name  = ecore_device_name_get( keyEvent->dev );
699         ecoreKeyDownEvent.dev_class = static_cast<Ecore_IMF_Device_Class>( ecore_device_class_get( keyEvent->dev ) );
700         ecoreKeyDownEvent.dev_subclass = static_cast<Ecore_IMF_Device_Subclass>( ecore_device_subclass_get( keyEvent->dev ) );
701
702         std::string checkDevice;
703         GetDeviceName( keyEvent, checkDevice );
704
705         // If the device is IME and the focused key is the direction keys, then we should send a key event to move a key cursor.
706         if( ( checkDevice == "ime" ) && ( ( !strncmp( keyEvent->keyname, "Left",  4 ) ) ||
707                                           ( !strncmp( keyEvent->keyname, "Right", 5 ) ) ||
708                                           ( !strncmp( keyEvent->keyname, "Up",    2 ) ) ||
709                                           ( !strncmp( keyEvent->keyname, "Down",  4 ) ) ) )
710         {
711           eventHandled = 0;
712         }
713         else
714         {
715           eventHandled = ecore_imf_context_filter_event( imfContext,
716                                                          ECORE_IMF_EVENT_KEY_DOWN,
717                                                          (Ecore_IMF_Event *) &ecoreKeyDownEvent );
718         }
719
720         // If the event has not been handled by IMF then check if we should reset our IMF context
721         if( !eventHandled )
722         {
723           if ( !strcmp( keyEvent->keyname, "Escape"   ) ||
724                !strcmp( keyEvent->keyname, "Return"   ) ||
725                !strcmp( keyEvent->keyname, "KP_Enter" ) )
726           {
727             ecore_imf_context_reset( imfContext );
728           }
729         }
730       }
731     }
732
733     // If the event wasn't handled then we should send a key event.
734     if ( !eventHandled )
735     {
736       if ( keyEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
737       {
738         std::string keyName( keyEvent->keyname );
739         std::string keyString( "" );
740         int keyCode = KeyLookup::GetDaliKeyCode( keyEvent->keyname);
741         keyCode = (keyCode == -1) ? 0 : keyCode;
742         int modifier( keyEvent->modifiers );
743         unsigned long time = keyEvent->timestamp;
744         if (!strncmp(keyEvent->keyname, "Keycode-", 8))
745           keyCode = atoi(keyEvent->keyname + 8);
746
747         // Ensure key event string is not NULL as keys like SHIFT have a null string.
748         if ( keyEvent->string )
749         {
750           keyString = keyEvent->string;
751         }
752
753         std::string deviceName;
754         Device::Class::Type deviceClass;
755         Device::Subclass::Type deviceSubclass;
756
757         GetDeviceName( keyEvent, deviceName );
758         GetDeviceClass( ecore_device_class_get( keyEvent->dev ), deviceClass );
759         GetDeviceSubclass( ecore_device_subclass_get( keyEvent->dev ), deviceSubclass );
760
761         DALI_LOG_INFO( gImfLogging, Debug::Verbose, "EVENT EcoreEventKeyDown - >>EcoreEventKeyDown deviceName(%s) deviceClass(%d)\n", deviceName.c_str(), deviceClass );
762
763         Integration::KeyEvent keyEvent(keyName, keyString, keyCode, modifier, time, Integration::KeyEvent::Down, deviceName, deviceClass, deviceSubclass );
764         handler->SendEvent( keyEvent );
765       }
766     }
767
768     return ECORE_CALLBACK_PASS_ON;
769   }
770
771   /**
772    * Called when a key up is received.
773    */
774   static Eina_Bool EcoreEventKeyUp( void* data, int type, void* event )
775   {
776     DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventKeyUp\n" );
777
778     EventHandler* handler( (EventHandler*)data );
779     Ecore_Event_Key *keyEvent( (Ecore_Event_Key*)event );
780     bool eventHandled( false );
781
782     // Device keys like Menu, home, back button must skip ecore_imf_context_filter_event.
783     if ( ! KeyLookup::IsDeviceButton( keyEvent->keyname ) )
784     {
785       Ecore_IMF_Context* imfContext = NULL;
786       Dali::ImfManager imfManager( ImfManager::Get() );
787       if ( imfManager )
788       {
789         imfContext = reinterpret_cast<Ecore_IMF_Context*>(ImfManager::GetImplementation( imfManager ).GetContext());
790       }
791
792       if ( imfContext )
793       {
794         // We're consuming key up event so we have to pass to IMF so that it can parse it as well.
795         Ecore_IMF_Event_Key_Up ecoreKeyUpEvent;
796         ecoreKeyUpEvent.keyname   = keyEvent->keyname;
797         ecoreKeyUpEvent.key       = keyEvent->key;
798         ecoreKeyUpEvent.string    = keyEvent->string;
799         ecoreKeyUpEvent.compose   = keyEvent->compose;
800         ecoreKeyUpEvent.timestamp = keyEvent->timestamp;
801         ecoreKeyUpEvent.modifiers = EcoreInputModifierToEcoreIMFModifier ( keyEvent->modifiers );
802         ecoreKeyUpEvent.locks     = EcoreInputModifierToEcoreIMFLock( keyEvent->modifiers );
803         ecoreKeyUpEvent.dev_name  = ecore_device_name_get( keyEvent->dev );
804         ecoreKeyUpEvent.dev_class = static_cast<Ecore_IMF_Device_Class>( ecore_device_class_get( keyEvent->dev ) );
805         ecoreKeyUpEvent.dev_subclass = static_cast<Ecore_IMF_Device_Subclass>( ecore_device_subclass_get( keyEvent->dev ) );
806
807         eventHandled = ecore_imf_context_filter_event( imfContext,
808                                                        ECORE_IMF_EVENT_KEY_UP,
809                                                        (Ecore_IMF_Event *) &ecoreKeyUpEvent );
810       }
811     }
812
813     // If the event wasn't handled then we should send a key event.
814     if ( !eventHandled )
815     {
816       if ( keyEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
817       {
818         std::string keyName( keyEvent->keyname );
819         std::string keyString( "" );
820         int keyCode = KeyLookup::GetDaliKeyCode( keyEvent->keyname);
821         keyCode = (keyCode == -1) ? 0 : keyCode;
822         int modifier( keyEvent->modifiers );
823         unsigned long time = keyEvent->timestamp;
824         if (!strncmp(keyEvent->keyname, "Keycode-", 8))
825           keyCode = atoi(keyEvent->keyname + 8);
826
827         // Ensure key event string is not NULL as keys like SHIFT have a null string.
828         if ( keyEvent->string )
829         {
830           keyString = keyEvent->string;
831         }
832
833         std::string deviceName;
834         Device::Class::Type deviceClass;
835         Device::Subclass::Type deviceSubclass;
836
837         GetDeviceName( keyEvent, deviceName );
838         GetDeviceClass( ecore_device_class_get( keyEvent->dev ), deviceClass );
839         GetDeviceSubclass( ecore_device_subclass_get( keyEvent->dev ), deviceSubclass );
840
841         Integration::KeyEvent keyEvent(keyName, keyString, keyCode, modifier, time, Integration::KeyEvent::Up, deviceName, deviceClass, deviceSubclass );
842         handler->SendEvent( keyEvent );
843       }
844     }
845
846     return ECORE_CALLBACK_PASS_ON;
847   }
848
849   /////////////////////////////////////////////////////////////////////////////////////////////////
850   // Window Callbacks
851   /////////////////////////////////////////////////////////////////////////////////////////////////
852
853   /**
854    * Called when the window gains focus.
855    */
856   static Eina_Bool EcoreEventWindowFocusIn( void* data, int type, void* event )
857   {
858     Ecore_Wl_Event_Focus_In* focusInEvent( (Ecore_Wl_Event_Focus_In*)event );
859     EventHandler* handler( (EventHandler*)data );
860
861     DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventWindowFocusIn \n" );
862
863     // If the window gains focus and we hid the keyboard then show it again.
864     if ( focusInEvent->win == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
865     {
866       DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT EcoreEventWindowFocusIn - >>WindowFocusGained \n" );
867
868       if ( ImfManager::IsAvailable() /* Only get the ImfManager if it's available as we do not want to create it */ )
869       {
870         Dali::ImfManager imfManager( ImfManager::Get() );
871         if ( imfManager )
872         {
873           ImfManager& imfManagerImpl( ImfManager::GetImplementation( imfManager ) );
874           if( imfManagerImpl.RestoreAfterFocusLost() )
875           {
876             imfManagerImpl.Activate();
877           }
878         }
879       }
880       Dali::Clipboard clipboard = Clipboard::Get();
881       clipboard.HideClipboard();
882     }
883
884     return ECORE_CALLBACK_PASS_ON;
885   }
886
887   /**
888    * Called when the window loses focus.
889    */
890   static Eina_Bool EcoreEventWindowFocusOut( void* data, int type, void* event )
891   {
892     Ecore_Wl_Event_Focus_Out* focusOutEvent( (Ecore_Wl_Event_Focus_Out*)event );
893     EventHandler* handler( (EventHandler*)data );
894
895     DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventWindowFocusOut \n" );
896
897     // If the window loses focus then hide the keyboard.
898     if ( focusOutEvent->win == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
899     {
900       if ( ImfManager::IsAvailable() /* Only get the ImfManager if it's available as we do not want to create it */ )
901       {
902         Dali::ImfManager imfManager( ImfManager::Get() );
903         if ( imfManager )
904         {
905           ImfManager& imfManagerImpl( ImfManager::GetImplementation( imfManager ) );
906           if( imfManagerImpl.RestoreAfterFocusLost() )
907           {
908             imfManagerImpl.Deactivate();
909           }
910         }
911       }
912
913       // Hiding clipboard event will be ignored once because window focus out event is always received on showing clipboard
914       Dali::Clipboard clipboard = Clipboard::Get();
915       if ( clipboard )
916       {
917         Clipboard& clipBoardImpl( GetImplementation( clipboard ) );
918         clipBoardImpl.HideClipboard(true);
919       }
920     }
921
922     return ECORE_CALLBACK_PASS_ON;
923   }
924
925   /**
926    * Called when the window is damaged.
927    */
928   static Eina_Bool EcoreEventWindowDamaged(void *data, int type, void *event)
929   {
930     return ECORE_CALLBACK_PASS_ON;
931   }
932
933   /**
934    * Called when the window properties are changed.
935    * We are only interested in the font change.
936    */
937
938
939   /////////////////////////////////////////////////////////////////////////////////////////////////
940   // Drag & Drop Callbacks
941   /////////////////////////////////////////////////////////////////////////////////////////////////
942
943   /**
944    * Called when a dragged item enters our window's bounds.
945    * This is when items are dragged INTO our window.
946    */
947   static Eina_Bool EcoreEventDndEnter( void* data, int type, void* event )
948   {
949     DALI_LOG_INFO( gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndEnter\n" );
950
951     return ECORE_CALLBACK_PASS_ON;
952   }
953
954   /**
955    * Called when a dragged item is moved within our window.
956    * This is when items are dragged INTO our window.
957    */
958   static Eina_Bool EcoreEventDndPosition( void* data, int type, void* event )
959   {
960     DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndPosition\n" );
961
962     return ECORE_CALLBACK_PASS_ON;
963   }
964
965   /**
966    * Called when a dragged item leaves our window's bounds.
967    * This is when items are dragged INTO our window.
968    */
969   static Eina_Bool EcoreEventDndLeave( void* data, int type, void* event )
970   {
971     DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndLeave\n" );
972
973     return ECORE_CALLBACK_PASS_ON;
974   }
975
976   /**
977    * Called when the dragged item is dropped within our window's bounds.
978    * This is when items are dragged INTO our window.
979    */
980   static Eina_Bool EcoreEventDndDrop( void* data, int type, void* event )
981   {
982     DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndDrop\n" );
983
984     return ECORE_CALLBACK_PASS_ON;
985   }
986
987   /**
988    * Called when a dragged item is moved from our window and the target window has done processing it.
989    * This is when items are dragged FROM our window.
990    */
991   static Eina_Bool EcoreEventDndFinished( void* data, int type, void* event )
992   {
993     DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndFinished\n" );
994     return ECORE_CALLBACK_PASS_ON;
995   }
996
997   /**
998    * Called when a dragged item is moved from our window and the target window has sent us a status.
999    * This is when items are dragged FROM our window.
1000    */
1001   static Eina_Bool EcoreEventDndStatus( void* data, int type, void* event )
1002   {
1003     DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndStatus\n" );
1004     return ECORE_CALLBACK_PASS_ON;
1005   }
1006
1007   /**
1008    * Called when the client messages (i.e. the accessibility events) are received.
1009    */
1010   static Eina_Bool EcoreEventClientMessage( void* data, int type, void* event )
1011   {
1012     return ECORE_CALLBACK_PASS_ON;
1013   }
1014
1015
1016   /////////////////////////////////////////////////////////////////////////////////////////////////
1017   // ElDBus Accessibility Callbacks
1018   /////////////////////////////////////////////////////////////////////////////////////////////////
1019
1020 #ifdef DALI_ELDBUS_AVAILABLE
1021   // Callback for Ecore ElDBus accessibility events.
1022   static void OnEcoreElDBusAccessibilityNotification( void *context EINA_UNUSED, const Eldbus_Message *message )
1023   {
1024     EventHandler* handler = static_cast< EventHandler* >( context );
1025     // Ignore any accessibility events when paused.
1026     if( handler->mPaused )
1027     {
1028       return;
1029     }
1030
1031     if( !handler->mAccessibilityAdaptor )
1032     {
1033       DALI_LOG_ERROR( "Invalid accessibility adaptor\n" );
1034       return;
1035     }
1036
1037     AccessibilityAdaptor* accessibilityAdaptor( &AccessibilityAdaptor::GetImplementation( handler->mAccessibilityAdaptor ) );
1038     if( !accessibilityAdaptor )
1039     {
1040       DALI_LOG_ERROR( "Cannot access accessibility adaptor\n" );
1041       return;
1042     }
1043
1044     int gestureValue;
1045     int xS, yS, xE, yE;
1046     int state; // 0 - begin, 1 - ongoing, 2 - ended, 3 - aborted
1047     int eventTime;
1048
1049     // The string defines the arg-list's respective types.
1050     if( !eldbus_message_arguments_get( message, "iiiiiiu", &gestureValue, &xS, &yS, &xE, &yE, &state, &eventTime ) )
1051     {
1052       DALI_LOG_ERROR( "OnEcoreElDBusAccessibilityNotification: Error getting arguments\n" );
1053     }
1054
1055     DALI_LOG_INFO( gImfLogging, Debug::General, "Got gesture: Name: %d  Args: %d,%d,%d,%d  State: %d\n", gestureValue, xS, yS, xE, yE );
1056
1057     // Create a touch point object.
1058     TouchPoint::State touchPointState( TouchPoint::Down );
1059     if( state == 0 )
1060     {
1061       touchPointState = TouchPoint::Down; // Mouse down.
1062     }
1063     else if( state == 1 )
1064     {
1065       touchPointState = TouchPoint::Motion; // Mouse move.
1066     }
1067     else if( state == 2 )
1068     {
1069       touchPointState = TouchPoint::Up; // Mouse up.
1070     }
1071     else
1072     {
1073       touchPointState = TouchPoint::Interrupted; // Error.
1074     }
1075
1076     // Send touch event to accessibility adaptor.
1077     TouchPoint point( 0, touchPointState, (float)xS, (float)yS );
1078
1079     // Perform actions based on received gestures.
1080     // Note: This is seperated from the reading so we can have other input readers without changing the below code.
1081     switch( gestureValue )
1082     {
1083       case 0: // OneFingerHover
1084       {
1085         // Focus, read out.
1086         accessibilityAdaptor->HandleActionReadEvent( (unsigned int)xS, (unsigned int)yS, true /* allow read again */ );
1087         break;
1088       }
1089       case 1: // TwoFingersHover
1090       {
1091         // In accessibility mode, scroll action should be handled when the currently focused actor is contained in scrollable control
1092         accessibilityAdaptor->HandleActionScrollEvent( point, GetCurrentMilliSeconds() );
1093         break;
1094       }
1095       case 2: // ThreeFingersHover
1096       {
1097         // Read from top item on screen continuously.
1098         accessibilityAdaptor->HandleActionReadFromTopEvent();
1099         break;
1100       }
1101       case 3: // OneFingerFlickLeft
1102       {
1103         // Move to previous item.
1104         accessibilityAdaptor->HandleActionReadPreviousEvent();
1105         break;
1106       }
1107       case 4: // OneFingerFlickRight
1108       {
1109         // Move to next item.
1110         accessibilityAdaptor->HandleActionReadNextEvent();
1111         break;
1112       }
1113       case 5: // OneFingerFlickUp
1114       {
1115         // Move to previous item.
1116         accessibilityAdaptor->HandleActionPreviousEvent();
1117         break;
1118       }
1119       case 6: // OneFingerFlickDown
1120       {
1121         // Move to next item.
1122         accessibilityAdaptor->HandleActionNextEvent();
1123         break;
1124       }
1125       case 7: // TwoFingersFlickUp
1126       {
1127         // Scroll up the list.
1128         accessibilityAdaptor->HandleActionScrollUpEvent();
1129         break;
1130       }
1131       case 8: // TwoFingersFlickDown
1132       {
1133         // Scroll down the list.
1134         accessibilityAdaptor->HandleActionScrollDownEvent();
1135         break;
1136       }
1137       case 9: // TwoFingersFlickLeft
1138       {
1139         // Scroll left to the previous page
1140         accessibilityAdaptor->HandleActionPageLeftEvent();
1141         break;
1142       }
1143       case 10: // TwoFingersFlickRight
1144       {
1145         // Scroll right to the next page
1146         accessibilityAdaptor->HandleActionPageRightEvent();
1147         break;
1148       }
1149       case 11: // ThreeFingersFlickLeft
1150       {
1151         // Not exist yet
1152         break;
1153       }
1154       case 12: // ThreeFingersFlickRight
1155       {
1156         // Not exist yet
1157         break;
1158       }
1159       case 13: // ThreeFingersFlickUp
1160       {
1161         // Not exist yet
1162         break;
1163       }
1164       case 14: // ThreeFingersFlickDown
1165       {
1166         // Not exist yet
1167         break;
1168       }
1169       case 15: // OneFingerSingleTap
1170       {
1171         // Focus, read out.
1172         accessibilityAdaptor->HandleActionReadEvent( (unsigned int)xS, (unsigned int)yS, true /* allow read again */ );
1173         break;
1174       }
1175       case 16: // OneFingerDoubleTap
1176       {
1177         // Activate selected item / active edit mode.
1178         accessibilityAdaptor->HandleActionActivateEvent();
1179         break;
1180       }
1181       case 17: // OneFingerTripleTap
1182       {
1183         // Zoom
1184         accessibilityAdaptor->HandleActionZoomEvent();
1185         break;
1186       }
1187       case 18: // TwoFingersSingleTap
1188       {
1189         // Pause/Resume current speech
1190         accessibilityAdaptor->HandleActionReadPauseResumeEvent();
1191         break;
1192       }
1193       case 19: // TwoFingersDoubleTap
1194       {
1195         // Start/Stop current action
1196         accessibilityAdaptor->HandleActionStartStopEvent();
1197         break;
1198       }
1199       case 20: // TwoFingersTripleTap
1200       {
1201         // Read information from indicator
1202         accessibilityAdaptor->HandleActionReadIndicatorInformationEvent();
1203         break;
1204       }
1205       case 21: // ThreeFingersSingleTap
1206       {
1207         // Read from top item on screen continuously.
1208         accessibilityAdaptor->HandleActionReadFromTopEvent();
1209         break;
1210       }
1211       case 22: // ThreeFingersDoubleTap
1212       {
1213         // Read from next item continuously.
1214         accessibilityAdaptor->HandleActionReadFromNextEvent();
1215         break;
1216       }
1217       case 23: // ThreeFingersTripleTap
1218       {
1219         // Not exist yet
1220         break;
1221       }
1222       case 24: // OneFingerFlickLeftReturn
1223       {
1224         // Scroll up to the previous page
1225         accessibilityAdaptor->HandleActionPageUpEvent();
1226         break;
1227       }
1228       case 25: // OneFingerFlickRightReturn
1229       {
1230         // Scroll down to the next page
1231         accessibilityAdaptor->HandleActionPageDownEvent();
1232         break;
1233       }
1234       case 26: // OneFingerFlickUpReturn
1235       {
1236         // Move to the first item on screen
1237         accessibilityAdaptor->HandleActionMoveToFirstEvent();
1238         break;
1239       }
1240       case 27: // OneFingerFlickDownReturn
1241       {
1242         // Move to the last item on screen
1243         accessibilityAdaptor->HandleActionMoveToLastEvent();
1244         break;
1245       }
1246       case 28: // TwoFingersFlickLeftReturn
1247       {
1248         // Not exist yet
1249         break;
1250       }
1251       case 29: // TwoFingersFlickRightReturn
1252       {
1253         // Not exist yet
1254         break;
1255       }
1256       case 30: // TwoFingersFlickUpReturn
1257       {
1258         // Not exist yet
1259         break;
1260       }
1261       case 31: // TwoFingersFlickDownReturn
1262       {
1263         // Not exist yet
1264         break;
1265       }
1266       case 32: // ThreeFingersFlickLeftReturn
1267       {
1268         // Not exist yet
1269         break;
1270       }
1271       case 33: // ThreeFingersFlickRightReturn
1272       {
1273         // Not exist yet
1274         break;
1275       }
1276       case 34: // ThreeFingersFlickUpReturn
1277       {
1278         // Not exist yet
1279         break;
1280       }
1281       case 35: // ThreeFingersFlickDownReturn
1282       {
1283         // Not exist yet
1284         break;
1285       }
1286     }
1287   }
1288
1289   void EcoreElDBusInitialisation( void *handle )
1290   {
1291     Eldbus_Object *object;
1292     Eldbus_Proxy *manager;
1293
1294     if( !( mSystemConnection = eldbus_connection_get(ELDBUS_CONNECTION_TYPE_SYSTEM) ) )
1295     {
1296       DALI_LOG_ERROR( "Unable to get system bus\n" );
1297     }
1298
1299     object = eldbus_object_get( mSystemConnection, BUS, PATH );
1300     if( !object )
1301     {
1302       DALI_LOG_ERROR( "Getting object failed\n" );
1303       return;
1304     }
1305
1306     manager = eldbus_proxy_get( object, INTERFACE );
1307     if( !manager )
1308     {
1309       DALI_LOG_ERROR( "Getting proxy failed\n" );
1310       return;
1311     }
1312
1313     if( !eldbus_proxy_signal_handler_add( manager, "GestureDetected", OnEcoreElDBusAccessibilityNotification, handle ) )
1314     {
1315       DALI_LOG_ERROR( "No signal handler returned\n" );
1316     }
1317   }
1318 #endif // DALI_ELDBUS_AVAILABLE
1319
1320   /**
1321    * Called when the source window notifies us the content in clipboard is selected.
1322    */
1323   static Eina_Bool EcoreEventSelectionClear( void* data, int type, void* event )
1324   {
1325     DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventSelectionClear\n" );
1326     return ECORE_CALLBACK_PASS_ON;
1327   }
1328
1329   /**
1330    * Called when the source window sends us about the selected content.
1331    * For example, when dragged items are dragged INTO our window or when items are selected in the clipboard.
1332    */
1333   static Eina_Bool EcoreEventSelectionNotify( void* data, int type, void* event )
1334   {
1335     DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventSelectionNotify\n" );
1336     return ECORE_CALLBACK_PASS_ON;
1337   }
1338
1339   /**
1340   * Called when the source window notifies us the content in clipboard is selected.
1341   */
1342   static Eina_Bool EcoreEventDataSend( void* data, int type, void* event )
1343   {
1344     DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventDataSend\n" );
1345
1346     Dali::Clipboard clipboard = Clipboard::Get();
1347     if ( clipboard )
1348     {
1349       Clipboard& clipBoardImpl( GetImplementation( clipboard ) );
1350       clipBoardImpl.ExcuteBuffered( true, event );
1351     }
1352     return ECORE_CALLBACK_PASS_ON;
1353   }
1354
1355    /**
1356     * Called when the source window sends us about the selected content.
1357     * For example, when item is selected in the clipboard.
1358     */
1359    static Eina_Bool EcoreEventDataReceive( void* data, int type, void* event )
1360    {
1361      DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventDataReceive\n" );
1362
1363      EventHandler* handler( (EventHandler*)data );
1364       Dali::Clipboard clipboard = Clipboard::Get();
1365       char *selectionData = NULL;
1366       if ( clipboard )
1367       {
1368         Clipboard& clipBoardImpl( GetImplementation( clipboard ) );
1369         selectionData = clipBoardImpl.ExcuteBuffered( false, event );
1370       }
1371       if ( selectionData && handler->mClipboardEventNotifier )
1372       {
1373         ClipboardEventNotifier& clipboardEventNotifier( ClipboardEventNotifier::GetImplementation( handler->mClipboardEventNotifier ) );
1374         std::string content( selectionData, strlen(selectionData) );
1375
1376         clipboardEventNotifier.SetContent( content );
1377         clipboardEventNotifier.EmitContentSelectedSignal();
1378       }
1379      return ECORE_CALLBACK_PASS_ON;
1380    }
1381
1382   /*
1383   * Called when rotate event is recevied
1384   */
1385   static Eina_Bool EcoreEventRotate( void* data, int type, void* event )
1386   {
1387     DALI_LOG_INFO( gSelectionEventLogFilter, Debug::Concise, "EcoreEventRotate\n" );
1388
1389     EventHandler* handler( (EventHandler*)data );
1390     Ecore_Wl_Event_Window_Rotate* ev( (Ecore_Wl_Event_Window_Rotate*)event );
1391
1392     if( ev->win != (unsigned int)ecore_wl_window_id_get( handler->mImpl->mWindow ) )
1393     {
1394       return ECORE_CALLBACK_PASS_ON;
1395     }
1396
1397     RotationEvent rotationEvent;
1398     rotationEvent.angle = ev->angle;
1399     rotationEvent.winResize = 0;
1400
1401     if( ev->angle == 0 || ev->angle == 180 )
1402     {
1403       rotationEvent.width = ev->w;
1404       rotationEvent.height = ev->h;
1405     }
1406     else
1407     {
1408       rotationEvent.width = ev->h;
1409       rotationEvent.height = ev->w;
1410     }
1411
1412     handler->SendRotationPrepareEvent( rotationEvent );
1413
1414     return ECORE_CALLBACK_PASS_ON;
1415   }
1416
1417   /*
1418   * Called when detent event is recevied
1419   */
1420   static Eina_Bool EcoreEventDetent( void* data, int type, void* event )
1421   {
1422     DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventDetent\n" );
1423     EventHandler* handler( (EventHandler*)data );
1424     Ecore_Event_Detent_Rotate *e((Ecore_Event_Detent_Rotate *)event);
1425     int direction = (e->direction == ECORE_DETENT_DIRECTION_CLOCKWISE) ? 1 : -1;
1426     int timeStamp = e->timestamp;
1427
1428     WheelEvent wheelEvent( WheelEvent::CUSTOM_WHEEL, 0, 0, Vector2(0.0f, 0.0f), direction, timeStamp );
1429     handler->SendWheelEvent( wheelEvent );
1430     return ECORE_CALLBACK_PASS_ON;
1431   }
1432
1433   /////////////////////////////////////////////////////////////////////////////////////////////////
1434   // Font Callbacks
1435   /////////////////////////////////////////////////////////////////////////////////////////////////
1436   /**
1437    * Called when a font name is changed.
1438    */
1439   static void VconfNotifyFontNameChanged( keynode_t* node, void* data )
1440   {
1441     EventHandler* handler = static_cast<EventHandler*>( data );
1442     handler->SendEvent( StyleChange::DEFAULT_FONT_CHANGE );
1443   }
1444
1445   /**
1446    * Called when a font size is changed.
1447    */
1448   static void VconfNotifyFontSizeChanged( keynode_t* node, void* data )
1449   {
1450     EventHandler* handler = static_cast<EventHandler*>( data );
1451     handler->SendEvent( StyleChange::DEFAULT_FONT_SIZE_CHANGE );
1452   }
1453
1454   void ConvertTouchPosition( Integration::Point& point )
1455   {
1456     Vector2 position = point.GetScreenPosition();
1457     Vector2 convertedPosition;
1458
1459     switch( mRotationAngle )
1460     {
1461       case 90:
1462       {
1463         convertedPosition.x = mWindowWidth - position.y;
1464         convertedPosition.y = position.x;
1465         break;
1466       }
1467       case 180:
1468       {
1469         convertedPosition.x = mWindowWidth - position.x;
1470         convertedPosition.y = mWindowHeight - position.y;
1471         break;
1472       }
1473       case 270:
1474       {
1475         convertedPosition.x = position.y;
1476         convertedPosition.y = mWindowHeight - position.x;
1477         break;
1478       }
1479       default:
1480       {
1481         convertedPosition = position;
1482         break;
1483       }
1484     }
1485
1486     point.SetScreenPosition( convertedPosition );
1487   }
1488
1489   // Data
1490   EventHandler* mHandler;
1491   std::vector<Ecore_Event_Handler*> mEcoreEventHandler;
1492   Ecore_Wl_Window* mWindow;
1493   int mRotationAngle;
1494   int mWindowWidth;
1495   int mWindowHeight;
1496 #ifdef DALI_ELDBUS_AVAILABLE
1497   Eldbus_Connection* mSystemConnection;
1498 #endif // DALI_ELDBUS_AVAILABLE
1499 };
1500
1501 EventHandler::EventHandler( RenderSurface* surface, CoreEventInterface& coreEventInterface, GestureManager& gestureManager, DamageObserver& damageObserver, DragAndDropDetectorPtr dndDetector )
1502 : mCoreEventInterface( coreEventInterface ),
1503   mGestureManager( gestureManager ),
1504   mStyleMonitor( StyleMonitor::Get() ),
1505   mDamageObserver( damageObserver ),
1506   mRotationObserver( NULL ),
1507   mDragAndDropDetector( dndDetector ),
1508   mAccessibilityAdaptor( AccessibilityAdaptor::Get() ),
1509   mClipboardEventNotifier( ClipboardEventNotifier::Get() ),
1510   mClipboard( Clipboard::Get() ),
1511   mImpl( NULL ),
1512   mPaused( false )
1513 {
1514   Ecore_Wl_Window* window = 0;
1515
1516   // this code only works with the Ecore RenderSurface so need to downcast
1517   ECore::WindowRenderSurface* ecoreSurface = dynamic_cast< ECore::WindowRenderSurface* >( surface );
1518   if( ecoreSurface )
1519   {
1520     window = ecoreSurface->GetWlWindow();
1521   }
1522
1523   mImpl = new Impl(this, window);
1524 }
1525
1526 EventHandler::~EventHandler()
1527 {
1528   if(mImpl)
1529   {
1530     delete mImpl;
1531   }
1532
1533   mGestureManager.Stop();
1534 }
1535
1536 void EventHandler::SendEvent(Integration::Point& point, unsigned long timeStamp)
1537 {
1538   if(timeStamp < 1)
1539   {
1540     timeStamp = GetCurrentMilliSeconds();
1541   }
1542
1543   mImpl->ConvertTouchPosition( point );
1544
1545   Integration::TouchEvent touchEvent;
1546   Integration::HoverEvent hoverEvent;
1547   Integration::TouchEventCombiner::EventDispatchType type = mCombiner.GetNextTouchEvent(point, timeStamp, touchEvent, hoverEvent);
1548   if(type != Integration::TouchEventCombiner::DispatchNone )
1549   {
1550     DALI_LOG_INFO(gTouchEventLogFilter, Debug::General, "%d: Device %d: Button state %d (%.2f, %.2f)\n", timeStamp, point.GetDeviceId(), point.GetState(), point.GetScreenPosition().x, point.GetScreenPosition().y);
1551
1552     // First the touch and/or hover event & related gesture events are queued
1553     if(type == Integration::TouchEventCombiner::DispatchTouch || type == Integration::TouchEventCombiner::DispatchBoth)
1554     {
1555       mCoreEventInterface.QueueCoreEvent( touchEvent );
1556       mGestureManager.SendEvent(touchEvent);
1557     }
1558
1559     if(type == Integration::TouchEventCombiner::DispatchHover || type == Integration::TouchEventCombiner::DispatchBoth)
1560     {
1561       mCoreEventInterface.QueueCoreEvent( hoverEvent );
1562     }
1563
1564     // Next the events are processed with a single call into Core
1565     mCoreEventInterface.ProcessCoreEvents();
1566   }
1567 }
1568
1569 void EventHandler::SendEvent(Integration::KeyEvent& keyEvent)
1570 {
1571   Dali::PhysicalKeyboard physicalKeyboard = PhysicalKeyboard::Get();
1572   if ( physicalKeyboard )
1573   {
1574     if ( ! KeyLookup::IsDeviceButton( keyEvent.keyName.c_str() ) )
1575     {
1576       GetImplementation( physicalKeyboard ).KeyReceived( keyEvent.time > 1 );
1577     }
1578   }
1579
1580   // Create send KeyEvent to Core.
1581   mCoreEventInterface.QueueCoreEvent( keyEvent );
1582   mCoreEventInterface.ProcessCoreEvents();
1583 }
1584
1585 void EventHandler::SendWheelEvent( WheelEvent& wheelEvent )
1586 {
1587   // Create WheelEvent and send to Core.
1588   Integration::WheelEvent event( static_cast< Integration::WheelEvent::Type >(wheelEvent.type), wheelEvent.direction, wheelEvent.modifiers, wheelEvent.point, wheelEvent.z, wheelEvent.timeStamp );
1589   mCoreEventInterface.QueueCoreEvent( event );
1590   mCoreEventInterface.ProcessCoreEvents();
1591 }
1592
1593 void EventHandler::SendEvent( StyleChange::Type styleChange )
1594 {
1595   DALI_ASSERT_DEBUG( mStyleMonitor && "StyleMonitor Not Available" );
1596   GetImplementation( mStyleMonitor ).StyleChanged(styleChange);
1597 }
1598
1599 void EventHandler::SendEvent( const DamageArea& area )
1600 {
1601   mDamageObserver.OnDamaged( area );
1602 }
1603
1604 void EventHandler::SendRotationPrepareEvent( const RotationEvent& event )
1605 {
1606   if( mRotationObserver != NULL )
1607   {
1608     mImpl->mRotationAngle = event.angle;
1609     mImpl->mWindowWidth = event.width;
1610     mImpl->mWindowHeight = event.height;
1611
1612     mRotationObserver->OnRotationPrepare( event );
1613     mRotationObserver->OnRotationRequest();
1614   }
1615 }
1616
1617 void EventHandler::SendRotationRequestEvent( )
1618 {
1619   // No need to separate event into prepare and request in wayland
1620 }
1621
1622 void EventHandler::FeedTouchPoint( TouchPoint& point, int timeStamp)
1623 {
1624   Integration::Point convertedPoint( point );
1625   SendEvent(convertedPoint, timeStamp);
1626 }
1627
1628 void EventHandler::FeedWheelEvent( WheelEvent& wheelEvent )
1629 {
1630   SendWheelEvent( wheelEvent );
1631 }
1632
1633 void EventHandler::FeedKeyEvent( KeyEvent& event )
1634 {
1635   Integration::KeyEvent convertedEvent( event );
1636   SendEvent( convertedEvent );
1637 }
1638
1639 void EventHandler::FeedEvent( Integration::Event& event )
1640 {
1641   mCoreEventInterface.QueueCoreEvent( event );
1642   mCoreEventInterface.ProcessCoreEvents();
1643 }
1644
1645 void EventHandler::Reset()
1646 {
1647   mCombiner.Reset();
1648
1649   // Any touch listeners should be told of the interruption.
1650   Integration::TouchEvent event;
1651   Integration::Point point;
1652   point.SetState( PointState::INTERRUPTED );
1653   event.AddPoint( point );
1654
1655   // First the touch event & related gesture events are queued
1656   mCoreEventInterface.QueueCoreEvent( event );
1657   mGestureManager.SendEvent( event );
1658
1659   // Next the events are processed with a single call into Core
1660   mCoreEventInterface.ProcessCoreEvents();
1661 }
1662
1663 void EventHandler::Pause()
1664 {
1665   mPaused = true;
1666   Reset();
1667 }
1668
1669 void EventHandler::Resume()
1670 {
1671   mPaused = false;
1672   Reset();
1673 }
1674
1675 void EventHandler::SetDragAndDropDetector( DragAndDropDetectorPtr detector )
1676 {
1677   mDragAndDropDetector = detector;
1678 }
1679
1680 void EventHandler::SetRotationObserver( RotationObserver* observer )
1681 {
1682   mRotationObserver = observer;
1683 }
1684
1685 } // namespace Adaptor
1686
1687 } // namespace Internal
1688
1689 } // namespace Dali
1690
1691 #pragma GCC diagnostic pop