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 #include <dali/public-api/common/vector-wrapper.h>
35 #include <dali/public-api/events/touch-point.h>
36 #include <dali/public-api/events/key-event.h>
37 #include <dali/public-api/events/wheel-event.h>
38 #include <dali/integration-api/debug.h>
39 #include <dali/integration-api/events/key-event-integ.h>
40 #include <dali/integration-api/events/touch-event-integ.h>
41 #include <dali/integration-api/events/hover-event-integ.h>
42 #include <dali/integration-api/events/wheel-event-integ.h>
45 #include <events/gesture-manager.h>
46 #include <window-render-surface.h>
47 #include <clipboard-impl.h>
49 #include <physical-keyboard-impl.h>
50 #include <style-monitor-impl.h>
51 #include <base/core-event-interface.h>
62 #if defined(DEBUG_ENABLED)
65 Integration::Log::Filter* gTouchEventLogFilter = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_TOUCH");
66 Integration::Log::Filter* gClientMessageLogFilter = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_CLIENT_MESSAGE");
67 Integration::Log::Filter* gDragAndDropLogFilter = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_DND");
68 Integration::Log::Filter* gImfLogging = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_IMF");
69 Integration::Log::Filter* gSelectionEventLogFilter = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_SELECTION");
70 } // unnamed namespace
76 const unsigned int PRIMARY_TOUCH_BUTTON_ID( 1 );
78 const unsigned int BYTES_PER_CHARACTER_FOR_ATTRIBUTES = 3;
81 * Ecore_Event_Modifier enums in Ecore_Input.h do not match Ecore_IMF_Keyboard_Modifiers in Ecore_IMF.h.
82 * This function converts from Ecore_Event_Modifier to Ecore_IMF_Keyboard_Modifiers enums.
83 * @param[in] ecoreModifier the Ecore_Event_Modifier input.
84 * @return the Ecore_IMF_Keyboard_Modifiers output.
86 Ecore_IMF_Keyboard_Modifiers EcoreInputModifierToEcoreIMFModifier(unsigned int ecoreModifier)
88 int modifier( ECORE_IMF_KEYBOARD_MODIFIER_NONE ); // If no other matches returns NONE.
91 if ( ecoreModifier & ECORE_EVENT_MODIFIER_SHIFT ) // enums from ecore_input/Ecore_Input.h
93 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_SHIFT; // enums from ecore_imf/ecore_imf.h
96 if ( ecoreModifier & ECORE_EVENT_MODIFIER_ALT )
98 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_ALT;
101 if ( ecoreModifier & ECORE_EVENT_MODIFIER_CTRL )
103 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_CTRL;
106 if ( ecoreModifier & ECORE_EVENT_MODIFIER_WIN )
108 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_WIN;
111 if ( ecoreModifier & ECORE_EVENT_MODIFIER_ALTGR )
113 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_ALTGR;
116 return static_cast<Ecore_IMF_Keyboard_Modifiers>( modifier );
120 // Copied from x server
121 static unsigned int GetCurrentMilliSeconds(void)
126 static clockid_t clockid;
130 #ifdef CLOCK_MONOTONIC_COARSE
131 if (clock_getres(CLOCK_MONOTONIC_COARSE, &tp) == 0 &&
132 (tp.tv_nsec / 1000) <= 1000 && clock_gettime(CLOCK_MONOTONIC_COARSE, &tp) == 0)
134 clockid = CLOCK_MONOTONIC_COARSE;
138 if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0)
140 clockid = CLOCK_MONOTONIC;
147 if (clockid != ~0L && clock_gettime(clockid, &tp) == 0)
149 return (tp.tv_sec * 1000) + (tp.tv_nsec / 1000000L);
152 gettimeofday(&tv, NULL);
153 return (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
156 #ifndef DALI_PROFILE_UBUNTU
157 const char * DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE = "db/setting/accessibility/font_name"; // It will be update at vconf-key.h and replaced.
158 #endif // DALI_PROFILE_UBUNTU
160 } // unnamed namespace
162 // Impl to hide EFL implementation.
163 struct EventHandler::Impl
165 // Construction & Destruction
170 Impl( EventHandler* handler, Ecore_Wl_Window* window )
171 : mHandler( handler ),
172 mEcoreEventHandler(),
175 // Only register for touch and key events if we have a window
178 // Register Touch events
179 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_BUTTON_DOWN, EcoreEventMouseButtonDown, handler ) );
180 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_BUTTON_UP, EcoreEventMouseButtonUp, handler ) );
181 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_MOVE, EcoreEventMouseButtonMove, handler ) );
182 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_OUT, EcoreEventMouseButtonUp, handler ) ); // process mouse out event like up event
184 // Register Mouse wheel events
185 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_WHEEL, EcoreEventMouseWheel, handler ) );
187 // Register Key events
188 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_KEY_DOWN, EcoreEventKeyDown, handler ) );
189 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_KEY_UP, EcoreEventKeyUp, handler ) );
191 #ifndef DALI_PROFILE_UBUNTU
192 // Register Vconf notify - font name and size
193 vconf_notify_key_changed( DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontNameChanged, handler );
194 vconf_notify_key_changed( VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontSizeChanged, handler );
195 #endif // DALI_PROFILE_UBUNTU
204 #ifndef DALI_PROFILE_UBUNTU
205 vconf_ignore_key_changed( VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontSizeChanged );
206 vconf_ignore_key_changed( DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontNameChanged );
207 #endif // DALI_PROFILE_UBUNTU
209 for( std::vector<Ecore_Event_Handler*>::iterator iter = mEcoreEventHandler.begin(), endIter = mEcoreEventHandler.end(); iter != endIter; ++iter )
211 ecore_event_handler_del( *iter );
217 /////////////////////////////////////////////////////////////////////////////////////////////////
219 /////////////////////////////////////////////////////////////////////////////////////////////////
222 * Called when a touch down is received.
224 static Eina_Bool EcoreEventMouseButtonDown( void* data, int type, void* event )
226 Ecore_Event_Mouse_Button *touchEvent( (Ecore_Event_Mouse_Button*)event );
227 EventHandler* handler( (EventHandler*)data );
229 if ( touchEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
231 PointState::Type state ( PointState::DOWN );
233 // Check if the buttons field is set and ensure it's the primary touch button.
234 // If this event was triggered by buttons other than the primary button (used for touch), then
235 // just send an interrupted event to Core.
236 if ( touchEvent->buttons && (touchEvent->buttons != PRIMARY_TOUCH_BUTTON_ID ) )
238 state = PointState::INTERRUPTED;
241 Integration::Point point;
242 point.SetDeviceId( touchEvent->multi.device );
243 point.SetState( state );
244 point.SetScreenPosition( Vector2( touchEvent->x, touchEvent->y ) );
245 point.SetRadius( touchEvent->multi.radius, Vector2( touchEvent->multi.radius_x, touchEvent->multi.radius_y ) );
246 point.SetPressure( touchEvent->multi.pressure );
247 point.SetAngle( Degree( touchEvent->multi.angle ) );
248 handler->SendEvent( point, touchEvent->timestamp );
251 return ECORE_CALLBACK_PASS_ON;
255 * Called when a touch up is received.
257 static Eina_Bool EcoreEventMouseButtonUp( void* data, int type, void* event )
259 Ecore_Event_Mouse_Button *touchEvent( (Ecore_Event_Mouse_Button*)event );
260 EventHandler* handler( (EventHandler*)data );
262 if ( touchEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
264 Integration::Point point;
265 point.SetDeviceId( touchEvent->multi.device );
266 point.SetState( PointState::UP );
267 point.SetScreenPosition( Vector2( touchEvent->x, touchEvent->y ) );
268 point.SetRadius( touchEvent->multi.radius, Vector2( touchEvent->multi.radius_x, touchEvent->multi.radius_y ) );
269 point.SetPressure( touchEvent->multi.pressure );
270 point.SetAngle( Degree( touchEvent->multi.angle ) );
271 handler->SendEvent( point, touchEvent->timestamp );
274 return ECORE_CALLBACK_PASS_ON;
278 * Called when a touch up is received.
280 static Eina_Bool EcoreEventMouseWheel( void* data, int type, void* event )
282 Ecore_Event_Mouse_Wheel *mouseWheelEvent( (Ecore_Event_Mouse_Wheel*)event );
284 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);
286 EventHandler* handler( (EventHandler*)data );
287 if ( mouseWheelEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
289 WheelEvent wheelEvent( WheelEvent::MOUSE_WHEEL, mouseWheelEvent->direction, mouseWheelEvent->modifiers, Vector2(mouseWheelEvent->x, mouseWheelEvent->y), mouseWheelEvent->z, mouseWheelEvent->timestamp );
290 handler->SendWheelEvent( wheelEvent );
292 return ECORE_CALLBACK_PASS_ON;
296 * Called when a touch motion is received.
298 static Eina_Bool EcoreEventMouseButtonMove( void* data, int type, void* event )
300 Ecore_Event_Mouse_Move *touchEvent( (Ecore_Event_Mouse_Move*)event );
301 EventHandler* handler( (EventHandler*)data );
303 if ( touchEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
305 Integration::Point point;
306 point.SetDeviceId( touchEvent->multi.device );
307 point.SetState( PointState::MOTION );
308 point.SetScreenPosition( Vector2( touchEvent->x, touchEvent->y ) );
309 point.SetRadius( touchEvent->multi.radius, Vector2( touchEvent->multi.radius_x, touchEvent->multi.radius_y ) );
310 point.SetPressure( touchEvent->multi.pressure );
311 point.SetAngle( Degree( touchEvent->multi.angle ) );
312 handler->SendEvent( point, touchEvent->timestamp );
315 return ECORE_CALLBACK_PASS_ON;
318 /////////////////////////////////////////////////////////////////////////////////////////////////
320 /////////////////////////////////////////////////////////////////////////////////////////////////
323 * Called when a key down is received.
325 static Eina_Bool EcoreEventKeyDown( void* data, int type, void* event )
327 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventKeyDown \n" );
329 EventHandler* handler( (EventHandler*)data );
330 Ecore_Event_Key *keyEvent( (Ecore_Event_Key*)event );
331 bool eventHandled( false );
333 // If a device key then skip ecore_imf_context_filter_event.
334 if ( ! KeyLookup::IsDeviceButton( keyEvent->keyname ) )
336 Ecore_IMF_Context* imfContext = NULL;
337 Dali::ImfManager imfManager( ImfManager::Get() );
340 imfContext = ImfManager::GetImplementation( imfManager ).GetContext();
345 // We're consuming key down event so we have to pass to IMF so that it can parse it as well.
346 Ecore_IMF_Event_Key_Down ecoreKeyDownEvent;
347 ecoreKeyDownEvent.keyname = keyEvent->keyname;
348 ecoreKeyDownEvent.key = keyEvent->key;
349 ecoreKeyDownEvent.string = keyEvent->string;
350 ecoreKeyDownEvent.compose = keyEvent->compose;
351 ecoreKeyDownEvent.timestamp = keyEvent->timestamp;
352 ecoreKeyDownEvent.modifiers = EcoreInputModifierToEcoreIMFModifier ( keyEvent->modifiers );
353 ecoreKeyDownEvent.locks = (Ecore_IMF_Keyboard_Locks) ECORE_IMF_KEYBOARD_LOCK_NONE;
355 eventHandled = ecore_imf_context_filter_event( imfContext,
356 ECORE_IMF_EVENT_KEY_DOWN,
357 (Ecore_IMF_Event *) &ecoreKeyDownEvent );
359 // If the event has not been handled by IMF then check if we should reset our IMF context
362 if ( !strcmp( keyEvent->keyname, "Escape" ) ||
363 !strcmp( keyEvent->keyname, "Return" ) ||
364 !strcmp( keyEvent->keyname, "KP_Enter" ) )
366 ecore_imf_context_reset( imfContext );
372 // If the event wasn't handled then we should send a key event.
375 if ( keyEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
377 std::string keyName( keyEvent->keyname );
378 std::string keyString( "" );
379 int keyCode = 0/*ecore_x_keysym_keycode_get(keyEvent->keyname)*/;
380 int modifier( keyEvent->modifiers );
381 unsigned long time = keyEvent->timestamp;
383 if (!strncmp(keyEvent->keyname, "Keycode-", 8))
384 keyCode = atoi(keyEvent->keyname + 8);
386 // Ensure key event string is not NULL as keys like SHIFT have a null string.
387 if ( keyEvent->string )
389 keyString = keyEvent->string;
392 KeyEvent keyEvent(keyName, keyString, keyCode, modifier, time, KeyEvent::Down);
393 handler->SendEvent( keyEvent );
397 return ECORE_CALLBACK_PASS_ON;
401 * Called when a key up is received.
403 static Eina_Bool EcoreEventKeyUp( void* data, int type, void* event )
405 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventKeyUp\n" );
407 EventHandler* handler( (EventHandler*)data );
408 Ecore_Event_Key *keyEvent( (Ecore_Event_Key*)event );
409 bool eventHandled( false );
411 // Device keys like Menu, home, back button must skip ecore_imf_context_filter_event.
412 if ( ! KeyLookup::IsDeviceButton( keyEvent->keyname ) )
414 Ecore_IMF_Context* imfContext = NULL;
415 Dali::ImfManager imfManager( ImfManager::Get() );
418 imfContext = ImfManager::GetImplementation( imfManager ).GetContext();
423 // We're consuming key up event so we have to pass to IMF so that it can parse it as well.
424 Ecore_IMF_Event_Key_Up ecoreKeyUpEvent;
425 ecoreKeyUpEvent.keyname = keyEvent->keyname;
426 ecoreKeyUpEvent.key = keyEvent->key;
427 ecoreKeyUpEvent.string = keyEvent->string;
428 ecoreKeyUpEvent.compose = keyEvent->compose;
429 ecoreKeyUpEvent.timestamp = keyEvent->timestamp;
430 ecoreKeyUpEvent.modifiers = EcoreInputModifierToEcoreIMFModifier ( keyEvent->modifiers );
431 ecoreKeyUpEvent.locks = (Ecore_IMF_Keyboard_Locks) ECORE_IMF_KEYBOARD_LOCK_NONE;
433 eventHandled = ecore_imf_context_filter_event( imfContext,
434 ECORE_IMF_EVENT_KEY_UP,
435 (Ecore_IMF_Event *) &ecoreKeyUpEvent );
439 // If the event wasn't handled then we should send a key event.
442 if ( keyEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
444 std::string keyName( keyEvent->keyname );
445 std::string keyString( "" );
446 int keyCode = 0/*ecore_x_keysym_keycode_get(keyEvent->keyname)*/;
447 int modifier( keyEvent->modifiers );
448 unsigned long time( keyEvent->timestamp );
450 if (!strncmp(keyEvent->keyname, "Keycode-", 8))
451 keyCode = atoi(keyEvent->keyname + 8);
453 // Ensure key event string is not NULL as keys like SHIFT have a null string.
454 if ( keyEvent->string )
456 keyString = keyEvent->string;
459 KeyEvent keyEvent(keyName, keyString, keyCode, modifier, time, KeyEvent::Up);
460 handler->SendEvent( keyEvent );
464 return ECORE_CALLBACK_PASS_ON;
467 /////////////////////////////////////////////////////////////////////////////////////////////////
469 /////////////////////////////////////////////////////////////////////////////////////////////////
472 * Called when the window gains focus.
474 static Eina_Bool EcoreEventWindowFocusIn( void* data, int type, void* event )
476 Ecore_Wl_Event_Focus_In* focusInEvent( (Ecore_Wl_Event_Focus_In*)event );
477 EventHandler* handler( (EventHandler*)data );
479 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventWindowFocusIn \n" );
481 // If the window gains focus and we hid the keyboard then show it again.
482 if ( focusInEvent->win == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
484 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT EcoreEventWindowFocusIn - >>WindowFocusGained \n" );
486 if ( ImfManager::IsAvailable() /* Only get the ImfManager if it's available as we do not want to create it */ )
488 Dali::ImfManager imfManager( ImfManager::Get() );
491 ImfManager& imfManagerImpl( ImfManager::GetImplementation( imfManager ) );
492 if( imfManagerImpl.RestoreAfterFocusLost() )
494 imfManagerImpl.Activate();
498 // No need to connect callbacks as KeyboardStatusChanged will be called.
501 return ECORE_CALLBACK_PASS_ON;
505 * Called when the window loses focus.
507 static Eina_Bool EcoreEventWindowFocusOut( void* data, int type, void* event )
509 Ecore_Wl_Event_Focus_Out* focusOutEvent( (Ecore_Wl_Event_Focus_Out*)event );
510 EventHandler* handler( (EventHandler*)data );
512 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventWindowFocusOut \n" );
514 // If the window loses focus then hide the keyboard.
515 if ( focusOutEvent->win == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
517 if ( ImfManager::IsAvailable() /* Only get the ImfManager if it's available as we do not want to create it */ )
519 Dali::ImfManager imfManager( ImfManager::Get() );
522 ImfManager& imfManagerImpl( ImfManager::GetImplementation( imfManager ) );
523 if( imfManagerImpl.RestoreAfterFocusLost() )
525 imfManagerImpl.Deactivate();
530 // Clipboard don't support that whether clipboard is shown or not. Hide clipboard.
531 Dali::Clipboard clipboard = Clipboard::Get();
532 clipboard.HideClipboard();
535 return ECORE_CALLBACK_PASS_ON;
539 * Called when the window is damaged.
541 static Eina_Bool EcoreEventWindowDamaged(void *data, int type, void *event)
543 return ECORE_CALLBACK_PASS_ON;
547 * Called when the window properties are changed.
548 * We are only interested in the font change.
552 /////////////////////////////////////////////////////////////////////////////////////////////////
553 // Drag & Drop Callbacks
554 /////////////////////////////////////////////////////////////////////////////////////////////////
557 * Called when a dragged item enters our window's bounds.
558 * This is when items are dragged INTO our window.
560 static Eina_Bool EcoreEventDndEnter( void* data, int type, void* event )
562 DALI_LOG_INFO( gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndEnter\n" );
564 return ECORE_CALLBACK_PASS_ON;
568 * Called when a dragged item is moved within our window.
569 * This is when items are dragged INTO our window.
571 static Eina_Bool EcoreEventDndPosition( void* data, int type, void* event )
573 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndPosition\n" );
575 return ECORE_CALLBACK_PASS_ON;
579 * Called when a dragged item leaves our window's bounds.
580 * This is when items are dragged INTO our window.
582 static Eina_Bool EcoreEventDndLeave( void* data, int type, void* event )
584 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndLeave\n" );
586 return ECORE_CALLBACK_PASS_ON;
590 * Called when the dragged item is dropped within our window's bounds.
591 * This is when items are dragged INTO our window.
593 static Eina_Bool EcoreEventDndDrop( void* data, int type, void* event )
595 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndDrop\n" );
597 return ECORE_CALLBACK_PASS_ON;
601 * Called when a dragged item is moved from our window and the target window has done processing it.
602 * This is when items are dragged FROM our window.
604 static Eina_Bool EcoreEventDndFinished( void* data, int type, void* event )
606 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndFinished\n" );
607 return ECORE_CALLBACK_PASS_ON;
611 * Called when a dragged item is moved from our window and the target window has sent us a status.
612 * This is when items are dragged FROM our window.
614 static Eina_Bool EcoreEventDndStatus( void* data, int type, void* event )
616 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndStatus\n" );
617 return ECORE_CALLBACK_PASS_ON;
621 * Called when the client messages (i.e. the accessibility events) are received.
623 static Eina_Bool EcoreEventClientMessage( void* data, int type, void* event )
625 return ECORE_CALLBACK_PASS_ON;
629 * Called when the source window notifies us the content in clipboard is selected.
631 static Eina_Bool EcoreEventSelectionClear( void* data, int type, void* event )
633 DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventSelectionClear\n" );
634 return ECORE_CALLBACK_PASS_ON;
638 * Called when the source window sends us about the selected content.
639 * For example, when dragged items are dragged INTO our window or when items are selected in the clipboard.
641 static Eina_Bool EcoreEventSelectionNotify( void* data, int type, void* event )
643 DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventSelectionNotify\n" );
644 return ECORE_CALLBACK_PASS_ON;
647 /////////////////////////////////////////////////////////////////////////////////////////////////
649 /////////////////////////////////////////////////////////////////////////////////////////////////
651 * Called when a font name is changed.
653 static void VconfNotifyFontNameChanged( keynode_t* node, void* data )
655 EventHandler* handler = static_cast<EventHandler*>( data );
656 handler->SendEvent( StyleChange::DEFAULT_FONT_CHANGE );
660 * Called when a font size is changed.
662 static void VconfNotifyFontSizeChanged( keynode_t* node, void* data )
664 EventHandler* handler = static_cast<EventHandler*>( data );
665 handler->SendEvent( StyleChange::DEFAULT_FONT_SIZE_CHANGE );
669 EventHandler* mHandler;
670 std::vector<Ecore_Event_Handler*> mEcoreEventHandler;
671 Ecore_Wl_Window* mWindow;
674 EventHandler::EventHandler( RenderSurface* surface, CoreEventInterface& coreEventInterface, GestureManager& gestureManager, DamageObserver& damageObserver, DragAndDropDetectorPtr dndDetector )
675 : mCoreEventInterface(coreEventInterface),
676 mGestureManager( gestureManager ),
677 mStyleMonitor( StyleMonitor::Get() ),
678 mDamageObserver( damageObserver ),
679 mRotationObserver( NULL ),
680 mDragAndDropDetector( dndDetector ),
681 mAccessibilityAdaptor( AccessibilityAdaptor::Get() ),
682 mClipboardEventNotifier( ClipboardEventNotifier::Get() ),
683 mClipboard(Clipboard::Get()),
686 Ecore_Wl_Window* window = 0;
688 // this code only works with the Ecore RenderSurface so need to downcast
689 ECore::WindowRenderSurface* ecoreSurface = dynamic_cast< ECore::WindowRenderSurface* >( surface );
692 window = ecoreSurface->GetWlWindow();
695 mImpl = new Impl(this, window);
698 EventHandler::~EventHandler()
705 mGestureManager.Stop();
708 void EventHandler::SendEvent(Integration::Point& point, unsigned long timeStamp)
712 timeStamp = GetCurrentMilliSeconds();
715 Integration::TouchEvent touchEvent;
716 Integration::HoverEvent hoverEvent;
717 Integration::TouchEventCombiner::EventDispatchType type = mCombiner.GetNextTouchEvent(point, timeStamp, touchEvent, hoverEvent);
718 if(type != Integration::TouchEventCombiner::DispatchNone )
720 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);
722 // First the touch and/or hover event & related gesture events are queued
723 if(type == Integration::TouchEventCombiner::DispatchTouch || type == Integration::TouchEventCombiner::DispatchBoth)
725 mCoreEventInterface.QueueCoreEvent( touchEvent );
726 mGestureManager.SendEvent(touchEvent);
729 if(type == Integration::TouchEventCombiner::DispatchHover || type == Integration::TouchEventCombiner::DispatchBoth)
731 mCoreEventInterface.QueueCoreEvent( hoverEvent );
734 // Next the events are processed with a single call into Core
735 mCoreEventInterface.ProcessCoreEvents();
739 void EventHandler::SendEvent(KeyEvent& keyEvent)
741 Dali::PhysicalKeyboard physicalKeyboard = PhysicalKeyboard::Get();
742 if ( physicalKeyboard )
744 if ( ! KeyLookup::IsDeviceButton( keyEvent.keyPressedName.c_str() ) )
746 GetImplementation( physicalKeyboard ).KeyReceived( keyEvent.time > 1 );
750 // Create KeyEvent and send to Core.
751 Integration::KeyEvent event(keyEvent.keyPressedName, keyEvent.keyPressed, keyEvent.keyCode,
752 keyEvent.keyModifier, keyEvent.time, static_cast<Integration::KeyEvent::State>(keyEvent.state));
753 mCoreEventInterface.QueueCoreEvent( event );
754 mCoreEventInterface.ProcessCoreEvents();
757 void EventHandler::SendWheelEvent( WheelEvent& wheelEvent )
759 // Create WheelEvent and send to Core.
760 Integration::WheelEvent event( static_cast< Integration::WheelEvent::Type >(wheelEvent.type), wheelEvent.direction, wheelEvent.modifiers, wheelEvent.point, wheelEvent.z, wheelEvent.timeStamp );
761 mCoreEventInterface.QueueCoreEvent( event );
762 mCoreEventInterface.ProcessCoreEvents();
765 void EventHandler::SendEvent( StyleChange::Type styleChange )
767 DALI_ASSERT_DEBUG( mStyleMonitor && "StyleMonitor Not Available" );
768 GetImplementation( mStyleMonitor ).StyleChanged(styleChange);
771 void EventHandler::SendEvent( const DamageArea& area )
773 mDamageObserver.OnDamaged( area );
776 void EventHandler::SendRotationPrepareEvent( const RotationEvent& event )
778 if( mRotationObserver != NULL )
780 mRotationObserver->OnRotationPrepare( event );
784 void EventHandler::SendRotationRequestEvent( )
786 if( mRotationObserver != NULL )
788 mRotationObserver->OnRotationRequest( );
792 void EventHandler::FeedTouchPoint( TouchPoint& point, int timeStamp)
794 Integration::Point convertedPoint( point );
795 SendEvent(convertedPoint, timeStamp);
798 void EventHandler::FeedWheelEvent( WheelEvent& wheelEvent )
800 SendWheelEvent( wheelEvent );
803 void EventHandler::FeedKeyEvent( KeyEvent& event )
808 void EventHandler::FeedEvent( Integration::Event& event )
810 mCoreEventInterface.QueueCoreEvent( event );
811 mCoreEventInterface.ProcessCoreEvents();
814 void EventHandler::Reset()
818 // Any touch listeners should be told of the interruption.
819 Integration::TouchEvent event;
820 Integration::Point point;
821 point.SetState( PointState::INTERRUPTED );
822 event.AddPoint( point );
824 // First the touch event & related gesture events are queued
825 mCoreEventInterface.QueueCoreEvent( event );
826 mGestureManager.SendEvent( event );
828 // Next the events are processed with a single call into Core
829 mCoreEventInterface.ProcessCoreEvents();
832 void EventHandler::Pause()
838 void EventHandler::Resume()
844 void EventHandler::SetDragAndDropDetector( DragAndDropDetectorPtr detector )
846 mDragAndDropDetector = detector;
849 void EventHandler::SetRotationObserver( RotationObserver* observer )
851 mRotationObserver = observer;
854 } // namespace Adaptor
856 } // namespace Internal