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

Side by Side Diff: chrome/browser/ui/toolbar/toolbar_actions_bar.cc

Issue 1241063003: Support Component Actions in the toolbar. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changes per rdevlin.cronin@'s comments. Created 5 years, 4 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
OLDNEW
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 "base/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/profiler/scoped_tracker.h" 9 #include "base/profiler/scoped_tracker.h"
10 #include "base/single_thread_task_runner.h" 10 #include "base/single_thread_task_runner.h"
11 #include "base/thread_task_runner_handle.h" 11 #include "base/thread_task_runner_handle.h"
12 #include "chrome/browser/extensions/extension_action_manager.h" 12 #include "chrome/browser/extensions/extension_action_manager.h"
13 #include "chrome/browser/extensions/extension_message_bubble_controller.h" 13 #include "chrome/browser/extensions/extension_message_bubble_controller.h"
14 #include "chrome/browser/extensions/extension_util.h" 14 #include "chrome/browser/extensions/extension_util.h"
15 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/sessions/session_tab_helper.h" 16 #include "chrome/browser/sessions/session_tab_helper.h"
17 #include "chrome/browser/ui/browser.h" 17 #include "chrome/browser/ui/browser.h"
18 #include "chrome/browser/ui/browser_window.h" 18 #include "chrome/browser/ui/browser_window.h"
19 #include "chrome/browser/ui/extensions/extension_action_view_controller.h" 19 #include "chrome/browser/ui/extensions/extension_action_view_controller.h"
20 #include "chrome/browser/ui/extensions/extension_message_bubble_factory.h" 20 #include "chrome/browser/ui/extensions/extension_message_bubble_factory.h"
21 #include "chrome/browser/ui/tabs/tab_strip_model.h" 21 #include "chrome/browser/ui/tabs/tab_strip_model.h"
22 #include "chrome/browser/ui/toolbar/component_toolbar_actions_factory.h" 22 #include "chrome/browser/ui/toolbar/component_toolbar_actions_factory.h"
23 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h" 23 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h"
24 #include "chrome/browser/ui/toolbar/toolbar_actions_bar_delegate.h" 24 #include "chrome/browser/ui/toolbar/toolbar_actions_bar_delegate.h"
25 #include "chrome/common/pref_names.h" 25 #include "chrome/common/pref_names.h"
26 #include "components/crx_file/id_util.h" 26 #include "components/crx_file/id_util.h"
27 #include "components/pref_registry/pref_registry_syncable.h" 27 #include "components/pref_registry/pref_registry_syncable.h"
28 #include "extensions/browser/extension_registry.h"
28 #include "extensions/browser/extension_system.h" 29 #include "extensions/browser/extension_system.h"
29 #include "extensions/browser/runtime_data.h" 30 #include "extensions/browser/runtime_data.h"
30 #include "extensions/common/extension.h" 31 #include "extensions/common/extension.h"
31 #include "extensions/common/feature_switch.h" 32 #include "extensions/common/feature_switch.h"
32 #include "grit/theme_resources.h" 33 #include "grit/theme_resources.h"
33 #include "ui/base/resource/resource_bundle.h" 34 #include "ui/base/resource/resource_bundle.h"
34 #include "ui/gfx/image/image_skia.h" 35 #include "ui/gfx/image/image_skia.h"
35 36
36 namespace { 37 namespace {
37 38
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 icons_per_overflow_menu_row(1), 113 icons_per_overflow_menu_row(1),
113 chevron_enabled(!extensions::FeatureSwitch::extension_action_redesign()-> 114 chevron_enabled(!extensions::FeatureSwitch::extension_action_redesign()->
114 IsEnabled()) { 115 IsEnabled()) {
115 } 116 }
116 117
117 ToolbarActionsBar::ToolbarActionsBar(ToolbarActionsBarDelegate* delegate, 118 ToolbarActionsBar::ToolbarActionsBar(ToolbarActionsBarDelegate* delegate,
118 Browser* browser, 119 Browser* browser,
119 ToolbarActionsBar* main_bar) 120 ToolbarActionsBar* main_bar)
120 : delegate_(delegate), 121 : delegate_(delegate),
121 browser_(browser), 122 browser_(browser),
122 model_(extensions::ExtensionToolbarModel::Get(browser_->profile())), 123 model_(ToolbarActionsModel::Get(browser_->profile())),
123 main_bar_(main_bar), 124 main_bar_(main_bar),
124 platform_settings_(main_bar != nullptr), 125 platform_settings_(main_bar != nullptr),
125 popup_owner_(nullptr), 126 popup_owner_(nullptr),
126 model_observer_(this), 127 model_observer_(this),
127 suppress_layout_(false), 128 suppress_layout_(false),
128 suppress_animation_(true), 129 suppress_animation_(true),
129 overflowed_action_wants_to_run_(false), 130 overflowed_action_wants_to_run_(false),
130 checked_extension_bubble_(false), 131 checked_extension_bubble_(false),
131 popped_out_action_(nullptr), 132 popped_out_action_(nullptr),
132 weak_ptr_factory_(this) { 133 weak_ptr_factory_(this) {
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 // want to "slide" the action back in. 252 // want to "slide" the action back in.
252 size_t visible_icons = in_overflow_mode() ? 253 size_t visible_icons = in_overflow_mode() ?
253 toolbar_actions_.size() - model_->visible_icon_count() : 254 toolbar_actions_.size() - model_->visible_icon_count() :
254 model_->visible_icon_count() + pop_out_modifier; 255 model_->visible_icon_count() + pop_out_modifier;
255 256
256 #if DCHECK_IS_ON() 257 #if DCHECK_IS_ON()
257 // Good time for some sanity checks: We should never try to display more 258 // Good time for some sanity checks: We should never try to display more
258 // icons than we have, and we should always have a view per item in the model. 259 // icons than we have, and we should always have a view per item in the model.
259 // (The only exception is if this is in initialization.) 260 // (The only exception is if this is in initialization.)
260 if (!toolbar_actions_.empty() && !suppress_layout_ && 261 if (!toolbar_actions_.empty() && !suppress_layout_ &&
261 model_->extensions_initialized()) { 262 model_->actions_initialized()) {
262 size_t num_extension_actions = 0u; 263 DCHECK_LE(visible_icons, toolbar_actions_.size());
263 for (ToolbarActionViewController* action : toolbar_actions_) { 264 DCHECK_EQ(model_->toolbar_items().size(), toolbar_actions_.size());
264 // No component action should ever have a valid extension id, so we can
265 // use this to check the extension amount.
266 if (crx_file::id_util::IdIsValid(action->GetId()))
267 ++num_extension_actions;
268 }
269
270 int num_component_actions =
271 ComponentToolbarActionsFactory::GetInstance()->
272 GetNumComponentActions(browser_);
273 size_t num_total_actions = num_extension_actions + num_component_actions;
274
275 DCHECK_LE(visible_icons, num_total_actions);
276 DCHECK_EQ(model_->toolbar_items().size(), num_extension_actions);
277 } 265 }
278 #endif 266 #endif
279 267
280 return visible_icons; 268 return visible_icons;
281 } 269 }
282 270
283 gfx::Rect ToolbarActionsBar::GetFrameForIndex(size_t index) const { 271 gfx::Rect ToolbarActionsBar::GetFrameForIndex(size_t index) const {
284 size_t start_index = in_overflow_mode() ? 272 size_t start_index = in_overflow_mode() ?
285 toolbar_actions_.size() - GetIconCount() : 0u; 273 toolbar_actions_.size() - GetIconCount() : 0u;
286 274
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 } 312 }
325 } 313 }
326 314
327 return actions; 315 return actions;
328 } 316 }
329 317
330 void ToolbarActionsBar::CreateActions() { 318 void ToolbarActionsBar::CreateActions() {
331 DCHECK(toolbar_actions_.empty()); 319 DCHECK(toolbar_actions_.empty());
332 // We wait for the extension system to be initialized before we add any 320 // We wait for the extension system to be initialized before we add any
333 // actions, as they rely on the extension system to function. 321 // actions, as they rely on the extension system to function.
334 if (!model_ || !model_->extensions_initialized()) 322 if (!model_ || !model_->actions_initialized())
335 return; 323 return;
336 324
337 { 325 {
338 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/463337 326 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/463337
339 // is fixed. 327 // is fixed.
340 tracked_objects::ScopedTracker tracking_profile1( 328 tracked_objects::ScopedTracker tracking_profile1(
341 FROM_HERE_WITH_EXPLICIT_FUNCTION("ToolbarActionsBar::CreateActions1")); 329 FROM_HERE_WITH_EXPLICIT_FUNCTION("ToolbarActionsBar::CreateActions1"));
342 // We don't redraw the view while creating actions. 330 // We don't redraw the view while creating actions.
343 base::AutoReset<bool> layout_resetter(&suppress_layout_, true); 331 base::AutoReset<bool> layout_resetter(&suppress_layout_, true);
344 332
345 // Extension actions come first. 333 // Get the toolbar actions.
346 extensions::ExtensionActionManager* action_manager = 334 toolbar_actions_ = model_->CreateActions(browser_, this);
347 extensions::ExtensionActionManager::Get(browser_->profile());
348 const extensions::ExtensionList& toolbar_items = model_->toolbar_items();
349 for (const scoped_refptr<const extensions::Extension>& extension :
350 toolbar_items) {
351 toolbar_actions_.push_back(new ExtensionActionViewController(
352 extension.get(),
353 browser_,
354 action_manager->GetExtensionAction(*extension),
355 this));
356 }
357
358 // Component actions come second, and are suppressed if the extension
359 // actions are being highlighted.
360 if (!model_->is_highlighting()) { 335 if (!model_->is_highlighting()) {
361 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/463337 336 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/463337
362 // is fixed. 337 // is fixed.
363 tracked_objects::ScopedTracker tracking_profile2( 338 tracked_objects::ScopedTracker tracking_profile2(
364 FROM_HERE_WITH_EXPLICIT_FUNCTION( 339 FROM_HERE_WITH_EXPLICIT_FUNCTION(
365 "ToolbarActionsBar::CreateActions2")); 340 "ToolbarActionsBar::CreateActions2"));
366
367 ScopedVector<ToolbarActionViewController> component_actions =
368 ComponentToolbarActionsFactory::GetInstance()->
369 GetComponentToolbarActions(browser_);
370 DCHECK(component_actions.empty() ||
371 extensions::FeatureSwitch::extension_action_redesign()->IsEnabled());
372 toolbar_actions_.insert(toolbar_actions_.end(),
373 component_actions.begin(),
374 component_actions.end());
375 component_actions.weak_clear();
376 } 341 }
377 342
378 if (!toolbar_actions_.empty()) { 343 if (!toolbar_actions_.empty()) {
379 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/463337 344 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/463337
380 // is fixed. 345 // is fixed.
381 tracked_objects::ScopedTracker tracking_profile3( 346 tracked_objects::ScopedTracker tracking_profile3(
382 FROM_HERE_WITH_EXPLICIT_FUNCTION( 347 FROM_HERE_WITH_EXPLICIT_FUNCTION(
383 "ToolbarActionsBar::CreateActions3")); 348 "ToolbarActionsBar::CreateActions3"));
384 ReorderActions(); 349 ReorderActions();
385 } 350 }
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 if (in_overflow_mode()) { 420 if (in_overflow_mode()) {
456 main_bar_->OnDragDrop(dragged_index, dropped_index, drag_type); 421 main_bar_->OnDragDrop(dragged_index, dropped_index, drag_type);
457 return; 422 return;
458 } 423 }
459 424
460 int delta = 0; 425 int delta = 0;
461 if (drag_type == DRAG_TO_OVERFLOW) 426 if (drag_type == DRAG_TO_OVERFLOW)
462 delta = -1; 427 delta = -1;
463 else if (drag_type == DRAG_TO_MAIN) 428 else if (drag_type == DRAG_TO_MAIN)
464 delta = 1; 429 delta = 1;
465 model_->MoveExtensionIcon(toolbar_actions_[dragged_index]->GetId(), 430 model_->MoveActionIcon(toolbar_actions_[dragged_index]->GetId(),
466 dropped_index); 431 dropped_index);
467 if (delta) 432 if (delta)
468 model_->SetVisibleIconCount(model_->visible_icon_count() + delta); 433 model_->SetVisibleIconCount(model_->visible_icon_count() + delta);
469 } 434 }
470 435
471 void ToolbarActionsBar::OnAnimationEnded() { 436 void ToolbarActionsBar::OnAnimationEnded() {
472 // Check if we were waiting for animation to complete to either show a 437 // Check if we were waiting for animation to complete to either show a
473 // message bubble, or to show a popup. 438 // message bubble, or to show a popup.
474 if (pending_extension_bubble_controller_) { 439 if (pending_extension_bubble_controller_) {
475 MaybeShowExtensionBubble(pending_extension_bubble_controller_.Pass()); 440 MaybeShowExtensionBubble(pending_extension_bubble_controller_.Pass());
476 } else if (!popped_out_closure_.is_null()) { 441 } else if (!popped_out_closure_.is_null()) {
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
545 } 510 }
546 511
547 void ToolbarActionsBar::MaybeShowExtensionBubble( 512 void ToolbarActionsBar::MaybeShowExtensionBubble(
548 scoped_ptr<extensions::ExtensionMessageBubbleController> controller) { 513 scoped_ptr<extensions::ExtensionMessageBubbleController> controller) {
549 controller->HighlightExtensionsIfNecessary(); // Safe to call multiple times. 514 controller->HighlightExtensionsIfNecessary(); // Safe to call multiple times.
550 if (delegate_->IsAnimating()) { 515 if (delegate_->IsAnimating()) {
551 // If the toolbar is animating, we can't effectively anchor the bubble, 516 // If the toolbar is animating, we can't effectively anchor the bubble,
552 // so wait until animation stops. 517 // so wait until animation stops.
553 pending_extension_bubble_controller_ = controller.Pass(); 518 pending_extension_bubble_controller_ = controller.Pass();
554 } else { 519 } else {
555 const extensions::ExtensionIdList& affected_extensions = 520 const std::vector<std::string>& affected_extensions =
556 controller->GetExtensionIdList(); 521 controller->GetExtensionIdList();
557 ToolbarActionViewController* anchor_action = nullptr; 522 ToolbarActionViewController* anchor_action = nullptr;
558 for (const std::string& id : affected_extensions) { 523 for (const std::string& id : affected_extensions) {
559 anchor_action = GetActionForId(id); 524 anchor_action = GetActionForId(id);
560 if (anchor_action) 525 if (anchor_action)
561 break; 526 break;
562 } 527 }
563 delegate_->ShowExtensionMessageBubble(controller.Pass(), anchor_action); 528 delegate_->ShowExtensionMessageBubble(controller.Pass(), anchor_action);
564 } 529 }
565 } 530 }
566 531
567 void ToolbarActionsBar::OnToolbarExtensionAdded( 532 void ToolbarActionsBar::OnToolbarActionAdded(const std::string& action_id,
568 const extensions::Extension* extension, 533 int index) {
569 int index) { 534 DCHECK(GetActionForId(action_id) == nullptr) <<
570 DCHECK(GetActionForId(extension->id()) == nullptr) <<
571 "Asked to add a toolbar action view for an extension that already exists"; 535 "Asked to add a toolbar action view for an extension that already exists";
572 536
537 // TODO(devlin): This is a minor layering violation and the model should pass
538 // in an action directly.
539 const extensions::Extension* extension =
540 extensions::ExtensionRegistry::Get(browser_->profile())->
541 enabled_extensions().GetByID(action_id);
542 // Only extensions should be added after initialization.
543 DCHECK(extension);
544
573 toolbar_actions_.insert( 545 toolbar_actions_.insert(
574 toolbar_actions_.begin() + index, 546 toolbar_actions_.begin() + index,
575 new ExtensionActionViewController( 547 new ExtensionActionViewController(
576 extension, 548 extension,
577 browser_, 549 browser_,
578 extensions::ExtensionActionManager::Get(browser_->profile())-> 550 extensions::ExtensionActionManager::Get(browser_->profile())->
579 GetExtensionAction(*extension), 551 GetExtensionAction(*extension),
580 this)); 552 this));
581 553
582 delegate_->AddViewForAction(toolbar_actions_[index], index); 554 delegate_->AddViewForAction(toolbar_actions_[index], index);
583 555
584 // If we are still initializing the container, don't bother animating. 556 // If we are still initializing the container, don't bother animating.
585 if (!model_->extensions_initialized()) 557 if (!model_->actions_initialized())
586 return; 558 return;
587 559
588 // We may need to resize (e.g. to show the new icon, or the chevron). We don't 560 // We may need to resize (e.g. to show the new icon, or the chevron). We don't
589 // need to check if the extension is upgrading here, because ResizeDelegate() 561 // need to check if the extension is upgrading here, because ResizeDelegate()
590 // checks to see if the container is already the proper size, and because 562 // checks to see if the container is already the proper size, and because
591 // if the action is newly incognito enabled, even though it's a reload, it's 563 // if the action is newly incognito enabled, even though it's a reload, it's
592 // a new extension to this toolbar. 564 // a new extension to this toolbar.
593 // We suppress the chevron during animation because, if we're expanding to 565 // We suppress the chevron during animation because, if we're expanding to
594 // show a new icon, we don't want to have the chevron visible only for the 566 // show a new icon, we don't want to have the chevron visible only for the
595 // duration of the animation. 567 // duration of the animation.
596 ResizeDelegate(gfx::Tween::LINEAR, true); 568 ResizeDelegate(gfx::Tween::LINEAR, true);
597 } 569 }
598 570
599 void ToolbarActionsBar::OnToolbarExtensionRemoved( 571 void ToolbarActionsBar::OnToolbarActionRemoved(const std::string& action_id) {
600 const extensions::Extension* extension) {
601 ToolbarActions::iterator iter = toolbar_actions_.begin(); 572 ToolbarActions::iterator iter = toolbar_actions_.begin();
602 while (iter != toolbar_actions_.end() && (*iter)->GetId() != extension->id()) 573 while (iter != toolbar_actions_.end() && (*iter)->GetId() != action_id)
603 ++iter; 574 ++iter;
604 575
605 if (iter == toolbar_actions_.end()) 576 if (iter == toolbar_actions_.end())
606 return; 577 return;
607 578
608 // The action should outlive the UI element (which is owned by the delegate), 579 // The action should outlive the UI element (which is owned by the delegate),
609 // so we can't delete it just yet. But we should remove it from the list of 580 // so we can't delete it just yet. But we should remove it from the list of
610 // actions so that any width calculations are correct. 581 // actions so that any width calculations are correct.
611 scoped_ptr<ToolbarActionViewController> removed_action(*iter); 582 scoped_ptr<ToolbarActionViewController> removed_action(*iter);
612 toolbar_actions_.weak_erase(iter); 583 toolbar_actions_.weak_erase(iter);
613 delegate_->RemoveViewForAction(removed_action.get()); 584 delegate_->RemoveViewForAction(removed_action.get());
614 removed_action.reset(); 585 removed_action.reset();
615 586
616 // If the extension is being upgraded we don't want the bar to shrink 587 // If the extension is being upgraded we don't want the bar to shrink
617 // because the icon is just going to get re-added to the same location. 588 // because the icon is just going to get re-added to the same location.
618 // There is an exception if this is an off-the-record profile, and the 589 // There is an exception if this is an off-the-record profile, and the
619 // extension is no longer incognito-enabled. 590 // extension is no longer incognito-enabled.
620 if (!extensions::ExtensionSystem::Get(browser_->profile())->runtime_data()-> 591 if (!extensions::ExtensionSystem::Get(browser_->profile())->runtime_data()->
621 IsBeingUpgraded(extension->id()) || 592 IsBeingUpgraded(action_id) ||
622 (browser_->profile()->IsOffTheRecord() && 593 (browser_->profile()->IsOffTheRecord() &&
623 !extensions::util::IsIncognitoEnabled(extension->id(), 594 !extensions::util::IsIncognitoEnabled(action_id,
624 browser_->profile()))) { 595 browser_->profile()))) {
625 if (toolbar_actions_.size() > model_->visible_icon_count()) { 596 if (toolbar_actions_.size() > model_->visible_icon_count()) {
626 // If we have more icons than we can show, then we must not be changing 597 // If we have more icons than we can show, then we must not be changing
627 // the container size (since we either removed an icon from the main 598 // the container size (since we either removed an icon from the main
628 // area and one from the overflow list will have shifted in, or we 599 // area and one from the overflow list will have shifted in, or we
629 // removed an entry directly from the overflow list). 600 // removed an entry directly from the overflow list).
630 delegate_->Redraw(false); 601 delegate_->Redraw(false);
631 } else { 602 } else {
632 delegate_->SetChevronVisibility(false); 603 delegate_->SetChevronVisibility(false);
633 // Either we went from overflow to no-overflow, or we shrunk the no- 604 // Either we went from overflow to no-overflow, or we shrunk the no-
634 // overflow container by 1. Either way the size changed, so animate. 605 // overflow container by 1. Either way the size changed, so animate.
635 ResizeDelegate(gfx::Tween::EASE_OUT, false); 606 ResizeDelegate(gfx::Tween::EASE_OUT, false);
636 } 607 }
637 } 608 }
638 609
639 SetOverflowedActionWantsToRun(); 610 SetOverflowedActionWantsToRun();
640 } 611 }
641 612
642 void ToolbarActionsBar::OnToolbarExtensionMoved( 613 void ToolbarActionsBar::OnToolbarActionMoved(const std::string& action_id,
643 const extensions::Extension* extension, 614 int index) {
644 int index) {
645 DCHECK(index >= 0 && index < static_cast<int>(toolbar_actions_.size())); 615 DCHECK(index >= 0 && index < static_cast<int>(toolbar_actions_.size()));
646 // Unfortunately, |index| doesn't really mean a lot to us, because this 616 // Unfortunately, |index| doesn't really mean a lot to us, because this
647 // window's toolbar could be different (if actions are popped out). Just 617 // window's toolbar could be different (if actions are popped out). Just
648 // do a full reorder. 618 // do a full reorder.
649 ReorderActions(); 619 ReorderActions();
650 } 620 }
651 621
652 void ToolbarActionsBar::OnToolbarExtensionUpdated( 622 void ToolbarActionsBar::OnToolbarActionUpdated(const std::string& action_id) {
653 const extensions::Extension* extension) { 623 ToolbarActionViewController* action = GetActionForId(action_id);
654 ToolbarActionViewController* action = GetActionForId(extension->id());
655 // There might not be a view in cases where we are highlighting or if we 624 // There might not be a view in cases where we are highlighting or if we
656 // haven't fully initialized the actions. 625 // haven't fully initialized the actions.
657 if (action) { 626 if (action) {
658 action->UpdateState(); 627 action->UpdateState();
659 SetOverflowedActionWantsToRun(); 628 SetOverflowedActionWantsToRun();
660 } 629 }
661 } 630 }
662 631
663 bool ToolbarActionsBar::ShowExtensionActionPopup( 632 bool ToolbarActionsBar::ShowToolbarActionPopup(const std::string& action_id,
664 const extensions::Extension* extension, 633 bool grant_active_tab) {
665 bool grant_active_tab) {
666 // Don't override another popup, and only show in the active window. 634 // Don't override another popup, and only show in the active window.
667 if (popup_owner() || !browser_->window()->IsActive()) 635 if (popup_owner() || !browser_->window()->IsActive())
668 return false; 636 return false;
669 637
670 ToolbarActionViewController* action = GetActionForId(extension->id()); 638 ToolbarActionViewController* action = GetActionForId(action_id);
671 return action && action->ExecuteAction(grant_active_tab); 639 return action && action->ExecuteAction(grant_active_tab);
672 } 640 }
673 641
674 void ToolbarActionsBar::OnToolbarVisibleCountChanged() { 642 void ToolbarActionsBar::OnToolbarVisibleCountChanged() {
675 ResizeDelegate(gfx::Tween::EASE_OUT, false); 643 ResizeDelegate(gfx::Tween::EASE_OUT, false);
676 SetOverflowedActionWantsToRun(); 644 SetOverflowedActionWantsToRun();
677 } 645 }
678 646
679 void ToolbarActionsBar::ResizeDelegate(gfx::Tween::Type tween_type, 647 void ToolbarActionsBar::ResizeDelegate(gfx::Tween::Type tween_type,
680 bool suppress_chevron) { 648 bool suppress_chevron) {
681 int desired_width = GetPreferredSize().width(); 649 int desired_width = GetPreferredSize().width();
682 if (desired_width != delegate_->GetWidth()) { 650 if (desired_width != delegate_->GetWidth()) {
683 delegate_->ResizeAndAnimate(tween_type, desired_width, suppress_chevron); 651 delegate_->ResizeAndAnimate(tween_type, desired_width, suppress_chevron);
684 } else if (delegate_->IsAnimating()) { 652 } else if (delegate_->IsAnimating()) {
685 // It's possible that we're right where we're supposed to be in terms of 653 // It's possible that we're right where we're supposed to be in terms of
686 // width, but that we're also currently resizing. If this is the case, end 654 // width, but that we're also currently resizing. If this is the case, end
687 // the current animation with the current width. 655 // the current animation with the current width.
688 delegate_->StopAnimating(); 656 delegate_->StopAnimating();
689 } else { 657 } else {
690 // We may already be at the right size (this can happen frequently with 658 // We may already be at the right size (this can happen frequently with
691 // overflow, where we have a fixed width, and in tests, where we skip 659 // overflow, where we have a fixed width, and in tests, where we skip
692 // animations). If this is the case, we still need to Redraw(), because the 660 // animations). If this is the case, we still need to Redraw(), because the
693 // icons within the toolbar may have changed (e.g. if we removed one 661 // icons within the toolbar may have changed (e.g. if we removed one
694 // action and added a different one in quick succession). 662 // action and added a different one in quick succession).
695 delegate_->Redraw(false); 663 delegate_->Redraw(false);
696 } 664 }
697 } 665 }
698 666
699 void ToolbarActionsBar::OnToolbarHighlightModeChanged(bool is_highlighting) { 667 void ToolbarActionsBar::OnToolbarHighlightModeChanged(bool is_highlighting) {
700 if (!model_->extensions_initialized()) 668 if (!model_->actions_initialized())
701 return; 669 return;
702 // It's a bit of a pain that we delete and recreate everything here, but given 670 // It's a bit of a pain that we delete and recreate everything here, but given
703 // everything else going on (the lack of highlight, [n] more extensions 671 // everything else going on (the lack of highlight, [n] more extensions
704 // appearing, etc), it's not worth the extra complexity to create and insert 672 // appearing, etc), it's not worth the extra complexity to create and insert
705 // only the new actions. 673 // only the new actions.
706 DeleteActions(); 674 DeleteActions();
707 CreateActions(); 675 CreateActions();
708 // Resize the delegate. We suppress the chevron so that we don't risk showing 676 // Resize the delegate. We suppress the chevron so that we don't risk showing
709 // it only for the duration of the animation. 677 // it only for the duration of the animation.
710 ResizeDelegate(gfx::Tween::LINEAR, true); 678 ResizeDelegate(gfx::Tween::LINEAR, true);
(...skipping 15 matching lines...) Expand all
726 Browser* ToolbarActionsBar::GetBrowser() { 694 Browser* ToolbarActionsBar::GetBrowser() {
727 return browser_; 695 return browser_;
728 } 696 }
729 697
730 void ToolbarActionsBar::ReorderActions() { 698 void ToolbarActionsBar::ReorderActions() {
731 if (toolbar_actions_.empty()) 699 if (toolbar_actions_.empty())
732 return; 700 return;
733 701
734 // First, reset the order to that of the model. 702 // First, reset the order to that of the model.
735 auto compare = [](ToolbarActionViewController* const& action, 703 auto compare = [](ToolbarActionViewController* const& action,
736 const scoped_refptr<const extensions::Extension>& ext) { 704 const ToolbarActionsModel::ToolbarItem& item) {
737 return action->GetId() == ext->id(); 705 return action->GetId() == item.id;
738 }; 706 };
739 SortContainer(&toolbar_actions_.get(), model_->toolbar_items(), compare); 707 SortContainer(&toolbar_actions_.get(), model_->toolbar_items(), compare);
740 708
741 // Our visible browser actions may have changed - re-Layout() and check the 709 // Our visible browser actions may have changed - re-Layout() and check the
742 // size (if we aren't suppressing the layout). 710 // size (if we aren't suppressing the layout).
743 if (!suppress_layout_) { 711 if (!suppress_layout_) {
744 ResizeDelegate(gfx::Tween::EASE_OUT, false); 712 ResizeDelegate(gfx::Tween::EASE_OUT, false);
745 delegate_->Redraw(true); 713 delegate_->Redraw(true);
746 } 714 }
747 715
(...skipping 14 matching lines...) Expand all
762 730
763 if (overflowed_action_wants_to_run_ != overflowed_action_wants_to_run) { 731 if (overflowed_action_wants_to_run_ != overflowed_action_wants_to_run) {
764 overflowed_action_wants_to_run_ = overflowed_action_wants_to_run; 732 overflowed_action_wants_to_run_ = overflowed_action_wants_to_run;
765 if (send_overflowed_action_changes_) 733 if (send_overflowed_action_changes_)
766 delegate_->OnOverflowedActionWantsToRunChanged( 734 delegate_->OnOverflowedActionWantsToRunChanged(
767 overflowed_action_wants_to_run_); 735 overflowed_action_wants_to_run_);
768 } 736 }
769 } 737 }
770 738
771 ToolbarActionViewController* ToolbarActionsBar::GetActionForId( 739 ToolbarActionViewController* ToolbarActionsBar::GetActionForId(
772 const std::string& id) { 740 const std::string& action_id) {
773 for (ToolbarActionViewController* action : toolbar_actions_) { 741 for (ToolbarActionViewController* action : toolbar_actions_) {
774 if (action->GetId() == id) 742 if (action->GetId() == action_id)
775 return action; 743 return action;
776 } 744 }
777 return nullptr; 745 return nullptr;
778 } 746 }
779 747
780 content::WebContents* ToolbarActionsBar::GetCurrentWebContents() { 748 content::WebContents* ToolbarActionsBar::GetCurrentWebContents() {
781 return browser_->tab_strip_model()->GetActiveWebContents(); 749 return browser_->tab_strip_model()->GetActiveWebContents();
782 } 750 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698