2 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <events/event-handler.h>
23 #include <Ecore_Input.h>
24 #include <ecore-wl-render-surface.h>
29 #ifndef DALI_PROFILE_UBUNTU
31 #include <vconf-keys.h>
32 #endif // DALI_PROFILE_UBUNTU
34 #ifdef DALI_ELDBUS_AVAILABLE
36 #endif // DALI_ELDBUS_AVAILABLE
38 #include <dali/public-api/common/vector-wrapper.h>
39 #include <dali/public-api/events/touch-point.h>
40 #include <dali/public-api/events/key-event.h>
41 #include <dali/public-api/events/wheel-event.h>
42 #include <dali/integration-api/debug.h>
43 #include <dali/integration-api/events/key-event-integ.h>
44 #include <dali/integration-api/events/touch-event-integ.h>
45 #include <dali/integration-api/events/hover-event-integ.h>
46 #include <dali/integration-api/events/wheel-event-integ.h>
49 #include <events/gesture-manager.h>
50 #include <window-render-surface.h>
51 #include <clipboard-impl.h>
53 #include <physical-keyboard-impl.h>
54 #include <style-monitor-impl.h>
55 #include <base/core-event-interface.h>
56 #include <virtual-keyboard.h>
67 #if defined(DEBUG_ENABLED)
70 Integration::Log::Filter* gTouchEventLogFilter = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_TOUCH");
71 Integration::Log::Filter* gDragAndDropLogFilter = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_DND");
72 Integration::Log::Filter* gImfLogging = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_IMF");
73 Integration::Log::Filter* gSelectionEventLogFilter = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_SELECTION");
74 } // unnamed namespace
82 const char* BUS = "org.enlightenment.wm-screen-reader";
83 const char* INTERFACE = "org.tizen.GestureNavigation";
84 const char* PATH = "/org/tizen/GestureNavigation";
86 const unsigned int PRIMARY_TOUCH_BUTTON_ID( 1 );
88 const unsigned int BYTES_PER_CHARACTER_FOR_ATTRIBUTES = 3;
91 * Ecore_Event_Modifier enums in Ecore_Input.h do not match Ecore_IMF_Keyboard_Modifiers in Ecore_IMF.h.
92 * This function converts from Ecore_Event_Modifier to Ecore_IMF_Keyboard_Modifiers enums.
93 * @param[in] ecoreModifier the Ecore_Event_Modifier input.
94 * @return the Ecore_IMF_Keyboard_Modifiers output.
96 Ecore_IMF_Keyboard_Modifiers EcoreInputModifierToEcoreIMFModifier(unsigned int ecoreModifier)
98 int modifier( ECORE_IMF_KEYBOARD_MODIFIER_NONE ); // If no other matches returns NONE.
101 if ( ecoreModifier & ECORE_EVENT_MODIFIER_SHIFT ) // enums from ecore_input/Ecore_Input.h
103 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_SHIFT; // enums from ecore_imf/ecore_imf.h
106 if ( ecoreModifier & ECORE_EVENT_MODIFIER_ALT )
108 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_ALT;
111 if ( ecoreModifier & ECORE_EVENT_MODIFIER_CTRL )
113 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_CTRL;
116 if ( ecoreModifier & ECORE_EVENT_MODIFIER_WIN )
118 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_WIN;
121 if ( ecoreModifier & ECORE_EVENT_MODIFIER_ALTGR )
123 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_ALTGR;
126 return static_cast<Ecore_IMF_Keyboard_Modifiers>( modifier );
130 // Copied from x server
131 static unsigned int GetCurrentMilliSeconds(void)
136 static clockid_t clockid;
140 #ifdef CLOCK_MONOTONIC_COARSE
141 if (clock_getres(CLOCK_MONOTONIC_COARSE, &tp) == 0 &&
142 (tp.tv_nsec / 1000) <= 1000 && clock_gettime(CLOCK_MONOTONIC_COARSE, &tp) == 0)
144 clockid = CLOCK_MONOTONIC_COARSE;
148 if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0)
150 clockid = CLOCK_MONOTONIC;
157 if (clockid != ~0L && clock_gettime(clockid, &tp) == 0)
159 return (tp.tv_sec * 1000) + (tp.tv_nsec / 1000000L);
162 gettimeofday(&tv, NULL);
163 return (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
166 #ifndef DALI_PROFILE_UBUNTU
167 const char * DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE = "db/setting/accessibility/font_name"; // It will be update at vconf-key.h and replaced.
168 #endif // DALI_PROFILE_UBUNTU
170 } // unnamed namespace
172 // Impl to hide EFL implementation.
173 struct EventHandler::Impl
175 // Construction & Destruction
180 Impl( EventHandler* handler, Ecore_Wl_Window* window )
181 : mHandler( handler ),
182 mEcoreEventHandler(),
184 #ifdef DALI_ELDBUS_AVAILABLE
185 , mSystemConnection( NULL )
186 #endif // DALI_ELDBUS_AVAILABLE
188 // Only register for touch and key events if we have a window
191 // Register Touch events
192 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_BUTTON_DOWN, EcoreEventMouseButtonDown, handler ) );
193 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_BUTTON_UP, EcoreEventMouseButtonUp, handler ) );
194 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_MOVE, EcoreEventMouseButtonMove, handler ) );
195 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_OUT, EcoreEventMouseButtonUp, handler ) ); // process mouse out event like up event
197 // Register Mouse wheel events
198 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_WHEEL, EcoreEventMouseWheel, handler ) );
200 // Register Focus events
201 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_WL_EVENT_FOCUS_IN, EcoreEventWindowFocusIn, handler ) );
202 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_WL_EVENT_FOCUS_OUT, EcoreEventWindowFocusOut, handler ) );
204 // Register Key events
205 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_KEY_DOWN, EcoreEventKeyDown, handler ) );
206 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_KEY_UP, EcoreEventKeyUp, handler ) );
208 // Register Selection event - clipboard selection
209 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_WL_EVENT_DATA_SOURCE_SEND, EcoreEventDataSend, handler ) );
210 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_WL_EVENT_SELECTION_DATA_READY, EcoreEventDataReceive, handler ) );
212 // Register Rotate event
213 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_WL_EVENT_WINDOW_ROTATE, EcoreEventRotate, handler) );
215 // Register Detent event
216 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_DETENT_ROTATE, EcoreEventDetent, handler) );
218 #ifndef DALI_PROFILE_UBUNTU
219 // Register Vconf notify - font name and size
220 vconf_notify_key_changed( DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontNameChanged, handler );
221 vconf_notify_key_changed( VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontSizeChanged, handler );
222 #endif // DALI_PROFILE_UBUNTU
224 #ifdef DALI_ELDBUS_AVAILABLE
225 // Initialize ElDBus.
226 DALI_LOG_INFO( gImfLogging, Debug::General, "Starting DBus Initialization\n" );
229 EcoreElDBusInitialisation( handler );
231 DALI_LOG_INFO( gImfLogging, Debug::General, "Finished DBus Initialization\n" );
232 #endif // DALI_ELDBUS_AVAILABLE
241 #ifndef DALI_PROFILE_UBUNTU
242 vconf_ignore_key_changed( VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontSizeChanged );
243 vconf_ignore_key_changed( DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontNameChanged );
244 #endif // DALI_PROFILE_UBUNTU
246 for( std::vector<Ecore_Event_Handler*>::iterator iter = mEcoreEventHandler.begin(), endIter = mEcoreEventHandler.end(); iter != endIter; ++iter )
248 ecore_event_handler_del( *iter );
251 #ifdef DALI_ELDBUS_AVAILABLE
252 // Close down ElDBus connections.
253 if( mSystemConnection )
255 eldbus_connection_unref( mSystemConnection );
257 #endif // DALI_ELDBUS_AVAILABLE
262 /////////////////////////////////////////////////////////////////////////////////////////////////
264 /////////////////////////////////////////////////////////////////////////////////////////////////
267 * Called when a touch down is received.
269 static Eina_Bool EcoreEventMouseButtonDown( void* data, int type, void* event )
271 Ecore_Event_Mouse_Button *touchEvent( (Ecore_Event_Mouse_Button*)event );
272 EventHandler* handler( (EventHandler*)data );
274 if ( touchEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
276 PointState::Type state ( PointState::DOWN );
278 // Check if the buttons field is set and ensure it's the primary touch button.
279 // If this event was triggered by buttons other than the primary button (used for touch), then
280 // just send an interrupted event to Core.
281 if ( touchEvent->buttons && (touchEvent->buttons != PRIMARY_TOUCH_BUTTON_ID ) )
283 state = PointState::INTERRUPTED;
286 Integration::Point point;
287 point.SetDeviceId( touchEvent->multi.device );
288 point.SetState( state );
289 point.SetScreenPosition( Vector2( touchEvent->x, touchEvent->y ) );
290 point.SetRadius( touchEvent->multi.radius, Vector2( touchEvent->multi.radius_x, touchEvent->multi.radius_y ) );
291 point.SetPressure( touchEvent->multi.pressure );
292 point.SetAngle( Degree( touchEvent->multi.angle ) );
293 handler->SendEvent( point, touchEvent->timestamp );
296 return ECORE_CALLBACK_PASS_ON;
300 * Called when a touch up is received.
302 static Eina_Bool EcoreEventMouseButtonUp( void* data, int type, void* event )
304 Ecore_Event_Mouse_Button *touchEvent( (Ecore_Event_Mouse_Button*)event );
305 EventHandler* handler( (EventHandler*)data );
307 if ( touchEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
309 Integration::Point point;
310 point.SetDeviceId( touchEvent->multi.device );
311 point.SetState( PointState::UP );
312 point.SetScreenPosition( Vector2( touchEvent->x, touchEvent->y ) );
313 point.SetRadius( touchEvent->multi.radius, Vector2( touchEvent->multi.radius_x, touchEvent->multi.radius_y ) );
314 point.SetPressure( touchEvent->multi.pressure );
315 point.SetAngle( Degree( touchEvent->multi.angle ) );
316 handler->SendEvent( point, touchEvent->timestamp );
319 return ECORE_CALLBACK_PASS_ON;
323 * Called when a touch up is received.
325 static Eina_Bool EcoreEventMouseWheel( void* data, int type, void* event )
327 Ecore_Event_Mouse_Wheel *mouseWheelEvent( (Ecore_Event_Mouse_Wheel*)event );
329 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);
331 EventHandler* handler( (EventHandler*)data );
332 if ( mouseWheelEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
334 WheelEvent wheelEvent( WheelEvent::MOUSE_WHEEL, mouseWheelEvent->direction, mouseWheelEvent->modifiers, Vector2(mouseWheelEvent->x, mouseWheelEvent->y), mouseWheelEvent->z, mouseWheelEvent->timestamp );
335 handler->SendWheelEvent( wheelEvent );
337 return ECORE_CALLBACK_PASS_ON;
341 * Called when a touch motion is received.
343 static Eina_Bool EcoreEventMouseButtonMove( void* data, int type, void* event )
345 Ecore_Event_Mouse_Move *touchEvent( (Ecore_Event_Mouse_Move*)event );
346 EventHandler* handler( (EventHandler*)data );
348 if ( touchEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
350 Integration::Point point;
351 point.SetDeviceId( touchEvent->multi.device );
352 point.SetState( PointState::MOTION );
353 point.SetScreenPosition( Vector2( touchEvent->x, touchEvent->y ) );
354 point.SetRadius( touchEvent->multi.radius, Vector2( touchEvent->multi.radius_x, touchEvent->multi.radius_y ) );
355 point.SetPressure( touchEvent->multi.pressure );
356 point.SetAngle( Degree( touchEvent->multi.angle ) );
357 handler->SendEvent( point, touchEvent->timestamp );
360 return ECORE_CALLBACK_PASS_ON;
363 /////////////////////////////////////////////////////////////////////////////////////////////////
365 /////////////////////////////////////////////////////////////////////////////////////////////////
368 * Called when a key down is received.
370 static Eina_Bool EcoreEventKeyDown( void* data, int type, void* event )
372 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventKeyDown \n" );
374 EventHandler* handler( (EventHandler*)data );
375 Ecore_Event_Key *keyEvent( (Ecore_Event_Key*)event );
376 bool eventHandled( false );
378 // If a device key then skip ecore_imf_context_filter_event.
379 if ( ! KeyLookup::IsDeviceButton( keyEvent->keyname ) )
381 Ecore_IMF_Context* imfContext = NULL;
382 Dali::ImfManager imfManager( ImfManager::Get() );
385 imfContext = ImfManager::GetImplementation( imfManager ).GetContext();
390 // We're consuming key down event so we have to pass to IMF so that it can parse it as well.
391 Ecore_IMF_Event_Key_Down ecoreKeyDownEvent;
392 ecoreKeyDownEvent.keyname = keyEvent->keyname;
393 ecoreKeyDownEvent.key = keyEvent->key;
394 ecoreKeyDownEvent.string = keyEvent->string;
395 ecoreKeyDownEvent.compose = keyEvent->compose;
396 ecoreKeyDownEvent.timestamp = keyEvent->timestamp;
397 ecoreKeyDownEvent.modifiers = EcoreInputModifierToEcoreIMFModifier ( keyEvent->modifiers );
398 ecoreKeyDownEvent.locks = (Ecore_IMF_Keyboard_Locks) ECORE_IMF_KEYBOARD_LOCK_NONE;
399 #ifdef ECORE_IMF_1_13
400 ecoreKeyDownEvent.dev_name = "";
401 ecoreKeyDownEvent.dev_class = ECORE_IMF_DEVICE_CLASS_KEYBOARD;
402 ecoreKeyDownEvent.dev_subclass = ECORE_IMF_DEVICE_SUBCLASS_NONE;
403 #endif // ECORE_IMF_1_13
405 eventHandled = ecore_imf_context_filter_event( imfContext,
406 ECORE_IMF_EVENT_KEY_DOWN,
407 (Ecore_IMF_Event *) &ecoreKeyDownEvent );
409 // If the event has not been handled by IMF then check if we should reset our IMF context
412 if ( !strcmp( keyEvent->keyname, "Escape" ) ||
413 !strcmp( keyEvent->keyname, "Return" ) ||
414 !strcmp( keyEvent->keyname, "KP_Enter" ) )
416 ecore_imf_context_reset( imfContext );
422 // If the event wasn't handled then we should send a key event.
425 if ( keyEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
427 std::string keyName( keyEvent->keyname );
428 std::string keyString( "" );
429 int keyCode = KeyLookup::GetDaliKeyCode( keyEvent->keyname);
430 keyCode = (keyCode == -1) ? 0 : keyCode;
431 int modifier( keyEvent->modifiers );
432 unsigned long time = keyEvent->timestamp;
433 if (!strncmp(keyEvent->keyname, "Keycode-", 8))
434 keyCode = atoi(keyEvent->keyname + 8);
436 // Ensure key event string is not NULL as keys like SHIFT have a null string.
437 if ( keyEvent->string )
439 keyString = keyEvent->string;
442 KeyEvent keyEvent(keyName, keyString, keyCode, modifier, time, KeyEvent::Down);
443 handler->SendEvent( keyEvent );
447 return ECORE_CALLBACK_PASS_ON;
451 * Called when a key up is received.
453 static Eina_Bool EcoreEventKeyUp( void* data, int type, void* event )
455 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventKeyUp\n" );
457 EventHandler* handler( (EventHandler*)data );
458 Ecore_Event_Key *keyEvent( (Ecore_Event_Key*)event );
459 bool eventHandled( false );
461 // Device keys like Menu, home, back button must skip ecore_imf_context_filter_event.
462 if ( ! KeyLookup::IsDeviceButton( keyEvent->keyname ) )
464 Ecore_IMF_Context* imfContext = NULL;
465 Dali::ImfManager imfManager( ImfManager::Get() );
468 imfContext = ImfManager::GetImplementation( imfManager ).GetContext();
473 // We're consuming key up event so we have to pass to IMF so that it can parse it as well.
474 Ecore_IMF_Event_Key_Up ecoreKeyUpEvent;
475 ecoreKeyUpEvent.keyname = keyEvent->keyname;
476 ecoreKeyUpEvent.key = keyEvent->key;
477 ecoreKeyUpEvent.string = keyEvent->string;
478 ecoreKeyUpEvent.compose = keyEvent->compose;
479 ecoreKeyUpEvent.timestamp = keyEvent->timestamp;
480 ecoreKeyUpEvent.modifiers = EcoreInputModifierToEcoreIMFModifier ( keyEvent->modifiers );
481 ecoreKeyUpEvent.locks = (Ecore_IMF_Keyboard_Locks) ECORE_IMF_KEYBOARD_LOCK_NONE;
482 #ifdef ECORE_IMF_1_13
483 ecoreKeyUpEvent.dev_name = "";
484 ecoreKeyUpEvent.dev_class = ECORE_IMF_DEVICE_CLASS_KEYBOARD;
485 ecoreKeyUpEvent.dev_subclass = ECORE_IMF_DEVICE_SUBCLASS_NONE;
486 #endif // ECORE_IMF_1_13
488 eventHandled = ecore_imf_context_filter_event( imfContext,
489 ECORE_IMF_EVENT_KEY_UP,
490 (Ecore_IMF_Event *) &ecoreKeyUpEvent );
494 // If the event wasn't handled then we should send a key event.
497 if ( keyEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
499 std::string keyName( keyEvent->keyname );
500 std::string keyString( "" );
501 int keyCode = KeyLookup::GetDaliKeyCode( keyEvent->keyname);
502 keyCode = (keyCode == -1) ? 0 : keyCode;
503 int modifier( keyEvent->modifiers );
504 unsigned long time = keyEvent->timestamp;
505 if (!strncmp(keyEvent->keyname, "Keycode-", 8))
506 keyCode = atoi(keyEvent->keyname + 8);
508 // Ensure key event string is not NULL as keys like SHIFT have a null string.
509 if ( keyEvent->string )
511 keyString = keyEvent->string;
514 KeyEvent keyEvent(keyName, keyString, keyCode, modifier, time, KeyEvent::Up);
515 handler->SendEvent( keyEvent );
519 return ECORE_CALLBACK_PASS_ON;
522 /////////////////////////////////////////////////////////////////////////////////////////////////
524 /////////////////////////////////////////////////////////////////////////////////////////////////
527 * Called when the window gains focus.
529 static Eina_Bool EcoreEventWindowFocusIn( void* data, int type, void* event )
531 Ecore_Wl_Event_Focus_In* focusInEvent( (Ecore_Wl_Event_Focus_In*)event );
532 EventHandler* handler( (EventHandler*)data );
534 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventWindowFocusIn \n" );
536 // If the window gains focus and we hid the keyboard then show it again.
537 if ( focusInEvent->win == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
539 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT EcoreEventWindowFocusIn - >>WindowFocusGained \n" );
541 if ( ImfManager::IsAvailable() /* Only get the ImfManager if it's available as we do not want to create it */ )
543 Dali::ImfManager imfManager( ImfManager::Get() );
546 ImfManager& imfManagerImpl( ImfManager::GetImplementation( imfManager ) );
547 if( imfManagerImpl.RestoreAfterFocusLost() )
549 imfManagerImpl.Activate();
553 Dali::Clipboard clipboard = Clipboard::Get();
554 clipboard.HideClipboard();
557 return ECORE_CALLBACK_PASS_ON;
561 * Called when the window loses focus.
563 static Eina_Bool EcoreEventWindowFocusOut( void* data, int type, void* event )
565 Ecore_Wl_Event_Focus_Out* focusOutEvent( (Ecore_Wl_Event_Focus_Out*)event );
566 EventHandler* handler( (EventHandler*)data );
568 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventWindowFocusOut \n" );
570 // If the window loses focus then hide the keyboard.
571 if ( focusOutEvent->win == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
573 if ( ImfManager::IsAvailable() /* Only get the ImfManager if it's available as we do not want to create it */ )
575 Dali::ImfManager imfManager( ImfManager::Get() );
578 ImfManager& imfManagerImpl( ImfManager::GetImplementation( imfManager ) );
579 if( imfManagerImpl.RestoreAfterFocusLost() )
581 imfManagerImpl.Deactivate();
586 // Hiding clipboard event will be ignored once because window focus out event is always received on showing clipboard
587 Dali::Clipboard clipboard = Clipboard::Get();
590 Clipboard& clipBoardImpl( GetImplementation( clipboard ) );
591 clipBoardImpl.HideClipboard(true);
595 return ECORE_CALLBACK_PASS_ON;
599 * Called when the window is damaged.
601 static Eina_Bool EcoreEventWindowDamaged(void *data, int type, void *event)
603 return ECORE_CALLBACK_PASS_ON;
607 * Called when the window properties are changed.
608 * We are only interested in the font change.
612 /////////////////////////////////////////////////////////////////////////////////////////////////
613 // Drag & Drop Callbacks
614 /////////////////////////////////////////////////////////////////////////////////////////////////
617 * Called when a dragged item enters our window's bounds.
618 * This is when items are dragged INTO our window.
620 static Eina_Bool EcoreEventDndEnter( void* data, int type, void* event )
622 DALI_LOG_INFO( gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndEnter\n" );
624 return ECORE_CALLBACK_PASS_ON;
628 * Called when a dragged item is moved within our window.
629 * This is when items are dragged INTO our window.
631 static Eina_Bool EcoreEventDndPosition( void* data, int type, void* event )
633 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndPosition\n" );
635 return ECORE_CALLBACK_PASS_ON;
639 * Called when a dragged item leaves our window's bounds.
640 * This is when items are dragged INTO our window.
642 static Eina_Bool EcoreEventDndLeave( void* data, int type, void* event )
644 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndLeave\n" );
646 return ECORE_CALLBACK_PASS_ON;
650 * Called when the dragged item is dropped within our window's bounds.
651 * This is when items are dragged INTO our window.
653 static Eina_Bool EcoreEventDndDrop( void* data, int type, void* event )
655 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndDrop\n" );
657 return ECORE_CALLBACK_PASS_ON;
661 * Called when a dragged item is moved from our window and the target window has done processing it.
662 * This is when items are dragged FROM our window.
664 static Eina_Bool EcoreEventDndFinished( void* data, int type, void* event )
666 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndFinished\n" );
667 return ECORE_CALLBACK_PASS_ON;
671 * Called when a dragged item is moved from our window and the target window has sent us a status.
672 * This is when items are dragged FROM our window.
674 static Eina_Bool EcoreEventDndStatus( void* data, int type, void* event )
676 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndStatus\n" );
677 return ECORE_CALLBACK_PASS_ON;
681 * Called when the client messages (i.e. the accessibility events) are received.
683 static Eina_Bool EcoreEventClientMessage( void* data, int type, void* event )
685 return ECORE_CALLBACK_PASS_ON;
689 /////////////////////////////////////////////////////////////////////////////////////////////////
690 // ElDBus Accessibility Callbacks
691 /////////////////////////////////////////////////////////////////////////////////////////////////
693 #ifdef DALI_ELDBUS_AVAILABLE
694 // Callback for Ecore ElDBus accessibility events.
695 static void OnEcoreElDBusAccessibilityNotification( void *context EINA_UNUSED, const Eldbus_Message *message )
697 EventHandler* handler = static_cast< EventHandler* >( context );
698 // Ignore any accessibility events when paused.
699 if( handler->mPaused )
704 if( !handler->mAccessibilityAdaptor )
706 DALI_LOG_ERROR( "Invalid accessibility adaptor\n" );
710 AccessibilityAdaptor* accessibilityAdaptor( &AccessibilityAdaptor::GetImplementation( handler->mAccessibilityAdaptor ) );
711 if( !accessibilityAdaptor )
713 DALI_LOG_ERROR( "Cannot access accessibility adaptor\n" );
719 int state; // 0 - begin, 1 - ongoing, 2 - ended, 3 - aborted
722 // The string defines the arg-list's respective types.
723 if( !eldbus_message_arguments_get( message, "iiiiiiu", &gestureValue, &xS, &yS, &xE, &yE, &state, &eventTime ) )
725 DALI_LOG_ERROR( "OnEcoreElDBusAccessibilityNotification: Error getting arguments\n" );
728 DALI_LOG_INFO( gImfLogging, Debug::General, "Got gesture: Name: %d Args: %d,%d,%d,%d State: %d\n", gestureValue, xS, yS, xE, yE );
730 // Create a touch point object.
731 TouchPoint::State touchPointState( TouchPoint::Down );
734 touchPointState = TouchPoint::Down; // Mouse down.
736 else if( state == 1 )
738 touchPointState = TouchPoint::Motion; // Mouse move.
740 else if( state == 2 )
742 touchPointState = TouchPoint::Up; // Mouse up.
746 touchPointState = TouchPoint::Interrupted; // Error.
749 // Send touch event to accessibility adaptor.
750 TouchPoint point( 0, touchPointState, (float)xS, (float)yS );
752 // Perform actions based on received gestures.
753 // Note: This is seperated from the reading so we can have other input readers without changing the below code.
754 switch( gestureValue )
756 case 0: // OneFingerHover
759 accessibilityAdaptor->HandleActionReadEvent( (unsigned int)xS, (unsigned int)yS, true /* allow read again */ );
762 case 1: // TwoFingersHover
764 // In accessibility mode, scroll action should be handled when the currently focused actor is contained in scrollable control
765 accessibilityAdaptor->HandleActionScrollEvent( point, GetCurrentMilliSeconds() );
768 case 2: // ThreeFingersHover
770 // Read from top item on screen continuously.
771 accessibilityAdaptor->HandleActionReadFromTopEvent();
774 case 3: // OneFingerFlickLeft
776 // Move to previous item.
777 accessibilityAdaptor->HandleActionReadPreviousEvent();
780 case 4: // OneFingerFlickRight
782 // Move to next item.
783 accessibilityAdaptor->HandleActionReadNextEvent();
786 case 5: // OneFingerFlickUp
788 // Move to previous item.
789 accessibilityAdaptor->HandleActionPreviousEvent();
792 case 6: // OneFingerFlickDown
794 // Move to next item.
795 accessibilityAdaptor->HandleActionNextEvent();
798 case 7: // TwoFingersFlickUp
800 // Scroll up the list.
801 accessibilityAdaptor->HandleActionScrollUpEvent();
804 case 8: // TwoFingersFlickDown
806 // Scroll down the list.
807 accessibilityAdaptor->HandleActionScrollDownEvent();
810 case 9: // TwoFingersFlickLeft
812 // Scroll left to the previous page
813 accessibilityAdaptor->HandleActionPageLeftEvent();
816 case 10: // TwoFingersFlickRight
818 // Scroll right to the next page
819 accessibilityAdaptor->HandleActionPageRightEvent();
822 case 11: // ThreeFingersFlickLeft
827 case 12: // ThreeFingersFlickRight
832 case 13: // ThreeFingersFlickUp
837 case 14: // ThreeFingersFlickDown
842 case 15: // OneFingerSingleTap
845 accessibilityAdaptor->HandleActionReadEvent( (unsigned int)xS, (unsigned int)yS, true /* allow read again */ );
848 case 16: // OneFingerDoubleTap
850 // Activate selected item / active edit mode.
851 accessibilityAdaptor->HandleActionActivateEvent();
854 case 17: // OneFingerTripleTap
857 accessibilityAdaptor->HandleActionZoomEvent();
860 case 18: // TwoFingersSingleTap
862 // Pause/Resume current speech
863 accessibilityAdaptor->HandleActionReadPauseResumeEvent();
866 case 19: // TwoFingersDoubleTap
868 // Start/Stop current action
869 accessibilityAdaptor->HandleActionStartStopEvent();
872 case 20: // TwoFingersTripleTap
874 // Read information from indicator
875 accessibilityAdaptor->HandleActionReadIndicatorInformationEvent();
878 case 21: // ThreeFingersSingleTap
880 // Read from top item on screen continuously.
881 accessibilityAdaptor->HandleActionReadFromTopEvent();
884 case 22: // ThreeFingersDoubleTap
886 // Read from next item continuously.
887 accessibilityAdaptor->HandleActionReadFromNextEvent();
890 case 23: // ThreeFingersTripleTap
895 case 24: // OneFingerFlickLeftReturn
897 // Scroll up to the previous page
898 accessibilityAdaptor->HandleActionPageUpEvent();
901 case 25: // OneFingerFlickRightReturn
903 // Scroll down to the next page
904 accessibilityAdaptor->HandleActionPageDownEvent();
907 case 26: // OneFingerFlickUpReturn
909 // Move to the first item on screen
910 accessibilityAdaptor->HandleActionMoveToFirstEvent();
913 case 27: // OneFingerFlickDownReturn
915 // Move to the last item on screen
916 accessibilityAdaptor->HandleActionMoveToLastEvent();
919 case 28: // TwoFingersFlickLeftReturn
924 case 29: // TwoFingersFlickRightReturn
929 case 30: // TwoFingersFlickUpReturn
934 case 31: // TwoFingersFlickDownReturn
939 case 32: // ThreeFingersFlickLeftReturn
944 case 33: // ThreeFingersFlickRightReturn
949 case 34: // ThreeFingersFlickUpReturn
954 case 35: // ThreeFingersFlickDownReturn
962 void EcoreElDBusInitialisation( void *handle )
964 Eldbus_Object *object;
965 Eldbus_Proxy *manager;
967 if( !( mSystemConnection = eldbus_connection_get(ELDBUS_CONNECTION_TYPE_SYSTEM) ) )
969 DALI_LOG_ERROR( "Unable to get system bus\n" );
972 object = eldbus_object_get( mSystemConnection, BUS, PATH );
975 DALI_LOG_ERROR( "Getting object failed\n" );
979 manager = eldbus_proxy_get( object, INTERFACE );
982 DALI_LOG_ERROR( "Getting proxy failed\n" );
986 if( !eldbus_proxy_signal_handler_add( manager, "GestureDetected", OnEcoreElDBusAccessibilityNotification, handle ) )
988 DALI_LOG_ERROR( "No signal handler returned\n" );
991 #endif // DALI_ELDBUS_AVAILABLE
994 * Called when the source window notifies us the content in clipboard is selected.
996 static Eina_Bool EcoreEventSelectionClear( void* data, int type, void* event )
998 DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventSelectionClear\n" );
999 return ECORE_CALLBACK_PASS_ON;
1003 * Called when the source window sends us about the selected content.
1004 * For example, when dragged items are dragged INTO our window or when items are selected in the clipboard.
1006 static Eina_Bool EcoreEventSelectionNotify( void* data, int type, void* event )
1008 DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventSelectionNotify\n" );
1009 return ECORE_CALLBACK_PASS_ON;
1013 * Called when the source window notifies us the content in clipboard is selected.
1015 static Eina_Bool EcoreEventDataSend( void* data, int type, void* event )
1017 DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventDataSend\n" );
1019 Dali::Clipboard clipboard = Clipboard::Get();
1022 Clipboard& clipBoardImpl( GetImplementation( clipboard ) );
1023 clipBoardImpl.ExcuteBuffered( true, event );
1025 return ECORE_CALLBACK_PASS_ON;
1029 * Called when the source window sends us about the selected content.
1030 * For example, when item is selected in the clipboard.
1032 static Eina_Bool EcoreEventDataReceive( void* data, int type, void* event )
1034 DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventDataReceive\n" );
1036 EventHandler* handler( (EventHandler*)data );
1037 Dali::Clipboard clipboard = Clipboard::Get();
1038 char *selectionData = NULL;
1041 Clipboard& clipBoardImpl( GetImplementation( clipboard ) );
1042 selectionData = clipBoardImpl.ExcuteBuffered( false, event );
1044 if ( selectionData && handler->mClipboardEventNotifier )
1046 ClipboardEventNotifier& clipboardEventNotifier( ClipboardEventNotifier::GetImplementation( handler->mClipboardEventNotifier ) );
1047 std::string content( selectionData, strlen(selectionData) );
1049 clipboardEventNotifier.SetContent( content );
1050 clipboardEventNotifier.EmitContentSelectedSignal();
1052 return ECORE_CALLBACK_PASS_ON;
1056 * Called when rotate event is recevied
1058 static Eina_Bool EcoreEventRotate( void* data, int type, void* event )
1060 DALI_LOG_INFO( gSelectionEventLogFilter, Debug::Concise, "EcoreEventRotate\n" );
1062 EventHandler* handler( (EventHandler*)data );
1063 Ecore_Wl_Event_Window_Rotate* ev( (Ecore_Wl_Event_Window_Rotate*)event );
1065 if( ev->win != (unsigned int)ecore_wl_window_id_get( handler->mImpl->mWindow ) )
1067 return ECORE_CALLBACK_PASS_ON;
1070 RotationEvent rotationEvent;
1071 rotationEvent.angle = ev->angle;
1072 rotationEvent.winResize = 0;
1073 rotationEvent.width = ev->w;
1074 rotationEvent.height = ev->h;
1075 handler->SendRotationPrepareEvent( rotationEvent );
1077 return ECORE_CALLBACK_PASS_ON;
1081 * Called when detent event is recevied
1083 static Eina_Bool EcoreEventDetent( void* data, int type, void* event )
1085 DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventDetent\n" );
1086 EventHandler* handler( (EventHandler*)data );
1087 Ecore_Event_Detent_Rotate *e((Ecore_Event_Detent_Rotate *)event);
1088 int direction = (e->direction == ECORE_DETENT_DIRECTION_CLOCKWISE) ? 1 : -1;
1089 int timeStamp = e->timestamp;
1091 WheelEvent wheelEvent( WheelEvent::CUSTOM_WHEEL, 0, 0, Vector2(0.0f, 0.0f), direction, timeStamp );
1092 handler->SendWheelEvent( wheelEvent );
1093 return ECORE_CALLBACK_PASS_ON;
1096 /////////////////////////////////////////////////////////////////////////////////////////////////
1098 /////////////////////////////////////////////////////////////////////////////////////////////////
1100 * Called when a font name is changed.
1102 static void VconfNotifyFontNameChanged( keynode_t* node, void* data )
1104 EventHandler* handler = static_cast<EventHandler*>( data );
1105 handler->SendEvent( StyleChange::DEFAULT_FONT_CHANGE );
1109 * Called when a font size is changed.
1111 static void VconfNotifyFontSizeChanged( keynode_t* node, void* data )
1113 EventHandler* handler = static_cast<EventHandler*>( data );
1114 handler->SendEvent( StyleChange::DEFAULT_FONT_SIZE_CHANGE );
1118 EventHandler* mHandler;
1119 std::vector<Ecore_Event_Handler*> mEcoreEventHandler;
1120 Ecore_Wl_Window* mWindow;
1121 #ifdef DALI_ELDBUS_AVAILABLE
1122 Eldbus_Connection* mSystemConnection;
1123 #endif // DALI_ELDBUS_AVAILABLE
1126 EventHandler::EventHandler( RenderSurface* surface, CoreEventInterface& coreEventInterface, GestureManager& gestureManager, DamageObserver& damageObserver, DragAndDropDetectorPtr dndDetector )
1127 : mCoreEventInterface( coreEventInterface ),
1128 mGestureManager( gestureManager ),
1129 mStyleMonitor( StyleMonitor::Get() ),
1130 mDamageObserver( damageObserver ),
1131 mRotationObserver( NULL ),
1132 mDragAndDropDetector( dndDetector ),
1133 mAccessibilityAdaptor( AccessibilityAdaptor::Get() ),
1134 mClipboardEventNotifier( ClipboardEventNotifier::Get() ),
1135 mClipboard( Clipboard::Get() ),
1139 Ecore_Wl_Window* window = 0;
1141 // this code only works with the Ecore RenderSurface so need to downcast
1142 ECore::WindowRenderSurface* ecoreSurface = dynamic_cast< ECore::WindowRenderSurface* >( surface );
1145 window = ecoreSurface->GetWlWindow();
1148 mImpl = new Impl(this, window);
1151 EventHandler::~EventHandler()
1158 mGestureManager.Stop();
1161 void EventHandler::SendEvent(Integration::Point& point, unsigned long timeStamp)
1165 timeStamp = GetCurrentMilliSeconds();
1168 Integration::TouchEvent touchEvent;
1169 Integration::HoverEvent hoverEvent;
1170 Integration::TouchEventCombiner::EventDispatchType type = mCombiner.GetNextTouchEvent(point, timeStamp, touchEvent, hoverEvent);
1171 if(type != Integration::TouchEventCombiner::DispatchNone )
1173 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);
1175 // First the touch and/or hover event & related gesture events are queued
1176 if(type == Integration::TouchEventCombiner::DispatchTouch || type == Integration::TouchEventCombiner::DispatchBoth)
1178 mCoreEventInterface.QueueCoreEvent( touchEvent );
1179 mGestureManager.SendEvent(touchEvent);
1182 if(type == Integration::TouchEventCombiner::DispatchHover || type == Integration::TouchEventCombiner::DispatchBoth)
1184 mCoreEventInterface.QueueCoreEvent( hoverEvent );
1187 // Next the events are processed with a single call into Core
1188 mCoreEventInterface.ProcessCoreEvents();
1192 void EventHandler::SendEvent(KeyEvent& keyEvent)
1194 Dali::PhysicalKeyboard physicalKeyboard = PhysicalKeyboard::Get();
1195 if ( physicalKeyboard )
1197 if ( ! KeyLookup::IsDeviceButton( keyEvent.keyPressedName.c_str() ) )
1199 GetImplementation( physicalKeyboard ).KeyReceived( keyEvent.time > 1 );
1203 // Create KeyEvent and send to Core.
1204 Integration::KeyEvent event(keyEvent.keyPressedName, keyEvent.keyPressed, keyEvent.keyCode,
1205 keyEvent.keyModifier, keyEvent.time, static_cast<Integration::KeyEvent::State>(keyEvent.state));
1206 mCoreEventInterface.QueueCoreEvent( event );
1207 mCoreEventInterface.ProcessCoreEvents();
1210 void EventHandler::SendWheelEvent( WheelEvent& wheelEvent )
1212 // Create WheelEvent and send to Core.
1213 Integration::WheelEvent event( static_cast< Integration::WheelEvent::Type >(wheelEvent.type), wheelEvent.direction, wheelEvent.modifiers, wheelEvent.point, wheelEvent.z, wheelEvent.timeStamp );
1214 mCoreEventInterface.QueueCoreEvent( event );
1215 mCoreEventInterface.ProcessCoreEvents();
1218 void EventHandler::SendEvent( StyleChange::Type styleChange )
1220 DALI_ASSERT_DEBUG( mStyleMonitor && "StyleMonitor Not Available" );
1221 GetImplementation( mStyleMonitor ).StyleChanged(styleChange);
1224 void EventHandler::SendEvent( const DamageArea& area )
1226 mDamageObserver.OnDamaged( area );
1229 void EventHandler::SendRotationPrepareEvent( const RotationEvent& event )
1231 if( mRotationObserver != NULL )
1233 mRotationObserver->OnRotationPrepare( event );
1234 mRotationObserver->OnRotationRequest();
1238 void EventHandler::SendRotationRequestEvent( )
1240 // No need to separate event into prepare and request in wayland
1243 void EventHandler::FeedTouchPoint( TouchPoint& point, int timeStamp)
1245 Integration::Point convertedPoint( point );
1246 SendEvent(convertedPoint, timeStamp);
1249 void EventHandler::FeedWheelEvent( WheelEvent& wheelEvent )
1251 SendWheelEvent( wheelEvent );
1254 void EventHandler::FeedKeyEvent( KeyEvent& event )
1259 void EventHandler::FeedEvent( Integration::Event& event )
1261 mCoreEventInterface.QueueCoreEvent( event );
1262 mCoreEventInterface.ProcessCoreEvents();
1265 void EventHandler::Reset()
1269 // Any touch listeners should be told of the interruption.
1270 Integration::TouchEvent event;
1271 Integration::Point point;
1272 point.SetState( PointState::INTERRUPTED );
1273 event.AddPoint( point );
1275 // First the touch event & related gesture events are queued
1276 mCoreEventInterface.QueueCoreEvent( event );
1277 mGestureManager.SendEvent( event );
1279 // Next the events are processed with a single call into Core
1280 mCoreEventInterface.ProcessCoreEvents();
1283 void EventHandler::Pause()
1289 void EventHandler::Resume()
1295 void EventHandler::SetDragAndDropDetector( DragAndDropDetectorPtr detector )
1297 mDragAndDropDetector = detector;
1300 void EventHandler::SetRotationObserver( RotationObserver* observer )
1302 mRotationObserver = observer;
1305 } // namespace Adaptor
1307 } // namespace Internal