[AT-SPI] ScrollView: Use child postion for ScrollToChild 92/274392/1
authorShinwoo Kim <cinoo.kim@samsung.com>
Wed, 27 Apr 2022 10:44:01 +0000 (19:44 +0900)
committerShinwoo Kim <cinoo.kim@samsung.com>
Wed, 27 Apr 2022 10:44:01 +0000 (19:44 +0900)
It was not able to scroll in a child of scroll view if the child is
not a child of the first depth.

(1) [scroll pane],[(class=ScrollView)],[364,199,656,36],[TextSelectionScrollView]
  (2) [table],[(class=TableView)],[364,101,901,134],[]
    (3) [push button],[(class=PushButton)],[364,101,447,134],[Select all]
      (4) [image],[(class=ImageView)(highlight=)],[364,101,447,134],[]
    (5) [unknown],[(class=Control)],[811,107,1,122],[]
    (6) [push button],[(class=PushButton)],[812,101,265,134],[Copy]
    (7) [unknown],[(class=Control)],[1077,107,1,122],[]
    (8) [push button],[(class=PushButton)],[1078,101,187,134],[Cut]

The node (8) was not able to bring in even though it has highlight.
This patch makes node (8) bring in when it grabs highlight.

Change-Id: I862a8adcc2bd6212464ffc833a2a0d0cf0a4480c

dali-toolkit/internal/controls/scrollable/scroll-view/scroll-view-impl.cpp

index 0dceb47..3779e35 100644 (file)
@@ -530,6 +530,17 @@ void SnapWithVelocity(
   }
 }
 
+Dali::Vector2 GetPosition(Dali::Actor actor)
+{
+  Vector2     screenPosition          = actor.GetProperty<Vector2>(Actor::Property::SCREEN_POSITION);
+  Vector3     size                    = actor.GetCurrentProperty<Vector3>(Actor::Property::SIZE) * actor.GetCurrentProperty<Vector3>(Actor::Property::WORLD_SCALE);
+  bool        positionUsesAnchorPoint = actor.GetProperty<bool>(Actor::Property::POSITION_USES_ANCHOR_POINT);
+  Vector3     anchorPointOffSet       = size * (positionUsesAnchorPoint ? actor.GetCurrentProperty<Vector3>(Actor::Property::ANCHOR_POINT) : AnchorPoint::TOP_LEFT);
+  Vector2     position                = Vector2(screenPosition.x - anchorPointOffSet.x, screenPosition.y - anchorPointOffSet.y);
+
+  return position;
+}
+
 } // unnamed namespace
 
 namespace Dali
@@ -1272,21 +1283,11 @@ bool ScrollView::ScrollViewAccessible::ScrollToChild(Actor child)
     return false;
   }
 
-  // child can be one of descendants
-  // find direct child of ScrollView to avoid the ASSERT in ScrollTo
-  auto parent = child.GetParent();
-  while (parent && parent != Self())
-  {
-    child = parent;
-    parent = child.GetParent();
-  }
-  if (!parent)
-  {
-    return false;
-  }
+  auto childPosition = GetPosition(child);
+  auto selfPosition  = GetPosition(Self());
+
+  scrollView.ScrollTo(childPosition - selfPosition, scrollView.GetScrollFlickDuration());
 
-  // FIXME: ScrollTo does not work (snaps back to original position)
-  scrollView.ScrollTo(child, scrollView.GetScrollFlickDuration());
   return true;
 }