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