Commit 49b47da0 authored by Collin Baker's avatar Collin Baker Committed by Commit Bot

Make tab view order match tab strip model order

Bug: 897086
Change-Id: Idfd8e9a68c663ba3e560a6f2443b2a468cdd3c65
Reviewed-on: https://chromium-review.googlesource.com/c/1331617
Commit-Queue: Collin Baker <collinbaker@chromium.org>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#608076}
parent 58a6b491
......@@ -429,8 +429,14 @@ void TabStrip::StopAllHighlighting() {
void TabStrip::AddTabAt(int model_index, TabRendererData data, bool is_active) {
const bool was_single_tab_mode = SingleTabMode();
// Get view child index of where we want to insert
int view_index = 0;
if (model_index > 0) {
view_index = GetIndexOf(tab_at(model_index - 1)) + 1;
}
Tab* tab = new Tab(this, animation_container_.get());
AddChildView(tab);
AddChildViewAt(tab, view_index);
const bool pinned = data.pinned;
tab->SetData(std::move(data));
UpdateTabsClosingMap(model_index, 1);
......@@ -487,8 +493,14 @@ void TabStrip::MoveTab(int from_model_index,
int to_model_index,
TabRendererData data) {
DCHECK_GT(tabs_.view_size(), 0);
const Tab* last_tab = GetLastVisibleTab();
tab_at(from_model_index)->SetData(std::move(data));
// Keep child views in same order as tab strip model.
const int to_view_index = GetIndexOf(tab_at(to_model_index));
ReorderChildView(tab_at(from_model_index), to_view_index);
if (touch_layout_) {
tabs_.MoveViewOnly(from_model_index, to_model_index);
int pinned_count = 0;
......
......@@ -311,6 +311,40 @@ TEST_P(TabStripTest, RemoveTab) {
EXPECT_EQ(0, observer.last_tab_removed());
}
namespace {
bool TabViewsInOrder(TabStrip* tab_strip) {
for (int i = 1; i < tab_strip->tab_count(); ++i) {
Tab* left = tab_strip->tab_at(i - 1);
Tab* right = tab_strip->tab_at(i);
if (tab_strip->GetIndexOf(right) < tab_strip->GetIndexOf(left)) {
return false;
}
}
return true;
}
} // namespace
// Verifies child view order matches model order.
TEST_P(TabStripTest, TabViewOrder) {
controller_->AddTab(0, false);
controller_->AddTab(1, false);
controller_->AddTab(2, false);
EXPECT_TRUE(TabViewsInOrder(tab_strip_));
tab_strip_->MoveTab(0, 1, TabRendererData());
EXPECT_TRUE(TabViewsInOrder(tab_strip_));
tab_strip_->MoveTab(1, 2, TabRendererData());
EXPECT_TRUE(TabViewsInOrder(tab_strip_));
tab_strip_->MoveTab(1, 0, TabRendererData());
EXPECT_TRUE(TabViewsInOrder(tab_strip_));
tab_strip_->MoveTab(0, 2, TabRendererData());
EXPECT_TRUE(TabViewsInOrder(tab_strip_));
}
TEST_P(TabStripTest, VisibilityInOverflow) {
constexpr int kInitialWidth = 250;
tab_strip_->SetBounds(0, 0, kInitialWidth, 20);
......
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