If it is a key event that occurred in another window, it skipped 56/303056/9
authorjoogab.yun <joogab.yun@samsung.com>
Tue, 19 Dec 2023 10:48:40 +0000 (19:48 +0900)
committerjoogab.yun <joogab.yun@samsung.com>
Tue, 26 Dec 2023 01:25:46 +0000 (10:25 +0900)
Change-Id: I32973650a1a7974f1ee58ecc2afe2cd5c53e570a

automated-tests/src/dali-toolkit/utc-Dali-KeyInputFocusManager.cpp
automated-tests/src/dali-toolkit/utc-Dali-KeyboardFocusManager.cpp
dali-toolkit/internal/focus-manager/keyboard-focus-manager-impl.cpp
dali-toolkit/internal/focus-manager/keyboard-focus-manager-impl.h
dali-toolkit/internal/focus-manager/keyinput-focus-manager-impl.cpp
dali-toolkit/internal/focus-manager/keyinput-focus-manager-impl.h

index 6f8ee50..8377ec7 100644 (file)
@@ -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;
+}
index 60e9eea..4d0d54e 100644 (file)
@@ -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<int>(Actor::Property::ID)));
+  button1.SetProperty(Toolkit::DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID, Property::Value((int)button2.GetProperty<int>(Actor::Property::ID)));
+  button1.SetProperty(Toolkit::DevelControl::Property::UP_FOCUSABLE_ACTOR_ID, Property::Value((int)button2.GetProperty<int>(Actor::Property::ID)));
+  button1.SetProperty(Toolkit::DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID, Property::Value((int)button2.GetProperty<int>(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
index 1c9f619..e8a990f 100644 (file)
@@ -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<uint32_t>(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<uint32_t>(Integration::SceneHolder::Get(rootLayer).GetNativeId());
 
     // Get Current Focused Actor from window
     Actor currentFocusedActor = GetFocusActorFromCurrentWindow();
index 31b0601..87e73f8 100644 (file)
@@ -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
index 9e1986c..2b64a0c 100644 (file)
 #include <dali/integration-api/adaptor-framework/adaptor.h>
 #include <dali/integration-api/adaptor-framework/scene-holder.h>
 #include <dali/integration-api/debug.h>
+#include <dali/devel-api/adaptor-framework/window-devel.h>
 #include <dali/public-api/actors/layer.h>
 #include <cstring> // for strcmp
 
 // INTERNAL INCLUDES
 #include <dali-toolkit/devel-api/controls/control-devel.h>
-
 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<uint32_t>(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)
     {
index 5974b88..f668901 100644 (file)
@@ -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<KeyInputFocusManager> mSlotDelegate;
 
   Toolkit::Control mCurrentFocusControl; ///< The current focused control
+  uint32_t mCurrentWindowId; ///< The native window id of current focused control
 };
 
 } // namespace Internal