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>
24 #include <dali/public-api/common/vector-wrapper.h>
25 #include <dali/public-api/events/touch-point.h>
26 #include <dali/public-api/events/key-event.h>
27 #include <dali/public-api/events/wheel-event.h>
28 #include <dali/integration-api/debug.h>
29 #include <dali/integration-api/events/key-event-integ.h>
30 #include <dali/integration-api/events/touch-event-integ.h>
31 #include <dali/integration-api/events/hover-event-integ.h>
32 #include <dali/integration-api/events/wheel-event-integ.h>
36 #include <render-surface/render-surface-wl.h>
37 #include <events/gesture-manager.h>
39 #include <clipboard.h>
40 #include <physical-keyboard-impl.h>
41 #include <style-monitor-impl.h>
42 #include <base/core-event-interface.h>
43 #include <base/interfaces/window-event-interface.h>
56 struct EventHandler::Impl : public WindowEventInterface
58 // Construction & Destruction
63 Impl( EventHandler* handler )
64 : mHandler( handler ),
74 // @todo Consider allowing the EventHandler class to inherit from WindowEventInterface directly
75 virtual void TouchEvent( Dali::Integration::Point& point, unsigned long timeStamp )
77 mHandler->SendEvent( point, timeStamp );
79 virtual void KeyEvent( Dali::KeyEvent& keyEvent )
81 mHandler->SendEvent( keyEvent );
83 virtual void WheelEvent( Dali::WheelEvent& wheelEvent )
85 mHandler->SendWheelEvent( wheelEvent );
87 virtual void DamageEvent( Rect<int>& damageArea )
89 mHandler->SendEvent( damageArea );
91 virtual void WindowFocusOut( )
93 // used to do some work with ime
95 virtual void WindowFocusIn()
97 // used to do some work with ime
100 EventHandler* mHandler;
105 * @TODO the event handler code seems to be common across all adaptors, could do with moving into common
108 EventHandler::EventHandler( RenderSurface* surface, CoreEventInterface& coreEventInterface, GestureManager& gestureManager, DamageObserver& damageObserver, DragAndDropDetectorPtr dndDetector )
109 : mCoreEventInterface(coreEventInterface),
110 mGestureManager( gestureManager ),
111 mStyleMonitor( StyleMonitor::Get() ),
112 mDamageObserver( damageObserver ),
113 mRotationObserver( NULL ),
114 mDragAndDropDetector( dndDetector ),
115 mClipboardEventNotifier( ClipboardEventNotifier::Get() ),
116 mClipboard( Dali::Clipboard::Get()),
122 // this code only works with the wayland RenderSurface so need to downcast
123 Wayland::RenderSurface* waylandSurface = dynamic_cast< Wayland::RenderSurface* >( surface );
125 mImpl = new Impl(this );
129 waylandSurface->AssignWindowEventInterface( mImpl );
133 EventHandler::~EventHandler()
140 mGestureManager.Stop();
143 void EventHandler::SendEvent(Integration::Point& point, unsigned long timeStamp)
146 Integration::TouchEvent touchEvent;
147 Integration::HoverEvent hoverEvent;
148 Integration::TouchEventCombiner::EventDispatchType type = mCombiner.GetNextTouchEvent(point, timeStamp, touchEvent, hoverEvent);
149 if(type != Integration::TouchEventCombiner::DispatchNone )
151 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);
153 // First the touch and/or hover event & related gesture events are queued
154 if(type == Integration::TouchEventCombiner::DispatchTouch || type == Integration::TouchEventCombiner::DispatchBoth)
156 mCoreEventInterface.QueueCoreEvent( touchEvent );
157 mGestureManager.SendEvent(touchEvent);
160 if(type == Integration::TouchEventCombiner::DispatchHover || type == Integration::TouchEventCombiner::DispatchBoth)
162 mCoreEventInterface.QueueCoreEvent( hoverEvent );
165 // Next the events are processed with a single call into Core
166 mCoreEventInterface.ProcessCoreEvents();
170 void EventHandler::SendEvent(KeyEvent& keyEvent)
172 Dali::PhysicalKeyboard physicalKeyboard = PhysicalKeyboard::Get();
173 if ( physicalKeyboard )
175 if ( ! KeyLookup::IsDeviceButton( keyEvent.keyPressedName.c_str() ) )
177 GetImplementation( physicalKeyboard ).KeyReceived( keyEvent.time > 1 );
181 // Create KeyEvent and send to Core.
182 Integration::KeyEvent event(keyEvent.keyPressedName, keyEvent.keyPressed, keyEvent.keyCode,
183 keyEvent.keyModifier, keyEvent.time, static_cast<Integration::KeyEvent::State>(keyEvent.state));
184 mCoreEventInterface.QueueCoreEvent( event );
185 mCoreEventInterface.ProcessCoreEvents();
188 void EventHandler::SendWheelEvent( WheelEvent& wheelEvent )
190 // Create WheelEvent and send to Core.
191 Integration::WheelEvent event( static_cast< Integration::WheelEvent::Type >(wheelEvent.type), wheelEvent.direction, wheelEvent.modifiers, wheelEvent.point, wheelEvent.z, wheelEvent.timeStamp );
192 mCoreEventInterface.QueueCoreEvent( event );
193 mCoreEventInterface.ProcessCoreEvents();
196 void EventHandler::SendEvent( StyleChange::Type styleChange )
198 DALI_ASSERT_DEBUG( mStyleMonitor && "StyleMonitor Not Available" );
199 GetImplementation( mStyleMonitor ).StyleChanged(styleChange);
202 void EventHandler::SendEvent( const DamageArea& area )
204 mDamageObserver.OnDamaged( area );
207 void EventHandler::SendRotationPrepareEvent( const RotationEvent& event )
209 if( mRotationObserver != NULL )
211 mRotationObserver->OnRotationPrepare( event );
215 void EventHandler::SendRotationRequestEvent( )
217 if( mRotationObserver != NULL )
219 mRotationObserver->OnRotationRequest( );
223 void EventHandler::FeedTouchPoint( TouchPoint& point, int timeStamp)
225 Integration::Point convertedPoint( point );
226 SendEvent(convertedPoint, timeStamp);
229 void EventHandler::FeedWheelEvent( WheelEvent& wheelEvent )
231 SendWheelEvent( wheelEvent );
234 void EventHandler::FeedKeyEvent( KeyEvent& event )
239 void EventHandler::FeedEvent( Integration::Event& event )
241 mCoreEventInterface.QueueCoreEvent( event );
242 mCoreEventInterface.ProcessCoreEvents();
245 void EventHandler::Reset()
249 // Any touch listeners should be told of the interruption.
250 Integration::TouchEvent event;
251 Integration::Point point;
252 point.SetState( PointState::INTERRUPTED );
253 event.AddPoint( point );
255 // First the touch event & related gesture events are queued
256 mCoreEventInterface.QueueCoreEvent( event );
257 mGestureManager.SendEvent( event );
259 // Next the events are processed with a single call into Core
260 mCoreEventInterface.ProcessCoreEvents();
263 void EventHandler::Pause()
269 void EventHandler::Resume()
275 void EventHandler::SetDragAndDropDetector( DragAndDropDetectorPtr detector )
277 mDragAndDropDetector = detector;
280 void EventHandler::SetRotationObserver( RotationObserver* observer )
282 mRotationObserver = observer;
285 } // namespace Adaptor
287 } // namespace Internal