X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali%2Finternal%2Fwindow-system%2Fcommon%2Fevent-handler.cpp;h=911a3bdafcd3d34e2c6f14e15c1c235f5867b720;hb=389cecd224ef9c24793f78eb48af08e54b31e5c9;hp=1cfab481b086a08a0388dbc158c0546043bd2c00;hpb=b7c45bdf0893f8797006ff5002837ebd39106d02;p=platform%2Fcore%2Fuifw%2Fdali-adaptor.git diff --git a/dali/internal/window-system/common/event-handler.cpp b/dali/internal/window-system/common/event-handler.cpp index 1cfab48..911a3bd 100755 --- a/dali/internal/window-system/common/event-handler.cpp +++ b/dali/internal/window-system/common/event-handler.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 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. @@ -22,7 +22,7 @@ #include #include -#include +#include #include #include #include @@ -30,13 +30,9 @@ #include #include #include -#include // INTERNAL INCLUDES -#include #include -#include -#include #include #include @@ -52,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 { @@ -97,32 +93,22 @@ static uint32_t GetCurrentMilliSeconds(void) } } // unnamed namespace +#endif -EventHandler::EventHandler( Dali::Integration::Scene scene, CoreEventInterface& coreEventInterface, GestureManager& gestureManager, DamageObserver& damageObserver ) -: mScene( scene ), - mCoreEventInterface( coreEventInterface ), - mGestureManager( gestureManager ), - mStyleMonitor( StyleMonitor::Get() ), +EventHandler::EventHandler( WindowBase* windowBase, 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 ) + // Connect signals + if( windowBase ) { - WindowBase* windowBase = windowRenderSurface->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 ); @@ -131,68 +117,14 @@ EventHandler::EventHandler( Dali::Integration::Scene scene, CoreEventInterface& windowBase->StyleChangedSignal().Connect( this, &EventHandler::OnStyleChanged ); windowBase->AccessibilitySignal().Connect( this, &EventHandler::OnAccessibilityNotification ); } -} - -EventHandler::~EventHandler() -{ - mGestureManager.Stop(); -} - -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 ); - mGestureManager.SendEvent( mScene, 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 ) + else { - if( ! KeyLookup::IsDeviceButton( keyEvent.keyName.c_str() ) ) - { - GetImplementation( physicalKeyboard ).KeyReceived( keyEvent.time > 1 ); - } + DALI_LOG_ERROR("WindowBase is invalid!!!\n"); } - - // Create send KeyEvent to Core. - mScene.QueueEvent( keyEvent ); - mCoreEventInterface.ProcessCoreEvents(); } -void EventHandler::SendWheelEvent( WheelEvent& wheelEvent ) +EventHandler::~EventHandler() { - // 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 ) @@ -206,96 +138,38 @@ 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 ); - - mGestureManager.SendEvent( mScene, 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 ) +void EventHandler::OnWheelEvent( Integration::WheelEvent& wheelEvent ) { - SendWheelEvent( wheelEvent ); + for ( ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter ) + { + (*iter)->OnWheelEvent( wheelEvent ); + } } 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 ) @@ -321,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 ); @@ -386,22 +268,22 @@ void EventHandler::OnAccessibilityNotification( const WindowBase::AccessibilityI } // Create a touch point object. - TouchPoint::State touchPointState( TouchPoint::Down ); + PointState::Type touchPointState( PointState::DOWN ); if( info.state == 0 ) { - touchPointState = TouchPoint::Down; // Mouse down. + touchPointState = PointState::DOWN; // Mouse down. } else if( info.state == 1 ) { - touchPointState = TouchPoint::Motion; // Mouse move. + touchPointState = PointState::MOTION; // Mouse move. } else if( info.state == 2 ) { - touchPointState = TouchPoint::Up; // Mouse up. + touchPointState = PointState::UP; // Mouse up. } else { - touchPointState = TouchPoint::Interrupted; // Error. + touchPointState = PointState::INTERRUPTED; // Error. } // Send touch event to accessibility adaptor. @@ -618,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