Fix IME (key input) issues on Text control
[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         KeyEvent keyEvent(keyName, keyString, keyCode, modifier, time, 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
514         KeyEvent keyEvent(keyName, keyString, keyCode, modifier, time, KeyEvent::Up);
515         handler->SendEvent( keyEvent );
516       }
517     }
518
519     return ECORE_CALLBACK_PASS_ON;
520   }
521
522   /////////////////////////////////////////////////////////////////////////////////////////////////
523   // Window Callbacks
524   /////////////////////////////////////////////////////////////////////////////////////////////////
525
526   /**
527    * Called when the window gains focus.
528    */
529   static Eina_Bool EcoreEventWindowFocusIn( void* data, int type, void* event )
530   {
531     Ecore_Wl_Event_Focus_In* focusInEvent( (Ecore_Wl_Event_Focus_In*)event );
532     EventHandler* handler( (EventHandler*)data );
533
534     DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventWindowFocusIn \n" );
535
536     // If the window gains focus and we hid the keyboard then show it again.
537     if ( focusInEvent->win == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
538     {
539       DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT EcoreEventWindowFocusIn - >>WindowFocusGained \n" );
540
541       if ( ImfManager::IsAvailable() /* Only get the ImfManager if it's available as we do not want to create it */ )
542       {
543         Dali::ImfManager imfManager( ImfManager::Get() );
544         if ( imfManager )
545         {
546           ImfManager& imfManagerImpl( ImfManager::GetImplementation( imfManager ) );
547           if( imfManagerImpl.RestoreAfterFocusLost() )
548           {
549             imfManagerImpl.Activate();
550           }
551         }
552       }
553       Dali::Clipboard clipboard = Clipboard::Get();
554       clipboard.HideClipboard();
555     }
556
557     return ECORE_CALLBACK_PASS_ON;
558   }
559
560   /**
561    * Called when the window loses focus.
562    */
563   static Eina_Bool EcoreEventWindowFocusOut( void* data, int type, void* event )
564   {
565     Ecore_Wl_Event_Focus_Out* focusOutEvent( (Ecore_Wl_Event_Focus_Out*)event );
566     EventHandler* handler( (EventHandler*)data );
567
568     DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventWindowFocusOut \n" );
569
570     // If the window loses focus then hide the keyboard.
571     if ( focusOutEvent->win == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
572     {
573       if ( ImfManager::IsAvailable() /* Only get the ImfManager if it's available as we do not want to create it */ )
574       {
575         Dali::ImfManager imfManager( ImfManager::Get() );
576         if ( imfManager )
577         {
578           ImfManager& imfManagerImpl( ImfManager::GetImplementation( imfManager ) );
579           if( imfManagerImpl.RestoreAfterFocusLost() )
580           {
581             imfManagerImpl.Deactivate();
582           }
583         }
584       }
585
586       // Hiding clipboard event will be ignored once because window focus out event is always received on showing clipboard
587       Dali::Clipboard clipboard = Clipboard::Get();
588       if ( clipboard )
589       {
590         Clipboard& clipBoardImpl( GetImplementation( clipboard ) );
591         clipBoardImpl.HideClipboard(true);
592       }
593     }
594
595     return ECORE_CALLBACK_PASS_ON;
596   }
597
598   /**
599    * Called when the window is damaged.
600    */
601   static Eina_Bool EcoreEventWindowDamaged(void *data, int type, void *event)
602   {
603     return ECORE_CALLBACK_PASS_ON;
604   }
605
606   /**
607    * Called when the window properties are changed.
608    * We are only interested in the font change.
609    */
610
611
612   /////////////////////////////////////////////////////////////////////////////////////////////////
613   // Drag & Drop Callbacks
614   /////////////////////////////////////////////////////////////////////////////////////////////////
615
616   /**
617    * Called when a dragged item enters our window's bounds.
618    * This is when items are dragged INTO our window.
619    */
620   static Eina_Bool EcoreEventDndEnter( void* data, int type, void* event )
621   {
622     DALI_LOG_INFO( gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndEnter\n" );
623
624     return ECORE_CALLBACK_PASS_ON;
625   }
626
627   /**
628    * Called when a dragged item is moved within our window.
629    * This is when items are dragged INTO our window.
630    */
631   static Eina_Bool EcoreEventDndPosition( void* data, int type, void* event )
632   {
633     DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndPosition\n" );
634
635     return ECORE_CALLBACK_PASS_ON;
636   }
637
638   /**
639    * Called when a dragged item leaves our window's bounds.
640    * This is when items are dragged INTO our window.
641    */
642   static Eina_Bool EcoreEventDndLeave( void* data, int type, void* event )
643   {
644     DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndLeave\n" );
645
646     return ECORE_CALLBACK_PASS_ON;
647   }
648
649   /**
650    * Called when the dragged item is dropped within our window's bounds.
651    * This is when items are dragged INTO our window.
652    */
653   static Eina_Bool EcoreEventDndDrop( void* data, int type, void* event )
654   {
655     DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndDrop\n" );
656
657     return ECORE_CALLBACK_PASS_ON;
658   }
659
660   /**
661    * Called when a dragged item is moved from our window and the target window has done processing it.
662    * This is when items are dragged FROM our window.
663    */
664   static Eina_Bool EcoreEventDndFinished( void* data, int type, void* event )
665   {
666     DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndFinished\n" );
667     return ECORE_CALLBACK_PASS_ON;
668   }
669
670   /**
671    * Called when a dragged item is moved from our window and the target window has sent us a status.
672    * This is when items are dragged FROM our window.
673    */
674   static Eina_Bool EcoreEventDndStatus( void* data, int type, void* event )
675   {
676     DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndStatus\n" );
677     return ECORE_CALLBACK_PASS_ON;
678   }
679
680   /**
681    * Called when the client messages (i.e. the accessibility events) are received.
682    */
683   static Eina_Bool EcoreEventClientMessage( void* data, int type, void* event )
684   {
685     return ECORE_CALLBACK_PASS_ON;
686   }
687
688
689   /////////////////////////////////////////////////////////////////////////////////////////////////
690   // ElDBus Accessibility Callbacks
691   /////////////////////////////////////////////////////////////////////////////////////////////////
692
693 #ifdef DALI_ELDBUS_AVAILABLE
694   // Callback for Ecore ElDBus accessibility events.
695   static void OnEcoreElDBusAccessibilityNotification( void *context EINA_UNUSED, const Eldbus_Message *message )
696   {
697     EventHandler* handler = static_cast< EventHandler* >( context );
698     // Ignore any accessibility events when paused.
699     if( handler->mPaused )
700     {
701       return;
702     }
703
704     if( !handler->mAccessibilityAdaptor )
705     {
706       DALI_LOG_ERROR( "Invalid accessibility adaptor\n" );
707       return;
708     }
709
710     AccessibilityAdaptor* accessibilityAdaptor( &AccessibilityAdaptor::GetImplementation( handler->mAccessibilityAdaptor ) );
711     if( !accessibilityAdaptor )
712     {
713       DALI_LOG_ERROR( "Cannot access accessibility adaptor\n" );
714       return;
715     }
716
717     int gestureValue;
718     int xS, yS, xE, yE;
719     int state; // 0 - begin, 1 - ongoing, 2 - ended, 3 - aborted
720     int eventTime;
721
722     // The string defines the arg-list's respective types.
723     if( !eldbus_message_arguments_get( message, "iiiiiiu", &gestureValue, &xS, &yS, &xE, &yE, &state, &eventTime ) )
724     {
725       DALI_LOG_ERROR( "OnEcoreElDBusAccessibilityNotification: Error getting arguments\n" );
726     }
727
728     DALI_LOG_INFO( gImfLogging, Debug::General, "Got gesture: Name: %d  Args: %d,%d,%d,%d  State: %d\n", gestureValue, xS, yS, xE, yE );
729
730     // Create a touch point object.
731     TouchPoint::State touchPointState( TouchPoint::Down );
732     if( state == 0 )
733     {
734       touchPointState = TouchPoint::Down; // Mouse down.
735     }
736     else if( state == 1 )
737     {
738       touchPointState = TouchPoint::Motion; // Mouse move.
739     }
740     else if( state == 2 )
741     {
742       touchPointState = TouchPoint::Up; // Mouse up.
743     }
744     else
745     {
746       touchPointState = TouchPoint::Interrupted; // Error.
747     }
748
749     // Send touch event to accessibility adaptor.
750     TouchPoint point( 0, touchPointState, (float)xS, (float)yS );
751
752     // Perform actions based on received gestures.
753     // Note: This is seperated from the reading so we can have other input readers without changing the below code.
754     switch( gestureValue )
755     {
756       case 0: // OneFingerHover
757       {
758         // Focus, read out.
759         accessibilityAdaptor->HandleActionReadEvent( (unsigned int)xS, (unsigned int)yS, true /* allow read again */ );
760         break;
761       }
762       case 1: // TwoFingersHover
763       {
764         // In accessibility mode, scroll action should be handled when the currently focused actor is contained in scrollable control
765         accessibilityAdaptor->HandleActionScrollEvent( point, GetCurrentMilliSeconds() );
766         break;
767       }
768       case 2: // ThreeFingersHover
769       {
770         // Read from top item on screen continuously.
771         accessibilityAdaptor->HandleActionReadFromTopEvent();
772         break;
773       }
774       case 3: // OneFingerFlickLeft
775       {
776         // Move to previous item.
777         accessibilityAdaptor->HandleActionReadPreviousEvent();
778         break;
779       }
780       case 4: // OneFingerFlickRight
781       {
782         // Move to next item.
783         accessibilityAdaptor->HandleActionReadNextEvent();
784         break;
785       }
786       case 5: // OneFingerFlickUp
787       {
788         // Move to previous item.
789         accessibilityAdaptor->HandleActionPreviousEvent();
790         break;
791       }
792       case 6: // OneFingerFlickDown
793       {
794         // Move to next item.
795         accessibilityAdaptor->HandleActionNextEvent();
796         break;
797       }
798       case 7: // TwoFingersFlickUp
799       {
800         // Scroll up the list.
801         accessibilityAdaptor->HandleActionScrollUpEvent();
802         break;
803       }
804       case 8: // TwoFingersFlickDown
805       {
806         // Scroll down the list.
807         accessibilityAdaptor->HandleActionScrollDownEvent();
808         break;
809       }
810       case 9: // TwoFingersFlickLeft
811       {
812         // Scroll left to the previous page
813         accessibilityAdaptor->HandleActionPageLeftEvent();
814         break;
815       }
816       case 10: // TwoFingersFlickRight
817       {
818         // Scroll right to the next page
819         accessibilityAdaptor->HandleActionPageRightEvent();
820         break;
821       }
822       case 11: // ThreeFingersFlickLeft
823       {
824         // Not exist yet
825         break;
826       }
827       case 12: // ThreeFingersFlickRight
828       {
829         // Not exist yet
830         break;
831       }
832       case 13: // ThreeFingersFlickUp
833       {
834         // Not exist yet
835         break;
836       }
837       case 14: // ThreeFingersFlickDown
838       {
839         // Not exist yet
840         break;
841       }
842       case 15: // OneFingerSingleTap
843       {
844         // Focus, read out.
845         accessibilityAdaptor->HandleActionReadEvent( (unsigned int)xS, (unsigned int)yS, true /* allow read again */ );
846         break;
847       }
848       case 16: // OneFingerDoubleTap
849       {
850         // Activate selected item / active edit mode.
851         accessibilityAdaptor->HandleActionActivateEvent();
852         break;
853       }
854       case 17: // OneFingerTripleTap
855       {
856         // Zoom
857         accessibilityAdaptor->HandleActionZoomEvent();
858         break;
859       }
860       case 18: // TwoFingersSingleTap
861       {
862         // Pause/Resume current speech
863         accessibilityAdaptor->HandleActionReadPauseResumeEvent();
864         break;
865       }
866       case 19: // TwoFingersDoubleTap
867       {
868         // Start/Stop current action
869         accessibilityAdaptor->HandleActionStartStopEvent();
870         break;
871       }
872       case 20: // TwoFingersTripleTap
873       {
874         // Read information from indicator
875         accessibilityAdaptor->HandleActionReadIndicatorInformationEvent();
876         break;
877       }
878       case 21: // ThreeFingersSingleTap
879       {
880         // Read from top item on screen continuously.
881         accessibilityAdaptor->HandleActionReadFromTopEvent();
882         break;
883       }
884       case 22: // ThreeFingersDoubleTap
885       {
886         // Read from next item continuously.
887         accessibilityAdaptor->HandleActionReadFromNextEvent();
888         break;
889       }
890       case 23: // ThreeFingersTripleTap
891       {
892         // Not exist yet
893         break;
894       }
895       case 24: // OneFingerFlickLeftReturn
896       {
897         // Scroll up to the previous page
898         accessibilityAdaptor->HandleActionPageUpEvent();
899         break;
900       }
901       case 25: // OneFingerFlickRightReturn
902       {
903         // Scroll down to the next page
904         accessibilityAdaptor->HandleActionPageDownEvent();
905         break;
906       }
907       case 26: // OneFingerFlickUpReturn
908       {
909         // Move to the first item on screen
910         accessibilityAdaptor->HandleActionMoveToFirstEvent();
911         break;
912       }
913       case 27: // OneFingerFlickDownReturn
914       {
915         // Move to the last item on screen
916         accessibilityAdaptor->HandleActionMoveToLastEvent();
917         break;
918       }
919       case 28: // TwoFingersFlickLeftReturn
920       {
921         // Not exist yet
922         break;
923       }
924       case 29: // TwoFingersFlickRightReturn
925       {
926         // Not exist yet
927         break;
928       }
929       case 30: // TwoFingersFlickUpReturn
930       {
931         // Not exist yet
932         break;
933       }
934       case 31: // TwoFingersFlickDownReturn
935       {
936         // Not exist yet
937         break;
938       }
939       case 32: // ThreeFingersFlickLeftReturn
940       {
941         // Not exist yet
942         break;
943       }
944       case 33: // ThreeFingersFlickRightReturn
945       {
946         // Not exist yet
947         break;
948       }
949       case 34: // ThreeFingersFlickUpReturn
950       {
951         // Not exist yet
952         break;
953       }
954       case 35: // ThreeFingersFlickDownReturn
955       {
956         // Not exist yet
957         break;
958       }
959     }
960   }
961
962   void EcoreElDBusInitialisation( void *handle )
963   {
964     Eldbus_Object *object;
965     Eldbus_Proxy *manager;
966
967     if( !( mSystemConnection = eldbus_connection_get(ELDBUS_CONNECTION_TYPE_SYSTEM) ) )
968     {
969       DALI_LOG_ERROR( "Unable to get system bus\n" );
970     }
971
972     object = eldbus_object_get( mSystemConnection, BUS, PATH );
973     if( !object )
974     {
975       DALI_LOG_ERROR( "Getting object failed\n" );
976       return;
977     }
978
979     manager = eldbus_proxy_get( object, INTERFACE );
980     if( !manager )
981     {
982       DALI_LOG_ERROR( "Getting proxy failed\n" );
983       return;
984     }
985
986     if( !eldbus_proxy_signal_handler_add( manager, "GestureDetected", OnEcoreElDBusAccessibilityNotification, handle ) )
987     {
988       DALI_LOG_ERROR( "No signal handler returned\n" );
989     }
990   }
991 #endif // DALI_ELDBUS_AVAILABLE
992
993   /**
994    * Called when the source window notifies us the content in clipboard is selected.
995    */
996   static Eina_Bool EcoreEventSelectionClear( void* data, int type, void* event )
997   {
998     DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventSelectionClear\n" );
999     return ECORE_CALLBACK_PASS_ON;
1000   }
1001
1002   /**
1003    * Called when the source window sends us about the selected content.
1004    * For example, when dragged items are dragged INTO our window or when items are selected in the clipboard.
1005    */
1006   static Eina_Bool EcoreEventSelectionNotify( void* data, int type, void* event )
1007   {
1008     DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventSelectionNotify\n" );
1009     return ECORE_CALLBACK_PASS_ON;
1010   }
1011
1012   /**
1013   * Called when the source window notifies us the content in clipboard is selected.
1014   */
1015   static Eina_Bool EcoreEventDataSend( void* data, int type, void* event )
1016   {
1017     DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventDataSend\n" );
1018
1019     Dali::Clipboard clipboard = Clipboard::Get();
1020     if ( clipboard )
1021     {
1022       Clipboard& clipBoardImpl( GetImplementation( clipboard ) );
1023       clipBoardImpl.ExcuteBuffered( true, event );
1024     }
1025     return ECORE_CALLBACK_PASS_ON;
1026   }
1027
1028    /**
1029     * Called when the source window sends us about the selected content.
1030     * For example, when item is selected in the clipboard.
1031     */
1032    static Eina_Bool EcoreEventDataReceive( void* data, int type, void* event )
1033    {
1034      DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventDataReceive\n" );
1035
1036      EventHandler* handler( (EventHandler*)data );
1037       Dali::Clipboard clipboard = Clipboard::Get();
1038       char *selectionData = NULL;
1039       if ( clipboard )
1040       {
1041         Clipboard& clipBoardImpl( GetImplementation( clipboard ) );
1042         selectionData = clipBoardImpl.ExcuteBuffered( false, event );
1043       }
1044       if ( selectionData && handler->mClipboardEventNotifier )
1045       {
1046         ClipboardEventNotifier& clipboardEventNotifier( ClipboardEventNotifier::GetImplementation( handler->mClipboardEventNotifier ) );
1047         std::string content( selectionData, strlen(selectionData) );
1048
1049         clipboardEventNotifier.SetContent( content );
1050         clipboardEventNotifier.EmitContentSelectedSignal();
1051       }
1052      return ECORE_CALLBACK_PASS_ON;
1053    }
1054
1055   /*
1056   * Called when rotate event is recevied
1057   */
1058   static Eina_Bool EcoreEventRotate( void* data, int type, void* event )
1059   {
1060     DALI_LOG_INFO( gSelectionEventLogFilter, Debug::Concise, "EcoreEventRotate\n" );
1061
1062     EventHandler* handler( (EventHandler*)data );
1063     Ecore_Wl_Event_Window_Rotate* ev( (Ecore_Wl_Event_Window_Rotate*)event );
1064
1065     if( ev->win != (unsigned int)ecore_wl_window_id_get( handler->mImpl->mWindow ) )
1066     {
1067       return ECORE_CALLBACK_PASS_ON;
1068     }
1069
1070     RotationEvent rotationEvent;
1071     rotationEvent.angle = ev->angle;
1072     rotationEvent.winResize = 0;
1073     rotationEvent.width = ev->w;
1074     rotationEvent.height = ev->h;
1075     handler->SendRotationPrepareEvent( rotationEvent );
1076
1077     return ECORE_CALLBACK_PASS_ON;
1078   }
1079
1080   /*
1081   * Called when detent event is recevied
1082   */
1083   static Eina_Bool EcoreEventDetent( void* data, int type, void* event )
1084   {
1085     DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventDetent\n" );
1086     EventHandler* handler( (EventHandler*)data );
1087     Ecore_Event_Detent_Rotate *e((Ecore_Event_Detent_Rotate *)event);
1088     int direction = (e->direction == ECORE_DETENT_DIRECTION_CLOCKWISE) ? 1 : -1;
1089     int timeStamp = e->timestamp;
1090
1091     WheelEvent wheelEvent( WheelEvent::CUSTOM_WHEEL, 0, 0, Vector2(0.0f, 0.0f), direction, timeStamp );
1092     handler->SendWheelEvent( wheelEvent );
1093     return ECORE_CALLBACK_PASS_ON;
1094   }
1095
1096   /////////////////////////////////////////////////////////////////////////////////////////////////
1097   // Font Callbacks
1098   /////////////////////////////////////////////////////////////////////////////////////////////////
1099   /**
1100    * Called when a font name is changed.
1101    */
1102   static void VconfNotifyFontNameChanged( keynode_t* node, void* data )
1103   {
1104     EventHandler* handler = static_cast<EventHandler*>( data );
1105     handler->SendEvent( StyleChange::DEFAULT_FONT_CHANGE );
1106   }
1107
1108   /**
1109    * Called when a font size is changed.
1110    */
1111   static void VconfNotifyFontSizeChanged( keynode_t* node, void* data )
1112   {
1113     EventHandler* handler = static_cast<EventHandler*>( data );
1114     handler->SendEvent( StyleChange::DEFAULT_FONT_SIZE_CHANGE );
1115   }
1116
1117   // Data
1118   EventHandler* mHandler;
1119   std::vector<Ecore_Event_Handler*> mEcoreEventHandler;
1120   Ecore_Wl_Window* mWindow;
1121 #ifdef DALI_ELDBUS_AVAILABLE
1122   Eldbus_Connection* mSystemConnection;
1123 #endif // DALI_ELDBUS_AVAILABLE
1124 };
1125
1126 EventHandler::EventHandler( RenderSurface* surface, CoreEventInterface& coreEventInterface, GestureManager& gestureManager, DamageObserver& damageObserver, DragAndDropDetectorPtr dndDetector )
1127 : mCoreEventInterface( coreEventInterface ),
1128   mGestureManager( gestureManager ),
1129   mStyleMonitor( StyleMonitor::Get() ),
1130   mDamageObserver( damageObserver ),
1131   mRotationObserver( NULL ),
1132   mDragAndDropDetector( dndDetector ),
1133   mAccessibilityAdaptor( AccessibilityAdaptor::Get() ),
1134   mClipboardEventNotifier( ClipboardEventNotifier::Get() ),
1135   mClipboard( Clipboard::Get() ),
1136   mImpl( NULL ),
1137   mPaused( false )
1138 {
1139   Ecore_Wl_Window* window = 0;
1140
1141   // this code only works with the Ecore RenderSurface so need to downcast
1142   ECore::WindowRenderSurface* ecoreSurface = dynamic_cast< ECore::WindowRenderSurface* >( surface );
1143   if( ecoreSurface )
1144   {
1145     window = ecoreSurface->GetWlWindow();
1146   }
1147
1148   mImpl = new Impl(this, window);
1149 }
1150
1151 EventHandler::~EventHandler()
1152 {
1153   if(mImpl)
1154   {
1155     delete mImpl;
1156   }
1157
1158   mGestureManager.Stop();
1159 }
1160
1161 void EventHandler::SendEvent(Integration::Point& point, unsigned long timeStamp)
1162 {
1163   if(timeStamp < 1)
1164   {
1165     timeStamp = GetCurrentMilliSeconds();
1166   }
1167
1168   Integration::TouchEvent touchEvent;
1169   Integration::HoverEvent hoverEvent;
1170   Integration::TouchEventCombiner::EventDispatchType type = mCombiner.GetNextTouchEvent(point, timeStamp, touchEvent, hoverEvent);
1171   if(type != Integration::TouchEventCombiner::DispatchNone )
1172   {
1173     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);
1174
1175     // First the touch and/or hover event & related gesture events are queued
1176     if(type == Integration::TouchEventCombiner::DispatchTouch || type == Integration::TouchEventCombiner::DispatchBoth)
1177     {
1178       mCoreEventInterface.QueueCoreEvent( touchEvent );
1179       mGestureManager.SendEvent(touchEvent);
1180     }
1181
1182     if(type == Integration::TouchEventCombiner::DispatchHover || type == Integration::TouchEventCombiner::DispatchBoth)
1183     {
1184       mCoreEventInterface.QueueCoreEvent( hoverEvent );
1185     }
1186
1187     // Next the events are processed with a single call into Core
1188     mCoreEventInterface.ProcessCoreEvents();
1189   }
1190 }
1191
1192 void EventHandler::SendEvent(KeyEvent& keyEvent)
1193 {
1194   Dali::PhysicalKeyboard physicalKeyboard = PhysicalKeyboard::Get();
1195   if ( physicalKeyboard )
1196   {
1197     if ( ! KeyLookup::IsDeviceButton( keyEvent.keyPressedName.c_str() ) )
1198     {
1199       GetImplementation( physicalKeyboard ).KeyReceived( keyEvent.time > 1 );
1200     }
1201   }
1202
1203   // Create KeyEvent and send to Core.
1204   Integration::KeyEvent event(keyEvent.keyPressedName, keyEvent.keyPressed, keyEvent.keyCode,
1205   keyEvent.keyModifier, keyEvent.time, static_cast<Integration::KeyEvent::State>(keyEvent.state));
1206   mCoreEventInterface.QueueCoreEvent( event );
1207   mCoreEventInterface.ProcessCoreEvents();
1208 }
1209
1210 void EventHandler::SendWheelEvent( WheelEvent& wheelEvent )
1211 {
1212   // Create WheelEvent and send to Core.
1213   Integration::WheelEvent event( static_cast< Integration::WheelEvent::Type >(wheelEvent.type), wheelEvent.direction, wheelEvent.modifiers, wheelEvent.point, wheelEvent.z, wheelEvent.timeStamp );
1214   mCoreEventInterface.QueueCoreEvent( event );
1215   mCoreEventInterface.ProcessCoreEvents();
1216 }
1217
1218 void EventHandler::SendEvent( StyleChange::Type styleChange )
1219 {
1220   DALI_ASSERT_DEBUG( mStyleMonitor && "StyleMonitor Not Available" );
1221   GetImplementation( mStyleMonitor ).StyleChanged(styleChange);
1222 }
1223
1224 void EventHandler::SendEvent( const DamageArea& area )
1225 {
1226   mDamageObserver.OnDamaged( area );
1227 }
1228
1229 void EventHandler::SendRotationPrepareEvent( const RotationEvent& event )
1230 {
1231   if( mRotationObserver != NULL )
1232   {
1233     mRotationObserver->OnRotationPrepare( event );
1234     mRotationObserver->OnRotationRequest();
1235   }
1236 }
1237
1238 void EventHandler::SendRotationRequestEvent( )
1239 {
1240   // No need to separate event into prepare and request in wayland
1241 }
1242
1243 void EventHandler::FeedTouchPoint( TouchPoint& point, int timeStamp)
1244 {
1245   Integration::Point convertedPoint( point );
1246   SendEvent(convertedPoint, timeStamp);
1247 }
1248
1249 void EventHandler::FeedWheelEvent( WheelEvent& wheelEvent )
1250 {
1251   SendWheelEvent( wheelEvent );
1252 }
1253
1254 void EventHandler::FeedKeyEvent( KeyEvent& event )
1255 {
1256   SendEvent( event );
1257 }
1258
1259 void EventHandler::FeedEvent( Integration::Event& event )
1260 {
1261   mCoreEventInterface.QueueCoreEvent( event );
1262   mCoreEventInterface.ProcessCoreEvents();
1263 }
1264
1265 void EventHandler::Reset()
1266 {
1267   mCombiner.Reset();
1268
1269   // Any touch listeners should be told of the interruption.
1270   Integration::TouchEvent event;
1271   Integration::Point point;
1272   point.SetState( PointState::INTERRUPTED );
1273   event.AddPoint( point );
1274
1275   // First the touch event & related gesture events are queued
1276   mCoreEventInterface.QueueCoreEvent( event );
1277   mGestureManager.SendEvent( event );
1278
1279   // Next the events are processed with a single call into Core
1280   mCoreEventInterface.ProcessCoreEvents();
1281 }
1282
1283 void EventHandler::Pause()
1284 {
1285   mPaused = true;
1286   Reset();
1287 }
1288
1289 void EventHandler::Resume()
1290 {
1291   mPaused = false;
1292   Reset();
1293 }
1294
1295 void EventHandler::SetDragAndDropDetector( DragAndDropDetectorPtr detector )
1296 {
1297   mDragAndDropDetector = detector;
1298 }
1299
1300 void EventHandler::SetRotationObserver( RotationObserver* observer )
1301 {
1302   mRotationObserver = observer;
1303 }
1304
1305 } // namespace Adaptor
1306
1307 } // namespace Internal
1308
1309 } // namespace Dali