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>
30 #include <vconf-keys.h>
32 #include <dali/public-api/common/vector-wrapper.h>
33 #include <dali/public-api/events/touch-point.h>
34 #include <dali/public-api/events/key-event.h>
35 #include <dali/public-api/events/mouse-wheel-event.h>
36 #include <dali/integration-api/debug.h>
37 #include <dali/integration-api/events/key-event-integ.h>
38 #include <dali/integration-api/events/touch-event-integ.h>
39 #include <dali/integration-api/events/mouse-wheel-event-integ.h>
42 #include <events/gesture-manager.h>
43 #include <window-render-surface.h>
44 #include <clipboard-impl.h>
46 #include <physical-keyboard-impl.h>
47 #include <style-monitor-impl.h>
48 #include <base/core-event-interface.h>
61 #if defined(DEBUG_ENABLED)
64 Integration::Log::Filter* gTouchEventLogFilter = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_TOUCH");
65 Integration::Log::Filter* gClientMessageLogFilter = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_CLIENT_MESSAGE");
66 Integration::Log::Filter* gDragAndDropLogFilter = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_DND");
67 Integration::Log::Filter* gImfLogging = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_IMF");
68 Integration::Log::Filter* gSelectionEventLogFilter = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_SELECTION");
69 } // unnamed namespace
75 // Currently this code is internal to dali/dali/internal/event/text/utf8.h but should be made Public and used from there instead.
76 size_t Utf8SequenceLength(const unsigned char leadByte)
80 if ((leadByte & 0x80) == 0 ) //ASCII character (lead bit zero)
84 else if (( leadByte & 0xe0 ) == 0xc0 ) //110x xxxx
88 else if (( leadByte & 0xf0 ) == 0xe0 ) //1110 xxxx
92 else if (( leadByte & 0xf8 ) == 0xf0 ) //1111 0xxx
98 DALI_LOG_WARNING("Unrecognized lead byte %c\n", leadByte);
104 const unsigned int PRIMARY_TOUCH_BUTTON_ID( 1 );
106 const unsigned int BYTES_PER_CHARACTER_FOR_ATTRIBUTES = 3;
109 * Ecore_Event_Modifier enums in Ecore_Input.h do not match Ecore_IMF_Keyboard_Modifiers in Ecore_IMF.h.
110 * This function converts from Ecore_Event_Modifier to Ecore_IMF_Keyboard_Modifiers enums.
111 * @param[in] ecoreModifier the Ecore_Event_Modifier input.
112 * @return the Ecore_IMF_Keyboard_Modifiers output.
114 Ecore_IMF_Keyboard_Modifiers EcoreInputModifierToEcoreIMFModifier(unsigned int ecoreModifier)
116 int modifier( ECORE_IMF_KEYBOARD_MODIFIER_NONE ); // If no other matches returns NONE.
119 if ( ecoreModifier & ECORE_EVENT_MODIFIER_SHIFT ) // enums from ecore_input/Ecore_Input.h
121 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_SHIFT; // enums from ecore_imf/ecore_imf.h
124 if ( ecoreModifier & ECORE_EVENT_MODIFIER_ALT )
126 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_ALT;
129 if ( ecoreModifier & ECORE_EVENT_MODIFIER_CTRL )
131 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_CTRL;
134 if ( ecoreModifier & ECORE_EVENT_MODIFIER_WIN )
136 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_WIN;
139 if ( ecoreModifier & ECORE_EVENT_MODIFIER_ALTGR )
141 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_ALTGR;
144 return static_cast<Ecore_IMF_Keyboard_Modifiers>( modifier );
148 // Copied from x server
149 static unsigned int GetCurrentMilliSeconds(void)
154 static clockid_t clockid;
158 #ifdef CLOCK_MONOTONIC_COARSE
159 if (clock_getres(CLOCK_MONOTONIC_COARSE, &tp) == 0 &&
160 (tp.tv_nsec / 1000) <= 1000 && clock_gettime(CLOCK_MONOTONIC_COARSE, &tp) == 0)
162 clockid = CLOCK_MONOTONIC_COARSE;
166 if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0)
168 clockid = CLOCK_MONOTONIC;
175 if (clockid != ~0L && clock_gettime(clockid, &tp) == 0)
177 return (tp.tv_sec * 1000) + (tp.tv_nsec / 1000000L);
180 gettimeofday(&tv, NULL);
181 return (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
184 const char * DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE = "db/setting/accessibility/font_name"; // It will be update at vconf-key.h and replaced.
186 } // unnamed namespace
188 // Impl to hide EFL implementation.
189 struct EventHandler::Impl
191 // Construction & Destruction
196 Impl( EventHandler* handler, Ecore_Wl_Window* window )
197 : mHandler( handler ),
198 mEcoreEventHandler(),
201 // Only register for touch and key events if we have a window
204 // Register Touch events
205 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_BUTTON_DOWN, EcoreEventMouseButtonDown, handler ) );
206 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_BUTTON_UP, EcoreEventMouseButtonUp, handler ) );
207 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_MOVE, EcoreEventMouseButtonMove, handler ) );
208 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_OUT, EcoreEventMouseButtonUp, handler ) ); // process mouse out event like up event
210 // Register Mouse wheel events
211 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_WHEEL, EcoreEventMouseWheel, handler ) );
213 // Register Key events
214 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_KEY_DOWN, EcoreEventKeyDown, handler ) );
215 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_KEY_UP, EcoreEventKeyUp, handler ) );
217 // Register Vconf notify - font name and size
218 vconf_notify_key_changed( DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontNameChanged, handler );
219 vconf_notify_key_changed( VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontSizeChanged, handler );
228 vconf_ignore_key_changed( VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontSizeChanged );
229 vconf_ignore_key_changed( DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontNameChanged );
231 for( std::vector<Ecore_Event_Handler*>::iterator iter = mEcoreEventHandler.begin(), endIter = mEcoreEventHandler.end(); iter != endIter; ++iter )
233 ecore_event_handler_del( *iter );
239 /////////////////////////////////////////////////////////////////////////////////////////////////
241 /////////////////////////////////////////////////////////////////////////////////////////////////
244 * Called when a touch down is received.
246 static Eina_Bool EcoreEventMouseButtonDown( void* data, int type, void* event )
248 Ecore_Event_Mouse_Button *touchEvent( (Ecore_Event_Mouse_Button*)event );
249 EventHandler* handler( (EventHandler*)data );
251 if ( touchEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
253 TouchPoint::State state ( TouchPoint::Down );
255 // Check if the buttons field is set and ensure it's the primary touch button.
256 // If this event was triggered by buttons other than the primary button (used for touch), then
257 // just send an interrupted event to Core.
258 if ( touchEvent->buttons && (touchEvent->buttons != PRIMARY_TOUCH_BUTTON_ID ) )
260 state = TouchPoint::Interrupted;
263 TouchPoint point( touchEvent->multi.device, state, touchEvent->x, touchEvent->y );
264 handler->SendEvent( point, touchEvent->timestamp );
267 return ECORE_CALLBACK_PASS_ON;
271 * Called when a touch up is received.
273 static Eina_Bool EcoreEventMouseButtonUp( void* data, int type, void* event )
275 Ecore_Event_Mouse_Button *touchEvent( (Ecore_Event_Mouse_Button*)event );
276 EventHandler* handler( (EventHandler*)data );
278 if ( touchEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
280 TouchPoint point( touchEvent->multi.device, TouchPoint::Up, touchEvent->x, touchEvent->y );
281 handler->SendEvent( point, touchEvent->timestamp );
284 return ECORE_CALLBACK_PASS_ON;
288 * Called when a touch up is received.
290 static Eina_Bool EcoreEventMouseWheel( void* data, int type, void* event )
292 Ecore_Event_Mouse_Wheel *mouseWheelEvent( (Ecore_Event_Mouse_Wheel*)event );
294 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);
296 EventHandler* handler( (EventHandler*)data );
297 if ( mouseWheelEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
299 MouseWheelEvent wheelEvent(mouseWheelEvent->direction, mouseWheelEvent->modifiers, Vector2(mouseWheelEvent->x, mouseWheelEvent->y), mouseWheelEvent->z, mouseWheelEvent->timestamp);
300 handler->SendMouseWheelEvent( wheelEvent );
302 return ECORE_CALLBACK_PASS_ON;
306 * Called when a touch motion is received.
308 static Eina_Bool EcoreEventMouseButtonMove( void* data, int type, void* event )
310 Ecore_Event_Mouse_Move *touchEvent( (Ecore_Event_Mouse_Move*)event );
311 EventHandler* handler( (EventHandler*)data );
313 if ( touchEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
315 TouchPoint point( touchEvent->multi.device, TouchPoint::Motion, touchEvent->x, touchEvent->y );
316 handler->SendEvent( point, touchEvent->timestamp );
319 return ECORE_CALLBACK_PASS_ON;
322 /////////////////////////////////////////////////////////////////////////////////////////////////
324 /////////////////////////////////////////////////////////////////////////////////////////////////
327 * Called when a key down is received.
329 static Eina_Bool EcoreEventKeyDown( void* data, int type, void* event )
331 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventKeyDown \n" );
333 EventHandler* handler( (EventHandler*)data );
334 Ecore_Event_Key *keyEvent( (Ecore_Event_Key*)event );
335 bool eventHandled( false );
337 Ecore_IMF_Context* imfContext = NULL;
338 if ( Dali::Adaptor::IsAvailable() && handler->mImfManager )
340 imfContext = reinterpret_cast<Ecore_IMF_Context*>( handler->mImfManager.GetContext() );
343 // If a device key then skip ecore_imf_context_filter_event.
344 if ( imfContext && !( KeyLookup::IsDeviceButton( keyEvent->keyname ) ) )
346 // We're consuming key down event so we have to pass to IMF so that it can parse it as well.
347 Ecore_IMF_Event_Key_Down ecoreKeyDownEvent;
348 ecoreKeyDownEvent.keyname = keyEvent->keyname;
349 ecoreKeyDownEvent.key = keyEvent->key;
350 ecoreKeyDownEvent.string = keyEvent->string;
351 ecoreKeyDownEvent.compose = keyEvent->compose;
352 ecoreKeyDownEvent.timestamp = keyEvent->timestamp;
353 ecoreKeyDownEvent.modifiers = EcoreInputModifierToEcoreIMFModifier ( keyEvent->modifiers );
354 ecoreKeyDownEvent.locks = (Ecore_IMF_Keyboard_Locks) ECORE_IMF_KEYBOARD_LOCK_NONE;
356 eventHandled = ecore_imf_context_filter_event( imfContext,
357 ECORE_IMF_EVENT_KEY_DOWN,
358 (Ecore_IMF_Event *) &ecoreKeyDownEvent );
360 // If the event has not been handled by IMF then check if we should reset our IMF context
363 if ( !strcmp( keyEvent->keyname, "Escape" ) ||
364 !strcmp( keyEvent->keyname, "Return" ) ||
365 !strcmp( keyEvent->keyname, "KP_Enter" ) )
367 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 Ecore_IMF_Context* imfContext = NULL;
412 if ( Dali::Adaptor::IsAvailable() && handler->mImfManager )
414 imfContext = reinterpret_cast<Ecore_IMF_Context*>( handler->mImfManager.GetContext() );
417 // XF86Stop and XF86Send must skip ecore_imf_context_filter_event.
418 if ( imfContext && strcmp( keyEvent->keyname, "XF86Send" ) && strcmp( keyEvent->keyname, "XF86Phone" ) && strcmp( keyEvent->keyname, "XF86Stop" ) )
421 // We're consuming key up event so we have to pass to IMF so that it can parse it as well.
422 Ecore_IMF_Event_Key_Up ecoreKeyUpEvent;
423 ecoreKeyUpEvent.keyname = keyEvent->keyname;
424 ecoreKeyUpEvent.key = keyEvent->key;
425 ecoreKeyUpEvent.string = keyEvent->string;
426 ecoreKeyUpEvent.compose = keyEvent->compose;
427 ecoreKeyUpEvent.timestamp = keyEvent->timestamp;
428 ecoreKeyUpEvent.modifiers = EcoreInputModifierToEcoreIMFModifier ( keyEvent->modifiers );
429 ecoreKeyUpEvent.locks = (Ecore_IMF_Keyboard_Locks) ECORE_IMF_KEYBOARD_LOCK_NONE;
431 eventHandled = ecore_imf_context_filter_event( imfContext,
432 ECORE_IMF_EVENT_KEY_UP,
433 (Ecore_IMF_Event *) &ecoreKeyUpEvent );
436 // If the event wasn't handled then we should send a key event.
439 if ( keyEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
441 std::string keyName( keyEvent->keyname );
442 std::string keyString( "" );
443 int keyCode = 0/*ecore_x_keysym_keycode_get(keyEvent->keyname)*/;
444 int modifier( keyEvent->modifiers );
445 unsigned long time( keyEvent->timestamp );
447 if (!strncmp(keyEvent->keyname, "Keycode-", 8))
448 keyCode = atoi(keyEvent->keyname + 8);
450 // Ensure key event string is not NULL as keys like SHIFT have a null string.
451 if ( keyEvent->string )
453 keyString = keyEvent->string;
456 KeyEvent keyEvent(keyName, keyString, keyCode, modifier, time, KeyEvent::Up);
457 handler->SendEvent( keyEvent );
461 return ECORE_CALLBACK_PASS_ON;
464 /////////////////////////////////////////////////////////////////////////////////////////////////
466 /////////////////////////////////////////////////////////////////////////////////////////////////
469 * Called when the window gains focus.
471 static Eina_Bool EcoreEventWindowFocusIn( void* data, int type, void* event )
473 Ecore_Wl_Event_Focus_In* focusInEvent( (Ecore_Wl_Event_Focus_In*)event );
474 EventHandler* handler( (EventHandler*)data );
476 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventWindowFocusIn \n" );
478 // If the window gains focus and we hid the keyboard then show it again.
479 if ( focusInEvent->win == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
481 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT EcoreEventWindowFocusIn - >>WindowFocusGained \n" );
483 if ( handler->mImfManager )
485 ImfManager& imfManager( ImfManager::GetImplementation( handler->mImfManager ) );
486 if( imfManager.RestoreAfterFocusLost() )
488 imfManager.Activate();
491 // No need to connect callbacks as KeyboardStatusChanged will be called.
494 return ECORE_CALLBACK_PASS_ON;
498 * Called when the window loses focus.
500 static Eina_Bool EcoreEventWindowFocusOut( void* data, int type, void* event )
502 Ecore_Wl_Event_Focus_Out* focusOutEvent( (Ecore_Wl_Event_Focus_Out*)event );
503 EventHandler* handler( (EventHandler*)data );
505 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventWindowFocusOut \n" );
507 // If the window loses focus then hide the keyboard.
508 if ( focusOutEvent->win == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
510 if ( handler->mImfManager )
512 ImfManager& imfManager( ImfManager::GetImplementation( handler->mImfManager ) );
513 if( imfManager.RestoreAfterFocusLost() )
515 imfManager.Deactivate();
519 // Clipboard don't support that whether clipboard is shown or not. Hide clipboard.
520 Dali::Clipboard clipboard = Clipboard::Get();
521 clipboard.HideClipboard();
524 return ECORE_CALLBACK_PASS_ON;
528 * Called when the window is damaged.
530 static Eina_Bool EcoreEventWindowDamaged(void *data, int type, void *event)
532 return ECORE_CALLBACK_PASS_ON;
536 * Called when the window properties are changed.
537 * We are only interested in the font change.
541 /////////////////////////////////////////////////////////////////////////////////////////////////
542 // Drag & Drop Callbacks
543 /////////////////////////////////////////////////////////////////////////////////////////////////
546 * Called when a dragged item enters our window's bounds.
547 * This is when items are dragged INTO our window.
549 static Eina_Bool EcoreEventDndEnter( void* data, int type, void* event )
551 DALI_LOG_INFO( gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndEnter\n" );
553 return ECORE_CALLBACK_PASS_ON;
557 * Called when a dragged item is moved within our window.
558 * This is when items are dragged INTO our window.
560 static Eina_Bool EcoreEventDndPosition( void* data, int type, void* event )
562 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndPosition\n" );
564 return ECORE_CALLBACK_PASS_ON;
568 * Called when a dragged item leaves our window's bounds.
569 * This is when items are dragged INTO our window.
571 static Eina_Bool EcoreEventDndLeave( void* data, int type, void* event )
573 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndLeave\n" );
575 return ECORE_CALLBACK_PASS_ON;
579 * Called when the dragged item is dropped within our window's bounds.
580 * This is when items are dragged INTO our window.
582 static Eina_Bool EcoreEventDndDrop( void* data, int type, void* event )
584 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndDrop\n" );
586 return ECORE_CALLBACK_PASS_ON;
590 * Called when a dragged item is moved from our window and the target window has done processing it.
591 * This is when items are dragged FROM our window.
593 static Eina_Bool EcoreEventDndFinished( void* data, int type, void* event )
595 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndFinished\n" );
596 return ECORE_CALLBACK_PASS_ON;
600 * Called when a dragged item is moved from our window and the target window has sent us a status.
601 * This is when items are dragged FROM our window.
603 static Eina_Bool EcoreEventDndStatus( void* data, int type, void* event )
605 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndStatus\n" );
606 return ECORE_CALLBACK_PASS_ON;
610 * Called when the client messages (i.e. the accessibility events) are received.
612 static Eina_Bool EcoreEventClientMessage( void* data, int type, void* event )
614 return ECORE_CALLBACK_PASS_ON;
618 * Called when the source window notifies us the content in clipboard is selected.
620 static Eina_Bool EcoreEventSelectionClear( void* data, int type, void* event )
622 DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventSelectionClear\n" );
623 return ECORE_CALLBACK_PASS_ON;
627 * Called when the source window sends us about the selected content.
628 * For example, when dragged items are dragged INTO our window or when items are selected in the clipboard.
630 static Eina_Bool EcoreEventSelectionNotify( void* data, int type, void* event )
632 DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventSelectionNotify\n" );
633 return ECORE_CALLBACK_PASS_ON;
636 /////////////////////////////////////////////////////////////////////////////////////////////////
638 /////////////////////////////////////////////////////////////////////////////////////////////////
640 * Called when a font name is changed.
642 static void VconfNotifyFontNameChanged( keynode_t* node, void* data )
644 EventHandler* handler = static_cast<EventHandler*>( data );
646 StyleChange fontChange;
647 fontChange.defaultFontChange = true;
649 handler->SendEvent( fontChange );
653 * Called when a font size is changed.
655 static void VconfNotifyFontSizeChanged( keynode_t* node, void* data )
657 EventHandler* handler = static_cast<EventHandler*>( data );
659 StyleChange fontChange;
660 fontChange.defaultFontSizeChange = true;
662 handler->SendEvent( fontChange );
666 EventHandler* mHandler;
667 std::vector<Ecore_Event_Handler*> mEcoreEventHandler;
668 Ecore_Wl_Window* mWindow;
671 EventHandler::EventHandler( RenderSurface* surface, CoreEventInterface& coreEventInterface, GestureManager& gestureManager, DamageObserver& damageObserver, DragAndDropDetectorPtr dndDetector )
672 : mCoreEventInterface(coreEventInterface),
673 mGestureManager( gestureManager ),
674 mStyleMonitor( StyleMonitor::Get() ),
675 mDamageObserver( damageObserver ),
676 mRotationObserver( NULL ),
677 mDragAndDropDetector( dndDetector ),
678 mAccessibilityManager( AccessibilityManager::Get() ),
679 mClipboardEventNotifier( ClipboardEventNotifier::Get() ),
680 mClipboard(Clipboard::Get()),
681 mImfManager( ImfManager::Get() ),
684 Ecore_Wl_Window* window = 0;
686 if( surface->GetType() == Dali::RenderSurface::WINDOW )
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();
696 mImpl = new Impl(this, window);
699 EventHandler::~EventHandler()
706 mGestureManager.Stop();
709 void EventHandler::SendEvent(TouchPoint& point, unsigned long timeStamp)
713 timeStamp = GetCurrentMilliSeconds();
716 Integration::TouchEvent event;
717 if (mCombiner.GetNextTouchEvent(point, timeStamp, event))
719 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);
721 // First the touch event & related gesture events are queued
722 mCoreEventInterface.QueueCoreEvent( event );
723 mGestureManager.SendEvent(event);
725 // Next the events are processed with a single call into Core
726 mCoreEventInterface.ProcessCoreEvents();
730 void EventHandler::SendEvent(KeyEvent& keyEvent)
732 Dali::PhysicalKeyboard physicalKeyboard = PhysicalKeyboard::Get();
733 if ( physicalKeyboard )
735 if ( ! KeyLookup::IsDeviceButton( keyEvent.keyPressedName.c_str() ) )
737 GetImplementation( physicalKeyboard ).KeyReceived( keyEvent.time > 1 );
741 // Create KeyEvent and send to Core.
742 Integration::KeyEvent event(keyEvent.keyPressedName, keyEvent.keyPressed, keyEvent.keyCode,
743 keyEvent.keyModifier, keyEvent.time, static_cast<Integration::KeyEvent::State>(keyEvent.state));
744 mCoreEventInterface.QueueCoreEvent( event );
745 mCoreEventInterface.ProcessCoreEvents();
748 void EventHandler::SendMouseWheelEvent( MouseWheelEvent& wheelEvent )
750 // Create MouseWheelEvent and send to Core.
751 Integration::MouseWheelEvent event(wheelEvent.direction, wheelEvent.modifiers, wheelEvent.point, wheelEvent.z, wheelEvent.timeStamp);
752 mCoreEventInterface.QueueCoreEvent( event );
753 mCoreEventInterface.ProcessCoreEvents();
756 void EventHandler::SendEvent(StyleChange styleChange)
758 DALI_ASSERT_DEBUG( mStyleMonitor && "StyleMonitor Not Available" );
759 GetImplementation( mStyleMonitor ).StyleChanged(styleChange);
762 void EventHandler::SendEvent( const DamageArea& area )
764 mDamageObserver.OnDamaged( area );
767 void EventHandler::SendRotationPrepareEvent( const RotationEvent& event )
769 if( mRotationObserver != NULL )
771 mRotationObserver->OnRotationPrepare( event );
775 void EventHandler::SendRotationRequestEvent( )
777 if( mRotationObserver != NULL )
779 mRotationObserver->OnRotationRequest( );
783 void EventHandler::FeedTouchPoint( TouchPoint& point, int timeStamp)
785 SendEvent(point, timeStamp);
788 void EventHandler::FeedWheelEvent( MouseWheelEvent& wheelEvent )
790 SendMouseWheelEvent( wheelEvent );
793 void EventHandler::FeedKeyEvent( KeyEvent& event )
798 void EventHandler::FeedEvent( Integration::Event& event )
800 mCoreEventInterface.QueueCoreEvent( event );
801 mCoreEventInterface.ProcessCoreEvents();
804 void EventHandler::Reset()
808 // Any touch listeners should be told of the interruption.
809 Integration::TouchEvent event;
810 TouchPoint point(0, TouchPoint::Interrupted, 0, 0);
811 event.AddPoint( point );
813 // First the touch event & related gesture events are queued
814 mCoreEventInterface.QueueCoreEvent( event );
815 mGestureManager.SendEvent( event );
817 // Next the events are processed with a single call into Core
818 mCoreEventInterface.ProcessCoreEvents();
821 void EventHandler::SetDragAndDropDetector( DragAndDropDetectorPtr detector )
823 mDragAndDropDetector = detector;
826 void EventHandler::SetRotationObserver( RotationObserver* observer )
828 mRotationObserver = observer;
831 } // namespace Adaptor
833 } // namespace Internal