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