From a7328776c721b50f9020ccc6e90d0ce0985d6c5b Mon Sep 17 00:00:00 2001 From: Sunghyun kim Date: Thu, 13 Jun 2019 19:10:45 +0900 Subject: [PATCH] Add KeyEventGeneratedSignal for Get KeyEvent normally Window can get KeyEvent even if control already use it. Change-Id: I41631b5b3aef393e3e0134419b38acea20aed84a --- automated-tests/src/dali/utc-Dali-Scene.cpp | 97 +++++++++++++++++++ dali/integration-api/scene.cpp | 5 + dali/integration-api/scene.h | 17 ++++ dali/internal/event/common/scene-impl.cpp | 11 +++ dali/internal/event/common/scene-impl.h | 13 +++ .../event/events/key-event-processor.cpp | 7 +- 6 files changed, 149 insertions(+), 1 deletion(-) diff --git a/automated-tests/src/dali/utc-Dali-Scene.cpp b/automated-tests/src/dali/utc-Dali-Scene.cpp index b91447885..8508728f2 100644 --- a/automated-tests/src/dali/utc-Dali-Scene.cpp +++ b/automated-tests/src/dali/utc-Dali-Scene.cpp @@ -190,6 +190,50 @@ struct WheelEventReceivedFunctor WheelEventSignalData& signalData; }; +// Stores data that is populated in the KeyEventGeneratedSignal callback and will be read by the TET cases +struct KeyEventGeneratedSignalData +{ + KeyEventGeneratedSignalData() + : functorCalled(false) + {} + + void Reset() + { + functorCalled = false; + + receivedKeyEvent.keyModifier = 0; + receivedKeyEvent.keyPressedName.clear(); + receivedKeyEvent.keyPressed.clear(); + } + + bool functorCalled; + KeyEvent receivedKeyEvent; +}; + +// Functor that sets the data when called +struct KeyEventGeneratedReceivedFunctor +{ + KeyEventGeneratedReceivedFunctor( KeyEventGeneratedSignalData& data ) + : signalData( data ) + {} + + bool operator()( const KeyEvent& keyEvent ) + { + signalData.functorCalled = true; + signalData.receivedKeyEvent = keyEvent; + + return true; + } + + bool operator()() + { + signalData.functorCalled = true; + return true; + } + + KeyEventGeneratedSignalData& signalData; +}; + void GenerateTouch( TestApplication& application, PointState::Type state, const Vector2& screenPosition ) { Integration::TouchEvent touchEvent; @@ -1134,3 +1178,56 @@ int UtcDaliSceneSetSurface(void) END_TEST; } + +int UtcDaliSceneKeyEventGeneratedSignalP(void) +{ + TestApplication application; + Dali::Integration::Scene scene = application.GetScene(); + + KeyEventGeneratedSignalData data; + KeyEventGeneratedReceivedFunctor functor( data ); + scene.KeyEventGeneratedSignal().Connect( &application, functor ); + + Integration::KeyEvent event( "a", "", "a", 0, 0, 0, Integration::KeyEvent::Up, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ); + application.ProcessEvent( event ); + + DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION ); + DALI_TEST_CHECK( event.keyModifier == data.receivedKeyEvent.keyModifier ); + DALI_TEST_CHECK( event.keyName == data.receivedKeyEvent.keyPressedName ); + DALI_TEST_CHECK( event.keyString == data.receivedKeyEvent.keyPressed ); + DALI_TEST_CHECK( event.state == static_cast( data.receivedKeyEvent.state ) ); + + data.Reset(); + + Integration::KeyEvent event2( "i", "", "i", 0, 0, 0, Integration::KeyEvent::Up, "i", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ); + application.ProcessEvent( event2 ); + + DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION ); + DALI_TEST_CHECK( event2.keyModifier == data.receivedKeyEvent.keyModifier ); + DALI_TEST_CHECK( event2.keyName == data.receivedKeyEvent.keyPressedName ); + DALI_TEST_CHECK( event2.keyString == data.receivedKeyEvent.keyPressed ); + DALI_TEST_CHECK( event2.state == static_cast( data.receivedKeyEvent.state ) ); + + data.Reset(); + + Integration::KeyEvent event3( "a", "", "a", 0, 0, 0, Integration::KeyEvent::Down, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ); + application.ProcessEvent( event3 ); + + DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION ); + DALI_TEST_CHECK( event3.keyModifier == data.receivedKeyEvent.keyModifier ); + DALI_TEST_CHECK( event3.keyName == data.receivedKeyEvent.keyPressedName ); + DALI_TEST_CHECK( event3.keyString == data.receivedKeyEvent.keyPressed ); + DALI_TEST_CHECK( event3.state == static_cast( data.receivedKeyEvent.state ) ); + + data.Reset(); + + Integration::KeyEvent event4( "a", "", "a", 0, 0, 0, Integration::KeyEvent::Up, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ); + application.ProcessEvent( event4 ); + + DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION ); + DALI_TEST_CHECK( event4.keyModifier == data.receivedKeyEvent.keyModifier ); + DALI_TEST_CHECK( event4.keyName == data.receivedKeyEvent.keyPressedName ); + DALI_TEST_CHECK( event4.keyString == data.receivedKeyEvent.keyPressed ); + DALI_TEST_CHECK( event4.state == static_cast( data.receivedKeyEvent.state ) ); + END_TEST; +} diff --git a/dali/integration-api/scene.cpp b/dali/integration-api/scene.cpp index 38e2477eb..8fef6dbd7 100644 --- a/dali/integration-api/scene.cpp +++ b/dali/integration-api/scene.cpp @@ -164,6 +164,11 @@ Scene::KeyEventSignalType& Scene::KeyEventSignal() return GetImplementation(*this).KeyEventSignal(); } +Scene::KeyEventGeneratedSignalType& Scene::KeyEventGeneratedSignal() +{ + return GetImplementation(*this).KeyEventGeneratedSignal(); +} + Scene::TouchSignalType& Scene::TouchSignal() { return GetImplementation(*this).TouchSignal(); diff --git a/dali/integration-api/scene.h b/dali/integration-api/scene.h index c53c413e4..dca7cbca2 100755 --- a/dali/integration-api/scene.h +++ b/dali/integration-api/scene.h @@ -55,6 +55,7 @@ class DALI_CORE_API Scene : public BaseHandle public: typedef Signal< void () > EventProcessingFinishedSignalType; ///< Event Processing finished signal type typedef Signal< void (const Dali::KeyEvent&) > KeyEventSignalType; ///< Key event signal type + typedef Signal< bool (const Dali::KeyEvent&) > KeyEventGeneratedSignalType; ///< key event generated signal type typedef Signal< void (const Dali::TouchData&) > TouchSignalType; ///< Touch signal type typedef Signal< void (const Dali::WheelEvent&) > WheelEventSignalType; ///< Touched signal type @@ -253,6 +254,22 @@ public: */ KeyEventSignalType& KeyEventSignal(); + /** + * @brief The user would connect to this signal to get a KeyEvent when KeyEvent is generated. + * + * If the control already consumed key event, KeyEventProcessor do not need to Emit keyEvent. + * Therefore, KeyinputManager first checks whether KeyEvent is generated as KeyEventGeneratedSignal. + * After that keyEventProcessor must invoke KeyEvent only if KeyEventGeneratedSignal () is not consumed. + * + * A callback of the following type may be connected: + * @code + * bool YourCallbackName(const KeyEvent& event); + * @endcode + * + * @return The return is true if KeyEvent is consumed, otherwise false. + */ + KeyEventGeneratedSignalType& KeyEventGeneratedSignal(); + /** * @brief This signal is emitted when the screen is touched and when the touch ends * (i.e. the down & up touch events only). diff --git a/dali/internal/event/common/scene-impl.cpp b/dali/internal/event/common/scene-impl.cpp index a4c65c5cf..c14470df2 100644 --- a/dali/internal/event/common/scene-impl.cpp +++ b/dali/internal/event/common/scene-impl.cpp @@ -321,6 +321,12 @@ void Scene::EmitKeyEventSignal(const KeyEvent& event) } } +bool Scene::EmitKeyEventGeneratedSignal(const KeyEvent& event) +{ + // Emit the KeyEventGenerated signal when KeyEvent is generated + return mKeyEventGeneratedSignal.Emit( event ); +} + void Scene::EmitEventProcessingFinishedSignal() { if ( !mEventProcessingFinishedSignal.Empty() ) @@ -357,6 +363,11 @@ Integration::Scene::KeyEventSignalType& Scene::KeyEventSignal() return mKeyEventSignal; } +Integration::Scene::KeyEventGeneratedSignalType& Scene::KeyEventGeneratedSignal() +{ + return mKeyEventGeneratedSignal; +} + Integration::Scene::EventProcessingFinishedSignalType& Scene::EventProcessingFinishedSignal() { return mEventProcessingFinishedSignal; diff --git a/dali/internal/event/common/scene-impl.h b/dali/internal/event/common/scene-impl.h index 2c93c84b1..f9db963bf 100644 --- a/dali/internal/event/common/scene-impl.h +++ b/dali/internal/event/common/scene-impl.h @@ -186,6 +186,13 @@ public: */ void EmitKeyEventSignal(const KeyEvent& event); + /** + * Used by the KeyEventProcessor to emit KeyEventGenerated signals. + * @param[in] event The key event. + * @return The return is true if KeyEvent is consumed, otherwise false. + */ + bool EmitKeyEventGeneratedSignal(const KeyEvent& event); + /** * Emits the event processing finished signal. * @@ -211,6 +218,11 @@ public: */ Integration::Scene::KeyEventSignalType& KeyEventSignal(); + /** + * @copydoc Integration::Scene::KeyEventGeneratedSignal() + */ + Integration::Scene::KeyEventGeneratedSignalType& KeyEventGeneratedSignal(); + /** * @copydoc Integration::Scene::SignalEventProcessingFinished() */ @@ -292,6 +304,7 @@ private: // The key event signal Integration::Scene::KeyEventSignalType mKeyEventSignal; + Integration::Scene::KeyEventGeneratedSignalType mKeyEventGeneratedSignal; // The event processing finished signal Integration::Scene::EventProcessingFinishedSignalType mEventProcessingFinishedSignal; diff --git a/dali/internal/event/events/key-event-processor.cpp b/dali/internal/event/events/key-event-processor.cpp index 399c209b4..65be14ee8 100755 --- a/dali/internal/event/events/key-event-processor.cpp +++ b/dali/internal/event/events/key-event-processor.cpp @@ -50,7 +50,12 @@ void KeyEventProcessor::ProcessKeyEvent( const Integration::KeyEvent& event ) GetImplementation( &keyEvent )->SetDeviceSubclass( event.deviceSubclass ); // Emit the key event signal from the scene. - mScene.EmitKeyEventSignal( keyEvent ); + bool consumed = mScene.EmitKeyEventGeneratedSignal( keyEvent ); + if( !consumed ) + { + mScene.EmitKeyEventSignal(keyEvent); + } + } } // namespace Internal -- 2.34.1