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( ( info.quickpanelInfo & ( 1 << QUICKPANEL_TYPE_SYSTEM_DEFAULT ) ) && ( info.quickpanelInfo & ( 1 << QUICKPANEL_TYPE_APPS_MENU ) ) )
276 DALI_LOG_ERROR("Quickpanel is top now, so all dali apps should be stopped \n");
280 // Create a touch point object.
281 PointState::Type touchPointState( PointState::DOWN );
282 if( info.state == 0 )
284 touchPointState = PointState::DOWN; // Mouse down.
286 else if( info.state == 1 )
288 touchPointState = PointState::MOTION; // Mouse move.
290 else if( info.state == 2 )
292 touchPointState = PointState::UP; // Mouse up.
296 touchPointState = PointState::INTERRUPTED; // Error.
299 // Send touch event to accessibility adaptor.
300 TouchPoint point( 0, touchPointState, static_cast< float >( info.startX ), static_cast< float >( info.startY ) );
302 // Perform actions based on received gestures.
303 // Note: This is seperated from the reading so we can have other input readers without changing the below code.
304 switch( info.gestureValue )
306 case 0: // OneFingerHover
309 accessibilityAdaptor->HandleActionReadEvent( static_cast< unsigned int >( info.startX ), static_cast< unsigned int >( info.startY ), true /* allow read again */ );
312 case 1: // TwoFingersHover
314 // In accessibility mode, scroll action should be handled when the currently focused actor is contained in scrollable control
315 accessibilityAdaptor->HandleActionScrollEvent( point, GetCurrentMilliSeconds() );
318 case 2: // ThreeFingersHover
320 // Read from top item on screen continuously.
321 accessibilityAdaptor->HandleActionReadFromTopEvent();
324 case 3: // OneFingerFlickLeft
326 // Move to previous item.
327 accessibilityAdaptor->HandleActionReadPreviousEvent();
330 case 4: // OneFingerFlickRight
332 // Move to next item.
333 accessibilityAdaptor->HandleActionReadNextEvent();
336 case 5: // OneFingerFlickUp
338 // Move to previous item.
339 accessibilityAdaptor->HandleActionPreviousEvent();
342 case 6: // OneFingerFlickDown
344 // Move to next item.
345 accessibilityAdaptor->HandleActionNextEvent();
348 case 7: // TwoFingersFlickUp
350 // Scroll up the list.
351 accessibilityAdaptor->HandleActionScrollUpEvent();
354 case 8: // TwoFingersFlickDown
356 // Scroll down the list.
357 accessibilityAdaptor->HandleActionScrollDownEvent();
360 case 9: // TwoFingersFlickLeft
362 // Scroll left to the previous page
363 accessibilityAdaptor->HandleActionPageLeftEvent();
366 case 10: // TwoFingersFlickRight
368 // Scroll right to the next page
369 accessibilityAdaptor->HandleActionPageRightEvent();
372 case 11: // ThreeFingersFlickLeft
377 case 12: // ThreeFingersFlickRight
382 case 13: // ThreeFingersFlickUp
387 case 14: // ThreeFingersFlickDown
392 case 15: // OneFingerSingleTap
395 accessibilityAdaptor->HandleActionReadEvent( static_cast< unsigned int >( info.startX ), static_cast< unsigned int >( info.startY ), true /* allow read again */ );
398 case 16: // OneFingerDoubleTap
400 // Activate selected item / active edit mode.
401 accessibilityAdaptor->HandleActionActivateEvent();
404 case 17: // OneFingerTripleTap
407 accessibilityAdaptor->HandleActionZoomEvent();
410 case 18: // TwoFingersSingleTap
412 // Pause/Resume current speech
413 accessibilityAdaptor->HandleActionReadPauseResumeEvent();
416 case 19: // TwoFingersDoubleTap
418 // Start/Stop current action
419 accessibilityAdaptor->HandleActionStartStopEvent();
422 case 20: // TwoFingersTripleTap
424 // Read information from indicator
428 case 21: // ThreeFingersSingleTap
430 // Read from top item on screen continuously.
431 accessibilityAdaptor->HandleActionReadFromTopEvent();
434 case 22: // ThreeFingersDoubleTap
436 // Read from next item continuously.
437 accessibilityAdaptor->HandleActionReadFromNextEvent();
440 case 23: // ThreeFingersTripleTap
445 case 24: // OneFingerFlickLeftReturn
447 // Scroll up to the previous page
448 accessibilityAdaptor->HandleActionPageUpEvent();
451 case 25: // OneFingerFlickRightReturn
453 // Scroll down to the next page
454 accessibilityAdaptor->HandleActionPageDownEvent();
457 case 26: // OneFingerFlickUpReturn
459 // Move to the first item on screen
460 accessibilityAdaptor->HandleActionMoveToFirstEvent();
463 case 27: // OneFingerFlickDownReturn
465 // Move to the last item on screen
466 accessibilityAdaptor->HandleActionMoveToLastEvent();
469 case 28: // TwoFingersFlickLeftReturn
474 case 29: // TwoFingersFlickRightReturn
479 case 30: // TwoFingersFlickUpReturn
484 case 31: // TwoFingersFlickDownReturn
489 case 32: // ThreeFingersFlickLeftReturn
494 case 33: // ThreeFingersFlickRightReturn
499 case 34: // ThreeFingersFlickUpReturn
504 case 35: // ThreeFingersFlickDownReturn
513 void EventHandler::OnAccessibilityQuickpanelChanged( const unsigned char& info )
515 #ifdef DALI_ELDBUS_AVAILABLE
521 if( !mAccessibilityAdaptor )
523 DALI_LOG_ERROR( "Invalid accessibility adaptor\n" );
527 AccessibilityAdaptor* accessibilityAdaptor( &AccessibilityAdaptor::GetImplementation( mAccessibilityAdaptor ) );
528 if( !accessibilityAdaptor )
530 DALI_LOG_ERROR( "Cannot access accessibility adaptor\n" );
534 if( ( ( info & ( 1 << QUICKPANEL_TYPE_SYSTEM_DEFAULT ) ) && ( info & ( 1 << QUICKPANEL_TYPE_APPS_MENU ) ) ) || // Both QuickPanel and Apps are shown
535 ( info & ( 1 << QUICKPANEL_TYPE_SYSTEM_DEFAULT ) ) ) // QuickPanel is shown
537 // dali apps should be disabled.
538 accessibilityAdaptor->DisableAccessibility();
540 else if( info & ( 1 << QUICKPANEL_TYPE_APPS_MENU ) ) // Only Apps menu (dali application) is shown
542 if( !accessibilityAdaptor->IsForcedEnable() ) // It is not in case of that an application controls the accessibility status itself
544 accessibilityAdaptor->DisableAccessibility();
549 // dali app should be enabled.
550 accessibilityAdaptor->EnableAccessibility();
556 void EventHandler::AddObserver( Observer& observer )
558 ObserverContainer::iterator match ( find(mObservers.begin(), mObservers.end(), &observer) );
560 if ( match == mObservers.end() )
562 mObservers.push_back( &observer );
566 void EventHandler::RemoveObserver( Observer& observer )
568 ObserverContainer::iterator match ( find(mObservers.begin(), mObservers.end(), &observer) );
570 if ( match != mObservers.end() )
572 mObservers.erase( match );
576 } // namespace Adaptor
578 } // namespace Internal