2 * Copyright (c) 2014 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/mouse-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/mouse-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 TouchPoint::State state ( TouchPoint::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 = TouchPoint::Interrupted;
241 TouchPoint point( touchEvent->multi.device, state, touchEvent->x, touchEvent->y );
242 handler->SendEvent( point, touchEvent->timestamp );
245 return ECORE_CALLBACK_PASS_ON;
249 * Called when a touch up is received.
251 static Eina_Bool EcoreEventMouseButtonUp( void* data, int type, void* event )
253 Ecore_Event_Mouse_Button *touchEvent( (Ecore_Event_Mouse_Button*)event );
254 EventHandler* handler( (EventHandler*)data );
256 if ( touchEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
258 TouchPoint point( touchEvent->multi.device, TouchPoint::Up, touchEvent->x, touchEvent->y );
259 handler->SendEvent( point, touchEvent->timestamp );
262 return ECORE_CALLBACK_PASS_ON;
266 * Called when a touch up is received.
268 static Eina_Bool EcoreEventMouseWheel( void* data, int type, void* event )
270 Ecore_Event_Mouse_Wheel *mouseWheelEvent( (Ecore_Event_Mouse_Wheel*)event );
272 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);
274 EventHandler* handler( (EventHandler*)data );
275 if ( mouseWheelEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
277 MouseWheelEvent wheelEvent(mouseWheelEvent->direction, mouseWheelEvent->modifiers, Vector2(mouseWheelEvent->x, mouseWheelEvent->y), mouseWheelEvent->z, mouseWheelEvent->timestamp);
278 handler->SendMouseWheelEvent( wheelEvent );
280 return ECORE_CALLBACK_PASS_ON;
284 * Called when a touch motion is received.
286 static Eina_Bool EcoreEventMouseButtonMove( void* data, int type, void* event )
288 Ecore_Event_Mouse_Move *touchEvent( (Ecore_Event_Mouse_Move*)event );
289 EventHandler* handler( (EventHandler*)data );
291 if ( touchEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
293 TouchPoint point( touchEvent->multi.device, TouchPoint::Motion, touchEvent->x, touchEvent->y );
294 handler->SendEvent( point, touchEvent->timestamp );
297 return ECORE_CALLBACK_PASS_ON;
300 /////////////////////////////////////////////////////////////////////////////////////////////////
302 /////////////////////////////////////////////////////////////////////////////////////////////////
305 * Called when a key down is received.
307 static Eina_Bool EcoreEventKeyDown( void* data, int type, void* event )
309 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventKeyDown \n" );
311 EventHandler* handler( (EventHandler*)data );
312 Ecore_Event_Key *keyEvent( (Ecore_Event_Key*)event );
313 bool eventHandled( false );
315 // If a device key then skip ecore_imf_context_filter_event.
316 if ( ! KeyLookup::IsDeviceButton( keyEvent->keyname ) )
318 Ecore_IMF_Context* imfContext = NULL;
319 Dali::ImfManager imfManager( ImfManager::Get() );
322 imfContext = reinterpret_cast<Ecore_IMF_Context*>( imfManager.GetContext() );
327 // We're consuming key down event so we have to pass to IMF so that it can parse it as well.
328 Ecore_IMF_Event_Key_Down ecoreKeyDownEvent;
329 ecoreKeyDownEvent.keyname = keyEvent->keyname;
330 ecoreKeyDownEvent.key = keyEvent->key;
331 ecoreKeyDownEvent.string = keyEvent->string;
332 ecoreKeyDownEvent.compose = keyEvent->compose;
333 ecoreKeyDownEvent.timestamp = keyEvent->timestamp;
334 ecoreKeyDownEvent.modifiers = EcoreInputModifierToEcoreIMFModifier ( keyEvent->modifiers );
335 ecoreKeyDownEvent.locks = (Ecore_IMF_Keyboard_Locks) ECORE_IMF_KEYBOARD_LOCK_NONE;
337 eventHandled = ecore_imf_context_filter_event( imfContext,
338 ECORE_IMF_EVENT_KEY_DOWN,
339 (Ecore_IMF_Event *) &ecoreKeyDownEvent );
341 // If the event has not been handled by IMF then check if we should reset our IMF context
344 if ( !strcmp( keyEvent->keyname, "Escape" ) ||
345 !strcmp( keyEvent->keyname, "Return" ) ||
346 !strcmp( keyEvent->keyname, "KP_Enter" ) )
348 ecore_imf_context_reset( imfContext );
354 // If the event wasn't handled then we should send a key event.
357 if ( keyEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
359 std::string keyName( keyEvent->keyname );
360 std::string keyString( "" );
361 int keyCode = 0/*ecore_x_keysym_keycode_get(keyEvent->keyname)*/;
362 int modifier( keyEvent->modifiers );
363 unsigned long time = keyEvent->timestamp;
365 if (!strncmp(keyEvent->keyname, "Keycode-", 8))
366 keyCode = atoi(keyEvent->keyname + 8);
368 // Ensure key event string is not NULL as keys like SHIFT have a null string.
369 if ( keyEvent->string )
371 keyString = keyEvent->string;
374 KeyEvent keyEvent(keyName, keyString, keyCode, modifier, time, KeyEvent::Down);
375 handler->SendEvent( keyEvent );
379 return ECORE_CALLBACK_PASS_ON;
383 * Called when a key up is received.
385 static Eina_Bool EcoreEventKeyUp( void* data, int type, void* event )
387 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventKeyUp \n" );
389 EventHandler* handler( (EventHandler*)data );
390 Ecore_Event_Key *keyEvent( (Ecore_Event_Key*)event );
391 bool eventHandled( false );
393 // XF86Stop and XF86Send must skip ecore_imf_context_filter_event.
394 if ( strcmp( keyEvent->keyname, "XF86Send" ) &&
395 strcmp( keyEvent->keyname, "XF86Phone" ) &&
396 strcmp( keyEvent->keyname, "XF86Stop" ) )
398 Ecore_IMF_Context* imfContext = NULL;
399 Dali::ImfManager imfManager( ImfManager::Get() );
402 imfContext = reinterpret_cast<Ecore_IMF_Context*>( imfManager.GetContext() );
407 // We're consuming key up event so we have to pass to IMF so that it can parse it as well.
408 Ecore_IMF_Event_Key_Up ecoreKeyUpEvent;
409 ecoreKeyUpEvent.keyname = keyEvent->keyname;
410 ecoreKeyUpEvent.key = keyEvent->key;
411 ecoreKeyUpEvent.string = keyEvent->string;
412 ecoreKeyUpEvent.compose = keyEvent->compose;
413 ecoreKeyUpEvent.timestamp = keyEvent->timestamp;
414 ecoreKeyUpEvent.modifiers = EcoreInputModifierToEcoreIMFModifier ( keyEvent->modifiers );
415 ecoreKeyUpEvent.locks = (Ecore_IMF_Keyboard_Locks) ECORE_IMF_KEYBOARD_LOCK_NONE;
417 eventHandled = ecore_imf_context_filter_event( imfContext,
418 ECORE_IMF_EVENT_KEY_UP,
419 (Ecore_IMF_Event *) &ecoreKeyUpEvent );
423 // If the event wasn't handled then we should send a key event.
426 if ( keyEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
428 std::string keyName( keyEvent->keyname );
429 std::string keyString( "" );
430 int keyCode = 0/*ecore_x_keysym_keycode_get(keyEvent->keyname)*/;
431 int modifier( keyEvent->modifiers );
432 unsigned long time( keyEvent->timestamp );
434 if (!strncmp(keyEvent->keyname, "Keycode-", 8))
435 keyCode = atoi(keyEvent->keyname + 8);
437 // Ensure key event string is not NULL as keys like SHIFT have a null string.
438 if ( keyEvent->string )
440 keyString = keyEvent->string;
443 KeyEvent keyEvent(keyName, keyString, keyCode, modifier, time, KeyEvent::Up);
444 handler->SendEvent( keyEvent );
448 return ECORE_CALLBACK_PASS_ON;
451 /////////////////////////////////////////////////////////////////////////////////////////////////
453 /////////////////////////////////////////////////////////////////////////////////////////////////
456 * Called when the window gains focus.
458 static Eina_Bool EcoreEventWindowFocusIn( void* data, int type, void* event )
460 Ecore_Wl_Event_Focus_In* focusInEvent( (Ecore_Wl_Event_Focus_In*)event );
461 EventHandler* handler( (EventHandler*)data );
463 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventWindowFocusIn \n" );
465 // If the window gains focus and we hid the keyboard then show it again.
466 if ( focusInEvent->win == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
468 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT EcoreEventWindowFocusIn - >>WindowFocusGained \n" );
470 if ( ImfManager::IsAvailable() /* Only get the ImfManager if it's available as we do not want to create it */ )
472 Dali::ImfManager imfManager( ImfManager::Get() );
475 ImfManager& imfManagerImpl( ImfManager::GetImplementation( imfManager ) );
476 if( imfManagerImpl.RestoreAfterFocusLost() )
478 imfManagerImpl.Activate();
482 // No need to connect callbacks as KeyboardStatusChanged will be called.
485 return ECORE_CALLBACK_PASS_ON;
489 * Called when the window loses focus.
491 static Eina_Bool EcoreEventWindowFocusOut( void* data, int type, void* event )
493 Ecore_Wl_Event_Focus_Out* focusOutEvent( (Ecore_Wl_Event_Focus_Out*)event );
494 EventHandler* handler( (EventHandler*)data );
496 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventWindowFocusOut \n" );
498 // If the window loses focus then hide the keyboard.
499 if ( focusOutEvent->win == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
501 if ( ImfManager::IsAvailable() /* Only get the ImfManager if it's available as we do not want to create it */ )
503 Dali::ImfManager imfManager( ImfManager::Get() );
506 ImfManager& imfManagerImpl( ImfManager::GetImplementation( imfManager ) );
507 if( imfManagerImpl.RestoreAfterFocusLost() )
509 imfManagerImpl.Deactivate();
514 // Clipboard don't support that whether clipboard is shown or not. Hide clipboard.
515 Dali::Clipboard clipboard = Clipboard::Get();
516 clipboard.HideClipboard();
519 return ECORE_CALLBACK_PASS_ON;
523 * Called when the window is damaged.
525 static Eina_Bool EcoreEventWindowDamaged(void *data, int type, void *event)
527 return ECORE_CALLBACK_PASS_ON;
531 * Called when the window properties are changed.
532 * We are only interested in the font change.
536 /////////////////////////////////////////////////////////////////////////////////////////////////
537 // Drag & Drop Callbacks
538 /////////////////////////////////////////////////////////////////////////////////////////////////
541 * Called when a dragged item enters our window's bounds.
542 * This is when items are dragged INTO our window.
544 static Eina_Bool EcoreEventDndEnter( void* data, int type, void* event )
546 DALI_LOG_INFO( gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndEnter\n" );
548 return ECORE_CALLBACK_PASS_ON;
552 * Called when a dragged item is moved within our window.
553 * This is when items are dragged INTO our window.
555 static Eina_Bool EcoreEventDndPosition( void* data, int type, void* event )
557 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndPosition\n" );
559 return ECORE_CALLBACK_PASS_ON;
563 * Called when a dragged item leaves our window's bounds.
564 * This is when items are dragged INTO our window.
566 static Eina_Bool EcoreEventDndLeave( void* data, int type, void* event )
568 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndLeave\n" );
570 return ECORE_CALLBACK_PASS_ON;
574 * Called when the dragged item is dropped within our window's bounds.
575 * This is when items are dragged INTO our window.
577 static Eina_Bool EcoreEventDndDrop( void* data, int type, void* event )
579 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndDrop\n" );
581 return ECORE_CALLBACK_PASS_ON;
585 * Called when a dragged item is moved from our window and the target window has done processing it.
586 * This is when items are dragged FROM our window.
588 static Eina_Bool EcoreEventDndFinished( void* data, int type, void* event )
590 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndFinished\n" );
591 return ECORE_CALLBACK_PASS_ON;
595 * Called when a dragged item is moved from our window and the target window has sent us a status.
596 * This is when items are dragged FROM our window.
598 static Eina_Bool EcoreEventDndStatus( void* data, int type, void* event )
600 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndStatus\n" );
601 return ECORE_CALLBACK_PASS_ON;
605 * Called when the client messages (i.e. the accessibility events) are received.
607 static Eina_Bool EcoreEventClientMessage( void* data, int type, void* event )
609 return ECORE_CALLBACK_PASS_ON;
613 * Called when the source window notifies us the content in clipboard is selected.
615 static Eina_Bool EcoreEventSelectionClear( void* data, int type, void* event )
617 DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventSelectionClear\n" );
618 return ECORE_CALLBACK_PASS_ON;
622 * Called when the source window sends us about the selected content.
623 * For example, when dragged items are dragged INTO our window or when items are selected in the clipboard.
625 static Eina_Bool EcoreEventSelectionNotify( void* data, int type, void* event )
627 DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventSelectionNotify\n" );
628 return ECORE_CALLBACK_PASS_ON;
631 /////////////////////////////////////////////////////////////////////////////////////////////////
633 /////////////////////////////////////////////////////////////////////////////////////////////////
635 * Called when a font name is changed.
637 static void VconfNotifyFontNameChanged( keynode_t* node, void* data )
639 EventHandler* handler = static_cast<EventHandler*>( data );
641 StyleChange fontChange;
642 fontChange.defaultFontChange = true;
644 handler->SendEvent( fontChange );
648 * Called when a font size is changed.
650 static void VconfNotifyFontSizeChanged( keynode_t* node, void* data )
652 EventHandler* handler = static_cast<EventHandler*>( data );
654 StyleChange fontChange;
655 fontChange.defaultFontSizeChange = true;
657 handler->SendEvent( fontChange );
661 EventHandler* mHandler;
662 std::vector<Ecore_Event_Handler*> mEcoreEventHandler;
663 Ecore_Wl_Window* mWindow;
666 EventHandler::EventHandler( RenderSurface* surface, CoreEventInterface& coreEventInterface, GestureManager& gestureManager, DamageObserver& damageObserver, DragAndDropDetectorPtr dndDetector )
667 : mCoreEventInterface(coreEventInterface),
668 mGestureManager( gestureManager ),
669 mStyleMonitor( StyleMonitor::Get() ),
670 mDamageObserver( damageObserver ),
671 mRotationObserver( NULL ),
672 mDragAndDropDetector( dndDetector ),
673 mAccessibilityManager( AccessibilityManager::Get() ),
674 mClipboardEventNotifier( ClipboardEventNotifier::Get() ),
675 mClipboard(Clipboard::Get()),
678 Ecore_Wl_Window* window = 0;
680 // this code only works with the Ecore RenderSurface so need to downcast
681 ECore::WindowRenderSurface* ecoreSurface = dynamic_cast< ECore::WindowRenderSurface* >( surface );
684 window = ecoreSurface->GetWlWindow();
687 mImpl = new Impl(this, window);
690 EventHandler::~EventHandler()
697 mGestureManager.Stop();
700 void EventHandler::SendEvent(TouchPoint& point, unsigned long timeStamp)
704 timeStamp = GetCurrentMilliSeconds();
707 Integration::TouchEvent touchEvent;
708 Integration::HoverEvent hoverEvent;
709 Integration::TouchEventCombiner::EventDispatchType type = mCombiner.GetNextTouchEvent(point, timeStamp, touchEvent, hoverEvent);
710 if(type != Integration::TouchEventCombiner::DispatchNone )
712 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);
714 // First the touch and/or hover event & related gesture events are queued
715 if(type == Integration::TouchEventCombiner::DispatchTouch || type == Integration::TouchEventCombiner::DispatchBoth)
717 mCoreEventInterface.QueueCoreEvent( touchEvent );
718 mGestureManager.SendEvent(touchEvent);
721 if(type == Integration::TouchEventCombiner::DispatchHover || type == Integration::TouchEventCombiner::DispatchBoth)
723 mCoreEventInterface.QueueCoreEvent( hoverEvent );
726 // Next the events are processed with a single call into Core
727 mCoreEventInterface.ProcessCoreEvents();
731 void EventHandler::SendEvent(KeyEvent& keyEvent)
733 Dali::PhysicalKeyboard physicalKeyboard = PhysicalKeyboard::Get();
734 if ( physicalKeyboard )
736 if ( ! KeyLookup::IsDeviceButton( keyEvent.keyPressedName.c_str() ) )
738 GetImplementation( physicalKeyboard ).KeyReceived( keyEvent.time > 1 );
742 // Create KeyEvent and send to Core.
743 Integration::KeyEvent event(keyEvent.keyPressedName, keyEvent.keyPressed, keyEvent.keyCode,
744 keyEvent.keyModifier, keyEvent.time, static_cast<Integration::KeyEvent::State>(keyEvent.state));
745 mCoreEventInterface.QueueCoreEvent( event );
746 mCoreEventInterface.ProcessCoreEvents();
749 void EventHandler::SendMouseWheelEvent( MouseWheelEvent& wheelEvent )
751 // Create MouseWheelEvent and send to Core.
752 Integration::MouseWheelEvent event(wheelEvent.direction, wheelEvent.modifiers, wheelEvent.point, wheelEvent.z, wheelEvent.timeStamp);
753 mCoreEventInterface.QueueCoreEvent( event );
754 mCoreEventInterface.ProcessCoreEvents();
757 void EventHandler::SendEvent(StyleChange styleChange)
759 DALI_ASSERT_DEBUG( mStyleMonitor && "StyleMonitor Not Available" );
760 GetImplementation( mStyleMonitor ).StyleChanged(styleChange);
763 void EventHandler::SendEvent( const DamageArea& area )
765 mDamageObserver.OnDamaged( area );
768 void EventHandler::SendRotationPrepareEvent( const RotationEvent& event )
770 if( mRotationObserver != NULL )
772 mRotationObserver->OnRotationPrepare( event );
776 void EventHandler::SendRotationRequestEvent( )
778 if( mRotationObserver != NULL )
780 mRotationObserver->OnRotationRequest( );
784 void EventHandler::FeedTouchPoint( TouchPoint& point, int timeStamp)
786 SendEvent(point, timeStamp);
789 void EventHandler::FeedWheelEvent( MouseWheelEvent& wheelEvent )
791 SendMouseWheelEvent( wheelEvent );
794 void EventHandler::FeedKeyEvent( KeyEvent& event )
799 void EventHandler::FeedEvent( Integration::Event& event )
801 mCoreEventInterface.QueueCoreEvent( event );
802 mCoreEventInterface.ProcessCoreEvents();
805 void EventHandler::Reset()
809 // Any touch listeners should be told of the interruption.
810 Integration::TouchEvent event;
811 TouchPoint point(0, TouchPoint::Interrupted, 0, 0);
812 event.AddPoint( point );
814 // First the touch event & related gesture events are queued
815 mCoreEventInterface.QueueCoreEvent( event );
816 mGestureManager.SendEvent( event );
818 // Next the events are processed with a single call into Core
819 mCoreEventInterface.ProcessCoreEvents();
822 void EventHandler::SetDragAndDropDetector( DragAndDropDetectorPtr detector )
824 mDragAndDropDetector = detector;
827 void EventHandler::SetRotationObserver( RotationObserver* observer )
829 mRotationObserver = observer;
832 } // namespace Adaptor
834 } // namespace Internal