OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/base_tab_strip.h" | 5 #include "chrome/browser/ui/views/tabs/base_tab_strip.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "chrome/browser/ui/title_prefix_matcher.h" |
8 #include "chrome/browser/ui/view_ids.h" | 9 #include "chrome/browser/ui/view_ids.h" |
9 #include "chrome/browser/ui/views/tabs/dragged_tab_controller.h" | 10 #include "chrome/browser/ui/views/tabs/dragged_tab_controller.h" |
10 #include "chrome/browser/ui/views/tabs/tab_strip_controller.h" | 11 #include "chrome/browser/ui/views/tabs/tab_strip_controller.h" |
11 #include "views/widget/root_view.h" | 12 #include "views/widget/root_view.h" |
12 #include "views/window/window.h" | 13 #include "views/window/window.h" |
13 | 14 |
14 #if defined(OS_WIN) | 15 #if defined(OS_WIN) |
15 #include "views/widget/widget_win.h" | 16 #include "views/widget/widget_win.h" |
16 #endif | 17 #endif |
17 | 18 |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 } | 131 } |
131 | 132 |
132 void BaseTabStrip::AddTabAt(int model_index, | 133 void BaseTabStrip::AddTabAt(int model_index, |
133 bool foreground, | 134 bool foreground, |
134 const TabRendererData& data) { | 135 const TabRendererData& data) { |
135 BaseTab* tab = CreateTab(); | 136 BaseTab* tab = CreateTab(); |
136 tab->SetData(data); | 137 tab->SetData(data); |
137 | 138 |
138 TabData d = { tab, gfx::Rect() }; | 139 TabData d = { tab, gfx::Rect() }; |
139 tab_data_.insert(tab_data_.begin() + ModelIndexToTabIndex(model_index), d); | 140 tab_data_.insert(tab_data_.begin() + ModelIndexToTabIndex(model_index), d); |
| 141 UpdateCommonTitlePrefix(); |
140 | 142 |
141 AddChildView(tab); | 143 AddChildView(tab); |
142 | 144 |
143 // Don't animate the first tab, it looks weird, and don't animate anything | 145 // Don't animate the first tab, it looks weird, and don't animate anything |
144 // if the containing window isn't visible yet. | 146 // if the containing window isn't visible yet. |
145 if (tab_count() > 1 && GetWindow() && GetWindow()->IsVisible()) | 147 if (tab_count() > 1 && GetWindow() && GetWindow()->IsVisible()) |
146 StartInsertTabAnimation(model_index, foreground); | 148 StartInsertTabAnimation(model_index, foreground); |
147 else | 149 else |
148 DoLayout(); | 150 DoLayout(); |
149 } | 151 } |
(...skipping 10 matching lines...) Expand all Loading... |
160 | 162 |
161 tab_data_.insert(tab_data_.begin() + to_tab_data_index, data); | 163 tab_data_.insert(tab_data_.begin() + to_tab_data_index, data); |
162 | 164 |
163 StartMoveTabAnimation(); | 165 StartMoveTabAnimation(); |
164 } | 166 } |
165 | 167 |
166 void BaseTabStrip::SetTabData(int model_index, const TabRendererData& data) { | 168 void BaseTabStrip::SetTabData(int model_index, const TabRendererData& data) { |
167 BaseTab* tab = GetBaseTabAtModelIndex(model_index); | 169 BaseTab* tab = GetBaseTabAtModelIndex(model_index); |
168 bool mini_state_changed = tab->data().mini != data.mini; | 170 bool mini_state_changed = tab->data().mini != data.mini; |
169 tab->SetData(data); | 171 tab->SetData(data); |
| 172 UpdateCommonTitlePrefix(); |
170 | 173 |
171 if (mini_state_changed) { | 174 if (mini_state_changed) { |
172 if (GetWindow() && GetWindow()->IsVisible()) | 175 if (GetWindow() && GetWindow()->IsVisible()) |
173 StartMiniTabAnimation(); | 176 StartMiniTabAnimation(); |
174 else | 177 else |
175 DoLayout(); | 178 DoLayout(); |
176 } | 179 } |
177 } | 180 } |
178 | 181 |
179 BaseTab* BaseTabStrip::GetBaseTabAtModelIndex(int model_index) const { | 182 BaseTab* BaseTabStrip::GetBaseTabAtModelIndex(int model_index) const { |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 | 421 |
419 void BaseTabStrip::RemoveAndDeleteTab(BaseTab* tab) { | 422 void BaseTabStrip::RemoveAndDeleteTab(BaseTab* tab) { |
420 int tab_data_index = TabIndexOfTab(tab); | 423 int tab_data_index = TabIndexOfTab(tab); |
421 | 424 |
422 DCHECK(tab_data_index != -1); | 425 DCHECK(tab_data_index != -1); |
423 | 426 |
424 // Remove the Tab from the TabStrip's list... | 427 // Remove the Tab from the TabStrip's list... |
425 tab_data_.erase(tab_data_.begin() + tab_data_index); | 428 tab_data_.erase(tab_data_.begin() + tab_data_index); |
426 | 429 |
427 delete tab; | 430 delete tab; |
| 431 UpdateCommonTitlePrefix(); |
| 432 } |
| 433 |
| 434 void BaseTabStrip::UpdateCommonTitlePrefix() { |
| 435 std::vector<TitlePrefixMatcher::TitleInfo> tab_title_infos; |
| 436 for (int tab_index = 0; tab_index < tab_count(); ++tab_index) { |
| 437 DCHECK(tab_data_[tab_index].tab != NULL); |
| 438 if (!tab_data_[tab_index].tab->data().mini && |
| 439 !tab_data_[tab_index].tab->data().title.empty()) { |
| 440 tab_title_infos.push_back(TitlePrefixMatcher::TitleInfo( |
| 441 &tab_data_[tab_index].tab->data().title, tab_index)); |
| 442 } |
| 443 } |
| 444 TitlePrefixMatcher::CalculatePrefixLengths(&tab_title_infos); |
| 445 for (size_t title_index = 0; title_index < tab_title_infos.size(); |
| 446 ++title_index) { |
| 447 int tab_index = tab_title_infos[title_index].caller_value; |
| 448 TabRendererData data = tab_data_[tab_index].tab->data(); |
| 449 if (data.common_prefix_length != |
| 450 tab_title_infos[title_index].prefix_length) { |
| 451 data.common_prefix_length = tab_title_infos[title_index].prefix_length; |
| 452 tab_data_[tab_index].tab->SetData(data); |
| 453 } |
| 454 } |
428 } | 455 } |
429 | 456 |
430 int BaseTabStrip::TabIndexOfTab(BaseTab* tab) const { | 457 int BaseTabStrip::TabIndexOfTab(BaseTab* tab) const { |
431 for (int i = 0; i < tab_count(); ++i) { | 458 for (int i = 0; i < tab_count(); ++i) { |
432 if (base_tab_at_tab_index(i) == tab) | 459 if (base_tab_at_tab_index(i) == tab) |
433 return i; | 460 return i; |
434 } | 461 } |
435 return -1; | 462 return -1; |
436 } | 463 } |
437 | 464 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
509 | 536 |
510 StopAnimating(false); | 537 StopAnimating(false); |
511 | 538 |
512 GenerateIdealBounds(); | 539 GenerateIdealBounds(); |
513 | 540 |
514 for (int i = 0; i < tab_count(); ++i) | 541 for (int i = 0; i < tab_count(); ++i) |
515 tab_data_[i].tab->SetBoundsRect(tab_data_[i].ideal_bounds); | 542 tab_data_[i].tab->SetBoundsRect(tab_data_[i].ideal_bounds); |
516 | 543 |
517 SchedulePaint(); | 544 SchedulePaint(); |
518 } | 545 } |
OLD | NEW |