From: joogab.yun Date: Mon, 27 Jun 2022 09:18:20 +0000 (+0900) Subject: [Tizen] Add InterceptKeyEvent X-Git-Tag: accepted/tizen/6.5/unified/20220831.133912^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=72c0c0343aa6a83940a726946b237c132f32890f;p=platform%2Fcore%2Fuifw%2Fdali-core.git [Tizen] Add InterceptKeyEvent Intercepts KeyEvents in the window before dispatching KeyEvents to the control. If a KeyEvent is consumed, no KeyEvent is delivered to the control. Change-Id: If6ee2b2fb03d936a7840b4c984129a31bb8b948d --- diff --git a/automated-tests/src/dali/utc-Dali-Scene.cpp b/automated-tests/src/dali/utc-Dali-Scene.cpp index 26a7070..150f2c6 100644 --- a/automated-tests/src/dali/utc-Dali-Scene.cpp +++ b/automated-tests/src/dali/utc-Dali-Scene.cpp @@ -1752,3 +1752,82 @@ int UtcDaliSceneWheelEventGeneratedSignalP(void) DALI_TEST_CHECK(event2.timeStamp == data.receivedWheelEvent.GetTime()); END_TEST; } + +int UtcDaliSceneSignalInterceptKeyEventP(void) +{ + TestApplication application; + Dali::Integration::Scene scene = application.GetScene(); + + KeyEventSignalData data; + KeyEventReceivedFunctor functor(data); + scene.KeyEventSignal().Connect(&application, functor); + + KeyEventGeneratedSignalData interceptData; + KeyEventGeneratedReceivedFunctor interceptFunctor(interceptData); + scene.InterceptKeyEventSignal().Connect(&application, interceptFunctor); + + Integration::KeyEvent event("i", "", "i", 0, 0, 0, Integration::KeyEvent::DOWN, "i", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE); + application.ProcessEvent(event); + + DALI_TEST_EQUALS(true, interceptData.functorCalled, TEST_LOCATION); + DALI_TEST_CHECK(event.keyModifier == interceptData.receivedKeyEvent.GetKeyModifier()); + DALI_TEST_CHECK(event.keyName == interceptData.receivedKeyEvent.GetKeyName()); + DALI_TEST_CHECK(event.keyString == interceptData.receivedKeyEvent.GetKeyString()); + DALI_TEST_CHECK(event.state == static_cast(interceptData.receivedKeyEvent.GetState())); + DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION); + + data.Reset(); + interceptData.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, interceptData.functorCalled, TEST_LOCATION); + DALI_TEST_CHECK(event2.keyModifier == interceptData.receivedKeyEvent.GetKeyModifier()); + DALI_TEST_CHECK(event2.keyName == interceptData.receivedKeyEvent.GetKeyName()); + DALI_TEST_CHECK(event2.keyString == interceptData.receivedKeyEvent.GetKeyString()); + DALI_TEST_CHECK(event2.state == static_cast(interceptData.receivedKeyEvent.GetState())); + DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION); + + data.Reset(); + interceptData.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, interceptData.functorCalled, TEST_LOCATION); + DALI_TEST_CHECK(event3.keyModifier == interceptData.receivedKeyEvent.GetKeyModifier()); + DALI_TEST_CHECK(event3.keyName == interceptData.receivedKeyEvent.GetKeyName()); + DALI_TEST_CHECK(event3.keyString == interceptData.receivedKeyEvent.GetKeyString()); + DALI_TEST_CHECK(event3.state == static_cast(interceptData.receivedKeyEvent.GetState())); + DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION); + + data.Reset(); + interceptData.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, interceptData.functorCalled, TEST_LOCATION); + DALI_TEST_CHECK(event4.keyModifier == interceptData.receivedKeyEvent.GetKeyModifier()); + DALI_TEST_CHECK(event4.keyName == interceptData.receivedKeyEvent.GetKeyName()); + DALI_TEST_CHECK(event4.keyString == interceptData.receivedKeyEvent.GetKeyString()); + DALI_TEST_CHECK(event4.state == static_cast(interceptData.receivedKeyEvent.GetState())); + DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION); + END_TEST; +} + +int UtcDaliSceneSignalInterceptKeyEventN(void) +{ + TestApplication application; + Dali::Integration::Scene scene = application.GetScene(); + + KeyEventGeneratedSignalData data; + KeyEventGeneratedReceivedFunctor functor(data); + scene.InterceptKeyEventSignal().Connect(&application, functor); + + // Check that a non-pressed key events data is not modified. + DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION); + + END_TEST; +} \ No newline at end of file diff --git a/dali/integration-api/scene.cpp b/dali/integration-api/scene.cpp index 5aaaa4b..1f61607 100644 --- a/dali/integration-api/scene.cpp +++ b/dali/integration-api/scene.cpp @@ -209,6 +209,11 @@ Scene::KeyEventGeneratedSignalType& Scene::KeyEventGeneratedSignal() return GetImplementation(*this).KeyEventGeneratedSignal(); } +Scene::KeyEventGeneratedSignalType& Scene::InterceptKeyEventSignal() +{ + return GetImplementation(*this).InterceptKeyEventSignal(); +} + Scene::TouchEventSignalType& Scene::TouchedSignal() { return GetImplementation(*this).TouchedSignal(); diff --git a/dali/integration-api/scene.h b/dali/integration-api/scene.h index 3f2d7ed..c6bf691 100644 --- a/dali/integration-api/scene.h +++ b/dali/integration-api/scene.h @@ -385,6 +385,21 @@ public: KeyEventGeneratedSignalType& KeyEventGeneratedSignal(); /** + * @brief The user would connect to this signal to intercept a KeyEvent at window. + * + * Intercepts KeyEvents in the window before dispatching KeyEvents to the control. + * If a KeyEvent is consumed, no KeyEvent is delivered to the control. + * + * 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& InterceptKeyEventSignal(); + + /** * @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 723a1a4..2034c4e 100644 --- a/dali/internal/event/common/scene-impl.cpp +++ b/dali/internal/event/common/scene-impl.cpp @@ -346,6 +346,13 @@ bool Scene::EmitKeyEventGeneratedSignal(const Dali::KeyEvent& event) return mKeyEventGeneratedSignal.Emit(event); } +bool Scene::EmitInterceptKeyEventSignal(const Dali::KeyEvent& event) +{ + // Emit the InterceptKeyEvent signal + Dali::Integration::Scene handle(this); + return mInterceptKeyEventSignal.Emit(event); +} + void Scene::EmitEventProcessingFinishedSignal() { if(!mEventProcessingFinishedSignal.Empty()) @@ -412,6 +419,11 @@ Integration::Scene::KeyEventGeneratedSignalType& Scene::KeyEventGeneratedSignal( return mKeyEventGeneratedSignal; } +Integration::Scene::KeyEventGeneratedSignalType& Scene::InterceptKeyEventSignal() +{ + return mInterceptKeyEventSignal; +} + 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 7f9cbc1..278acc9 100644 --- a/dali/internal/event/common/scene-impl.h +++ b/dali/internal/event/common/scene-impl.h @@ -234,6 +234,13 @@ public: bool EmitKeyEventGeneratedSignal(const Dali::KeyEvent& event); /** + * Used by the KeyEventProcessor to emit InterceptKeyEventSignal signals. + * @param[in] event The key event. + * @return The return is true if KeyEvent is consumed, otherwise false. + */ + bool EmitInterceptKeyEventSignal(const Dali::KeyEvent& event); + + /** * Emits the event processing finished signal. * * @see Dali::Scene::SignalEventProcessingFinished() @@ -290,6 +297,11 @@ public: Integration::Scene::KeyEventGeneratedSignalType& KeyEventGeneratedSignal(); /** + * @copydoc Integration::Scene::InterceptKeyEventSignal() + */ + Integration::Scene::KeyEventGeneratedSignalType& InterceptKeyEventSignal(); + + /** * @copydoc Integration::Scene::SignalEventProcessingFinished() */ Integration::Scene::EventProcessingFinishedSignalType& EventProcessingFinishedSignal(); @@ -378,6 +390,7 @@ private: // The key event signal Integration::Scene::KeyEventSignalType mKeyEventSignal; Integration::Scene::KeyEventGeneratedSignalType mKeyEventGeneratedSignal; + Integration::Scene::KeyEventGeneratedSignalType mInterceptKeyEventSignal; // 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 bbaecdd..8fd1101 100644 --- a/dali/internal/event/events/key-event-processor.cpp +++ b/dali/internal/event/events/key-event-processor.cpp @@ -41,7 +41,11 @@ void KeyEventProcessor::ProcessKeyEvent(const Integration::KeyEvent& event) Dali::KeyEvent keyEventHandle(keyEvent.Get()); // Emit the key event signal from the scene. - bool consumed = mScene.EmitKeyEventGeneratedSignal(keyEventHandle); + bool consumed = mScene.EmitInterceptKeyEventSignal(keyEventHandle); + if(!consumed) + { + consumed = mScene.EmitKeyEventGeneratedSignal(keyEventHandle); + } if(!consumed) { mScene.EmitKeyEventSignal(keyEventHandle);