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/resource_bundle.h" | 10 #include "app/resource_bundle.h" |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 }; | 114 }; |
115 | 115 |
116 } // namespace | 116 } // namespace |
117 | 117 |
118 /////////////////////////////////////////////////////////////////////////////// | 118 /////////////////////////////////////////////////////////////////////////////// |
119 // TabStrip, public: | 119 // TabStrip, public: |
120 | 120 |
121 // static | 121 // static |
122 const int TabStrip::mini_to_non_mini_gap_ = 3; | 122 const int TabStrip::mini_to_non_mini_gap_ = 3; |
123 | 123 |
124 // static | |
125 const int TabStrip::extra_gap_for_nano_ = 10; | |
126 | |
127 TabStrip::TabStrip(TabStripController* controller) | 124 TabStrip::TabStrip(TabStripController* controller) |
128 : BaseTabStrip(controller, BaseTabStrip::HORIZONTAL_TAB_STRIP), | 125 : BaseTabStrip(controller, BaseTabStrip::HORIZONTAL_TAB_STRIP), |
129 resize_layout_factory_(this), | 126 resize_layout_factory_(this), |
130 added_as_message_loop_observer_(false), | 127 added_as_message_loop_observer_(false), |
131 current_unselected_width_(Tab::GetStandardSize().width()), | 128 current_unselected_width_(Tab::GetStandardSize().width()), |
132 current_selected_width_(Tab::GetStandardSize().width()), | 129 current_selected_width_(Tab::GetStandardSize().width()), |
133 available_width_for_tabs_(-1), | 130 available_width_for_tabs_(-1), |
134 in_tab_close_(false), | 131 in_tab_close_(false), |
135 animation_container_(new AnimationContainer()), | 132 animation_container_(new AnimationContainer()), |
136 new_tab_button_enabled_(true) { | 133 new_tab_button_enabled_(true) { |
(...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
650 } | 647 } |
651 | 648 |
652 void TabStrip::GetCurrentTabWidths(double* unselected_width, | 649 void TabStrip::GetCurrentTabWidths(double* unselected_width, |
653 double* selected_width) const { | 650 double* selected_width) const { |
654 *unselected_width = current_unselected_width_; | 651 *unselected_width = current_unselected_width_; |
655 *selected_width = current_selected_width_; | 652 *selected_width = current_selected_width_; |
656 } | 653 } |
657 | 654 |
658 void TabStrip::GetDesiredTabWidths(int tab_count, | 655 void TabStrip::GetDesiredTabWidths(int tab_count, |
659 int mini_tab_count, | 656 int mini_tab_count, |
660 int nano_tab_count, | |
661 double* unselected_width, | 657 double* unselected_width, |
662 double* selected_width) const { | 658 double* selected_width) const { |
663 DCHECK(tab_count >= 0 && mini_tab_count >= 0 && mini_tab_count <= tab_count); | 659 DCHECK(tab_count >= 0 && mini_tab_count >= 0 && mini_tab_count <= tab_count); |
664 DCHECK(nano_tab_count >= 0 && nano_tab_count <= tab_count); | |
665 const double min_unselected_width = Tab::GetMinimumUnselectedSize().width(); | 660 const double min_unselected_width = Tab::GetMinimumUnselectedSize().width(); |
666 const double min_selected_width = Tab::GetMinimumSelectedSize().width(); | 661 const double min_selected_width = Tab::GetMinimumSelectedSize().width(); |
667 | 662 |
668 *unselected_width = min_unselected_width; | 663 *unselected_width = min_unselected_width; |
669 *selected_width = min_selected_width; | 664 *selected_width = min_selected_width; |
670 | 665 |
671 if (tab_count == 0) { | 666 if (tab_count == 0) { |
672 // Return immediately to avoid divide-by-zero below. | 667 // Return immediately to avoid divide-by-zero below. |
673 return; | 668 return; |
674 } | 669 } |
(...skipping 18 matching lines...) Expand all Loading... |
693 | 688 |
694 if (mini_tab_count > 0) { | 689 if (mini_tab_count > 0) { |
695 available_width -= mini_tab_count * (Tab::GetMiniWidth() + kTabHOffset); | 690 available_width -= mini_tab_count * (Tab::GetMiniWidth() + kTabHOffset); |
696 tab_count -= mini_tab_count; | 691 tab_count -= mini_tab_count; |
697 if (tab_count == 0) { | 692 if (tab_count == 0) { |
698 *selected_width = *unselected_width = Tab::GetStandardSize().width(); | 693 *selected_width = *unselected_width = Tab::GetStandardSize().width(); |
699 return; | 694 return; |
700 } | 695 } |
701 // Account for gap between the last mini-tab and first non-mini-tab. | 696 // Account for gap between the last mini-tab and first non-mini-tab. |
702 available_width -= mini_to_non_mini_gap_; | 697 available_width -= mini_to_non_mini_gap_; |
703 // And add some extra space if you have nano tabs in the mix. | |
704 if (nano_tab_count > 0) | |
705 available_width -= extra_gap_for_nano_; | |
706 } | 698 } |
707 | 699 |
708 // Calculate the desired tab widths by dividing the available space into equal | 700 // Calculate the desired tab widths by dividing the available space into equal |
709 // portions. Don't let tabs get larger than the "standard width" or smaller | 701 // portions. Don't let tabs get larger than the "standard width" or smaller |
710 // than the minimum width for each type, respectively. | 702 // than the minimum width for each type, respectively. |
711 const int total_offset = kTabHOffset * (tab_count - 1); | 703 const int total_offset = kTabHOffset * (tab_count - 1); |
712 const double desired_tab_width = std::min((static_cast<double>( | 704 const double desired_tab_width = std::min((static_cast<double>( |
713 available_width - total_offset) / static_cast<double>(tab_count)), | 705 available_width - total_offset) / static_cast<double>(tab_count)), |
714 static_cast<double>(Tab::GetStandardSize().width())); | 706 static_cast<double>(Tab::GetStandardSize().width())); |
715 *unselected_width = std::max(desired_tab_width, min_unselected_width); | 707 *unselected_width = std::max(desired_tab_width, min_unselected_width); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
756 in_tab_close_ = false; | 748 in_tab_close_ = false; |
757 available_width_for_tabs_ = -1; | 749 available_width_for_tabs_ = -1; |
758 int mini_tab_count = GetMiniTabCount(); | 750 int mini_tab_count = GetMiniTabCount(); |
759 if (mini_tab_count == tab_count()) { | 751 if (mini_tab_count == tab_count()) { |
760 // Only mini-tabs, we know the tab widths won't have changed (all | 752 // Only mini-tabs, we know the tab widths won't have changed (all |
761 // mini-tabs have the same width), so there is nothing to do. | 753 // mini-tabs have the same width), so there is nothing to do. |
762 return; | 754 return; |
763 } | 755 } |
764 Tab* first_tab = GetTabAtTabDataIndex(mini_tab_count); | 756 Tab* first_tab = GetTabAtTabDataIndex(mini_tab_count); |
765 double unselected, selected; | 757 double unselected, selected; |
766 GetDesiredTabWidths(tab_count(), mini_tab_count, GetNanoTabCount(), | 758 GetDesiredTabWidths(tab_count(), mini_tab_count, &unselected, &selected); |
767 &unselected, &selected); | |
768 int w = Round(first_tab->IsSelected() ? selected : selected); | 759 int w = Round(first_tab->IsSelected() ? selected : selected); |
769 | 760 |
770 // We only want to run the animation if we're not already at the desired | 761 // We only want to run the animation if we're not already at the desired |
771 // size. | 762 // size. |
772 if (abs(first_tab->width() - w) > 1) | 763 if (abs(first_tab->width() - w) > 1) |
773 StartResizeLayoutAnimation(); | 764 StartResizeLayoutAnimation(); |
774 } | 765 } |
775 | 766 |
776 bool TabStrip::IsCursorInTabStripZone() const { | 767 bool TabStrip::IsCursorInTabStripZone() const { |
777 gfx::Rect bounds = GetLocalBounds(true); | 768 gfx::Rect bounds = GetLocalBounds(true); |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
962 | 953 |
963 /////////////////////////////////////////////////////////////////////////////// | 954 /////////////////////////////////////////////////////////////////////////////// |
964 | 955 |
965 // Called from: | 956 // Called from: |
966 // - BasicLayout | 957 // - BasicLayout |
967 // - Tab insertion/removal | 958 // - Tab insertion/removal |
968 // - Tab reorder | 959 // - Tab reorder |
969 void TabStrip::GenerateIdealBounds() { | 960 void TabStrip::GenerateIdealBounds() { |
970 int non_closing_tab_count = 0; | 961 int non_closing_tab_count = 0; |
971 int mini_tab_count = 0; | 962 int mini_tab_count = 0; |
972 int nano_tab_count = 0; | |
973 for (int i = 0; i < tab_count(); ++i) { | 963 for (int i = 0; i < tab_count(); ++i) { |
974 BaseTab* tab = base_tab_at_tab_index(i); | 964 BaseTab* tab = base_tab_at_tab_index(i); |
975 if (!tab->closing()) { | 965 if (!tab->closing()) { |
976 ++non_closing_tab_count; | 966 ++non_closing_tab_count; |
977 if (tab->data().mini) | 967 if (tab->data().mini) |
978 mini_tab_count++; | 968 mini_tab_count++; |
979 if (tab->data().app) | |
980 nano_tab_count++; | |
981 } | 969 } |
982 } | 970 } |
983 | 971 |
984 double unselected, selected; | 972 double unselected, selected; |
985 GetDesiredTabWidths(non_closing_tab_count, mini_tab_count, nano_tab_count, | 973 GetDesiredTabWidths(non_closing_tab_count, mini_tab_count, &unselected, |
986 &unselected, &selected); | 974 &selected); |
987 | 975 |
988 current_unselected_width_ = unselected; | 976 current_unselected_width_ = unselected; |
989 current_selected_width_ = selected; | 977 current_selected_width_ = selected; |
990 | 978 |
991 // NOTE: This currently assumes a tab's height doesn't differ based on | 979 // NOTE: This currently assumes a tab's height doesn't differ based on |
992 // selected state or the number of tabs in the strip! | 980 // selected state or the number of tabs in the strip! |
993 int tab_height = Tab::GetStandardSize().height(); | 981 int tab_height = Tab::GetStandardSize().height(); |
994 double tab_x = 0; | 982 double tab_x = 0; |
995 bool last_was_mini = false; | 983 bool last_was_mini = false; |
996 for (int i = 0; i < tab_count(); ++i) { | 984 for (int i = 0; i < tab_count(); ++i) { |
997 Tab* tab = GetTabAtTabDataIndex(i); | 985 Tab* tab = GetTabAtTabDataIndex(i); |
998 if (!tab->closing()) { | 986 if (!tab->closing()) { |
999 double tab_width = unselected; | 987 double tab_width = unselected; |
1000 if (tab->data().mini) { | 988 if (tab->data().mini) { |
1001 tab_width = Tab::GetMiniWidth(); | 989 tab_width = Tab::GetMiniWidth(); |
1002 } else { | 990 } else { |
1003 if (last_was_mini) { | 991 if (last_was_mini) { |
1004 // Give a bigger gap between mini and non-mini tabs. | 992 // Give a bigger gap between mini and non-mini tabs. |
1005 tab_x += mini_to_non_mini_gap_; | 993 tab_x += mini_to_non_mini_gap_; |
1006 if (nano_tab_count > 0) | |
1007 tab_x += extra_gap_for_nano_; | |
1008 } | 994 } |
1009 if (tab->IsSelected()) | 995 if (tab->IsSelected()) |
1010 tab_width = selected; | 996 tab_width = selected; |
1011 } | 997 } |
1012 double end_of_tab = tab_x + tab_width; | 998 double end_of_tab = tab_x + tab_width; |
1013 int rounded_tab_x = Round(tab_x); | 999 int rounded_tab_x = Round(tab_x); |
1014 set_ideal_bounds(i, | 1000 set_ideal_bounds(i, |
1015 gfx::Rect(rounded_tab_x, 0, Round(end_of_tab) - rounded_tab_x, | 1001 gfx::Rect(rounded_tab_x, 0, Round(end_of_tab) - rounded_tab_x, |
1016 tab_height)); | 1002 tab_height)); |
1017 tab_x = end_of_tab + kTabHOffset; | 1003 tab_x = end_of_tab + kTabHOffset; |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1111 int mini_count = 0; | 1097 int mini_count = 0; |
1112 for (int i = 0; i < tab_count(); ++i) { | 1098 for (int i = 0; i < tab_count(); ++i) { |
1113 if (base_tab_at_tab_index(i)->data().mini) | 1099 if (base_tab_at_tab_index(i)->data().mini) |
1114 mini_count++; | 1100 mini_count++; |
1115 else | 1101 else |
1116 return mini_count; | 1102 return mini_count; |
1117 } | 1103 } |
1118 return mini_count; | 1104 return mini_count; |
1119 } | 1105 } |
1120 | 1106 |
1121 int TabStrip::GetNanoTabCount() const { | |
1122 int nano_count = 0; | |
1123 for (int i = 0; i < tab_count(); ++i) { | |
1124 if (base_tab_at_tab_index(i)->data().app) | |
1125 nano_count++; | |
1126 else | |
1127 return nano_count; | |
1128 } | |
1129 return nano_count; | |
1130 } | |
1131 | |
1132 int TabStrip::GetAvailableWidthForTabs(Tab* last_tab) const { | 1107 int TabStrip::GetAvailableWidthForTabs(Tab* last_tab) const { |
1133 return last_tab->x() + last_tab->width(); | 1108 return last_tab->x() + last_tab->width(); |
1134 } | 1109 } |
1135 | 1110 |
1136 bool TabStrip::IsPointInTab(Tab* tab, | 1111 bool TabStrip::IsPointInTab(Tab* tab, |
1137 const gfx::Point& point_in_tabstrip_coords) { | 1112 const gfx::Point& point_in_tabstrip_coords) { |
1138 gfx::Point point_in_tab_coords(point_in_tabstrip_coords); | 1113 gfx::Point point_in_tab_coords(point_in_tabstrip_coords); |
1139 View::ConvertPointToView(this, tab, &point_in_tab_coords); | 1114 View::ConvertPointToView(this, tab, &point_in_tab_coords); |
1140 return tab->HitTest(point_in_tab_coords); | 1115 return tab->HitTest(point_in_tab_coords); |
1141 } | 1116 } |
(...skipping 16 matching lines...) Expand all Loading... |
1158 } | 1133 } |
1159 } | 1134 } |
1160 | 1135 |
1161 bool TabStrip::HasPhantomTabs() const { | 1136 bool TabStrip::HasPhantomTabs() const { |
1162 for (int i = 0; i < tab_count(); ++i) { | 1137 for (int i = 0; i < tab_count(); ++i) { |
1163 if (GetTabAtTabDataIndex(i)->data().phantom) | 1138 if (GetTabAtTabDataIndex(i)->data().phantom) |
1164 return true; | 1139 return true; |
1165 } | 1140 } |
1166 return false; | 1141 return false; |
1167 } | 1142 } |
OLD | NEW |