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 <vector> | |
8 | |
9 #include "base/command_line.h" | |
10 #include "base/hash_tables.h" | |
7 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/string_split.h" | |
13 #include "chrome/browser/ui/title_prefix_matcher.h" | |
8 #include "chrome/browser/ui/view_ids.h" | 14 #include "chrome/browser/ui/view_ids.h" |
9 #include "chrome/browser/ui/views/tabs/dragged_tab_controller.h" | 15 #include "chrome/browser/ui/views/tabs/dragged_tab_controller.h" |
10 #include "chrome/browser/ui/views/tabs/tab_strip_controller.h" | 16 #include "chrome/browser/ui/views/tabs/tab_strip_controller.h" |
17 #include "chrome/common/chrome_switches.h" | |
sky
2011/03/11 00:00:45
Do we know this include anymore? In fact I suspect
MAD
2011/03/11 03:01:37
D'ho...ne.
Sorry about that...
| |
11 #include "views/widget/root_view.h" | 18 #include "views/widget/root_view.h" |
12 #include "views/window/window.h" | 19 #include "views/window/window.h" |
13 | 20 |
14 #if defined(OS_WIN) | 21 #if defined(OS_WIN) |
15 #include "views/widget/widget_win.h" | 22 #include "views/widget/widget_win.h" |
16 #endif | 23 #endif |
17 | 24 |
18 namespace { | 25 namespace { |
19 | 26 |
20 // Animation delegate used when a dragged tab is released. When done sets the | 27 // Animation delegate used when a dragged tab is released. When done sets the |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
134 } | 141 } |
135 | 142 |
136 void BaseTabStrip::AddTabAt(int model_index, | 143 void BaseTabStrip::AddTabAt(int model_index, |
137 bool foreground, | 144 bool foreground, |
138 const TabRendererData& data) { | 145 const TabRendererData& data) { |
139 BaseTab* tab = CreateTab(); | 146 BaseTab* tab = CreateTab(); |
140 tab->SetData(data); | 147 tab->SetData(data); |
141 | 148 |
142 TabData d = { tab, gfx::Rect() }; | 149 TabData d = { tab, gfx::Rect() }; |
143 tab_data_.insert(tab_data_.begin() + ModelIndexToTabIndex(model_index), d); | 150 tab_data_.insert(tab_data_.begin() + ModelIndexToTabIndex(model_index), d); |
151 UpdateCommonTitlePrefix(); | |
144 | 152 |
145 AddChildView(tab); | 153 AddChildView(tab); |
146 | 154 |
147 // Don't animate the first tab, it looks weird, and don't animate anything | 155 // Don't animate the first tab, it looks weird, and don't animate anything |
148 // if the containing window isn't visible yet. | 156 // if the containing window isn't visible yet. |
149 if (tab_count() > 1 && GetWindow() && GetWindow()->IsVisible()) | 157 if (tab_count() > 1 && GetWindow() && GetWindow()->IsVisible()) |
150 StartInsertTabAnimation(model_index, foreground); | 158 StartInsertTabAnimation(model_index, foreground); |
151 else | 159 else |
152 DoLayout(); | 160 DoLayout(); |
153 } | 161 } |
(...skipping 10 matching lines...) Expand all Loading... | |
164 | 172 |
165 tab_data_.insert(tab_data_.begin() + to_tab_data_index, data); | 173 tab_data_.insert(tab_data_.begin() + to_tab_data_index, data); |
166 | 174 |
167 StartMoveTabAnimation(); | 175 StartMoveTabAnimation(); |
168 } | 176 } |
169 | 177 |
170 void BaseTabStrip::SetTabData(int model_index, const TabRendererData& data) { | 178 void BaseTabStrip::SetTabData(int model_index, const TabRendererData& data) { |
171 BaseTab* tab = GetBaseTabAtModelIndex(model_index); | 179 BaseTab* tab = GetBaseTabAtModelIndex(model_index); |
172 bool mini_state_changed = tab->data().mini != data.mini; | 180 bool mini_state_changed = tab->data().mini != data.mini; |
173 tab->SetData(data); | 181 tab->SetData(data); |
182 UpdateCommonTitlePrefix(); | |
174 | 183 |
175 if (mini_state_changed) { | 184 if (mini_state_changed) { |
176 if (GetWindow() && GetWindow()->IsVisible()) | 185 if (GetWindow() && GetWindow()->IsVisible()) |
177 StartMiniTabAnimation(); | 186 StartMiniTabAnimation(); |
178 else | 187 else |
179 DoLayout(); | 188 DoLayout(); |
180 } | 189 } |
181 } | 190 } |
182 | 191 |
183 BaseTab* BaseTabStrip::GetBaseTabAtModelIndex(int model_index) const { | 192 BaseTab* BaseTabStrip::GetBaseTabAtModelIndex(int model_index) const { |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
396 | 405 |
397 void BaseTabStrip::RemoveAndDeleteTab(BaseTab* tab) { | 406 void BaseTabStrip::RemoveAndDeleteTab(BaseTab* tab) { |
398 int tab_data_index = TabIndexOfTab(tab); | 407 int tab_data_index = TabIndexOfTab(tab); |
399 | 408 |
400 DCHECK(tab_data_index != -1); | 409 DCHECK(tab_data_index != -1); |
401 | 410 |
402 // Remove the Tab from the TabStrip's list... | 411 // Remove the Tab from the TabStrip's list... |
403 tab_data_.erase(tab_data_.begin() + tab_data_index); | 412 tab_data_.erase(tab_data_.begin() + tab_data_index); |
404 | 413 |
405 delete tab; | 414 delete tab; |
415 UpdateCommonTitlePrefix(); | |
416 } | |
417 | |
418 void BaseTabStrip::UpdateCommonTitlePrefix() { | |
419 std::vector<browser::TitlePrefixMatcher::TitleInfo> tab_title_infos; | |
420 for (int tab_index = 0; tab_index < tab_count(); ++tab_index) { | |
421 DCHECK(tab_data_[tab_index].tab != NULL); | |
422 if (!tab_data_[tab_index].tab->data().mini && | |
423 !tab_data_[tab_index].tab->data().title.empty()) { | |
424 tab_title_infos.push_back(browser::TitlePrefixMatcher::TitleInfo( | |
425 &tab_data_[tab_index].tab->data().title, tab_index)); | |
426 } | |
427 } | |
428 browser::TitlePrefixMatcher::CalculatePrefixLengths(&tab_title_infos); | |
429 for (size_t title_index = 0; title_index < tab_title_infos.size(); | |
430 ++title_index) { | |
431 int tab_index = tab_title_infos[title_index].caller_value; | |
432 TabRendererData data = tab_data_[tab_index].tab->data(); | |
433 if (data.common_prefix_length != | |
434 tab_title_infos[title_index].prefix_length) { | |
435 data.common_prefix_length = tab_title_infos[title_index].prefix_length; | |
436 tab_data_[tab_index].tab->SetData(data); | |
sky
2011/03/11 00:00:45
Didn't we want a SchedulePaint here?
sky
2011/03/11 00:01:37
Never mind. I see it in BaseTab.
| |
437 } | |
438 } | |
406 } | 439 } |
407 | 440 |
408 int BaseTabStrip::TabIndexOfTab(BaseTab* tab) const { | 441 int BaseTabStrip::TabIndexOfTab(BaseTab* tab) const { |
409 for (int i = 0; i < tab_count(); ++i) { | 442 for (int i = 0; i < tab_count(); ++i) { |
410 if (base_tab_at_tab_index(i) == tab) | 443 if (base_tab_at_tab_index(i) == tab) |
411 return i; | 444 return i; |
412 } | 445 } |
413 return -1; | 446 return -1; |
414 } | 447 } |
415 | 448 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
487 | 520 |
488 StopAnimating(false); | 521 StopAnimating(false); |
489 | 522 |
490 GenerateIdealBounds(); | 523 GenerateIdealBounds(); |
491 | 524 |
492 for (int i = 0; i < tab_count(); ++i) | 525 for (int i = 0; i < tab_count(); ++i) |
493 tab_data_[i].tab->SetBoundsRect(tab_data_[i].ideal_bounds); | 526 tab_data_[i].tab->SetBoundsRect(tab_data_[i].ideal_bounds); |
494 | 527 |
495 SchedulePaint(); | 528 SchedulePaint(); |
496 } | 529 } |
OLD | NEW |