[Vertical Tabs] Scroll-in animating tabs in the non-overflow state

This CL handles the sepecific edge case where:
  - Animating view is activated
  - ScrollView is in a non-overflow state
  - Final animated bounds are partially overflowing

This is handled by a follow-up call to
EnsureVisibleInViewportPostActivationAndLayout() which will scroll-in
the view (if necessary).

Bug: 485334280, 459824840
Change-Id: I84e91b4377915b0695bfe6e7360c34a0c8728c95
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7651216
Commit-Queue: Tom Lukaszewicz <tluk@chromium.org>
Reviewed-by: Eshwar Stalin <estalin@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1599630}
diff --git a/chrome/browser/ui/views/tabs/vertical/vertical_tab_strip_view.cc b/chrome/browser/ui/views/tabs/vertical/vertical_tab_strip_view.cc
index 65054b1..ec8f51a9 100644
--- a/chrome/browser/ui/views/tabs/vertical/vertical_tab_strip_view.cc
+++ b/chrome/browser/ui/views/tabs/vertical/vertical_tab_strip_view.cc
@@ -69,6 +69,11 @@
   }
   views::View* view() { return view_; }
 
+  // Returns true if the tracked view height matches its preferred height.
+  bool IsViewAtPreferredHeight() {
+    return view_->size().height() == view_->GetPreferredSize().height();
+  }
+
   // Sets a callback that is run when the tracked view's height reaches its
   // preferred height.
   void SetOnReachedPreferredHeightCallback(
@@ -80,8 +85,7 @@
  private:
   void CheckTrackedViewHeight() {
     CHECK(view_);
-    if ((view_->size().height() == view_->GetPreferredSize().height()) &&
-        on_reached_preferred_height_cb_) {
+    if (IsViewAtPreferredHeight() && on_reached_preferred_height_cb_) {
       std::move(on_reached_preferred_height_cb_).Run();
     }
   }
@@ -465,10 +469,16 @@
     // (i.e. it was activated as it is being animated in). In such a case
     // disable overflow visuals to prevent jank that can occur if content view
     // bounds are changed in quick succession.
-    DisableOverflowVisuals(scroll_view);
-    activated_view_tracker_->SetOnReachedPreferredHeightCallback(
-        base::BindOnce(&VerticalTabStripView::EnableOverflowVisuals,
-                       base::Unretained(this), scroll_view));
+    if (!activated_view_tracker_->IsViewAtPreferredHeight()) {
+      DisableOverflowVisuals(scroll_view);
+      activated_view_tracker_->SetOnReachedPreferredHeightCallback(
+          base::BindOnce(&VerticalTabStripView::
+                             EnsureVisibleInViewportPostActivationAndLayout,
+                         base::Unretained(this), scroll_view));
+    } else {
+      // Always exit with overflow visuals enabled.
+      EnableOverflowVisuals(scroll_view);
+    }
     return;
   }