OLD | NEW |
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/touch_tab_strip_layout.h" | 5 #include "chrome/browser/ui/views/tabs/touch_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/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 if (!requires_stacking() || normal_tab_count() <= 1) { | 101 if (!requires_stacking() || normal_tab_count() <= 1) { |
102 ResetToIdealState(); | 102 ResetToIdealState(); |
103 return; | 103 return; |
104 } | 104 } |
105 int active_x = (index + 1 == tab_count()) ? | 105 int active_x = (index + 1 == tab_count()) ? |
106 width_ - size_.width() : ideal_x(index + 1); | 106 width_ - size_.width() : ideal_x(index + 1); |
107 SetIdealBoundsAt(active_index(), ConstrainActiveX(active_x)); | 107 SetIdealBoundsAt(active_index(), ConstrainActiveX(active_x)); |
108 LayoutByTabOffsetAfter(active_index()); | 108 LayoutByTabOffsetAfter(active_index()); |
109 LayoutByTabOffsetBefore(active_index()); | 109 LayoutByTabOffsetBefore(active_index()); |
110 AdjustStackedTabs(); | 110 AdjustStackedTabs(); |
| 111 |
| 112 if ((add_types & kAddTypeActive) == 0) |
| 113 MakeVisible(index); |
111 } | 114 } |
112 | 115 |
113 void TouchTabStripLayout::RemoveTab(int index, int start_x, int old_x) { | 116 void TouchTabStripLayout::RemoveTab(int index, int start_x, int old_x) { |
114 if (index == active_index_) | 117 if (index == active_index_) |
115 active_index_ = std::min(active_index_, tab_count() - 1); | 118 active_index_ = std::min(active_index_, tab_count() - 1); |
116 else if (index < active_index_) | 119 else if (index < active_index_) |
117 active_index_--; | 120 active_index_--; |
118 bool removed_mini_tab = index < mini_tab_count_; | 121 bool removed_mini_tab = index < mini_tab_count_; |
119 if (removed_mini_tab) { | 122 if (removed_mini_tab) { |
120 mini_tab_count_--; | 123 mini_tab_count_--; |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 SetIdealBoundsAt(index, x_ + stacked_padding); | 224 SetIdealBoundsAt(index, x_ + stacked_padding); |
222 LayoutByTabOffsetAfter(index); | 225 LayoutByTabOffsetAfter(index); |
223 LayoutByTabOffsetBefore(index); | 226 LayoutByTabOffsetBefore(index); |
224 index--; | 227 index--; |
225 } while (index >= mini_tab_count_ && ideal_x(mini_tab_count_) != x_ && | 228 } while (index >= mini_tab_count_ && ideal_x(mini_tab_count_) != x_ && |
226 ideal_x(tab_count() - 1) != width_ - size_.width()); | 229 ideal_x(tab_count() - 1) != width_ - size_.width()); |
227 } | 230 } |
228 AdjustStackedTabs(); | 231 AdjustStackedTabs(); |
229 } | 232 } |
230 | 233 |
| 234 void TouchTabStripLayout::MakeVisible(int index) { |
| 235 // Currently no need to support tabs openning before |index| visible. |
| 236 if (index <= active_index() || !requires_stacking() || !IsStacked(index)) |
| 237 return; |
| 238 |
| 239 int ideal_delta = width_for_count(index - active_index()) + padding_; |
| 240 if (ideal_x(index) - ideal_x(active_index()) == ideal_delta) |
| 241 return; |
| 242 |
| 243 // First push active index as far to the left as it'll go. |
| 244 int active_x = std::max(GetMinX(active_index()), |
| 245 std::min(ideal_x(index) - ideal_delta, |
| 246 ideal_x(active_index()))); |
| 247 SetIdealBoundsAt(active_index(), active_x); |
| 248 LayoutUsingCurrentBefore(active_index()); |
| 249 LayoutUsingCurrentAfter(active_index()); |
| 250 AdjustStackedTabs(); |
| 251 if (ideal_x(index) - ideal_x(active_index()) == ideal_delta) |
| 252 return; |
| 253 |
| 254 // If we get here active_index() is left aligned. Push |index| as far to |
| 255 // the right as possible. |
| 256 int x = std::min(GetMaxX(index), active_x + ideal_delta); |
| 257 SetIdealBoundsAt(index, x); |
| 258 LayoutByTabOffsetAfter(index); |
| 259 for (int next_x = x, i = index - 1; i > active_index(); --i) { |
| 260 next_x = std::max(GetMinXCompressed(i), next_x - tab_offset()); |
| 261 SetIdealBoundsAt(i, next_x); |
| 262 } |
| 263 LayoutUsingCurrentAfter(active_index()); |
| 264 AdjustStackedTabs(); |
| 265 } |
| 266 |
231 int TouchTabStripLayout::ConstrainActiveX(int x) const { | 267 int TouchTabStripLayout::ConstrainActiveX(int x) const { |
232 return std::min(GetMaxX(active_index()), | 268 return std::min(GetMaxX(active_index()), |
233 std::max(GetMinX(active_index()), x)); | 269 std::max(GetMinX(active_index()), x)); |
234 } | 270 } |
235 | 271 |
236 void TouchTabStripLayout::SetActiveBoundsAndLayoutFromActiveTab() { | 272 void TouchTabStripLayout::SetActiveBoundsAndLayoutFromActiveTab() { |
237 int x = ConstrainActiveX(ideal_x(active_index())); | 273 int x = ConstrainActiveX(ideal_x(active_index())); |
238 SetIdealBoundsAt(active_index(), x); | 274 SetIdealBoundsAt(active_index(), x); |
239 LayoutUsingCurrentBefore(active_index()); | 275 LayoutUsingCurrentBefore(active_index()); |
240 LayoutUsingCurrentAfter(active_index()); | 276 LayoutUsingCurrentAfter(active_index()); |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
397 } | 433 } |
398 | 434 |
399 int TouchTabStripLayout::GetMinXCompressed(int index) const { | 435 int TouchTabStripLayout::GetMinXCompressed(int index) const { |
400 DCHECK_GT(index, active_index()); | 436 DCHECK_GT(index, active_index()); |
401 return std::max( | 437 return std::max( |
402 width_ - width_for_count(tab_count() - index), | 438 width_ - width_for_count(tab_count() - index), |
403 ideal_x(active_index()) + | 439 ideal_x(active_index()) + |
404 stacked_padding_for_count(index - active_index())); | 440 stacked_padding_for_count(index - active_index())); |
405 | 441 |
406 } | 442 } |
OLD | NEW |