Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1192)

Side by Side Diff: chrome/browser/ui/views/tabs/stacked_tab_strip_layout.cc

Issue 2963023002: [stacked tabs] Fix stacking logic with 'open link in new tab' (Closed)
Patch Set: Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/views/tabs/stacked_tab_strip_layout.h" 5 #include "chrome/browser/ui/views/tabs/stacked_tab_strip_layout.h"
6 6
7 #include <stdio.h> 7 #include <stdio.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/metrics/user_metrics.h" 10 #include "base/metrics/user_metrics.h"
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 active_index_ = index; 164 active_index_ = index;
165 else if (active_index_ >= index) 165 else if (active_index_ >= index)
166 active_index_++; 166 active_index_++;
167 if (add_types & kAddTypePinned) 167 if (add_types & kAddTypePinned)
168 pinned_tab_count_++; 168 pinned_tab_count_++;
169 x_ = start_x; 169 x_ = start_x;
170 if (!requires_stacking() || normal_tab_count() <= 1) { 170 if (!requires_stacking() || normal_tab_count() <= 1) {
171 ResetToIdealState(); 171 ResetToIdealState();
172 return; 172 return;
173 } 173 }
174 int active_x = (index + 1 == tab_count()) ? 174
175 int active_x = ideal_x(active_index());
176 if (add_types & kAddTypeActive) {
177 active_x = (index + 1 == tab_count()) ?
175 width_ - size_.width() : ideal_x(index + 1); 178 width_ - size_.width() : ideal_x(index + 1);
179 }
180
176 SetIdealBoundsAt(active_index(), ConstrainActiveX(active_x)); 181 SetIdealBoundsAt(active_index(), ConstrainActiveX(active_x));
177 LayoutByTabOffsetAfter(active_index()); 182 LayoutByTabOffsetAfter(active_index());
178 LayoutByTabOffsetBefore(active_index()); 183 LayoutByTabOffsetBefore(active_index());
179 AdjustStackedTabs(); 184 AdjustStackedTabs();
180 185
181 if ((add_types & kAddTypeActive) == 0) 186 if ((add_types & kAddTypeActive) == 0)
182 MakeVisible(index); 187 MakeVisible(index);
183 } 188 }
184 189
185 void StackedTabStripLayout::RemoveTab(int index, int start_x, int old_x) { 190 void StackedTabStripLayout::RemoveTab(int index, int start_x, int old_x) {
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 ideal_x(tab_count() - 1) != width_ - size_.width()); 334 ideal_x(tab_count() - 1) != width_ - size_.width());
330 } 335 }
331 AdjustStackedTabs(); 336 AdjustStackedTabs();
332 } 337 }
333 338
334 void StackedTabStripLayout::MakeVisible(int index) { 339 void StackedTabStripLayout::MakeVisible(int index) {
335 // Currently no need to support tabs opening before |index| visible. 340 // Currently no need to support tabs opening before |index| visible.
336 if (index <= active_index() || !requires_stacking() || !IsStacked(index)) 341 if (index <= active_index() || !requires_stacking() || !IsStacked(index))
337 return; 342 return;
338 343
339 int ideal_delta = width_for_count(index - active_index()) - overlap_; 344 const int ideal_delta = width_for_count(index - active_index()) - overlap_;
340 if (ideal_x(index) - ideal_x(active_index()) == ideal_delta) 345 if (ideal_x(index) - ideal_x(active_index()) == ideal_delta)
341 return; 346 return;
342 347
343 // First push active index as far to the left as it'll go. 348 // Move the active tab to the left so that all tabs between the active tab
344 int active_x = std::max(GetMinX(active_index()), 349 // and |index| (inclusive) can be made visible.
345 std::min(ideal_x(index) - ideal_delta, 350 const int active_x = std::max(GetMinX(active_index()),
346 ideal_x(active_index()))); 351 std::min(ideal_x(index) - ideal_delta,
352 ideal_x(active_index())));
347 SetIdealBoundsAt(active_index(), active_x); 353 SetIdealBoundsAt(active_index(), active_x);
348 LayoutUsingCurrentBefore(active_index()); 354 LayoutByTabOffsetBefore(active_index());
349 LayoutUsingCurrentAfter(active_index()); 355 LayoutByTabOffsetAfter(active_index());
Peter Kasting 2017/06/28 22:04:33 This now leaves only one caller of LayoutUsingCurr
tdanderson 2017/06/29 16:01:04 There are actually still two: SetActiveBoundsAndLa
350 AdjustStackedTabs(); 356 AdjustStackedTabs();
357
351 if (ideal_x(index) - ideal_x(active_index()) == ideal_delta) 358 if (ideal_x(index) - ideal_x(active_index()) == ideal_delta)
352 return; 359 return;
353 360
354 // If we get here active_index() is left aligned. Push |index| as far to 361 // If we get here active_index() is left aligned. Push |index| as far to
355 // the right as possible. 362 // the right as possible, forming a stack immediately to the right of the
356 int x = std::min(GetMaxX(index), active_x + ideal_delta); 363 // active tab if necessary.
364 const int x = std::min(GetMaxX(index), active_x + ideal_delta);
357 SetIdealBoundsAt(index, x); 365 SetIdealBoundsAt(index, x);
358 LayoutByTabOffsetAfter(index); 366 LayoutByTabOffsetAfter(index);
359 for (int next_x = x, i = index - 1; i > active_index(); --i) { 367 for (int next_x = x, i = index - 1; i > active_index(); --i) {
360 next_x = std::max(GetMinXCompressed(i), next_x - tab_offset()); 368 next_x = std::max(GetMinXCompressed(i), next_x - tab_offset());
361 SetIdealBoundsAt(i, next_x); 369 SetIdealBoundsAt(i, next_x);
362 } 370 }
363 LayoutUsingCurrentAfter(active_index()); 371 LayoutUsingCurrentAfter(active_index());
364 AdjustStackedTabs(); 372 AdjustStackedTabs();
365 } 373 }
366 374
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
577 return width_ - trailing_offset - size_.width(); 585 return width_ - trailing_offset - size_.width();
578 } 586 }
579 587
580 int StackedTabStripLayout::GetMinXCompressed(int index) const { 588 int StackedTabStripLayout::GetMinXCompressed(int index) const {
581 DCHECK_GT(index, active_index()); 589 DCHECK_GT(index, active_index());
582 return std::max( 590 return std::max(
583 width_ - width_for_count(tab_count() - index), 591 width_ - width_for_count(tab_count() - index),
584 ideal_x(active_index()) + 592 ideal_x(active_index()) +
585 stacked_padding_for_count(index - active_index())); 593 stacked_padding_for_count(index - active_index()));
586 } 594 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698