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 #if defined(DEBUG_ENABLED)
59 Integration::Log::Filter* gTouchEventLogFilter = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_TOUCH");
60 } // unnamed namespace
63 struct EventHandler::Impl : public WindowEventInterface
65 // Construction & Destruction
70 Impl( EventHandler* handler )
71 : mHandler( handler ),
81 // @todo Consider allowing the EventHandler class to inherit from WindowEventInterface directly
82 virtual void TouchEvent( Dali::Integration::Point& point, unsigned long timeStamp )
84 mHandler->SendEvent( point, timeStamp );
86 virtual void KeyEvent( Dali::KeyEvent& keyEvent )
88 mHandler->SendEvent( keyEvent );
90 virtual void WheelEvent( Dali::WheelEvent& wheelEvent )
92 mHandler->SendWheelEvent( wheelEvent );
94 virtual void DamageEvent( Rect<int>& damageArea )
96 mHandler->SendEvent( damageArea );
98 virtual void WindowFocusOut( )
100 // used to do some work with ime
102 virtual void WindowFocusIn()
104 // used to do some work with ime
107 EventHandler* mHandler;
112 * @TODO the event handler code seems to be common across all adaptors, could do with moving into common
115 EventHandler::EventHandler( RenderSurface* surface, CoreEventInterface& coreEventInterface, GestureManager& gestureManager, DamageObserver& damageObserver, DragAndDropDetectorPtr dndDetector )
116 : mCoreEventInterface(coreEventInterface),
117 mGestureManager( gestureManager ),
118 mStyleMonitor( StyleMonitor::Get() ),
119 mDamageObserver( damageObserver ),
120 mRotationObserver( NULL ),
121 mDragAndDropDetector( dndDetector ),
122 mClipboardEventNotifier( ClipboardEventNotifier::Get() ),
123 mClipboard( Dali::Clipboard::Get()),
129 // this code only works with the wayland RenderSurface so need to downcast
130 Wayland::RenderSurface* waylandSurface = dynamic_cast< Wayland::RenderSurface* >( surface );
132 mImpl = new Impl(this );
136 waylandSurface->AssignWindowEventInterface( mImpl );
140 EventHandler::~EventHandler()
147 mGestureManager.Stop();
150 void EventHandler::SendEvent(Integration::Point& point, unsigned long timeStamp)
153 Integration::TouchEvent touchEvent;
154 Integration::HoverEvent hoverEvent;
155 Integration::TouchEventCombiner::EventDispatchType type = mCombiner.GetNextTouchEvent(point, timeStamp, touchEvent, hoverEvent);
156 if(type != Integration::TouchEventCombiner::DispatchNone )
158 DALI_LOG_INFO(gTouchEventLogFilter, Debug::General, "%d: Device %d: Button state %d (%.2f, %.2f)\n", timeStamp, point.GetDeviceId(), point.GetState(), point.GetLocalPosition().x, point.GetLocalPosition().y);
160 // First the touch and/or hover event & related gesture events are queued
161 if(type == Integration::TouchEventCombiner::DispatchTouch || type == Integration::TouchEventCombiner::DispatchBoth)
163 mCoreEventInterface.QueueCoreEvent( touchEvent );
164 mGestureManager.SendEvent(touchEvent);
167 if(type == Integration::TouchEventCombiner::DispatchHover || type == Integration::TouchEventCombiner::DispatchBoth)
169 mCoreEventInterface.QueueCoreEvent( hoverEvent );
172 // Next the events are processed with a single call into Core
173 mCoreEventInterface.ProcessCoreEvents();
177 void EventHandler::SendEvent(KeyEvent& keyEvent)
179 Dali::PhysicalKeyboard physicalKeyboard = PhysicalKeyboard::Get();
180 if ( physicalKeyboard )
182 if ( ! KeyLookup::IsDeviceButton( keyEvent.keyPressedName.c_str() ) )
184 GetImplementation( physicalKeyboard ).KeyReceived( keyEvent.time > 1 );
188 // Create KeyEvent and send to Core.
189 Integration::KeyEvent event(keyEvent.keyPressedName, keyEvent.keyPressed, keyEvent.keyCode,
190 keyEvent.keyModifier, keyEvent.time, static_cast<Integration::KeyEvent::State>(keyEvent.state));
191 mCoreEventInterface.QueueCoreEvent( event );
192 mCoreEventInterface.ProcessCoreEvents();
195 void EventHandler::SendWheelEvent( WheelEvent& wheelEvent )
197 // Create WheelEvent and send to Core.
198 Integration::WheelEvent event( static_cast< Integration::WheelEvent::Type >(wheelEvent.type), wheelEvent.direction, wheelEvent.modifiers, wheelEvent.point, wheelEvent.z, wheelEvent.timeStamp );
199 mCoreEventInterface.QueueCoreEvent( event );
200 mCoreEventInterface.ProcessCoreEvents();
203 void EventHandler::SendEvent( StyleChange::Type styleChange )
205 DALI_ASSERT_DEBUG( mStyleMonitor && "StyleMonitor Not Available" );
206 GetImplementation( mStyleMonitor ).StyleChanged(styleChange);
209 void EventHandler::SendEvent( const DamageArea& area )
211 mDamageObserver.OnDamaged( area );
214 void EventHandler::SendRotationPrepareEvent( const RotationEvent& event )
216 if( mRotationObserver != NULL )
218 mRotationObserver->OnRotationPrepare( event );
222 void EventHandler::SendRotationRequestEvent( )
224 if( mRotationObserver != NULL )
226 mRotationObserver->OnRotationRequest( );
230 void EventHandler::FeedTouchPoint( TouchPoint& point, int timeStamp)
232 Integration::Point convertedPoint( point );
233 SendEvent(convertedPoint, timeStamp);
236 void EventHandler::FeedWheelEvent( WheelEvent& wheelEvent )
238 SendWheelEvent( wheelEvent );
241 void EventHandler::FeedKeyEvent( KeyEvent& event )
246 void EventHandler::FeedEvent( Integration::Event& event )
248 mCoreEventInterface.QueueCoreEvent( event );
249 mCoreEventInterface.ProcessCoreEvents();
252 void EventHandler::Reset()
256 // Any touch listeners should be told of the interruption.
257 Integration::TouchEvent event;
258 Integration::Point point;
259 point.SetState( PointState::INTERRUPTED );
260 event.AddPoint( point );
262 // First the touch event & related gesture events are queued
263 mCoreEventInterface.QueueCoreEvent( event );
264 mGestureManager.SendEvent( event );
266 // Next the events are processed with a single call into Core
267 mCoreEventInterface.ProcessCoreEvents();
270 void EventHandler::Pause()
276 void EventHandler::Resume()
282 void EventHandler::SetDragAndDropDetector( DragAndDropDetectorPtr detector )
284 mDragAndDropDetector = detector;
287 void EventHandler::SetRotationObserver( RotationObserver* observer )
289 mRotationObserver = observer;
292 } // namespace Adaptor
294 } // namespace Internal