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()),
128 // this code only works with the wayland RenderSurface so need to downcast
129 Wayland::RenderSurface* waylandSurface = dynamic_cast< Wayland::RenderSurface* >( surface );
131 mImpl = new Impl(this );
135 waylandSurface->AssignWindowEventInterface( mImpl );
139 EventHandler::~EventHandler()
146 mGestureManager.Stop();
149 void EventHandler::SendEvent(Integration::Point& point, unsigned long timeStamp)
152 Integration::TouchEvent touchEvent;
153 Integration::HoverEvent hoverEvent;
154 Integration::TouchEventCombiner::EventDispatchType type = mCombiner.GetNextTouchEvent(point, timeStamp, touchEvent, hoverEvent);
155 if(type != Integration::TouchEventCombiner::DispatchNone )
157 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);
159 // First the touch and/or hover event & related gesture events are queued
160 if(type == Integration::TouchEventCombiner::DispatchTouch || type == Integration::TouchEventCombiner::DispatchBoth)
162 mCoreEventInterface.QueueCoreEvent( touchEvent );
163 mGestureManager.SendEvent(touchEvent);
166 if(type == Integration::TouchEventCombiner::DispatchHover || type == Integration::TouchEventCombiner::DispatchBoth)
168 mCoreEventInterface.QueueCoreEvent( hoverEvent );
171 // Next the events are processed with a single call into Core
172 mCoreEventInterface.ProcessCoreEvents();
176 void EventHandler::SendEvent(KeyEvent& keyEvent)
178 Dali::PhysicalKeyboard physicalKeyboard = PhysicalKeyboard::Get();
179 if ( physicalKeyboard )
181 if ( ! KeyLookup::IsDeviceButton( keyEvent.keyPressedName.c_str() ) )
183 GetImplementation( physicalKeyboard ).KeyReceived( keyEvent.time > 1 );
187 // Create KeyEvent and send to Core.
188 Integration::KeyEvent event(keyEvent.keyPressedName, keyEvent.keyPressed, keyEvent.keyCode,
189 keyEvent.keyModifier, keyEvent.time, static_cast<Integration::KeyEvent::State>(keyEvent.state));
190 mCoreEventInterface.QueueCoreEvent( event );
191 mCoreEventInterface.ProcessCoreEvents();
194 void EventHandler::SendWheelEvent( WheelEvent& wheelEvent )
196 // Create WheelEvent and send to Core.
197 Integration::WheelEvent event( static_cast< Integration::WheelEvent::Type >(wheelEvent.type), wheelEvent.direction, wheelEvent.modifiers, wheelEvent.point, wheelEvent.z, wheelEvent.timeStamp );
198 mCoreEventInterface.QueueCoreEvent( event );
199 mCoreEventInterface.ProcessCoreEvents();
202 void EventHandler::SendEvent( StyleChange::Type styleChange )
204 DALI_ASSERT_DEBUG( mStyleMonitor && "StyleMonitor Not Available" );
205 GetImplementation( mStyleMonitor ).StyleChanged(styleChange);
208 void EventHandler::SendEvent( const DamageArea& area )
210 mDamageObserver.OnDamaged( area );
213 void EventHandler::SendRotationPrepareEvent( const RotationEvent& event )
215 if( mRotationObserver != NULL )
217 mRotationObserver->OnRotationPrepare( event );
221 void EventHandler::SendRotationRequestEvent( )
223 if( mRotationObserver != NULL )
225 mRotationObserver->OnRotationRequest( );
229 void EventHandler::FeedTouchPoint( TouchPoint& point, int timeStamp)
231 Integration::Point convertedPoint( point );
232 SendEvent(convertedPoint, timeStamp);
235 void EventHandler::FeedWheelEvent( WheelEvent& wheelEvent )
237 SendWheelEvent( wheelEvent );
240 void EventHandler::FeedKeyEvent( KeyEvent& event )
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