Commit 6e6ed678 authored by Charlene Yan's avatar Charlene Yan Committed by Chromium LUCI CQ

[Tab Scrolling] Scroll the active tab into view when selecting a tab.

The active tab is not yet reflected in the tab strip when
BrowserTabStripController is notified of the select change.

The index given to TabStrip to show as active will scroll the tabstrip
the minimum amount to make it visible.

Bug: 1116120

Change-Id: Iee5260960f30f06e84812261beaffb7317180efb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2625910
Commit-Queue: Charlene Yan <cyan@chromium.org>
Reviewed-by: default avatarTaylor Bergquist <tbergquist@chromium.org>
Cr-Commit-Position: refs/heads/master@{#843806}
parent e3279315
...@@ -88,6 +88,7 @@ ...@@ -88,6 +88,7 @@
#include "ui/gfx/skia_util.h" #include "ui/gfx/skia_util.h"
#include "ui/views/accessibility/view_accessibility.h" #include "ui/views/accessibility/view_accessibility.h"
#include "ui/views/controls/image_view.h" #include "ui/views/controls/image_view.h"
#include "ui/views/controls/scroll_view.h"
#include "ui/views/masked_targeter_delegate.h" #include "ui/views/masked_targeter_delegate.h"
#include "ui/views/metadata/metadata_impl_macros.h" #include "ui/views/metadata/metadata_impl_macros.h"
#include "ui/views/mouse_watcher_view_host.h" #include "ui/views/mouse_watcher_view_host.h"
...@@ -1389,6 +1390,36 @@ void TabStrip::RemoveTabAt(content::WebContents* contents, ...@@ -1389,6 +1390,36 @@ void TabStrip::RemoveTabAt(content::WebContents* contents,
EndDrag(END_DRAG_COMPLETE); EndDrag(END_DRAG_COMPLETE);
} }
void TabStrip::ScrollTabToVisible(int model_index) {
views::ScrollView* scroll_container =
views::ScrollView::GetScrollViewForContents(this);
if (!scroll_container) {
return;
}
gfx::Rect visible_content_rect = scroll_container->GetVisibleRect();
Tab* active_tab = tab_at(model_index);
if ((active_tab->x() >= visible_content_rect.x()) &&
(active_tab->bounds().right() <= visible_content_rect.right())) {
return;
}
bool scroll_left = active_tab->x() < visible_content_rect.x();
if (scroll_left) {
gfx::Rect new_visible(active_tab->x(), visible_content_rect.y(),
visible_content_rect.width(),
visible_content_rect.height());
ScrollRectToVisible(new_visible);
} else {
gfx::Rect new_visible(
active_tab->bounds().right() - visible_content_rect.width(),
visible_content_rect.y(), visible_content_rect.width(),
visible_content_rect.height());
ScrollRectToVisible(new_visible);
}
}
void TabStrip::SetTabData(int model_index, TabRendererData data) { void TabStrip::SetTabData(int model_index, TabRendererData data) {
Tab* tab = tab_at(model_index); Tab* tab = tab_at(model_index);
const bool pinned = data.pinned; const bool pinned = data.pinned;
...@@ -1653,6 +1684,9 @@ void TabStrip::SetSelection(const ui::ListSelectionModel& new_selection) { ...@@ -1653,6 +1684,9 @@ void TabStrip::SetSelection(const ui::ListSelectionModel& new_selection) {
new_active_tab->ActiveStateChanged(); new_active_tab->ActiveStateChanged();
layout_helper_->SetActiveTab(selected_tabs_.active(), layout_helper_->SetActiveTab(selected_tabs_.active(),
new_selection.active()); new_selection.active());
if (base::FeatureList::IsEnabled(features::kScrollableTabStrip)) {
ScrollTabToVisible(new_selection.active());
}
} }
if (touch_layout_) { if (touch_layout_) {
......
...@@ -160,6 +160,8 @@ class TabStrip : public views::View, ...@@ -160,6 +160,8 @@ class TabStrip : public views::View,
int model_index, int model_index,
bool was_active); bool was_active);
void ScrollTabToVisible(int model_index);
// Sets the tab data at the specified model index. // Sets the tab data at the specified model index.
void SetTabData(int model_index, TabRendererData data); void SetTabData(int model_index, TabRendererData data);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment