| 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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 } | 97 } |
| 98 } | 98 } |
| 99 | 99 |
| 100 } // namespace | 100 } // namespace |
| 101 | 101 |
| 102 // static | 102 // static |
| 103 bool ToolbarActionsBar::disable_animations_for_testing_ = false; | 103 bool ToolbarActionsBar::disable_animations_for_testing_ = false; |
| 104 | 104 |
| 105 ToolbarActionsBar::PlatformSettings::PlatformSettings() | 105 ToolbarActionsBar::PlatformSettings::PlatformSettings() |
| 106 : item_spacing(GetLayoutConstant(TOOLBAR_STANDARD_SPACING)), | 106 : item_spacing(GetLayoutConstant(TOOLBAR_STANDARD_SPACING)), |
| 107 left_padding(GetLayoutConstant(TOOLBAR_ACTIONS_LEFT_PADDING)), |
| 108 right_padding(GetLayoutConstant(TOOLBAR_ACTIONS_RIGHT_PADDING)), |
| 107 icons_per_overflow_menu_row(1), | 109 icons_per_overflow_menu_row(1), |
| 108 chevron_enabled(!extensions::FeatureSwitch::extension_action_redesign()-> | 110 chevron_enabled(!extensions::FeatureSwitch::extension_action_redesign()-> |
| 109 IsEnabled()) { | 111 IsEnabled()) { |
| 110 } | 112 } |
| 111 | 113 |
| 112 ToolbarActionsBar::ToolbarActionsBar(ToolbarActionsBarDelegate* delegate, | 114 ToolbarActionsBar::ToolbarActionsBar(ToolbarActionsBarDelegate* delegate, |
| 113 Browser* browser, | 115 Browser* browser, |
| 114 ToolbarActionsBar* main_bar) | 116 ToolbarActionsBar* main_bar) |
| 115 : delegate_(delegate), | 117 : delegate_(delegate), |
| 116 browser_(browser), | 118 browser_(browser), |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 // then don't show the container at all. | 180 // then don't show the container at all. |
| 179 if (toolbar_actions_.empty()) | 181 if (toolbar_actions_.empty()) |
| 180 return gfx::Size(); | 182 return gfx::Size(); |
| 181 | 183 |
| 182 return gfx::Size(IconCountToWidth(GetIconCount()), IconHeight()); | 184 return gfx::Size(IconCountToWidth(GetIconCount()), IconHeight()); |
| 183 } | 185 } |
| 184 | 186 |
| 185 int ToolbarActionsBar::GetMinimumWidth() const { | 187 int ToolbarActionsBar::GetMinimumWidth() const { |
| 186 if (!platform_settings_.chevron_enabled || toolbar_actions_.empty()) | 188 if (!platform_settings_.chevron_enabled || toolbar_actions_.empty()) |
| 187 return platform_settings_.item_spacing; | 189 return platform_settings_.item_spacing; |
| 188 return 2 * platform_settings_.item_spacing + delegate_->GetChevronWidth(); | 190 return platform_settings_.left_padding + delegate_->GetChevronWidth() + |
| 191 platform_settings_.right_padding; |
| 189 } | 192 } |
| 190 | 193 |
| 191 int ToolbarActionsBar::GetMaximumWidth() const { | 194 int ToolbarActionsBar::GetMaximumWidth() const { |
| 192 return IconCountToWidth(-1); | 195 return IconCountToWidth(-1); |
| 193 } | 196 } |
| 194 | 197 |
| 195 int ToolbarActionsBar::IconCountToWidth(int icons) const { | 198 int ToolbarActionsBar::IconCountToWidth(int icons) const { |
| 196 if (icons < 0) | 199 if (icons < 0) |
| 197 icons = toolbar_actions_.size(); | 200 icons = toolbar_actions_.size(); |
| 198 const bool display_chevron = | 201 const bool display_chevron = |
| 199 platform_settings_.chevron_enabled && | 202 platform_settings_.chevron_enabled && |
| 200 static_cast<size_t>(icons) < toolbar_actions_.size(); | 203 static_cast<size_t>(icons) < toolbar_actions_.size(); |
| 201 if (icons == 0 && !display_chevron) | 204 if (icons == 0 && !display_chevron) |
| 202 return platform_settings_.item_spacing; | 205 return platform_settings_.item_spacing; |
| 203 | 206 |
| 204 const int icons_size = (icons == 0) ? 0 : | 207 const int icons_size = (icons == 0) ? 0 : |
| 205 (icons * IconWidth(true)) - platform_settings_.item_spacing; | 208 (icons * IconWidth(true)) - platform_settings_.item_spacing; |
| 206 const int chevron_size = display_chevron ? delegate_->GetChevronWidth() : 0; | 209 const int chevron_size = display_chevron ? delegate_->GetChevronWidth() : 0; |
| 207 const int side_padding = platform_settings_.item_spacing * 2; | |
| 208 | 210 |
| 209 return icons_size + chevron_size + side_padding; | 211 return platform_settings_.left_padding + icons_size + chevron_size + |
| 212 platform_settings_.right_padding; |
| 210 } | 213 } |
| 211 | 214 |
| 212 size_t ToolbarActionsBar::WidthToIconCount(int pixels) const { | 215 size_t ToolbarActionsBar::WidthToIconCount(int pixels) const { |
| 213 // Check for widths large enough to show the entire icon set. | 216 // Check for widths large enough to show the entire icon set. |
| 214 if (pixels >= IconCountToWidth(-1)) | 217 if (pixels >= IconCountToWidth(-1)) |
| 215 return toolbar_actions_.size(); | 218 return toolbar_actions_.size(); |
| 216 | 219 |
| 217 // 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 and, |
| 218 // if enabled, for the chevron. | 221 // if enabled, for the chevron. |
| 219 int available_space = pixels - (platform_settings_.item_spacing * 2); | 222 int available_space = pixels - |
| 223 (platform_settings_.left_padding + platform_settings_.right_padding); |
| 220 if (platform_settings_.chevron_enabled) | 224 if (platform_settings_.chevron_enabled) |
| 221 available_space -= delegate_->GetChevronWidth(); | 225 available_space -= delegate_->GetChevronWidth(); |
| 222 | 226 |
| 223 // Now we add an extra between-item padding value so the space can be divided | 227 // Now we add an extra between-item padding value so the space can be divided |
| 224 // evenly by (size of icon with padding). | 228 // evenly by (size of icon with padding). |
| 225 return static_cast<size_t>(std::max( | 229 return static_cast<size_t>(std::max( |
| 226 0, available_space + platform_settings_.item_spacing) / IconWidth(true)); | 230 0, available_space + platform_settings_.item_spacing) / IconWidth(true)); |
| 227 } | 231 } |
| 228 | 232 |
| 229 size_t ToolbarActionsBar::GetIconCount() const { | 233 size_t ToolbarActionsBar::GetIconCount() const { |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 if (index < start_index) | 303 if (index < start_index) |
| 300 return gfx::Rect(); | 304 return gfx::Rect(); |
| 301 | 305 |
| 302 size_t relative_index = index - start_index; | 306 size_t relative_index = index - start_index; |
| 303 int icons_per_overflow_row = platform_settings().icons_per_overflow_menu_row; | 307 int icons_per_overflow_row = platform_settings().icons_per_overflow_menu_row; |
| 304 size_t row_index = in_overflow_mode() ? | 308 size_t row_index = in_overflow_mode() ? |
| 305 relative_index / icons_per_overflow_row : 0; | 309 relative_index / icons_per_overflow_row : 0; |
| 306 size_t index_in_row = in_overflow_mode() ? | 310 size_t index_in_row = in_overflow_mode() ? |
| 307 relative_index % icons_per_overflow_row : relative_index; | 311 relative_index % icons_per_overflow_row : relative_index; |
| 308 | 312 |
| 309 return gfx::Rect(platform_settings().item_spacing + | 313 return gfx::Rect(platform_settings().left_padding + |
| 310 index_in_row * IconWidth(true), | 314 index_in_row * IconWidth(true), |
| 311 row_index * IconHeight(), | 315 row_index * IconHeight(), |
| 312 IconWidth(false), | 316 IconWidth(false), |
| 313 IconHeight()); | 317 IconHeight()); |
| 314 } | 318 } |
| 315 | 319 |
| 316 std::vector<ToolbarActionViewController*> | 320 std::vector<ToolbarActionViewController*> |
| 317 ToolbarActionsBar::GetActions() const { | 321 ToolbarActionsBar::GetActions() const { |
| 318 std::vector<ToolbarActionViewController*> actions = toolbar_actions_.get(); | 322 std::vector<ToolbarActionViewController*> actions = toolbar_actions_.get(); |
| 319 | 323 |
| (...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 776 for (ToolbarActionViewController* action : toolbar_actions_) { | 780 for (ToolbarActionViewController* action : toolbar_actions_) { |
| 777 if (action->GetId() == action_id) | 781 if (action->GetId() == action_id) |
| 778 return action; | 782 return action; |
| 779 } | 783 } |
| 780 return nullptr; | 784 return nullptr; |
| 781 } | 785 } |
| 782 | 786 |
| 783 content::WebContents* ToolbarActionsBar::GetCurrentWebContents() { | 787 content::WebContents* ToolbarActionsBar::GetCurrentWebContents() { |
| 784 return browser_->tab_strip_model()->GetActiveWebContents(); | 788 return browser_->tab_strip_model()->GetActiveWebContents(); |
| 785 } | 789 } |
| OLD | NEW |