| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/views/tabs/tab_strip.h" | 5 #include "chrome/browser/views/tabs/tab_strip.h" |
| 6 | 6 |
| 7 #include "app/animation_container.h" | 7 #include "app/animation_container.h" |
| 8 #include "app/drag_drop_types.h" | 8 #include "app/drag_drop_types.h" |
| 9 #include "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
| 10 #include "app/os_exchange_data.h" | 10 #include "app/os_exchange_data.h" |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 | 231 |
| 232 DISALLOW_COPY_AND_ASSIGN(RemoveTabDelegate); | 232 DISALLOW_COPY_AND_ASSIGN(RemoveTabDelegate); |
| 233 }; | 233 }; |
| 234 | 234 |
| 235 /////////////////////////////////////////////////////////////////////////////// | 235 /////////////////////////////////////////////////////////////////////////////// |
| 236 // TabStrip, public: | 236 // TabStrip, public: |
| 237 | 237 |
| 238 // static | 238 // static |
| 239 const int TabStrip::mini_to_non_mini_gap_ = 3; | 239 const int TabStrip::mini_to_non_mini_gap_ = 3; |
| 240 | 240 |
| 241 // static |
| 242 const int TabStrip::extra_gap_for_nano_ = 10; |
| 243 |
| 241 TabStrip::TabStrip(TabStripModel* model) | 244 TabStrip::TabStrip(TabStripModel* model) |
| 242 : model_(model), | 245 : model_(model), |
| 243 resize_layout_factory_(this), | 246 resize_layout_factory_(this), |
| 244 added_as_message_loop_observer_(false), | 247 added_as_message_loop_observer_(false), |
| 245 needs_resize_layout_(false), | 248 needs_resize_layout_(false), |
| 246 current_unselected_width_(Tab::GetStandardSize().width()), | 249 current_unselected_width_(Tab::GetStandardSize().width()), |
| 247 current_selected_width_(Tab::GetStandardSize().width()), | 250 current_selected_width_(Tab::GetStandardSize().width()), |
| 248 available_width_for_tabs_(-1), | 251 available_width_for_tabs_(-1), |
| 249 animation_container_(new AnimationContainer()), | 252 animation_container_(new AnimationContainer()), |
| 250 ALLOW_THIS_IN_INITIALIZER_LIST(bounds_animator_(this)), | 253 ALLOW_THIS_IN_INITIALIZER_LIST(bounds_animator_(this)), |
| (...skipping 818 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1069 } | 1072 } |
| 1070 | 1073 |
| 1071 void TabStrip::GetCurrentTabWidths(double* unselected_width, | 1074 void TabStrip::GetCurrentTabWidths(double* unselected_width, |
| 1072 double* selected_width) const { | 1075 double* selected_width) const { |
| 1073 *unselected_width = current_unselected_width_; | 1076 *unselected_width = current_unselected_width_; |
| 1074 *selected_width = current_selected_width_; | 1077 *selected_width = current_selected_width_; |
| 1075 } | 1078 } |
| 1076 | 1079 |
| 1077 void TabStrip::GetDesiredTabWidths(int tab_count, | 1080 void TabStrip::GetDesiredTabWidths(int tab_count, |
| 1078 int mini_tab_count, | 1081 int mini_tab_count, |
| 1082 int nano_tab_count, |
| 1079 double* unselected_width, | 1083 double* unselected_width, |
| 1080 double* selected_width) const { | 1084 double* selected_width) const { |
| 1081 DCHECK(tab_count >= 0 && mini_tab_count >= 0 && mini_tab_count <= tab_count); | 1085 DCHECK(tab_count >= 0 && mini_tab_count >= 0 && mini_tab_count <= tab_count); |
| 1086 DCHECK(nano_tab_count >= 0 && nano_tab_count <= tab_count); |
| 1082 const double min_unselected_width = Tab::GetMinimumUnselectedSize().width(); | 1087 const double min_unselected_width = Tab::GetMinimumUnselectedSize().width(); |
| 1083 const double min_selected_width = Tab::GetMinimumSelectedSize().width(); | 1088 const double min_selected_width = Tab::GetMinimumSelectedSize().width(); |
| 1084 | 1089 |
| 1085 *unselected_width = min_unselected_width; | 1090 *unselected_width = min_unselected_width; |
| 1086 *selected_width = min_selected_width; | 1091 *selected_width = min_selected_width; |
| 1087 | 1092 |
| 1088 if (tab_count == 0) { | 1093 if (tab_count == 0) { |
| 1089 // Return immediately to avoid divide-by-zero below. | 1094 // Return immediately to avoid divide-by-zero below. |
| 1090 return; | 1095 return; |
| 1091 } | 1096 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1110 | 1115 |
| 1111 if (mini_tab_count > 0) { | 1116 if (mini_tab_count > 0) { |
| 1112 available_width -= mini_tab_count * (Tab::GetMiniWidth() + kTabHOffset); | 1117 available_width -= mini_tab_count * (Tab::GetMiniWidth() + kTabHOffset); |
| 1113 tab_count -= mini_tab_count; | 1118 tab_count -= mini_tab_count; |
| 1114 if (tab_count == 0) { | 1119 if (tab_count == 0) { |
| 1115 *selected_width = *unselected_width = Tab::GetStandardSize().width(); | 1120 *selected_width = *unselected_width = Tab::GetStandardSize().width(); |
| 1116 return; | 1121 return; |
| 1117 } | 1122 } |
| 1118 // Account for gap between the last mini-tab and first non-mini-tab. | 1123 // Account for gap between the last mini-tab and first non-mini-tab. |
| 1119 available_width -= mini_to_non_mini_gap_; | 1124 available_width -= mini_to_non_mini_gap_; |
| 1125 // And add some extra space if you have nano tabs in the mix. |
| 1126 if (nano_tab_count > 0) |
| 1127 available_width -= extra_gap_for_nano_; |
| 1120 } | 1128 } |
| 1121 | 1129 |
| 1122 // Calculate the desired tab widths by dividing the available space into equal | 1130 // Calculate the desired tab widths by dividing the available space into equal |
| 1123 // portions. Don't let tabs get larger than the "standard width" or smaller | 1131 // portions. Don't let tabs get larger than the "standard width" or smaller |
| 1124 // than the minimum width for each type, respectively. | 1132 // than the minimum width for each type, respectively. |
| 1125 const int total_offset = kTabHOffset * (tab_count - 1); | 1133 const int total_offset = kTabHOffset * (tab_count - 1); |
| 1126 const double desired_tab_width = std::min((static_cast<double>( | 1134 const double desired_tab_width = std::min((static_cast<double>( |
| 1127 available_width - total_offset) / static_cast<double>(tab_count)), | 1135 available_width - total_offset) / static_cast<double>(tab_count)), |
| 1128 static_cast<double>(Tab::GetStandardSize().width())); | 1136 static_cast<double>(Tab::GetStandardSize().width())); |
| 1129 *unselected_width = std::max(desired_tab_width, min_unselected_width); | 1137 *unselected_width = std::max(desired_tab_width, min_unselected_width); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1169 | 1177 |
| 1170 available_width_for_tabs_ = -1; | 1178 available_width_for_tabs_ = -1; |
| 1171 int mini_tab_count = GetMiniTabCount(); | 1179 int mini_tab_count = GetMiniTabCount(); |
| 1172 if (mini_tab_count == GetTabCount()) { | 1180 if (mini_tab_count == GetTabCount()) { |
| 1173 // Only mini-tabs, we know the tab widths won't have changed (all | 1181 // Only mini-tabs, we know the tab widths won't have changed (all |
| 1174 // mini-tabs have the same width), so there is nothing to do. | 1182 // mini-tabs have the same width), so there is nothing to do. |
| 1175 return; | 1183 return; |
| 1176 } | 1184 } |
| 1177 Tab* first_tab = GetTabAtTabDataIndex(mini_tab_count); | 1185 Tab* first_tab = GetTabAtTabDataIndex(mini_tab_count); |
| 1178 double unselected, selected; | 1186 double unselected, selected; |
| 1179 GetDesiredTabWidths(GetTabCount(), mini_tab_count, &unselected, &selected); | 1187 GetDesiredTabWidths(GetTabCount(), mini_tab_count, GetNanoTabCount(), |
| 1188 &unselected, &selected); |
| 1180 int w = Round(first_tab->IsSelected() ? selected : selected); | 1189 int w = Round(first_tab->IsSelected() ? selected : selected); |
| 1181 | 1190 |
| 1182 // We only want to run the animation if we're not already at the desired | 1191 // We only want to run the animation if we're not already at the desired |
| 1183 // size. | 1192 // size. |
| 1184 if (abs(first_tab->width() - w) > 1) | 1193 if (abs(first_tab->width() - w) > 1) |
| 1185 StartResizeLayoutAnimation(); | 1194 StartResizeLayoutAnimation(); |
| 1186 } | 1195 } |
| 1187 | 1196 |
| 1188 bool TabStrip::IsCursorInTabStripZone() const { | 1197 bool TabStrip::IsCursorInTabStripZone() const { |
| 1189 gfx::Rect bounds = GetLocalBounds(true); | 1198 gfx::Rect bounds = GetLocalBounds(true); |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1378 /////////////////////////////////////////////////////////////////////////////// | 1387 /////////////////////////////////////////////////////////////////////////////// |
| 1379 | 1388 |
| 1380 // Called from: | 1389 // Called from: |
| 1381 // - BasicLayout | 1390 // - BasicLayout |
| 1382 // - Tab insertion/removal | 1391 // - Tab insertion/removal |
| 1383 // - Tab reorder | 1392 // - Tab reorder |
| 1384 void TabStrip::GenerateIdealBounds() { | 1393 void TabStrip::GenerateIdealBounds() { |
| 1385 int tab_count = GetTabCount(); | 1394 int tab_count = GetTabCount(); |
| 1386 int non_closing_tab_count = 0; | 1395 int non_closing_tab_count = 0; |
| 1387 int mini_tab_count = 0; | 1396 int mini_tab_count = 0; |
| 1397 int nano_tab_count = 0; |
| 1388 for (int i = 0; i < tab_count; ++i) { | 1398 for (int i = 0; i < tab_count; ++i) { |
| 1389 if (!tab_data_[i].tab->closing()) { | 1399 if (!tab_data_[i].tab->closing()) { |
| 1390 ++non_closing_tab_count; | 1400 ++non_closing_tab_count; |
| 1391 if (tab_data_[i].tab->mini()) | 1401 if (tab_data_[i].tab->mini()) |
| 1392 mini_tab_count++; | 1402 mini_tab_count++; |
| 1403 if (tab_data_[i].tab->app()) |
| 1404 nano_tab_count++; |
| 1393 } | 1405 } |
| 1394 } | 1406 } |
| 1395 | 1407 |
| 1396 double unselected, selected; | 1408 double unselected, selected; |
| 1397 GetDesiredTabWidths(non_closing_tab_count, mini_tab_count, &unselected, | 1409 GetDesiredTabWidths(non_closing_tab_count, mini_tab_count, nano_tab_count, |
| 1398 &selected); | 1410 &unselected, &selected); |
| 1399 | 1411 |
| 1400 current_unselected_width_ = unselected; | 1412 current_unselected_width_ = unselected; |
| 1401 current_selected_width_ = selected; | 1413 current_selected_width_ = selected; |
| 1402 | 1414 |
| 1403 // NOTE: This currently assumes a tab's height doesn't differ based on | 1415 // NOTE: This currently assumes a tab's height doesn't differ based on |
| 1404 // selected state or the number of tabs in the strip! | 1416 // selected state or the number of tabs in the strip! |
| 1405 int tab_height = Tab::GetStandardSize().height(); | 1417 int tab_height = Tab::GetStandardSize().height(); |
| 1406 double tab_x = 0; | 1418 double tab_x = 0; |
| 1407 bool last_was_mini = false; | 1419 bool last_was_mini = false; |
| 1408 for (int i = 0; i < tab_count; ++i) { | 1420 for (int i = 0; i < tab_count; ++i) { |
| 1409 if (!tab_data_[i].tab->closing()) { | 1421 if (!tab_data_[i].tab->closing()) { |
| 1410 Tab* tab = GetTabAtTabDataIndex(i); | 1422 Tab* tab = GetTabAtTabDataIndex(i); |
| 1411 double tab_width = unselected; | 1423 double tab_width = unselected; |
| 1412 if (tab->mini()) { | 1424 if (tab->mini()) { |
| 1413 tab_width = Tab::GetMiniWidth(); | 1425 tab_width = Tab::GetMiniWidth(); |
| 1414 } else { | 1426 } else { |
| 1415 if (last_was_mini) { | 1427 if (last_was_mini) { |
| 1416 // Give a bigger gap between mini and non-mini tabs. | 1428 // Give a bigger gap between mini and non-mini tabs. |
| 1417 tab_x += mini_to_non_mini_gap_; | 1429 tab_x += mini_to_non_mini_gap_; |
| 1430 if (nano_tab_count > 0) |
| 1431 tab_x += extra_gap_for_nano_; |
| 1418 } | 1432 } |
| 1419 if (tab->IsSelected()) | 1433 if (tab->IsSelected()) |
| 1420 tab_width = selected; | 1434 tab_width = selected; |
| 1421 } | 1435 } |
| 1422 double end_of_tab = tab_x + tab_width; | 1436 double end_of_tab = tab_x + tab_width; |
| 1423 int rounded_tab_x = Round(tab_x); | 1437 int rounded_tab_x = Round(tab_x); |
| 1424 tab_data_[i].ideal_bounds = | 1438 tab_data_[i].ideal_bounds = |
| 1425 gfx::Rect(rounded_tab_x, 0, Round(end_of_tab) - rounded_tab_x, | 1439 gfx::Rect(rounded_tab_x, 0, Round(end_of_tab) - rounded_tab_x, |
| 1426 tab_height); | 1440 tab_height); |
| 1427 tab_x = end_of_tab + kTabHOffset; | 1441 tab_x = end_of_tab + kTabHOffset; |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1663 int mini_count = 0; | 1677 int mini_count = 0; |
| 1664 for (size_t i = 0; i < tab_data_.size(); ++i) { | 1678 for (size_t i = 0; i < tab_data_.size(); ++i) { |
| 1665 if (tab_data_[i].tab->mini()) | 1679 if (tab_data_[i].tab->mini()) |
| 1666 mini_count++; | 1680 mini_count++; |
| 1667 else | 1681 else |
| 1668 return mini_count; | 1682 return mini_count; |
| 1669 } | 1683 } |
| 1670 return mini_count; | 1684 return mini_count; |
| 1671 } | 1685 } |
| 1672 | 1686 |
| 1687 int TabStrip::GetNanoTabCount() const { |
| 1688 int nano_count = 0; |
| 1689 for (size_t i = 0; i < tab_data_.size(); ++i) { |
| 1690 if (tab_data_[i].tab->app()) |
| 1691 nano_count++; |
| 1692 else |
| 1693 return nano_count; |
| 1694 } |
| 1695 return nano_count; |
| 1696 } |
| 1697 |
| 1673 int TabStrip::GetAvailableWidthForTabs(Tab* last_tab) const { | 1698 int TabStrip::GetAvailableWidthForTabs(Tab* last_tab) const { |
| 1674 return last_tab->x() + last_tab->width(); | 1699 return last_tab->x() + last_tab->width(); |
| 1675 } | 1700 } |
| 1676 | 1701 |
| 1677 bool TabStrip::IsPointInTab(Tab* tab, | 1702 bool TabStrip::IsPointInTab(Tab* tab, |
| 1678 const gfx::Point& point_in_tabstrip_coords) { | 1703 const gfx::Point& point_in_tabstrip_coords) { |
| 1679 gfx::Point point_in_tab_coords(point_in_tabstrip_coords); | 1704 gfx::Point point_in_tab_coords(point_in_tabstrip_coords); |
| 1680 View::ConvertPointToView(this, tab, &point_in_tab_coords); | 1705 View::ConvertPointToView(this, tab, &point_in_tab_coords); |
| 1681 return tab->HitTest(point_in_tab_coords); | 1706 return tab->HitTest(point_in_tab_coords); |
| 1682 } | 1707 } |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1748 return tab_data_.size(); | 1773 return tab_data_.size(); |
| 1749 } | 1774 } |
| 1750 | 1775 |
| 1751 int TabStrip::TabDataIndexOfTab(Tab* tab) const { | 1776 int TabStrip::TabDataIndexOfTab(Tab* tab) const { |
| 1752 for (size_t i = 0; i < tab_data_.size(); ++i) { | 1777 for (size_t i = 0; i < tab_data_.size(); ++i) { |
| 1753 if (tab_data_[i].tab == tab) | 1778 if (tab_data_[i].tab == tab) |
| 1754 return i; | 1779 return i; |
| 1755 } | 1780 } |
| 1756 return -1; | 1781 return -1; |
| 1757 } | 1782 } |
| OLD | NEW |