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