OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_ACTION_VIEW_CONTROLLER_VIEW
S_H_ |
| 6 #define CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_ACTION_VIEW_CONTROLLER_VIEW
S_H_ |
| 7 |
| 8 #include "chrome/browser/ui/extensions/extension_action_view_controller.h" |
| 9 #include "chrome/browser/ui/views/extensions/extension_popup.h" |
| 10 #include "content/public/browser/notification_observer.h" |
| 11 #include "content/public/browser/notification_registrar.h" |
| 12 #include "ui/base/accelerators/accelerator.h" |
| 13 #include "ui/views/context_menu_controller.h" |
| 14 #include "ui/views/widget/widget_observer.h" |
| 15 |
| 16 class Browser; |
| 17 class ExtensionAction; |
| 18 class ToolbarActionViewDelegateViews; |
| 19 |
| 20 namespace content { |
| 21 class WebContents; |
| 22 } |
| 23 |
| 24 namespace extensions { |
| 25 class Command; |
| 26 class Extension; |
| 27 } |
| 28 |
| 29 namespace ui { |
| 30 class Accelerator; |
| 31 } |
| 32 |
| 33 namespace views { |
| 34 class MenuRunner; |
| 35 class View; |
| 36 class Widget; |
| 37 } |
| 38 |
| 39 // An abstract "View" for an ExtensionAction (either a BrowserAction or a |
| 40 // PageAction). This contains the logic for showing the action's popup and |
| 41 // the context menu. This class doesn't subclass View directly, as the |
| 42 // implementations for page actions/browser actions are different types of |
| 43 // views. |
| 44 // All common logic for executing extension actions should go in this class; |
| 45 // ToolbarActionViewDelegate classes should only have knowledge relating to |
| 46 // the views::View wrapper. |
| 47 class ExtensionActionViewControllerViews |
| 48 : public ExtensionActionViewController, |
| 49 public content::NotificationObserver, |
| 50 public ui::AcceleratorTarget, |
| 51 public views::ContextMenuController, |
| 52 public views::WidgetObserver { |
| 53 public: |
| 54 ExtensionActionViewControllerViews(const extensions::Extension* extension, |
| 55 Browser* browser, |
| 56 ExtensionAction* extension_action); |
| 57 ~ExtensionActionViewControllerViews() override; |
| 58 |
| 59 // ToolbarActionViewController: |
| 60 gfx::NativeView GetPopupNativeView() override; |
| 61 bool IsMenuRunning() const override; |
| 62 void RegisterCommand() override; |
| 63 |
| 64 void set_icon_observer(ExtensionActionIconFactory::Observer* icon_observer) { |
| 65 icon_observer_ = icon_observer; |
| 66 } |
| 67 |
| 68 private: |
| 69 // ExtensionActionViewController: |
| 70 bool IsShowingPopup() const override; |
| 71 void CloseActivePopup() override; |
| 72 void ClosePopupImpl() override; |
| 73 bool ShowPopupWithUrlImpl(PopupShowAction show_action, |
| 74 const GURL& popup_url, |
| 75 bool grant_tab_permissions) override; |
| 76 void OnDelegateSet() override; |
| 77 |
| 78 // content::NotificationObserver: |
| 79 void Observe(int type, |
| 80 const content::NotificationSource& source, |
| 81 const content::NotificationDetails& details) override; |
| 82 |
| 83 // ui::AcceleratorTarget: |
| 84 bool AcceleratorPressed(const ui::Accelerator& accelerator) override; |
| 85 bool CanHandleAccelerators() const override; |
| 86 |
| 87 // views::WidgetObserver: |
| 88 void OnWidgetDestroying(views::Widget* widget) override; |
| 89 |
| 90 // views::ContextMenuController: |
| 91 void ShowContextMenuForView(views::View* source, |
| 92 const gfx::Point& point, |
| 93 ui::MenuSourceType source_type) override; |
| 94 |
| 95 // Shows the context menu for extension action. |
| 96 void DoShowContextMenu(ui::MenuSourceType source_type); |
| 97 |
| 98 // Unregisters the accelerator for the extension action's command, if one |
| 99 // exists. If |only_if_removed| is true, then this will only unregister if the |
| 100 // command has been removed. |
| 101 void UnregisterCommand(bool only_if_removed); |
| 102 |
| 103 // Closes the currently-active menu, if needed. This is the case when there |
| 104 // is an active menu that wouldn't close automatically when a new one is |
| 105 // opened. |
| 106 // Returns true if a menu was closed, false otherwise. |
| 107 bool CloseActiveMenuIfNeeded(); |
| 108 |
| 109 // Cleans up after the popup. If |close_widget| is true, this will call |
| 110 // Widget::Close() on the popup's widget; otherwise it assumes the popup is |
| 111 // already closing. |
| 112 void CleanupPopup(bool close_widget); |
| 113 |
| 114 ToolbarActionViewDelegateViews* GetDelegateViews() const; |
| 115 |
| 116 // The observer that we need to notify when the icon of the button has been |
| 117 // updated. |
| 118 ExtensionActionIconFactory::Observer* icon_observer_; |
| 119 |
| 120 // Responsible for running the menu. |
| 121 scoped_ptr<views::MenuRunner> menu_runner_; |
| 122 |
| 123 // The browser action's popup, if it is visible; NULL otherwise. |
| 124 ExtensionPopup* popup_; |
| 125 |
| 126 // The extension key binding accelerator this extension action is listening |
| 127 // for (to show the popup). |
| 128 scoped_ptr<ui::Accelerator> action_keybinding_; |
| 129 |
| 130 // If non-NULL, this is the next ExtensionActionViewController context menu |
| 131 // which wants to run once the current owner (this one) is done. |
| 132 base::Closure followup_context_menu_task_; |
| 133 |
| 134 content::NotificationRegistrar registrar_; |
| 135 |
| 136 base::WeakPtrFactory<ExtensionActionViewControllerViews> weak_factory_; |
| 137 |
| 138 DISALLOW_COPY_AND_ASSIGN(ExtensionActionViewControllerViews); |
| 139 }; |
| 140 |
| 141 #endif // CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_ACTION_VIEW_CONTROLLER_V
IEWS_H_ |
OLD | NEW |