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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 width_ - size_.width() : ideal_x(index + 1); | 102 width_ - size_.width() : ideal_x(index + 1); |
103 SetIdealBoundsAt(active_index(), ConstrainActiveX(active_x)); | 103 SetIdealBoundsAt(active_index(), ConstrainActiveX(active_x)); |
104 LayoutByTabOffsetAfter(active_index()); | 104 LayoutByTabOffsetAfter(active_index()); |
105 LayoutByTabOffsetBefore(active_index()); | 105 LayoutByTabOffsetBefore(active_index()); |
106 AdjustStackedTabs(); | 106 AdjustStackedTabs(); |
107 } | 107 } |
108 | 108 |
109 void TouchTabStripLayout::RemoveTab(int index, int start_x, int old_x) { | 109 void TouchTabStripLayout::RemoveTab(int index, int start_x, int old_x) { |
110 if (index == active_index_) | 110 if (index == active_index_) |
111 active_index_ = std::min(active_index_, tab_count() - 1); | 111 active_index_ = std::min(active_index_, tab_count() - 1); |
112 else if (index > active_index_) | 112 else if (index < active_index_) |
113 active_index_--; | 113 active_index_--; |
114 bool removed_mini_tab = index < mini_tab_count_; | 114 bool removed_mini_tab = index < mini_tab_count_; |
115 if (removed_mini_tab) { | 115 if (removed_mini_tab) { |
116 mini_tab_count_--; | 116 mini_tab_count_--; |
117 DCHECK_GE(mini_tab_count_, 0); | 117 DCHECK_GE(mini_tab_count_, 0); |
118 } | 118 } |
119 int delta = start_x - x_; | 119 int delta = start_x - x_; |
120 x_ = start_x; | 120 x_ = start_x; |
121 if (!requires_stacking()) { | 121 if (!requires_stacking()) { |
122 ResetToIdealState(); | 122 ResetToIdealState(); |
123 return; | 123 return; |
124 } | 124 } |
125 if (removed_mini_tab) { | 125 if (removed_mini_tab) { |
126 for (int i = mini_tab_count_; i < tab_count(); ++i) | 126 for (int i = mini_tab_count_; i < tab_count(); ++i) |
127 SetIdealBoundsAt(i, ideal_x(i) + delta); | 127 SetIdealBoundsAt(i, ideal_x(i) + delta); |
128 } | 128 } |
129 SetActiveBoundsAndLayoutFromActiveTab(); | 129 SetActiveBoundsAndLayoutFromActiveTab(); |
130 AdjustStackedTabs(); | 130 AdjustStackedTabs(); |
131 } | 131 } |
132 | 132 |
133 void TouchTabStripLayout::MoveTab(int from, | 133 void TouchTabStripLayout::MoveTab(int from, |
134 int to, | 134 int to, |
135 int new_active_index, | 135 int new_active_index, |
136 int start_x, | 136 int start_x, |
137 int mini_tab_count) { | 137 int mini_tab_count) { |
138 x_ = start_x; | 138 x_ = start_x; |
139 mini_tab_count_ = mini_tab_count; | 139 mini_tab_count_ = mini_tab_count; |
140 active_index_ = new_active_index; | 140 active_index_ = new_active_index; |
| 141 if (!requires_stacking() || tab_count() == mini_tab_count_) { |
| 142 ResetToIdealState(); |
| 143 return; |
| 144 } |
141 SetIdealBoundsAt(active_index(), ConstrainActiveX(ideal_x(active_index()))); | 145 SetIdealBoundsAt(active_index(), ConstrainActiveX(ideal_x(active_index()))); |
142 LayoutByTabOffsetAfter(active_index()); | 146 LayoutByTabOffsetAfter(active_index()); |
143 LayoutByTabOffsetBefore(active_index()); | 147 LayoutByTabOffsetBefore(active_index()); |
144 AdjustStackedTabs(); | 148 AdjustStackedTabs(); |
145 } | 149 } |
146 | 150 |
| 151 bool TouchTabStripLayout::IsStacked(int index) const { |
| 152 if (index == active_index() || tab_count() == mini_tab_count_) |
| 153 return false; |
| 154 if (index > active_index()) |
| 155 return ideal_x(index) != ideal_x(index - 1) + tab_offset(); |
| 156 return ideal_x(index + 1) != ideal_x(index) + tab_offset(); |
| 157 } |
| 158 |
147 void TouchTabStripLayout::Reset(int x, | 159 void TouchTabStripLayout::Reset(int x, |
148 int width, | 160 int width, |
149 int mini_tab_count, | 161 int mini_tab_count, |
150 int active_index) { | 162 int active_index) { |
151 x_ = x; | 163 x_ = x; |
152 width_ = width; | 164 width_ = width; |
153 mini_tab_count_ = mini_tab_count; | 165 mini_tab_count_ = mini_tab_count; |
154 active_index_ = active_index; | 166 active_index_ = active_index; |
155 ResetToIdealState(); | 167 ResetToIdealState(); |
156 } | 168 } |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 result += " "; | 389 result += " "; |
378 if (i == active_index()) | 390 if (i == active_index()) |
379 result += "["; | 391 result += "["; |
380 result += base::IntToString(view_model_->ideal_bounds(i).x()); | 392 result += base::IntToString(view_model_->ideal_bounds(i).x()); |
381 if (i == active_index()) | 393 if (i == active_index()) |
382 result += "]"; | 394 result += "]"; |
383 } | 395 } |
384 return result; | 396 return result; |
385 } | 397 } |
386 #endif | 398 #endif |
OLD | NEW |