| 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 <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| 11 #include "base/profiler/scoped_tracker.h" | 11 #include "base/profiler/scoped_tracker.h" |
| 12 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
| 13 #include "base/thread_task_runner_handle.h" | 13 #include "base/thread_task_runner_handle.h" |
| 14 #include "base/time/time.h" |
| 14 #include "chrome/browser/extensions/extension_message_bubble_controller.h" | 15 #include "chrome/browser/extensions/extension_message_bubble_controller.h" |
| 15 #include "chrome/browser/extensions/extension_util.h" | 16 #include "chrome/browser/extensions/extension_util.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/browser/sessions/session_tab_helper.h" | 18 #include "chrome/browser/sessions/session_tab_helper.h" |
| 18 #include "chrome/browser/ui/browser.h" | 19 #include "chrome/browser/ui/browser.h" |
| 19 #include "chrome/browser/ui/browser_window.h" | 20 #include "chrome/browser/ui/browser_window.h" |
| 20 #include "chrome/browser/ui/extensions/extension_action_view_controller.h" | 21 #include "chrome/browser/ui/extensions/extension_action_view_controller.h" |
| 21 #include "chrome/browser/ui/extensions/extension_message_bubble_bridge.h" | 22 #include "chrome/browser/ui/extensions/extension_message_bubble_bridge.h" |
| 22 #include "chrome/browser/ui/extensions/extension_message_bubble_factory.h" | 23 #include "chrome/browser/ui/extensions/extension_message_bubble_factory.h" |
| 23 #include "chrome/browser/ui/layout_constants.h" | 24 #include "chrome/browser/ui/layout_constants.h" |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 while (!equal(to_sort->at(j), reference[i])) { | 92 while (!equal(to_sort->at(j), reference[i])) { |
| 92 ++j; | 93 ++j; |
| 93 DCHECK_LT(j, to_sort->size()) << | 94 DCHECK_LT(j, to_sort->size()) << |
| 94 "Item in |reference| not found in |to_sort|."; | 95 "Item in |reference| not found in |to_sort|."; |
| 95 } | 96 } |
| 96 std::swap(to_sort->at(i), to_sort->at(j)); | 97 std::swap(to_sort->at(i), to_sort->at(j)); |
| 97 } | 98 } |
| 98 } | 99 } |
| 99 } | 100 } |
| 100 | 101 |
| 102 // How long to wait until showing an extension message bubble. |
| 103 int g_extension_bubble_appearance_wait_time_in_seconds = 5; |
| 104 |
| 101 } // namespace | 105 } // namespace |
| 102 | 106 |
| 103 // static | 107 // static |
| 104 bool ToolbarActionsBar::disable_animations_for_testing_ = false; | 108 bool ToolbarActionsBar::disable_animations_for_testing_ = false; |
| 105 | 109 |
| 106 ToolbarActionsBar::PlatformSettings::PlatformSettings() | 110 ToolbarActionsBar::PlatformSettings::PlatformSettings() |
| 107 : item_spacing(GetLayoutConstant(TOOLBAR_STANDARD_SPACING)), | 111 : item_spacing(GetLayoutConstant(TOOLBAR_STANDARD_SPACING)), |
| 108 icons_per_overflow_menu_row(1), | 112 icons_per_overflow_menu_row(1), |
| 109 chevron_enabled(!extensions::FeatureSwitch::extension_action_redesign()-> | 113 chevron_enabled(!extensions::FeatureSwitch::extension_action_redesign()-> |
| 110 IsEnabled()) { | 114 IsEnabled()) { |
| (...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 599 delegate_->ShowToolbarActionBubble(std::move(bubble)); | 603 delegate_->ShowToolbarActionBubble(std::move(bubble)); |
| 600 } | 604 } |
| 601 } | 605 } |
| 602 | 606 |
| 603 void ToolbarActionsBar::MaybeShowExtensionBubble( | 607 void ToolbarActionsBar::MaybeShowExtensionBubble( |
| 604 std::unique_ptr<extensions::ExtensionMessageBubbleController> controller) { | 608 std::unique_ptr<extensions::ExtensionMessageBubbleController> controller) { |
| 605 if (!controller->ShouldShow()) | 609 if (!controller->ShouldShow()) |
| 606 return; | 610 return; |
| 607 | 611 |
| 608 controller->HighlightExtensionsIfNecessary(); // Safe to call multiple times. | 612 controller->HighlightExtensionsIfNecessary(); // Safe to call multiple times. |
| 609 ShowToolbarActionBubble(scoped_ptr<ToolbarActionsBarBubbleDelegate>( | 613 |
| 610 new ExtensionMessageBubbleBridge(std::move(controller)))); | 614 // Not showing the bubble right away (during startup) has a few benefits: |
| 615 // We don't have to worry about focus being lost due to the Omnibox (or to |
| 616 // other things that want focus at startup). This allows Esc to work to close |
| 617 // the bubble and also solves the keyboard accessibility problem that comes |
| 618 // with focus being lost (we don't have a good generic mechanism of injecting |
| 619 // bubbles into the focus cycle). Another benefit of delaying the show is |
| 620 // that fade-in works (the fade-in isn't apparent if the the bubble appears at |
| 621 // startup). |
| 622 std::unique_ptr<ToolbarActionsBarBubbleDelegate> delegate( |
| 623 new ExtensionMessageBubbleBridge(std::move(controller))); |
| 624 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 625 FROM_HERE, base::Bind(&ToolbarActionsBar::ShowToolbarActionBubble, |
| 626 weak_ptr_factory_.GetWeakPtr(), |
| 627 base::Passed(std::move(delegate))), |
| 628 base::TimeDelta::FromSeconds( |
| 629 g_extension_bubble_appearance_wait_time_in_seconds)); |
| 630 } |
| 631 |
| 632 // static |
| 633 void ToolbarActionsBar::set_extension_bubble_appearance_wait_time_for_testing( |
| 634 int time_in_seconds) { |
| 635 g_extension_bubble_appearance_wait_time_in_seconds = time_in_seconds; |
| 611 } | 636 } |
| 612 | 637 |
| 613 void ToolbarActionsBar::OnToolbarActionAdded( | 638 void ToolbarActionsBar::OnToolbarActionAdded( |
| 614 const ToolbarActionsModel::ToolbarItem& item, | 639 const ToolbarActionsModel::ToolbarItem& item, |
| 615 int index) { | 640 int index) { |
| 616 DCHECK(GetActionForId(item.id) == nullptr) | 641 DCHECK(GetActionForId(item.id) == nullptr) |
| 617 << "Asked to add a toolbar action view for an action that already " | 642 << "Asked to add a toolbar action view for an action that already " |
| 618 "exists"; | 643 "exists"; |
| 619 | 644 |
| 620 toolbar_actions_.insert(toolbar_actions_.begin() + index, | 645 toolbar_actions_.insert(toolbar_actions_.begin() + index, |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 796 for (ToolbarActionViewController* action : toolbar_actions_) { | 821 for (ToolbarActionViewController* action : toolbar_actions_) { |
| 797 if (action->GetId() == action_id) | 822 if (action->GetId() == action_id) |
| 798 return action; | 823 return action; |
| 799 } | 824 } |
| 800 return nullptr; | 825 return nullptr; |
| 801 } | 826 } |
| 802 | 827 |
| 803 content::WebContents* ToolbarActionsBar::GetCurrentWebContents() { | 828 content::WebContents* ToolbarActionsBar::GetCurrentWebContents() { |
| 804 return browser_->tab_strip_model()->GetActiveWebContents(); | 829 return browser_->tab_strip_model()->GetActiveWebContents(); |
| 805 } | 830 } |
| OLD | NEW |