| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/toolbar/toolbar_actions_bar.h" | 5 #include "chrome/browser/ui/toolbar/toolbar_actions_bar.h" |
| 6 | 6 |
| 7 #include "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/browser/ui/toolbar/toolbar_actions_bar_observer.h" |
| 25 #include "chrome/common/pref_names.h" | 26 #include "chrome/common/pref_names.h" |
| 26 #include "components/crx_file/id_util.h" | 27 #include "components/crx_file/id_util.h" |
| 27 #include "components/pref_registry/pref_registry_syncable.h" | 28 #include "components/pref_registry/pref_registry_syncable.h" |
| 28 #include "extensions/browser/extension_registry.h" | 29 #include "extensions/browser/extension_registry.h" |
| 29 #include "extensions/browser/extension_system.h" | 30 #include "extensions/browser/extension_system.h" |
| 30 #include "extensions/browser/runtime_data.h" | 31 #include "extensions/browser/runtime_data.h" |
| 31 #include "extensions/common/extension.h" | 32 #include "extensions/common/extension.h" |
| 32 #include "extensions/common/feature_switch.h" | 33 #include "extensions/common/feature_switch.h" |
| 33 #include "grit/theme_resources.h" | 34 #include "grit/theme_resources.h" |
| 34 #include "ui/base/resource/resource_bundle.h" | 35 #include "ui/base/resource/resource_bundle.h" |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 weak_ptr_factory_(this) { | 131 weak_ptr_factory_(this) { |
| 131 if (model_) // |model_| can be null in unittests. | 132 if (model_) // |model_| can be null in unittests. |
| 132 model_observer_.Add(model_); | 133 model_observer_.Add(model_); |
| 133 } | 134 } |
| 134 | 135 |
| 135 ToolbarActionsBar::~ToolbarActionsBar() { | 136 ToolbarActionsBar::~ToolbarActionsBar() { |
| 136 // We don't just call DeleteActions() here because it makes assumptions about | 137 // We don't just call DeleteActions() here because it makes assumptions about |
| 137 // the order of deletion between the views and the ToolbarActionsBar. | 138 // the order of deletion between the views and the ToolbarActionsBar. |
| 138 DCHECK(toolbar_actions_.empty()) << | 139 DCHECK(toolbar_actions_.empty()) << |
| 139 "Must call DeleteActions() before destruction."; | 140 "Must call DeleteActions() before destruction."; |
| 141 FOR_EACH_OBSERVER(ToolbarActionsBarObserver, observers_, |
| 142 OnToolbarActionsBarDestroyed()); |
| 140 } | 143 } |
| 141 | 144 |
| 142 // static | 145 // static |
| 143 int ToolbarActionsBar::IconWidth(bool include_padding) { | 146 int ToolbarActionsBar::IconWidth(bool include_padding) { |
| 144 return GetIconDimension(WIDTH) + (include_padding ? kItemSpacing : 0); | 147 return GetIconDimension(WIDTH) + (include_padding ? kItemSpacing : 0); |
| 145 } | 148 } |
| 146 | 149 |
| 147 // static | 150 // static |
| 148 int ToolbarActionsBar::IconHeight() { | 151 int ToolbarActionsBar::IconHeight() { |
| 149 return GetIconDimension(HEIGHT); | 152 return GetIconDimension(HEIGHT); |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 | 448 |
| 446 void ToolbarActionsBar::OnDragStarted() { | 449 void ToolbarActionsBar::OnDragStarted() { |
| 447 // All drag-and-drop commands should go to the main bar. | 450 // All drag-and-drop commands should go to the main bar. |
| 448 ToolbarActionsBar* main_bar = in_overflow_mode() ? main_bar_ : this; | 451 ToolbarActionsBar* main_bar = in_overflow_mode() ? main_bar_ : this; |
| 449 DCHECK(!main_bar->is_drag_in_progress_); | 452 DCHECK(!main_bar->is_drag_in_progress_); |
| 450 main_bar->is_drag_in_progress_ = true; | 453 main_bar->is_drag_in_progress_ = true; |
| 451 } | 454 } |
| 452 | 455 |
| 453 void ToolbarActionsBar::OnDragEnded() { | 456 void ToolbarActionsBar::OnDragEnded() { |
| 454 // All drag-and-drop commands should go to the main bar. | 457 // All drag-and-drop commands should go to the main bar. |
| 455 ToolbarActionsBar* main_bar = in_overflow_mode() ? main_bar_ : this; | 458 if (in_overflow_mode()) { |
| 456 DCHECK(main_bar->is_drag_in_progress_); | 459 main_bar_->OnDragEnded(); |
| 457 main_bar->is_drag_in_progress_ = false; | 460 return; |
| 461 } |
| 462 |
| 463 DCHECK(is_drag_in_progress_); |
| 464 is_drag_in_progress_ = false; |
| 465 FOR_EACH_OBSERVER(ToolbarActionsBarObserver, |
| 466 observers_, OnToolbarActionDragDone()); |
| 458 } | 467 } |
| 459 | 468 |
| 460 void ToolbarActionsBar::OnDragDrop(int dragged_index, | 469 void ToolbarActionsBar::OnDragDrop(int dragged_index, |
| 461 int dropped_index, | 470 int dropped_index, |
| 462 DragType drag_type) { | 471 DragType drag_type) { |
| 463 if (in_overflow_mode()) { | 472 if (in_overflow_mode()) { |
| 464 // All drag-and-drop commands should go to the main bar. | 473 // All drag-and-drop commands should go to the main bar. |
| 465 main_bar_->OnDragDrop(dragged_index, dropped_index, drag_type); | 474 main_bar_->OnDragDrop(dragged_index, dropped_index, drag_type); |
| 466 return; | 475 return; |
| 467 } | 476 } |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 547 popup_owner_->HidePopup(); | 556 popup_owner_->HidePopup(); |
| 548 DCHECK(!popup_owner_); | 557 DCHECK(!popup_owner_); |
| 549 } | 558 } |
| 550 | 559 |
| 551 ToolbarActionViewController* ToolbarActionsBar::GetMainControllerForAction( | 560 ToolbarActionViewController* ToolbarActionsBar::GetMainControllerForAction( |
| 552 ToolbarActionViewController* action) { | 561 ToolbarActionViewController* action) { |
| 553 return in_overflow_mode() ? | 562 return in_overflow_mode() ? |
| 554 main_bar_->GetActionForId(action->GetId()) : action; | 563 main_bar_->GetActionForId(action->GetId()) : action; |
| 555 } | 564 } |
| 556 | 565 |
| 566 void ToolbarActionsBar::AddObserver(ToolbarActionsBarObserver* observer) { |
| 567 observers_.AddObserver(observer); |
| 568 } |
| 569 |
| 570 void ToolbarActionsBar::RemoveObserver(ToolbarActionsBarObserver* observer) { |
| 571 observers_.RemoveObserver(observer); |
| 572 } |
| 573 |
| 557 void ToolbarActionsBar::MaybeShowExtensionBubble( | 574 void ToolbarActionsBar::MaybeShowExtensionBubble( |
| 558 scoped_ptr<extensions::ExtensionMessageBubbleController> controller) { | 575 scoped_ptr<extensions::ExtensionMessageBubbleController> controller) { |
| 559 controller->HighlightExtensionsIfNecessary(); // Safe to call multiple times. | 576 controller->HighlightExtensionsIfNecessary(); // Safe to call multiple times. |
| 560 if (delegate_->IsAnimating()) { | 577 if (delegate_->IsAnimating()) { |
| 561 // If the toolbar is animating, we can't effectively anchor the bubble, | 578 // If the toolbar is animating, we can't effectively anchor the bubble, |
| 562 // so wait until animation stops. | 579 // so wait until animation stops. |
| 563 pending_extension_bubble_controller_ = controller.Pass(); | 580 pending_extension_bubble_controller_ = controller.Pass(); |
| 564 } else if (controller->ShouldShow()) { | 581 } else if (controller->ShouldShow()) { |
| 565 // We check ShouldShow() above because the affected extensions may have been | 582 // We check ShouldShow() above because the affected extensions may have been |
| 566 // removed since the controller was initialized. | 583 // removed since the controller was initialized. |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 690 // the current animation with the current width. | 707 // the current animation with the current width. |
| 691 delegate_->StopAnimating(); | 708 delegate_->StopAnimating(); |
| 692 } else { | 709 } else { |
| 693 // We may already be at the right size (this can happen frequently with | 710 // We may already be at the right size (this can happen frequently with |
| 694 // overflow, where we have a fixed width, and in tests, where we skip | 711 // overflow, where we have a fixed width, and in tests, where we skip |
| 695 // animations). If this is the case, we still need to Redraw(), because the | 712 // animations). If this is the case, we still need to Redraw(), because the |
| 696 // icons within the toolbar may have changed (e.g. if we removed one | 713 // icons within the toolbar may have changed (e.g. if we removed one |
| 697 // action and added a different one in quick succession). | 714 // action and added a different one in quick succession). |
| 698 delegate_->Redraw(false); | 715 delegate_->Redraw(false); |
| 699 } | 716 } |
| 717 |
| 718 FOR_EACH_OBSERVER(ToolbarActionsBarObserver, |
| 719 observers_, OnToolbarActionsBarDidStartResize()); |
| 700 } | 720 } |
| 701 | 721 |
| 702 void ToolbarActionsBar::OnToolbarHighlightModeChanged(bool is_highlighting) { | 722 void ToolbarActionsBar::OnToolbarHighlightModeChanged(bool is_highlighting) { |
| 703 if (!model_->actions_initialized()) | 723 if (!model_->actions_initialized()) |
| 704 return; | 724 return; |
| 705 | 725 |
| 706 { | 726 { |
| 707 base::AutoReset<bool> layout_resetter(&suppress_layout_, true); | 727 base::AutoReset<bool> layout_resetter(&suppress_layout_, true); |
| 708 base::AutoReset<bool> animation_resetter(&suppress_animation_, true); | 728 base::AutoReset<bool> animation_resetter(&suppress_animation_, true); |
| 709 std::set<std::string> seen; | 729 std::set<std::string> seen; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 774 for (ToolbarActionViewController* action : toolbar_actions_) { | 794 for (ToolbarActionViewController* action : toolbar_actions_) { |
| 775 if (action->GetId() == action_id) | 795 if (action->GetId() == action_id) |
| 776 return action; | 796 return action; |
| 777 } | 797 } |
| 778 return nullptr; | 798 return nullptr; |
| 779 } | 799 } |
| 780 | 800 |
| 781 content::WebContents* ToolbarActionsBar::GetCurrentWebContents() { | 801 content::WebContents* ToolbarActionsBar::GetCurrentWebContents() { |
| 782 return browser_->tab_strip_model()->GetActiveWebContents(); | 802 return browser_->tab_strip_model()->GetActiveWebContents(); |
| 783 } | 803 } |
| OLD | NEW |