From 39aa1ca3375a2f47686bfe95523c51ca914bb310 Mon Sep 17 00:00:00 2001 From: Richard Huang Date: Wed, 15 May 2019 11:05:25 +0100 Subject: [PATCH] Event handling refactoring to support EvasPlugin Change-Id: Ia2cf3bacb49bceee0dda58a175bd6035ecb1941a --- dali/integration-api/scene-holder-impl.cpp | 129 +++++++++++++ dali/integration-api/scene-holder-impl.h | 52 +++-- dali/integration-api/scene-holder.cpp | 15 +- dali/internal/adaptor/common/adaptor-impl.cpp | 11 +- dali/internal/adaptor/common/adaptor-impl.h | 12 +- dali/internal/adaptor/common/application-impl.h | 1 - .../tizen-wearable/watch-application-impl.cpp | 3 + .../window-system/common/event-handler.cpp | 211 ++++----------------- dali/internal/window-system/common/event-handler.h | 152 +++++++-------- .../window-system/common/orientation-impl.cpp | 12 +- .../window-system/common/orientation-impl.h | 25 +-- .../{rotation-observer.h => rotation-event.h} | 42 +--- dali/internal/window-system/common/window-base.h | 16 +- dali/internal/window-system/common/window-impl.cpp | 101 ++++++---- dali/internal/window-system/common/window-impl.h | 61 +++--- dali/public-api/adaptor-framework/window.cpp | 1 - 16 files changed, 419 insertions(+), 425 deletions(-) rename dali/internal/window-system/common/{rotation-observer.h => rotation-event.h} (54%) diff --git a/dali/integration-api/scene-holder-impl.cpp b/dali/integration-api/scene-holder-impl.cpp index b228452..efbbd60 100644 --- a/dali/integration-api/scene-holder-impl.cpp +++ b/dali/integration-api/scene-holder-impl.cpp @@ -19,12 +19,20 @@ #include // EXTERNAL HEADERS +#include #include #include +#include +#include +#include +#include +#include // INTERNAL HEADERS #include #include +#include +#include namespace Dali { @@ -35,6 +43,51 @@ namespace Internal namespace Adaptor { +namespace +{ + +#if defined(DEBUG_ENABLED) +Integration::Log::Filter* gTouchEventLogFilter = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_TOUCH"); +#endif + +// Copied from x server +static uint32_t GetCurrentMilliSeconds(void) +{ + struct timeval tv; + + struct timespec tp; + static clockid_t clockid; + + if (!clockid) + { +#ifdef CLOCK_MONOTONIC_COARSE + if (clock_getres(CLOCK_MONOTONIC_COARSE, &tp) == 0 && + (tp.tv_nsec / 1000) <= 1000 && clock_gettime(CLOCK_MONOTONIC_COARSE, &tp) == 0) + { + clockid = CLOCK_MONOTONIC_COARSE; + } + else +#endif + if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0) + { + clockid = CLOCK_MONOTONIC; + } + else + { + clockid = ~0L; + } + } + if (clockid != ~0L && clock_gettime(clockid, &tp) == 0) + { + return static_cast( (tp.tv_sec * 1000 ) + (tp.tv_nsec / 1000000L) ); + } + + gettimeofday(&tv, NULL); + return static_cast( (tv.tv_sec * 1000 ) + (tv.tv_usec / 1000) ); +} + +} // unnamed namespace + uint32_t SceneHolder::mSceneHolderCounter = 0; class SceneHolder::SceneHolderLifeCycleObserver : public LifeCycleObserver @@ -195,14 +248,90 @@ void SceneHolder::SetAdaptor(Dali::Adaptor& adaptor) void SceneHolder::Pause() { + Reset(); + OnPause(); } void SceneHolder::Resume() { + Reset(); + OnResume(); } +void SceneHolder::FeedTouchPoint( Dali::Integration::Point& point, int timeStamp ) +{ + if( timeStamp < 1 ) + { + timeStamp = GetCurrentMilliSeconds(); + } + + RecalculateTouchPosition( point ); + + Integration::TouchEvent touchEvent; + Integration::HoverEvent hoverEvent; + Integration::TouchEventCombiner::EventDispatchType type = mCombiner.GetNextTouchEvent(point, timeStamp, touchEvent, hoverEvent); + if( type != Integration::TouchEventCombiner::DispatchNone ) + { + DALI_LOG_INFO( gTouchEventLogFilter, Debug::General, "%d: Device %d: Button state %d (%.2f, %.2f)\n", timeStamp, point.GetDeviceId(), point.GetState(), point.GetScreenPosition().x, point.GetScreenPosition().y ); + + // First the touch and/or hover event & related gesture events are queued + if( type == Integration::TouchEventCombiner::DispatchTouch || type == Integration::TouchEventCombiner::DispatchBoth ) + { + mScene.QueueEvent( touchEvent ); + } + + if( type == Integration::TouchEventCombiner::DispatchHover || type == Integration::TouchEventCombiner::DispatchBoth ) + { + mScene.QueueEvent( hoverEvent ); + } + + // Next the events are processed with a single call into Core + mAdaptor->ProcessCoreEvents(); + } +} + +void SceneHolder::FeedWheelEvent( Dali::Integration::WheelEvent& wheelEvent ) +{ + mScene.QueueEvent( wheelEvent ); + mAdaptor->ProcessCoreEvents(); +} + +void SceneHolder::FeedKeyEvent( Dali::Integration::KeyEvent& keyEvent ) +{ + Dali::PhysicalKeyboard physicalKeyboard = PhysicalKeyboard::Get(); + if( physicalKeyboard ) + { + if( ! KeyLookup::IsDeviceButton( keyEvent.keyName.c_str() ) ) + { + GetImplementation( physicalKeyboard ).KeyReceived( keyEvent.time > 1 ); + } + } + + // Create send KeyEvent to Core. + mScene.QueueEvent( keyEvent ); + mAdaptor->ProcessCoreEvents(); +} + +void SceneHolder::Reset() +{ + mCombiner.Reset(); + + // Any touch listeners should be told of the interruption. + Integration::TouchEvent event; + Integration::Point point; + point.SetState( PointState::INTERRUPTED ); + event.AddPoint( point ); + + // First the touch event & related gesture events are queued + mScene.QueueEvent( event ); + + // Next the events are processed with a single call into Core + mAdaptor->ProcessCoreEvents(); +} + + }// Adaptor }// Internal diff --git a/dali/integration-api/scene-holder-impl.h b/dali/integration-api/scene-holder-impl.h index 97e4512..12c5432 100644 --- a/dali/integration-api/scene-holder-impl.h +++ b/dali/integration-api/scene-holder-impl.h @@ -24,9 +24,11 @@ #include #include #include +#include +#include +#include // INTERNAL INCLUDES - #ifdef DALI_ADAPTOR_COMPILATION #include #include @@ -50,6 +52,9 @@ namespace Integration { class Scene; +struct Point; +struct KeyEvent; +struct WheelEvent; } @@ -142,35 +147,35 @@ public: */ void Resume(); -public: // The following methods can be overridden if required - /** - * @brief Returns whether the Scene is visible or not. - * @return True if the Scene is visible, false otherwise. + * @copydoc Dali::Integration::SceneHolder::FeedTouchPoint */ - virtual bool IsVisible() const; - -public: // The following methods must be overridden + void FeedTouchPoint( Dali::Integration::Point& point, int timeStamp ); /** - * @copydoc Dali::Integration::SceneHolder::GetNativeHandle + * @copydoc Dali::Integration::SceneHolder::FeedWheelEvent */ - virtual Dali::Any GetNativeHandle() const = 0; + void FeedWheelEvent( Dali::Integration::WheelEvent& wheelEvent ); /** - * @copydoc Dali::Integration::SceneHolder::FeedTouchPoint + * @copydoc Dali::Integration::SceneHolder::FeedKeyEvent */ - virtual void FeedTouchPoint( Dali::TouchPoint& point, int timeStamp ) = 0; + void FeedKeyEvent( Dali::Integration::KeyEvent& keyEvent ); + +public: // The following methods can be overridden if required /** - * @copydoc Dali::Integration::SceneHolder::FeedWheelEvent + * @brief Returns whether the Scene is visible or not. + * @return True if the Scene is visible, false otherwise. */ - virtual void FeedWheelEvent( Dali::WheelEvent& wheelEvent ) = 0; + virtual bool IsVisible() const; + +public: // The following methods must be overridden /** - * @copydoc Dali::Integration::SceneHolder::FeedKeyEvent + * @copydoc Dali::Integration::SceneHolder::GetNativeHandle */ - virtual void FeedKeyEvent( Dali::KeyEvent& keyEvent ) = 0; + virtual Dali::Any GetNativeHandle() const = 0; protected: @@ -212,6 +217,19 @@ private: // The following methods can be overridden if required */ virtual void OnResume() {}; + /** + * Recalculate the touch position if required + * @param[in,out] point The touch point + */ + virtual void RecalculateTouchPosition( Integration::Point& point ) {}; + +private: + + /** + * Resets the event handling. + */ + void Reset(); + private: static uint32_t mSceneHolderCounter; ///< A counter to track the SceneHolder creation @@ -228,6 +246,8 @@ protected: std::unique_ptr< Dali::RenderSurfaceInterface > mSurface; ///< The window rendering surface Adaptor* mAdaptor; ///< The adaptor + Dali::Integration::TouchEventCombiner mCombiner; ///< Combines multi-touch events. + bool mAdaptorStarted:1; ///< Whether the adaptor has started or not bool mVisible:1; ///< Whether the scene is visible or not }; diff --git a/dali/integration-api/scene-holder.cpp b/dali/integration-api/scene-holder.cpp index 9b6c91e..ca5e4f4 100644 --- a/dali/integration-api/scene-holder.cpp +++ b/dali/integration-api/scene-holder.cpp @@ -18,6 +18,12 @@ // CLASS HEADER #include +// EXTERNAL INCLUDES +#include +#include +#include +#include + // INTERNAL INCLUDES #include #include @@ -79,17 +85,20 @@ Vector4 SceneHolder::GetBackgroundColor() const void SceneHolder::FeedTouchPoint( Dali::TouchPoint& point, int timeStamp ) { - GetImplementation(*this).FeedTouchPoint( point, timeStamp ); + Integration::Point convertedPoint( point ); + GetImplementation(*this).FeedTouchPoint( convertedPoint, timeStamp ); } void SceneHolder::FeedWheelEvent( Dali::WheelEvent& wheelEvent ) { - GetImplementation(*this).FeedWheelEvent( wheelEvent ); + Integration::WheelEvent event( static_cast< Integration::WheelEvent::Type >(wheelEvent.type), wheelEvent.direction, wheelEvent.modifiers, wheelEvent.point, wheelEvent.z, wheelEvent.timeStamp ); + GetImplementation(*this).FeedWheelEvent( event ); } void SceneHolder::FeedKeyEvent( Dali::KeyEvent& keyEvent ) { - GetImplementation(*this).FeedKeyEvent( keyEvent ); + Integration::KeyEvent convertedEvent( keyEvent ); + GetImplementation(*this).FeedKeyEvent( convertedEvent ); } }// Integration diff --git a/dali/internal/adaptor/common/adaptor-impl.cpp b/dali/internal/adaptor/common/adaptor-impl.cpp index 7907c7a..5ddb445 100755 --- a/dali/internal/adaptor/common/adaptor-impl.cpp +++ b/dali/internal/adaptor/common/adaptor-impl.cpp @@ -29,7 +29,9 @@ #include #include #include +#include #include +#include #include // INTERNAL INCLUDES @@ -478,17 +480,20 @@ void Adaptor::ContextRegained() void Adaptor::FeedTouchPoint( TouchPoint& point, int timeStamp ) { - mWindows.front()->FeedTouchPoint( point, timeStamp ); + Integration::Point convertedPoint( point ); + mWindows.front()->FeedTouchPoint( convertedPoint, timeStamp ); } void Adaptor::FeedWheelEvent( WheelEvent& wheelEvent ) { - mWindows.front()->FeedWheelEvent( wheelEvent ); + Integration::WheelEvent event( static_cast< Integration::WheelEvent::Type >(wheelEvent.type), wheelEvent.direction, wheelEvent.modifiers, wheelEvent.point, wheelEvent.z, wheelEvent.timeStamp ); + mWindows.front()->FeedWheelEvent( event ); } void Adaptor::FeedKeyEvent( KeyEvent& keyEvent ) { - mWindows.front()->FeedKeyEvent( keyEvent ); + Integration::KeyEvent convertedEvent( keyEvent ); + mWindows.front()->FeedKeyEvent( convertedEvent ); } void Adaptor::ReplaceSurface( Dali::Integration::SceneHolder window, Dali::RenderSurfaceInterface& newSurface ) diff --git a/dali/internal/adaptor/common/adaptor-impl.h b/dali/internal/adaptor/common/adaptor-impl.h index e7e2bf9..edd2e40 100755 --- a/dali/internal/adaptor/common/adaptor-impl.h +++ b/dali/internal/adaptor/common/adaptor-impl.h @@ -503,17 +503,19 @@ public: // Signals return mLanguageChangedSignal; } -private: // From Dali::Internal::Adaptor::CoreEventInterface +public: // From Dali::Internal::Adaptor::CoreEventInterface /** - * @copydoc Dali::Internal::Adaptor::CoreEventInterface::QueueCoreEvent() + * @copydoc Dali::Internal::Adaptor:CoreEventInterface:::ProcessCoreEvents() */ - virtual void QueueCoreEvent(const Dali::Integration::Event& event); + virtual void ProcessCoreEvents(); + +private: // From Dali::Internal::Adaptor::CoreEventInterface /** - * @copydoc Dali::Internal::Adaptor:CoreEventInterface:::ProcessCoreEvents() + * @copydoc Dali::Internal::Adaptor::CoreEventInterface::QueueCoreEvent() */ - virtual void ProcessCoreEvents(); + virtual void QueueCoreEvent(const Dali::Integration::Event& event); private: // From Dali::Integration::RenderController diff --git a/dali/internal/adaptor/common/application-impl.h b/dali/internal/adaptor/common/application-impl.h index 1c1673d..b56814d 100755 --- a/dali/internal/adaptor/common/application-impl.h +++ b/dali/internal/adaptor/common/application-impl.h @@ -27,7 +27,6 @@ #include #include -#include #include #include diff --git a/dali/internal/adaptor/tizen-wayland/tizen-wearable/watch-application-impl.cpp b/dali/internal/adaptor/tizen-wayland/tizen-wearable/watch-application-impl.cpp index 3ffd722..f937172 100644 --- a/dali/internal/adaptor/tizen-wayland/tizen-wearable/watch-application-impl.cpp +++ b/dali/internal/adaptor/tizen-wayland/tizen-wearable/watch-application-impl.cpp @@ -17,6 +17,9 @@ // CLASS HEADER #include + +// INTERNAL INCLUDES +#include #include namespace Dali diff --git a/dali/internal/window-system/common/event-handler.cpp b/dali/internal/window-system/common/event-handler.cpp index cb0ff0f..99f1796 100755 --- a/dali/internal/window-system/common/event-handler.cpp +++ b/dali/internal/window-system/common/event-handler.cpp @@ -30,12 +30,9 @@ #include #include #include -#include // INTERNAL INCLUDES #include -#include -#include #include #include @@ -51,11 +48,11 @@ namespace Adaptor #if defined(DEBUG_ENABLED) namespace { -Integration::Log::Filter* gTouchEventLogFilter = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_TOUCH"); Integration::Log::Filter* gSelectionEventLogFilter = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_SELECTION"); } // unnamed namespace #endif +#ifdef DALI_ELDBUS_AVAILABLE namespace { @@ -96,31 +93,24 @@ static uint32_t GetCurrentMilliSeconds(void) } } // unnamed namespace +#endif -EventHandler::EventHandler( Dali::Integration::Scene scene, CoreEventInterface& coreEventInterface, DamageObserver& damageObserver ) -: mScene( scene ), - mCoreEventInterface( coreEventInterface ), - mStyleMonitor( StyleMonitor::Get() ), +EventHandler::EventHandler( WindowRenderSurface* surface, DamageObserver& damageObserver ) +: mStyleMonitor( StyleMonitor::Get() ), mDamageObserver( damageObserver ), - mRotationObserver( NULL ), mAccessibilityAdaptor( AccessibilityAdaptor::Get() ), mClipboardEventNotifier( ClipboardEventNotifier::Get() ), mClipboard( Clipboard::Get() ), - mRotationAngle( 0 ), - mWindowWidth( 0 ), - mWindowHeight( 0 ), mPaused( false ) { - // this code only works with the WindowRenderSurface so need to downcast - WindowRenderSurface* windowRenderSurface = static_cast< WindowRenderSurface* >( scene.GetSurface() ); - if( windowRenderSurface ) + if( surface ) { - WindowBase* windowBase = windowRenderSurface->GetWindowBase(); + WindowBase* windowBase = surface->GetWindowBase(); // Connect signals windowBase->WindowDamagedSignal().Connect( this, &EventHandler::OnWindowDamaged ); windowBase->FocusChangedSignal().Connect( this, &EventHandler::OnFocusChanged ); - windowBase->RotationSignal().Connect( this, &EventHandler::SendRotationPrepareEvent ); + windowBase->RotationSignal().Connect( this, &EventHandler::OnRotation ); windowBase->TouchEventSignal().Connect( this, &EventHandler::OnTouchEvent ); windowBase->WheelEventSignal().Connect( this, &EventHandler::OnWheelEvent ); windowBase->KeyEventSignal().Connect( this, &EventHandler::OnKeyEvent ); @@ -135,62 +125,6 @@ EventHandler::~EventHandler() { } -void EventHandler::SendEvent( Integration::Point& point, uint32_t timeStamp ) -{ - if( timeStamp < 1 ) - { - timeStamp = GetCurrentMilliSeconds(); - } - - ConvertTouchPosition( point ); - - Integration::TouchEvent touchEvent; - Integration::HoverEvent hoverEvent; - Integration::TouchEventCombiner::EventDispatchType type = mCombiner.GetNextTouchEvent(point, timeStamp, touchEvent, hoverEvent); - if( type != Integration::TouchEventCombiner::DispatchNone ) - { - DALI_LOG_INFO( gTouchEventLogFilter, Debug::General, "%d: Device %d: Button state %d (%.2f, %.2f)\n", timeStamp, point.GetDeviceId(), point.GetState(), point.GetScreenPosition().x, point.GetScreenPosition().y ); - // First the touch and/or hover event & related gesture events are queued - if( type == Integration::TouchEventCombiner::DispatchTouch || type == Integration::TouchEventCombiner::DispatchBoth ) - { - mScene.QueueEvent( touchEvent ); - } - - if( type == Integration::TouchEventCombiner::DispatchHover || type == Integration::TouchEventCombiner::DispatchBoth ) - { - mScene.QueueEvent( hoverEvent ); - } - - // Next the events are processed with a single call into Core - mCoreEventInterface.ProcessCoreEvents(); - } -} - -void EventHandler::SendEvent(Integration::KeyEvent& keyEvent) -{ - Dali::PhysicalKeyboard physicalKeyboard = PhysicalKeyboard::Get(); - if( physicalKeyboard ) - { - if( ! KeyLookup::IsDeviceButton( keyEvent.keyName.c_str() ) ) - { - GetImplementation( physicalKeyboard ).KeyReceived( keyEvent.time > 1 ); - } - } - - // Create send KeyEvent to Core. - mScene.QueueEvent( keyEvent ); - mCoreEventInterface.ProcessCoreEvents(); -} - -void EventHandler::SendWheelEvent( WheelEvent& wheelEvent ) -{ - // Create WheelEvent and send to Core. - Integration::WheelEvent event( static_cast< Integration::WheelEvent::Type >(wheelEvent.type), wheelEvent.direction, wheelEvent.modifiers, wheelEvent.point, wheelEvent.z, wheelEvent.timeStamp ); - - mScene.QueueEvent( event ); - mCoreEventInterface.ProcessCoreEvents(); -} - void EventHandler::SendEvent( StyleChange::Type styleChange ) { DALI_ASSERT_DEBUG( mStyleMonitor && "StyleMonitor Not Available" ); @@ -202,94 +136,40 @@ void EventHandler::SendEvent( const DamageArea& area ) mDamageObserver.OnDamaged( area ); } -void EventHandler::SendRotationPrepareEvent( const RotationEvent& event ) -{ - if( mRotationObserver != NULL ) - { - mRotationAngle = event.angle; - mWindowWidth = event.width; - mWindowHeight = event.height; - - mRotationObserver->OnRotationPrepare( event ); - mRotationObserver->OnRotationRequest(); - } -} - -void EventHandler::SendRotationRequestEvent( ) -{ - // No need to separate event into prepare and request -} - -void EventHandler::FeedTouchPoint( TouchPoint& point, uint32_t timeStamp) -{ - Integration::Point convertedPoint( point ); - SendEvent( convertedPoint, timeStamp ); -} - -void EventHandler::FeedWheelEvent( WheelEvent& wheelEvent ) -{ - SendWheelEvent( wheelEvent ); -} - -void EventHandler::FeedKeyEvent( KeyEvent& event ) -{ - Integration::KeyEvent convertedEvent( event ); - SendEvent( convertedEvent ); -} - -void EventHandler::FeedEvent( Integration::Event& event ) -{ - mScene.QueueEvent( event ); - mCoreEventInterface.ProcessCoreEvents(); -} - -void EventHandler::Reset() -{ - mCombiner.Reset(); - - // Any touch listeners should be told of the interruption. - Integration::TouchEvent event; - Integration::Point point; - point.SetState( PointState::INTERRUPTED ); - event.AddPoint( point ); - - // First the touch event & related gesture events are queued - mScene.QueueEvent( event ); - - // Next the events are processed with a single call into Core - mCoreEventInterface.ProcessCoreEvents(); -} - void EventHandler::Pause() { mPaused = true; - Reset(); } void EventHandler::Resume() { mPaused = false; - Reset(); -} - -void EventHandler::SetRotationObserver( RotationObserver* observer ) -{ - mRotationObserver = observer; } void EventHandler::OnTouchEvent( Integration::Point& point, uint32_t timeStamp ) { - SendEvent( point, timeStamp ); + for ( ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter ) + { + (*iter)->OnTouchPoint( point, timeStamp ); + } } void EventHandler::OnWheelEvent( WheelEvent& wheelEvent ) { - SendWheelEvent( wheelEvent ); + Integration::WheelEvent event( static_cast< Integration::WheelEvent::Type >(wheelEvent.type), wheelEvent.direction, wheelEvent.modifiers, wheelEvent.point, wheelEvent.z, wheelEvent.timeStamp ); + + for ( ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter ) + { + (*iter)->OnWheelEvent( event ); + } } void EventHandler::OnKeyEvent( Integration::KeyEvent& keyEvent ) { - SendEvent( keyEvent ); + for ( ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter ) + { + (*iter)->OnKeyEvent( keyEvent ); + } } void EventHandler::OnFocusChanged( bool focusIn ) @@ -315,6 +195,14 @@ void EventHandler::OnFocusChanged( bool focusIn ) } } +void EventHandler::OnRotation( const RotationEvent& event ) +{ + for ( ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter ) + { + (*iter)->OnRotation( event ); + } +} + void EventHandler::OnWindowDamaged( const DamageArea& area ) { SendEvent( area ); @@ -612,39 +500,24 @@ void EventHandler::OnAccessibilityNotification( const WindowBase::AccessibilityI #endif } -void EventHandler::ConvertTouchPosition( Integration::Point& point ) +void EventHandler::AddObserver( Observer& observer ) { - Vector2 position = point.GetScreenPosition(); - Vector2 convertedPosition; + ObserverContainer::iterator match ( find(mObservers.begin(), mObservers.end(), &observer) ); - switch( mRotationAngle ) + if ( match == mObservers.end() ) { - case 90: - { - convertedPosition.x = static_cast( mWindowWidth ) - position.y; - convertedPosition.y = position.x; - break; - } - case 180: - { - convertedPosition.x = static_cast( mWindowWidth ) - position.x; - convertedPosition.y = static_cast( mWindowHeight ) - position.y; - break; - } - case 270: - { - convertedPosition.x = position.y; - convertedPosition.y = static_cast( mWindowHeight ) - position.x; - break; - } - default: - { - convertedPosition = position; - break; - } + mObservers.push_back( &observer ); } +} + +void EventHandler::RemoveObserver( Observer& observer ) +{ + ObserverContainer::iterator match ( find(mObservers.begin(), mObservers.end(), &observer) ); - point.SetScreenPosition( convertedPosition ); + if ( match != mObservers.end() ) + { + mObservers.erase( match ); + } } } // namespace Adaptor diff --git a/dali/internal/window-system/common/event-handler.h b/dali/internal/window-system/common/event-handler.h index ed5ad59..795a919 100755 --- a/dali/internal/window-system/common/event-handler.h +++ b/dali/internal/window-system/common/event-handler.h @@ -22,18 +22,13 @@ #include // uint32_t #include -#include -#include -#include #include #include // INTERNAL INCLUDES #include #include -#include #include -#include #include namespace Dali @@ -42,8 +37,10 @@ namespace Dali namespace Integration { -class RenderSurface; -class Scene; +struct Point; +struct KeyEvent; +struct WheelEvent; + } namespace Internal @@ -52,8 +49,8 @@ namespace Internal namespace Adaptor { -class GestureManager; class StyleMonitor; +class WindowRenderSurface; /** * The Event Handler class is responsible for setting up receiving of Ecore events and then converts them @@ -66,41 +63,63 @@ class EventHandler : public ConnectionTracker, public Dali::RefObject public: /** - * Constructor. - * @param[in] scene The scene where events will be sent to. - * @param[in] coreEventInterface Used to send events to Core. - * @param[in] damageObserver The damage observer (to pass damage events to). + * The observer can be overridden in order to listen to the events. */ - EventHandler( Dali::Integration::Scene scene, CoreEventInterface& coreEventInterface, DamageObserver& damageObserver ); + class Observer + { + public: - /** - * Destructor. - */ - ~EventHandler(); + /** + * Deriving classes should override this to be notified when we receive a touch point event. + * @param[in] point The touch point + * @param[in] timeStamp The time stamp + */ + virtual void OnTouchPoint( Dali::Integration::Point& point, int timeStamp ) = 0; - /** - * Feed (Send) touch event to core and gesture manager - * @param[in] touchEvent The touch event holding the touch point information. - */ - void FeedTouchPoint( TouchPoint& point, uint32_t timeStamp ); + /** + * Deriving classes should override this to be notified when we receive a wheel event. + * @param[in] wheelEvent The wheel event + */ + virtual void OnWheelEvent( Dali::Integration::WheelEvent& wheelEvent ) = 0; - /** - * Feed (Send) wheel event to core and gesture manager - * @param[in] wheelEvent The wheel event - */ - void FeedWheelEvent( WheelEvent& wheelEvent ); + /** + * Deriving classes should override this to be notified when we receive a key event. + * @param[in] keyEvent The key event holding the key information. + */ + virtual void OnKeyEvent( Dali::Integration::KeyEvent& keyEvent ) = 0; + + /** + * Deriving classes should override this to be notified when the window is rotated. + * @param[in] rotation The rotation event. + */ + virtual void OnRotation( const RotationEvent& rotation ) = 0; + + protected: + + /** + * Protected Constructor. + */ + Observer() {} + + /** + * Protected virtual destructor. + */ + virtual ~Observer() {} + }; + +public: /** - * Feed (Send) key event to core - * @param[in] keyEvent The key event holding the key information. + * Constructor. + * @param[in] surface The render surface of the window. + * @param[in] damageObserver The damage observer (to pass damage events to). */ - void FeedKeyEvent( KeyEvent& keyEvent ); + EventHandler( WindowRenderSurface* surface, DamageObserver& damageObserver ); /** - * Feed (Send) an event to core - * @param[in] event The event information. + * Destructor. */ - void FeedEvent( Integration::Event& event ); + ~EventHandler(); /** * Called when the adaptor is paused. @@ -113,31 +132,19 @@ public: void Resume(); /** - * Set the rotation observer (note, some adaptors may not have a rotation observer) - * @param[in] observer The rotation observer - */ - void SetRotationObserver( RotationObserver* observer ); - -private: - - /** - * Send touch event to core. - * @param[in] point The touch point information. - * @param[in] timeStamp The time the touch occurred. + * Adds an observer so that we can observe the events. + * @param[in] observer The observer. */ - void SendEvent(Integration::Point& point, uint32_t timeStamp); + void AddObserver( Observer& observer ); /** - * Send key event to core. - * @param[in] keyEvent The KeyEvent to send. + * Removes the observer from the EventHandler. + * @param[in] observer The observer to remove. + * @note Observers should remove themselves when they are destroyed. */ - void SendEvent(Integration::KeyEvent& keyEvent); + void RemoveObserver( Observer& observer ); - /** - * Send wheel event to core. - * @param[in] wheelEvent The wheel event - */ - void SendWheelEvent( WheelEvent& wheelEvent ); +private: /** * Send a style change event to the style monitor. @@ -152,23 +159,6 @@ private: void SendEvent( const DamageArea& area ); /** - * Inform rotation observer of rotation prepare event - * @param[in] rotation The rotation event - */ - void SendRotationPrepareEvent( const RotationEvent& rotation ); - - /** - * Inform rotation observer of rotation prepare event - */ - void SendRotationRequestEvent(); - - /** - * Resets the event handler. - * Called when the adaptor is paused or resumed. - */ - void Reset(); - - /** * Called when a touch event is received. */ void OnTouchEvent( Integration::Point& point, uint32_t timeStamp ); @@ -189,6 +179,12 @@ private: void OnFocusChanged( bool focusIn ); /** + * Called when the window is rotated. + * @param[in] event The rotation event + */ + void OnRotation( const RotationEvent& event ); + + /** * Called when the window is damaged. */ void OnWindowDamaged( const DamageArea& area ); @@ -215,13 +211,6 @@ private: private: - /** - * Convert touch event position - */ - void ConvertTouchPosition( Integration::Point& point ); - -private: - // Undefined EventHandler( const EventHandler& eventHandler ); @@ -230,20 +219,15 @@ private: private: - Dali::Integration::Scene mScene; ///< The scene the event handler is created for. - CoreEventInterface& mCoreEventInterface; ///< Used to send events to Core. - Dali::Integration::TouchEventCombiner mCombiner; ///< Combines multi-touch events. Dali::StyleMonitor mStyleMonitor; ///< Handle to the style monitor, set on construction, to send font size and font change events to. DamageObserver& mDamageObserver; ///< Reference to the DamageObserver, set on construction, to sent damage events to. - RotationObserver* mRotationObserver; ///< Pointer to rotation observer, if present. Dali::AccessibilityAdaptor mAccessibilityAdaptor; ///< Pointer to the accessibility adaptor Dali::ClipboardEventNotifier mClipboardEventNotifier; ///< Pointer to the clipboard event notifier Dali::Clipboard mClipboard;///< Pointer to the clipboard - int mRotationAngle; - int mWindowWidth; - int mWindowHeight; + using ObserverContainer = std::vector; + ObserverContainer mObservers; ///< A list of event observer pointers bool mPaused; ///< The paused state of the adaptor. }; diff --git a/dali/internal/window-system/common/orientation-impl.cpp b/dali/internal/window-system/common/orientation-impl.cpp index c2341eb..70af3c4 100644 --- a/dali/internal/window-system/common/orientation-impl.cpp +++ b/dali/internal/window-system/common/orientation-impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * Copyright (c) 2019 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -68,26 +68,18 @@ Orientation::OrientationSignalType& Orientation::ChangedSignal() return mChangedSignal; } -void Orientation::OnRotationPrepare( const RotationEvent& rotation ) +void Orientation::OnOrientationChange( const RotationEvent& rotation ) { mOrientation = rotation.angle; mWindowWidth = rotation.width; mWindowHeight = rotation.height; -} -void Orientation::OnRotationRequest() -{ // Emit signal if( !mChangedSignal.Empty() ) { Dali::Orientation handle( this ); mChangedSignal.Emit( handle ); } - - if( mWindow != NULL ) - { - mWindow->RotationDone( mOrientation, mWindowWidth, mWindowHeight ); - } } } // namespace Adaptor diff --git a/dali/internal/window-system/common/orientation-impl.h b/dali/internal/window-system/common/orientation-impl.h index 65d02ea..2b16f2e 100644 --- a/dali/internal/window-system/common/orientation-impl.h +++ b/dali/internal/window-system/common/orientation-impl.h @@ -25,7 +25,7 @@ // INTERNAL INCLUDES #include -#include +#include namespace Dali { @@ -40,7 +40,7 @@ class Orientation; typedef IntrusivePtr OrientationPtr; -class Orientation : public BaseObject, public RotationObserver +class Orientation : public BaseObject { public: @@ -73,6 +73,12 @@ public: */ float GetRadians() const; + /** + * Called by the Window when orientation is changed + * @param[in] rotation The rotation event + */ + void OnOrientationChange( const RotationEvent& rotation ); + public: // Signals /** @@ -81,27 +87,12 @@ public: // Signals OrientationSignalType& ChangedSignal(); private: - /** - * @copydoc Dali::Internal::Adaptor::RotationObserver::OnRotationPrepare() - */ - virtual void OnRotationPrepare( const RotationEvent& rotation ); - - /** - * @copydoc Dali::Internal::Adaptor::RotationObserver::OnRotationRequest() - */ - virtual void OnRotationRequest( ); // Undefined Orientation(const Orientation&); Orientation& operator=(Orientation&); private: - /** - * Signals and sends event of orientation change. - */ - void EmitOrientationChange(); - -private: Window* mWindow; diff --git a/dali/internal/window-system/common/rotation-observer.h b/dali/internal/window-system/common/rotation-event.h similarity index 54% rename from dali/internal/window-system/common/rotation-observer.h rename to dali/internal/window-system/common/rotation-event.h index 46ad874..4972eff 100644 --- a/dali/internal/window-system/common/rotation-observer.h +++ b/dali/internal/window-system/common/rotation-event.h @@ -1,5 +1,5 @@ -#ifndef DALI_INTERNAL_ROTATION_OBSERVER_H -#define DALI_INTERNAL_ROTATION_OBSERVER_H +#ifndef DALI_INTERNAL_ROTATION_EVENT_H +#define DALI_INTERNAL_ROTATION_EVENT_H /* * Copyright (c) 2019 Samsung Electronics Co., Ltd. @@ -37,46 +37,10 @@ struct RotationEvent int height; ///< new window height }; - -/** - * The RotationObserver can be overridden in order to listen to rotation events. - */ -class RotationObserver -{ -public: - - /** - * Deriving classes should override this to be notified when we receive a RotationPrepare event. - * @param[in] area The area that has been rotationd. - */ - virtual void OnRotationPrepare( const RotationEvent& rotation ) = 0; - - /** - * Deriving classes should override this to be notifed when a RotationRequest event is received - */ - virtual void OnRotationRequest( ) = 0; - -protected: - - /** - * Protected Constructor. - */ - RotationObserver() - { - } - - /** - * Protected virtual destructor. - */ - virtual ~RotationObserver() - { - } -}; - } // namespace Adaptor } // namespace Internal } // namespace Dali -#endif // DALI_INTERNAL_ROTATION_OBSERVER_H +#endif // DALI_INTERNAL_ROTATION_EVENT_H diff --git a/dali/internal/window-system/common/window-base.h b/dali/internal/window-system/common/window-base.h index e93287e..165a69a 100644 --- a/dali/internal/window-system/common/window-base.h +++ b/dali/internal/window-system/common/window-base.h @@ -18,14 +18,6 @@ * */ -// INTERNAL INCLUDES -#include -#include -#include -#include -#include -#include - // EXTERNAL INCLUDES #include #include @@ -34,6 +26,14 @@ #include #include +// INTERNAL INCLUDES +#include +#include +#include +#include +#include +#include + namespace Dali { namespace Internal diff --git a/dali/internal/window-system/common/window-impl.cpp b/dali/internal/window-system/common/window-impl.cpp index 443f86a..0ede554 100644 --- a/dali/internal/window-system/common/window-impl.cpp +++ b/dali/internal/window-system/common/window-impl.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #ifdef DALI_ADAPTOR_COMPILATION #include @@ -78,6 +79,9 @@ Window::Window() mResizeEnabled( false ), mType( Dali::Window::NORMAL ), mPreferredOrientation( Dali::Window::PORTRAIT ), + mRotationAngle( 0 ), + mWindowWidth( 0 ), + mWindowHeight( 0 ), mFocusChangedSignal(), mResizedSignal(), mDeleteRequestSignal() @@ -88,7 +92,7 @@ Window::~Window() { if ( mEventHandler ) { - mEventHandler->SetRotationObserver( nullptr ); + mEventHandler->RemoveObserver( *this ); } } @@ -125,13 +129,8 @@ void Window::Initialize(const PositionSize& positionSize, const std::string& nam void Window::OnAdaptorSet(Dali::Adaptor& adaptor) { - mEventHandler = EventHandlerPtr(new EventHandler( mScene, *mAdaptor, *mAdaptor ) ); - - // TODO: Orientation should be passed into the constructor of EventHandler - if( mOrientation ) - { - SetRotationObserver( &(*mOrientation) ); - } + mEventHandler = EventHandlerPtr(new EventHandler( mWindowSurface, *mAdaptor ) ); + mEventHandler->AddObserver( *this ); } void Window::OnSurfaceSet( Dali::RenderSurfaceInterface* surface ) @@ -537,18 +536,6 @@ bool Window::UngrabKeyList( const Dali::Vector< Dali::KEY >& key, Dali::Vector< return mWindowBase->UngrabKeyList( key, result ); } -void Window::RotationDone( int orientation, int width, int height ) -{ - mWindowSurface->RequestRotation( orientation, width, height ); - - mAdaptor->SurfaceResizePrepare( mSurface.get(), Adaptor::SurfaceSize( width, height ) ); - - // Emit signal - mResizedSignal.Emit( Dali::Window::WindowSize( width, height ) ); - - mAdaptor->SurfaceResizeComplete( mSurface.get(), Adaptor::SurfaceSize( width, height ) ); -} - void Window::OnIconifyChanged( bool iconified ) { if( iconified ) @@ -594,28 +581,38 @@ void Window::OnDeleteRequest() mDeleteRequestSignal.Emit(); } -void Window::FeedTouchPoint( TouchPoint& point, int timeStamp ) +void Window::OnTouchPoint( Dali::Integration::Point& point, int timeStamp ) { - if( mEventHandler ) - { - mEventHandler->FeedTouchPoint( point, timeStamp ); - } + FeedTouchPoint( point, timeStamp ); } -void Window::FeedWheelEvent( WheelEvent& wheelEvent ) +void Window::OnWheelEvent( Dali::Integration::WheelEvent& wheelEvent ) { - if( mEventHandler ) - { - mEventHandler->FeedWheelEvent( wheelEvent ); - } + FeedWheelEvent( wheelEvent ); } -void Window::FeedKeyEvent( KeyEvent& keyEvent ) +void Window::OnKeyEvent( Dali::Integration::KeyEvent& keyEvent ) { - if( mEventHandler ) - { - mEventHandler->FeedKeyEvent( keyEvent ); - } + FeedKeyEvent( keyEvent ); +} + +void Window::OnRotation( const RotationEvent& rotation ) +{ + mRotationAngle = rotation.angle; + mWindowWidth = rotation.width; + mWindowHeight = rotation.height; + + // Notify that the orientation is changed + mOrientation->OnOrientationChange( rotation ); + + mWindowSurface->RequestRotation( mRotationAngle, mWindowWidth, mWindowHeight ); + + mAdaptor->SurfaceResizePrepare( mSurface.get(), Adaptor::SurfaceSize( mRotationAngle, mWindowHeight ) ); + + // Emit signal + mResizedSignal.Emit( Dali::Window::WindowSize( mRotationAngle, mWindowHeight ) ); + + mAdaptor->SurfaceResizeComplete( mSurface.get(), Adaptor::SurfaceSize( mRotationAngle, mWindowHeight ) ); } void Window::OnPause() @@ -634,15 +631,39 @@ void Window::OnResume() } } -bool Window::SetRotationObserver( RotationObserver* observer ) +void Window::RecalculateTouchPosition( Integration::Point& point ) { - if( mEventHandler ) + Vector2 position = point.GetScreenPosition(); + Vector2 convertedPosition; + + switch( mRotationAngle ) { - mEventHandler->SetRotationObserver( observer ); - return true; + case 90: + { + convertedPosition.x = static_cast( mWindowWidth ) - position.y; + convertedPosition.y = position.x; + break; + } + case 180: + { + convertedPosition.x = static_cast( mWindowWidth ) - position.x; + convertedPosition.y = static_cast( mWindowHeight ) - position.y; + break; + } + case 270: + { + convertedPosition.x = position.y; + convertedPosition.y = static_cast( mWindowHeight ) - position.x; + break; + } + default: + { + convertedPosition = position; + break; + } } - return false; + point.SetScreenPosition( convertedPosition ); } Dali::Window Window::Get( Dali::Actor actor ) diff --git a/dali/internal/window-system/common/window-impl.h b/dali/internal/window-system/common/window-impl.h index 85f5a8f..b4dd829 100644 --- a/dali/internal/window-system/common/window-impl.h +++ b/dali/internal/window-system/common/window-impl.h @@ -35,6 +35,7 @@ #include #include #include +#include namespace Dali { @@ -46,9 +47,7 @@ namespace Internal { namespace Adaptor { -class EventHandler; class Orientation; -class RotationObserver; class WindowRenderSurface; class WindowBase; @@ -60,7 +59,7 @@ using EventHandlerPtr = IntrusivePtr< EventHandler >; /** * Window provides a surface to render onto with orientation & indicator properties. */ -class Window : public Dali::Internal::Adaptor::SceneHolder, public ConnectionTracker +class Window : public Dali::Internal::Adaptor::SceneHolder, public EventHandler::Observer, public ConnectionTracker { public: typedef Dali::Window::IndicatorSignalType IndicatorSignalType; @@ -325,18 +324,6 @@ public: bool UngrabKeyList( const Dali::Vector< Dali::KEY >& key, Dali::Vector< bool >& result ); /** - * Called from Orientation after the Change signal has been sent - */ - void RotationDone( int orientation, int width, int height ); - - /** - * Set the rotation observer (note, some adaptors may not have a rotation observer) - * @param[in] observer The rotation observer - * @return If the rotation observer is set - */ - bool SetRotationObserver( RotationObserver* observer ); - - /** * @copydoc Dali::DevelWindow::Get() */ static Dali::Window Get( Dali::Actor actor ); @@ -394,39 +381,51 @@ private: private: // Dali::Internal::Adaptor::SceneHolder /** - * @copydoc Dali::Internal::Adaptor::SceneHolder::FeedTouchPoint + * @copydoc Dali::Internal::Adaptor::SceneHolder::OnAdaptorSet */ - void FeedTouchPoint( TouchPoint& point, int timeStamp ) override; + void OnAdaptorSet( Dali::Adaptor& adaptor ) override; /** - * @copydoc Dali::Internal::Adaptor::SceneHolder::FeedWheelEvent + * @copydoc Dali::Internal::Adaptor::SceneHolder::OnSurfaceSet */ - void FeedWheelEvent( WheelEvent& wheelEvent ) override; + void OnSurfaceSet( Dali::RenderSurfaceInterface* surface ) override; /** - * @copydoc Dali::Internal::Adaptor::SceneHolder::FeedKeyEvent + * @copydoc Dali::Internal::Adaptor::SceneHolder::OnPause */ - void FeedKeyEvent( KeyEvent& keyEvent ) override; + void OnPause() override; /** - * @copydoc Dali::Internal::Adaptor::SceneHolder::OnAdaptorSet + * @copydoc Dali::Internal::Adaptor::SceneHolder::OnResume */ - void OnAdaptorSet( Dali::Adaptor& adaptor ) override; + void OnResume() override; /** - * @copydoc Dali::Internal::Adaptor::SceneHolder::OnSurfaceSet + * @copydoc Dali::Internal::Adaptor::SceneHolder::RecalculateTouchPosition */ - void OnSurfaceSet( Dali::RenderSurfaceInterface* surface ) override; + void RecalculateTouchPosition( Integration::Point& point ) override; + +private: // Dali::Internal::Adaptor::EventHandler::Observer /** - * @copydoc Dali::Internal::Adaptor::SceneHolder::OnPause + * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnTouchPoint */ - void OnPause() override; + void OnTouchPoint( Dali::Integration::Point& point, int timeStamp ) override; /** - * @copydoc Dali::Internal::Adaptor::SceneHolder::OnResume + * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnWheelEvent */ - void OnResume() override; + void OnWheelEvent( Dali::Integration::WheelEvent& wheelEvent ) override; + + /** + * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnKeyEvent + */ + void OnKeyEvent( Dali::Integration::KeyEvent& keyEvent ) override; + + /** + * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnRotation + */ + void OnRotation( const RotationEvent& rotation ) override; public: // Signals @@ -487,6 +486,10 @@ private: std::vector mAvailableOrientations; Dali::Window::WindowOrientation mPreferredOrientation; + int mRotationAngle; ///< The angle of the rotation + int mWindowWidth; ///< The width of the window + int mWindowHeight; ///< The height of the window + EventHandlerPtr mEventHandler; ///< The window events handler // Signals diff --git a/dali/public-api/adaptor-framework/window.cpp b/dali/public-api/adaptor-framework/window.cpp index 4fc941b..2e6a28c 100644 --- a/dali/public-api/adaptor-framework/window.cpp +++ b/dali/public-api/adaptor-framework/window.cpp @@ -23,7 +23,6 @@ // INTERNAL INCLUDES #include -#include #include #include -- 2.7.4