OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/toolbar/browser_actions_container.h" | 5 #include "chrome/browser/ui/views/toolbar/browser_actions_container.h" |
6 | 6 |
7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "chrome/browser/extensions/extension_service.h" | 10 #include "chrome/browser/extensions/extension_service.h" |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 BrowserActionsContainerObserver* observer) { | 201 BrowserActionsContainerObserver* observer) { |
202 observers_.AddObserver(observer); | 202 observers_.AddObserver(observer); |
203 } | 203 } |
204 | 204 |
205 void BrowserActionsContainer::RemoveObserver( | 205 void BrowserActionsContainer::RemoveObserver( |
206 BrowserActionsContainerObserver* observer) { | 206 BrowserActionsContainerObserver* observer) { |
207 observers_.RemoveObserver(observer); | 207 observers_.RemoveObserver(observer); |
208 } | 208 } |
209 | 209 |
210 gfx::Size BrowserActionsContainer::GetPreferredSize() { | 210 gfx::Size BrowserActionsContainer::GetPreferredSize() { |
211 if (browser_action_views_.empty()) | |
212 return gfx::Size(ToolbarView::kStandardSpacing, 0); | |
213 | |
214 // We calculate the size of the view by taking the current width and | 211 // We calculate the size of the view by taking the current width and |
215 // subtracting resize_amount_ (the latter represents how far the user is | 212 // subtracting resize_amount_ (the latter represents how far the user is |
216 // resizing the view or, if animating the snapping, how far to animate it). | 213 // resizing the view or, if animating the snapping, how far to animate it). |
217 // But we also clamp it to a minimum size and the maximum size, so that the | 214 // But we also clamp it to a minimum size and the maximum size, so that the |
218 // container can never shrink too far or take up more space than it needs. In | 215 // container can never shrink too far or take up more space than it needs. In |
219 // other words: ContainerMinSize() < width() - resize < ClampTo(MAX). | 216 // other words: MinimumNonemptyWidth() < width() - resize < ClampTo(MAX). |
220 int clamped_width = std::min( | 217 int preferred_width = std::min( |
221 std::max(ContainerMinSize(), container_width_ - resize_amount_), | 218 std::max(MinimumNonemptyWidth(), container_width_ - resize_amount_), |
222 IconCountToWidth(-1, false)); | 219 IconCountToWidth(-1, false)); |
223 return gfx::Size(clamped_width, 0); | 220 // Height will be ignored by the ToolbarView. |
| 221 return gfx::Size(preferred_width, 0); |
| 222 } |
| 223 |
| 224 gfx::Size BrowserActionsContainer::GetMinimumSize() { |
| 225 int min_width = std::min(MinimumNonemptyWidth(), IconCountToWidth(-1, false)); |
| 226 // Height will be ignored by the ToolbarView. |
| 227 return gfx::Size(min_width, 0); |
224 } | 228 } |
225 | 229 |
226 void BrowserActionsContainer::Layout() { | 230 void BrowserActionsContainer::Layout() { |
227 if (browser_action_views_.empty()) { | 231 if (browser_action_views_.empty()) { |
228 SetVisible(false); | 232 SetVisible(false); |
229 return; | 233 return; |
230 } | 234 } |
231 | 235 |
232 SetVisible(true); | 236 SetVisible(true); |
233 resize_area_->SetBounds(0, 0, kItemSpacing, height()); | 237 resize_area_->SetBounds(0, 0, kItemSpacing, height()); |
(...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
846 // either side of the chevron. | 850 // either side of the chevron. |
847 int available_space = pixels - ToolbarView::kStandardSpacing - | 851 int available_space = pixels - ToolbarView::kStandardSpacing - |
848 chevron_->GetPreferredSize().width() - kChevronSpacing - | 852 chevron_->GetPreferredSize().width() - kChevronSpacing - |
849 ToolbarView::kStandardSpacing; | 853 ToolbarView::kStandardSpacing; |
850 // Now we add an extra between-item padding value so the space can be divided | 854 // Now we add an extra between-item padding value so the space can be divided |
851 // evenly by (size of icon with padding). | 855 // evenly by (size of icon with padding). |
852 return static_cast<size_t>( | 856 return static_cast<size_t>( |
853 std::max(0, available_space + kItemSpacing) / IconWidth(true)); | 857 std::max(0, available_space + kItemSpacing) / IconWidth(true)); |
854 } | 858 } |
855 | 859 |
856 int BrowserActionsContainer::ContainerMinSize() const { | 860 int BrowserActionsContainer::MinimumNonemptyWidth() const { |
857 return ToolbarView::kStandardSpacing + kChevronSpacing + | 861 return ToolbarView::kStandardSpacing + kChevronSpacing + |
858 chevron_->GetPreferredSize().width() + ToolbarView::kStandardSpacing; | 862 chevron_->GetPreferredSize().width() + ToolbarView::kStandardSpacing; |
859 } | 863 } |
860 | 864 |
861 void BrowserActionsContainer::SaveDesiredSizeAndAnimate( | 865 void BrowserActionsContainer::SaveDesiredSizeAndAnimate( |
862 gfx::Tween::Type tween_type, | 866 gfx::Tween::Type tween_type, |
863 size_t num_visible_icons) { | 867 size_t num_visible_icons) { |
864 // Save off the desired number of visible icons. We do this now instead of at | 868 // Save off the desired number of visible icons. We do this now instead of at |
865 // the end of the animation so that even if the browser is shut down while | 869 // the end of the animation so that even if the browser is shut down while |
866 // animating, the right value will be restored on next run. | 870 // animating, the right value will be restored on next run. |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
922 views::BubbleBorder::TOP_RIGHT, | 926 views::BubbleBorder::TOP_RIGHT, |
923 show_action); | 927 show_action); |
924 popup_->GetWidget()->AddObserver(this); | 928 popup_->GetWidget()->AddObserver(this); |
925 popup_button_ = button; | 929 popup_button_ = button; |
926 | 930 |
927 // Only set button as pushed if it was triggered by a user click. | 931 // Only set button as pushed if it was triggered by a user click. |
928 if (should_grant) | 932 if (should_grant) |
929 popup_button_->SetButtonPushed(); | 933 popup_button_->SetButtonPushed(); |
930 return true; | 934 return true; |
931 } | 935 } |
OLD | NEW |