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 return icons * IconWidth(true) + platform_settings_.item_spacing; |
| 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; | |
| 219 | |
| 220 const int icons_size = (icons == 0) ? 0 : | |
| 221 (icons * IconWidth(true)) - platform_settings_.item_spacing; | |
| 222 const int chevron_size = display_chevron ? delegate_->GetChevronWidth() : 0; | |
| 223 const int side_padding = platform_settings_.item_spacing * 2; | |
| 224 | |
| 225 return icons_size + chevron_size + side_padding; | |
| 226 } | 213 } |
| 227 | 214 |
| 228 size_t ToolbarActionsBar::WidthToIconCount(int pixels) const { | 215 size_t ToolbarActionsBar::WidthToIconCount(int pixels) const { |
| 229 // Check for widths large enough to show the entire icon set. | 216 // Check for widths large enough to show the entire icon set. |
| 230 if (pixels >= IconCountToWidth(-1)) | 217 if (pixels >= IconCountToWidth(-1)) |
| 231 return toolbar_actions_.size(); | 218 return toolbar_actions_.size(); |
| 232 | 219 |
| 233 // We reserve space for the padding on either side of the toolbar and, | 220 // 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); | 221 int available_space = pixels - (platform_settings_.item_spacing * 2); |
| 236 if (platform_settings_.chevron_enabled) | |
| 237 available_space -= delegate_->GetChevronWidth(); | |
| 238 | 222 |
| 239 // Now we add an extra between-item padding value so the space can be divided | 223 // Now we add an extra between-item padding value so the space can be divided |
| 240 // evenly by (size of icon with padding). | 224 // evenly by (size of icon with padding). |
| 241 return static_cast<size_t>(std::max( | 225 return static_cast<size_t>(std::max( |
| 242 0, available_space + platform_settings_.item_spacing) / IconWidth(true)); | 226 0, available_space + platform_settings_.item_spacing) / IconWidth(true)); |
|
Evan Stade
2016/05/24 22:07:18
optional nit: pixels - platform_settings_.item_spa
Devlin
2016/05/25 00:38:46
Done.
| |
| 243 } | 227 } |
| 244 | 228 |
| 245 size_t ToolbarActionsBar::GetIconCount() const { | 229 size_t ToolbarActionsBar::GetIconCount() const { |
| 246 if (!model_) | 230 if (!model_) |
| 247 return 0; | 231 return 0; |
| 248 | 232 |
| 249 int pop_out_modifier = 0; | 233 int pop_out_modifier = 0; |
| 250 // If there is a popped out action, it could affect the number of visible | 234 // If there is a popped out action, it could affect the number of visible |
| 251 // icons - but only if it wouldn't otherwise be visible. | 235 // icons - but only if it wouldn't otherwise be visible. |
| 252 if (popped_out_action_) { | 236 if (popped_out_action_) { |
| (...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 704 ->IsBeingUpgraded(action_id) || | 688 ->IsBeingUpgraded(action_id) || |
| 705 (browser_->profile()->IsOffTheRecord() && | 689 (browser_->profile()->IsOffTheRecord() && |
| 706 !extensions::util::IsIncognitoEnabled(action_id, browser_->profile()))) { | 690 !extensions::util::IsIncognitoEnabled(action_id, browser_->profile()))) { |
| 707 if (toolbar_actions_.size() > model_->visible_icon_count()) { | 691 if (toolbar_actions_.size() > model_->visible_icon_count()) { |
| 708 // If we have more icons than we can show, then we must not be changing | 692 // 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 | 693 // 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 | 694 // area and one from the overflow list will have shifted in, or we |
| 711 // removed an entry directly from the overflow list). | 695 // removed an entry directly from the overflow list). |
| 712 delegate_->Redraw(false); | 696 delegate_->Redraw(false); |
| 713 } else { | 697 } else { |
| 714 delegate_->SetChevronVisibility(false); | |
| 715 // Either we went from overflow to no-overflow, or we shrunk the no- | 698 // 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. | 699 // overflow container by 1. Either way the size changed, so animate. |
| 717 ResizeDelegate(gfx::Tween::EASE_OUT, false); | 700 ResizeDelegate(gfx::Tween::EASE_OUT, false); |
| 718 } | 701 } |
| 719 } | 702 } |
| 720 } | 703 } |
| 721 | 704 |
| 722 void ToolbarActionsBar::OnToolbarActionMoved(const std::string& action_id, | 705 void ToolbarActionsBar::OnToolbarActionMoved(const std::string& action_id, |
| 723 int index) { | 706 int index) { |
| 724 DCHECK(index >= 0 && index < static_cast<int>(toolbar_actions_.size())); | 707 DCHECK(index >= 0 && index < static_cast<int>(toolbar_actions_.size())); |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 738 | 721 |
| 739 void ToolbarActionsBar::OnToolbarVisibleCountChanged() { | 722 void ToolbarActionsBar::OnToolbarVisibleCountChanged() { |
| 740 ResizeDelegate(gfx::Tween::EASE_OUT, false); | 723 ResizeDelegate(gfx::Tween::EASE_OUT, false); |
| 741 } | 724 } |
| 742 | 725 |
| 743 void ToolbarActionsBar::ResizeDelegate(gfx::Tween::Type tween_type, | 726 void ToolbarActionsBar::ResizeDelegate(gfx::Tween::Type tween_type, |
| 744 bool suppress_chevron) { | 727 bool suppress_chevron) { |
| 745 int desired_width = GetPreferredSize().width(); | 728 int desired_width = GetPreferredSize().width(); |
| 746 if (desired_width != | 729 if (desired_width != |
| 747 delegate_->GetWidth(ToolbarActionsBarDelegate::GET_WIDTH_CURRENT)) { | 730 delegate_->GetWidth(ToolbarActionsBarDelegate::GET_WIDTH_CURRENT)) { |
| 748 delegate_->ResizeAndAnimate(tween_type, desired_width, suppress_chevron); | 731 delegate_->ResizeAndAnimate(tween_type, desired_width); |
| 749 } else if (delegate_->IsAnimating()) { | 732 } else if (delegate_->IsAnimating()) { |
| 750 // It's possible that we're right where we're supposed to be in terms of | 733 // 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 | 734 // width, but that we're also currently resizing. If this is the case, end |
| 752 // the current animation with the current width. | 735 // the current animation with the current width. |
| 753 delegate_->StopAnimating(); | 736 delegate_->StopAnimating(); |
| 754 } else { | 737 } else { |
| 755 // We may already be at the right size (this can happen frequently with | 738 // 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 | 739 // 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 | 740 // 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 | 741 // 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_) { | 829 for (ToolbarActionViewController* action : toolbar_actions_) { |
| 847 if (action->GetId() == action_id) | 830 if (action->GetId() == action_id) |
| 848 return action; | 831 return action; |
| 849 } | 832 } |
| 850 return nullptr; | 833 return nullptr; |
| 851 } | 834 } |
| 852 | 835 |
| 853 content::WebContents* ToolbarActionsBar::GetCurrentWebContents() { | 836 content::WebContents* ToolbarActionsBar::GetCurrentWebContents() { |
| 854 return browser_->tab_strip_model()->GetActiveWebContents(); | 837 return browser_->tab_strip_model()->GetActiveWebContents(); |
| 855 } | 838 } |
| OLD | NEW |