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>
64 #if defined(DEBUG_ENABLED)
67 Integration::Log::Filter* gTouchEventLogFilter = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_TOUCH");
68 Integration::Log::Filter* gClientMessageLogFilter = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_CLIENT_MESSAGE");
69 Integration::Log::Filter* gDragAndDropLogFilter = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_DND");
70 Integration::Log::Filter* gImfLogging = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_IMF");
71 Integration::Log::Filter* gSelectionEventLogFilter = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_SELECTION");
72 } // unnamed namespace
78 const unsigned int PRIMARY_TOUCH_BUTTON_ID( 1 );
80 const unsigned int BYTES_PER_CHARACTER_FOR_ATTRIBUTES = 3;
83 * Ecore_Event_Modifier enums in Ecore_Input.h do not match Ecore_IMF_Keyboard_Modifiers in Ecore_IMF.h.
84 * This function converts from Ecore_Event_Modifier to Ecore_IMF_Keyboard_Modifiers enums.
85 * @param[in] ecoreModifier the Ecore_Event_Modifier input.
86 * @return the Ecore_IMF_Keyboard_Modifiers output.
88 Ecore_IMF_Keyboard_Modifiers EcoreInputModifierToEcoreIMFModifier(unsigned int ecoreModifier)
90 int modifier( ECORE_IMF_KEYBOARD_MODIFIER_NONE ); // If no other matches returns NONE.
93 if ( ecoreModifier & ECORE_EVENT_MODIFIER_SHIFT ) // enums from ecore_input/Ecore_Input.h
95 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_SHIFT; // enums from ecore_imf/ecore_imf.h
98 if ( ecoreModifier & ECORE_EVENT_MODIFIER_ALT )
100 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_ALT;
103 if ( ecoreModifier & ECORE_EVENT_MODIFIER_CTRL )
105 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_CTRL;
108 if ( ecoreModifier & ECORE_EVENT_MODIFIER_WIN )
110 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_WIN;
113 if ( ecoreModifier & ECORE_EVENT_MODIFIER_ALTGR )
115 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_ALTGR;
118 return static_cast<Ecore_IMF_Keyboard_Modifiers>( modifier );
122 // Copied from x server
123 static unsigned int GetCurrentMilliSeconds(void)
128 static clockid_t clockid;
132 #ifdef CLOCK_MONOTONIC_COARSE
133 if (clock_getres(CLOCK_MONOTONIC_COARSE, &tp) == 0 &&
134 (tp.tv_nsec / 1000) <= 1000 && clock_gettime(CLOCK_MONOTONIC_COARSE, &tp) == 0)
136 clockid = CLOCK_MONOTONIC_COARSE;
140 if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0)
142 clockid = CLOCK_MONOTONIC;
149 if (clockid != ~0L && clock_gettime(clockid, &tp) == 0)
151 return (tp.tv_sec * 1000) + (tp.tv_nsec / 1000000L);
154 gettimeofday(&tv, NULL);
155 return (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
158 #ifndef DALI_PROFILE_UBUNTU
159 const char * DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE = "db/setting/accessibility/font_name"; // It will be update at vconf-key.h and replaced.
160 #endif // DALI_PROFILE_UBUNTU
162 } // unnamed namespace
164 // Impl to hide EFL implementation.
165 struct EventHandler::Impl
167 // Construction & Destruction
172 Impl( EventHandler* handler, Ecore_Wl_Window* window )
173 : mHandler( handler ),
174 mEcoreEventHandler(),
177 // Only register for touch and key events if we have a window
180 // Register Touch events
181 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_BUTTON_DOWN, EcoreEventMouseButtonDown, handler ) );
182 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_BUTTON_UP, EcoreEventMouseButtonUp, handler ) );
183 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_MOVE, EcoreEventMouseButtonMove, handler ) );
184 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_OUT, EcoreEventMouseButtonUp, handler ) ); // process mouse out event like up event
186 // Register Mouse wheel events
187 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_WHEEL, EcoreEventMouseWheel, handler ) );
189 // Register Key events
190 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_KEY_DOWN, EcoreEventKeyDown, handler ) );
191 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_KEY_UP, EcoreEventKeyUp, handler ) );
193 #ifndef DALI_PROFILE_UBUNTU
194 // Register Vconf notify - font name and size
195 vconf_notify_key_changed( DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontNameChanged, handler );
196 vconf_notify_key_changed( VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontSizeChanged, handler );
197 #endif // DALI_PROFILE_UBUNTU
206 #ifndef DALI_PROFILE_UBUNTU
207 vconf_ignore_key_changed( VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontSizeChanged );
208 vconf_ignore_key_changed( DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontNameChanged );
209 #endif // DALI_PROFILE_UBUNTU
211 for( std::vector<Ecore_Event_Handler*>::iterator iter = mEcoreEventHandler.begin(), endIter = mEcoreEventHandler.end(); iter != endIter; ++iter )
213 ecore_event_handler_del( *iter );
219 /////////////////////////////////////////////////////////////////////////////////////////////////
221 /////////////////////////////////////////////////////////////////////////////////////////////////
224 * Called when a touch down is received.
226 static Eina_Bool EcoreEventMouseButtonDown( void* data, int type, void* event )
228 Ecore_Event_Mouse_Button *touchEvent( (Ecore_Event_Mouse_Button*)event );
229 EventHandler* handler( (EventHandler*)data );
231 if ( touchEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
233 TouchPoint::State state ( TouchPoint::Down );
235 // Check if the buttons field is set and ensure it's the primary touch button.
236 // If this event was triggered by buttons other than the primary button (used for touch), then
237 // just send an interrupted event to Core.
238 if ( touchEvent->buttons && (touchEvent->buttons != PRIMARY_TOUCH_BUTTON_ID ) )
240 state = TouchPoint::Interrupted;
243 TouchPoint point( touchEvent->multi.device, state, touchEvent->x, touchEvent->y );
244 handler->SendEvent( point, touchEvent->timestamp );
247 return ECORE_CALLBACK_PASS_ON;
251 * Called when a touch up is received.
253 static Eina_Bool EcoreEventMouseButtonUp( void* data, int type, void* event )
255 Ecore_Event_Mouse_Button *touchEvent( (Ecore_Event_Mouse_Button*)event );
256 EventHandler* handler( (EventHandler*)data );
258 if ( touchEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
260 TouchPoint point( touchEvent->multi.device, TouchPoint::Up, touchEvent->x, touchEvent->y );
261 handler->SendEvent( point, touchEvent->timestamp );
264 return ECORE_CALLBACK_PASS_ON;
268 * Called when a touch up is received.
270 static Eina_Bool EcoreEventMouseWheel( void* data, int type, void* event )
272 Ecore_Event_Mouse_Wheel *mouseWheelEvent( (Ecore_Event_Mouse_Wheel*)event );
274 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);
276 EventHandler* handler( (EventHandler*)data );
277 if ( mouseWheelEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
279 MouseWheelEvent wheelEvent(mouseWheelEvent->direction, mouseWheelEvent->modifiers, Vector2(mouseWheelEvent->x, mouseWheelEvent->y), mouseWheelEvent->z, mouseWheelEvent->timestamp);
280 handler->SendMouseWheelEvent( wheelEvent );
282 return ECORE_CALLBACK_PASS_ON;
286 * Called when a touch motion is received.
288 static Eina_Bool EcoreEventMouseButtonMove( void* data, int type, void* event )
290 Ecore_Event_Mouse_Move *touchEvent( (Ecore_Event_Mouse_Move*)event );
291 EventHandler* handler( (EventHandler*)data );
293 if ( touchEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
295 TouchPoint point( touchEvent->multi.device, TouchPoint::Motion, touchEvent->x, touchEvent->y );
296 handler->SendEvent( point, touchEvent->timestamp );
299 return ECORE_CALLBACK_PASS_ON;
302 /////////////////////////////////////////////////////////////////////////////////////////////////
304 /////////////////////////////////////////////////////////////////////////////////////////////////
307 * Called when a key down is received.
309 static Eina_Bool EcoreEventKeyDown( void* data, int type, void* event )
311 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventKeyDown \n" );
313 EventHandler* handler( (EventHandler*)data );
314 Ecore_Event_Key *keyEvent( (Ecore_Event_Key*)event );
315 bool eventHandled( false );
317 // If a device key then skip ecore_imf_context_filter_event.
318 if ( ! KeyLookup::IsDeviceButton( keyEvent->keyname ) )
320 Ecore_IMF_Context* imfContext = NULL;
321 Dali::ImfManager imfManager( ImfManager::Get() );
324 imfContext = reinterpret_cast<Ecore_IMF_Context*>( imfManager.GetContext() );
329 // We're consuming key down event so we have to pass to IMF so that it can parse it as well.
330 Ecore_IMF_Event_Key_Down ecoreKeyDownEvent;
331 ecoreKeyDownEvent.keyname = keyEvent->keyname;
332 ecoreKeyDownEvent.key = keyEvent->key;
333 ecoreKeyDownEvent.string = keyEvent->string;
334 ecoreKeyDownEvent.compose = keyEvent->compose;
335 ecoreKeyDownEvent.timestamp = keyEvent->timestamp;
336 ecoreKeyDownEvent.modifiers = EcoreInputModifierToEcoreIMFModifier ( keyEvent->modifiers );
337 ecoreKeyDownEvent.locks = (Ecore_IMF_Keyboard_Locks) ECORE_IMF_KEYBOARD_LOCK_NONE;
339 eventHandled = ecore_imf_context_filter_event( imfContext,
340 ECORE_IMF_EVENT_KEY_DOWN,
341 (Ecore_IMF_Event *) &ecoreKeyDownEvent );
343 // If the event has not been handled by IMF then check if we should reset our IMF context
346 if ( !strcmp( keyEvent->keyname, "Escape" ) ||
347 !strcmp( keyEvent->keyname, "Return" ) ||
348 !strcmp( keyEvent->keyname, "KP_Enter" ) )
350 ecore_imf_context_reset( imfContext );
356 // If the event wasn't handled then we should send a key event.
359 if ( keyEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
361 std::string keyName( keyEvent->keyname );
362 std::string keyString( "" );
363 int keyCode = 0/*ecore_x_keysym_keycode_get(keyEvent->keyname)*/;
364 int modifier( keyEvent->modifiers );
365 unsigned long time = keyEvent->timestamp;
367 if (!strncmp(keyEvent->keyname, "Keycode-", 8))
368 keyCode = atoi(keyEvent->keyname + 8);
370 // Ensure key event string is not NULL as keys like SHIFT have a null string.
371 if ( keyEvent->string )
373 keyString = keyEvent->string;
376 KeyEvent keyEvent(keyName, keyString, keyCode, modifier, time, KeyEvent::Down);
377 handler->SendEvent( keyEvent );
381 return ECORE_CALLBACK_PASS_ON;
385 * Called when a key up is received.
387 static Eina_Bool EcoreEventKeyUp( void* data, int type, void* event )
389 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventKeyUp \n" );
391 EventHandler* handler( (EventHandler*)data );
392 Ecore_Event_Key *keyEvent( (Ecore_Event_Key*)event );
393 bool eventHandled( false );
395 // XF86Stop and XF86Send must skip ecore_imf_context_filter_event.
396 if ( strcmp( keyEvent->keyname, "XF86Send" ) &&
397 strcmp( keyEvent->keyname, "XF86Phone" ) &&
398 strcmp( keyEvent->keyname, "XF86Stop" ) )
400 Ecore_IMF_Context* imfContext = NULL;
401 Dali::ImfManager imfManager( ImfManager::Get() );
404 imfContext = reinterpret_cast<Ecore_IMF_Context*>( imfManager.GetContext() );
409 // We're consuming key up event so we have to pass to IMF so that it can parse it as well.
410 Ecore_IMF_Event_Key_Up ecoreKeyUpEvent;
411 ecoreKeyUpEvent.keyname = keyEvent->keyname;
412 ecoreKeyUpEvent.key = keyEvent->key;
413 ecoreKeyUpEvent.string = keyEvent->string;
414 ecoreKeyUpEvent.compose = keyEvent->compose;
415 ecoreKeyUpEvent.timestamp = keyEvent->timestamp;
416 ecoreKeyUpEvent.modifiers = EcoreInputModifierToEcoreIMFModifier ( keyEvent->modifiers );
417 ecoreKeyUpEvent.locks = (Ecore_IMF_Keyboard_Locks) ECORE_IMF_KEYBOARD_LOCK_NONE;
419 eventHandled = ecore_imf_context_filter_event( imfContext,
420 ECORE_IMF_EVENT_KEY_UP,
421 (Ecore_IMF_Event *) &ecoreKeyUpEvent );
425 // If the event wasn't handled then we should send a key event.
428 if ( keyEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
430 std::string keyName( keyEvent->keyname );
431 std::string keyString( "" );
432 int keyCode = 0/*ecore_x_keysym_keycode_get(keyEvent->keyname)*/;
433 int modifier( keyEvent->modifiers );
434 unsigned long time( keyEvent->timestamp );
436 if (!strncmp(keyEvent->keyname, "Keycode-", 8))
437 keyCode = atoi(keyEvent->keyname + 8);
439 // Ensure key event string is not NULL as keys like SHIFT have a null string.
440 if ( keyEvent->string )
442 keyString = keyEvent->string;
445 KeyEvent keyEvent(keyName, keyString, keyCode, modifier, time, KeyEvent::Up);
446 handler->SendEvent( keyEvent );
450 return ECORE_CALLBACK_PASS_ON;
453 /////////////////////////////////////////////////////////////////////////////////////////////////
455 /////////////////////////////////////////////////////////////////////////////////////////////////
458 * Called when the window gains focus.
460 static Eina_Bool EcoreEventWindowFocusIn( void* data, int type, void* event )
462 Ecore_Wl_Event_Focus_In* focusInEvent( (Ecore_Wl_Event_Focus_In*)event );
463 EventHandler* handler( (EventHandler*)data );
465 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventWindowFocusIn \n" );
467 // If the window gains focus and we hid the keyboard then show it again.
468 if ( focusInEvent->win == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
470 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT EcoreEventWindowFocusIn - >>WindowFocusGained \n" );
472 if ( ImfManager::IsAvailable() /* Only get the ImfManager if it's available as we do not want to create it */ )
474 Dali::ImfManager imfManager( ImfManager::Get() );
477 ImfManager& imfManagerImpl( ImfManager::GetImplementation( imfManager ) );
478 if( imfManagerImpl.RestoreAfterFocusLost() )
480 imfManagerImpl.Activate();
484 // No need to connect callbacks as KeyboardStatusChanged will be called.
487 return ECORE_CALLBACK_PASS_ON;
491 * Called when the window loses focus.
493 static Eina_Bool EcoreEventWindowFocusOut( void* data, int type, void* event )
495 Ecore_Wl_Event_Focus_Out* focusOutEvent( (Ecore_Wl_Event_Focus_Out*)event );
496 EventHandler* handler( (EventHandler*)data );
498 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventWindowFocusOut \n" );
500 // If the window loses focus then hide the keyboard.
501 if ( focusOutEvent->win == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
503 if ( ImfManager::IsAvailable() /* Only get the ImfManager if it's available as we do not want to create it */ )
505 Dali::ImfManager imfManager( ImfManager::Get() );
508 ImfManager& imfManagerImpl( ImfManager::GetImplementation( imfManager ) );
509 if( imfManagerImpl.RestoreAfterFocusLost() )
511 imfManagerImpl.Deactivate();
516 // Clipboard don't support that whether clipboard is shown or not. Hide clipboard.
517 Dali::Clipboard clipboard = Clipboard::Get();
518 clipboard.HideClipboard();
521 return ECORE_CALLBACK_PASS_ON;
525 * Called when the window is damaged.
527 static Eina_Bool EcoreEventWindowDamaged(void *data, int type, void *event)
529 return ECORE_CALLBACK_PASS_ON;
533 * Called when the window properties are changed.
534 * We are only interested in the font change.
538 /////////////////////////////////////////////////////////////////////////////////////////////////
539 // Drag & Drop Callbacks
540 /////////////////////////////////////////////////////////////////////////////////////////////////
543 * Called when a dragged item enters our window's bounds.
544 * This is when items are dragged INTO our window.
546 static Eina_Bool EcoreEventDndEnter( void* data, int type, void* event )
548 DALI_LOG_INFO( gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndEnter\n" );
550 return ECORE_CALLBACK_PASS_ON;
554 * Called when a dragged item is moved within our window.
555 * This is when items are dragged INTO our window.
557 static Eina_Bool EcoreEventDndPosition( void* data, int type, void* event )
559 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndPosition\n" );
561 return ECORE_CALLBACK_PASS_ON;
565 * Called when a dragged item leaves our window's bounds.
566 * This is when items are dragged INTO our window.
568 static Eina_Bool EcoreEventDndLeave( void* data, int type, void* event )
570 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndLeave\n" );
572 return ECORE_CALLBACK_PASS_ON;
576 * Called when the dragged item is dropped within our window's bounds.
577 * This is when items are dragged INTO our window.
579 static Eina_Bool EcoreEventDndDrop( void* data, int type, void* event )
581 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndDrop\n" );
583 return ECORE_CALLBACK_PASS_ON;
587 * Called when a dragged item is moved from our window and the target window has done processing it.
588 * This is when items are dragged FROM our window.
590 static Eina_Bool EcoreEventDndFinished( void* data, int type, void* event )
592 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndFinished\n" );
593 return ECORE_CALLBACK_PASS_ON;
597 * Called when a dragged item is moved from our window and the target window has sent us a status.
598 * This is when items are dragged FROM our window.
600 static Eina_Bool EcoreEventDndStatus( void* data, int type, void* event )
602 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndStatus\n" );
603 return ECORE_CALLBACK_PASS_ON;
607 * Called when the client messages (i.e. the accessibility events) are received.
609 static Eina_Bool EcoreEventClientMessage( void* data, int type, void* event )
611 return ECORE_CALLBACK_PASS_ON;
615 * Called when the source window notifies us the content in clipboard is selected.
617 static Eina_Bool EcoreEventSelectionClear( void* data, int type, void* event )
619 DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventSelectionClear\n" );
620 return ECORE_CALLBACK_PASS_ON;
624 * Called when the source window sends us about the selected content.
625 * For example, when dragged items are dragged INTO our window or when items are selected in the clipboard.
627 static Eina_Bool EcoreEventSelectionNotify( void* data, int type, void* event )
629 DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventSelectionNotify\n" );
630 return ECORE_CALLBACK_PASS_ON;
633 /////////////////////////////////////////////////////////////////////////////////////////////////
635 /////////////////////////////////////////////////////////////////////////////////////////////////
637 * Called when a font name is changed.
639 static void VconfNotifyFontNameChanged( keynode_t* node, void* data )
641 EventHandler* handler = static_cast<EventHandler*>( data );
643 StyleChange fontChange;
644 fontChange.defaultFontChange = true;
646 handler->SendEvent( fontChange );
650 * Called when a font size is changed.
652 static void VconfNotifyFontSizeChanged( keynode_t* node, void* data )
654 EventHandler* handler = static_cast<EventHandler*>( data );
656 StyleChange fontChange;
657 fontChange.defaultFontSizeChange = true;
659 handler->SendEvent( fontChange );
663 EventHandler* mHandler;
664 std::vector<Ecore_Event_Handler*> mEcoreEventHandler;
665 Ecore_Wl_Window* mWindow;
668 EventHandler::EventHandler( RenderSurface* surface, CoreEventInterface& coreEventInterface, GestureManager& gestureManager, DamageObserver& damageObserver, DragAndDropDetectorPtr dndDetector )
669 : mCoreEventInterface(coreEventInterface),
670 mGestureManager( gestureManager ),
671 mStyleMonitor( StyleMonitor::Get() ),
672 mDamageObserver( damageObserver ),
673 mRotationObserver( NULL ),
674 mDragAndDropDetector( dndDetector ),
675 mAccessibilityManager( AccessibilityManager::Get() ),
676 mClipboardEventNotifier( ClipboardEventNotifier::Get() ),
677 mClipboard(Clipboard::Get()),
680 Ecore_Wl_Window* window = 0;
682 if( surface->GetType() == Dali::RenderSurface::WINDOW )
684 // this code only works with the Ecore RenderSurface so need to downcast
685 ECore::WindowRenderSurface* ecoreSurface = dynamic_cast< ECore::WindowRenderSurface* >( surface );
688 window = ecoreSurface->GetWlWindow();
692 mImpl = new Impl(this, window);
695 EventHandler::~EventHandler()
702 mGestureManager.Stop();
705 void EventHandler::SendEvent(TouchPoint& point, unsigned long timeStamp)
709 timeStamp = GetCurrentMilliSeconds();
712 Integration::TouchEvent touchEvent;
713 Integration::HoverEvent hoverEvent;
714 Integration::TouchEventCombiner::EventDispatchType type = mCombiner.GetNextTouchEvent(point, timeStamp, touchEvent, hoverEvent);
715 if(type != Integration::TouchEventCombiner::DispatchNone )
717 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);
719 // First the touch and/or hover event & related gesture events are queued
720 if(type == Integration::TouchEventCombiner::DispatchTouch || type == Integration::TouchEventCombiner::DispatchBoth)
722 mCoreEventInterface.QueueCoreEvent( touchEvent );
723 mGestureManager.SendEvent(touchEvent);
726 if(type == Integration::TouchEventCombiner::DispatchHover || type == Integration::TouchEventCombiner::DispatchBoth)
728 mCoreEventInterface.QueueCoreEvent( hoverEvent );
731 // Next the events are processed with a single call into Core
732 mCoreEventInterface.ProcessCoreEvents();
736 void EventHandler::SendEvent(KeyEvent& keyEvent)
738 Dali::PhysicalKeyboard physicalKeyboard = PhysicalKeyboard::Get();
739 if ( physicalKeyboard )
741 if ( ! KeyLookup::IsDeviceButton( keyEvent.keyPressedName.c_str() ) )
743 GetImplementation( physicalKeyboard ).KeyReceived( keyEvent.time > 1 );
747 // Create KeyEvent and send to Core.
748 Integration::KeyEvent event(keyEvent.keyPressedName, keyEvent.keyPressed, keyEvent.keyCode,
749 keyEvent.keyModifier, keyEvent.time, static_cast<Integration::KeyEvent::State>(keyEvent.state));
750 mCoreEventInterface.QueueCoreEvent( event );
751 mCoreEventInterface.ProcessCoreEvents();
754 void EventHandler::SendMouseWheelEvent( MouseWheelEvent& wheelEvent )
756 // Create MouseWheelEvent and send to Core.
757 Integration::MouseWheelEvent event(wheelEvent.direction, wheelEvent.modifiers, wheelEvent.point, wheelEvent.z, wheelEvent.timeStamp);
758 mCoreEventInterface.QueueCoreEvent( event );
759 mCoreEventInterface.ProcessCoreEvents();
762 void EventHandler::SendEvent(StyleChange styleChange)
764 DALI_ASSERT_DEBUG( mStyleMonitor && "StyleMonitor Not Available" );
765 GetImplementation( mStyleMonitor ).StyleChanged(styleChange);
768 void EventHandler::SendEvent( const DamageArea& area )
770 mDamageObserver.OnDamaged( area );
773 void EventHandler::SendRotationPrepareEvent( const RotationEvent& event )
775 if( mRotationObserver != NULL )
777 mRotationObserver->OnRotationPrepare( event );
781 void EventHandler::SendRotationRequestEvent( )
783 if( mRotationObserver != NULL )
785 mRotationObserver->OnRotationRequest( );
789 void EventHandler::FeedTouchPoint( TouchPoint& point, int timeStamp)
791 SendEvent(point, timeStamp);
794 void EventHandler::FeedWheelEvent( MouseWheelEvent& wheelEvent )
796 SendMouseWheelEvent( wheelEvent );
799 void EventHandler::FeedKeyEvent( KeyEvent& event )
804 void EventHandler::FeedEvent( Integration::Event& event )
806 mCoreEventInterface.QueueCoreEvent( event );
807 mCoreEventInterface.ProcessCoreEvents();
810 void EventHandler::Reset()
814 // Any touch listeners should be told of the interruption.
815 Integration::TouchEvent event;
816 TouchPoint point(0, TouchPoint::Interrupted, 0, 0);
817 event.AddPoint( point );
819 // First the touch event & related gesture events are queued
820 mCoreEventInterface.QueueCoreEvent( event );
821 mGestureManager.SendEvent( event );
823 // Next the events are processed with a single call into Core
824 mCoreEventInterface.ProcessCoreEvents();
827 void EventHandler::SetDragAndDropDetector( DragAndDropDetectorPtr detector )
829 mDragAndDropDetector = detector;
832 void EventHandler::SetRotationObserver( RotationObserver* observer )
834 mRotationObserver = observer;
837 } // namespace Adaptor
839 } // namespace Internal