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( Integration::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(Integration::KeyEvent& keyEvent)
179 Dali::PhysicalKeyboard physicalKeyboard = PhysicalKeyboard::Get();
180 if ( physicalKeyboard )
182 if ( ! KeyLookup::IsDeviceButton( keyEvent.keyName.c_str() ) )
184 GetImplementation( physicalKeyboard ).KeyReceived( keyEvent.time > 1 );
188 // Create send KeyEvent to Core.
189 mCoreEventInterface.QueueCoreEvent( keyEvent );
190 mCoreEventInterface.ProcessCoreEvents();
193 void EventHandler::SendWheelEvent( WheelEvent& wheelEvent )
195 // Create WheelEvent and send to Core.
196 Integration::WheelEvent event( static_cast< Integration::WheelEvent::Type >(wheelEvent.type), wheelEvent.direction, wheelEvent.modifiers, wheelEvent.point, wheelEvent.z, wheelEvent.timeStamp );
197 mCoreEventInterface.QueueCoreEvent( event );
198 mCoreEventInterface.ProcessCoreEvents();
201 void EventHandler::SendEvent( StyleChange::Type styleChange )
203 DALI_ASSERT_DEBUG( mStyleMonitor && "StyleMonitor Not Available" );
204 GetImplementation( mStyleMonitor ).StyleChanged(styleChange);
207 void EventHandler::SendEvent( const DamageArea& area )
209 mDamageObserver.OnDamaged( area );
212 void EventHandler::SendRotationPrepareEvent( const RotationEvent& event )
214 if( mRotationObserver != NULL )
216 mRotationObserver->OnRotationPrepare( event );
220 void EventHandler::SendRotationRequestEvent( )
222 if( mRotationObserver != NULL )
224 mRotationObserver->OnRotationRequest( );
228 void EventHandler::FeedTouchPoint( TouchPoint& point, int timeStamp)
230 Integration::Point convertedPoint( point );
231 SendEvent(convertedPoint, timeStamp);
234 void EventHandler::FeedWheelEvent( WheelEvent& wheelEvent )
236 SendWheelEvent( wheelEvent );
239 void EventHandler::FeedKeyEvent( KeyEvent& event )
241 Integration::KeyEvent convertedEvent( event );
242 SendEvent( convertedEvent );
245 void EventHandler::FeedEvent( Integration::Event& event )
247 mCoreEventInterface.QueueCoreEvent( event );
248 mCoreEventInterface.ProcessCoreEvents();
251 void EventHandler::Reset()
255 // Any touch listeners should be told of the interruption.
256 Integration::TouchEvent event;
257 Integration::Point point;
258 point.SetState( PointState::INTERRUPTED );
259 event.AddPoint( point );
261 // First the touch event & related gesture events are queued
262 mCoreEventInterface.QueueCoreEvent( event );
263 mGestureManager.SendEvent( event );
265 // Next the events are processed with a single call into Core
266 mCoreEventInterface.ProcessCoreEvents();
269 void EventHandler::Pause()
275 void EventHandler::Resume()
281 void EventHandler::SetDragAndDropDetector( DragAndDropDetectorPtr detector )
283 mDragAndDropDetector = detector;
286 void EventHandler::SetRotationObserver( RotationObserver* observer )
288 mRotationObserver = observer;
291 } // namespace Adaptor
293 } // namespace Internal