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