| 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" | |
| 9 #include "chrome/browser/ui/view_ids.h" | 8 #include "chrome/browser/ui/view_ids.h" |
| 10 #include "chrome/browser/ui/views/tabs/dragged_tab_controller.h" | 9 #include "chrome/browser/ui/views/tabs/dragged_tab_controller.h" |
| 11 #include "chrome/browser/ui/views/tabs/tab_strip_controller.h" | 10 #include "chrome/browser/ui/views/tabs/tab_strip_controller.h" |
| 12 #include "views/widget/root_view.h" | 11 #include "views/widget/root_view.h" |
| 13 #include "views/window/window.h" | 12 #include "views/window/window.h" |
| 14 | 13 |
| 15 #if defined(OS_WIN) | 14 #if defined(OS_WIN) |
| 16 // GET_X_LPARAM, et al. | 15 // GET_X_LPARAM, et al. |
| 17 #include <windowsx.h> | 16 #include <windowsx.h> |
| 18 #endif | 17 #endif |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 | 124 |
| 126 BaseTabStrip::~BaseTabStrip() { | 125 BaseTabStrip::~BaseTabStrip() { |
| 127 } | 126 } |
| 128 | 127 |
| 129 void BaseTabStrip::AddTabAt(int model_index, const TabRendererData& data) { | 128 void BaseTabStrip::AddTabAt(int model_index, const TabRendererData& data) { |
| 130 BaseTab* tab = CreateTab(); | 129 BaseTab* tab = CreateTab(); |
| 131 tab->SetData(data); | 130 tab->SetData(data); |
| 132 | 131 |
| 133 TabData d = { tab, gfx::Rect() }; | 132 TabData d = { tab, gfx::Rect() }; |
| 134 tab_data_.insert(tab_data_.begin() + ModelIndexToTabIndex(model_index), d); | 133 tab_data_.insert(tab_data_.begin() + ModelIndexToTabIndex(model_index), d); |
| 135 UpdateCommonTitlePrefix(); | |
| 136 | 134 |
| 137 AddChildView(tab); | 135 AddChildView(tab); |
| 138 | 136 |
| 139 // Don't animate the first tab, it looks weird, and don't animate anything | 137 // Don't animate the first tab, it looks weird, and don't animate anything |
| 140 // if the containing window isn't visible yet. | 138 // if the containing window isn't visible yet. |
| 141 if (tab_count() > 1 && GetWindow() && GetWindow()->IsVisible()) | 139 if (tab_count() > 1 && GetWindow() && GetWindow()->IsVisible()) |
| 142 StartInsertTabAnimation(model_index); | 140 StartInsertTabAnimation(model_index); |
| 143 else | 141 else |
| 144 DoLayout(); | 142 DoLayout(); |
| 145 } | 143 } |
| 146 | 144 |
| 147 void BaseTabStrip::MoveTab(int from_model_index, int to_model_index) { | 145 void BaseTabStrip::MoveTab(int from_model_index, int to_model_index) { |
| 148 int from_tab_data_index = ModelIndexToTabIndex(from_model_index); | 146 int from_tab_data_index = ModelIndexToTabIndex(from_model_index); |
| 149 BaseTab* tab = tab_data_[from_tab_data_index].tab; | 147 BaseTab* tab = tab_data_[from_tab_data_index].tab; |
| 150 tab_data_.erase(tab_data_.begin() + from_tab_data_index); | 148 tab_data_.erase(tab_data_.begin() + from_tab_data_index); |
| 151 | 149 |
| 152 TabData data = {tab, gfx::Rect()}; | 150 TabData data = {tab, gfx::Rect()}; |
| 153 int to_tab_data_index = ModelIndexToTabIndex(to_model_index); | 151 int to_tab_data_index = ModelIndexToTabIndex(to_model_index); |
| 154 tab_data_.insert(tab_data_.begin() + to_tab_data_index, data); | 152 tab_data_.insert(tab_data_.begin() + to_tab_data_index, data); |
| 155 | 153 |
| 156 StartMoveTabAnimation(); | 154 StartMoveTabAnimation(); |
| 157 } | 155 } |
| 158 | 156 |
| 159 void BaseTabStrip::SetTabData(int model_index, const TabRendererData& data) { | 157 void BaseTabStrip::SetTabData(int model_index, const TabRendererData& data) { |
| 160 BaseTab* tab = GetBaseTabAtModelIndex(model_index); | 158 BaseTab* tab = GetBaseTabAtModelIndex(model_index); |
| 161 bool mini_state_changed = tab->data().mini != data.mini; | 159 bool mini_state_changed = tab->data().mini != data.mini; |
| 162 tab->SetData(data); | 160 tab->SetData(data); |
| 163 UpdateCommonTitlePrefix(); | |
| 164 | 161 |
| 165 if (mini_state_changed) { | 162 if (mini_state_changed) { |
| 166 if (GetWindow() && GetWindow()->IsVisible()) | 163 if (GetWindow() && GetWindow()->IsVisible()) |
| 167 StartMiniTabAnimation(); | 164 StartMiniTabAnimation(); |
| 168 else | 165 else |
| 169 DoLayout(); | 166 DoLayout(); |
| 170 } | 167 } |
| 171 } | 168 } |
| 172 | 169 |
| 173 BaseTab* BaseTabStrip::GetBaseTabAtModelIndex(int model_index) const { | 170 BaseTab* BaseTabStrip::GetBaseTabAtModelIndex(int model_index) const { |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 | 463 |
| 467 void BaseTabStrip::RemoveAndDeleteTab(BaseTab* tab) { | 464 void BaseTabStrip::RemoveAndDeleteTab(BaseTab* tab) { |
| 468 int tab_data_index = TabIndexOfTab(tab); | 465 int tab_data_index = TabIndexOfTab(tab); |
| 469 | 466 |
| 470 DCHECK(tab_data_index != -1); | 467 DCHECK(tab_data_index != -1); |
| 471 | 468 |
| 472 // Remove the Tab from the TabStrip's list... | 469 // Remove the Tab from the TabStrip's list... |
| 473 tab_data_.erase(tab_data_.begin() + tab_data_index); | 470 tab_data_.erase(tab_data_.begin() + tab_data_index); |
| 474 | 471 |
| 475 delete tab; | 472 delete tab; |
| 476 UpdateCommonTitlePrefix(); | |
| 477 } | |
| 478 | |
| 479 bool BaseTabStrip::IgnoreTitlePrefixEliding(BaseTab* tab) { | |
| 480 DCHECK(tab != NULL); | |
| 481 return tab->data().mini || tab->data().title.empty(); | |
| 482 } | |
| 483 | |
| 484 void BaseTabStrip::UpdateCommonTitlePrefix() { | |
| 485 std::vector<TitlePrefixMatcher::TitleInfo> tab_title_infos; | |
| 486 for (int tab_index = 0; tab_index < tab_count(); ++tab_index) { | |
| 487 DCHECK(tab_data_[tab_index].tab != NULL); | |
| 488 if (!IgnoreTitlePrefixEliding(tab_data_[tab_index].tab)) { | |
| 489 tab_title_infos.push_back(TitlePrefixMatcher::TitleInfo( | |
| 490 &tab_data_[tab_index].tab->data().title, | |
| 491 tab_data_[tab_index].tab->data().url, | |
| 492 tab_index)); | |
| 493 } | |
| 494 } | |
| 495 TitlePrefixMatcher::CalculatePrefixLengths(&tab_title_infos); | |
| 496 for (size_t title_index = 0; title_index < tab_title_infos.size(); | |
| 497 ++title_index) { | |
| 498 int tab_index = tab_title_infos[title_index].caller_value; | |
| 499 TabRendererData data = tab_data_[tab_index].tab->data(); | |
| 500 if (data.common_prefix_length != | |
| 501 tab_title_infos[title_index].prefix_length) { | |
| 502 data.common_prefix_length = tab_title_infos[title_index].prefix_length; | |
| 503 tab_data_[tab_index].tab->SetData(data); | |
| 504 } | |
| 505 } | |
| 506 } | 473 } |
| 507 | 474 |
| 508 int BaseTabStrip::TabIndexOfTab(BaseTab* tab) const { | 475 int BaseTabStrip::TabIndexOfTab(BaseTab* tab) const { |
| 509 for (int i = 0; i < tab_count(); ++i) { | 476 for (int i = 0; i < tab_count(); ++i) { |
| 510 if (base_tab_at_tab_index(i) == tab) | 477 if (base_tab_at_tab_index(i) == tab) |
| 511 return i; | 478 return i; |
| 512 } | 479 } |
| 513 return -1; | 480 return -1; |
| 514 } | 481 } |
| 515 | 482 |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 613 // Animate the view back to its correct position. | 580 // Animate the view back to its correct position. |
| 614 GenerateIdealBounds(); | 581 GenerateIdealBounds(); |
| 615 AnimateToIdealBounds(); | 582 AnimateToIdealBounds(); |
| 616 } | 583 } |
| 617 bounds_animator_.AnimateViewTo(tab, ideal_bounds(TabIndexOfTab(tab))); | 584 bounds_animator_.AnimateViewTo(tab, ideal_bounds(TabIndexOfTab(tab))); |
| 618 // Install a delegate to reset the dragging state when done. We have to leave | 585 // Install a delegate to reset the dragging state when done. We have to leave |
| 619 // dragging true for the tab otherwise it'll draw beneath the new tab button. | 586 // dragging true for the tab otherwise it'll draw beneath the new tab button. |
| 620 bounds_animator_.SetAnimationDelegate( | 587 bounds_animator_.SetAnimationDelegate( |
| 621 tab, new ResetDraggingStateDelegate(tab), true); | 588 tab, new ResetDraggingStateDelegate(tab), true); |
| 622 } | 589 } |
| OLD | NEW |