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