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