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