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

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: Switch GetComponentActionId to unix_hacker_style. 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) << 535 << "Asked to add a toolbar action view for an extension that already "
571 "Asked to add a toolbar action view for an extension that already exists"; 536 "exists";
537
538 // TODO(devlin): This is a minor layering violation and the model should pass
539 // in an action directly.
540 const extensions::Extension* extension =
541 extensions::ExtensionRegistry::Get(browser_->profile())
542 ->enabled_extensions()
543 .GetByID(action_id);
544 // Only extensions should be added after initialization.
545 DCHECK(extension);
572 546
573 toolbar_actions_.insert( 547 toolbar_actions_.insert(
574 toolbar_actions_.begin() + index, 548 toolbar_actions_.begin() + index,
575 new ExtensionActionViewController( 549 new ExtensionActionViewController(
576 extension, 550 extension,
577 browser_, 551 browser_,
578 extensions::ExtensionActionManager::Get(browser_->profile())-> 552 extensions::ExtensionActionManager::Get(browser_->profile())->
579 GetExtensionAction(*extension), 553 GetExtensionAction(*extension),
580 this)); 554 this));
581 555
582 delegate_->AddViewForAction(toolbar_actions_[index], index); 556 delegate_->AddViewForAction(toolbar_actions_[index], index);
583 557
584 // If we are still initializing the container, don't bother animating. 558 // If we are still initializing the container, don't bother animating.
585 if (!model_->extensions_initialized()) 559 if (!model_->actions_initialized())
586 return; 560 return;
587 561
588 // We may need to resize (e.g. to show the new icon, or the chevron). We don't 562 // 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() 563 // 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 564 // 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 565 // if the action is newly incognito enabled, even though it's a reload, it's
592 // a new extension to this toolbar. 566 // a new extension to this toolbar.
593 // We suppress the chevron during animation because, if we're expanding to 567 // 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 568 // show a new icon, we don't want to have the chevron visible only for the
595 // duration of the animation. 569 // duration of the animation.
596 ResizeDelegate(gfx::Tween::LINEAR, true); 570 ResizeDelegate(gfx::Tween::LINEAR, true);
597 } 571 }
598 572
599 void ToolbarActionsBar::OnToolbarExtensionRemoved( 573 void ToolbarActionsBar::OnToolbarActionRemoved(const std::string& action_id) {
600 const extensions::Extension* extension) {
601 ToolbarActions::iterator iter = toolbar_actions_.begin(); 574 ToolbarActions::iterator iter = toolbar_actions_.begin();
602 while (iter != toolbar_actions_.end() && (*iter)->GetId() != extension->id()) 575 while (iter != toolbar_actions_.end() && (*iter)->GetId() != action_id)
603 ++iter; 576 ++iter;
604 577
605 if (iter == toolbar_actions_.end()) 578 if (iter == toolbar_actions_.end())
606 return; 579 return;
607 580
608 // The action should outlive the UI element (which is owned by the delegate), 581 // 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 582 // 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. 583 // actions so that any width calculations are correct.
611 scoped_ptr<ToolbarActionViewController> removed_action(*iter); 584 scoped_ptr<ToolbarActionViewController> removed_action(*iter);
612 toolbar_actions_.weak_erase(iter); 585 toolbar_actions_.weak_erase(iter);
613 delegate_->RemoveViewForAction(removed_action.get()); 586 delegate_->RemoveViewForAction(removed_action.get());
614 removed_action.reset(); 587 removed_action.reset();
615 588
616 // If the extension is being upgraded we don't want the bar to shrink 589 // 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. 590 // 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 591 // There is an exception if this is an off-the-record profile, and the
619 // extension is no longer incognito-enabled. 592 // extension is no longer incognito-enabled.
620 if (!extensions::ExtensionSystem::Get(browser_->profile())->runtime_data()-> 593 if (!extensions::ExtensionSystem::Get(browser_->profile())
621 IsBeingUpgraded(extension->id()) || 594 ->runtime_data()
595 ->IsBeingUpgraded(action_id) ||
622 (browser_->profile()->IsOffTheRecord() && 596 (browser_->profile()->IsOffTheRecord() &&
623 !extensions::util::IsIncognitoEnabled(extension->id(), 597 !extensions::util::IsIncognitoEnabled(action_id, browser_->profile()))) {
624 browser_->profile()))) {
625 if (toolbar_actions_.size() > model_->visible_icon_count()) { 598 if (toolbar_actions_.size() > model_->visible_icon_count()) {
626 // If we have more icons than we can show, then we must not be changing 599 // 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 600 // 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 601 // area and one from the overflow list will have shifted in, or we
629 // removed an entry directly from the overflow list). 602 // removed an entry directly from the overflow list).
630 delegate_->Redraw(false); 603 delegate_->Redraw(false);
631 } else { 604 } else {
632 delegate_->SetChevronVisibility(false); 605 delegate_->SetChevronVisibility(false);
633 // Either we went from overflow to no-overflow, or we shrunk the no- 606 // 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. 607 // overflow container by 1. Either way the size changed, so animate.
635 ResizeDelegate(gfx::Tween::EASE_OUT, false); 608 ResizeDelegate(gfx::Tween::EASE_OUT, false);
636 } 609 }
637 } 610 }
638 611
639 SetOverflowedActionWantsToRun(); 612 SetOverflowedActionWantsToRun();
640 } 613 }
641 614
642 void ToolbarActionsBar::OnToolbarExtensionMoved( 615 void ToolbarActionsBar::OnToolbarActionMoved(const std::string& action_id,
643 const extensions::Extension* extension, 616 int index) {
644 int index) {
645 DCHECK(index >= 0 && index < static_cast<int>(toolbar_actions_.size())); 617 DCHECK(index >= 0 && index < static_cast<int>(toolbar_actions_.size()));
646 // Unfortunately, |index| doesn't really mean a lot to us, because this 618 // 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 619 // window's toolbar could be different (if actions are popped out). Just
648 // do a full reorder. 620 // do a full reorder.
649 ReorderActions(); 621 ReorderActions();
650 } 622 }
651 623
652 void ToolbarActionsBar::OnToolbarExtensionUpdated( 624 void ToolbarActionsBar::OnToolbarActionUpdated(const std::string& action_id) {
653 const extensions::Extension* extension) { 625 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 626 // There might not be a view in cases where we are highlighting or if we
656 // haven't fully initialized the actions. 627 // haven't fully initialized the actions.
657 if (action) { 628 if (action) {
658 action->UpdateState(); 629 action->UpdateState();
659 SetOverflowedActionWantsToRun(); 630 SetOverflowedActionWantsToRun();
660 } 631 }
661 } 632 }
662 633
663 bool ToolbarActionsBar::ShowExtensionActionPopup( 634 bool ToolbarActionsBar::ShowToolbarActionPopup(const std::string& action_id,
664 const extensions::Extension* extension, 635 bool grant_active_tab) {
665 bool grant_active_tab) {
666 // Don't override another popup, and only show in the active window. 636 // Don't override another popup, and only show in the active window.
667 if (popup_owner() || !browser_->window()->IsActive()) 637 if (popup_owner() || !browser_->window()->IsActive())
668 return false; 638 return false;
669 639
670 ToolbarActionViewController* action = GetActionForId(extension->id()); 640 ToolbarActionViewController* action = GetActionForId(action_id);
671 return action && action->ExecuteAction(grant_active_tab); 641 return action && action->ExecuteAction(grant_active_tab);
672 } 642 }
673 643
674 void ToolbarActionsBar::OnToolbarVisibleCountChanged() { 644 void ToolbarActionsBar::OnToolbarVisibleCountChanged() {
675 ResizeDelegate(gfx::Tween::EASE_OUT, false); 645 ResizeDelegate(gfx::Tween::EASE_OUT, false);
676 SetOverflowedActionWantsToRun(); 646 SetOverflowedActionWantsToRun();
677 } 647 }
678 648
679 void ToolbarActionsBar::ResizeDelegate(gfx::Tween::Type tween_type, 649 void ToolbarActionsBar::ResizeDelegate(gfx::Tween::Type tween_type,
680 bool suppress_chevron) { 650 bool suppress_chevron) {
681 int desired_width = GetPreferredSize().width(); 651 int desired_width = GetPreferredSize().width();
682 if (desired_width != delegate_->GetWidth()) { 652 if (desired_width != delegate_->GetWidth()) {
683 delegate_->ResizeAndAnimate(tween_type, desired_width, suppress_chevron); 653 delegate_->ResizeAndAnimate(tween_type, desired_width, suppress_chevron);
684 } else if (delegate_->IsAnimating()) { 654 } else if (delegate_->IsAnimating()) {
685 // It's possible that we're right where we're supposed to be in terms of 655 // 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 656 // width, but that we're also currently resizing. If this is the case, end
687 // the current animation with the current width. 657 // the current animation with the current width.
688 delegate_->StopAnimating(); 658 delegate_->StopAnimating();
689 } else { 659 } else {
690 // We may already be at the right size (this can happen frequently with 660 // 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 661 // 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 662 // 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 663 // icons within the toolbar may have changed (e.g. if we removed one
694 // action and added a different one in quick succession). 664 // action and added a different one in quick succession).
695 delegate_->Redraw(false); 665 delegate_->Redraw(false);
696 } 666 }
697 } 667 }
698 668
699 void ToolbarActionsBar::OnToolbarHighlightModeChanged(bool is_highlighting) { 669 void ToolbarActionsBar::OnToolbarHighlightModeChanged(bool is_highlighting) {
700 if (!model_->extensions_initialized()) 670 if (!model_->actions_initialized())
701 return; 671 return;
702 // It's a bit of a pain that we delete and recreate everything here, but given 672 // 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 673 // 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 674 // appearing, etc), it's not worth the extra complexity to create and insert
705 // only the new actions. 675 // only the new actions.
706 DeleteActions(); 676 DeleteActions();
707 CreateActions(); 677 CreateActions();
708 // Resize the delegate. We suppress the chevron so that we don't risk showing 678 // Resize the delegate. We suppress the chevron so that we don't risk showing
709 // it only for the duration of the animation. 679 // it only for the duration of the animation.
710 ResizeDelegate(gfx::Tween::LINEAR, true); 680 ResizeDelegate(gfx::Tween::LINEAR, true);
(...skipping 15 matching lines...) Expand all
726 Browser* ToolbarActionsBar::GetBrowser() { 696 Browser* ToolbarActionsBar::GetBrowser() {
727 return browser_; 697 return browser_;
728 } 698 }
729 699
730 void ToolbarActionsBar::ReorderActions() { 700 void ToolbarActionsBar::ReorderActions() {
731 if (toolbar_actions_.empty()) 701 if (toolbar_actions_.empty())
732 return; 702 return;
733 703
734 // First, reset the order to that of the model. 704 // First, reset the order to that of the model.
735 auto compare = [](ToolbarActionViewController* const& action, 705 auto compare = [](ToolbarActionViewController* const& action,
736 const scoped_refptr<const extensions::Extension>& ext) { 706 const ToolbarActionsModel::ToolbarItem& item) {
737 return action->GetId() == ext->id(); 707 return action->GetId() == item.id;
738 }; 708 };
739 SortContainer(&toolbar_actions_.get(), model_->toolbar_items(), compare); 709 SortContainer(&toolbar_actions_.get(), model_->toolbar_items(), compare);
740 710
741 // Our visible browser actions may have changed - re-Layout() and check the 711 // Our visible browser actions may have changed - re-Layout() and check the
742 // size (if we aren't suppressing the layout). 712 // size (if we aren't suppressing the layout).
743 if (!suppress_layout_) { 713 if (!suppress_layout_) {
744 ResizeDelegate(gfx::Tween::EASE_OUT, false); 714 ResizeDelegate(gfx::Tween::EASE_OUT, false);
745 delegate_->Redraw(true); 715 delegate_->Redraw(true);
746 } 716 }
747 717
(...skipping 14 matching lines...) Expand all
762 732
763 if (overflowed_action_wants_to_run_ != overflowed_action_wants_to_run) { 733 if (overflowed_action_wants_to_run_ != overflowed_action_wants_to_run) {
764 overflowed_action_wants_to_run_ = overflowed_action_wants_to_run; 734 overflowed_action_wants_to_run_ = overflowed_action_wants_to_run;
765 if (send_overflowed_action_changes_) 735 if (send_overflowed_action_changes_)
766 delegate_->OnOverflowedActionWantsToRunChanged( 736 delegate_->OnOverflowedActionWantsToRunChanged(
767 overflowed_action_wants_to_run_); 737 overflowed_action_wants_to_run_);
768 } 738 }
769 } 739 }
770 740
771 ToolbarActionViewController* ToolbarActionsBar::GetActionForId( 741 ToolbarActionViewController* ToolbarActionsBar::GetActionForId(
772 const std::string& id) { 742 const std::string& action_id) {
773 for (ToolbarActionViewController* action : toolbar_actions_) { 743 for (ToolbarActionViewController* action : toolbar_actions_) {
774 if (action->GetId() == id) 744 if (action->GetId() == action_id)
775 return action; 745 return action;
776 } 746 }
777 return nullptr; 747 return nullptr;
778 } 748 }
779 749
780 content::WebContents* ToolbarActionsBar::GetCurrentWebContents() { 750 content::WebContents* ToolbarActionsBar::GetCurrentWebContents() {
781 return browser_->tab_strip_model()->GetActiveWebContents(); 751 return browser_->tab_strip_model()->GetActiveWebContents();
782 } 752 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/toolbar/toolbar_actions_bar.h ('k') | chrome/browser/ui/toolbar/toolbar_actions_bar_unittest.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698