From 2fffd33d16a6eb42ec4be3e9ec86bb5b1de11e4c Mon Sep 17 00:00:00 2001 From: "joogab.yun" Date: Tue, 19 Dec 2023 19:48:40 +0900 Subject: [PATCH] [Tizen] If it is a key event that occurred in another window, it skipped Change-Id: I32973650a1a7974f1ee58ecc2afe2cd5c53e570a --- .../dali-toolkit/utc-Dali-KeyInputFocusManager.cpp | 29 ++++++++++ .../dali-toolkit/utc-Dali-KeyboardFocusManager.cpp | 67 ++++++++++++++++++++++ .../focus-manager/keyboard-focus-manager-impl.cpp | 21 ++++++- .../focus-manager/keyboard-focus-manager-impl.h | 7 +++ .../focus-manager/keyinput-focus-manager-impl.cpp | 20 ++++++- .../focus-manager/keyinput-focus-manager-impl.h | 6 ++ 6 files changed, 147 insertions(+), 3 deletions(-) diff --git a/automated-tests/src/dali-toolkit/utc-Dali-KeyInputFocusManager.cpp b/automated-tests/src/dali-toolkit/utc-Dali-KeyInputFocusManager.cpp index 6f8ee50..8377ec7 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-KeyInputFocusManager.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-KeyInputFocusManager.cpp @@ -519,3 +519,32 @@ int UtcDaliKeyInputFocusManagerSignalKeyInputFocusChangedforNewWindow(void) window.Reset(); END_TEST; } + +int UtcDaliKeyInputFocusManagerKeyEventOtherWindow(void) +{ + ToolkitTestApplication application; + + tet_infoline(" UtcDaliKeyInputFocusManagerSignalKeyEventOtherWindow"); + + Dali::Integration::Scene scene = application.GetScene(); + + KeyInputFocusManager manager = KeyInputFocusManager::Get(); + DALI_TEST_CHECK(manager); + + PushButton pushButton1 = PushButton::New(); + scene.Add(pushButton1); + + KeyEventCallback windowCallback(false); + pushButton1.KeyEventSignal().Connect(&windowCallback, &KeyEventCallback::Callback); + + manager.SetFocus(pushButton1); + + Integration::KeyEvent event("a", "", "a", 0, 0, 0, Integration::KeyEvent::UP, "", "", Device::Class::TOUCH, Device::Subclass::NONE); + event.windowId = 3; + + application.ProcessEvent(event); + + DALI_TEST_CHECK(!windowCallback.mIsCalled); + + END_TEST; +} diff --git a/automated-tests/src/dali-toolkit/utc-Dali-KeyboardFocusManager.cpp b/automated-tests/src/dali-toolkit/utc-Dali-KeyboardFocusManager.cpp index 60e9eea..4d0d54e 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-KeyboardFocusManager.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-KeyboardFocusManager.cpp @@ -2389,3 +2389,70 @@ int UtcDaliKeyboardFocusManagerFocusFinderRootActor(void) END_TEST; } + +int UtcDaliKeyboardFocusManagerKeyEventOtherWindow(void) +{ + ToolkitTestApplication application; + + tet_infoline(" UtcDaliKeyboardFocusManagerKeyEventOtherWindow"); + + Dali::Integration::Scene scene = application.GetScene(); + + // Register Type + TypeInfo type; + type = TypeRegistry::Get().GetTypeInfo("KeyboardFocusManager"); + DALI_TEST_CHECK(type); + BaseHandle handle = type.CreateInstance(); + DALI_TEST_CHECK(handle); + + KeyboardFocusManager manager = KeyboardFocusManager::Get(); + DALI_TEST_CHECK(manager); + + + PushButton button1 = PushButton::New(); + PushButton button2 = PushButton::New(); + button1.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true); + button2.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true); + application.GetScene().Add(button1); + application.GetScene().Add(button2); + + // Set the focus to the button1 + DALI_TEST_CHECK(manager.SetCurrentFocusActor(button1) == true); + DALI_TEST_CHECK(manager.GetCurrentFocusActor() == button1); + + // set the navigation properties of button1 + button1.SetProperty(Toolkit::DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID, Property::Value((int)button2.GetProperty(Actor::Property::ID))); + button1.SetProperty(Toolkit::DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID, Property::Value((int)button2.GetProperty(Actor::Property::ID))); + button1.SetProperty(Toolkit::DevelControl::Property::UP_FOCUSABLE_ACTOR_ID, Property::Value((int)button2.GetProperty(Actor::Property::ID))); + button1.SetProperty(Toolkit::DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID, Property::Value((int)button2.GetProperty(Actor::Property::ID))); + button1.SetProperty(Toolkit::DevelControl::Property::CLOCKWISE_FOCUSABLE_ACTOR_ID, Property::Value((int)button2.GetProperty< int >( Actor::Property::ID))); + button1.SetProperty(Toolkit::DevelControl::Property::COUNTER_CLOCKWISE_FOCUSABLE_ACTOR_ID, Property::Value((int)button2.GetProperty< int >( Actor::Property::ID))); + + Integration::KeyEvent event("Right", "", "Right", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE); + // It makes mIsFocusIndicatorEnabled true + application.ProcessEvent(event); + + // Move the focus towards right + application.ProcessEvent(event); + + // flush the queue and render once + application.SendNotification(); + application.Render(); + + DALI_TEST_CHECK(manager.GetCurrentFocusActor() == button2); + + DALI_TEST_CHECK(manager.SetCurrentFocusActor(button1) == true); + DALI_TEST_CHECK(manager.GetCurrentFocusActor() == button1); + + Integration::KeyEvent event1("Right", "", "Right", 0, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE); + event1.windowId = 3; + application.ProcessEvent(event1); + + // flush the queue and render once + application.SendNotification(); + application.Render(); + + DALI_TEST_CHECK(manager.GetCurrentFocusActor() == button1); + + END_TEST; +} \ No newline at end of file diff --git a/dali-toolkit/internal/focus-manager/keyboard-focus-manager-impl.cpp b/dali-toolkit/internal/focus-manager/keyboard-focus-manager-impl.cpp index 1c9f619..e8a990f 100644 --- a/dali-toolkit/internal/focus-manager/keyboard-focus-manager-impl.cpp +++ b/dali-toolkit/internal/focus-manager/keyboard-focus-manager-impl.cpp @@ -130,7 +130,8 @@ KeyboardFocusManager::KeyboardFocusManager() mFocusGroupLoopEnabled(false), mIsWaitingKeyboardFocusChangeCommit(false), mClearFocusOnTouch(true), - mEnableDefaultAlgorithm(false) + mEnableDefaultAlgorithm(false), + mCurrentWindowId(0) { // TODO: Get FocusIndicatorEnable constant from stylesheet to set mIsFocusIndicatorShown. @@ -238,6 +239,7 @@ bool KeyboardFocusManager::DoSetCurrentFocusActor(Actor actor) { Layer rootLayer = currentWindow.GetRootLayer(); mCurrentFocusedWindow = rootLayer; + mCurrentWindowId = static_cast(currentWindow.GetNativeId()); } if((mIsFocusIndicatorShown == SHOW) && (mEnableFocusIndicator == ENABLE)) @@ -799,8 +801,24 @@ Actor KeyboardFocusManager::GetFocusIndicatorActor() return mFocusIndicatorActor; } +uint32_t KeyboardFocusManager::GetCurrentWindowId() const +{ + return mCurrentWindowId; +} + void KeyboardFocusManager::OnKeyEvent(const KeyEvent& event) { + if(mCurrentFocusedWindow.GetHandle()) + { + // If it is a key event that occurred in another window, it returns. + uint32_t eventWindowId = event.GetWindowId(); + if(eventWindowId > 0 && GetCurrentWindowId() != eventWindowId) + { + DALI_LOG_RELEASE_INFO("CurrentFocusedWindow id %d, window ID where key event occurred %d : key event skip\n", GetCurrentWindowId(), eventWindowId); + return; + } + } + const std::string& keyName = event.GetKeyName(); const std::string& deviceName = event.GetDeviceName(); @@ -1088,6 +1106,7 @@ void KeyboardFocusManager::OnWindowFocusChanged(Window window, bool focusIn) // Change Current Focused Window Layer rootLayer = window.GetRootLayer(); mCurrentFocusedWindow = rootLayer; + mCurrentWindowId = static_cast(Integration::SceneHolder::Get(rootLayer).GetNativeId()); // Get Current Focused Actor from window Actor currentFocusedActor = GetFocusActorFromCurrentWindow(); diff --git a/dali-toolkit/internal/focus-manager/keyboard-focus-manager-impl.h b/dali-toolkit/internal/focus-manager/keyboard-focus-manager-impl.h index 31b0601..87e73f8 100644 --- a/dali-toolkit/internal/focus-manager/keyboard-focus-manager-impl.h +++ b/dali-toolkit/internal/focus-manager/keyboard-focus-manager-impl.h @@ -338,6 +338,11 @@ private: */ void ClearFocusIndicator(); + /** + * Gets the current native window id + */ + uint32_t GetCurrentWindowId() const; + private: // Undefined KeyboardFocusManager(const KeyboardFocusManager&); @@ -382,6 +387,8 @@ private: bool mEnableDefaultAlgorithm : 1; ///< Whether use default algorithm focus + uint32_t mCurrentWindowId; ///< The current native window id + }; } // namespace Internal diff --git a/dali-toolkit/internal/focus-manager/keyinput-focus-manager-impl.cpp b/dali-toolkit/internal/focus-manager/keyinput-focus-manager-impl.cpp index 9e1986c..2b64a0c 100644 --- a/dali-toolkit/internal/focus-manager/keyinput-focus-manager-impl.cpp +++ b/dali-toolkit/internal/focus-manager/keyinput-focus-manager-impl.cpp @@ -23,12 +23,12 @@ #include #include #include +#include #include #include // for strcmp // INTERNAL INCLUDES #include - namespace Dali { namespace Toolkit @@ -45,7 +45,8 @@ const char* const SIGNAL_KEY_INPUT_FOCUS_CHANGED = "keyInputFocusChanged"; KeyInputFocusManager::KeyInputFocusManager() : mSlotDelegate(this), - mCurrentFocusControl() + mCurrentFocusControl(), + mCurrentWindowId(0) { // Retrieve all the existing widnows Dali::SceneHolderList sceneHolders = Adaptor::Get().GetSceneHolders(); @@ -87,6 +88,7 @@ void KeyInputFocusManager::SetFocus(Toolkit::Control control) // Set control to currentFocusControl mCurrentFocusControl = control; + mCurrentWindowId = static_cast(Integration::SceneHolder::Get(control).GetNativeId()); if(previousFocusControl) { @@ -112,6 +114,7 @@ void KeyInputFocusManager::RemoveFocus(Toolkit::Control control) control.OffSceneSignal().Disconnect(mSlotDelegate, &KeyInputFocusManager::OnFocusControlSceneDisconnection); mCurrentFocusControl.Reset(); + mCurrentWindowId = 0; // Notify the control that it has lost key input focus GetImplementation(control).OnKeyInputFocusLost(); @@ -123,6 +126,11 @@ Toolkit::Control KeyInputFocusManager::GetCurrentFocusControl() const return mCurrentFocusControl; } +uint32_t KeyInputFocusManager::GetCurrentWindowId() const +{ + return mCurrentWindowId; +} + Toolkit::KeyInputFocusManager::KeyInputFocusChangedSignalType& KeyInputFocusManager::KeyInputFocusChangedSignal() { return mKeyInputFocusChangedSignal; @@ -135,6 +143,14 @@ bool KeyInputFocusManager::OnKeyEvent(const KeyEvent& event) Toolkit::Control control = GetCurrentFocusControl(); if(control) { + // Key events that occur in windows other than the currently focused control are skipped. + uint32_t eventWindowId = event.GetWindowId(); + if(eventWindowId > 0 && GetCurrentWindowId() != eventWindowId) + { + DALI_LOG_RELEASE_INFO("Current control window id %d, window ID where key event occurred %d : key event skip\n", GetCurrentWindowId(), eventWindowId); + return consumed; + } + Dali::Actor dispatch = control; while(dispatch) { diff --git a/dali-toolkit/internal/focus-manager/keyinput-focus-manager-impl.h b/dali-toolkit/internal/focus-manager/keyinput-focus-manager-impl.h index 5974b88..f668901 100644 --- a/dali-toolkit/internal/focus-manager/keyinput-focus-manager-impl.h +++ b/dali-toolkit/internal/focus-manager/keyinput-focus-manager-impl.h @@ -117,6 +117,11 @@ private: */ bool EmitKeyEventSignal(Toolkit::Control control, const KeyEvent& event); + /** + * Gets the current native window id + */ + uint32_t GetCurrentWindowId() const; + private: // Undefined KeyInputFocusManager(const KeyInputFocusManager&); @@ -130,6 +135,7 @@ private: SlotDelegate mSlotDelegate; Toolkit::Control mCurrentFocusControl; ///< The current focused control + uint32_t mCurrentWindowId; ///< The native window id of current focused control }; } // namespace Internal -- 2.7.4