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;
90 #ifdef DALI_ELDBUS_AVAILABLE
91 // DBus gesture string matching lists.
92 // TODO: This needs moving to its own module.
93 const char * ElDBusAccessibilityFingerCountStrings[] =
99 const unsigned int FingerCountStringsTotal = sizeof( ElDBusAccessibilityFingerCountStrings ) / sizeof( ElDBusAccessibilityFingerCountStrings[0] );
104 GESTURE_TYPE_SINGLE_TAP,
105 GESTURE_TYPE_DOUBLE_TAP,
106 GESTURE_TYPE_TRIPLE_TAP
108 struct GestureTypeTable
111 const GestureType type;
113 GestureTypeTable ElDBusAccessibilityFullEventTypeStrings[] =
115 { "Hover", GESTURE_TYPE_HOVER },
116 { "SingleTap", GESTURE_TYPE_SINGLE_TAP },
117 { "DoubleTap", GESTURE_TYPE_DOUBLE_TAP },
118 { "TripleTap", GESTURE_TYPE_TRIPLE_TAP }
120 const unsigned int FullEventTypeStringsTotal = sizeof( ElDBusAccessibilityFullEventTypeStrings ) / sizeof( ElDBusAccessibilityFullEventTypeStrings[0] );
123 SUB_GESTURE_TYPE_NONE,
124 SUB_GESTURE_TYPE_FLICK
126 struct SubGestureTypeTable
129 const SubGestureType type;
131 SubGestureTypeTable ElDBusAccessibilityDirectionalEventTypeStrings[] =
133 { "Flick", SUB_GESTURE_TYPE_FLICK }
135 const unsigned int DirectionalEventTypeStringsTotal = sizeof( ElDBusAccessibilityDirectionalEventTypeStrings ) / sizeof( ElDBusAccessibilityDirectionalEventTypeStrings[0] );
136 enum GestureDirection
138 GESTURE_DIRECTION_NONE,
139 GESTURE_DIRECTION_UP,
140 GESTURE_DIRECTION_DOWN,
141 GESTURE_DIRECTION_LEFT,
142 GESTURE_DIRECTION_RIGHT,
143 GESTURE_DIRECTION_UP_RETURN,
144 GESTURE_DIRECTION_DOWN_RETURN,
145 GESTURE_DIRECTION_LEFT_RETURN,
146 GESTURE_DIRECTION_RIGHT_RETURN
148 struct GestureDirectionTable
151 const GestureDirection direction;
153 GestureDirectionTable ElDBusAccessibilityDirectionStrings[] =
155 { "Up", GESTURE_DIRECTION_UP },
156 { "Down", GESTURE_DIRECTION_DOWN },
157 { "Left", GESTURE_DIRECTION_LEFT },
158 { "Right", GESTURE_DIRECTION_RIGHT },
159 { "UpReturn", GESTURE_DIRECTION_UP_RETURN },
160 { "DownReturn", GESTURE_DIRECTION_DOWN_RETURN },
161 { "LeftReturn", GESTURE_DIRECTION_LEFT_RETURN },
162 { "RightReturn", GESTURE_DIRECTION_RIGHT_RETURN }
164 const unsigned int DirectionStringsTotal = sizeof( ElDBusAccessibilityDirectionStrings ) / sizeof( ElDBusAccessibilityDirectionStrings[0] );
165 #endif // DALI_ELDBUS_AVAILABLE
168 * Ecore_Event_Modifier enums in Ecore_Input.h do not match Ecore_IMF_Keyboard_Modifiers in Ecore_IMF.h.
169 * This function converts from Ecore_Event_Modifier to Ecore_IMF_Keyboard_Modifiers enums.
170 * @param[in] ecoreModifier the Ecore_Event_Modifier input.
171 * @return the Ecore_IMF_Keyboard_Modifiers output.
173 Ecore_IMF_Keyboard_Modifiers EcoreInputModifierToEcoreIMFModifier(unsigned int ecoreModifier)
175 int modifier( ECORE_IMF_KEYBOARD_MODIFIER_NONE ); // If no other matches returns NONE.
178 if ( ecoreModifier & ECORE_EVENT_MODIFIER_SHIFT ) // enums from ecore_input/Ecore_Input.h
180 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_SHIFT; // enums from ecore_imf/ecore_imf.h
183 if ( ecoreModifier & ECORE_EVENT_MODIFIER_ALT )
185 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_ALT;
188 if ( ecoreModifier & ECORE_EVENT_MODIFIER_CTRL )
190 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_CTRL;
193 if ( ecoreModifier & ECORE_EVENT_MODIFIER_WIN )
195 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_WIN;
198 if ( ecoreModifier & ECORE_EVENT_MODIFIER_ALTGR )
200 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_ALTGR;
203 return static_cast<Ecore_IMF_Keyboard_Modifiers>( modifier );
207 // Copied from x server
208 static unsigned int GetCurrentMilliSeconds(void)
213 static clockid_t clockid;
217 #ifdef CLOCK_MONOTONIC_COARSE
218 if (clock_getres(CLOCK_MONOTONIC_COARSE, &tp) == 0 &&
219 (tp.tv_nsec / 1000) <= 1000 && clock_gettime(CLOCK_MONOTONIC_COARSE, &tp) == 0)
221 clockid = CLOCK_MONOTONIC_COARSE;
225 if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0)
227 clockid = CLOCK_MONOTONIC;
234 if (clockid != ~0L && clock_gettime(clockid, &tp) == 0)
236 return (tp.tv_sec * 1000) + (tp.tv_nsec / 1000000L);
239 gettimeofday(&tv, NULL);
240 return (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
243 #ifndef DALI_PROFILE_UBUNTU
244 const char * DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE = "db/setting/accessibility/font_name"; // It will be update at vconf-key.h and replaced.
245 #endif // DALI_PROFILE_UBUNTU
247 } // unnamed namespace
249 // Impl to hide EFL implementation.
250 struct EventHandler::Impl
252 // Construction & Destruction
257 Impl( EventHandler* handler, Ecore_Wl_Window* window )
258 : mHandler( handler ),
259 mEcoreEventHandler(),
261 #ifdef DALI_ELDBUS_AVAILABLE
262 , mSystemConnection( NULL )
263 #endif // DALI_ELDBUS_AVAILABLE
265 // Only register for touch and key events if we have a window
268 // Register Touch events
269 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_BUTTON_DOWN, EcoreEventMouseButtonDown, handler ) );
270 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_BUTTON_UP, EcoreEventMouseButtonUp, handler ) );
271 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_MOVE, EcoreEventMouseButtonMove, handler ) );
272 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_OUT, EcoreEventMouseButtonUp, handler ) ); // process mouse out event like up event
274 // Register Mouse wheel events
275 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_WHEEL, EcoreEventMouseWheel, handler ) );
277 // Register Focus events
278 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_WL_EVENT_FOCUS_IN, EcoreEventWindowFocusIn, handler ) );
279 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_WL_EVENT_FOCUS_OUT, EcoreEventWindowFocusOut, handler ) );
281 // Register Key events
282 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_KEY_DOWN, EcoreEventKeyDown, handler ) );
283 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_KEY_UP, EcoreEventKeyUp, handler ) );
285 // Register Selection event - clipboard selection
286 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_WL_EVENT_DATA_SOURCE_SEND, EcoreEventDataSend, handler ) );
287 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_WL_EVENT_SELECTION_DATA_READY, EcoreEventDataReceive, handler ) );
289 // Register Rotate event
290 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_WL_EVENT_WINDOW_ROTATE, EcoreEventRotate, handler) );
292 // Register Detent event
293 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_DETENT_ROTATE, EcoreEventDetent, handler) );
295 #ifndef DALI_PROFILE_UBUNTU
296 // Register Vconf notify - font name and size
297 vconf_notify_key_changed( DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontNameChanged, handler );
298 vconf_notify_key_changed( VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontSizeChanged, handler );
299 #endif // DALI_PROFILE_UBUNTU
301 #ifdef DALI_ELDBUS_AVAILABLE
302 // Initialize ElDBus.
303 DALI_LOG_INFO( gImfLogging, Debug::General, "Starting DBus Initialization\n" );
306 EcoreElDBusInitialisation( handler );
308 DALI_LOG_INFO( gImfLogging, Debug::General, "Finished DBus Initialization\n" );
309 #endif // DALI_ELDBUS_AVAILABLE
318 #ifndef DALI_PROFILE_UBUNTU
319 vconf_ignore_key_changed( VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontSizeChanged );
320 vconf_ignore_key_changed( DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontNameChanged );
321 #endif // DALI_PROFILE_UBUNTU
323 for( std::vector<Ecore_Event_Handler*>::iterator iter = mEcoreEventHandler.begin(), endIter = mEcoreEventHandler.end(); iter != endIter; ++iter )
325 ecore_event_handler_del( *iter );
328 #ifdef DALI_ELDBUS_AVAILABLE
329 // Close down ElDBus connections.
330 if( mSystemConnection )
332 eldbus_connection_unref( mSystemConnection );
334 #endif // DALI_ELDBUS_AVAILABLE
339 /////////////////////////////////////////////////////////////////////////////////////////////////
341 /////////////////////////////////////////////////////////////////////////////////////////////////
344 * Called when a touch down is received.
346 static Eina_Bool EcoreEventMouseButtonDown( void* data, int type, void* event )
348 Ecore_Event_Mouse_Button *touchEvent( (Ecore_Event_Mouse_Button*)event );
349 EventHandler* handler( (EventHandler*)data );
351 if ( touchEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
353 PointState::Type state ( PointState::DOWN );
355 // Check if the buttons field is set and ensure it's the primary touch button.
356 // If this event was triggered by buttons other than the primary button (used for touch), then
357 // just send an interrupted event to Core.
358 if ( touchEvent->buttons && (touchEvent->buttons != PRIMARY_TOUCH_BUTTON_ID ) )
360 state = PointState::INTERRUPTED;
363 Integration::Point point;
364 point.SetDeviceId( touchEvent->multi.device );
365 point.SetState( state );
366 point.SetScreenPosition( Vector2( touchEvent->x, touchEvent->y ) );
367 point.SetRadius( touchEvent->multi.radius, Vector2( touchEvent->multi.radius_x, touchEvent->multi.radius_y ) );
368 point.SetPressure( touchEvent->multi.pressure );
369 point.SetAngle( Degree( touchEvent->multi.angle ) );
370 handler->SendEvent( point, touchEvent->timestamp );
373 return ECORE_CALLBACK_PASS_ON;
377 * Called when a touch up is received.
379 static Eina_Bool EcoreEventMouseButtonUp( void* data, int type, void* event )
381 Ecore_Event_Mouse_Button *touchEvent( (Ecore_Event_Mouse_Button*)event );
382 EventHandler* handler( (EventHandler*)data );
384 if ( touchEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
386 Integration::Point point;
387 point.SetDeviceId( touchEvent->multi.device );
388 point.SetState( PointState::UP );
389 point.SetScreenPosition( Vector2( touchEvent->x, touchEvent->y ) );
390 point.SetRadius( touchEvent->multi.radius, Vector2( touchEvent->multi.radius_x, touchEvent->multi.radius_y ) );
391 point.SetPressure( touchEvent->multi.pressure );
392 point.SetAngle( Degree( touchEvent->multi.angle ) );
393 handler->SendEvent( point, touchEvent->timestamp );
396 return ECORE_CALLBACK_PASS_ON;
400 * Called when a touch up is received.
402 static Eina_Bool EcoreEventMouseWheel( void* data, int type, void* event )
404 Ecore_Event_Mouse_Wheel *mouseWheelEvent( (Ecore_Event_Mouse_Wheel*)event );
406 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);
408 EventHandler* handler( (EventHandler*)data );
409 if ( mouseWheelEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
411 WheelEvent wheelEvent( WheelEvent::MOUSE_WHEEL, mouseWheelEvent->direction, mouseWheelEvent->modifiers, Vector2(mouseWheelEvent->x, mouseWheelEvent->y), mouseWheelEvent->z, mouseWheelEvent->timestamp );
412 handler->SendWheelEvent( wheelEvent );
414 return ECORE_CALLBACK_PASS_ON;
418 * Called when a touch motion is received.
420 static Eina_Bool EcoreEventMouseButtonMove( void* data, int type, void* event )
422 Ecore_Event_Mouse_Move *touchEvent( (Ecore_Event_Mouse_Move*)event );
423 EventHandler* handler( (EventHandler*)data );
425 if ( touchEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
427 Integration::Point point;
428 point.SetDeviceId( touchEvent->multi.device );
429 point.SetState( PointState::MOTION );
430 point.SetScreenPosition( Vector2( touchEvent->x, touchEvent->y ) );
431 point.SetRadius( touchEvent->multi.radius, Vector2( touchEvent->multi.radius_x, touchEvent->multi.radius_y ) );
432 point.SetPressure( touchEvent->multi.pressure );
433 point.SetAngle( Degree( touchEvent->multi.angle ) );
434 handler->SendEvent( point, touchEvent->timestamp );
437 return ECORE_CALLBACK_PASS_ON;
440 /////////////////////////////////////////////////////////////////////////////////////////////////
442 /////////////////////////////////////////////////////////////////////////////////////////////////
445 * Called when a key down is received.
447 static Eina_Bool EcoreEventKeyDown( void* data, int type, void* event )
449 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventKeyDown \n" );
451 EventHandler* handler( (EventHandler*)data );
452 Ecore_Event_Key *keyEvent( (Ecore_Event_Key*)event );
453 bool eventHandled( false );
455 // If a device key then skip ecore_imf_context_filter_event.
456 if ( ! KeyLookup::IsDeviceButton( keyEvent->keyname ) )
458 Ecore_IMF_Context* imfContext = NULL;
459 Dali::ImfManager imfManager( ImfManager::Get() );
462 imfContext = ImfManager::GetImplementation( imfManager ).GetContext();
467 // We're consuming key down event so we have to pass to IMF so that it can parse it as well.
468 Ecore_IMF_Event_Key_Down ecoreKeyDownEvent;
469 ecoreKeyDownEvent.keyname = keyEvent->keyname;
470 ecoreKeyDownEvent.key = keyEvent->key;
471 ecoreKeyDownEvent.string = keyEvent->string;
472 ecoreKeyDownEvent.compose = keyEvent->compose;
473 ecoreKeyDownEvent.timestamp = keyEvent->timestamp;
474 ecoreKeyDownEvent.modifiers = EcoreInputModifierToEcoreIMFModifier ( keyEvent->modifiers );
475 ecoreKeyDownEvent.locks = (Ecore_IMF_Keyboard_Locks) ECORE_IMF_KEYBOARD_LOCK_NONE;
476 #ifdef ECORE_IMF_1_13
477 ecoreKeyDownEvent.dev_name = "";
478 ecoreKeyDownEvent.dev_class = ECORE_IMF_DEVICE_CLASS_KEYBOARD;
479 ecoreKeyDownEvent.dev_subclass = ECORE_IMF_DEVICE_SUBCLASS_NONE;
480 #endif // ECORE_IMF_1_13
482 eventHandled = ecore_imf_context_filter_event( imfContext,
483 ECORE_IMF_EVENT_KEY_DOWN,
484 (Ecore_IMF_Event *) &ecoreKeyDownEvent );
486 // If the event has not been handled by IMF then check if we should reset our IMF context
489 if ( !strcmp( keyEvent->keyname, "Escape" ) ||
490 !strcmp( keyEvent->keyname, "Return" ) ||
491 !strcmp( keyEvent->keyname, "KP_Enter" ) )
493 ecore_imf_context_reset( imfContext );
499 // If the event wasn't handled then we should send a key event.
502 if ( keyEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
504 std::string keyName( keyEvent->keyname );
505 std::string keyString( "" );
506 int keyCode = KeyLookup::GetDaliKeyCode( keyEvent->keyname);
507 keyCode = (keyCode == -1) ? 0 : keyCode;
508 int modifier( keyEvent->modifiers );
509 unsigned long time = keyEvent->timestamp;
510 if (!strncmp(keyEvent->keyname, "Keycode-", 8))
511 keyCode = atoi(keyEvent->keyname + 8);
513 // Ensure key event string is not NULL as keys like SHIFT have a null string.
514 if ( keyEvent->string )
516 keyString = keyEvent->string;
519 KeyEvent keyEvent(keyName, keyString, keyCode, modifier, time, KeyEvent::Down);
520 handler->SendEvent( keyEvent );
524 return ECORE_CALLBACK_PASS_ON;
528 * Called when a key up is received.
530 static Eina_Bool EcoreEventKeyUp( void* data, int type, void* event )
532 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventKeyUp\n" );
534 EventHandler* handler( (EventHandler*)data );
535 Ecore_Event_Key *keyEvent( (Ecore_Event_Key*)event );
536 bool eventHandled( false );
538 // Device keys like Menu, home, back button must skip ecore_imf_context_filter_event.
539 if ( ! KeyLookup::IsDeviceButton( keyEvent->keyname ) )
541 Ecore_IMF_Context* imfContext = NULL;
542 Dali::ImfManager imfManager( ImfManager::Get() );
545 imfContext = ImfManager::GetImplementation( imfManager ).GetContext();
550 // We're consuming key up event so we have to pass to IMF so that it can parse it as well.
551 Ecore_IMF_Event_Key_Up ecoreKeyUpEvent;
552 ecoreKeyUpEvent.keyname = keyEvent->keyname;
553 ecoreKeyUpEvent.key = keyEvent->key;
554 ecoreKeyUpEvent.string = keyEvent->string;
555 ecoreKeyUpEvent.compose = keyEvent->compose;
556 ecoreKeyUpEvent.timestamp = keyEvent->timestamp;
557 ecoreKeyUpEvent.modifiers = EcoreInputModifierToEcoreIMFModifier ( keyEvent->modifiers );
558 ecoreKeyUpEvent.locks = (Ecore_IMF_Keyboard_Locks) ECORE_IMF_KEYBOARD_LOCK_NONE;
560 eventHandled = ecore_imf_context_filter_event( imfContext,
561 ECORE_IMF_EVENT_KEY_UP,
562 (Ecore_IMF_Event *) &ecoreKeyUpEvent );
566 // If the event wasn't handled then we should send a key event.
569 if ( keyEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
571 std::string keyName( keyEvent->keyname );
572 std::string keyString( "" );
573 int keyCode = KeyLookup::GetDaliKeyCode( keyEvent->keyname);
574 keyCode = (keyCode == -1) ? 0 : keyCode;
575 int modifier( keyEvent->modifiers );
576 unsigned long time = keyEvent->timestamp;
577 if (!strncmp(keyEvent->keyname, "Keycode-", 8))
578 keyCode = atoi(keyEvent->keyname + 8);
580 // Ensure key event string is not NULL as keys like SHIFT have a null string.
581 if ( keyEvent->string )
583 keyString = keyEvent->string;
586 KeyEvent keyEvent(keyName, keyString, keyCode, modifier, time, KeyEvent::Up);
587 handler->SendEvent( keyEvent );
591 return ECORE_CALLBACK_PASS_ON;
594 /////////////////////////////////////////////////////////////////////////////////////////////////
596 /////////////////////////////////////////////////////////////////////////////////////////////////
599 * Called when the window gains focus.
601 static Eina_Bool EcoreEventWindowFocusIn( void* data, int type, void* event )
603 Ecore_Wl_Event_Focus_In* focusInEvent( (Ecore_Wl_Event_Focus_In*)event );
604 EventHandler* handler( (EventHandler*)data );
606 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventWindowFocusIn \n" );
608 // If the window gains focus and we hid the keyboard then show it again.
609 if ( focusInEvent->win == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
611 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT EcoreEventWindowFocusIn - >>WindowFocusGained \n" );
613 if ( ImfManager::IsAvailable() /* Only get the ImfManager if it's available as we do not want to create it */ )
615 Dali::ImfManager imfManager( ImfManager::Get() );
618 ImfManager& imfManagerImpl( ImfManager::GetImplementation( imfManager ) );
619 if( imfManagerImpl.RestoreAfterFocusLost() )
621 imfManagerImpl.Activate();
625 Dali::Clipboard clipboard = Clipboard::Get();
626 clipboard.HideClipboard();
629 return ECORE_CALLBACK_PASS_ON;
633 * Called when the window loses focus.
635 static Eina_Bool EcoreEventWindowFocusOut( void* data, int type, void* event )
637 Ecore_Wl_Event_Focus_Out* focusOutEvent( (Ecore_Wl_Event_Focus_Out*)event );
638 EventHandler* handler( (EventHandler*)data );
640 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventWindowFocusOut \n" );
642 // If the window loses focus then hide the keyboard.
643 if ( focusOutEvent->win == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
645 if ( ImfManager::IsAvailable() /* Only get the ImfManager if it's available as we do not want to create it */ )
647 Dali::ImfManager imfManager( ImfManager::Get() );
650 ImfManager& imfManagerImpl( ImfManager::GetImplementation( imfManager ) );
651 if( imfManagerImpl.RestoreAfterFocusLost() )
653 imfManagerImpl.Deactivate();
658 // Hiding clipboard event will be ignored once because window focus out event is always received on showing clipboard
659 Dali::Clipboard clipboard = Clipboard::Get();
662 Clipboard& clipBoardImpl( GetImplementation( clipboard ) );
663 clipBoardImpl.HideClipboard(true);
667 return ECORE_CALLBACK_PASS_ON;
671 * Called when the window is damaged.
673 static Eina_Bool EcoreEventWindowDamaged(void *data, int type, void *event)
675 return ECORE_CALLBACK_PASS_ON;
679 * Called when the window properties are changed.
680 * We are only interested in the font change.
684 /////////////////////////////////////////////////////////////////////////////////////////////////
685 // Drag & Drop Callbacks
686 /////////////////////////////////////////////////////////////////////////////////////////////////
689 * Called when a dragged item enters our window's bounds.
690 * This is when items are dragged INTO our window.
692 static Eina_Bool EcoreEventDndEnter( void* data, int type, void* event )
694 DALI_LOG_INFO( gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndEnter\n" );
696 return ECORE_CALLBACK_PASS_ON;
700 * Called when a dragged item is moved within our window.
701 * This is when items are dragged INTO our window.
703 static Eina_Bool EcoreEventDndPosition( void* data, int type, void* event )
705 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndPosition\n" );
707 return ECORE_CALLBACK_PASS_ON;
711 * Called when a dragged item leaves our window's bounds.
712 * This is when items are dragged INTO our window.
714 static Eina_Bool EcoreEventDndLeave( void* data, int type, void* event )
716 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndLeave\n" );
718 return ECORE_CALLBACK_PASS_ON;
722 * Called when the dragged item is dropped within our window's bounds.
723 * This is when items are dragged INTO our window.
725 static Eina_Bool EcoreEventDndDrop( void* data, int type, void* event )
727 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndDrop\n" );
729 return ECORE_CALLBACK_PASS_ON;
733 * Called when a dragged item is moved from our window and the target window has done processing it.
734 * This is when items are dragged FROM our window.
736 static Eina_Bool EcoreEventDndFinished( void* data, int type, void* event )
738 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndFinished\n" );
739 return ECORE_CALLBACK_PASS_ON;
743 * Called when a dragged item is moved from our window and the target window has sent us a status.
744 * This is when items are dragged FROM our window.
746 static Eina_Bool EcoreEventDndStatus( void* data, int type, void* event )
748 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndStatus\n" );
749 return ECORE_CALLBACK_PASS_ON;
753 * Called when the client messages (i.e. the accessibility events) are received.
755 static Eina_Bool EcoreEventClientMessage( void* data, int type, void* event )
757 return ECORE_CALLBACK_PASS_ON;
761 /////////////////////////////////////////////////////////////////////////////////////////////////
762 // ElDBus Accessibility Callbacks
763 /////////////////////////////////////////////////////////////////////////////////////////////////
765 #ifdef DALI_ELDBUS_AVAILABLE
766 // Callback for Ecore ElDBus accessibility events.
767 static void OnEcoreElDBusAccessibilityNotification( void *context EINA_UNUSED, const Eldbus_Message *message )
769 EventHandler* handler = static_cast< EventHandler* >( context );
770 // Ignore any accessibility events when paused.
771 if( handler->mPaused )
776 if( !handler->mAccessibilityAdaptor )
778 DALI_LOG_ERROR( "Invalid accessibility adaptor\n" );
782 AccessibilityAdaptor* accessibilityAdaptor( &AccessibilityAdaptor::GetImplementation( handler->mAccessibilityAdaptor ) );
783 if( !accessibilityAdaptor )
785 DALI_LOG_ERROR( "Cannot access accessibility adaptor\n" );
791 int state; // 0 - begin, 1 - ongoing, 2 - ended, 3 - aborted
794 // The string defines the arg-list's respective types.
795 if( !eldbus_message_arguments_get( message, "iiiiiiu", &gestureValue, &xS, &yS, &xE, &yE, &state, &eventTime ) )
797 DALI_LOG_ERROR( "OnEcoreElDBusAccessibilityNotification: Error getting arguments\n" );
800 DALI_LOG_INFO( gImfLogging, Debug::General, "Got gesture: Name: %d Args: %d,%d,%d,%d State: %d\n", gestureValue, xS, yS, xE, yE );
802 // Create a touch point object.
803 TouchPoint::State touchPointState( TouchPoint::Down );
806 touchPointState = TouchPoint::Down; // Mouse down.
808 else if( state == 1 )
810 touchPointState = TouchPoint::Motion; // Mouse move.
812 else if( state == 2 )
814 touchPointState = TouchPoint::Up; // Mouse up.
818 touchPointState = TouchPoint::Interrupted; // Error.
821 // Send touch event to accessibility adaptor.
822 TouchPoint point( 0, touchPointState, (float)xS, (float)yS );
824 // Perform actions based on received gestures.
825 // Note: This is seperated from the reading so we can have other input readers without changing the below code.
826 switch( gestureValue )
828 case 0: // OneFingerHover
831 accessibilityAdaptor->HandleActionReadEvent( (unsigned int)xS, (unsigned int)yS, true /* allow read again */ );
834 case 1: // TwoFingersHover
836 // In accessibility mode, scroll action should be handled when the currently focused actor is contained in scrollable control
837 accessibilityAdaptor->HandleActionScrollEvent( point, GetCurrentMilliSeconds() );
840 case 2: // ThreeFingersHover
842 // Read from top item on screen continuously.
843 accessibilityAdaptor->HandleActionReadFromTopEvent();
846 case 3: // OneFingerFlickLeft
848 // Move to previous item.
849 accessibilityAdaptor->HandleActionReadPreviousEvent();
852 case 4: // OneFingerFlickRight
854 // Move to next item.
855 accessibilityAdaptor->HandleActionReadNextEvent();
858 case 5: // OneFingerFlickUp
860 // Move to previous item.
861 accessibilityAdaptor->HandleActionPreviousEvent();
864 case 6: // OneFingerFlickDown
866 // Move to next item.
867 accessibilityAdaptor->HandleActionNextEvent();
870 case 7: // TwoFingersFlickUp
872 // Scroll up the list.
873 accessibilityAdaptor->HandleActionScrollUpEvent();
876 case 8: // TwoFingersFlickDown
878 // Scroll down the list.
879 accessibilityAdaptor->HandleActionScrollDownEvent();
882 case 9: // TwoFingersFlickLeft
884 // Scroll left to the previous page
885 accessibilityAdaptor->HandleActionPageLeftEvent();
888 case 10: // TwoFingersFlickRight
890 // Scroll right to the next page
891 accessibilityAdaptor->HandleActionPageRightEvent();
894 case 11: // ThreeFingersFlickLeft
899 case 12: // ThreeFingersFlickRight
904 case 13: // ThreeFingersFlickUp
909 case 14: // ThreeFingersFlickDown
914 case 15: // OneFingerSingleTap
917 accessibilityAdaptor->HandleActionReadEvent( (unsigned int)xS, (unsigned int)yS, true /* allow read again */ );
920 case 16: // OneFingerDoubleTap
922 // Activate selected item / active edit mode.
923 accessibilityAdaptor->HandleActionActivateEvent();
926 case 17: // OneFingerTripleTap
929 accessibilityAdaptor->HandleActionZoomEvent();
932 case 18: // TwoFingersSingleTap
934 // Pause/Resume current speech
935 accessibilityAdaptor->HandleActionReadPauseResumeEvent();
938 case 19: // TwoFingersDoubleTap
940 // Start/Stop current action
941 accessibilityAdaptor->HandleActionStartStopEvent();
944 case 20: // TwoFingersTripleTap
946 // Read information from indicator
947 accessibilityAdaptor->HandleActionReadIndicatorInformationEvent();
950 case 21: // ThreeFingersSingleTap
952 // Read from top item on screen continuously.
953 accessibilityAdaptor->HandleActionReadFromTopEvent();
956 case 22: // ThreeFingersDoubleTap
958 // Read from next item continuously.
959 accessibilityAdaptor->HandleActionReadFromNextEvent();
962 case 23: // ThreeFingersTripleTap
967 case 24: // OneFingerFlickLeftReturn
969 // Scroll up to the previous page
970 accessibilityAdaptor->HandleActionPageUpEvent();
973 case 25: // OneFingerFlickRightReturn
975 // Scroll down to the next page
976 accessibilityAdaptor->HandleActionPageDownEvent();
979 case 26: // OneFingerFlickUpReturn
981 // Move to the first item on screen
982 accessibilityAdaptor->HandleActionMoveToFirstEvent();
985 case 27: // OneFingerFlickDownReturn
987 // Move to the last item on screen
988 accessibilityAdaptor->HandleActionMoveToLastEvent();
991 case 28: // TwoFingersFlickLeftReturn
996 case 29: // TwoFingersFlickRightReturn
1001 case 30: // TwoFingersFlickUpReturn
1006 case 31: // TwoFingersFlickDownReturn
1011 case 32: // ThreeFingersFlickLeftReturn
1016 case 33: // ThreeFingersFlickRightReturn
1021 case 34: // ThreeFingersFlickUpReturn
1026 case 35: // ThreeFingersFlickDownReturn
1034 void EcoreElDBusInitialisation( void *handle )
1036 Eldbus_Object *object;
1037 Eldbus_Proxy *manager;
1039 if( !( mSystemConnection = eldbus_connection_get(ELDBUS_CONNECTION_TYPE_SYSTEM) ) )
1041 DALI_LOG_ERROR( "Unable to get system bus\n" );
1044 object = eldbus_object_get( mSystemConnection, BUS, PATH );
1047 DALI_LOG_ERROR( "Getting object failed\n" );
1051 manager = eldbus_proxy_get( object, INTERFACE );
1054 DALI_LOG_ERROR( "Getting proxy failed\n" );
1058 if( !eldbus_proxy_signal_handler_add( manager, "GestureDetected", OnEcoreElDBusAccessibilityNotification, handle ) )
1060 DALI_LOG_ERROR( "No signal handler returned\n" );
1063 #endif // DALI_ELDBUS_AVAILABLE
1066 * Called when the source window notifies us the content in clipboard is selected.
1068 static Eina_Bool EcoreEventSelectionClear( void* data, int type, void* event )
1070 DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventSelectionClear\n" );
1071 return ECORE_CALLBACK_PASS_ON;
1075 * Called when the source window sends us about the selected content.
1076 * For example, when dragged items are dragged INTO our window or when items are selected in the clipboard.
1078 static Eina_Bool EcoreEventSelectionNotify( void* data, int type, void* event )
1080 DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventSelectionNotify\n" );
1081 return ECORE_CALLBACK_PASS_ON;
1085 * Called when the source window notifies us the content in clipboard is selected.
1087 static Eina_Bool EcoreEventDataSend( void* data, int type, void* event )
1089 DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventDataSend\n" );
1091 Dali::Clipboard clipboard = Clipboard::Get();
1094 Clipboard& clipBoardImpl( GetImplementation( clipboard ) );
1095 clipBoardImpl.ExcuteBuffered( true, event );
1097 return ECORE_CALLBACK_PASS_ON;
1101 * Called when the source window sends us about the selected content.
1102 * For example, when item is selected in the clipboard.
1104 static Eina_Bool EcoreEventDataReceive( void* data, int type, void* event )
1106 DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventDataReceive\n" );
1108 EventHandler* handler( (EventHandler*)data );
1109 Dali::Clipboard clipboard = Clipboard::Get();
1110 char *selectionData = NULL;
1113 Clipboard& clipBoardImpl( GetImplementation( clipboard ) );
1114 selectionData = clipBoardImpl.ExcuteBuffered( false, event );
1116 if ( selectionData && handler->mClipboardEventNotifier )
1118 ClipboardEventNotifier& clipboardEventNotifier( ClipboardEventNotifier::GetImplementation( handler->mClipboardEventNotifier ) );
1119 std::string content( selectionData, strlen(selectionData) );
1121 clipboardEventNotifier.SetContent( content );
1122 clipboardEventNotifier.EmitContentSelectedSignal();
1124 return ECORE_CALLBACK_PASS_ON;
1128 * Called when rotate event is recevied
1130 static Eina_Bool EcoreEventRotate( void* data, int type, void* event )
1132 DALI_LOG_INFO( gSelectionEventLogFilter, Debug::Concise, "EcoreEventRotate\n" );
1134 EventHandler* handler( (EventHandler*)data );
1135 Ecore_Wl_Event_Window_Rotate* ev( (Ecore_Wl_Event_Window_Rotate*)event );
1137 if( ev->win != (unsigned int)ecore_wl_window_id_get( handler->mImpl->mWindow ) )
1139 return ECORE_CALLBACK_PASS_ON;
1142 RotationEvent rotationEvent;
1143 rotationEvent.angle = ev->angle;
1144 rotationEvent.winResize = 0;
1145 rotationEvent.width = ev->w;
1146 rotationEvent.height = ev->h;
1147 handler->SendRotationPrepareEvent( rotationEvent );
1149 return ECORE_CALLBACK_PASS_ON;
1153 * Called when detent event is recevied
1155 static Eina_Bool EcoreEventDetent( void* data, int type, void* event )
1157 DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventDetent\n" );
1158 EventHandler* handler( (EventHandler*)data );
1159 Ecore_Event_Detent_Rotate *e((Ecore_Event_Detent_Rotate *)event);
1160 int direction = (e->direction == ECORE_DETENT_DIRECTION_CLOCKWISE) ? 1 : -1;
1161 int timeStamp = e->timestamp;
1163 WheelEvent wheelEvent( WheelEvent::CUSTOM_WHEEL, 0, 0, Vector2(0.0f, 0.0f), direction, timeStamp );
1164 handler->SendWheelEvent( wheelEvent );
1165 return ECORE_CALLBACK_PASS_ON;
1168 /////////////////////////////////////////////////////////////////////////////////////////////////
1170 /////////////////////////////////////////////////////////////////////////////////////////////////
1172 * Called when a font name is changed.
1174 static void VconfNotifyFontNameChanged( keynode_t* node, void* data )
1176 EventHandler* handler = static_cast<EventHandler*>( data );
1177 handler->SendEvent( StyleChange::DEFAULT_FONT_CHANGE );
1181 * Called when a font size is changed.
1183 static void VconfNotifyFontSizeChanged( keynode_t* node, void* data )
1185 EventHandler* handler = static_cast<EventHandler*>( data );
1186 handler->SendEvent( StyleChange::DEFAULT_FONT_SIZE_CHANGE );
1190 EventHandler* mHandler;
1191 std::vector<Ecore_Event_Handler*> mEcoreEventHandler;
1192 Ecore_Wl_Window* mWindow;
1193 #ifdef DALI_ELDBUS_AVAILABLE
1194 Eldbus_Connection* mSystemConnection;
1195 #endif // DALI_ELDBUS_AVAILABLE
1198 EventHandler::EventHandler( RenderSurface* surface, CoreEventInterface& coreEventInterface, GestureManager& gestureManager, DamageObserver& damageObserver, DragAndDropDetectorPtr dndDetector )
1199 : mCoreEventInterface( coreEventInterface ),
1200 mGestureManager( gestureManager ),
1201 mStyleMonitor( StyleMonitor::Get() ),
1202 mDamageObserver( damageObserver ),
1203 mRotationObserver( NULL ),
1204 mDragAndDropDetector( dndDetector ),
1205 mAccessibilityAdaptor( AccessibilityAdaptor::Get() ),
1206 mClipboardEventNotifier( ClipboardEventNotifier::Get() ),
1207 mClipboard( Clipboard::Get() ),
1211 Ecore_Wl_Window* window = 0;
1213 // this code only works with the Ecore RenderSurface so need to downcast
1214 ECore::WindowRenderSurface* ecoreSurface = dynamic_cast< ECore::WindowRenderSurface* >( surface );
1217 window = ecoreSurface->GetWlWindow();
1220 mImpl = new Impl(this, window);
1223 EventHandler::~EventHandler()
1230 mGestureManager.Stop();
1233 void EventHandler::SendEvent(Integration::Point& point, unsigned long timeStamp)
1237 timeStamp = GetCurrentMilliSeconds();
1240 Integration::TouchEvent touchEvent;
1241 Integration::HoverEvent hoverEvent;
1242 Integration::TouchEventCombiner::EventDispatchType type = mCombiner.GetNextTouchEvent(point, timeStamp, touchEvent, hoverEvent);
1243 if(type != Integration::TouchEventCombiner::DispatchNone )
1245 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);
1247 // First the touch and/or hover event & related gesture events are queued
1248 if(type == Integration::TouchEventCombiner::DispatchTouch || type == Integration::TouchEventCombiner::DispatchBoth)
1250 mCoreEventInterface.QueueCoreEvent( touchEvent );
1251 mGestureManager.SendEvent(touchEvent);
1254 if(type == Integration::TouchEventCombiner::DispatchHover || type == Integration::TouchEventCombiner::DispatchBoth)
1256 mCoreEventInterface.QueueCoreEvent( hoverEvent );
1259 // Next the events are processed with a single call into Core
1260 mCoreEventInterface.ProcessCoreEvents();
1264 void EventHandler::SendEvent(KeyEvent& keyEvent)
1266 Dali::PhysicalKeyboard physicalKeyboard = PhysicalKeyboard::Get();
1267 if ( physicalKeyboard )
1269 if ( ! KeyLookup::IsDeviceButton( keyEvent.keyPressedName.c_str() ) )
1271 GetImplementation( physicalKeyboard ).KeyReceived( keyEvent.time > 1 );
1275 // Create KeyEvent and send to Core.
1276 Integration::KeyEvent event(keyEvent.keyPressedName, keyEvent.keyPressed, keyEvent.keyCode,
1277 keyEvent.keyModifier, keyEvent.time, static_cast<Integration::KeyEvent::State>(keyEvent.state));
1278 mCoreEventInterface.QueueCoreEvent( event );
1279 mCoreEventInterface.ProcessCoreEvents();
1282 void EventHandler::SendWheelEvent( WheelEvent& wheelEvent )
1284 // Create WheelEvent and send to Core.
1285 Integration::WheelEvent event( static_cast< Integration::WheelEvent::Type >(wheelEvent.type), wheelEvent.direction, wheelEvent.modifiers, wheelEvent.point, wheelEvent.z, wheelEvent.timeStamp );
1286 mCoreEventInterface.QueueCoreEvent( event );
1287 mCoreEventInterface.ProcessCoreEvents();
1290 void EventHandler::SendEvent( StyleChange::Type styleChange )
1292 DALI_ASSERT_DEBUG( mStyleMonitor && "StyleMonitor Not Available" );
1293 GetImplementation( mStyleMonitor ).StyleChanged(styleChange);
1296 void EventHandler::SendEvent( const DamageArea& area )
1298 mDamageObserver.OnDamaged( area );
1301 void EventHandler::SendRotationPrepareEvent( const RotationEvent& event )
1303 if( mRotationObserver != NULL )
1305 mRotationObserver->OnRotationPrepare( event );
1306 mRotationObserver->OnRotationRequest();
1310 void EventHandler::SendRotationRequestEvent( )
1312 // No need to separate event into prepare and request in wayland
1315 void EventHandler::FeedTouchPoint( TouchPoint& point, int timeStamp)
1317 Integration::Point convertedPoint( point );
1318 SendEvent(convertedPoint, timeStamp);
1321 void EventHandler::FeedWheelEvent( WheelEvent& wheelEvent )
1323 SendWheelEvent( wheelEvent );
1326 void EventHandler::FeedKeyEvent( KeyEvent& event )
1331 void EventHandler::FeedEvent( Integration::Event& event )
1333 mCoreEventInterface.QueueCoreEvent( event );
1334 mCoreEventInterface.ProcessCoreEvents();
1337 void EventHandler::Reset()
1341 // Any touch listeners should be told of the interruption.
1342 Integration::TouchEvent event;
1343 Integration::Point point;
1344 point.SetState( PointState::INTERRUPTED );
1345 event.AddPoint( point );
1347 // First the touch event & related gesture events are queued
1348 mCoreEventInterface.QueueCoreEvent( event );
1349 mGestureManager.SendEvent( event );
1351 // Next the events are processed with a single call into Core
1352 mCoreEventInterface.ProcessCoreEvents();
1355 void EventHandler::Pause()
1361 void EventHandler::Resume()
1367 void EventHandler::SetDragAndDropDetector( DragAndDropDetectorPtr detector )
1369 mDragAndDropDetector = detector;
1372 void EventHandler::SetRotationObserver( RotationObserver* observer )
1374 mRotationObserver = observer;
1377 } // namespace Adaptor
1379 } // namespace Internal