[dali_2.3.24] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / scrollable / scroll-view / scroll-view-impl.cpp
index 218f6ae..986040b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -44,7 +44,7 @@
 //#define ENABLED_SCROLL_STATE_LOGGING
 
 #ifdef ENABLED_SCROLL_STATE_LOGGING
-#define DALI_LOG_SCROLL_STATE(format, ...) Dali::Integration::Log::LogMessageWithFunctionLine(Dali::Integration::Log::DebugInfo, "%s:%d " format "\n", __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)
+#define DALI_LOG_SCROLL_STATE(format, ...) Dali::Integration::Log::LogMessageWithFunctionLine(Dali::Integration::Log::INFO, "%s:%d " format "\n", __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)
 #else
 #define DALI_LOG_SCROLL_STATE(format, ...)
 #endif
@@ -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
@@ -680,10 +691,12 @@ void ScrollView::OnInitialize()
   // Connect wheel event
   self.WheelEventSignal().Connect(this, &ScrollView::OnWheelEvent);
 
-  DevelControl::SetAccessibilityConstructor(Self(), [](Dali::Actor actor) {
-    return std::unique_ptr<Dali::Accessibility::Accessible>(
-      new AccessibleImpl(actor, Dali::Accessibility::Role::SCROLL_PANE));
-  });
+  self.SetProperty(DevelControl::Property::ACCESSIBILITY_ROLE, Dali::Accessibility::Role::SCROLL_PANE);
+}
+
+DevelControl::ControlAccessible* ScrollView::CreateAccessibleObject()
+{
+  return new ScrollViewAccessible(Self());
 }
 
 void ScrollView::OnSceneConnection(int depth)
@@ -1262,7 +1275,7 @@ Toolkit::ScrollView::SnapStartedSignalType& ScrollView::SnapStartedSignal()
   return mSnapStartedSignal;
 }
 
-bool ScrollView::AccessibleImpl::ScrollToChild(Actor child)
+bool ScrollView::ScrollViewAccessible::ScrollToChild(Actor child)
 {
   auto scrollView = Dali::Toolkit::ScrollView::DownCast(Self());
   if(Toolkit::GetImpl(scrollView).FindClosestActor() == child)
@@ -1270,21 +1283,11 @@ bool ScrollView::AccessibleImpl::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;
 }