When using the auto-focusing function by enabling EnableDefaultAlgorithm, 65/272165/4
authorjoogab.yun <joogab.yun@samsung.com>
Thu, 10 Mar 2022 08:54:58 +0000 (17:54 +0900)
committerjoogab.yun <joogab.yun@samsung.com>
Fri, 11 Mar 2022 06:14:48 +0000 (15:14 +0900)
if there is no focused actor, focus on the closest actor based on the upper left corner of the current window.

Change-Id: I8538a1957a17163361ac3b479eaa5dc3228fb69a

automated-tests/src/dali-toolkit/utc-Dali-KeyboardFocusManager.cpp
dali-toolkit/devel-api/focus-manager/focus-finder.cpp
dali-toolkit/internal/focus-manager/keyboard-focus-manager-impl.cpp

index 65876fb..785b509 100644 (file)
@@ -1959,6 +1959,8 @@ int UtcDaliKeyboardFocusManagerEnableDefaultAlgorithm(void)
   // button1 -- button2
   button1.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 0.0f));
   button2.SetProperty(Actor::Property::POSITION, Vector2(100.0f, 0.0f));
+  button1.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
+  button2.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
 
   // flush the queue and render once
   application.SendNotification();
@@ -2003,13 +2005,31 @@ int UtcDaliKeyboardFocusManagerEnableDefaultAlgorithm(void)
   // Move the focus towards left, The focus move will success because the default algorithm is enabled.
   // [button1] -- button2
   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::LEFT) == true);
-  // Confirm whether focus is moved to button2
+  // Confirm whether focus is moved to button1
   DALI_TEST_EQUALS(button1.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
   DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
   DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == button2);
   DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
   focusChangedCallback.Reset();
 
+  // Clears focus.
+  manager.ClearFocus();
+  // There is no actor focused.
+  // button1 -- button2
+  DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor());
+
+  // Move the focus towards right, The focus is on the actor closest to the top left of the window.
+  // [button1] -- button2
+  DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
+
+  // Confirm whether focus is moved to button1
+  DALI_TEST_EQUALS(button1.GetProperty<int>(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION);
+  DALI_TEST_CHECK(focusChangedCallback.mSignalVerified);
+  DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor());
+  DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == button1);
+  focusChangedCallback.Reset();
+
+
   END_TEST;
 }
 
index c52bf57..d338e39 100644 (file)
@@ -385,12 +385,23 @@ Actor FindNextFocus(Actor& actor, Actor& focusedActor, Rect<float>& focusedRect,
 Actor GetNearestFocusableActor(Actor rootActor, Actor focusedActor, Toolkit::Control::KeyboardFocus::Direction direction)\r
 {\r
   Actor nearestActor;\r
-  if(!focusedActor || !rootActor)\r
+  if(!rootActor)\r
   {\r
     return nearestActor;\r
   }\r
 \r
-  Rect<float> focusedRect = DevelActor::CalculateScreenExtents(focusedActor);\r
+  Rect<float> focusedRect;\r
+  if (!focusedActor)\r
+  {\r
+    // If there is no currently focused actor, it is searched based on the upper left corner of the current window.\r
+    Rect<float> rootRect = DevelActor::CalculateScreenExtents(rootActor);\r
+    focusedRect = Rect<float>(rootRect.x, rootRect.y, 0.f, 0.f);\r
+  }\r
+  else\r
+  {\r
+    focusedRect = DevelActor::CalculateScreenExtents(focusedActor);\r
+  }\r
+\r
 \r
   // initialize the best candidate to something impossible\r
   // (so the first plausible actor will become the best choice)\r
index 75ffbfb..74e89dc 100644 (file)
@@ -516,13 +516,27 @@ bool KeyboardFocusManager::MoveFocus(Toolkit::Control::KeyboardFocus::Direction
         nextFocusableActor                  = mPreFocusChangeSignal.Emit(currentFocusActor, Actor(), direction);
         mIsWaitingKeyboardFocusChangeCommit = false;
       }
-      else if(mEnableDefaultAlgorithm && currentFocusActor)
+      else if (mEnableDefaultAlgorithm)
       {
-        // We should find it among the actors nearby.
-        Integration::SceneHolder window = Integration::SceneHolder::Get(currentFocusActor);
-        if(window)
+        Layer rootLayer;
+        if (currentFocusActor)
         {
-          nextFocusableActor = Toolkit::FocusFinder::GetNearestFocusableActor(window.GetRootLayer(), currentFocusActor, direction);
+          // Find the window of the focused actor.
+          Integration::SceneHolder window = Integration::SceneHolder::Get(currentFocusActor);
+          if (window)
+          {
+            rootLayer = window.GetRootLayer();
+          }
+        }
+        else
+        {
+          // Searches from the currently focused window.
+          rootLayer = mCurrentFocusedWindow.GetHandle();
+        }
+        if (rootLayer)
+        {
+          // We should find it among the actors nearby.
+          nextFocusableActor = Toolkit::FocusFinder::GetNearestFocusableActor(rootLayer, currentFocusActor, direction);
         }
       }
     }