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;
483 eventHandled = ecore_imf_context_filter_event( imfContext,
484 ECORE_IMF_EVENT_KEY_UP,
485 (Ecore_IMF_Event *) &ecoreKeyUpEvent );
489 // If the event wasn't handled then we should send a key event.
492 if ( keyEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
494 std::string keyName( keyEvent->keyname );
495 std::string keyString( "" );
496 int keyCode = KeyLookup::GetDaliKeyCode( keyEvent->keyname);
497 keyCode = (keyCode == -1) ? 0 : keyCode;
498 int modifier( keyEvent->modifiers );
499 unsigned long time = keyEvent->timestamp;
500 if (!strncmp(keyEvent->keyname, "Keycode-", 8))
501 keyCode = atoi(keyEvent->keyname + 8);
503 // Ensure key event string is not NULL as keys like SHIFT have a null string.
504 if ( keyEvent->string )
506 keyString = keyEvent->string;
509 KeyEvent keyEvent(keyName, keyString, keyCode, modifier, time, KeyEvent::Up);
510 handler->SendEvent( keyEvent );
514 return ECORE_CALLBACK_PASS_ON;
517 /////////////////////////////////////////////////////////////////////////////////////////////////
519 /////////////////////////////////////////////////////////////////////////////////////////////////
522 * Called when the window gains focus.
524 static Eina_Bool EcoreEventWindowFocusIn( void* data, int type, void* event )
526 Ecore_Wl_Event_Focus_In* focusInEvent( (Ecore_Wl_Event_Focus_In*)event );
527 EventHandler* handler( (EventHandler*)data );
529 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventWindowFocusIn \n" );
531 // If the window gains focus and we hid the keyboard then show it again.
532 if ( focusInEvent->win == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
534 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT EcoreEventWindowFocusIn - >>WindowFocusGained \n" );
536 if ( ImfManager::IsAvailable() /* Only get the ImfManager if it's available as we do not want to create it */ )
538 Dali::ImfManager imfManager( ImfManager::Get() );
541 ImfManager& imfManagerImpl( ImfManager::GetImplementation( imfManager ) );
542 if( imfManagerImpl.RestoreAfterFocusLost() )
544 imfManagerImpl.Activate();
548 Dali::Clipboard clipboard = Clipboard::Get();
549 clipboard.HideClipboard();
552 return ECORE_CALLBACK_PASS_ON;
556 * Called when the window loses focus.
558 static Eina_Bool EcoreEventWindowFocusOut( void* data, int type, void* event )
560 Ecore_Wl_Event_Focus_Out* focusOutEvent( (Ecore_Wl_Event_Focus_Out*)event );
561 EventHandler* handler( (EventHandler*)data );
563 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventWindowFocusOut \n" );
565 // If the window loses focus then hide the keyboard.
566 if ( focusOutEvent->win == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
568 if ( ImfManager::IsAvailable() /* Only get the ImfManager if it's available as we do not want to create it */ )
570 Dali::ImfManager imfManager( ImfManager::Get() );
573 ImfManager& imfManagerImpl( ImfManager::GetImplementation( imfManager ) );
574 if( imfManagerImpl.RestoreAfterFocusLost() )
576 imfManagerImpl.Deactivate();
581 // Hiding clipboard event will be ignored once because window focus out event is always received on showing clipboard
582 Dali::Clipboard clipboard = Clipboard::Get();
585 Clipboard& clipBoardImpl( GetImplementation( clipboard ) );
586 clipBoardImpl.HideClipboard(true);
590 return ECORE_CALLBACK_PASS_ON;
594 * Called when the window is damaged.
596 static Eina_Bool EcoreEventWindowDamaged(void *data, int type, void *event)
598 return ECORE_CALLBACK_PASS_ON;
602 * Called when the window properties are changed.
603 * We are only interested in the font change.
607 /////////////////////////////////////////////////////////////////////////////////////////////////
608 // Drag & Drop Callbacks
609 /////////////////////////////////////////////////////////////////////////////////////////////////
612 * Called when a dragged item enters our window's bounds.
613 * This is when items are dragged INTO our window.
615 static Eina_Bool EcoreEventDndEnter( void* data, int type, void* event )
617 DALI_LOG_INFO( gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndEnter\n" );
619 return ECORE_CALLBACK_PASS_ON;
623 * Called when a dragged item is moved within our window.
624 * This is when items are dragged INTO our window.
626 static Eina_Bool EcoreEventDndPosition( void* data, int type, void* event )
628 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndPosition\n" );
630 return ECORE_CALLBACK_PASS_ON;
634 * Called when a dragged item leaves our window's bounds.
635 * This is when items are dragged INTO our window.
637 static Eina_Bool EcoreEventDndLeave( void* data, int type, void* event )
639 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndLeave\n" );
641 return ECORE_CALLBACK_PASS_ON;
645 * Called when the dragged item is dropped within our window's bounds.
646 * This is when items are dragged INTO our window.
648 static Eina_Bool EcoreEventDndDrop( void* data, int type, void* event )
650 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndDrop\n" );
652 return ECORE_CALLBACK_PASS_ON;
656 * Called when a dragged item is moved from our window and the target window has done processing it.
657 * This is when items are dragged FROM our window.
659 static Eina_Bool EcoreEventDndFinished( void* data, int type, void* event )
661 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndFinished\n" );
662 return ECORE_CALLBACK_PASS_ON;
666 * Called when a dragged item is moved from our window and the target window has sent us a status.
667 * This is when items are dragged FROM our window.
669 static Eina_Bool EcoreEventDndStatus( void* data, int type, void* event )
671 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndStatus\n" );
672 return ECORE_CALLBACK_PASS_ON;
676 * Called when the client messages (i.e. the accessibility events) are received.
678 static Eina_Bool EcoreEventClientMessage( void* data, int type, void* event )
680 return ECORE_CALLBACK_PASS_ON;
684 /////////////////////////////////////////////////////////////////////////////////////////////////
685 // ElDBus Accessibility Callbacks
686 /////////////////////////////////////////////////////////////////////////////////////////////////
688 #ifdef DALI_ELDBUS_AVAILABLE
689 // Callback for Ecore ElDBus accessibility events.
690 static void OnEcoreElDBusAccessibilityNotification( void *context EINA_UNUSED, const Eldbus_Message *message )
692 EventHandler* handler = static_cast< EventHandler* >( context );
693 // Ignore any accessibility events when paused.
694 if( handler->mPaused )
699 if( !handler->mAccessibilityAdaptor )
701 DALI_LOG_ERROR( "Invalid accessibility adaptor\n" );
705 AccessibilityAdaptor* accessibilityAdaptor( &AccessibilityAdaptor::GetImplementation( handler->mAccessibilityAdaptor ) );
706 if( !accessibilityAdaptor )
708 DALI_LOG_ERROR( "Cannot access accessibility adaptor\n" );
714 int state; // 0 - begin, 1 - ongoing, 2 - ended, 3 - aborted
717 // The string defines the arg-list's respective types.
718 if( !eldbus_message_arguments_get( message, "iiiiiiu", &gestureValue, &xS, &yS, &xE, &yE, &state, &eventTime ) )
720 DALI_LOG_ERROR( "OnEcoreElDBusAccessibilityNotification: Error getting arguments\n" );
723 DALI_LOG_INFO( gImfLogging, Debug::General, "Got gesture: Name: %d Args: %d,%d,%d,%d State: %d\n", gestureValue, xS, yS, xE, yE );
725 // Create a touch point object.
726 TouchPoint::State touchPointState( TouchPoint::Down );
729 touchPointState = TouchPoint::Down; // Mouse down.
731 else if( state == 1 )
733 touchPointState = TouchPoint::Motion; // Mouse move.
735 else if( state == 2 )
737 touchPointState = TouchPoint::Up; // Mouse up.
741 touchPointState = TouchPoint::Interrupted; // Error.
744 // Send touch event to accessibility adaptor.
745 TouchPoint point( 0, touchPointState, (float)xS, (float)yS );
747 // Perform actions based on received gestures.
748 // Note: This is seperated from the reading so we can have other input readers without changing the below code.
749 switch( gestureValue )
751 case 0: // OneFingerHover
754 accessibilityAdaptor->HandleActionReadEvent( (unsigned int)xS, (unsigned int)yS, true /* allow read again */ );
757 case 1: // TwoFingersHover
759 // In accessibility mode, scroll action should be handled when the currently focused actor is contained in scrollable control
760 accessibilityAdaptor->HandleActionScrollEvent( point, GetCurrentMilliSeconds() );
763 case 2: // ThreeFingersHover
765 // Read from top item on screen continuously.
766 accessibilityAdaptor->HandleActionReadFromTopEvent();
769 case 3: // OneFingerFlickLeft
771 // Move to previous item.
772 accessibilityAdaptor->HandleActionReadPreviousEvent();
775 case 4: // OneFingerFlickRight
777 // Move to next item.
778 accessibilityAdaptor->HandleActionReadNextEvent();
781 case 5: // OneFingerFlickUp
783 // Move to previous item.
784 accessibilityAdaptor->HandleActionPreviousEvent();
787 case 6: // OneFingerFlickDown
789 // Move to next item.
790 accessibilityAdaptor->HandleActionNextEvent();
793 case 7: // TwoFingersFlickUp
795 // Scroll up the list.
796 accessibilityAdaptor->HandleActionScrollUpEvent();
799 case 8: // TwoFingersFlickDown
801 // Scroll down the list.
802 accessibilityAdaptor->HandleActionScrollDownEvent();
805 case 9: // TwoFingersFlickLeft
807 // Scroll left to the previous page
808 accessibilityAdaptor->HandleActionPageLeftEvent();
811 case 10: // TwoFingersFlickRight
813 // Scroll right to the next page
814 accessibilityAdaptor->HandleActionPageRightEvent();
817 case 11: // ThreeFingersFlickLeft
822 case 12: // ThreeFingersFlickRight
827 case 13: // ThreeFingersFlickUp
832 case 14: // ThreeFingersFlickDown
837 case 15: // OneFingerSingleTap
840 accessibilityAdaptor->HandleActionReadEvent( (unsigned int)xS, (unsigned int)yS, true /* allow read again */ );
843 case 16: // OneFingerDoubleTap
845 // Activate selected item / active edit mode.
846 accessibilityAdaptor->HandleActionActivateEvent();
849 case 17: // OneFingerTripleTap
852 accessibilityAdaptor->HandleActionZoomEvent();
855 case 18: // TwoFingersSingleTap
857 // Pause/Resume current speech
858 accessibilityAdaptor->HandleActionReadPauseResumeEvent();
861 case 19: // TwoFingersDoubleTap
863 // Start/Stop current action
864 accessibilityAdaptor->HandleActionStartStopEvent();
867 case 20: // TwoFingersTripleTap
869 // Read information from indicator
870 accessibilityAdaptor->HandleActionReadIndicatorInformationEvent();
873 case 21: // ThreeFingersSingleTap
875 // Read from top item on screen continuously.
876 accessibilityAdaptor->HandleActionReadFromTopEvent();
879 case 22: // ThreeFingersDoubleTap
881 // Read from next item continuously.
882 accessibilityAdaptor->HandleActionReadFromNextEvent();
885 case 23: // ThreeFingersTripleTap
890 case 24: // OneFingerFlickLeftReturn
892 // Scroll up to the previous page
893 accessibilityAdaptor->HandleActionPageUpEvent();
896 case 25: // OneFingerFlickRightReturn
898 // Scroll down to the next page
899 accessibilityAdaptor->HandleActionPageDownEvent();
902 case 26: // OneFingerFlickUpReturn
904 // Move to the first item on screen
905 accessibilityAdaptor->HandleActionMoveToFirstEvent();
908 case 27: // OneFingerFlickDownReturn
910 // Move to the last item on screen
911 accessibilityAdaptor->HandleActionMoveToLastEvent();
914 case 28: // TwoFingersFlickLeftReturn
919 case 29: // TwoFingersFlickRightReturn
924 case 30: // TwoFingersFlickUpReturn
929 case 31: // TwoFingersFlickDownReturn
934 case 32: // ThreeFingersFlickLeftReturn
939 case 33: // ThreeFingersFlickRightReturn
944 case 34: // ThreeFingersFlickUpReturn
949 case 35: // ThreeFingersFlickDownReturn
957 void EcoreElDBusInitialisation( void *handle )
959 Eldbus_Object *object;
960 Eldbus_Proxy *manager;
962 if( !( mSystemConnection = eldbus_connection_get(ELDBUS_CONNECTION_TYPE_SYSTEM) ) )
964 DALI_LOG_ERROR( "Unable to get system bus\n" );
967 object = eldbus_object_get( mSystemConnection, BUS, PATH );
970 DALI_LOG_ERROR( "Getting object failed\n" );
974 manager = eldbus_proxy_get( object, INTERFACE );
977 DALI_LOG_ERROR( "Getting proxy failed\n" );
981 if( !eldbus_proxy_signal_handler_add( manager, "GestureDetected", OnEcoreElDBusAccessibilityNotification, handle ) )
983 DALI_LOG_ERROR( "No signal handler returned\n" );
986 #endif // DALI_ELDBUS_AVAILABLE
989 * Called when the source window notifies us the content in clipboard is selected.
991 static Eina_Bool EcoreEventSelectionClear( void* data, int type, void* event )
993 DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventSelectionClear\n" );
994 return ECORE_CALLBACK_PASS_ON;
998 * Called when the source window sends us about the selected content.
999 * For example, when dragged items are dragged INTO our window or when items are selected in the clipboard.
1001 static Eina_Bool EcoreEventSelectionNotify( void* data, int type, void* event )
1003 DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventSelectionNotify\n" );
1004 return ECORE_CALLBACK_PASS_ON;
1008 * Called when the source window notifies us the content in clipboard is selected.
1010 static Eina_Bool EcoreEventDataSend( void* data, int type, void* event )
1012 DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventDataSend\n" );
1014 Dali::Clipboard clipboard = Clipboard::Get();
1017 Clipboard& clipBoardImpl( GetImplementation( clipboard ) );
1018 clipBoardImpl.ExcuteBuffered( true, event );
1020 return ECORE_CALLBACK_PASS_ON;
1024 * Called when the source window sends us about the selected content.
1025 * For example, when item is selected in the clipboard.
1027 static Eina_Bool EcoreEventDataReceive( void* data, int type, void* event )
1029 DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventDataReceive\n" );
1031 EventHandler* handler( (EventHandler*)data );
1032 Dali::Clipboard clipboard = Clipboard::Get();
1033 char *selectionData = NULL;
1036 Clipboard& clipBoardImpl( GetImplementation( clipboard ) );
1037 selectionData = clipBoardImpl.ExcuteBuffered( false, event );
1039 if ( selectionData && handler->mClipboardEventNotifier )
1041 ClipboardEventNotifier& clipboardEventNotifier( ClipboardEventNotifier::GetImplementation( handler->mClipboardEventNotifier ) );
1042 std::string content( selectionData, strlen(selectionData) );
1044 clipboardEventNotifier.SetContent( content );
1045 clipboardEventNotifier.EmitContentSelectedSignal();
1047 return ECORE_CALLBACK_PASS_ON;
1051 * Called when rotate event is recevied
1053 static Eina_Bool EcoreEventRotate( void* data, int type, void* event )
1055 DALI_LOG_INFO( gSelectionEventLogFilter, Debug::Concise, "EcoreEventRotate\n" );
1057 EventHandler* handler( (EventHandler*)data );
1058 Ecore_Wl_Event_Window_Rotate* ev( (Ecore_Wl_Event_Window_Rotate*)event );
1060 if( ev->win != (unsigned int)ecore_wl_window_id_get( handler->mImpl->mWindow ) )
1062 return ECORE_CALLBACK_PASS_ON;
1065 RotationEvent rotationEvent;
1066 rotationEvent.angle = ev->angle;
1067 rotationEvent.winResize = 0;
1068 rotationEvent.width = ev->w;
1069 rotationEvent.height = ev->h;
1070 handler->SendRotationPrepareEvent( rotationEvent );
1072 return ECORE_CALLBACK_PASS_ON;
1076 * Called when detent event is recevied
1078 static Eina_Bool EcoreEventDetent( void* data, int type, void* event )
1080 DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventDetent\n" );
1081 EventHandler* handler( (EventHandler*)data );
1082 Ecore_Event_Detent_Rotate *e((Ecore_Event_Detent_Rotate *)event);
1083 int direction = (e->direction == ECORE_DETENT_DIRECTION_CLOCKWISE) ? 1 : -1;
1084 int timeStamp = e->timestamp;
1086 WheelEvent wheelEvent( WheelEvent::CUSTOM_WHEEL, 0, 0, Vector2(0.0f, 0.0f), direction, timeStamp );
1087 handler->SendWheelEvent( wheelEvent );
1088 return ECORE_CALLBACK_PASS_ON;
1091 /////////////////////////////////////////////////////////////////////////////////////////////////
1093 /////////////////////////////////////////////////////////////////////////////////////////////////
1095 * Called when a font name is changed.
1097 static void VconfNotifyFontNameChanged( keynode_t* node, void* data )
1099 EventHandler* handler = static_cast<EventHandler*>( data );
1100 handler->SendEvent( StyleChange::DEFAULT_FONT_CHANGE );
1104 * Called when a font size is changed.
1106 static void VconfNotifyFontSizeChanged( keynode_t* node, void* data )
1108 EventHandler* handler = static_cast<EventHandler*>( data );
1109 handler->SendEvent( StyleChange::DEFAULT_FONT_SIZE_CHANGE );
1113 EventHandler* mHandler;
1114 std::vector<Ecore_Event_Handler*> mEcoreEventHandler;
1115 Ecore_Wl_Window* mWindow;
1116 #ifdef DALI_ELDBUS_AVAILABLE
1117 Eldbus_Connection* mSystemConnection;
1118 #endif // DALI_ELDBUS_AVAILABLE
1121 EventHandler::EventHandler( RenderSurface* surface, CoreEventInterface& coreEventInterface, GestureManager& gestureManager, DamageObserver& damageObserver, DragAndDropDetectorPtr dndDetector )
1122 : mCoreEventInterface( coreEventInterface ),
1123 mGestureManager( gestureManager ),
1124 mStyleMonitor( StyleMonitor::Get() ),
1125 mDamageObserver( damageObserver ),
1126 mRotationObserver( NULL ),
1127 mDragAndDropDetector( dndDetector ),
1128 mAccessibilityAdaptor( AccessibilityAdaptor::Get() ),
1129 mClipboardEventNotifier( ClipboardEventNotifier::Get() ),
1130 mClipboard( Clipboard::Get() ),
1134 Ecore_Wl_Window* window = 0;
1136 // this code only works with the Ecore RenderSurface so need to downcast
1137 ECore::WindowRenderSurface* ecoreSurface = dynamic_cast< ECore::WindowRenderSurface* >( surface );
1140 window = ecoreSurface->GetWlWindow();
1143 mImpl = new Impl(this, window);
1146 EventHandler::~EventHandler()
1153 mGestureManager.Stop();
1156 void EventHandler::SendEvent(Integration::Point& point, unsigned long timeStamp)
1160 timeStamp = GetCurrentMilliSeconds();
1163 Integration::TouchEvent touchEvent;
1164 Integration::HoverEvent hoverEvent;
1165 Integration::TouchEventCombiner::EventDispatchType type = mCombiner.GetNextTouchEvent(point, timeStamp, touchEvent, hoverEvent);
1166 if(type != Integration::TouchEventCombiner::DispatchNone )
1168 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);
1170 // First the touch and/or hover event & related gesture events are queued
1171 if(type == Integration::TouchEventCombiner::DispatchTouch || type == Integration::TouchEventCombiner::DispatchBoth)
1173 mCoreEventInterface.QueueCoreEvent( touchEvent );
1174 mGestureManager.SendEvent(touchEvent);
1177 if(type == Integration::TouchEventCombiner::DispatchHover || type == Integration::TouchEventCombiner::DispatchBoth)
1179 mCoreEventInterface.QueueCoreEvent( hoverEvent );
1182 // Next the events are processed with a single call into Core
1183 mCoreEventInterface.ProcessCoreEvents();
1187 void EventHandler::SendEvent(KeyEvent& keyEvent)
1189 Dali::PhysicalKeyboard physicalKeyboard = PhysicalKeyboard::Get();
1190 if ( physicalKeyboard )
1192 if ( ! KeyLookup::IsDeviceButton( keyEvent.keyPressedName.c_str() ) )
1194 GetImplementation( physicalKeyboard ).KeyReceived( keyEvent.time > 1 );
1198 // Create KeyEvent and send to Core.
1199 Integration::KeyEvent event(keyEvent.keyPressedName, keyEvent.keyPressed, keyEvent.keyCode,
1200 keyEvent.keyModifier, keyEvent.time, static_cast<Integration::KeyEvent::State>(keyEvent.state));
1201 mCoreEventInterface.QueueCoreEvent( event );
1202 mCoreEventInterface.ProcessCoreEvents();
1205 void EventHandler::SendWheelEvent( WheelEvent& wheelEvent )
1207 // Create WheelEvent and send to Core.
1208 Integration::WheelEvent event( static_cast< Integration::WheelEvent::Type >(wheelEvent.type), wheelEvent.direction, wheelEvent.modifiers, wheelEvent.point, wheelEvent.z, wheelEvent.timeStamp );
1209 mCoreEventInterface.QueueCoreEvent( event );
1210 mCoreEventInterface.ProcessCoreEvents();
1213 void EventHandler::SendEvent( StyleChange::Type styleChange )
1215 DALI_ASSERT_DEBUG( mStyleMonitor && "StyleMonitor Not Available" );
1216 GetImplementation( mStyleMonitor ).StyleChanged(styleChange);
1219 void EventHandler::SendEvent( const DamageArea& area )
1221 mDamageObserver.OnDamaged( area );
1224 void EventHandler::SendRotationPrepareEvent( const RotationEvent& event )
1226 if( mRotationObserver != NULL )
1228 mRotationObserver->OnRotationPrepare( event );
1229 mRotationObserver->OnRotationRequest();
1233 void EventHandler::SendRotationRequestEvent( )
1235 // No need to separate event into prepare and request in wayland
1238 void EventHandler::FeedTouchPoint( TouchPoint& point, int timeStamp)
1240 Integration::Point convertedPoint( point );
1241 SendEvent(convertedPoint, timeStamp);
1244 void EventHandler::FeedWheelEvent( WheelEvent& wheelEvent )
1246 SendWheelEvent( wheelEvent );
1249 void EventHandler::FeedKeyEvent( KeyEvent& event )
1254 void EventHandler::FeedEvent( Integration::Event& event )
1256 mCoreEventInterface.QueueCoreEvent( event );
1257 mCoreEventInterface.ProcessCoreEvents();
1260 void EventHandler::Reset()
1264 // Any touch listeners should be told of the interruption.
1265 Integration::TouchEvent event;
1266 Integration::Point point;
1267 point.SetState( PointState::INTERRUPTED );
1268 event.AddPoint( point );
1270 // First the touch event & related gesture events are queued
1271 mCoreEventInterface.QueueCoreEvent( event );
1272 mGestureManager.SendEvent( event );
1274 // Next the events are processed with a single call into Core
1275 mCoreEventInterface.ProcessCoreEvents();
1278 void EventHandler::Pause()
1284 void EventHandler::Resume()
1290 void EventHandler::SetDragAndDropDetector( DragAndDropDetectorPtr detector )
1292 mDragAndDropDetector = detector;
1295 void EventHandler::SetRotationObserver( RotationObserver* observer )
1297 mRotationObserver = observer;
1300 } // namespace Adaptor
1302 } // namespace Internal