/*
- * Copyright (c) 2018 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.
#include <cstring>
#include <sys/time.h>
-#include <dali/public-api/events/touch-point.h>
+#include <dali/devel-api/events/touch-point.h>
#include <dali/public-api/events/key-event.h>
#include <dali/public-api/events/wheel-event.h>
#include <dali/integration-api/debug.h>
#include <dali/integration-api/events/wheel-event-integ.h>
// INTERNAL INCLUDES
-#include <dali/internal/input/common/gesture-manager.h>
#include <dali/internal/clipboard/common/clipboard-impl.h>
-#include <dali/internal/input/common/key-impl.h>
-#include <dali/internal/input/common/physical-keyboard-impl.h>
#include <dali/internal/styling/common/style-monitor-impl.h>
#include <dali/internal/window-system/common/window-render-surface.h>
#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
{
+static constexpr auto QUICKPANEL_TYPE_SYSTEM_DEFAULT = 1;
+static constexpr auto QUICKPANEL_TYPE_APPS_MENU = 3;
+
// Copied from x server
-static unsigned int GetCurrentMilliSeconds(void)
+static uint32_t GetCurrentMilliSeconds(void)
{
struct timeval tv;
}
if (clockid != ~0L && clock_gettime(clockid, &tp) == 0)
{
- return (tp.tv_sec * 1000) + (tp.tv_nsec / 1000000L);
+ return static_cast<uint32_t>( (tp.tv_sec * 1000 ) + (tp.tv_nsec / 1000000L) );
}
gettimeofday(&tv, NULL);
- return (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
+ return static_cast<uint32_t>( (tv.tv_sec * 1000 ) + (tv.tv_usec / 1000) );
}
} // unnamed namespace
+#endif
-EventHandler::EventHandler( RenderSurface* surface, CoreEventInterface& coreEventInterface, GestureManager& gestureManager, DamageObserver& damageObserver, DragAndDropDetectorPtr dndDetector )
-: mCoreEventInterface( coreEventInterface ),
- mGestureManager( gestureManager ),
- mStyleMonitor( StyleMonitor::Get() ),
+EventHandler::EventHandler( WindowBase* windowBase, DamageObserver& damageObserver )
+: mStyleMonitor( StyleMonitor::Get() ),
mDamageObserver( damageObserver ),
- mRotationObserver( NULL ),
- mDragAndDropDetector( dndDetector ),
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* >( surface );
- 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 );
windowBase->SelectionDataReceivedSignal().Connect( this, &EventHandler::OnSelectionDataReceived );
windowBase->StyleChangedSignal().Connect( this, &EventHandler::OnStyleChanged );
windowBase->AccessibilitySignal().Connect( this, &EventHandler::OnAccessibilityNotification );
+ windowBase->QuickPanelSignal().Connect( this, &EventHandler::OnAccessibilityQuickpanelChanged );
}
-}
-
-EventHandler::~EventHandler()
-{
- mGestureManager.Stop();
-}
-
-void EventHandler::SendEvent(Integration::Point& point, unsigned long 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)
- {
- mCoreEventInterface.QueueCoreEvent( touchEvent );
- mGestureManager.SendEvent(touchEvent);
- }
-
- if(type == Integration::TouchEventCombiner::DispatchHover || type == Integration::TouchEventCombiner::DispatchBoth)
- {
- mCoreEventInterface.QueueCoreEvent( 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.
- mCoreEventInterface.QueueCoreEvent( 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 );
- mCoreEventInterface.QueueCoreEvent( event );
- mCoreEventInterface.ProcessCoreEvents();
}
void EventHandler::SendEvent( StyleChange::Type styleChange )
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, int 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 )
-{
- mCoreEventInterface.QueueCoreEvent( 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
- mCoreEventInterface.QueueCoreEvent( event );
- mGestureManager.SendEvent( 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::SetDragAndDropDetector( DragAndDropDetectorPtr detector )
-{
- mDragAndDropDetector = detector;
-}
-
-void EventHandler::SetRotationObserver( RotationObserver* observer )
-{
- mRotationObserver = observer;
}
-void EventHandler::OnTouchEvent( Integration::Point& point, unsigned long timeStamp )
+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 )
}
}
+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 );
return;
}
+ if( !accessibilityAdaptor->IsEnabled() )
+ {
+ DALI_LOG_ERROR( "The current dali accessibility is not available. \n" );
+ return;
+ }
+
+ if( ( info.quickpanelInfo & ( 1 << QUICKPANEL_TYPE_SYSTEM_DEFAULT ) ) && ( info.quickpanelInfo & ( 1 << QUICKPANEL_TYPE_APPS_MENU ) ) )
+ {
+ DALI_LOG_ERROR("Quickpanel is top now, so all dali apps should be stopped \n");
+ return;
+ }
+
// 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.
case 20: // TwoFingersTripleTap
{
// Read information from indicator
- accessibilityAdaptor->HandleActionReadIndicatorInformationEvent();
+ // Not supported
break;
}
case 21: // ThreeFingersSingleTap
#endif
}
-void EventHandler::ConvertTouchPosition( Integration::Point& point )
+void EventHandler::OnAccessibilityQuickpanelChanged( const unsigned char& info )
{
- Vector2 position = point.GetScreenPosition();
- Vector2 convertedPosition;
+#ifdef DALI_ELDBUS_AVAILABLE
+ if( mPaused )
+ {
+ return;
+ }
- switch( mRotationAngle )
+ if( !mAccessibilityAdaptor )
{
- case 90:
- {
- convertedPosition.x = mWindowWidth - position.y;
- convertedPosition.y = position.x;
- break;
- }
- case 180:
- {
- convertedPosition.x = mWindowWidth - position.x;
- convertedPosition.y = mWindowHeight - position.y;
- break;
- }
- case 270:
+ DALI_LOG_ERROR( "Invalid accessibility adaptor\n" );
+ return;
+ }
+
+ AccessibilityAdaptor* accessibilityAdaptor( &AccessibilityAdaptor::GetImplementation( mAccessibilityAdaptor ) );
+ if( !accessibilityAdaptor )
+ {
+ DALI_LOG_ERROR( "Cannot access accessibility adaptor\n" );
+ return;
+ }
+
+ if( ( ( info & ( 1 << QUICKPANEL_TYPE_SYSTEM_DEFAULT ) ) && ( info & ( 1 << QUICKPANEL_TYPE_APPS_MENU ) ) ) || // Both QuickPanel and Apps are shown
+ ( info & ( 1 << QUICKPANEL_TYPE_SYSTEM_DEFAULT ) ) ) // QuickPanel is shown
+ {
+ // dali apps should be disabled.
+ DALI_LOG_INFO( gSelectionEventLogFilter, Debug::General, "OnAccessibilityQuickpanelChanged: Quickpanel show -> DisableAccessibility \n" );
+ accessibilityAdaptor->DisableAccessibility();
+ }
+ else if( info & ( 1 << QUICKPANEL_TYPE_APPS_MENU ) ) // Only Apps menu (dali application) is shown
+ {
+ if( !accessibilityAdaptor->IsForcedEnable() ) // It is not in case of that an application controls the accessibility status itself
{
- convertedPosition.x = position.y;
- convertedPosition.y = mWindowHeight - position.x;
- break;
+ DALI_LOG_INFO( gSelectionEventLogFilter, Debug::General, "OnAccessibilityQuickpanelChanged: Only Apps show, but not forced dali -> DisableAccessibility \n" );
+ accessibilityAdaptor->DisableAccessibility();
}
- default:
+ else
{
- convertedPosition = position;
- break;
+ DALI_LOG_INFO( gSelectionEventLogFilter, Debug::General, "OnAccessibilityQuickpanelChanged: Only Apps show and it is a forced dali -> EnableAccessibility \n" );
+ accessibilityAdaptor->EnableAccessibility();
}
}
+ else
+ {
+ DALI_LOG_INFO( gSelectionEventLogFilter, Debug::General, "OnAccessibilityQuickpanelChanged: Nothing shows -> EnableAccessibility \n" );
+ // dali app should be enabled.
+ accessibilityAdaptor->EnableAccessibility();
+ }
+
+#endif
+}
+
+void EventHandler::AddObserver( Observer& observer )
+{
+ ObserverContainer::iterator match ( find(mObservers.begin(), mObservers.end(), &observer) );
- point.SetScreenPosition( convertedPosition );
+ if ( match == mObservers.end() )
+ {
+ mObservers.push_back( &observer );
+ }
+}
+
+void EventHandler::RemoveObserver( Observer& observer )
+{
+ ObserverContainer::iterator match ( find(mObservers.begin(), mObservers.end(), &observer) );
+
+ if ( match != mObservers.end() )
+ {
+ mObservers.erase( match );
+ }
}
} // namespace Adaptor