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>
27 #include <X11/extensions/XInput2.h>
28 #include <X11/extensions/XI2.h>
34 #ifndef DALI_PROFILE_UBUNTU
36 #include <vconf-keys.h>
37 #endif // DALI_PROFILE_UBUNTU
39 #ifdef DALI_ELDBUS_AVAILABLE
41 #endif // DALI_ELDBUS_AVAILABLE
43 #include <dali/public-api/common/vector-wrapper.h>
44 #include <dali/public-api/events/touch-point.h>
45 #include <dali/public-api/events/key-event.h>
46 #include <dali/public-api/events/wheel-event.h>
47 #include <dali/integration-api/debug.h>
48 #include <dali/integration-api/events/key-event-integ.h>
49 #include <dali/integration-api/events/touch-event-integ.h>
50 #include <dali/integration-api/events/hover-event-integ.h>
51 #include <dali/integration-api/events/wheel-event-integ.h>
54 #include <events/gesture-manager.h>
55 #include <window-render-surface.h>
56 #include <clipboard-impl.h>
58 #include <physical-keyboard-impl.h>
59 #include <style-monitor-impl.h>
60 #include <base/core-event-interface.h>
71 #if defined(DEBUG_ENABLED)
74 Integration::Log::Filter* gTouchEventLogFilter = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_TOUCH");
75 Integration::Log::Filter* gClientMessageLogFilter = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_CLIENT_MESSAGE");
76 Integration::Log::Filter* gDragAndDropLogFilter = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_DND");
77 Integration::Log::Filter* gImfLogging = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_IMF");
78 Integration::Log::Filter* gSelectionEventLogFilter = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_SELECTION");
79 } // unnamed namespace
86 const char * DETENT_DEVICE_NAME = "tizen_detent";
89 #define A11Y_BUS "org.a11y.Bus"
90 #define A11Y_INTERFACE "org.a11y.Bus"
91 #define A11Y_PATH "/org/a11y/bus"
92 #define A11Y_GET_ADDRESS "GetAddress"
93 #define BUS "com.samsung.EModule"
94 #define INTERFACE "com.samsung.GestureNavigation"
95 #define PATH "/com/samsung/GestureNavigation"
96 #define SIGNAL "GestureDetected"
98 #ifndef DALI_PROFILE_UBUNTU
99 const char * DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME = "db/setting/accessibility/font_name"; // It will be update at vconf-key.h and replaced.
100 #endif // DALI_PROFILE_UBUNTU
102 const unsigned int PRIMARY_TOUCH_BUTTON_ID( 1 );
104 #ifndef DALI_PROFILE_UBUNTU
105 const char * CLIPBOARD_ATOM = "CBHM_MSG";
106 const char * CLIPBOARD_SET_OWNER_MESSAGE = "SET_OWNER";
107 #endif // DALI_PROFILE_UBUNTU
109 /// The atoms required by Ecore for Drag & Drop behaviour.
110 Ecore_X_Atom DRAG_AND_DROP_ATOMS[] =
112 ECORE_X_ATOM_XDND_ACTION_COPY,
115 /// The types that we support.
116 const char * DRAG_AND_DROP_TYPES[] =
118 ECORE_X_SELECTION_TARGET_UTF8_STRING,
121 const unsigned int DRAG_AND_DROP_ATOMS_NUMBER = sizeof( DRAG_AND_DROP_ATOMS ) / sizeof( Ecore_X_Atom );
122 const unsigned int DRAG_AND_DROP_TYPES_NUMBER = sizeof( DRAG_AND_DROP_TYPES ) / sizeof( const char * );
124 const unsigned int BYTES_PER_CHARACTER_FOR_ATTRIBUTES = 3;
126 #ifdef DALI_ELDBUS_AVAILABLE
127 // DBus gesture string matching lists.
128 // TODO: This needs moving to its own module.
129 const char * ElDBusAccessibilityFingerCountStrings[] =
135 const unsigned int FingerCountStringsTotal = sizeof( ElDBusAccessibilityFingerCountStrings ) / sizeof( ElDBusAccessibilityFingerCountStrings[0] );
140 GESTURE_TYPE_SINGLE_TAP,
141 GESTURE_TYPE_DOUBLE_TAP,
142 GESTURE_TYPE_TRIPLE_TAP
144 struct GestureTypeTable
147 const GestureType type;
149 GestureTypeTable ElDBusAccessibilityFullEventTypeStrings[] =
151 { "Hover", GESTURE_TYPE_HOVER },
152 { "SingleTap", GESTURE_TYPE_SINGLE_TAP },
153 { "DoubleTap", GESTURE_TYPE_DOUBLE_TAP },
154 { "TripleTap", GESTURE_TYPE_TRIPLE_TAP }
156 const unsigned int FullEventTypeStringsTotal = sizeof( ElDBusAccessibilityFullEventTypeStrings ) / sizeof( ElDBusAccessibilityFullEventTypeStrings[0] );
159 SUB_GESTURE_TYPE_NONE,
160 SUB_GESTURE_TYPE_FLICK
162 struct SubGestureTypeTable
165 const SubGestureType type;
167 SubGestureTypeTable ElDBusAccessibilityDirectionalEventTypeStrings[] =
169 { "Flick", SUB_GESTURE_TYPE_FLICK }
171 const unsigned int DirectionalEventTypeStringsTotal = sizeof( ElDBusAccessibilityDirectionalEventTypeStrings ) / sizeof( ElDBusAccessibilityDirectionalEventTypeStrings[0] );
172 enum GestureDirection
174 GESTURE_DIRECTION_NONE,
175 GESTURE_DIRECTION_UP,
176 GESTURE_DIRECTION_DOWN,
177 GESTURE_DIRECTION_LEFT,
178 GESTURE_DIRECTION_RIGHT,
179 GESTURE_DIRECTION_UP_RETURN,
180 GESTURE_DIRECTION_DOWN_RETURN,
181 GESTURE_DIRECTION_LEFT_RETURN,
182 GESTURE_DIRECTION_RIGHT_RETURN
184 struct GestureDirectionTable
187 const GestureDirection direction;
189 GestureDirectionTable ElDBusAccessibilityDirectionStrings[] =
191 { "Up", GESTURE_DIRECTION_UP },
192 { "Down", GESTURE_DIRECTION_DOWN },
193 { "Left", GESTURE_DIRECTION_LEFT },
194 { "Right", GESTURE_DIRECTION_RIGHT },
195 { "UpReturn", GESTURE_DIRECTION_UP_RETURN },
196 { "DownReturn", GESTURE_DIRECTION_DOWN_RETURN },
197 { "LeftReturn", GESTURE_DIRECTION_LEFT_RETURN },
198 { "RightReturn", GESTURE_DIRECTION_RIGHT_RETURN }
200 const unsigned int DirectionStringsTotal = sizeof( ElDBusAccessibilityDirectionStrings ) / sizeof( ElDBusAccessibilityDirectionStrings[0] );
201 #endif // DALI_ELDBUS_AVAILABLE
204 * Ecore_Event_Modifier enums in Ecore_Input.h do not match Ecore_IMF_Keyboard_Modifiers in Ecore_IMF.h.
205 * This function converts from Ecore_Event_Modifier to Ecore_IMF_Keyboard_Modifiers enums.
206 * @param[in] ecoreModifier the Ecore_Event_Modifier input.
207 * @return the Ecore_IMF_Keyboard_Modifiers output.
209 Ecore_IMF_Keyboard_Modifiers EcoreInputModifierToEcoreIMFModifier(unsigned int ecoreModifier)
211 int modifier( ECORE_IMF_KEYBOARD_MODIFIER_NONE ); // If no other matches returns NONE.
214 if ( ecoreModifier & ECORE_EVENT_MODIFIER_SHIFT ) // enums from ecore_input/Ecore_Input.h
216 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_SHIFT; // enums from ecore_imf/ecore_imf.h
219 if ( ecoreModifier & ECORE_EVENT_MODIFIER_ALT )
221 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_ALT;
224 if ( ecoreModifier & ECORE_EVENT_MODIFIER_CTRL )
226 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_CTRL;
229 if ( ecoreModifier & ECORE_EVENT_MODIFIER_WIN )
231 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_WIN;
234 if ( ecoreModifier & ECORE_EVENT_MODIFIER_ALTGR )
236 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_ALTGR;
239 return static_cast<Ecore_IMF_Keyboard_Modifiers>( modifier );
243 // Copied from x server
244 static unsigned int GetCurrentMilliSeconds(void)
249 static clockid_t clockid;
253 #ifdef CLOCK_MONOTONIC_COARSE
254 if (clock_getres(CLOCK_MONOTONIC_COARSE, &tp) == 0 &&
255 (tp.tv_nsec / 1000) <= 1000 && clock_gettime(CLOCK_MONOTONIC_COARSE, &tp) == 0)
257 clockid = CLOCK_MONOTONIC_COARSE;
261 if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0)
263 clockid = CLOCK_MONOTONIC;
270 if (clockid != ~0L && clock_gettime(clockid, &tp) == 0)
272 return (tp.tv_sec * 1000) + (tp.tv_nsec / 1000000L);
275 gettimeofday(&tv, NULL);
276 return (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
279 } // unnamed namespace
281 // Impl to hide EFL implementation.
282 struct EventHandler::Impl
284 // Construction & Destruction
289 Impl( EventHandler* handler, Ecore_X_Window window )
290 : mHandler( handler ),
291 mEcoreEventHandler(),
295 // Only register for touch and key events if we have a window
298 // Register Touch events
299 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_BUTTON_DOWN, EcoreEventMouseButtonDown, handler ) );
300 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_BUTTON_UP, EcoreEventMouseButtonUp, handler ) );
301 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_MOVE, EcoreEventMouseButtonMove, handler ) );
302 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_OUT, EcoreEventMouseButtonUp, handler ) ); // process mouse out event like up event
304 // Register Mouse wheel events
305 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_WHEEL, EcoreEventMouseWheel, handler ) );
307 // Register Key events
308 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_KEY_DOWN, EcoreEventKeyDown, handler ) );
309 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_KEY_UP, EcoreEventKeyUp, handler ) );
311 // Register Focus events
312 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_X_EVENT_WINDOW_FOCUS_IN, EcoreEventWindowFocusIn, handler ) );
313 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_X_EVENT_WINDOW_FOCUS_OUT, EcoreEventWindowFocusOut, handler ) );
315 // Register Window damage events
316 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_X_EVENT_WINDOW_DAMAGE, EcoreEventWindowDamaged, handler ) );
318 // Enable Drag & Drop and register DnD events
319 ecore_x_dnd_aware_set( window, EINA_TRUE );
320 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_X_EVENT_XDND_ENTER, EcoreEventDndEnter, handler) );
321 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_X_EVENT_XDND_POSITION, EcoreEventDndPosition, handler) );
322 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_X_EVENT_XDND_LEAVE, EcoreEventDndLeave, handler) );
323 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_X_EVENT_XDND_DROP, EcoreEventDndDrop, handler) );
324 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_X_EVENT_XDND_FINISHED, EcoreEventDndFinished, handler) );
325 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_X_EVENT_XDND_STATUS, EcoreEventDndStatus, handler) );
327 // Register Client message events - accessibility etc.
328 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_X_EVENT_CLIENT_MESSAGE, EcoreEventClientMessage, handler ) );
330 // Register Selection event - clipboard selection, Drag & Drop selection etc.
331 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_X_EVENT_SELECTION_CLEAR, EcoreEventSelectionClear, handler ) );
332 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_X_EVENT_SELECTION_NOTIFY, EcoreEventSelectionNotify, handler ) );
334 // Initialize Xi2 system
335 Display* display = static_cast< Display* >(ecore_x_display_get());
336 Ecore_X_Window rootWindow = ecore_x_window_root_first_get();
337 int opcode = 0, event = 0, error = 0;
338 int major = XI_2_Major;
339 int minor = XI_2_Minor;
341 XIEventMask xiEventMask;
343 // Check if X input extension available
344 if( XQueryExtension( display, "XInputExtension", &opcode, &event, &error ) )
346 // We support version 2.0
347 if( XIQueryVersion( display, &major, &minor ) != BadRequest )
349 xiEventMask.deviceid = XIAllDevices;
353 XIDeviceInfo* deviceInfo = NULL;
354 deviceInfo = XIQueryDevice( display, XIAllDevices, &deviceCount );
356 for( int i = 0; i < deviceCount; i++ )
358 if( !strncmp( deviceInfo[i].name, DETENT_DEVICE_NAME, strlen( DETENT_DEVICE_NAME ) ) )
360 xiEventMask.deviceid = deviceInfo[i].deviceid;
368 mXiDeviceId = xiEventMask.deviceid;
371 xiEventMask.mask = (unsigned char*)(calloc( 1, XIMaskLen( XI_LASTEVENT ) ) );
372 XISetMask( xiEventMask.mask, XI_RawMotion );
374 xiEventMask.mask_len = sizeof( xiEventMask.mask );
376 int ret = XISelectEvents( display, rootWindow, &xiEventMask, 1 );
379 // Register custom wheel events
380 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_X_EVENT_GENERIC, EcoreEventCustomWheel, handler ) );
384 DALI_LOG_INFO( gImfLogging, Debug::General, "Failed to Select Events\n" );
387 free( xiEventMask.mask );
389 if( deviceInfo != NULL )
391 XIFreeDeviceInfo( deviceInfo );
397 DALI_LOG_INFO( gImfLogging, Debug::General, "Failed to query XI Version\n" );
402 DALI_LOG_INFO( gImfLogging, Debug::General, "Failed to query XInputExtension\n" );
405 #ifndef DALI_PROFILE_UBUNTU
406 // Register Vconf notify - font name, font size and style
407 vconf_notify_key_changed( DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME, VconfNotifyFontNameChanged, handler );
408 vconf_notify_key_changed( VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontSizeChanged, handler );
409 #endif // DALI_PROFILE_UBUNTU
411 #ifdef DALI_ELDBUS_AVAILABLE
413 // Initialize ElDBus.
414 DALI_LOG_INFO( gImfLogging, Debug::General, "Starting DBus Initialization" );
417 Eldbus_Connection *sessionConnection;
418 sessionConnection = eldbus_connection_get( ELDBUS_CONNECTION_TYPE_SESSION );
420 Eldbus_Object *a11yObject = eldbus_object_get( sessionConnection, A11Y_BUS, A11Y_PATH );
421 Eldbus_Proxy *elDBusManager = eldbus_proxy_get( a11yObject, A11Y_INTERFACE );
423 // Pass in handler in the cb_data field so we can access the accessibility adaptor within the callback.
424 eldbus_proxy_call( elDBusManager, A11Y_GET_ADDRESS, EcoreElDBusInitialisation, handler, -1, "" );
426 DALI_LOG_INFO( gImfLogging, Debug::General, "Finished DBus Initialization" );
428 #endif // DALI_ELDBUS_AVAILABLE
437 #ifndef DALI_PROFILE_UBUNTU
438 vconf_ignore_key_changed( VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontSizeChanged );
439 vconf_ignore_key_changed( DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME, VconfNotifyFontNameChanged );
440 #endif // DALI_PROFILE_UBUNTU
442 for( std::vector<Ecore_Event_Handler*>::iterator iter = mEcoreEventHandler.begin(), endIter = mEcoreEventHandler.end(); iter != endIter; ++iter )
444 ecore_event_handler_del( *iter );
447 #ifdef DALI_ELDBUS_AVAILABLE
450 #endif // DALI_ELDBUS_AVAILABLE
455 /////////////////////////////////////////////////////////////////////////////////////////////////
457 /////////////////////////////////////////////////////////////////////////////////////////////////
460 * Called when a touch down is received.
462 static Eina_Bool EcoreEventMouseButtonDown( void* data, int type, void* event )
464 Ecore_Event_Mouse_Button *touchEvent( (Ecore_Event_Mouse_Button*)event );
465 EventHandler* handler( (EventHandler*)data );
467 if ( touchEvent->window == handler->mImpl->mWindow )
469 TouchPoint::State state ( TouchPoint::Down );
471 // Check if the buttons field is set and ensure it's the primary touch button.
472 // If this event was triggered by buttons other than the primary button (used for touch), then
473 // just send an interrupted event to Core.
474 if ( touchEvent->buttons && (touchEvent->buttons != PRIMARY_TOUCH_BUTTON_ID ) )
476 state = TouchPoint::Interrupted;
479 TouchPoint point( touchEvent->multi.device, state, touchEvent->x, touchEvent->y );
480 handler->SendEvent( point, touchEvent->timestamp );
483 return ECORE_CALLBACK_PASS_ON;
487 * Called when a touch up is received.
489 static Eina_Bool EcoreEventMouseButtonUp( void* data, int type, void* event )
491 Ecore_Event_Mouse_Button *touchEvent( (Ecore_Event_Mouse_Button*)event );
492 EventHandler* handler( (EventHandler*)data );
494 if ( touchEvent->window == handler->mImpl->mWindow )
496 TouchPoint point( touchEvent->multi.device, TouchPoint::Up, touchEvent->x, touchEvent->y );
497 handler->SendEvent( point, touchEvent->timestamp );
500 return ECORE_CALLBACK_PASS_ON;
504 * Called when a touch motion is received.
506 static Eina_Bool EcoreEventMouseButtonMove( void* data, int type, void* event )
508 Ecore_Event_Mouse_Move *touchEvent( (Ecore_Event_Mouse_Move*)event );
509 EventHandler* handler( (EventHandler*)data );
511 if ( touchEvent->window == handler->mImpl->mWindow )
513 TouchPoint point( touchEvent->multi.device, TouchPoint::Motion, touchEvent->x, touchEvent->y );
514 handler->SendEvent( point, touchEvent->timestamp );
517 return ECORE_CALLBACK_PASS_ON;
520 /////////////////////////////////////////////////////////////////////////////////////////////////
522 /////////////////////////////////////////////////////////////////////////////////////////////////
525 * Called when a mouse wheel is received.
527 static Eina_Bool EcoreEventMouseWheel( void* data, int type, void* event )
529 Ecore_Event_Mouse_Wheel *mouseWheelEvent( (Ecore_Event_Mouse_Wheel*)event );
531 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 );
533 EventHandler* handler( (EventHandler*)data );
534 if ( mouseWheelEvent->window == handler->mImpl->mWindow )
536 WheelEvent wheelEvent( WheelEvent::MOUSE_WHEEL, mouseWheelEvent->direction, mouseWheelEvent->modifiers, Vector2(mouseWheelEvent->x, mouseWheelEvent->y), mouseWheelEvent->z, mouseWheelEvent->timestamp );
537 handler->SendWheelEvent( wheelEvent );
539 return ECORE_CALLBACK_PASS_ON;
543 * Called when a custom wheel is received.
545 static Eina_Bool EcoreEventCustomWheel( void* data, int type, void* event )
547 Ecore_X_Event_Generic *genericEvent( (Ecore_X_Event_Generic*)event );
548 EventHandler* handler( (EventHandler*)data );
550 switch( genericEvent->evtype )
554 XIRawEvent* xiRawEvent = static_cast< XIRawEvent* >( genericEvent->data );
555 unsigned int timeStamp = 0;
557 if( xiRawEvent->deviceid != handler->mImpl->mXiDeviceId )
559 return ECORE_CALLBACK_PASS_ON;
562 // X(0): rotate: NOT USED
566 double* value = xiRawEvent->raw_values;
568 if( XIMaskIsSet( xiRawEvent->valuators.mask, 1) )
570 timeStamp = static_cast< unsigned int >( *(value + 1) );
573 if( XIMaskIsSet( xiRawEvent->valuators.mask, 2) )
575 // if z == 1, clockwise
576 // otherwise counter-clockwise
577 int z = static_cast< int >( *(value + 2) );
579 // In DALi, positive value means clockwise, and negative value means counter-clockwise
585 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT EcoreEventCustomWheel: z: %d\n", z );
587 WheelEvent wheelEvent( WheelEvent::CUSTOM_WHEEL, 0, 0, Vector2(0.0f, 0.0f), z, timeStamp );
588 handler->SendWheelEvent( wheelEvent );
598 return ECORE_CALLBACK_PASS_ON;
601 /////////////////////////////////////////////////////////////////////////////////////////////////
603 /////////////////////////////////////////////////////////////////////////////////////////////////
606 * Called when a key down is received.
608 static Eina_Bool EcoreEventKeyDown( void* data, int type, void* event )
610 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventKeyDown \n" );
612 EventHandler* handler( (EventHandler*)data );
613 Ecore_Event_Key *keyEvent( (Ecore_Event_Key*)event );
614 bool eventHandled( false );
616 // If a device key then skip ecore_imf_context_filter_event.
617 if ( ! KeyLookup::IsDeviceButton( keyEvent->keyname ) )
619 Ecore_IMF_Context* imfContext = NULL;
620 Dali::ImfManager imfManager( ImfManager::Get() );
623 imfContext = reinterpret_cast<Ecore_IMF_Context*>( imfManager.GetContext() );
628 // We're consuming key down event so we have to pass to IMF so that it can parse it as well.
629 Ecore_IMF_Event_Key_Down ecoreKeyDownEvent;
630 ecoreKeyDownEvent.keyname = keyEvent->keyname;
631 ecoreKeyDownEvent.key = keyEvent->key;
632 ecoreKeyDownEvent.string = keyEvent->string;
633 ecoreKeyDownEvent.compose = keyEvent->compose;
634 ecoreKeyDownEvent.timestamp = keyEvent->timestamp;
635 ecoreKeyDownEvent.modifiers = EcoreInputModifierToEcoreIMFModifier ( keyEvent->modifiers );
636 ecoreKeyDownEvent.locks = (Ecore_IMF_Keyboard_Locks) ECORE_IMF_KEYBOARD_LOCK_NONE;
638 eventHandled = ecore_imf_context_filter_event( imfContext,
639 ECORE_IMF_EVENT_KEY_DOWN,
640 (Ecore_IMF_Event *) &ecoreKeyDownEvent );
642 // If the event has not been handled by IMF then check if we should reset our IMF context
645 if ( !strcmp( keyEvent->keyname, "Escape" ) ||
646 !strcmp( keyEvent->keyname, "Return" ) ||
647 !strcmp( keyEvent->keyname, "KP_Enter" ) )
649 ecore_imf_context_reset( imfContext );
655 // If the event wasn't handled then we should send a key event.
658 if ( keyEvent->window == handler->mImpl->mWindow )
660 std::string keyName( keyEvent->keyname );
661 std::string keyString( "" );
662 int keyCode = ecore_x_keysym_keycode_get(keyEvent->keyname);
663 int modifier( keyEvent->modifiers );
664 unsigned long time = keyEvent->timestamp;
666 // Ensure key event string is not NULL as keys like SHIFT have a null string.
667 if ( keyEvent->string )
669 keyString = keyEvent->string;
672 KeyEvent keyEvent(keyName, keyString, keyCode, modifier, time, KeyEvent::Down);
673 handler->SendEvent( keyEvent );
677 return ECORE_CALLBACK_PASS_ON;
681 * Called when a key up is received.
683 static Eina_Bool EcoreEventKeyUp( void* data, int type, void* event )
685 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventKeyUp \n" );
687 EventHandler* handler( (EventHandler*)data );
688 Ecore_Event_Key *keyEvent( (Ecore_Event_Key*)event );
689 bool eventHandled( false );
691 // XF86Stop and XF86Send must skip ecore_imf_context_filter_event.
692 if ( strcmp( keyEvent->keyname, "XF86Send" ) &&
693 strcmp( keyEvent->keyname, "XF86Phone" ) &&
694 strcmp( keyEvent->keyname, "XF86Stop" ) )
696 Ecore_IMF_Context* imfContext = NULL;
697 Dali::ImfManager imfManager( ImfManager::Get() );
700 imfContext = reinterpret_cast<Ecore_IMF_Context*>( imfManager.GetContext() );
705 // We're consuming key up event so we have to pass to IMF so that it can parse it as well.
706 Ecore_IMF_Event_Key_Up ecoreKeyUpEvent;
707 ecoreKeyUpEvent.keyname = keyEvent->keyname;
708 ecoreKeyUpEvent.key = keyEvent->key;
709 ecoreKeyUpEvent.string = keyEvent->string;
710 ecoreKeyUpEvent.compose = keyEvent->compose;
711 ecoreKeyUpEvent.timestamp = keyEvent->timestamp;
712 ecoreKeyUpEvent.modifiers = EcoreInputModifierToEcoreIMFModifier ( keyEvent->modifiers );
713 ecoreKeyUpEvent.locks = (Ecore_IMF_Keyboard_Locks) ECORE_IMF_KEYBOARD_LOCK_NONE;
715 eventHandled = ecore_imf_context_filter_event( imfContext,
716 ECORE_IMF_EVENT_KEY_UP,
717 (Ecore_IMF_Event *) &ecoreKeyUpEvent );
721 // If the event wasn't handled then we should send a key event.
724 if ( keyEvent->window == handler->mImpl->mWindow )
726 std::string keyName( keyEvent->keyname );
727 std::string keyString( "" );
728 int keyCode = ecore_x_keysym_keycode_get(keyEvent->keyname);
729 int modifier( keyEvent->modifiers );
730 unsigned long time( keyEvent->timestamp );
732 // Ensure key event string is not NULL as keys like SHIFT have a null string.
733 if ( keyEvent->string )
735 keyString = keyEvent->string;
738 KeyEvent keyEvent(keyName, keyString, keyCode, modifier, time, KeyEvent::Up);
739 handler->SendEvent( keyEvent );
744 return ECORE_CALLBACK_PASS_ON;
747 /////////////////////////////////////////////////////////////////////////////////////////////////
749 /////////////////////////////////////////////////////////////////////////////////////////////////
752 * Called when the window gains focus.
754 static Eina_Bool EcoreEventWindowFocusIn( void* data, int type, void* event )
756 Ecore_X_Event_Window_Focus_In* focusInEvent( (Ecore_X_Event_Window_Focus_In*)event );
757 EventHandler* handler( (EventHandler*)data );
759 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventWindowFocusIn \n" );
761 // If the window gains focus and we hid the keyboard then show it again.
762 if ( focusInEvent->win == handler->mImpl->mWindow )
764 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT EcoreEventWindowFocusIn - >>WindowFocusGained \n" );
766 if ( ImfManager::IsAvailable() /* Only get the ImfManager if it's available as we do not want to create it */ )
768 Dali::ImfManager imfManager( ImfManager::Get() );
771 ImfManager& imfManagerImpl( ImfManager::GetImplementation( imfManager ) );
772 if( imfManagerImpl.RestoreAfterFocusLost() )
774 imfManagerImpl.Activate();
778 // No need to connect callbacks as KeyboardStatusChanged will be called.
781 return ECORE_CALLBACK_PASS_ON;
785 * Called when the window loses focus.
787 static Eina_Bool EcoreEventWindowFocusOut( void* data, int type, void* event )
789 Ecore_X_Event_Window_Focus_Out* focusOutEvent( (Ecore_X_Event_Window_Focus_Out*)event );
790 EventHandler* handler( (EventHandler*)data );
792 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventWindowFocusOut \n" );
794 // If the window loses focus then hide the keyboard.
795 if ( focusOutEvent->win == handler->mImpl->mWindow )
797 if ( ImfManager::IsAvailable() /* Only get the ImfManager if it's available as we do not want to create it */ )
799 Dali::ImfManager imfManager( ImfManager::Get() );
802 ImfManager& imfManagerImpl( ImfManager::GetImplementation( imfManager ) );
803 if( imfManagerImpl.RestoreAfterFocusLost() )
805 imfManagerImpl.Deactivate();
810 // Clipboard don't support that whether clipboard is shown or not. Hide clipboard.
811 Dali::Clipboard clipboard = Clipboard::Get();
812 clipboard.HideClipboard();
815 return ECORE_CALLBACK_PASS_ON;
819 * Called when the window is damaged.
821 static Eina_Bool EcoreEventWindowDamaged(void *data, int type, void *event)
823 Ecore_X_Event_Window_Damage* windowDamagedEvent( (Ecore_X_Event_Window_Damage*)event );
824 EventHandler* handler( (EventHandler*)data );
826 if( windowDamagedEvent->win == handler->mImpl->mWindow )
829 area.x = windowDamagedEvent->x;
830 area.y = windowDamagedEvent->y;
831 area.width = windowDamagedEvent->w;
832 area.height = windowDamagedEvent->h;
834 handler->SendEvent( area );
837 return ECORE_CALLBACK_PASS_ON;
841 * Called when the window properties are changed.
842 * We are only interested in the font change.
846 /////////////////////////////////////////////////////////////////////////////////////////////////
847 // Drag & Drop Callbacks
848 /////////////////////////////////////////////////////////////////////////////////////////////////
851 * Called when a dragged item enters our window's bounds.
852 * This is when items are dragged INTO our window.
854 static Eina_Bool EcoreEventDndEnter( void* data, int type, void* event )
856 DALI_LOG_INFO( gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndEnter\n" );
858 Ecore_X_Event_Xdnd_Enter* enterEvent( (Ecore_X_Event_Xdnd_Enter*) event );
859 EventHandler* handler( (EventHandler*)data );
860 Ecore_X_Window window ( handler->mImpl->mWindow );
862 if ( enterEvent->win == window )
864 DragAndDropDetectorPtr dndDetector( handler->mDragAndDropDetector );
866 // Check whether the Drag & Drop detector has Drag & Drop behaviour enabled before we accept.
867 if ( dndDetector && dndDetector->IsEnabled() )
869 // Tell Ecore that we want to enable drop in the entire window.
870 Ecore_X_Rectangle rect;
872 ecore_x_window_geometry_get( window, NULL, NULL, (int*)&rect.width, (int*)&rect.height );
874 // Tell Ecore that we are able to process a drop.
875 ecore_x_dnd_send_status( EINA_TRUE, EINA_FALSE, rect, ECORE_X_ATOM_XDND_DROP );
877 // Register the required atoms and types.
878 ecore_x_dnd_actions_set( window, DRAG_AND_DROP_ATOMS, DRAG_AND_DROP_ATOMS_NUMBER );
879 ecore_x_dnd_types_set( window, DRAG_AND_DROP_TYPES, DRAG_AND_DROP_TYPES_NUMBER );
881 // Request to get the content from Ecore.
882 ecore_x_selection_xdnd_request( window, ECORE_X_SELECTION_TARGET_UTF8_STRING );
884 DALI_LOG_INFO( gDragAndDropLogFilter, Debug::General, "EcoreEventDndEnter: Requesting Drag & Drop\n" );
886 // Clear the previous content
887 dndDetector->ClearContent();
889 // Emit the entered signal
890 dndDetector->EmitEnteredSignal();
894 return ECORE_CALLBACK_PASS_ON;
898 * Called when a dragged item is moved within our window.
899 * This is when items are dragged INTO our window.
901 static Eina_Bool EcoreEventDndPosition( void* data, int type, void* event )
903 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndPosition\n" );
905 Ecore_X_Event_Xdnd_Position* positionEvent( (Ecore_X_Event_Xdnd_Position*) event );
906 EventHandler* handler( (EventHandler*)data );
908 if ( positionEvent->win == handler->mImpl->mWindow )
910 DragAndDropDetectorPtr dndDetector( handler->mDragAndDropDetector );
912 // If we have a detector then update its latest position.
915 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::General, "EcoreEventDndPosition: position ( %d x %d )\n", positionEvent->position.x, positionEvent->position.y );
916 dndDetector->SetPosition( Vector2( positionEvent->position.x, positionEvent->position.y ));
917 dndDetector->EmitMovedSignal();
921 return ECORE_CALLBACK_PASS_ON;
925 * Called when a dragged item leaves our window's bounds.
926 * This is when items are dragged INTO our window.
928 static Eina_Bool EcoreEventDndLeave( void* data, int type, void* event )
930 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndLeave\n" );
932 Ecore_X_Event_Xdnd_Leave* leaveEvent( (Ecore_X_Event_Xdnd_Leave*) event );
933 EventHandler* handler( (EventHandler*)data );
935 if ( leaveEvent->win == handler->mImpl->mWindow )
937 DragAndDropDetectorPtr dndDetector( handler->mDragAndDropDetector );
939 // If we have a detector then clear its content and emit the exited-signal. Also tell Ecore that we have finished.
942 dndDetector->ClearContent();
943 dndDetector->EmitExitedSignal();
945 ecore_x_dnd_send_finished();
947 DALI_LOG_INFO( gDragAndDropLogFilter, Debug::General, "EcoreEventDndLeave: Finished\n" );
951 return ECORE_CALLBACK_PASS_ON;
955 * Called when the dragged item is dropped within our window's bounds.
956 * This is when items are dragged INTO our window.
958 static Eina_Bool EcoreEventDndDrop( void* data, int type, void* event )
960 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndDrop\n" );
962 Ecore_X_Event_Xdnd_Drop* dropEvent ( (Ecore_X_Event_Xdnd_Drop*) event);
963 EventHandler* handler( (EventHandler*)data );
965 if ( dropEvent->win == handler->mImpl->mWindow )
967 DragAndDropDetectorPtr dndDetector( handler->mDragAndDropDetector );
969 // Something has been dropped, inform the detector (if we have one) and tell Ecore that we have finished.
972 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::General, "EcoreEventDndDrop: position ( %d x %d )\n", dropEvent->position.x, dropEvent->position.y );
974 dndDetector->SetPosition( Vector2( dropEvent->position.x, dropEvent->position.y ) );
975 dndDetector->EmitDroppedSignal();
976 ecore_x_dnd_send_finished();
978 DALI_LOG_INFO( gDragAndDropLogFilter, Debug::General, "EcoreEventDndDrop: Finished\n" );
982 return ECORE_CALLBACK_PASS_ON;
986 * Called when a dragged item is moved from our window and the target window has done processing it.
987 * This is when items are dragged FROM our window.
989 static Eina_Bool EcoreEventDndFinished( void* data, int type, void* event )
991 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndFinished\n" );
992 return ECORE_CALLBACK_PASS_ON;
996 * Called when a dragged item is moved from our window and the target window has sent us a status.
997 * This is when items are dragged FROM our window.
999 static Eina_Bool EcoreEventDndStatus( void* data, int type, void* event )
1001 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndStatus\n" );
1002 return ECORE_CALLBACK_PASS_ON;
1006 * Called when the client messages (i.e. the accessibility events) are received.
1008 static Eina_Bool EcoreEventClientMessage( void* data, int type, void* event )
1010 #ifndef DALI_PROFILE_UBUNTU
1011 Ecore_X_Event_Client_Message* clientMessageEvent( (Ecore_X_Event_Client_Message*)event );
1012 EventHandler* handler( (EventHandler*)data );
1014 if (clientMessageEvent->message_type == ECORE_X_ATOM_E_ILLUME_ACCESS_CONTROL)
1016 if ( ( (unsigned int)clientMessageEvent->data.l[0] == handler->mImpl->mWindow ) && handler->mAccessibilityAdaptor )
1018 AccessibilityAdaptor* accessibilityAdaptor( &AccessibilityAdaptor::GetImplementation( handler->mAccessibilityAdaptor ) );
1020 if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_SCROLL)
1022 // 2 finger touch & move, 2 finger flick
1024 // mouse state : e->data.l[2] (0: mouse down, 1: mouse move, 2: mouse up)
1027 TouchPoint::State state(TouchPoint::Down);
1029 if ((unsigned int)clientMessageEvent->data.l[2] == 0)
1031 state = TouchPoint::Down; // mouse down
1033 else if ((unsigned int)clientMessageEvent->data.l[2] == 1)
1035 state = TouchPoint::Motion; // mouse move
1037 else if ((unsigned int)clientMessageEvent->data.l[2] == 2)
1039 state = TouchPoint::Up; // mouse up
1043 state = TouchPoint::Interrupted; // error
1046 DALI_LOG_INFO(gClientMessageLogFilter, Debug::General,
1047 "[%s:%d] [%d] %d, %d\n", __FUNCTION__, __LINE__,
1048 (unsigned int)clientMessageEvent->data.l[2],
1049 (unsigned int)clientMessageEvent->data.l[3], (unsigned int)clientMessageEvent->data.l[4]);
1051 // Send touch event to accessibility adaptor.
1052 TouchPoint point( 0, state, (float)clientMessageEvent->data.l[3], (float)clientMessageEvent->data.l[4] );
1054 // In accessibility mode, scroll action should be handled when the currently focused actor is contained in scrollable control
1055 accessibilityAdaptor->HandleActionScrollEvent( point, GetCurrentMilliSeconds() );
1057 else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_MOUSE)
1059 // 1 finger double tap and hold
1061 // mouse state : e->data.l[2] (0: mouse down, 1: mouse move, 2: mouse up)
1064 TouchPoint::State state(TouchPoint::Down);
1066 if ((unsigned int)clientMessageEvent->data.l[2] == 0)
1068 state = TouchPoint::Down; // mouse down
1070 else if ((unsigned int)clientMessageEvent->data.l[2] == 1)
1072 state = TouchPoint::Motion; // mouse move
1074 else if ((unsigned int)clientMessageEvent->data.l[2] == 2)
1076 state = TouchPoint::Up; // mouse up
1080 state = TouchPoint::Interrupted; // error
1083 DALI_LOG_INFO(gClientMessageLogFilter, Debug::General,
1084 "[%s:%d] [%d] %d, %d\n", __FUNCTION__, __LINE__,
1085 (unsigned int)clientMessageEvent->data.l[2],
1086 (unsigned int)clientMessageEvent->data.l[3], (unsigned int)clientMessageEvent->data.l[4]);
1088 // Send touch event to accessibility adaptor.
1089 TouchPoint point( 0, state, (float)clientMessageEvent->data.l[3], (float)clientMessageEvent->data.l[4] );
1091 // In accessibility mode, scroll action should be handled when the currently focused actor is contained in scrollable control
1092 accessibilityAdaptor->HandleActionTouchEvent( point, GetCurrentMilliSeconds() );
1094 else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_BACK)
1096 // 2 finger circle draw, do back
1097 accessibilityAdaptor->HandleActionBackEvent();
1099 else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_NEXT)
1101 // one finger flick down
1102 // focus next object
1103 if(accessibilityAdaptor)
1105 accessibilityAdaptor->HandleActionNextEvent();
1108 else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_PREV)
1110 // one finger flick up
1111 // focus previous object
1112 if(accessibilityAdaptor)
1114 accessibilityAdaptor->HandleActionPreviousEvent();
1117 else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_ACTIVATE)
1119 // one finger double tap
1120 // same as one finger tap in normal mode (i.e. execute focused actor)
1121 if(accessibilityAdaptor)
1123 accessibilityAdaptor->HandleActionActivateEvent();
1126 else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_READ)
1129 // focus & read an actor at ( e->data.l[2], e->data.l[3] ) position according to finger
1130 if(accessibilityAdaptor)
1132 accessibilityAdaptor->HandleActionReadEvent((unsigned int)clientMessageEvent->data.l[2], (unsigned int)clientMessageEvent->data.l[3], true /* allow read again*/);
1135 #if defined(DALI_PROFILE_MOBILE)
1136 else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_OVER)
1138 // one finger tap & move
1139 // mouse state : e->data.l[2] (0: mouse down, 1: mouse move, 2: mouse up)
1142 // focus & read an actor at (x, y) position according to finger
1143 if(accessibilityAdaptor && (unsigned int)clientMessageEvent->data.l[2] == 1 /*only work for move event*/)
1145 accessibilityAdaptor->HandleActionReadEvent((unsigned int)clientMessageEvent->data.l[3], (unsigned int)clientMessageEvent->data.l[4], false /* not allow read again*/);
1149 else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_READ_NEXT)
1151 // one finger flick right
1152 // focus next object
1153 if(accessibilityAdaptor)
1155 accessibilityAdaptor->HandleActionReadNextEvent();
1158 else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_READ_PREV)
1160 // one finger flick left
1161 // focus previous object
1162 if(accessibilityAdaptor)
1164 accessibilityAdaptor->HandleActionReadPreviousEvent();
1167 else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_UP)
1169 // double down and move (right, up)
1170 // change slider value
1171 if(accessibilityAdaptor)
1173 accessibilityAdaptor->HandleActionUpEvent();
1176 else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_DOWN)
1178 // double down and move (left, down)
1179 // change slider value
1180 if(accessibilityAdaptor)
1182 accessibilityAdaptor->HandleActionDownEvent();
1185 else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_ENABLE)
1187 if(accessibilityAdaptor)
1189 accessibilityAdaptor->HandleActionEnableEvent();
1192 else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_DISABLE)
1194 if(accessibilityAdaptor)
1196 accessibilityAdaptor->HandleActionDisableEvent();
1199 // TODO: some more actions could be added later
1202 else if(clientMessageEvent->message_type == ecore_x_atom_get(CLIPBOARD_ATOM))
1204 std::string message(clientMessageEvent->data.b);
1205 if( message == CLIPBOARD_SET_OWNER_MESSAGE)
1207 // Claim the ownership of the SECONDARY selection.
1208 ecore_x_selection_secondary_set(handler->mImpl->mWindow, "", 1);
1210 // Show the clipboard window
1211 Dali::Clipboard clipboard = Dali::Clipboard::Get();
1212 clipboard.ShowClipboard();
1215 else if( clientMessageEvent->message_type == ECORE_X_ATOM_E_WINDOW_ROTATION_CHANGE_PREPARE )
1217 RotationEvent rotationEvent;
1218 rotationEvent.angle = static_cast<int>(clientMessageEvent->data.l[1]);
1219 rotationEvent.winResize = static_cast<int>(clientMessageEvent->data.l[2]);
1220 rotationEvent.width = static_cast<int>(clientMessageEvent->data.l[3]);
1221 rotationEvent.height = static_cast<int>(clientMessageEvent->data.l[4]);
1222 handler->SendRotationPrepareEvent( rotationEvent );
1224 else if( clientMessageEvent->message_type == ECORE_X_ATOM_E_WINDOW_ROTATION_CHANGE_REQUEST )
1226 handler->SendRotationRequestEvent();
1229 #endif // DALI_PROFILE_UBUNTU
1230 return ECORE_CALLBACK_PASS_ON;
1234 /////////////////////////////////////////////////////////////////////////////////////////////////
1235 // ElDBus Accessibility Callbacks
1236 /////////////////////////////////////////////////////////////////////////////////////////////////
1238 #ifdef DALI_ELDBUS_AVAILABLE
1239 // Callback for Ecore ElDBus accessibility events.
1240 static void OnEcoreElDBusAccessibilityNotification( void *context EINA_UNUSED, const Eldbus_Message *message )
1242 EventHandler* handler( (EventHandler*)context );
1244 if ( !handler->mAccessibilityAdaptor )
1246 DALI_LOG_ERROR( "Invalid accessibility adaptor\n" );
1250 AccessibilityAdaptor* accessibilityAdaptor( &AccessibilityAdaptor::GetImplementation( handler->mAccessibilityAdaptor ) );
1251 if ( !accessibilityAdaptor )
1253 DALI_LOG_ERROR( "Cannot access accessibility adaptor\n" );
1257 const char *gestureName;
1261 // The string defines the arg-list's respective types.
1262 if( !eldbus_message_arguments_get( message, "siiiiu", &gestureName, &xS, &yS, &xE, &yE, &state ) )
1264 DALI_LOG_ERROR( "OnEcoreElDBusAccessibilityNotification: Error getting arguments\n" );
1267 DALI_LOG_INFO( gImfLogging, Debug::General, "Got gesture: Name: %s Args: %d,%d,%d,%d State: %d\n", gestureName, xS, yS, xE, yE );
1269 unsigned int fingers = 0;
1270 char* stringPosition = ( char* )gestureName;
1272 // Check how many fingers the gesture uses.
1273 for( unsigned int i = 0; i < FingerCountStringsTotal; ++i )
1275 unsigned int matchLength = strlen( ElDBusAccessibilityFingerCountStrings[ i ] );
1276 if( strncmp( gestureName, ElDBusAccessibilityFingerCountStrings[ i ], matchLength ) == 0 )
1279 stringPosition += matchLength;
1286 // Error: invalid gesture.
1290 GestureType gestureType = GESTURE_TYPE_NONE;
1291 SubGestureType subGestureType = SUB_GESTURE_TYPE_NONE;
1292 GestureDirection direction = GESTURE_DIRECTION_NONE;
1294 // Check for full gesture type names first.
1295 for( unsigned int i = 0; i < FullEventTypeStringsTotal; ++i )
1297 unsigned int matchLength = strlen( ElDBusAccessibilityFullEventTypeStrings[ i ].name );
1298 if( strncmp( stringPosition, ElDBusAccessibilityFullEventTypeStrings[ i ].name, matchLength ) == 0 )
1300 gestureType = ElDBusAccessibilityFullEventTypeStrings[ i ].type;
1305 // If we didn't find a full gesture, check for sub gesture type names.
1306 if( gestureType == GESTURE_TYPE_NONE )
1308 // No full gesture name found, look for partial types.
1309 for( unsigned int i = 0; i < DirectionalEventTypeStringsTotal; ++i )
1311 unsigned int matchLength = strlen( ElDBusAccessibilityDirectionalEventTypeStrings[ i ].name );
1312 if( strncmp( stringPosition, ElDBusAccessibilityDirectionalEventTypeStrings[ i ].name, matchLength ) == 0 )
1314 subGestureType = ElDBusAccessibilityDirectionalEventTypeStrings[ i ].type;
1315 stringPosition += matchLength;
1320 if( subGestureType == SUB_GESTURE_TYPE_NONE )
1322 // ERROR: Gesture not recognised.
1326 // If the gesture was a sub type, get it's respective direction.
1327 for( unsigned int i = 0; i < DirectionStringsTotal; ++i )
1329 unsigned int matchLength = strlen( ElDBusAccessibilityDirectionStrings[ i ].name );
1330 if( strncmp( stringPosition, ElDBusAccessibilityDirectionStrings[ i ].name, matchLength ) == 0 )
1332 direction = ElDBusAccessibilityDirectionStrings[ i ].direction;
1333 stringPosition += matchLength;
1338 if( direction == GESTURE_DIRECTION_NONE )
1340 // ERROR: Gesture not recognised.
1345 // Action the detected gesture here.
1346 if( gestureType != GESTURE_TYPE_NONE )
1348 DALI_LOG_INFO( gImfLogging, Debug::General, "Got gesture: Fingers: %d Gesture type: %d\n", fingers, gestureType );
1352 DALI_LOG_INFO( gImfLogging, Debug::General, "Got gesture: Fingers: %d Gesture sub type: %d Gesture direction: %d\n",
1353 fingers, subGestureType, direction );
1356 // Create a touch point object.
1357 TouchPoint::State touchPointState( TouchPoint::Down );
1360 touchPointState = TouchPoint::Down; // Mouse down.
1362 else if ( state == 1 )
1364 touchPointState = TouchPoint::Motion; // Mouse move.
1366 else if ( state == 2 )
1368 touchPointState = TouchPoint::Up; // Mouse up.
1372 touchPointState = TouchPoint::Interrupted; // Error.
1375 // Send touch event to accessibility adaptor.
1376 TouchPoint point( 0, touchPointState, (float)xS, (float)yS );
1378 // Perform actions based on received gestures.
1379 // Note: This is seperated from the reading so we can (in future)
1380 // have other input readers without changing the below code.
1385 if( gestureType == GESTURE_TYPE_SINGLE_TAP || ( gestureType == GESTURE_TYPE_HOVER && touchPointState == TouchPoint::Motion ) )
1388 accessibilityAdaptor->HandleActionReadEvent( (unsigned int)xS, (unsigned int)yS, true /* allow read again */ );
1390 else if( gestureType == GESTURE_TYPE_DOUBLE_TAP )
1392 if( false ) // TODO: how to detect double tap + hold?
1394 // Move or drag icon / view more options for selected items.
1395 // accessibilityAdaptor->HandleActionTouchEvent( point, GetCurrentMilliSeconds() );
1399 // Activate selected item / active edit mode.
1400 accessibilityAdaptor->HandleActionActivateEvent();
1403 else if( gestureType == GESTURE_TYPE_TRIPLE_TAP )
1406 accessibilityAdaptor->HandleActionZoomEvent();
1408 else if( subGestureType == SUB_GESTURE_TYPE_FLICK )
1410 if( direction == GESTURE_DIRECTION_LEFT )
1412 // Move to previous item.
1413 accessibilityAdaptor->HandleActionReadPreviousEvent();
1415 else if( direction == GESTURE_DIRECTION_RIGHT )
1417 // Move to next item.
1418 accessibilityAdaptor->HandleActionReadNextEvent();
1420 else if( direction == GESTURE_DIRECTION_UP )
1422 // Move to next item.
1423 accessibilityAdaptor->HandleActionPreviousEvent();
1425 else if( direction == GESTURE_DIRECTION_DOWN )
1427 // Move to next item.
1428 accessibilityAdaptor->HandleActionNextEvent();
1430 else if( direction == GESTURE_DIRECTION_LEFT_RETURN )
1432 // Scroll up to the previous page
1433 accessibilityAdaptor->HandleActionPageUpEvent();
1435 else if( direction == GESTURE_DIRECTION_RIGHT_RETURN )
1437 // Scroll down to the next page
1438 accessibilityAdaptor->HandleActionPageDownEvent();
1440 else if( direction == GESTURE_DIRECTION_UP_RETURN )
1442 // Move to the first item on screen
1443 accessibilityAdaptor->HandleActionMoveToFirstEvent();
1445 else if( direction == GESTURE_DIRECTION_DOWN_RETURN )
1447 // Move to the last item on screen
1448 accessibilityAdaptor->HandleActionMoveToLastEvent();
1456 if( gestureType == GESTURE_TYPE_HOVER )
1458 // In accessibility mode, scroll action should be handled when the currently focused actor is contained in scrollable control
1459 accessibilityAdaptor->HandleActionScrollEvent( point, GetCurrentMilliSeconds() );
1461 else if( gestureType == GESTURE_TYPE_SINGLE_TAP )
1463 // Pause/Resume current speech
1464 accessibilityAdaptor->HandleActionReadPauseResumeEvent();
1466 else if( gestureType == GESTURE_TYPE_DOUBLE_TAP )
1468 // Start/Stop current action
1469 accessibilityAdaptor->HandleActionStartStopEvent();
1471 else if( gestureType == GESTURE_TYPE_TRIPLE_TAP )
1473 // Read information from indicator
1474 accessibilityAdaptor->HandleActionReadIndicatorInformationEvent();
1476 else if( subGestureType == SUB_GESTURE_TYPE_FLICK )
1478 if( direction == GESTURE_DIRECTION_LEFT )
1480 // Scroll left to the previous page
1481 accessibilityAdaptor->HandleActionPageLeftEvent();
1483 else if( direction == GESTURE_DIRECTION_RIGHT )
1485 // Scroll right to the next page
1486 accessibilityAdaptor->HandleActionPageRightEvent();
1488 else if( direction == GESTURE_DIRECTION_UP )
1490 // Scroll up the list.
1491 accessibilityAdaptor->HandleActionScrollUpEvent();
1493 else if( direction == GESTURE_DIRECTION_DOWN )
1495 // Scroll down the list.
1496 accessibilityAdaptor->HandleActionScrollDownEvent();
1504 if( gestureType == GESTURE_TYPE_SINGLE_TAP )
1506 // Read from top item on screen continuously.
1507 accessibilityAdaptor->HandleActionReadFromTopEvent();
1509 else if( gestureType == GESTURE_TYPE_DOUBLE_TAP )
1511 // Read from next item continuously.
1512 accessibilityAdaptor->HandleActionReadFromNextEvent();
1519 // Callback for to set up Ecore ElDBus for accessibility callbacks.
1520 static void EcoreElDBusInitialisation( void *handle, const Eldbus_Message *message, Eldbus_Pending *pending EINA_UNUSED )
1522 Eldbus_Object *object;
1523 Eldbus_Proxy *manager;
1524 const char *a11yBusAddress = NULL;
1526 // The string defines the arg-list's respective types.
1527 if( !eldbus_message_arguments_get( message, "s", &a11yBusAddress ) )
1529 DALI_LOG_ERROR( "EcoreElDBusInitialisation: Error getting arguments\n" );
1532 DALI_LOG_INFO( gImfLogging, Debug::General, "Ecore ElDBus Accessibility address: %s\n", a11yBusAddress );
1534 Eldbus_Connection *a11yConnection = eldbus_address_connection_get( a11yBusAddress );
1536 object = eldbus_object_get( a11yConnection, BUS, PATH );
1537 manager = eldbus_proxy_get( object, INTERFACE );
1539 // Pass the callback data through to the signal handler.
1540 eldbus_proxy_signal_handler_add( manager, SIGNAL, OnEcoreElDBusAccessibilityNotification, handle );
1542 #endif // DALI_ELDBUS_AVAILABLE
1545 * Called when the source window notifies us the content in clipboard is selected.
1547 static Eina_Bool EcoreEventSelectionClear( void* data, int type, void* event )
1549 DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventSelectionClear\n" );
1550 Ecore_X_Event_Selection_Clear* selectionClearEvent( (Ecore_X_Event_Selection_Clear*) event );
1551 EventHandler* handler( (EventHandler*)data );
1553 if ( selectionClearEvent->win == handler->mImpl->mWindow )
1555 if ( selectionClearEvent->selection == ECORE_X_SELECTION_SECONDARY )
1557 // Request to get the content from Ecore.
1558 ecore_x_selection_secondary_request(selectionClearEvent->win, ECORE_X_SELECTION_TARGET_TEXT);
1561 return ECORE_CALLBACK_PASS_ON;
1565 * Called when the source window sends us about the selected content.
1566 * For example, when dragged items are dragged INTO our window or when items are selected in the clipboard.
1568 static Eina_Bool EcoreEventSelectionNotify( void* data, int type, void* event )
1570 DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventSelectionNotify\n" );
1572 Ecore_X_Event_Selection_Notify* selectionNotifyEvent( (Ecore_X_Event_Selection_Notify*) event );
1573 EventHandler* handler( (EventHandler*)data );
1575 if ( selectionNotifyEvent->win == handler->mImpl->mWindow )
1577 Ecore_X_Selection_Data* selectionData( (Ecore_X_Selection_Data*) selectionNotifyEvent->data );
1578 if ( selectionData->data )
1580 if ( selectionNotifyEvent->selection == ECORE_X_SELECTION_XDND )
1582 DragAndDropDetectorPtr dndDetector( handler->mDragAndDropDetector );
1584 // We have got the content that is to be dropped, inform the DndListener (if we have one).
1587 std::string content( (char*) selectionData->data, selectionData->length );
1588 dndDetector->SetContent( content );
1590 DALI_LOG_INFO( gSelectionEventLogFilter, Debug::General, "EcoreEventSelectionNotify: Content(%d):\n" , selectionData->length );
1591 DALI_LOG_INFO( gSelectionEventLogFilter, Debug::General, "======================================\n" );
1592 DALI_LOG_INFO( gSelectionEventLogFilter, Debug::General, "%s\n", selectionData->data );
1593 DALI_LOG_INFO( gSelectionEventLogFilter, Debug::General, "======================================\n" );
1596 else if ( selectionNotifyEvent->selection == ECORE_X_SELECTION_SECONDARY )
1598 // We have got the selected content, inform the clipboard event listener (if we have one).
1599 if ( handler->mClipboardEventNotifier )
1601 ClipboardEventNotifier& clipboardEventNotifier( ClipboardEventNotifier::GetImplementation( handler->mClipboardEventNotifier ) );
1602 std::string content( (char*) selectionData->data, selectionData->length );
1603 clipboardEventNotifier.SetContent( content );
1604 clipboardEventNotifier.EmitContentSelectedSignal();
1607 // Claim the ownership of the SECONDARY selection.
1608 ecore_x_selection_secondary_set(handler->mImpl->mWindow, "", 1);
1610 DALI_LOG_INFO( gSelectionEventLogFilter, Debug::General, "EcoreEventSelectionNotify: Content(%d):\n" , selectionData->length );
1611 DALI_LOG_INFO( gSelectionEventLogFilter, Debug::General, "======================================\n" );
1612 DALI_LOG_INFO( gSelectionEventLogFilter, Debug::General, "%s\n", selectionData->data );
1613 DALI_LOG_INFO( gSelectionEventLogFilter, Debug::General, "======================================\n" );
1617 return ECORE_CALLBACK_PASS_ON;
1621 #ifndef DALI_PROFILE_UBUNTU
1622 /////////////////////////////////////////////////////////////////////////////////////////////////
1624 /////////////////////////////////////////////////////////////////////////////////////////////////
1626 * Called when a font name is changed.
1628 static void VconfNotifyFontNameChanged( keynode_t* node, void* data )
1630 EventHandler* handler = static_cast<EventHandler*>( data );
1631 handler->SendEvent( StyleChange::DEFAULT_FONT_CHANGE );
1635 * Called when a font size is changed.
1637 static void VconfNotifyFontSizeChanged( keynode_t* node, void* data )
1639 EventHandler* handler = static_cast<EventHandler*>( data );
1640 handler->SendEvent( StyleChange::DEFAULT_FONT_SIZE_CHANGE );
1642 #endif // DALI_PROFILE_UBUNTU
1645 EventHandler* mHandler;
1646 std::vector<Ecore_Event_Handler*> mEcoreEventHandler;
1647 Ecore_X_Window mWindow;
1651 EventHandler::EventHandler( RenderSurface* surface, CoreEventInterface& coreEventInterface, GestureManager& gestureManager, DamageObserver& damageObserver, DragAndDropDetectorPtr dndDetector )
1652 : mCoreEventInterface(coreEventInterface),
1653 mGestureManager( gestureManager ),
1654 mStyleMonitor( StyleMonitor::Get() ),
1655 mDamageObserver( damageObserver ),
1656 mRotationObserver( NULL ),
1657 mDragAndDropDetector( dndDetector ),
1658 mAccessibilityAdaptor( AccessibilityAdaptor::Get() ),
1659 mClipboardEventNotifier( ClipboardEventNotifier::Get() ),
1660 mClipboard(Clipboard::Get()),
1663 Ecore_X_Window window = 0;
1665 // this code only works with the EcoreX11 RenderSurface so need to downcast
1666 ECore::WindowRenderSurface* ecoreSurface = dynamic_cast< ECore::WindowRenderSurface* >( surface );
1669 // enable multi touch
1670 window = ecoreSurface->GetXWindow();
1673 mImpl = new Impl(this, window);
1676 EventHandler::~EventHandler()
1683 mGestureManager.Stop();
1686 void EventHandler::SendEvent(TouchPoint& point, unsigned long timeStamp)
1690 timeStamp = GetCurrentMilliSeconds();
1693 Integration::TouchEvent touchEvent;
1694 Integration::HoverEvent hoverEvent;
1695 Integration::TouchEventCombiner::EventDispatchType type = mCombiner.GetNextTouchEvent(point, timeStamp, touchEvent, hoverEvent);
1696 if(type != Integration::TouchEventCombiner::DispatchNone )
1698 DALI_LOG_INFO(gTouchEventLogFilter, Debug::General, "%d: Device %d: Button state %d (%.2f, %.2f)\n", timeStamp, point.deviceId, point.state, point.local.x, point.local.y);
1700 // First the touch and/or hover event & related gesture events are queued
1701 if(type == Integration::TouchEventCombiner::DispatchTouch || type == Integration::TouchEventCombiner::DispatchBoth)
1703 mCoreEventInterface.QueueCoreEvent( touchEvent );
1704 mGestureManager.SendEvent(touchEvent);
1707 if(type == Integration::TouchEventCombiner::DispatchHover || type == Integration::TouchEventCombiner::DispatchBoth)
1709 mCoreEventInterface.QueueCoreEvent( hoverEvent );
1712 // Next the events are processed with a single call into Core
1713 mCoreEventInterface.ProcessCoreEvents();
1717 void EventHandler::SendEvent(KeyEvent& keyEvent)
1719 Dali::PhysicalKeyboard physicalKeyboard = PhysicalKeyboard::Get();
1720 if ( physicalKeyboard )
1722 if ( ! KeyLookup::IsDeviceButton( keyEvent.keyPressedName.c_str() ) )
1724 GetImplementation( physicalKeyboard ).KeyReceived( keyEvent.time > 1 );
1728 // Create KeyEvent and send to Core.
1729 Integration::KeyEvent event(keyEvent.keyPressedName, keyEvent.keyPressed, keyEvent.keyCode,
1730 keyEvent.keyModifier, keyEvent.time, static_cast<Integration::KeyEvent::State>(keyEvent.state));
1731 mCoreEventInterface.QueueCoreEvent( event );
1732 mCoreEventInterface.ProcessCoreEvents();
1735 void EventHandler::SendWheelEvent( WheelEvent& wheelEvent )
1737 // Create WheelEvent and send to Core.
1738 Integration::WheelEvent event( static_cast< Integration::WheelEvent::Type >(wheelEvent.type), wheelEvent.direction, wheelEvent.modifiers, wheelEvent.point, wheelEvent.z, wheelEvent.timeStamp );
1739 mCoreEventInterface.QueueCoreEvent( event );
1740 mCoreEventInterface.ProcessCoreEvents();
1743 void EventHandler::SendEvent( StyleChange::Type styleChange )
1745 DALI_ASSERT_DEBUG( mStyleMonitor && "StyleMonitor Not Available" );
1746 GetImplementation( mStyleMonitor ).StyleChanged(styleChange);
1749 void EventHandler::SendEvent( const DamageArea& area )
1751 mDamageObserver.OnDamaged( area );
1754 void EventHandler::SendRotationPrepareEvent( const RotationEvent& event )
1756 if( mRotationObserver != NULL )
1758 mRotationObserver->OnRotationPrepare( event );
1762 void EventHandler::SendRotationRequestEvent( )
1764 if( mRotationObserver != NULL )
1766 mRotationObserver->OnRotationRequest( );
1770 void EventHandler::FeedTouchPoint( TouchPoint& point, int timeStamp)
1772 SendEvent(point, timeStamp);
1775 void EventHandler::FeedWheelEvent( WheelEvent& wheelEvent )
1777 SendWheelEvent( wheelEvent );
1780 void EventHandler::FeedKeyEvent( KeyEvent& event )
1785 void EventHandler::FeedEvent( Integration::Event& event )
1787 mCoreEventInterface.QueueCoreEvent( event );
1788 mCoreEventInterface.ProcessCoreEvents();
1791 void EventHandler::Reset()
1795 // Any touch listeners should be told of the interruption.
1796 Integration::TouchEvent event;
1797 TouchPoint point(0, TouchPoint::Interrupted, 0, 0);
1798 event.AddPoint( point );
1800 // First the touch event & related gesture events are queued
1801 mCoreEventInterface.QueueCoreEvent( event );
1802 mGestureManager.SendEvent( event );
1804 // Next the events are processed with a single call into Core
1805 mCoreEventInterface.ProcessCoreEvents();
1808 void EventHandler::SetDragAndDropDetector( DragAndDropDetectorPtr detector )
1810 mDragAndDropDetector = detector;
1813 void EventHandler::SetRotationObserver( RotationObserver* observer )
1815 mRotationObserver = observer;
1818 } // namespace Adaptor
1820 } // namespace Internal