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