Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/toolbar/toolbar_actions_bar.h" | 5 #include "chrome/browser/ui/toolbar/toolbar_actions_bar.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 192 | 192 |
| 193 // If there are no actions to show (and this isn't an overflow container), | 193 // If there are no actions to show (and this isn't an overflow container), |
| 194 // then don't show the container at all. | 194 // then don't show the container at all. |
| 195 if (toolbar_actions_.empty()) | 195 if (toolbar_actions_.empty()) |
| 196 return gfx::Size(); | 196 return gfx::Size(); |
| 197 | 197 |
| 198 return gfx::Size(IconCountToWidth(GetIconCount()), IconHeight()); | 198 return gfx::Size(IconCountToWidth(GetIconCount()), IconHeight()); |
| 199 } | 199 } |
| 200 | 200 |
| 201 int ToolbarActionsBar::GetMinimumWidth() const { | 201 int ToolbarActionsBar::GetMinimumWidth() const { |
| 202 if (!platform_settings_.chevron_enabled || toolbar_actions_.empty()) | 202 return platform_settings_.item_spacing; |
| 203 return platform_settings_.item_spacing; | |
| 204 return 2 * platform_settings_.item_spacing + delegate_->GetChevronWidth(); | |
| 205 } | 203 } |
| 206 | 204 |
| 207 int ToolbarActionsBar::GetMaximumWidth() const { | 205 int ToolbarActionsBar::GetMaximumWidth() const { |
| 208 return IconCountToWidth(-1); | 206 return IconCountToWidth(-1); |
| 209 } | 207 } |
| 210 | 208 |
| 211 int ToolbarActionsBar::IconCountToWidth(int icons) const { | 209 int ToolbarActionsBar::IconCountToWidth(int icons) const { |
| 212 if (icons < 0) | 210 if (icons < 0) |
| 213 icons = toolbar_actions_.size(); | 211 icons = toolbar_actions_.size(); |
| 214 const bool display_chevron = | 212 if (icons == 0) |
| 215 platform_settings_.chevron_enabled && | |
| 216 static_cast<size_t>(icons) < toolbar_actions_.size(); | |
| 217 if (icons == 0 && !display_chevron) | |
| 218 return platform_settings_.item_spacing; | 213 return platform_settings_.item_spacing; |
| 219 | 214 |
| 220 const int icons_size = (icons == 0) ? 0 : | 215 const int icons_size = |
| 221 (icons * IconWidth(true)) - platform_settings_.item_spacing; | 216 (icons * IconWidth(true)) - platform_settings_.item_spacing; |
|
Evan Stade
2016/05/24 17:58:55
nit: i think most of this fn can be rewritten as
Devlin
2016/05/24 21:59:00
Done.
| |
| 222 const int chevron_size = display_chevron ? delegate_->GetChevronWidth() : 0; | |
| 223 const int side_padding = platform_settings_.item_spacing * 2; | 217 const int side_padding = platform_settings_.item_spacing * 2; |
| 224 | 218 |
| 225 return icons_size + chevron_size + side_padding; | 219 return icons_size + side_padding; |
| 226 } | 220 } |
| 227 | 221 |
| 228 size_t ToolbarActionsBar::WidthToIconCount(int pixels) const { | 222 size_t ToolbarActionsBar::WidthToIconCount(int pixels) const { |
| 229 // Check for widths large enough to show the entire icon set. | 223 // Check for widths large enough to show the entire icon set. |
| 230 if (pixels >= IconCountToWidth(-1)) | 224 if (pixels >= IconCountToWidth(-1)) |
| 231 return toolbar_actions_.size(); | 225 return toolbar_actions_.size(); |
| 232 | 226 |
| 233 // We reserve space for the padding on either side of the toolbar and, | 227 // We reserve space for the padding on either side of the toolbar. |
| 234 // if enabled, for the chevron. | |
| 235 int available_space = pixels - (platform_settings_.item_spacing * 2); | 228 int available_space = pixels - (platform_settings_.item_spacing * 2); |
| 236 if (platform_settings_.chevron_enabled) | |
| 237 available_space -= delegate_->GetChevronWidth(); | |
| 238 | 229 |
| 239 // Now we add an extra between-item padding value so the space can be divided | 230 // Now we add an extra between-item padding value so the space can be divided |
| 240 // evenly by (size of icon with padding). | 231 // evenly by (size of icon with padding). |
| 241 return static_cast<size_t>(std::max( | 232 return static_cast<size_t>(std::max( |
| 242 0, available_space + platform_settings_.item_spacing) / IconWidth(true)); | 233 0, available_space + platform_settings_.item_spacing) / IconWidth(true)); |
| 243 } | 234 } |
| 244 | 235 |
| 245 size_t ToolbarActionsBar::GetIconCount() const { | 236 size_t ToolbarActionsBar::GetIconCount() const { |
| 246 if (!model_) | 237 if (!model_) |
| 247 return 0; | 238 return 0; |
| (...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 704 ->IsBeingUpgraded(action_id) || | 695 ->IsBeingUpgraded(action_id) || |
| 705 (browser_->profile()->IsOffTheRecord() && | 696 (browser_->profile()->IsOffTheRecord() && |
| 706 !extensions::util::IsIncognitoEnabled(action_id, browser_->profile()))) { | 697 !extensions::util::IsIncognitoEnabled(action_id, browser_->profile()))) { |
| 707 if (toolbar_actions_.size() > model_->visible_icon_count()) { | 698 if (toolbar_actions_.size() > model_->visible_icon_count()) { |
| 708 // If we have more icons than we can show, then we must not be changing | 699 // If we have more icons than we can show, then we must not be changing |
| 709 // the container size (since we either removed an icon from the main | 700 // the container size (since we either removed an icon from the main |
| 710 // area and one from the overflow list will have shifted in, or we | 701 // area and one from the overflow list will have shifted in, or we |
| 711 // removed an entry directly from the overflow list). | 702 // removed an entry directly from the overflow list). |
| 712 delegate_->Redraw(false); | 703 delegate_->Redraw(false); |
| 713 } else { | 704 } else { |
| 714 delegate_->SetChevronVisibility(false); | |
| 715 // Either we went from overflow to no-overflow, or we shrunk the no- | 705 // Either we went from overflow to no-overflow, or we shrunk the no- |
| 716 // overflow container by 1. Either way the size changed, so animate. | 706 // overflow container by 1. Either way the size changed, so animate. |
| 717 ResizeDelegate(gfx::Tween::EASE_OUT, false); | 707 ResizeDelegate(gfx::Tween::EASE_OUT, false); |
| 718 } | 708 } |
| 719 } | 709 } |
| 720 } | 710 } |
| 721 | 711 |
| 722 void ToolbarActionsBar::OnToolbarActionMoved(const std::string& action_id, | 712 void ToolbarActionsBar::OnToolbarActionMoved(const std::string& action_id, |
| 723 int index) { | 713 int index) { |
| 724 DCHECK(index >= 0 && index < static_cast<int>(toolbar_actions_.size())); | 714 DCHECK(index >= 0 && index < static_cast<int>(toolbar_actions_.size())); |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 738 | 728 |
| 739 void ToolbarActionsBar::OnToolbarVisibleCountChanged() { | 729 void ToolbarActionsBar::OnToolbarVisibleCountChanged() { |
| 740 ResizeDelegate(gfx::Tween::EASE_OUT, false); | 730 ResizeDelegate(gfx::Tween::EASE_OUT, false); |
| 741 } | 731 } |
| 742 | 732 |
| 743 void ToolbarActionsBar::ResizeDelegate(gfx::Tween::Type tween_type, | 733 void ToolbarActionsBar::ResizeDelegate(gfx::Tween::Type tween_type, |
| 744 bool suppress_chevron) { | 734 bool suppress_chevron) { |
| 745 int desired_width = GetPreferredSize().width(); | 735 int desired_width = GetPreferredSize().width(); |
| 746 if (desired_width != | 736 if (desired_width != |
| 747 delegate_->GetWidth(ToolbarActionsBarDelegate::GET_WIDTH_CURRENT)) { | 737 delegate_->GetWidth(ToolbarActionsBarDelegate::GET_WIDTH_CURRENT)) { |
| 748 delegate_->ResizeAndAnimate(tween_type, desired_width, suppress_chevron); | 738 delegate_->ResizeAndAnimate(tween_type, desired_width); |
| 749 } else if (delegate_->IsAnimating()) { | 739 } else if (delegate_->IsAnimating()) { |
| 750 // It's possible that we're right where we're supposed to be in terms of | 740 // It's possible that we're right where we're supposed to be in terms of |
| 751 // width, but that we're also currently resizing. If this is the case, end | 741 // width, but that we're also currently resizing. If this is the case, end |
| 752 // the current animation with the current width. | 742 // the current animation with the current width. |
| 753 delegate_->StopAnimating(); | 743 delegate_->StopAnimating(); |
| 754 } else { | 744 } else { |
| 755 // We may already be at the right size (this can happen frequently with | 745 // We may already be at the right size (this can happen frequently with |
| 756 // overflow, where we have a fixed width, and in tests, where we skip | 746 // overflow, where we have a fixed width, and in tests, where we skip |
| 757 // animations). If this is the case, we still need to Redraw(), because the | 747 // animations). If this is the case, we still need to Redraw(), because the |
| 758 // icons within the toolbar may have changed (e.g. if we removed one | 748 // icons within the toolbar may have changed (e.g. if we removed one |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 846 for (ToolbarActionViewController* action : toolbar_actions_) { | 836 for (ToolbarActionViewController* action : toolbar_actions_) { |
| 847 if (action->GetId() == action_id) | 837 if (action->GetId() == action_id) |
| 848 return action; | 838 return action; |
| 849 } | 839 } |
| 850 return nullptr; | 840 return nullptr; |
| 851 } | 841 } |
| 852 | 842 |
| 853 content::WebContents* ToolbarActionsBar::GetCurrentWebContents() { | 843 content::WebContents* ToolbarActionsBar::GetCurrentWebContents() { |
| 854 return browser_->tab_strip_model()->GetActiveWebContents(); | 844 return browser_->tab_strip_model()->GetActiveWebContents(); |
| 855 } | 845 } |
| OLD | NEW |