2 * Copyright (c) 2020 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 <dali/internal/window-system/common/event-handler.h>
25 #include <dali/devel-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>
35 #include <dali/internal/clipboard/common/clipboard-impl.h>
36 #include <dali/internal/styling/common/style-monitor-impl.h>
37 #include <dali/internal/window-system/common/window-render-surface.h>
48 #if defined(DEBUG_ENABLED)
51 Integration::Log::Filter* gSelectionEventLogFilter = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_SELECTION");
52 } // unnamed namespace
55 #ifdef DALI_ELDBUS_AVAILABLE
59 static constexpr auto QUICKPANEL_TYPE_SYSTEM_DEFAULT = 1;
60 static constexpr auto QUICKPANEL_TYPE_APPS_MENU = 3;
62 // Copied from x server
63 static uint32_t GetCurrentMilliSeconds(void)
68 static clockid_t clockid;
72 #ifdef CLOCK_MONOTONIC_COARSE
73 if (clock_getres(CLOCK_MONOTONIC_COARSE, &tp) == 0 &&
74 (tp.tv_nsec / 1000) <= 1000 && clock_gettime(CLOCK_MONOTONIC_COARSE, &tp) == 0)
76 clockid = CLOCK_MONOTONIC_COARSE;
80 if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0)
82 clockid = CLOCK_MONOTONIC;
89 if (clockid != ~0L && clock_gettime(clockid, &tp) == 0)
91 return static_cast<uint32_t>( (tp.tv_sec * 1000 ) + (tp.tv_nsec / 1000000L) );
94 gettimeofday(&tv, NULL);
95 return static_cast<uint32_t>( (tv.tv_sec * 1000 ) + (tv.tv_usec / 1000) );
98 } // unnamed namespace
101 EventHandler::EventHandler( WindowBase* windowBase, DamageObserver& damageObserver )
102 : mStyleMonitor( StyleMonitor::Get() ),
103 mDamageObserver( damageObserver ),
104 mAccessibilityAdaptor( AccessibilityAdaptor::Get() ),
105 mClipboardEventNotifier( ClipboardEventNotifier::Get() ),
106 mClipboard( Clipboard::Get() ),
112 windowBase->WindowDamagedSignal().Connect( this, &EventHandler::OnWindowDamaged );
113 windowBase->FocusChangedSignal().Connect( this, &EventHandler::OnFocusChanged );
114 windowBase->RotationSignal().Connect( this, &EventHandler::OnRotation );
115 windowBase->TouchEventSignal().Connect( this, &EventHandler::OnTouchEvent );
116 windowBase->WheelEventSignal().Connect( this, &EventHandler::OnWheelEvent );
117 windowBase->KeyEventSignal().Connect( this, &EventHandler::OnKeyEvent );
118 windowBase->SelectionDataSendSignal().Connect( this, &EventHandler::OnSelectionDataSend );
119 windowBase->SelectionDataReceivedSignal().Connect( this, &EventHandler::OnSelectionDataReceived );
120 windowBase->StyleChangedSignal().Connect( this, &EventHandler::OnStyleChanged );
121 windowBase->AccessibilitySignal().Connect( this, &EventHandler::OnAccessibilityNotification );
122 windowBase->QuickPanelSignal().Connect( this, &EventHandler::OnAccessibilityQuickpanelChanged );
126 DALI_LOG_ERROR("WindowBase is invalid!!!\n");
130 EventHandler::~EventHandler()
134 void EventHandler::SendEvent( StyleChange::Type styleChange )
136 DALI_ASSERT_DEBUG( mStyleMonitor && "StyleMonitor Not Available" );
137 GetImplementation( mStyleMonitor ).StyleChanged(styleChange);
140 void EventHandler::SendEvent( const DamageArea& area )
142 mDamageObserver.OnDamaged( area );
145 void EventHandler::Pause()
150 void EventHandler::Resume()
155 void EventHandler::OnTouchEvent( Integration::Point& point, uint32_t timeStamp )
157 for ( ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter )
159 (*iter)->OnTouchPoint( point, timeStamp );
163 void EventHandler::OnWheelEvent( Integration::WheelEvent& wheelEvent )
165 for ( ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter )
167 (*iter)->OnWheelEvent( wheelEvent );
171 void EventHandler::OnKeyEvent( Integration::KeyEvent& keyEvent )
173 for ( ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter )
175 (*iter)->OnKeyEvent( keyEvent );
179 void EventHandler::OnFocusChanged( bool focusIn )
181 // If the window gains focus and we hid the keyboard then show it again.
184 Dali::Clipboard clipboard = Clipboard::Get();
187 clipboard.HideClipboard();
192 // Hiding clipboard event will be ignored once because window focus out event is always received on showing clipboard
193 Dali::Clipboard clipboard = Clipboard::Get();
196 Clipboard& clipBoardImpl( GetImplementation( clipboard ) );
197 clipBoardImpl.HideClipboard(true);
202 void EventHandler::OnRotation( const RotationEvent& event )
204 for ( ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter )
206 (*iter)->OnRotation( event );
210 void EventHandler::OnWindowDamaged( const DamageArea& area )
215 void EventHandler::OnSelectionDataSend( void* event )
217 Dali::Clipboard clipboard = Clipboard::Get();
220 Clipboard& clipBoardImpl( GetImplementation( clipboard ) );
221 clipBoardImpl.ExcuteBuffered( true, event );
225 void EventHandler::OnSelectionDataReceived( void* event )
227 // We have got the selected content, inform the clipboard event listener (if we have one).
228 Dali::Clipboard clipboard = Clipboard::Get();
229 char* selectionData = NULL;
232 Clipboard& clipBoardImpl( GetImplementation( clipboard ) );
233 selectionData = clipBoardImpl.ExcuteBuffered( false, event );
236 if( selectionData && mClipboardEventNotifier )
238 ClipboardEventNotifier& clipboardEventNotifier( ClipboardEventNotifier::GetImplementation( mClipboardEventNotifier ) );
239 std::string content( selectionData, strlen( selectionData ) );
241 clipboardEventNotifier.SetContent( content );
242 clipboardEventNotifier.EmitContentSelectedSignal();
244 DALI_LOG_INFO( gSelectionEventLogFilter, Debug::General, "EcoreEventSelectionNotify: Content(%d): %s\n" , strlen(selectionData), selectionData );
248 void EventHandler::OnStyleChanged( StyleChange::Type styleChange )
250 SendEvent( styleChange );
253 void EventHandler::OnAccessibilityNotification( const WindowBase::AccessibilityInfo& info )
255 #ifdef DALI_ELDBUS_AVAILABLE
261 if( !mAccessibilityAdaptor )
263 DALI_LOG_ERROR( "Invalid accessibility adaptor\n" );
267 AccessibilityAdaptor* accessibilityAdaptor( &AccessibilityAdaptor::GetImplementation( mAccessibilityAdaptor ) );
268 if( !accessibilityAdaptor )
270 DALI_LOG_ERROR( "Cannot access accessibility adaptor\n" );
274 if( !accessibilityAdaptor->IsEnabled() )
276 DALI_LOG_ERROR( "The current dali accessibility is not available. \n" );
280 if( ( info.quickpanelInfo & ( 1 << QUICKPANEL_TYPE_SYSTEM_DEFAULT ) ) && ( info.quickpanelInfo & ( 1 << QUICKPANEL_TYPE_APPS_MENU ) ) )
282 DALI_LOG_ERROR("Quickpanel is top now, so all dali apps should be stopped \n");
286 // Create a touch point object.
287 PointState::Type touchPointState( PointState::DOWN );
288 if( info.state == 0 )
290 touchPointState = PointState::DOWN; // Mouse down.
292 else if( info.state == 1 )
294 touchPointState = PointState::MOTION; // Mouse move.
296 else if( info.state == 2 )
298 touchPointState = PointState::UP; // Mouse up.
302 touchPointState = PointState::INTERRUPTED; // Error.
305 // Send touch event to accessibility adaptor.
306 TouchPoint point( 0, touchPointState, static_cast< float >( info.startX ), static_cast< float >( info.startY ) );
308 // Perform actions based on received gestures.
309 // Note: This is seperated from the reading so we can have other input readers without changing the below code.
310 switch( info.gestureValue )
312 case 0: // OneFingerHover
315 accessibilityAdaptor->HandleActionReadEvent( static_cast< unsigned int >( info.startX ), static_cast< unsigned int >( info.startY ), true /* allow read again */ );
318 case 1: // TwoFingersHover
320 // In accessibility mode, scroll action should be handled when the currently focused actor is contained in scrollable control
321 accessibilityAdaptor->HandleActionScrollEvent( point, GetCurrentMilliSeconds() );
324 case 2: // ThreeFingersHover
326 // Read from top item on screen continuously.
327 accessibilityAdaptor->HandleActionReadFromTopEvent();
330 case 3: // OneFingerFlickLeft
332 // Move to previous item.
333 accessibilityAdaptor->HandleActionReadPreviousEvent();
336 case 4: // OneFingerFlickRight
338 // Move to next item.
339 accessibilityAdaptor->HandleActionReadNextEvent();
342 case 5: // OneFingerFlickUp
344 // Move to previous item.
345 accessibilityAdaptor->HandleActionPreviousEvent();
348 case 6: // OneFingerFlickDown
350 // Move to next item.
351 accessibilityAdaptor->HandleActionNextEvent();
354 case 7: // TwoFingersFlickUp
356 // Scroll up the list.
357 accessibilityAdaptor->HandleActionScrollUpEvent();
360 case 8: // TwoFingersFlickDown
362 // Scroll down the list.
363 accessibilityAdaptor->HandleActionScrollDownEvent();
366 case 9: // TwoFingersFlickLeft
368 // Scroll left to the previous page
369 accessibilityAdaptor->HandleActionPageLeftEvent();
372 case 10: // TwoFingersFlickRight
374 // Scroll right to the next page
375 accessibilityAdaptor->HandleActionPageRightEvent();
378 case 11: // ThreeFingersFlickLeft
383 case 12: // ThreeFingersFlickRight
388 case 13: // ThreeFingersFlickUp
393 case 14: // ThreeFingersFlickDown
398 case 15: // OneFingerSingleTap
401 accessibilityAdaptor->HandleActionReadEvent( static_cast< unsigned int >( info.startX ), static_cast< unsigned int >( info.startY ), true /* allow read again */ );
404 case 16: // OneFingerDoubleTap
406 // Activate selected item / active edit mode.
407 accessibilityAdaptor->HandleActionActivateEvent();
410 case 17: // OneFingerTripleTap
413 accessibilityAdaptor->HandleActionZoomEvent();
416 case 18: // TwoFingersSingleTap
418 // Pause/Resume current speech
419 accessibilityAdaptor->HandleActionReadPauseResumeEvent();
422 case 19: // TwoFingersDoubleTap
424 // Start/Stop current action
425 accessibilityAdaptor->HandleActionStartStopEvent();
428 case 20: // TwoFingersTripleTap
430 // Read information from indicator
434 case 21: // ThreeFingersSingleTap
436 // Read from top item on screen continuously.
437 accessibilityAdaptor->HandleActionReadFromTopEvent();
440 case 22: // ThreeFingersDoubleTap
442 // Read from next item continuously.
443 accessibilityAdaptor->HandleActionReadFromNextEvent();
446 case 23: // ThreeFingersTripleTap
451 case 24: // OneFingerFlickLeftReturn
453 // Scroll up to the previous page
454 accessibilityAdaptor->HandleActionPageUpEvent();
457 case 25: // OneFingerFlickRightReturn
459 // Scroll down to the next page
460 accessibilityAdaptor->HandleActionPageDownEvent();
463 case 26: // OneFingerFlickUpReturn
465 // Move to the first item on screen
466 accessibilityAdaptor->HandleActionMoveToFirstEvent();
469 case 27: // OneFingerFlickDownReturn
471 // Move to the last item on screen
472 accessibilityAdaptor->HandleActionMoveToLastEvent();
475 case 28: // TwoFingersFlickLeftReturn
480 case 29: // TwoFingersFlickRightReturn
485 case 30: // TwoFingersFlickUpReturn
490 case 31: // TwoFingersFlickDownReturn
495 case 32: // ThreeFingersFlickLeftReturn
500 case 33: // ThreeFingersFlickRightReturn
505 case 34: // ThreeFingersFlickUpReturn
510 case 35: // ThreeFingersFlickDownReturn
519 void EventHandler::OnAccessibilityQuickpanelChanged( const unsigned char& info )
521 #ifdef DALI_ELDBUS_AVAILABLE
527 if( !mAccessibilityAdaptor )
529 DALI_LOG_ERROR( "Invalid accessibility adaptor\n" );
533 AccessibilityAdaptor* accessibilityAdaptor( &AccessibilityAdaptor::GetImplementation( mAccessibilityAdaptor ) );
534 if( !accessibilityAdaptor )
536 DALI_LOG_ERROR( "Cannot access accessibility adaptor\n" );
540 if( ( ( info & ( 1 << QUICKPANEL_TYPE_SYSTEM_DEFAULT ) ) && ( info & ( 1 << QUICKPANEL_TYPE_APPS_MENU ) ) ) || // Both QuickPanel and Apps are shown
541 ( info & ( 1 << QUICKPANEL_TYPE_SYSTEM_DEFAULT ) ) ) // QuickPanel is shown
543 // dali apps should be disabled.
544 DALI_LOG_INFO( gSelectionEventLogFilter, Debug::General, "OnAccessibilityQuickpanelChanged: Quickpanel show -> DisableAccessibility \n" );
545 accessibilityAdaptor->DisableAccessibility();
547 else if( info & ( 1 << QUICKPANEL_TYPE_APPS_MENU ) ) // Only Apps menu (dali application) is shown
549 if( !accessibilityAdaptor->IsForcedEnable() ) // It is not in case of that an application controls the accessibility status itself
551 DALI_LOG_INFO( gSelectionEventLogFilter, Debug::General, "OnAccessibilityQuickpanelChanged: Only Apps show, but not forced dali -> DisableAccessibility \n" );
552 accessibilityAdaptor->DisableAccessibility();
556 DALI_LOG_INFO( gSelectionEventLogFilter, Debug::General, "OnAccessibilityQuickpanelChanged: Only Apps show and it is a forced dali -> EnableAccessibility \n" );
557 accessibilityAdaptor->EnableAccessibility();
562 DALI_LOG_INFO( gSelectionEventLogFilter, Debug::General, "OnAccessibilityQuickpanelChanged: Nothing shows -> EnableAccessibility \n" );
563 // dali app should be enabled.
564 accessibilityAdaptor->EnableAccessibility();
570 void EventHandler::AddObserver( Observer& observer )
572 ObserverContainer::iterator match ( find(mObservers.begin(), mObservers.end(), &observer) );
574 if ( match == mObservers.end() )
576 mObservers.push_back( &observer );
580 void EventHandler::RemoveObserver( Observer& observer )
582 ObserverContainer::iterator match ( find(mObservers.begin(), mObservers.end(), &observer) );
584 if ( match != mObservers.end() )
586 mObservers.erase( match );
590 } // namespace Adaptor
592 } // namespace Internal