Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(124)

Side by Side Diff: chrome/browser/ui/views/toolbar/browser_actions_container.cc

Issue 324393002: Extension Toolbar redesign, part 1 (overflow) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review comments Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
11 #include "chrome/browser/extensions/extension_util.h" 11 #include "chrome/browser/extensions/extension_util.h"
12 #include "chrome/browser/extensions/extension_view_host.h" 12 #include "chrome/browser/extensions/extension_view_host.h"
13 #include "chrome/browser/extensions/tab_helper.h" 13 #include "chrome/browser/extensions/tab_helper.h"
14 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/sessions/session_tab_helper.h" 15 #include "chrome/browser/sessions/session_tab_helper.h"
16 #include "chrome/browser/ui/browser.h" 16 #include "chrome/browser/ui/browser.h"
17 #include "chrome/browser/ui/browser_window.h" 17 #include "chrome/browser/ui/browser_window.h"
18 #include "chrome/browser/ui/tabs/tab_strip_model.h" 18 #include "chrome/browser/ui/tabs/tab_strip_model.h"
19 #include "chrome/browser/ui/view_ids.h" 19 #include "chrome/browser/ui/view_ids.h"
20 #include "chrome/browser/ui/views/extensions/browser_action_drag_data.h" 20 #include "chrome/browser/ui/views/extensions/browser_action_drag_data.h"
21 #include "chrome/browser/ui/views/extensions/extension_keybinding_registry_views .h" 21 #include "chrome/browser/ui/views/extensions/extension_keybinding_registry_views .h"
22 #include "chrome/browser/ui/views/extensions/extension_popup.h" 22 #include "chrome/browser/ui/views/extensions/extension_popup.h"
23 #include "chrome/browser/ui/views/toolbar/browser_action_view.h" 23 #include "chrome/browser/ui/views/toolbar/browser_action_view.h"
24 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" 24 #include "chrome/browser/ui/views/toolbar/toolbar_view.h"
25 #include "chrome/common/extensions/command.h" 25 #include "chrome/common/extensions/command.h"
26 #include "chrome/common/pref_names.h" 26 #include "chrome/common/pref_names.h"
27 #include "extensions/browser/extension_system.h" 27 #include "extensions/browser/extension_system.h"
28 #include "extensions/browser/pref_names.h" 28 #include "extensions/browser/pref_names.h"
29 #include "extensions/browser/runtime_data.h" 29 #include "extensions/browser/runtime_data.h"
30 #include "extensions/common/feature_switch.h"
30 #include "grit/generated_resources.h" 31 #include "grit/generated_resources.h"
31 #include "grit/theme_resources.h" 32 #include "grit/theme_resources.h"
32 #include "grit/ui_resources.h" 33 #include "grit/ui_resources.h"
33 #include "third_party/skia/include/core/SkColor.h" 34 #include "third_party/skia/include/core/SkColor.h"
34 #include "ui/accessibility/ax_view_state.h" 35 #include "ui/accessibility/ax_view_state.h"
35 #include "ui/base/dragdrop/drag_utils.h" 36 #include "ui/base/dragdrop/drag_utils.h"
36 #include "ui/base/l10n/l10n_util.h" 37 #include "ui/base/l10n/l10n_util.h"
37 #include "ui/base/nine_image_painter_factory.h" 38 #include "ui/base/nine_image_painter_factory.h"
38 #include "ui/base/resource/resource_bundle.h" 39 #include "ui/base/resource/resource_bundle.h"
39 #include "ui/base/theme_provider.h" 40 #include "ui/base/theme_provider.h"
(...skipping 10 matching lines...) Expand all
50 51
51 namespace { 52 namespace {
52 53
53 // Horizontal spacing between most items in the container, as well as after the 54 // Horizontal spacing between most items in the container, as well as after the
54 // last item or chevron (if visible). 55 // last item or chevron (if visible).
55 const int kItemSpacing = ToolbarView::kStandardSpacing; 56 const int kItemSpacing = ToolbarView::kStandardSpacing;
56 57
57 // Horizontal spacing before the chevron (if visible). 58 // Horizontal spacing before the chevron (if visible).
58 const int kChevronSpacing = kItemSpacing - 2; 59 const int kChevronSpacing = kItemSpacing - 2;
59 60
61 // Padding to make sure the badge appears in the right location vertically when
62 // in overflow mode (inside the app menu, aka. hamburger menu).
63 const int kPaddingForBadge = 9;
64
65 // The maximum number of icons to show per row when in overflow mode (showing
66 // icons in the application menu).
67 const int kIconsPerMenuRow = 7;
68
60 // A version of MenuButton with almost empty insets to fit properly on the 69 // A version of MenuButton with almost empty insets to fit properly on the
61 // toolbar. 70 // toolbar.
62 class ChevronMenuButton : public views::MenuButton { 71 class ChevronMenuButton : public views::MenuButton {
63 public: 72 public:
64 ChevronMenuButton(views::ButtonListener* listener, 73 ChevronMenuButton(views::ButtonListener* listener,
65 const base::string16& text, 74 const base::string16& text,
66 views::MenuButtonListener* menu_button_listener, 75 views::MenuButtonListener* menu_button_listener,
67 bool show_menu_marker) 76 bool show_menu_marker)
68 : views::MenuButton(listener, 77 : views::MenuButton(listener,
69 text, 78 text,
(...skipping 17 matching lines...) Expand all
87 }; 96 };
88 97
89 } // namespace 98 } // namespace
90 99
91 // static 100 // static
92 bool BrowserActionsContainer::disable_animations_during_testing_ = false; 101 bool BrowserActionsContainer::disable_animations_during_testing_ = false;
93 102
94 //////////////////////////////////////////////////////////////////////////////// 103 ////////////////////////////////////////////////////////////////////////////////
95 // BrowserActionsContainer 104 // BrowserActionsContainer
96 105
97 BrowserActionsContainer::BrowserActionsContainer(Browser* browser, 106 BrowserActionsContainer::BrowserActionsContainer(
98 View* owner_view) 107 Browser* browser, View* owner_view, BrowserActionsContainer* main_container)
99 : profile_(browser->profile()), 108 : profile_(browser->profile()),
100 browser_(browser), 109 browser_(browser),
101 owner_view_(owner_view), 110 owner_view_(owner_view),
111 main_container_(main_container),
102 popup_(NULL), 112 popup_(NULL),
103 popup_button_(NULL), 113 popup_button_(NULL),
104 model_(NULL), 114 model_(NULL),
105 container_width_(0), 115 container_width_(0),
116 resize_area_(NULL),
106 chevron_(NULL), 117 chevron_(NULL),
107 overflow_menu_(NULL), 118 overflow_menu_(NULL),
108 suppress_chevron_(false), 119 suppress_chevron_(false),
109 resize_amount_(0), 120 resize_amount_(0),
110 animation_target_size_(0), 121 animation_target_size_(0),
111 drop_indicator_position_(-1), 122 drop_indicator_position_(-1),
112 task_factory_(this), 123 task_factory_(this),
113 show_menu_task_factory_(this) { 124 show_menu_task_factory_(this) {
114 set_id(VIEW_ID_BROWSER_ACTION_TOOLBAR); 125 set_id(VIEW_ID_BROWSER_ACTION_TOOLBAR);
115 126
116 model_ = extensions::ExtensionToolbarModel::Get(browser->profile()); 127 model_ = extensions::ExtensionToolbarModel::Get(browser->profile());
117 if (model_) 128 if (model_)
118 model_->AddObserver(this); 129 model_->AddObserver(this);
119 130
120 extension_keybinding_registry_.reset(new ExtensionKeybindingRegistryViews( 131 bool overflow_experiment =
121 browser->profile(), 132 extensions::FeatureSwitch::extension_action_redesign()->IsEnabled();
122 owner_view->GetFocusManager(), 133 DCHECK(!handling_overflow() || overflow_experiment);
123 extensions::ExtensionKeybindingRegistry::ALL_EXTENSIONS,
124 this));
125 134
126 resize_animation_.reset(new gfx::SlideAnimation(this)); 135 if (!handling_overflow()) {
127 resize_area_ = new views::ResizeArea(this); 136 extension_keybinding_registry_.reset(new ExtensionKeybindingRegistryViews(
128 AddChildView(resize_area_); 137 browser->profile(),
138 owner_view->GetFocusManager(),
139 extensions::ExtensionKeybindingRegistry::ALL_EXTENSIONS,
140 this));
129 141
130 chevron_ = new ChevronMenuButton(NULL, base::string16(), this, false); 142 resize_animation_.reset(new gfx::SlideAnimation(this));
131 chevron_->EnableCanvasFlippingForRTLUI(true); 143 resize_area_ = new views::ResizeArea(this);
132 chevron_->SetAccessibleName( 144 AddChildView(resize_area_);
133 l10n_util::GetStringUTF16(IDS_ACCNAME_EXTENSIONS_CHEVRON)); 145
134 chevron_->SetVisible(false); 146 // 'Main' mode doesn't need a chevron overflow when overflow is shown inside
135 AddChildView(chevron_); 147 // the hamburger menu.
148 if (!overflow_experiment) {
149 chevron_ = new ChevronMenuButton(NULL, base::string16(), this, false);
150 chevron_->SetBorder(views::Border::NullBorder());
151 chevron_->EnableCanvasFlippingForRTLUI(true);
152 chevron_->SetAccessibleName(
153 l10n_util::GetStringUTF16(IDS_ACCNAME_EXTENSIONS_CHEVRON));
154 chevron_->SetVisible(false);
155 AddChildView(chevron_);
156 }
157 }
136 } 158 }
137 159
138 BrowserActionsContainer::~BrowserActionsContainer() { 160 BrowserActionsContainer::~BrowserActionsContainer() {
139 FOR_EACH_OBSERVER(BrowserActionsContainerObserver, 161 FOR_EACH_OBSERVER(BrowserActionsContainerObserver,
140 observers_, 162 observers_,
141 OnBrowserActionsContainerDestroyed()); 163 OnBrowserActionsContainerDestroyed());
142 164
143 if (overflow_menu_) 165 if (overflow_menu_)
144 overflow_menu_->set_observer(NULL); 166 overflow_menu_->set_observer(NULL);
145 if (model_) 167 if (model_)
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 void BrowserActionsContainer::ExecuteExtensionCommand( 248 void BrowserActionsContainer::ExecuteExtensionCommand(
227 const extensions::Extension* extension, 249 const extensions::Extension* extension,
228 const extensions::Command& command) { 250 const extensions::Command& command) {
229 // Global commands are handled by the ExtensionCommandsGlobalRegistry 251 // Global commands are handled by the ExtensionCommandsGlobalRegistry
230 // instance. 252 // instance.
231 DCHECK(!command.global()); 253 DCHECK(!command.global());
232 extension_keybinding_registry_->ExecuteCommand(extension->id(), 254 extension_keybinding_registry_->ExecuteCommand(extension->id(),
233 command.accelerator()); 255 command.accelerator());
234 } 256 }
235 257
258 bool BrowserActionsContainer::ShownInsideMenu() const {
259 return handling_overflow();
260 }
261
236 void BrowserActionsContainer::AddObserver( 262 void BrowserActionsContainer::AddObserver(
237 BrowserActionsContainerObserver* observer) { 263 BrowserActionsContainerObserver* observer) {
238 observers_.AddObserver(observer); 264 observers_.AddObserver(observer);
239 } 265 }
240 266
241 void BrowserActionsContainer::RemoveObserver( 267 void BrowserActionsContainer::RemoveObserver(
242 BrowserActionsContainerObserver* observer) { 268 BrowserActionsContainerObserver* observer) {
243 observers_.RemoveObserver(observer); 269 observers_.RemoveObserver(observer);
244 } 270 }
245 271
246 gfx::Size BrowserActionsContainer::GetPreferredSize() const { 272 gfx::Size BrowserActionsContainer::GetPreferredSize() const {
273 size_t our_icon_count = browser_action_views_.size() -
274 (handling_overflow() ? main_container_->VisibleBrowserActions() : 0);
275
276 // If there are no actions to show, or we are in overflow mode and the main
277 // container is already showing them all, then no further work is required.
278 if (browser_action_views_.empty() || our_icon_count == 0)
Devlin 2014/06/26 00:04:07 I don't think it should be possible for browser_ac
279 return gfx::Size();
280
281 if (handling_overflow()) {
282 return gfx::Size(
283 IconCountToWidth(kIconsPerMenuRow, false),
284 (std::max(((our_icon_count - 1) / kIconsPerMenuRow), 0U) + 1) *
285 IconHeight());
286 }
287
247 // We calculate the size of the view by taking the current width and 288 // We calculate the size of the view by taking the current width and
248 // subtracting resize_amount_ (the latter represents how far the user is 289 // subtracting resize_amount_ (the latter represents how far the user is
249 // resizing the view or, if animating the snapping, how far to animate it). 290 // resizing the view or, if animating the snapping, how far to animate it).
250 // But we also clamp it to a minimum size and the maximum size, so that the 291 // But we also clamp it to a minimum size and the maximum size, so that the
251 // container can never shrink too far or take up more space than it needs. In 292 // container can never shrink too far or take up more space than it needs.
252 // other words: MinimumNonemptyWidth() < width() - resize < ClampTo(MAX). 293 // In other words: MinimumNonemptyWidth() < width() - resize < ClampTo(MAX).
253 int preferred_width = std::min( 294 int preferred_width = std::min(
254 std::max(MinimumNonemptyWidth(), container_width_ - resize_amount_), 295 std::max(MinimumNonemptyWidth(), container_width_ - resize_amount_),
255 IconCountToWidth(-1, false)); 296 IconCountToWidth(-1, false));
256 // Height will be ignored by the ToolbarView. 297 return gfx::Size(preferred_width, IconHeight());
257 return gfx::Size(preferred_width, 0);
258 } 298 }
259 299
260 gfx::Size BrowserActionsContainer::GetMinimumSize() const { 300 gfx::Size BrowserActionsContainer::GetMinimumSize() const {
261 int min_width = std::min(MinimumNonemptyWidth(), IconCountToWidth(-1, false)); 301 int min_width = std::min(MinimumNonemptyWidth(), IconCountToWidth(-1, false));
262 // Height will be ignored by the ToolbarView. 302 return gfx::Size(min_width, IconHeight());
263 return gfx::Size(min_width, 0);
264 } 303 }
265 304
266 void BrowserActionsContainer::Layout() { 305 void BrowserActionsContainer::Layout() {
267 if (browser_action_views_.empty()) { 306 if (browser_action_views_.empty()) {
268 SetVisible(false); 307 SetVisible(false);
269 return; 308 return;
270 } 309 }
271 310
272 SetVisible(true); 311 SetVisible(true);
273 resize_area_->SetBounds(0, 0, kItemSpacing, height()); 312 if (resize_area_)
313 resize_area_->SetBounds(0, 0, kItemSpacing, height());
274 314
275 // If the icons don't all fit, show the chevron (unless suppressed). 315 // If the icons don't all fit, show the chevron (unless suppressed).
276 int max_x = GetPreferredSize().width(); 316 int max_x = GetPreferredSize().width();
277 if ((IconCountToWidth(-1, false) > max_x) && !suppress_chevron_) { 317 if ((IconCountToWidth(-1, false) > max_x) && !suppress_chevron_ && chevron_) {
278 chevron_->SetVisible(true); 318 chevron_->SetVisible(true);
279 gfx::Size chevron_size(chevron_->GetPreferredSize()); 319 gfx::Size chevron_size(chevron_->GetPreferredSize());
280 max_x -= 320 max_x -=
281 ToolbarView::kStandardSpacing + chevron_size.width() + kChevronSpacing; 321 ToolbarView::kStandardSpacing + chevron_size.width() + kChevronSpacing;
282 chevron_->SetBounds( 322 chevron_->SetBounds(
283 width() - ToolbarView::kStandardSpacing - chevron_size.width(), 323 width() - ToolbarView::kStandardSpacing - chevron_size.width(),
284 0, 324 0,
285 chevron_size.width(), 325 chevron_size.width(),
286 chevron_size.height()); 326 chevron_size.height());
287 } else { 327 } else if (chevron_) {
288 chevron_->SetVisible(false); 328 chevron_->SetVisible(false);
Devlin 2014/06/26 00:04:07 nit: indentation
289 } 329 }
290 330
291 // Now draw the icons for the browser actions in the available space. 331 // Now draw the icons for the browser actions in the available space.
292 int icon_width = IconWidth(false); 332 int icon_width = IconWidth(false);
293 for (size_t i = 0; i < browser_action_views_.size(); ++i) { 333 if (handling_overflow()) {
294 BrowserActionView* view = browser_action_views_[i]; 334 size_t our_icon_count =
295 int x = ToolbarView::kStandardSpacing + (i * IconWidth(true)); 335 browser_action_views_.size() - main_container_->VisibleBrowserActions();
Devlin 2014/06/26 00:04:07 We rely on VisibleBrowserActions() here, even thou
Finnur 2014/06/26 12:00:44 This code path only hits in the overflow container
296 if (x + icon_width <= max_x) { 336 for (size_t i = 0; i < our_icon_count; ++i) {
Devlin 2014/06/26 00:04:07 I personally think it's a bit clear that this is h
Finnur 2014/06/26 12:00:44 Done.
297 view->SetBounds(x, 0, icon_width, height()); 337 BrowserActionView* view =
338 browser_action_views_[i + main_container_->VisibleBrowserActions()];
339 int x = ToolbarView::kStandardSpacing + i * IconWidth(true) -
340 ((i / kIconsPerMenuRow) * (IconWidth(true) * kIconsPerMenuRow));
341 gfx::Rect rect_bounds(
342 x,
343 IconHeight() *
344 (std::max((static_cast<int>(i) / kIconsPerMenuRow), 0)),
Devlin 2014/06/26 00:04:07 I think this std::max() isn't needed, either?
Finnur 2014/06/26 12:00:44 What is this, a crusade now? ;) But yeah, I think
345 icon_width,
346 IconHeight() + kPaddingForBadge);
347 view->SetBoundsRect(rect_bounds);
298 view->SetVisible(true); 348 view->SetVisible(true);
Devlin 2014/06/26 00:04:07 We never SetVisible(false) for the overflow contai
Finnur 2014/06/26 12:00:44 The |view| here is the browser action. For the mai
Devlin 2014/06/26 16:29:13 Yeah, I was wondering if, since both BACs have a f
Finnur 2014/06/27 14:23:38 Done.
299 } else { 349 }
300 view->SetVisible(false); 350 } else {
351 for (size_t i = 0; i < browser_action_views_.size(); ++i) {
352 BrowserActionView* view = browser_action_views_[i];
353 int x = ToolbarView::kStandardSpacing + (i * IconWidth(true));
354 if (x + icon_width <= max_x) {
355 view->SetBounds(x, 0, icon_width, IconHeight());
356 view->SetVisible(true);
357 } else {
358 view->SetVisible(false);
359 }
301 } 360 }
302 } 361 }
303 } 362 }
304 363
305 bool BrowserActionsContainer::GetDropFormats( 364 bool BrowserActionsContainer::GetDropFormats(
306 int* formats, 365 int* formats,
307 std::set<OSExchangeData::CustomFormat>* custom_formats) { 366 std::set<OSExchangeData::CustomFormat>* custom_formats) {
308 custom_formats->insert(BrowserActionDragData::GetBrowserActionCustomFormat()); 367 custom_formats->insert(BrowserActionDragData::GetBrowserActionCustomFormat());
309 368
310 return true; 369 return true;
(...skipping 21 matching lines...) Expand all
332 return ui::DragDropTypes::DRAG_MOVE; 391 return ui::DragDropTypes::DRAG_MOVE;
333 } 392 }
334 StopShowFolderDropMenuTimer(); 393 StopShowFolderDropMenuTimer();
335 394
336 // Figure out where to display the indicator. This is a complex calculation: 395 // Figure out where to display the indicator. This is a complex calculation:
337 396
338 // First, we figure out how much space is to the left of the icon area, so we 397 // First, we figure out how much space is to the left of the icon area, so we
339 // can calculate the true offset into the icon area. 398 // can calculate the true offset into the icon area.
340 int width_before_icons = ToolbarView::kStandardSpacing + 399 int width_before_icons = ToolbarView::kStandardSpacing +
341 (base::i18n::IsRTL() ? 400 (base::i18n::IsRTL() ?
342 (chevron_->GetPreferredSize().width() + kChevronSpacing) : 0); 401 (chevron_->GetPreferredSize().width() + kChevronSpacing) : 0);
Devlin 2014/06/26 00:04:07 Is this not a seg fault risk because the wrench me
Finnur 2014/06/26 12:00:44 Correct. I'll fix this.
343 int offset_into_icon_area = event.x() - width_before_icons; 402 int offset_into_icon_area = event.x() - width_before_icons;
344 403
345 // Next, we determine which icon to place the indicator in front of. We want 404 // Next, we determine which icon to place the indicator in front of. We want
346 // to place the indicator in front of icon n when the cursor is between the 405 // to place the indicator in front of icon n when the cursor is between the
347 // midpoints of icons (n - 1) and n. To do this we take the offset into the 406 // midpoints of icons (n - 1) and n. To do this we take the offset into the
348 // icon area and transform it as follows: 407 // icon area and transform it as follows:
349 // 408 //
350 // Real icon area: 409 // Real icon area:
351 // 0 a * b c 410 // 0 a * b c
352 // | | | | 411 // | | | |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 return SessionTabHelper::FromWebContents(active_tab)->session_id().id(); 608 return SessionTabHelper::FromWebContents(active_tab)->session_id().id();
550 } 609 }
551 610
552 void BrowserActionsContainer::OnBrowserActionExecuted( 611 void BrowserActionsContainer::OnBrowserActionExecuted(
553 BrowserActionButton* button) { 612 BrowserActionButton* button) {
554 ShowPopup(button, ExtensionPopup::SHOW, true); 613 ShowPopup(button, ExtensionPopup::SHOW, true);
555 } 614 }
556 615
557 void BrowserActionsContainer::OnBrowserActionVisibilityChanged() { 616 void BrowserActionsContainer::OnBrowserActionVisibilityChanged() {
558 SetVisible(!browser_action_views_.empty()); 617 SetVisible(!browser_action_views_.empty());
559 owner_view_->Layout(); 618 if (owner_view_) {
560 owner_view_->SchedulePaint(); 619 owner_view_->Layout();
620 owner_view_->SchedulePaint();
621 }
561 } 622 }
562 623
563 extensions::ActiveTabPermissionGranter* 624 extensions::ActiveTabPermissionGranter*
564 BrowserActionsContainer::GetActiveTabPermissionGranter() { 625 BrowserActionsContainer::GetActiveTabPermissionGranter() {
565 content::WebContents* web_contents = 626 content::WebContents* web_contents =
566 browser_->tab_strip_model()->GetActiveWebContents(); 627 browser_->tab_strip_model()->GetActiveWebContents();
567 if (!web_contents) 628 if (!web_contents)
568 return NULL; 629 return NULL;
569 return extensions::TabHelper::FromWebContents(web_contents)-> 630 return extensions::TabHelper::FromWebContents(web_contents)->
570 active_tab_permission_granter(); 631 active_tab_permission_granter();
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
758 819
759 if (browser_action_views_.size() > visible_actions) { 820 if (browser_action_views_.size() > visible_actions) {
760 // If we have more icons than we can show, then we must not be changing 821 // If we have more icons than we can show, then we must not be changing
761 // the container size (since we either removed an icon from the main 822 // the container size (since we either removed an icon from the main
762 // area and one from the overflow list will have shifted in, or we 823 // area and one from the overflow list will have shifted in, or we
763 // removed an entry directly from the overflow list). 824 // removed an entry directly from the overflow list).
764 OnBrowserActionVisibilityChanged(); 825 OnBrowserActionVisibilityChanged();
765 } else { 826 } else {
766 // Either we went from overflow to no-overflow, or we shrunk the no- 827 // Either we went from overflow to no-overflow, or we shrunk the no-
767 // overflow container by 1. Either way the size changed, so animate. 828 // overflow container by 1. Either way the size changed, so animate.
768 chevron_->SetVisible(false); 829 if (chevron_)
830 chevron_->SetVisible(false);
769 SaveDesiredSizeAndAnimate(gfx::Tween::EASE_OUT, 831 SaveDesiredSizeAndAnimate(gfx::Tween::EASE_OUT,
770 browser_action_views_.size()); 832 browser_action_views_.size());
771 } 833 }
772 return; 834 return; // We have found the action to remove, bail out.
773 } 835 }
774 } 836 }
775 } 837 }
776 838
777 void BrowserActionsContainer::BrowserActionMoved(const Extension* extension, 839 void BrowserActionsContainer::BrowserActionMoved(const Extension* extension,
778 int index) { 840 int index) {
779 if (!ShouldDisplayBrowserAction(extension)) 841 if (!ShouldDisplayBrowserAction(extension))
780 return; 842 return;
781 843
782 if (profile_->IsOffTheRecord()) 844 if (profile_->IsOffTheRecord())
(...skipping 21 matching lines...) Expand all
804 // we delete and recreate everything here, but that's how it's done in 866 // we delete and recreate everything here, but that's how it's done in
805 // BrowserActionMoved(), too. If we want to optimize it, we could move the 867 // BrowserActionMoved(), too. If we want to optimize it, we could move the
806 // existing icons, instead of deleting it all. 868 // existing icons, instead of deleting it all.
807 DeleteBrowserActionViews(); 869 DeleteBrowserActionViews();
808 CreateBrowserActionViews(); 870 CreateBrowserActionViews();
809 SaveDesiredSizeAndAnimate(gfx::Tween::LINEAR, browser_action_views_.size()); 871 SaveDesiredSizeAndAnimate(gfx::Tween::LINEAR, browser_action_views_.size());
810 } 872 }
811 873
812 void BrowserActionsContainer::LoadImages() { 874 void BrowserActionsContainer::LoadImages() {
813 ui::ThemeProvider* tp = GetThemeProvider(); 875 ui::ThemeProvider* tp = GetThemeProvider();
876 if (!tp || !chevron_)
877 return;
878
814 chevron_->SetImage(views::Button::STATE_NORMAL, 879 chevron_->SetImage(views::Button::STATE_NORMAL,
815 *tp->GetImageSkiaNamed(IDR_BROWSER_ACTIONS_OVERFLOW)); 880 *tp->GetImageSkiaNamed(IDR_BROWSER_ACTIONS_OVERFLOW));
816 881
817 const int kImages[] = IMAGE_GRID(IDR_DEVELOPER_MODE_HIGHLIGHT); 882 const int kImages[] = IMAGE_GRID(IDR_DEVELOPER_MODE_HIGHLIGHT);
818 highlight_painter_.reset(views::Painter::CreateImageGridPainter(kImages)); 883 highlight_painter_.reset(views::Painter::CreateImageGridPainter(kImages));
819 } 884 }
820 885
821 void BrowserActionsContainer::SetContainerWidth() { 886 void BrowserActionsContainer::SetContainerWidth() {
822 int visible_actions = model_->GetVisibleIconCount(); 887 // The slave only draws the overflow (what isn't visible in the other
888 // container).
889 int visible_actions = handling_overflow() ? model_->toolbar_items().size() -
890 model_->GetVisibleIconCount()
891 : model_->GetVisibleIconCount();
823 if (visible_actions < 0) // All icons should be visible. 892 if (visible_actions < 0) // All icons should be visible.
824 visible_actions = model_->toolbar_items().size(); 893 visible_actions = model_->toolbar_items().size();
825 chevron_->SetVisible( 894 if (chevron_) {
826 static_cast<size_t>(visible_actions) < model_->toolbar_items().size()); 895 chevron_->SetVisible(
827 container_width_ = IconCountToWidth(visible_actions, chevron_->visible()); 896 static_cast<size_t>(visible_actions) < model_->toolbar_items().size());
897 }
898 container_width_ =
899 IconCountToWidth(visible_actions, chevron_ ? chevron_->visible() : false);
828 } 900 }
829 901
830 void BrowserActionsContainer::CloseOverflowMenu() { 902 void BrowserActionsContainer::CloseOverflowMenu() {
831 if (overflow_menu_) 903 if (overflow_menu_)
832 overflow_menu_->CancelMenu(); 904 overflow_menu_->CancelMenu();
833 } 905 }
834 906
835 void BrowserActionsContainer::StopShowFolderDropMenuTimer() { 907 void BrowserActionsContainer::StopShowFolderDropMenuTimer() {
836 show_menu_task_factory_.InvalidateWeakPtrs(); 908 show_menu_task_factory_.InvalidateWeakPtrs();
837 } 909 }
(...skipping 23 matching lines...) Expand all
861 } 933 }
862 934
863 int BrowserActionsContainer::IconCountToWidth(int icons, 935 int BrowserActionsContainer::IconCountToWidth(int icons,
864 bool display_chevron) const { 936 bool display_chevron) const {
865 if (icons < 0) 937 if (icons < 0)
866 icons = browser_action_views_.size(); 938 icons = browser_action_views_.size();
867 if ((icons == 0) && !display_chevron) 939 if ((icons == 0) && !display_chevron)
868 return ToolbarView::kStandardSpacing; 940 return ToolbarView::kStandardSpacing;
869 int icons_size = 941 int icons_size =
870 (icons == 0) ? 0 : ((icons * IconWidth(true)) - kItemSpacing); 942 (icons == 0) ? 0 : ((icons * IconWidth(true)) - kItemSpacing);
871 int chevron_size = display_chevron ? 943 int chevron_size = chevron_ && display_chevron ?
872 (kChevronSpacing + chevron_->GetPreferredSize().width()) : 0; 944 (kChevronSpacing + chevron_->GetPreferredSize().width()) : 0;
873 return ToolbarView::kStandardSpacing + icons_size + chevron_size + 945 return ToolbarView::kStandardSpacing + icons_size + chevron_size +
874 ToolbarView::kStandardSpacing; 946 ToolbarView::kStandardSpacing;
875 } 947 }
876 948
877 size_t BrowserActionsContainer::WidthToIconCount(int pixels) const { 949 size_t BrowserActionsContainer::WidthToIconCount(int pixels) const {
878 // Check for widths large enough to show the entire icon set. 950 // Check for widths large enough to show the entire icon set.
879 if (pixels >= IconCountToWidth(-1, false)) 951 if (pixels >= IconCountToWidth(-1, false))
880 return browser_action_views_.size(); 952 return browser_action_views_.size();
881 953
882 // We need to reserve space for the resize area, chevron, and the spacing on 954 // We need to reserve space for the resize area, chevron, and the spacing on
883 // either side of the chevron. 955 // either side of the chevron.
884 int available_space = pixels - ToolbarView::kStandardSpacing - 956 int available_space = pixels - ToolbarView::kStandardSpacing -
885 chevron_->GetPreferredSize().width() - kChevronSpacing - 957 (chevron_ ? chevron_->GetPreferredSize().width() : 0) -
886 ToolbarView::kStandardSpacing; 958 kChevronSpacing - ToolbarView::kStandardSpacing;
887 // Now we add an extra between-item padding value so the space can be divided 959 // Now we add an extra between-item padding value so the space can be divided
888 // evenly by (size of icon with padding). 960 // evenly by (size of icon with padding).
889 return static_cast<size_t>( 961 return static_cast<size_t>(
890 std::max(0, available_space + kItemSpacing) / IconWidth(true)); 962 std::max(0, available_space + kItemSpacing) / IconWidth(true));
891 } 963 }
892 964
893 int BrowserActionsContainer::MinimumNonemptyWidth() const { 965 int BrowserActionsContainer::MinimumNonemptyWidth() const {
894 return ToolbarView::kStandardSpacing + kChevronSpacing + 966 return ToolbarView::kStandardSpacing +
895 chevron_->GetPreferredSize().width() + ToolbarView::kStandardSpacing; 967 (chevron_ ? (kChevronSpacing + chevron_->GetPreferredSize().width() +
968 ToolbarView::kStandardSpacing)
969 : 0);
896 } 970 }
897 971
898 void BrowserActionsContainer::SaveDesiredSizeAndAnimate( 972 void BrowserActionsContainer::SaveDesiredSizeAndAnimate(
899 gfx::Tween::Type tween_type, 973 gfx::Tween::Type tween_type,
900 size_t num_visible_icons) { 974 size_t num_visible_icons) {
901 // Save off the desired number of visible icons. We do this now instead of at 975 // Save off the desired number of visible icons. We do this now instead of at
902 // the end of the animation so that even if the browser is shut down while 976 // the end of the animation so that even if the browser is shut down while
903 // animating, the right value will be restored on next run. 977 // animating, the right value will be restored on next run.
904 // NOTE: Don't save the icon count in incognito because there may be fewer 978 // NOTE: Don't save the icon count in incognito because there may be fewer
905 // icons in that mode. The result is that the container in a normal window is 979 // icons in that mode. The result is that the container in a normal window is
906 // always at least as wide as in an incognito window. 980 // always at least as wide as in an incognito window.
907 if (!profile_->IsOffTheRecord()) 981 if (!profile_->IsOffTheRecord())
908 model_->SetVisibleIconCount(num_visible_icons); 982 model_->SetVisibleIconCount(num_visible_icons);
909 int target_size = IconCountToWidth(num_visible_icons, 983 int target_size = IconCountToWidth(num_visible_icons,
910 num_visible_icons < browser_action_views_.size()); 984 num_visible_icons < browser_action_views_.size());
911 if (!disable_animations_during_testing_) { 985 if (resize_animation_ && !disable_animations_during_testing_) {
912 // Animate! We have to set the animation_target_size_ after calling Reset(), 986 // Animate! We have to set the animation_target_size_ after calling Reset(),
913 // because that could end up calling AnimationEnded which clears the value. 987 // because that could end up calling AnimationEnded which clears the value.
914 resize_animation_->Reset(); 988 resize_animation_->Reset();
915 resize_animation_->SetTweenType(tween_type); 989 resize_animation_->SetTweenType(tween_type);
916 animation_target_size_ = target_size; 990 animation_target_size_ = target_size;
917 resize_animation_->Show(); 991 resize_animation_->Show();
918 } else { 992 } else {
919 animation_target_size_ = target_size; 993 animation_target_size_ = target_size;
920 AnimationEnded(resize_animation_.get()); 994 AnimationEnded(resize_animation_.get());
921 } 995 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
958 views::BubbleBorder::TOP_RIGHT, 1032 views::BubbleBorder::TOP_RIGHT,
959 show_action); 1033 show_action);
960 popup_->GetWidget()->AddObserver(this); 1034 popup_->GetWidget()->AddObserver(this);
961 popup_button_ = button; 1035 popup_button_ = button;
962 1036
963 // Only set button as pushed if it was triggered by a user click. 1037 // Only set button as pushed if it was triggered by a user click.
964 if (should_grant) 1038 if (should_grant)
965 popup_button_->SetButtonPushed(); 1039 popup_button_->SetButtonPushed();
966 return true; 1040 return true;
967 } 1041 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698