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