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

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),
126 component_ids_(ComponentToolbarActionsFactory::GetComponentIds()),
Devlin 2015/08/03 20:58:30 I don't think the ToolbarActionsBar should need kn
apacible 2015/08/04 22:15:58 Done.
125 popup_owner_(nullptr), 127 popup_owner_(nullptr),
126 model_observer_(this), 128 model_observer_(this),
127 suppress_layout_(false), 129 suppress_layout_(false),
128 suppress_animation_(true), 130 suppress_animation_(true),
129 overflowed_action_wants_to_run_(false), 131 overflowed_action_wants_to_run_(false),
130 checked_extension_bubble_(false), 132 checked_extension_bubble_(false),
131 popped_out_action_(nullptr), 133 popped_out_action_(nullptr),
132 weak_ptr_factory_(this) { 134 weak_ptr_factory_(this) {
133 if (model_) // |model_| can be null in unittests. 135 if (model_) // |model_| can be null in unittests.
134 model_observer_.Add(model_); 136 model_observer_.Add(model_);
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 // want to "slide" the action back in. 253 // want to "slide" the action back in.
252 size_t visible_icons = in_overflow_mode() ? 254 size_t visible_icons = in_overflow_mode() ?
253 toolbar_actions_.size() - model_->visible_icon_count() : 255 toolbar_actions_.size() - model_->visible_icon_count() :
254 model_->visible_icon_count() + pop_out_modifier; 256 model_->visible_icon_count() + pop_out_modifier;
255 257
256 #if DCHECK_IS_ON() 258 #if DCHECK_IS_ON()
257 // Good time for some sanity checks: We should never try to display more 259 // 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. 260 // 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.) 261 // (The only exception is if this is in initialization.)
260 if (!toolbar_actions_.empty() && !suppress_layout_ && 262 if (!toolbar_actions_.empty() && !suppress_layout_ &&
261 model_->extensions_initialized()) { 263 model_->actions_initialized()) {
262 size_t num_extension_actions = 0u; 264 size_t num_extension_actions = 0u;
263 for (ToolbarActionViewController* action : toolbar_actions_) { 265 for (ToolbarActionViewController* action : toolbar_actions_) {
264 // No component action should ever have a valid extension id, so we can 266 // No component action should ever have a valid extension id, so we can
265 // use this to check the extension amount. 267 // use this to check the extension amount.
266 if (crx_file::id_util::IdIsValid(action->GetId())) 268 if (crx_file::id_util::IdIsValid(action->GetId()))
267 ++num_extension_actions; 269 ++num_extension_actions;
268 } 270 }
269 271
270 int num_component_actions = 272 int num_component_actions =
271 ComponentToolbarActionsFactory::GetInstance()-> 273 ComponentToolbarActionsFactory::GetInstance()->
272 GetNumComponentActions(browser_); 274 GetNumComponentActions(browser_);
273 size_t num_total_actions = num_extension_actions + num_component_actions; 275 size_t num_total_actions = num_extension_actions + num_component_actions;
274 276
275 DCHECK_LE(visible_icons, num_total_actions); 277 DCHECK_LE(visible_icons, num_total_actions);
276 DCHECK_EQ(model_->toolbar_items().size(), num_extension_actions); 278 DCHECK_EQ(model_->toolbar_items().size(), num_total_actions);
277 } 279 }
278 #endif 280 #endif
279 281
280 return visible_icons; 282 return visible_icons;
281 } 283 }
282 284
283 std::vector<ToolbarActionViewController*> 285 std::vector<ToolbarActionViewController*>
284 ToolbarActionsBar::GetActions() const { 286 ToolbarActionsBar::GetActions() const {
285 std::vector<ToolbarActionViewController*> actions = toolbar_actions_.get(); 287 std::vector<ToolbarActionViewController*> actions = toolbar_actions_.get();
286 288
(...skipping 13 matching lines...) Expand all
300 } 302 }
301 } 303 }
302 304
303 return actions; 305 return actions;
304 } 306 }
305 307
306 void ToolbarActionsBar::CreateActions() { 308 void ToolbarActionsBar::CreateActions() {
307 DCHECK(toolbar_actions_.empty()); 309 DCHECK(toolbar_actions_.empty());
308 // We wait for the extension system to be initialized before we add any 310 // We wait for the extension system to be initialized before we add any
309 // actions, as they rely on the extension system to function. 311 // actions, as they rely on the extension system to function.
310 if (!model_ || !model_->extensions_initialized()) 312 if (!model_ || !model_->actions_initialized())
311 return; 313 return;
312 314
313 { 315 {
314 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/463337 316 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/463337
315 // is fixed. 317 // is fixed.
316 tracked_objects::ScopedTracker tracking_profile1( 318 tracked_objects::ScopedTracker tracking_profile1(
317 FROM_HERE_WITH_EXPLICIT_FUNCTION("ToolbarActionsBar::CreateActions1")); 319 FROM_HERE_WITH_EXPLICIT_FUNCTION("ToolbarActionsBar::CreateActions1"));
318 // We don't redraw the view while creating actions. 320 // We don't redraw the view while creating actions.
319 base::AutoReset<bool> layout_resetter(&suppress_layout_, true); 321 base::AutoReset<bool> layout_resetter(&suppress_layout_, true);
320 322
321 // Extension actions come first. 323 // Get the toolbar actions.
322 extensions::ExtensionActionManager* action_manager = 324 toolbar_actions_ = model_->GetActions(browser_, this);
323 extensions::ExtensionActionManager::Get(browser_->profile());
324 const extensions::ExtensionList& toolbar_items = model_->toolbar_items();
325 for (const scoped_refptr<const extensions::Extension>& extension :
326 toolbar_items) {
327 toolbar_actions_.push_back(new ExtensionActionViewController(
328 extension.get(),
329 browser_,
330 action_manager->GetExtensionAction(*extension),
331 this));
332 }
333 325
334 // Component actions come second, and are suppressed if the extension
335 // actions are being highlighted.
336 if (!model_->is_highlighting()) { 326 if (!model_->is_highlighting()) {
337 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/463337 327 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/463337
338 // is fixed. 328 // is fixed.
339 tracked_objects::ScopedTracker tracking_profile2( 329 tracked_objects::ScopedTracker tracking_profile2(
340 FROM_HERE_WITH_EXPLICIT_FUNCTION( 330 FROM_HERE_WITH_EXPLICIT_FUNCTION(
341 "ToolbarActionsBar::CreateActions2")); 331 "ToolbarActionsBar::CreateActions2"));
342
343 ScopedVector<ToolbarActionViewController> component_actions =
344 ComponentToolbarActionsFactory::GetInstance()->
345 GetComponentToolbarActions(browser_);
346 DCHECK(component_actions.empty() ||
347 extensions::FeatureSwitch::extension_action_redesign()->IsEnabled());
348 toolbar_actions_.insert(toolbar_actions_.end(),
349 component_actions.begin(),
350 component_actions.end());
351 component_actions.weak_clear();
352 } 332 }
353 333
354 if (!toolbar_actions_.empty()) { 334 if (!toolbar_actions_.empty()) {
355 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/463337 335 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/463337
356 // is fixed. 336 // is fixed.
357 tracked_objects::ScopedTracker tracking_profile3( 337 tracked_objects::ScopedTracker tracking_profile3(
358 FROM_HERE_WITH_EXPLICIT_FUNCTION( 338 FROM_HERE_WITH_EXPLICIT_FUNCTION(
359 "ToolbarActionsBar::CreateActions3")); 339 "ToolbarActionsBar::CreateActions3"));
360 ReorderActions(); 340 ReorderActions();
361 } 341 }
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 if (in_overflow_mode()) { 411 if (in_overflow_mode()) {
432 main_bar_->OnDragDrop(dragged_index, dropped_index, drag_type); 412 main_bar_->OnDragDrop(dragged_index, dropped_index, drag_type);
433 return; 413 return;
434 } 414 }
435 415
436 int delta = 0; 416 int delta = 0;
437 if (drag_type == DRAG_TO_OVERFLOW) 417 if (drag_type == DRAG_TO_OVERFLOW)
438 delta = -1; 418 delta = -1;
439 else if (drag_type == DRAG_TO_MAIN) 419 else if (drag_type == DRAG_TO_MAIN)
440 delta = 1; 420 delta = 1;
441 model_->MoveExtensionIcon(toolbar_actions_[dragged_index]->GetId(), 421 model_->MoveActionIcon(toolbar_actions_[dragged_index]->GetId(),
442 dropped_index); 422 dropped_index);
443 if (delta) 423 if (delta)
444 model_->SetVisibleIconCount(model_->visible_icon_count() + delta); 424 model_->SetVisibleIconCount(model_->visible_icon_count() + delta);
445 } 425 }
446 426
447 void ToolbarActionsBar::OnAnimationEnded() { 427 void ToolbarActionsBar::OnAnimationEnded() {
448 // Check if we were waiting for animation to complete to either show a 428 // Check if we were waiting for animation to complete to either show a
449 // message bubble, or to show a popup. 429 // message bubble, or to show a popup.
450 if (pending_extension_bubble_controller_) { 430 if (pending_extension_bubble_controller_) {
451 MaybeShowExtensionBubble(pending_extension_bubble_controller_.Pass()); 431 MaybeShowExtensionBubble(pending_extension_bubble_controller_.Pass());
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 } 496 }
517 497
518 void ToolbarActionsBar::MaybeShowExtensionBubble( 498 void ToolbarActionsBar::MaybeShowExtensionBubble(
519 scoped_ptr<extensions::ExtensionMessageBubbleController> controller) { 499 scoped_ptr<extensions::ExtensionMessageBubbleController> controller) {
520 controller->HighlightExtensionsIfNecessary(); // Safe to call multiple times. 500 controller->HighlightExtensionsIfNecessary(); // Safe to call multiple times.
521 if (delegate_->IsAnimating()) { 501 if (delegate_->IsAnimating()) {
522 // If the toolbar is animating, we can't effectively anchor the bubble, 502 // If the toolbar is animating, we can't effectively anchor the bubble,
523 // so wait until animation stops. 503 // so wait until animation stops.
524 pending_extension_bubble_controller_ = controller.Pass(); 504 pending_extension_bubble_controller_ = controller.Pass();
525 } else { 505 } else {
526 const extensions::ExtensionIdList& affected_extensions = 506 const ActionIdList& affected_extensions = controller->GetExtensionIdList();
527 controller->GetExtensionIdList();
528 ToolbarActionViewController* anchor_action = nullptr; 507 ToolbarActionViewController* anchor_action = nullptr;
529 for (const std::string& id : affected_extensions) { 508 for (const std::string& id : affected_extensions) {
530 anchor_action = GetActionForId(id); 509 anchor_action = GetActionForId(id);
531 if (anchor_action) 510 if (anchor_action)
532 break; 511 break;
533 } 512 }
534 delegate_->ShowExtensionMessageBubble(controller.Pass(), anchor_action); 513 delegate_->ShowExtensionMessageBubble(controller.Pass(), anchor_action);
535 } 514 }
536 } 515 }
537 516
538 void ToolbarActionsBar::OnToolbarExtensionAdded( 517 void ToolbarActionsBar::OnToolbarActionAdded(const std::string& action_id,
539 const extensions::Extension* extension, 518 int index) {
540 int index) { 519 DCHECK(GetActionForId(action_id) == nullptr) <<
541 DCHECK(GetActionForId(extension->id()) == nullptr) <<
542 "Asked to add a toolbar action view for an extension that already exists"; 520 "Asked to add a toolbar action view for an extension that already exists";
543 521
522 // Check that |action_id| is not a component action since
523 // OnToolbarActionAdded is only called after the toolbar model has been
524 // initialized.
525 if (std::find(component_ids_.begin(), component_ids_.end(), action_id) !=
526 component_ids_.end())
527 return;
528
529 const extensions::Extension* extension =
530 extensions::ExtensionRegistry::Get(browser_->profile())->
531 enabled_extensions().GetByID(action_id);
532
544 toolbar_actions_.insert( 533 toolbar_actions_.insert(
545 toolbar_actions_.begin() + index, 534 toolbar_actions_.begin() + index,
546 new ExtensionActionViewController( 535 new ExtensionActionViewController(
547 extension, 536 extension,
548 browser_, 537 browser_,
549 extensions::ExtensionActionManager::Get(browser_->profile())-> 538 extensions::ExtensionActionManager::Get(browser_->profile())->
550 GetExtensionAction(*extension), 539 GetExtensionAction(*extension),
551 this)); 540 this));
552 541
553 delegate_->AddViewForAction(toolbar_actions_[index], index); 542 delegate_->AddViewForAction(toolbar_actions_[index], index);
554 543
555 // If we are still initializing the container, don't bother animating. 544 // If we are still initializing the container, don't bother animating.
556 if (!model_->extensions_initialized()) 545 if (!model_->actions_initialized())
557 return; 546 return;
558 547
559 // We may need to resize (e.g. to show the new icon, or the chevron). We don't 548 // We may need to resize (e.g. to show the new icon, or the chevron). We don't
560 // need to check if the extension is upgrading here, because ResizeDelegate() 549 // need to check if the extension is upgrading here, because ResizeDelegate()
561 // checks to see if the container is already the proper size, and because 550 // checks to see if the container is already the proper size, and because
562 // if the action is newly incognito enabled, even though it's a reload, it's 551 // if the action is newly incognito enabled, even though it's a reload, it's
563 // a new extension to this toolbar. 552 // a new extension to this toolbar.
564 // We suppress the chevron during animation because, if we're expanding to 553 // We suppress the chevron during animation because, if we're expanding to
565 // show a new icon, we don't want to have the chevron visible only for the 554 // show a new icon, we don't want to have the chevron visible only for the
566 // duration of the animation. 555 // duration of the animation.
567 ResizeDelegate(gfx::Tween::LINEAR, true); 556 ResizeDelegate(gfx::Tween::LINEAR, true);
568 } 557 }
569 558
570 void ToolbarActionsBar::OnToolbarExtensionRemoved( 559 void ToolbarActionsBar::OnToolbarActionRemoved(const std::string& action_id) {
571 const extensions::Extension* extension) {
572 ToolbarActions::iterator iter = toolbar_actions_.begin(); 560 ToolbarActions::iterator iter = toolbar_actions_.begin();
573 while (iter != toolbar_actions_.end() && (*iter)->GetId() != extension->id()) 561 while (iter != toolbar_actions_.end() && (*iter)->GetId() != action_id)
574 ++iter; 562 ++iter;
575 563
576 if (iter == toolbar_actions_.end()) 564 if (iter == toolbar_actions_.end())
577 return; 565 return;
578 566
567 // Component actions cannot be removed.
568 if (std::find(component_ids_.begin(), component_ids_.end(), action_id) !=
569 component_ids_.end())
570 return;
571
579 // The action should outlive the UI element (which is owned by the delegate), 572 // The action should outlive the UI element (which is owned by the delegate),
580 // so we can't delete it just yet. But we should remove it from the list of 573 // so we can't delete it just yet. But we should remove it from the list of
581 // actions so that any width calculations are correct. 574 // actions so that any width calculations are correct.
582 scoped_ptr<ToolbarActionViewController> removed_action(*iter); 575 scoped_ptr<ToolbarActionViewController> removed_action(*iter);
583 toolbar_actions_.weak_erase(iter); 576 toolbar_actions_.weak_erase(iter);
584 delegate_->RemoveViewForAction(removed_action.get()); 577 delegate_->RemoveViewForAction(removed_action.get());
585 removed_action.reset(); 578 removed_action.reset();
586 579
587 // If the extension is being upgraded we don't want the bar to shrink 580 // If the extension is being upgraded we don't want the bar to shrink
588 // because the icon is just going to get re-added to the same location. 581 // because the icon is just going to get re-added to the same location.
589 // There is an exception if this is an off-the-record profile, and the 582 // There is an exception if this is an off-the-record profile, and the
590 // extension is no longer incognito-enabled. 583 // extension is no longer incognito-enabled.
591 if (!extensions::ExtensionSystem::Get(browser_->profile())->runtime_data()-> 584 if (!extensions::ExtensionSystem::Get(browser_->profile())->runtime_data()->
592 IsBeingUpgraded(extension->id()) || 585 IsBeingUpgraded(action_id) ||
593 (browser_->profile()->IsOffTheRecord() && 586 (browser_->profile()->IsOffTheRecord() &&
594 !extensions::util::IsIncognitoEnabled(extension->id(), 587 !extensions::util::IsIncognitoEnabled(action_id,
595 browser_->profile()))) { 588 browser_->profile()))) {
596 if (toolbar_actions_.size() > model_->visible_icon_count()) { 589 if (toolbar_actions_.size() > model_->visible_icon_count()) {
597 // If we have more icons than we can show, then we must not be changing 590 // If we have more icons than we can show, then we must not be changing
598 // the container size (since we either removed an icon from the main 591 // the container size (since we either removed an icon from the main
599 // area and one from the overflow list will have shifted in, or we 592 // area and one from the overflow list will have shifted in, or we
600 // removed an entry directly from the overflow list). 593 // removed an entry directly from the overflow list).
601 delegate_->Redraw(false); 594 delegate_->Redraw(false);
602 } else { 595 } else {
603 delegate_->SetChevronVisibility(false); 596 delegate_->SetChevronVisibility(false);
604 // Either we went from overflow to no-overflow, or we shrunk the no- 597 // Either we went from overflow to no-overflow, or we shrunk the no-
605 // overflow container by 1. Either way the size changed, so animate. 598 // overflow container by 1. Either way the size changed, so animate.
606 ResizeDelegate(gfx::Tween::EASE_OUT, false); 599 ResizeDelegate(gfx::Tween::EASE_OUT, false);
607 } 600 }
608 } 601 }
609 602
610 SetOverflowedActionWantsToRun(); 603 SetOverflowedActionWantsToRun();
611 } 604 }
612 605
613 void ToolbarActionsBar::OnToolbarExtensionMoved( 606 void ToolbarActionsBar::OnToolbarActionMoved(const std::string& action_id,
614 const extensions::Extension* extension, 607 int index) {
615 int index) {
616 DCHECK(index >= 0 && index < static_cast<int>(toolbar_actions_.size())); 608 DCHECK(index >= 0 && index < static_cast<int>(toolbar_actions_.size()));
617 // Unfortunately, |index| doesn't really mean a lot to us, because this 609 // Unfortunately, |index| doesn't really mean a lot to us, because this
618 // window's toolbar could be different (if actions are popped out). Just 610 // window's toolbar could be different (if actions are popped out). Just
619 // do a full reorder. 611 // do a full reorder.
620 ReorderActions(); 612 ReorderActions();
621 } 613 }
622 614
623 void ToolbarActionsBar::OnToolbarExtensionUpdated( 615 void ToolbarActionsBar::OnToolbarActionUpdated(const std::string& action_id) {
624 const extensions::Extension* extension) { 616 ToolbarActionViewController* action = GetActionForId(action_id);
625 ToolbarActionViewController* action = GetActionForId(extension->id());
626 // There might not be a view in cases where we are highlighting or if we 617 // There might not be a view in cases where we are highlighting or if we
627 // haven't fully initialized the actions. 618 // haven't fully initialized the actions.
628 if (action) { 619 if (action) {
629 action->UpdateState(); 620 action->UpdateState();
630 SetOverflowedActionWantsToRun(); 621 SetOverflowedActionWantsToRun();
631 } 622 }
632 } 623 }
633 624
634 bool ToolbarActionsBar::ShowExtensionActionPopup( 625 bool ToolbarActionsBar::ShowToolbarActionPopup(const std::string& action_id,
635 const extensions::Extension* extension, 626 bool grant_active_tab) {
636 bool grant_active_tab) {
637 // Don't override another popup, and only show in the active window. 627 // Don't override another popup, and only show in the active window.
638 if (popup_owner() || !browser_->window()->IsActive()) 628 if (popup_owner() || !browser_->window()->IsActive())
639 return false; 629 return false;
640 630
641 ToolbarActionViewController* action = GetActionForId(extension->id()); 631 ToolbarActionViewController* action = GetActionForId(action_id);
642 return action && action->ExecuteAction(grant_active_tab); 632 return action && action->ExecuteAction(grant_active_tab);
643 } 633 }
644 634
645 void ToolbarActionsBar::OnToolbarVisibleCountChanged() { 635 void ToolbarActionsBar::OnToolbarVisibleCountChanged() {
646 ResizeDelegate(gfx::Tween::EASE_OUT, false); 636 ResizeDelegate(gfx::Tween::EASE_OUT, false);
647 SetOverflowedActionWantsToRun(); 637 SetOverflowedActionWantsToRun();
648 } 638 }
649 639
650 void ToolbarActionsBar::ResizeDelegate(gfx::Tween::Type tween_type, 640 void ToolbarActionsBar::ResizeDelegate(gfx::Tween::Type tween_type,
651 bool suppress_chevron) { 641 bool suppress_chevron) {
652 int desired_width = GetPreferredSize().width(); 642 int desired_width = GetPreferredSize().width();
653 if (desired_width != delegate_->GetWidth()) { 643 if (desired_width != delegate_->GetWidth()) {
654 delegate_->ResizeAndAnimate(tween_type, desired_width, suppress_chevron); 644 delegate_->ResizeAndAnimate(tween_type, desired_width, suppress_chevron);
655 } else if (delegate_->IsAnimating()) { 645 } else if (delegate_->IsAnimating()) {
656 // It's possible that we're right where we're supposed to be in terms of 646 // It's possible that we're right where we're supposed to be in terms of
657 // width, but that we're also currently resizing. If this is the case, end 647 // width, but that we're also currently resizing. If this is the case, end
658 // the current animation with the current width. 648 // the current animation with the current width.
659 delegate_->StopAnimating(); 649 delegate_->StopAnimating();
660 } else { 650 } else {
661 // We may already be at the right size (this can happen frequently with 651 // We may already be at the right size (this can happen frequently with
662 // overflow, where we have a fixed width, and in tests, where we skip 652 // overflow, where we have a fixed width, and in tests, where we skip
663 // animations). If this is the case, we still need to Redraw(), because the 653 // animations). If this is the case, we still need to Redraw(), because the
664 // icons within the toolbar may have changed (e.g. if we removed one 654 // icons within the toolbar may have changed (e.g. if we removed one
665 // action and added a different one in quick succession). 655 // action and added a different one in quick succession).
666 delegate_->Redraw(false); 656 delegate_->Redraw(false);
667 } 657 }
668 } 658 }
669 659
670 void ToolbarActionsBar::OnToolbarHighlightModeChanged(bool is_highlighting) { 660 void ToolbarActionsBar::OnToolbarHighlightModeChanged(bool is_highlighting) {
671 if (!model_->extensions_initialized()) 661 if (!model_->actions_initialized())
672 return; 662 return;
673 // It's a bit of a pain that we delete and recreate everything here, but given 663 // It's a bit of a pain that we delete and recreate everything here, but given
674 // everything else going on (the lack of highlight, [n] more extensions 664 // everything else going on (the lack of highlight, [n] more extensions
675 // appearing, etc), it's not worth the extra complexity to create and insert 665 // appearing, etc), it's not worth the extra complexity to create and insert
676 // only the new actions. 666 // only the new actions.
677 DeleteActions(); 667 DeleteActions();
678 CreateActions(); 668 CreateActions();
679 // Resize the delegate. We suppress the chevron so that we don't risk showing 669 // Resize the delegate. We suppress the chevron so that we don't risk showing
680 // it only for the duration of the animation. 670 // it only for the duration of the animation.
681 ResizeDelegate(gfx::Tween::LINEAR, true); 671 ResizeDelegate(gfx::Tween::LINEAR, true);
(...skipping 15 matching lines...) Expand all
697 Browser* ToolbarActionsBar::GetBrowser() { 687 Browser* ToolbarActionsBar::GetBrowser() {
698 return browser_; 688 return browser_;
699 } 689 }
700 690
701 void ToolbarActionsBar::ReorderActions() { 691 void ToolbarActionsBar::ReorderActions() {
702 if (toolbar_actions_.empty()) 692 if (toolbar_actions_.empty())
703 return; 693 return;
704 694
705 // First, reset the order to that of the model. 695 // First, reset the order to that of the model.
706 auto compare = [](ToolbarActionViewController* const& action, 696 auto compare = [](ToolbarActionViewController* const& action,
707 const scoped_refptr<const extensions::Extension>& ext) { 697 const std::string ext) {
708 return action->GetId() == ext->id(); 698 return action->GetId() == ext;
709 }; 699 };
710 SortContainer(&toolbar_actions_.get(), model_->toolbar_items(), compare); 700 SortContainer(&toolbar_actions_.get(), model_->toolbar_items(), compare);
711 701
712 // Our visible browser actions may have changed - re-Layout() and check the 702 // Our visible browser actions may have changed - re-Layout() and check the
713 // size (if we aren't suppressing the layout). 703 // size (if we aren't suppressing the layout).
714 if (!suppress_layout_) { 704 if (!suppress_layout_) {
715 ResizeDelegate(gfx::Tween::EASE_OUT, false); 705 ResizeDelegate(gfx::Tween::EASE_OUT, false);
716 delegate_->Redraw(true); 706 delegate_->Redraw(true);
717 } 707 }
718 708
(...skipping 14 matching lines...) Expand all
733 723
734 if (overflowed_action_wants_to_run_ != overflowed_action_wants_to_run) { 724 if (overflowed_action_wants_to_run_ != overflowed_action_wants_to_run) {
735 overflowed_action_wants_to_run_ = overflowed_action_wants_to_run; 725 overflowed_action_wants_to_run_ = overflowed_action_wants_to_run;
736 if (send_overflowed_action_changes_) 726 if (send_overflowed_action_changes_)
737 delegate_->OnOverflowedActionWantsToRunChanged( 727 delegate_->OnOverflowedActionWantsToRunChanged(
738 overflowed_action_wants_to_run_); 728 overflowed_action_wants_to_run_);
739 } 729 }
740 } 730 }
741 731
742 ToolbarActionViewController* ToolbarActionsBar::GetActionForId( 732 ToolbarActionViewController* ToolbarActionsBar::GetActionForId(
743 const std::string& id) { 733 const std::string& action_id) {
744 for (ToolbarActionViewController* action : toolbar_actions_) { 734 for (ToolbarActionViewController* action : toolbar_actions_) {
745 if (action->GetId() == id) 735 if (action->GetId() == action_id)
746 return action; 736 return action;
747 } 737 }
748 return nullptr; 738 return nullptr;
749 } 739 }
750 740
751 content::WebContents* ToolbarActionsBar::GetCurrentWebContents() { 741 content::WebContents* ToolbarActionsBar::GetCurrentWebContents() {
752 return browser_->tab_strip_model()->GetActiveWebContents(); 742 return browser_->tab_strip_model()->GetActiveWebContents();
753 } 743 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698