2 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <events/event-handler.h>
23 #include <Ecore_Input.h>
24 #include <ecore-wl-render-surface.h>
29 #ifndef DALI_PROFILE_UBUNTU
31 #include <vconf-keys.h>
32 #endif // DALI_PROFILE_UBUNTU
34 #ifdef DALI_ELDBUS_AVAILABLE
36 #endif // DALI_ELDBUS_AVAILABLE
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>
49 #include <events/gesture-manager.h>
50 #include <window-render-surface.h>
51 #include <clipboard-impl.h>
53 #include <physical-keyboard-impl.h>
54 #include <style-monitor-impl.h>
55 #include <base/core-event-interface.h>
56 #include <virtual-keyboard.h>
67 #if defined(DEBUG_ENABLED)
70 Integration::Log::Filter* gTouchEventLogFilter = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_TOUCH");
71 Integration::Log::Filter* gDragAndDropLogFilter = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_DND");
72 Integration::Log::Filter* gImfLogging = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_IMF");
73 Integration::Log::Filter* gSelectionEventLogFilter = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_SELECTION");
74 } // unnamed namespace
82 const char* BUS = "org.enlightenment.wm-screen-reader";
83 const char* INTERFACE = "org.tizen.GestureNavigation";
84 const char* PATH = "/org/tizen/GestureNavigation";
86 const unsigned int PRIMARY_TOUCH_BUTTON_ID( 1 );
88 const unsigned int BYTES_PER_CHARACTER_FOR_ATTRIBUTES = 3;
91 * Ecore_Event_Modifier enums in Ecore_Input.h do not match Ecore_IMF_Keyboard_Modifiers in Ecore_IMF.h.
92 * This function converts from Ecore_Event_Modifier to Ecore_IMF_Keyboard_Modifiers enums.
93 * @param[in] ecoreModifier the Ecore_Event_Modifier input.
94 * @return the Ecore_IMF_Keyboard_Modifiers output.
96 Ecore_IMF_Keyboard_Modifiers EcoreInputModifierToEcoreIMFModifier(unsigned int ecoreModifier)
98 int modifier( ECORE_IMF_KEYBOARD_MODIFIER_NONE ); // If no other matches returns NONE.
101 if ( ecoreModifier & ECORE_EVENT_MODIFIER_SHIFT ) // enums from ecore_input/Ecore_Input.h
103 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_SHIFT; // enums from ecore_imf/ecore_imf.h
106 if ( ecoreModifier & ECORE_EVENT_MODIFIER_ALT )
108 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_ALT;
111 if ( ecoreModifier & ECORE_EVENT_MODIFIER_CTRL )
113 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_CTRL;
116 if ( ecoreModifier & ECORE_EVENT_MODIFIER_WIN )
118 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_WIN;
121 if ( ecoreModifier & ECORE_EVENT_MODIFIER_ALTGR )
123 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_ALTGR;
126 return static_cast<Ecore_IMF_Keyboard_Modifiers>( modifier );
130 // Copied from x server
131 static unsigned int GetCurrentMilliSeconds(void)
136 static clockid_t clockid;
140 #ifdef CLOCK_MONOTONIC_COARSE
141 if (clock_getres(CLOCK_MONOTONIC_COARSE, &tp) == 0 &&
142 (tp.tv_nsec / 1000) <= 1000 && clock_gettime(CLOCK_MONOTONIC_COARSE, &tp) == 0)
144 clockid = CLOCK_MONOTONIC_COARSE;
148 if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0)
150 clockid = CLOCK_MONOTONIC;
157 if (clockid != ~0L && clock_gettime(clockid, &tp) == 0)
159 return (tp.tv_sec * 1000) + (tp.tv_nsec / 1000000L);
162 gettimeofday(&tv, NULL);
163 return (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
166 #ifndef DALI_PROFILE_UBUNTU
167 const char * DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE = "db/setting/accessibility/font_name"; // It will be update at vconf-key.h and replaced.
168 #endif // DALI_PROFILE_UBUNTU
171 * Get the device name from the provided ecore key event
173 void GetDeviceName( Ecore_Event_Key* keyEvent, std::string& result )
175 const char* ecoreDeviceName = ecore_device_name_get( keyEvent->dev );
177 if ( ecoreDeviceName )
179 result = ecoreDeviceName;
184 } // unnamed namespace
186 // Impl to hide EFL implementation.
187 struct EventHandler::Impl
189 // Construction & Destruction
194 Impl( EventHandler* handler, Ecore_Wl_Window* window )
195 : mHandler( handler ),
196 mEcoreEventHandler(),
198 #ifdef DALI_ELDBUS_AVAILABLE
199 , mSystemConnection( NULL )
200 #endif // DALI_ELDBUS_AVAILABLE
202 // Only register for touch and key events if we have a window
205 // Register Touch events
206 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_BUTTON_DOWN, EcoreEventMouseButtonDown, handler ) );
207 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_BUTTON_UP, EcoreEventMouseButtonUp, handler ) );
208 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_MOVE, EcoreEventMouseButtonMove, handler ) );
209 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_OUT, EcoreEventMouseButtonUp, handler ) ); // process mouse out event like up event
211 // Register Mouse wheel events
212 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_WHEEL, EcoreEventMouseWheel, handler ) );
214 // Register Focus events
215 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_WL_EVENT_FOCUS_IN, EcoreEventWindowFocusIn, handler ) );
216 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_WL_EVENT_FOCUS_OUT, EcoreEventWindowFocusOut, handler ) );
218 // Register Key events
219 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_KEY_DOWN, EcoreEventKeyDown, handler ) );
220 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_KEY_UP, EcoreEventKeyUp, handler ) );
222 // Register Selection event - clipboard selection
223 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_WL_EVENT_DATA_SOURCE_SEND, EcoreEventDataSend, handler ) );
224 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_WL_EVENT_SELECTION_DATA_READY, EcoreEventDataReceive, handler ) );
226 // Register Rotate event
227 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_WL_EVENT_WINDOW_ROTATE, EcoreEventRotate, handler) );
229 // Register Detent event
230 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_DETENT_ROTATE, EcoreEventDetent, handler) );
232 #ifndef DALI_PROFILE_UBUNTU
233 // Register Vconf notify - font name and size
234 vconf_notify_key_changed( DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontNameChanged, handler );
235 vconf_notify_key_changed( VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontSizeChanged, handler );
236 #endif // DALI_PROFILE_UBUNTU
238 #ifdef DALI_ELDBUS_AVAILABLE
239 // Initialize ElDBus.
240 DALI_LOG_INFO( gImfLogging, Debug::General, "Starting DBus Initialization\n" );
243 EcoreElDBusInitialisation( handler );
245 DALI_LOG_INFO( gImfLogging, Debug::General, "Finished DBus Initialization\n" );
246 #endif // DALI_ELDBUS_AVAILABLE
255 #ifndef DALI_PROFILE_UBUNTU
256 vconf_ignore_key_changed( VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontSizeChanged );
257 vconf_ignore_key_changed( DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontNameChanged );
258 #endif // DALI_PROFILE_UBUNTU
260 for( std::vector<Ecore_Event_Handler*>::iterator iter = mEcoreEventHandler.begin(), endIter = mEcoreEventHandler.end(); iter != endIter; ++iter )
262 ecore_event_handler_del( *iter );
265 #ifdef DALI_ELDBUS_AVAILABLE
266 // Close down ElDBus connections.
267 if( mSystemConnection )
269 eldbus_connection_unref( mSystemConnection );
271 #endif // DALI_ELDBUS_AVAILABLE
276 /////////////////////////////////////////////////////////////////////////////////////////////////
278 /////////////////////////////////////////////////////////////////////////////////////////////////
281 * Called when a touch down is received.
283 static Eina_Bool EcoreEventMouseButtonDown( void* data, int type, void* event )
285 Ecore_Event_Mouse_Button *touchEvent( (Ecore_Event_Mouse_Button*)event );
286 EventHandler* handler( (EventHandler*)data );
288 if ( touchEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
290 PointState::Type state ( PointState::DOWN );
292 // Check if the buttons field is set and ensure it's the primary touch button.
293 // If this event was triggered by buttons other than the primary button (used for touch), then
294 // just send an interrupted event to Core.
295 if ( touchEvent->buttons && (touchEvent->buttons != PRIMARY_TOUCH_BUTTON_ID ) )
297 state = PointState::INTERRUPTED;
300 Integration::Point point;
301 point.SetDeviceId( touchEvent->multi.device );
302 point.SetState( state );
303 point.SetScreenPosition( Vector2( touchEvent->x, touchEvent->y ) );
304 point.SetRadius( touchEvent->multi.radius, Vector2( touchEvent->multi.radius_x, touchEvent->multi.radius_y ) );
305 point.SetPressure( touchEvent->multi.pressure );
306 point.SetAngle( Degree( touchEvent->multi.angle ) );
307 handler->SendEvent( point, touchEvent->timestamp );
310 return ECORE_CALLBACK_PASS_ON;
314 * Called when a touch up is received.
316 static Eina_Bool EcoreEventMouseButtonUp( void* data, int type, void* event )
318 Ecore_Event_Mouse_Button *touchEvent( (Ecore_Event_Mouse_Button*)event );
319 EventHandler* handler( (EventHandler*)data );
321 if ( touchEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
323 Integration::Point point;
324 point.SetDeviceId( touchEvent->multi.device );
325 point.SetState( PointState::UP );
326 point.SetScreenPosition( Vector2( touchEvent->x, touchEvent->y ) );
327 point.SetRadius( touchEvent->multi.radius, Vector2( touchEvent->multi.radius_x, touchEvent->multi.radius_y ) );
328 point.SetPressure( touchEvent->multi.pressure );
329 point.SetAngle( Degree( touchEvent->multi.angle ) );
330 handler->SendEvent( point, touchEvent->timestamp );
333 return ECORE_CALLBACK_PASS_ON;
337 * Called when a touch up is received.
339 static Eina_Bool EcoreEventMouseWheel( void* data, int type, void* event )
341 Ecore_Event_Mouse_Wheel *mouseWheelEvent( (Ecore_Event_Mouse_Wheel*)event );
343 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);
345 EventHandler* handler( (EventHandler*)data );
346 if ( mouseWheelEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
348 WheelEvent wheelEvent( WheelEvent::MOUSE_WHEEL, mouseWheelEvent->direction, mouseWheelEvent->modifiers, Vector2(mouseWheelEvent->x, mouseWheelEvent->y), mouseWheelEvent->z, mouseWheelEvent->timestamp );
349 handler->SendWheelEvent( wheelEvent );
351 return ECORE_CALLBACK_PASS_ON;
355 * Called when a touch motion is received.
357 static Eina_Bool EcoreEventMouseButtonMove( void* data, int type, void* event )
359 Ecore_Event_Mouse_Move *touchEvent( (Ecore_Event_Mouse_Move*)event );
360 EventHandler* handler( (EventHandler*)data );
362 if ( touchEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
364 Integration::Point point;
365 point.SetDeviceId( touchEvent->multi.device );
366 point.SetState( PointState::MOTION );
367 point.SetScreenPosition( Vector2( touchEvent->x, touchEvent->y ) );
368 point.SetRadius( touchEvent->multi.radius, Vector2( touchEvent->multi.radius_x, touchEvent->multi.radius_y ) );
369 point.SetPressure( touchEvent->multi.pressure );
370 point.SetAngle( Degree( touchEvent->multi.angle ) );
371 handler->SendEvent( point, touchEvent->timestamp );
374 return ECORE_CALLBACK_PASS_ON;
377 /////////////////////////////////////////////////////////////////////////////////////////////////
379 /////////////////////////////////////////////////////////////////////////////////////////////////
382 * Called when a key down is received.
384 static Eina_Bool EcoreEventKeyDown( void* data, int type, void* event )
386 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventKeyDown \n" );
388 EventHandler* handler( (EventHandler*)data );
389 Ecore_Event_Key *keyEvent( (Ecore_Event_Key*)event );
390 bool eventHandled( false );
392 // If a device key then skip ecore_imf_context_filter_event.
393 if ( ! KeyLookup::IsDeviceButton( keyEvent->keyname ) )
395 Ecore_IMF_Context* imfContext = NULL;
396 Dali::ImfManager imfManager( ImfManager::Get() );
399 imfContext = ImfManager::GetImplementation( imfManager ).GetContext();
404 // We're consuming key down event so we have to pass to IMF so that it can parse it as well.
405 Ecore_IMF_Event_Key_Down ecoreKeyDownEvent;
406 ecoreKeyDownEvent.keyname = keyEvent->keyname;
407 ecoreKeyDownEvent.key = keyEvent->key;
408 ecoreKeyDownEvent.string = keyEvent->string;
409 ecoreKeyDownEvent.compose = keyEvent->compose;
410 ecoreKeyDownEvent.timestamp = keyEvent->timestamp;
411 ecoreKeyDownEvent.modifiers = EcoreInputModifierToEcoreIMFModifier ( keyEvent->modifiers );
412 ecoreKeyDownEvent.locks = (Ecore_IMF_Keyboard_Locks) ECORE_IMF_KEYBOARD_LOCK_NONE;
413 #ifdef ECORE_IMF_1_13
414 ecoreKeyDownEvent.dev_name = "";
415 ecoreKeyDownEvent.dev_class = ECORE_IMF_DEVICE_CLASS_KEYBOARD;
416 ecoreKeyDownEvent.dev_subclass = ECORE_IMF_DEVICE_SUBCLASS_NONE;
417 #endif // ECORE_IMF_1_13
419 eventHandled = ecore_imf_context_filter_event( imfContext,
420 ECORE_IMF_EVENT_KEY_DOWN,
421 (Ecore_IMF_Event *) &ecoreKeyDownEvent );
423 // If the event has not been handled by IMF then check if we should reset our IMF context
426 if ( !strcmp( keyEvent->keyname, "Escape" ) ||
427 !strcmp( keyEvent->keyname, "Return" ) ||
428 !strcmp( keyEvent->keyname, "KP_Enter" ) )
430 ecore_imf_context_reset( imfContext );
436 // If the event wasn't handled then we should send a key event.
439 if ( keyEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
441 std::string keyName( keyEvent->keyname );
442 std::string keyString( "" );
443 int keyCode = KeyLookup::GetDaliKeyCode( keyEvent->keyname);
444 keyCode = (keyCode == -1) ? 0 : keyCode;
445 int modifier( keyEvent->modifiers );
446 unsigned long time = keyEvent->timestamp;
447 if (!strncmp(keyEvent->keyname, "Keycode-", 8))
448 keyCode = atoi(keyEvent->keyname + 8);
450 // Ensure key event string is not NULL as keys like SHIFT have a null string.
451 if ( keyEvent->string )
453 keyString = keyEvent->string;
456 std::string deviceName;
457 GetDeviceName( keyEvent, deviceName );
459 DALI_LOG_INFO( gImfLogging, Debug::Verbose, "EVENT EcoreEventKeyDown - >>EcoreEventKeyDown deviceName(%s)\n", deviceName.c_str() );
461 Integration::KeyEvent keyEvent(keyName, keyString, keyCode, modifier, time, Integration::KeyEvent::Down, deviceName );
462 handler->SendEvent( keyEvent );
466 return ECORE_CALLBACK_PASS_ON;
470 * Called when a key up is received.
472 static Eina_Bool EcoreEventKeyUp( void* data, int type, void* event )
474 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventKeyUp\n" );
476 EventHandler* handler( (EventHandler*)data );
477 Ecore_Event_Key *keyEvent( (Ecore_Event_Key*)event );
478 bool eventHandled( false );
480 // Device keys like Menu, home, back button must skip ecore_imf_context_filter_event.
481 if ( ! KeyLookup::IsDeviceButton( keyEvent->keyname ) )
483 Ecore_IMF_Context* imfContext = NULL;
484 Dali::ImfManager imfManager( ImfManager::Get() );
487 imfContext = ImfManager::GetImplementation( imfManager ).GetContext();
492 // We're consuming key up event so we have to pass to IMF so that it can parse it as well.
493 Ecore_IMF_Event_Key_Up ecoreKeyUpEvent;
494 ecoreKeyUpEvent.keyname = keyEvent->keyname;
495 ecoreKeyUpEvent.key = keyEvent->key;
496 ecoreKeyUpEvent.string = keyEvent->string;
497 ecoreKeyUpEvent.compose = keyEvent->compose;
498 ecoreKeyUpEvent.timestamp = keyEvent->timestamp;
499 ecoreKeyUpEvent.modifiers = EcoreInputModifierToEcoreIMFModifier ( keyEvent->modifiers );
500 ecoreKeyUpEvent.locks = (Ecore_IMF_Keyboard_Locks) ECORE_IMF_KEYBOARD_LOCK_NONE;
501 #ifdef ECORE_IMF_1_13
502 ecoreKeyUpEvent.dev_name = "";
503 ecoreKeyUpEvent.dev_class = ECORE_IMF_DEVICE_CLASS_KEYBOARD;
504 ecoreKeyUpEvent.dev_subclass = ECORE_IMF_DEVICE_SUBCLASS_NONE;
505 #endif // ECORE_IMF_1_13
507 eventHandled = ecore_imf_context_filter_event( imfContext,
508 ECORE_IMF_EVENT_KEY_UP,
509 (Ecore_IMF_Event *) &ecoreKeyUpEvent );
513 // If the event wasn't handled then we should send a key event.
516 if ( keyEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
518 std::string keyName( keyEvent->keyname );
519 std::string keyString( "" );
520 int keyCode = KeyLookup::GetDaliKeyCode( keyEvent->keyname);
521 keyCode = (keyCode == -1) ? 0 : keyCode;
522 int modifier( keyEvent->modifiers );
523 unsigned long time = keyEvent->timestamp;
524 if (!strncmp(keyEvent->keyname, "Keycode-", 8))
525 keyCode = atoi(keyEvent->keyname + 8);
527 // Ensure key event string is not NULL as keys like SHIFT have a null string.
528 if ( keyEvent->string )
530 keyString = keyEvent->string;
533 std::string deviceName;
534 GetDeviceName( keyEvent, deviceName );
536 Integration::KeyEvent keyEvent(keyName, keyString, keyCode, modifier, time, Integration::KeyEvent::Up, deviceName );
537 handler->SendEvent( keyEvent );
541 return ECORE_CALLBACK_PASS_ON;
544 /////////////////////////////////////////////////////////////////////////////////////////////////
546 /////////////////////////////////////////////////////////////////////////////////////////////////
549 * Called when the window gains focus.
551 static Eina_Bool EcoreEventWindowFocusIn( void* data, int type, void* event )
553 Ecore_Wl_Event_Focus_In* focusInEvent( (Ecore_Wl_Event_Focus_In*)event );
554 EventHandler* handler( (EventHandler*)data );
556 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventWindowFocusIn \n" );
558 // If the window gains focus and we hid the keyboard then show it again.
559 if ( focusInEvent->win == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
561 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT EcoreEventWindowFocusIn - >>WindowFocusGained \n" );
563 if ( ImfManager::IsAvailable() /* Only get the ImfManager if it's available as we do not want to create it */ )
565 Dali::ImfManager imfManager( ImfManager::Get() );
568 ImfManager& imfManagerImpl( ImfManager::GetImplementation( imfManager ) );
569 if( imfManagerImpl.RestoreAfterFocusLost() )
571 imfManagerImpl.Activate();
575 Dali::Clipboard clipboard = Clipboard::Get();
576 clipboard.HideClipboard();
579 return ECORE_CALLBACK_PASS_ON;
583 * Called when the window loses focus.
585 static Eina_Bool EcoreEventWindowFocusOut( void* data, int type, void* event )
587 Ecore_Wl_Event_Focus_Out* focusOutEvent( (Ecore_Wl_Event_Focus_Out*)event );
588 EventHandler* handler( (EventHandler*)data );
590 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventWindowFocusOut \n" );
592 // If the window loses focus then hide the keyboard.
593 if ( focusOutEvent->win == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
595 if ( ImfManager::IsAvailable() /* Only get the ImfManager if it's available as we do not want to create it */ )
597 Dali::ImfManager imfManager( ImfManager::Get() );
600 ImfManager& imfManagerImpl( ImfManager::GetImplementation( imfManager ) );
601 if( imfManagerImpl.RestoreAfterFocusLost() )
603 imfManagerImpl.Deactivate();
608 // Hiding clipboard event will be ignored once because window focus out event is always received on showing clipboard
609 Dali::Clipboard clipboard = Clipboard::Get();
612 Clipboard& clipBoardImpl( GetImplementation( clipboard ) );
613 clipBoardImpl.HideClipboard(true);
617 return ECORE_CALLBACK_PASS_ON;
621 * Called when the window is damaged.
623 static Eina_Bool EcoreEventWindowDamaged(void *data, int type, void *event)
625 return ECORE_CALLBACK_PASS_ON;
629 * Called when the window properties are changed.
630 * We are only interested in the font change.
634 /////////////////////////////////////////////////////////////////////////////////////////////////
635 // Drag & Drop Callbacks
636 /////////////////////////////////////////////////////////////////////////////////////////////////
639 * Called when a dragged item enters our window's bounds.
640 * This is when items are dragged INTO our window.
642 static Eina_Bool EcoreEventDndEnter( void* data, int type, void* event )
644 DALI_LOG_INFO( gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndEnter\n" );
646 return ECORE_CALLBACK_PASS_ON;
650 * Called when a dragged item is moved within our window.
651 * This is when items are dragged INTO our window.
653 static Eina_Bool EcoreEventDndPosition( void* data, int type, void* event )
655 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndPosition\n" );
657 return ECORE_CALLBACK_PASS_ON;
661 * Called when a dragged item leaves our window's bounds.
662 * This is when items are dragged INTO our window.
664 static Eina_Bool EcoreEventDndLeave( void* data, int type, void* event )
666 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndLeave\n" );
668 return ECORE_CALLBACK_PASS_ON;
672 * Called when the dragged item is dropped within our window's bounds.
673 * This is when items are dragged INTO our window.
675 static Eina_Bool EcoreEventDndDrop( void* data, int type, void* event )
677 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndDrop\n" );
679 return ECORE_CALLBACK_PASS_ON;
683 * Called when a dragged item is moved from our window and the target window has done processing it.
684 * This is when items are dragged FROM our window.
686 static Eina_Bool EcoreEventDndFinished( void* data, int type, void* event )
688 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndFinished\n" );
689 return ECORE_CALLBACK_PASS_ON;
693 * Called when a dragged item is moved from our window and the target window has sent us a status.
694 * This is when items are dragged FROM our window.
696 static Eina_Bool EcoreEventDndStatus( void* data, int type, void* event )
698 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndStatus\n" );
699 return ECORE_CALLBACK_PASS_ON;
703 * Called when the client messages (i.e. the accessibility events) are received.
705 static Eina_Bool EcoreEventClientMessage( void* data, int type, void* event )
707 return ECORE_CALLBACK_PASS_ON;
711 /////////////////////////////////////////////////////////////////////////////////////////////////
712 // ElDBus Accessibility Callbacks
713 /////////////////////////////////////////////////////////////////////////////////////////////////
715 #ifdef DALI_ELDBUS_AVAILABLE
716 // Callback for Ecore ElDBus accessibility events.
717 static void OnEcoreElDBusAccessibilityNotification( void *context EINA_UNUSED, const Eldbus_Message *message )
719 EventHandler* handler = static_cast< EventHandler* >( context );
720 // Ignore any accessibility events when paused.
721 if( handler->mPaused )
726 if( !handler->mAccessibilityAdaptor )
728 DALI_LOG_ERROR( "Invalid accessibility adaptor\n" );
732 AccessibilityAdaptor* accessibilityAdaptor( &AccessibilityAdaptor::GetImplementation( handler->mAccessibilityAdaptor ) );
733 if( !accessibilityAdaptor )
735 DALI_LOG_ERROR( "Cannot access accessibility adaptor\n" );
741 int state; // 0 - begin, 1 - ongoing, 2 - ended, 3 - aborted
744 // The string defines the arg-list's respective types.
745 if( !eldbus_message_arguments_get( message, "iiiiiiu", &gestureValue, &xS, &yS, &xE, &yE, &state, &eventTime ) )
747 DALI_LOG_ERROR( "OnEcoreElDBusAccessibilityNotification: Error getting arguments\n" );
750 DALI_LOG_INFO( gImfLogging, Debug::General, "Got gesture: Name: %d Args: %d,%d,%d,%d State: %d\n", gestureValue, xS, yS, xE, yE );
752 // Create a touch point object.
753 TouchPoint::State touchPointState( TouchPoint::Down );
756 touchPointState = TouchPoint::Down; // Mouse down.
758 else if( state == 1 )
760 touchPointState = TouchPoint::Motion; // Mouse move.
762 else if( state == 2 )
764 touchPointState = TouchPoint::Up; // Mouse up.
768 touchPointState = TouchPoint::Interrupted; // Error.
771 // Send touch event to accessibility adaptor.
772 TouchPoint point( 0, touchPointState, (float)xS, (float)yS );
774 // Perform actions based on received gestures.
775 // Note: This is seperated from the reading so we can have other input readers without changing the below code.
776 switch( gestureValue )
778 case 0: // OneFingerHover
781 accessibilityAdaptor->HandleActionReadEvent( (unsigned int)xS, (unsigned int)yS, true /* allow read again */ );
784 case 1: // TwoFingersHover
786 // In accessibility mode, scroll action should be handled when the currently focused actor is contained in scrollable control
787 accessibilityAdaptor->HandleActionScrollEvent( point, GetCurrentMilliSeconds() );
790 case 2: // ThreeFingersHover
792 // Read from top item on screen continuously.
793 accessibilityAdaptor->HandleActionReadFromTopEvent();
796 case 3: // OneFingerFlickLeft
798 // Move to previous item.
799 accessibilityAdaptor->HandleActionReadPreviousEvent();
802 case 4: // OneFingerFlickRight
804 // Move to next item.
805 accessibilityAdaptor->HandleActionReadNextEvent();
808 case 5: // OneFingerFlickUp
810 // Move to previous item.
811 accessibilityAdaptor->HandleActionPreviousEvent();
814 case 6: // OneFingerFlickDown
816 // Move to next item.
817 accessibilityAdaptor->HandleActionNextEvent();
820 case 7: // TwoFingersFlickUp
822 // Scroll up the list.
823 accessibilityAdaptor->HandleActionScrollUpEvent();
826 case 8: // TwoFingersFlickDown
828 // Scroll down the list.
829 accessibilityAdaptor->HandleActionScrollDownEvent();
832 case 9: // TwoFingersFlickLeft
834 // Scroll left to the previous page
835 accessibilityAdaptor->HandleActionPageLeftEvent();
838 case 10: // TwoFingersFlickRight
840 // Scroll right to the next page
841 accessibilityAdaptor->HandleActionPageRightEvent();
844 case 11: // ThreeFingersFlickLeft
849 case 12: // ThreeFingersFlickRight
854 case 13: // ThreeFingersFlickUp
859 case 14: // ThreeFingersFlickDown
864 case 15: // OneFingerSingleTap
867 accessibilityAdaptor->HandleActionReadEvent( (unsigned int)xS, (unsigned int)yS, true /* allow read again */ );
870 case 16: // OneFingerDoubleTap
872 // Activate selected item / active edit mode.
873 accessibilityAdaptor->HandleActionActivateEvent();
876 case 17: // OneFingerTripleTap
879 accessibilityAdaptor->HandleActionZoomEvent();
882 case 18: // TwoFingersSingleTap
884 // Pause/Resume current speech
885 accessibilityAdaptor->HandleActionReadPauseResumeEvent();
888 case 19: // TwoFingersDoubleTap
890 // Start/Stop current action
891 accessibilityAdaptor->HandleActionStartStopEvent();
894 case 20: // TwoFingersTripleTap
896 // Read information from indicator
897 accessibilityAdaptor->HandleActionReadIndicatorInformationEvent();
900 case 21: // ThreeFingersSingleTap
902 // Read from top item on screen continuously.
903 accessibilityAdaptor->HandleActionReadFromTopEvent();
906 case 22: // ThreeFingersDoubleTap
908 // Read from next item continuously.
909 accessibilityAdaptor->HandleActionReadFromNextEvent();
912 case 23: // ThreeFingersTripleTap
917 case 24: // OneFingerFlickLeftReturn
919 // Scroll up to the previous page
920 accessibilityAdaptor->HandleActionPageUpEvent();
923 case 25: // OneFingerFlickRightReturn
925 // Scroll down to the next page
926 accessibilityAdaptor->HandleActionPageDownEvent();
929 case 26: // OneFingerFlickUpReturn
931 // Move to the first item on screen
932 accessibilityAdaptor->HandleActionMoveToFirstEvent();
935 case 27: // OneFingerFlickDownReturn
937 // Move to the last item on screen
938 accessibilityAdaptor->HandleActionMoveToLastEvent();
941 case 28: // TwoFingersFlickLeftReturn
946 case 29: // TwoFingersFlickRightReturn
951 case 30: // TwoFingersFlickUpReturn
956 case 31: // TwoFingersFlickDownReturn
961 case 32: // ThreeFingersFlickLeftReturn
966 case 33: // ThreeFingersFlickRightReturn
971 case 34: // ThreeFingersFlickUpReturn
976 case 35: // ThreeFingersFlickDownReturn
984 void EcoreElDBusInitialisation( void *handle )
986 Eldbus_Object *object;
987 Eldbus_Proxy *manager;
989 if( !( mSystemConnection = eldbus_connection_get(ELDBUS_CONNECTION_TYPE_SYSTEM) ) )
991 DALI_LOG_ERROR( "Unable to get system bus\n" );
994 object = eldbus_object_get( mSystemConnection, BUS, PATH );
997 DALI_LOG_ERROR( "Getting object failed\n" );
1001 manager = eldbus_proxy_get( object, INTERFACE );
1004 DALI_LOG_ERROR( "Getting proxy failed\n" );
1008 if( !eldbus_proxy_signal_handler_add( manager, "GestureDetected", OnEcoreElDBusAccessibilityNotification, handle ) )
1010 DALI_LOG_ERROR( "No signal handler returned\n" );
1013 #endif // DALI_ELDBUS_AVAILABLE
1016 * Called when the source window notifies us the content in clipboard is selected.
1018 static Eina_Bool EcoreEventSelectionClear( void* data, int type, void* event )
1020 DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventSelectionClear\n" );
1021 return ECORE_CALLBACK_PASS_ON;
1025 * Called when the source window sends us about the selected content.
1026 * For example, when dragged items are dragged INTO our window or when items are selected in the clipboard.
1028 static Eina_Bool EcoreEventSelectionNotify( void* data, int type, void* event )
1030 DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventSelectionNotify\n" );
1031 return ECORE_CALLBACK_PASS_ON;
1035 * Called when the source window notifies us the content in clipboard is selected.
1037 static Eina_Bool EcoreEventDataSend( void* data, int type, void* event )
1039 DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventDataSend\n" );
1041 Dali::Clipboard clipboard = Clipboard::Get();
1044 Clipboard& clipBoardImpl( GetImplementation( clipboard ) );
1045 clipBoardImpl.ExcuteBuffered( true, event );
1047 return ECORE_CALLBACK_PASS_ON;
1051 * Called when the source window sends us about the selected content.
1052 * For example, when item is selected in the clipboard.
1054 static Eina_Bool EcoreEventDataReceive( void* data, int type, void* event )
1056 DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventDataReceive\n" );
1058 EventHandler* handler( (EventHandler*)data );
1059 Dali::Clipboard clipboard = Clipboard::Get();
1060 char *selectionData = NULL;
1063 Clipboard& clipBoardImpl( GetImplementation( clipboard ) );
1064 selectionData = clipBoardImpl.ExcuteBuffered( false, event );
1066 if ( selectionData && handler->mClipboardEventNotifier )
1068 ClipboardEventNotifier& clipboardEventNotifier( ClipboardEventNotifier::GetImplementation( handler->mClipboardEventNotifier ) );
1069 std::string content( selectionData, strlen(selectionData) );
1071 clipboardEventNotifier.SetContent( content );
1072 clipboardEventNotifier.EmitContentSelectedSignal();
1074 return ECORE_CALLBACK_PASS_ON;
1078 * Called when rotate event is recevied
1080 static Eina_Bool EcoreEventRotate( void* data, int type, void* event )
1082 DALI_LOG_INFO( gSelectionEventLogFilter, Debug::Concise, "EcoreEventRotate\n" );
1084 EventHandler* handler( (EventHandler*)data );
1085 Ecore_Wl_Event_Window_Rotate* ev( (Ecore_Wl_Event_Window_Rotate*)event );
1087 if( ev->win != (unsigned int)ecore_wl_window_id_get( handler->mImpl->mWindow ) )
1089 return ECORE_CALLBACK_PASS_ON;
1092 RotationEvent rotationEvent;
1093 rotationEvent.angle = ev->angle;
1094 rotationEvent.winResize = 0;
1095 rotationEvent.width = ev->w;
1096 rotationEvent.height = ev->h;
1097 handler->SendRotationPrepareEvent( rotationEvent );
1099 return ECORE_CALLBACK_PASS_ON;
1103 * Called when detent event is recevied
1105 static Eina_Bool EcoreEventDetent( void* data, int type, void* event )
1107 DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventDetent\n" );
1108 EventHandler* handler( (EventHandler*)data );
1109 Ecore_Event_Detent_Rotate *e((Ecore_Event_Detent_Rotate *)event);
1110 int direction = (e->direction == ECORE_DETENT_DIRECTION_CLOCKWISE) ? 1 : -1;
1111 int timeStamp = e->timestamp;
1113 WheelEvent wheelEvent( WheelEvent::CUSTOM_WHEEL, 0, 0, Vector2(0.0f, 0.0f), direction, timeStamp );
1114 handler->SendWheelEvent( wheelEvent );
1115 return ECORE_CALLBACK_PASS_ON;
1118 /////////////////////////////////////////////////////////////////////////////////////////////////
1120 /////////////////////////////////////////////////////////////////////////////////////////////////
1122 * Called when a font name is changed.
1124 static void VconfNotifyFontNameChanged( keynode_t* node, void* data )
1126 EventHandler* handler = static_cast<EventHandler*>( data );
1127 handler->SendEvent( StyleChange::DEFAULT_FONT_CHANGE );
1131 * Called when a font size is changed.
1133 static void VconfNotifyFontSizeChanged( keynode_t* node, void* data )
1135 EventHandler* handler = static_cast<EventHandler*>( data );
1136 handler->SendEvent( StyleChange::DEFAULT_FONT_SIZE_CHANGE );
1140 EventHandler* mHandler;
1141 std::vector<Ecore_Event_Handler*> mEcoreEventHandler;
1142 Ecore_Wl_Window* mWindow;
1143 #ifdef DALI_ELDBUS_AVAILABLE
1144 Eldbus_Connection* mSystemConnection;
1145 #endif // DALI_ELDBUS_AVAILABLE
1148 EventHandler::EventHandler( RenderSurface* surface, CoreEventInterface& coreEventInterface, GestureManager& gestureManager, DamageObserver& damageObserver, DragAndDropDetectorPtr dndDetector )
1149 : mCoreEventInterface( coreEventInterface ),
1150 mGestureManager( gestureManager ),
1151 mStyleMonitor( StyleMonitor::Get() ),
1152 mDamageObserver( damageObserver ),
1153 mRotationObserver( NULL ),
1154 mDragAndDropDetector( dndDetector ),
1155 mAccessibilityAdaptor( AccessibilityAdaptor::Get() ),
1156 mClipboardEventNotifier( ClipboardEventNotifier::Get() ),
1157 mClipboard( Clipboard::Get() ),
1161 Ecore_Wl_Window* window = 0;
1163 // this code only works with the Ecore RenderSurface so need to downcast
1164 ECore::WindowRenderSurface* ecoreSurface = dynamic_cast< ECore::WindowRenderSurface* >( surface );
1167 window = ecoreSurface->GetWlWindow();
1170 mImpl = new Impl(this, window);
1173 EventHandler::~EventHandler()
1180 mGestureManager.Stop();
1183 void EventHandler::SendEvent(Integration::Point& point, unsigned long timeStamp)
1187 timeStamp = GetCurrentMilliSeconds();
1190 Integration::TouchEvent touchEvent;
1191 Integration::HoverEvent hoverEvent;
1192 Integration::TouchEventCombiner::EventDispatchType type = mCombiner.GetNextTouchEvent(point, timeStamp, touchEvent, hoverEvent);
1193 if(type != Integration::TouchEventCombiner::DispatchNone )
1195 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);
1197 // First the touch and/or hover event & related gesture events are queued
1198 if(type == Integration::TouchEventCombiner::DispatchTouch || type == Integration::TouchEventCombiner::DispatchBoth)
1200 mCoreEventInterface.QueueCoreEvent( touchEvent );
1201 mGestureManager.SendEvent(touchEvent);
1204 if(type == Integration::TouchEventCombiner::DispatchHover || type == Integration::TouchEventCombiner::DispatchBoth)
1206 mCoreEventInterface.QueueCoreEvent( hoverEvent );
1209 // Next the events are processed with a single call into Core
1210 mCoreEventInterface.ProcessCoreEvents();
1214 void EventHandler::SendEvent(Integration::KeyEvent& keyEvent)
1216 Dali::PhysicalKeyboard physicalKeyboard = PhysicalKeyboard::Get();
1217 if ( physicalKeyboard )
1219 if ( ! KeyLookup::IsDeviceButton( keyEvent.keyName.c_str() ) )
1221 GetImplementation( physicalKeyboard ).KeyReceived( keyEvent.time > 1 );
1225 // Create send KeyEvent to Core.
1226 mCoreEventInterface.QueueCoreEvent( keyEvent );
1227 mCoreEventInterface.ProcessCoreEvents();
1230 void EventHandler::SendWheelEvent( WheelEvent& wheelEvent )
1232 // Create WheelEvent and send to Core.
1233 Integration::WheelEvent event( static_cast< Integration::WheelEvent::Type >(wheelEvent.type), wheelEvent.direction, wheelEvent.modifiers, wheelEvent.point, wheelEvent.z, wheelEvent.timeStamp );
1234 mCoreEventInterface.QueueCoreEvent( event );
1235 mCoreEventInterface.ProcessCoreEvents();
1238 void EventHandler::SendEvent( StyleChange::Type styleChange )
1240 DALI_ASSERT_DEBUG( mStyleMonitor && "StyleMonitor Not Available" );
1241 GetImplementation( mStyleMonitor ).StyleChanged(styleChange);
1244 void EventHandler::SendEvent( const DamageArea& area )
1246 mDamageObserver.OnDamaged( area );
1249 void EventHandler::SendRotationPrepareEvent( const RotationEvent& event )
1251 if( mRotationObserver != NULL )
1253 mRotationObserver->OnRotationPrepare( event );
1254 mRotationObserver->OnRotationRequest();
1258 void EventHandler::SendRotationRequestEvent( )
1260 // No need to separate event into prepare and request in wayland
1263 void EventHandler::FeedTouchPoint( TouchPoint& point, int timeStamp)
1265 Integration::Point convertedPoint( point );
1266 SendEvent(convertedPoint, timeStamp);
1269 void EventHandler::FeedWheelEvent( WheelEvent& wheelEvent )
1271 SendWheelEvent( wheelEvent );
1274 void EventHandler::FeedKeyEvent( KeyEvent& event )
1276 Integration::KeyEvent convertedEvent( event );
1277 SendEvent( convertedEvent );
1280 void EventHandler::FeedEvent( Integration::Event& event )
1282 mCoreEventInterface.QueueCoreEvent( event );
1283 mCoreEventInterface.ProcessCoreEvents();
1286 void EventHandler::Reset()
1290 // Any touch listeners should be told of the interruption.
1291 Integration::TouchEvent event;
1292 Integration::Point point;
1293 point.SetState( PointState::INTERRUPTED );
1294 event.AddPoint( point );
1296 // First the touch event & related gesture events are queued
1297 mCoreEventInterface.QueueCoreEvent( event );
1298 mGestureManager.SendEvent( event );
1300 // Next the events are processed with a single call into Core
1301 mCoreEventInterface.ProcessCoreEvents();
1304 void EventHandler::Pause()
1310 void EventHandler::Resume()
1316 void EventHandler::SetDragAndDropDetector( DragAndDropDetectorPtr detector )
1318 mDragAndDropDetector = detector;
1321 void EventHandler::SetRotationObserver( RotationObserver* observer )
1323 mRotationObserver = observer;
1326 } // namespace Adaptor
1328 } // namespace Internal