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

Side by Side Diff: chrome/browser/ui/views/extensions/extension_action_platform_delegate_views.h

Issue 670463004: Make a platform-independent ToolbarActionViewController (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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
(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_PLATFORM_DELEGATE_VI EWS_H_
6 #define CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_ACTION_PLATFORM_DELEGATE_VI EWS_H_
7
8 #include "chrome/browser/ui/extensions/extension_action_platform_delegate.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 ExtensionActionPlatformDelegateViews
48 : public ExtensionActionPlatformDelegate,
49 public content::NotificationObserver,
50 public ui::AcceleratorTarget,
51 public views::ContextMenuController,
52 public views::WidgetObserver {
53 public:
54 ExtensionActionPlatformDelegateViews(
55 ExtensionActionViewController* controller);
56 ~ExtensionActionPlatformDelegateViews() override;
57
58 private:
59 // ExtensionActionPlatformDelegate:
60 gfx::NativeView GetPopupNativeView() override;
61 bool IsMenuRunning() const override;
62 void RegisterCommand() override;
63 void OnDelegateSet() override;
64 bool IsShowingPopup() const override;
65 void CloseActivePopup() override;
66 void CloseOwnPopup() override;
67 bool ShowPopupWithUrl(
68 ExtensionActionViewController::PopupShowAction show_action,
69 const GURL& popup_url,
70 bool grant_tab_permissions) override;
71
72 // content::NotificationObserver:
73 void Observe(int type,
74 const content::NotificationSource& source,
75 const content::NotificationDetails& details) override;
76
77 // ui::AcceleratorTarget:
78 bool AcceleratorPressed(const ui::Accelerator& accelerator) override;
79 bool CanHandleAccelerators() const override;
80
81 // views::WidgetObserver:
82 void OnWidgetDestroying(views::Widget* widget) override;
83
84 // views::ContextMenuController:
85 void ShowContextMenuForView(views::View* source,
86 const gfx::Point& point,
87 ui::MenuSourceType source_type) override;
88
89 // Shows the context menu for extension action.
90 void DoShowContextMenu(ui::MenuSourceType source_type);
91
92 // Unregisters the accelerator for the extension action's command, if one
93 // exists. If |only_if_removed| is true, then this will only unregister if the
94 // command has been removed.
95 void UnregisterCommand(bool only_if_removed);
96
97 // Closes the currently-active menu, if needed. This is the case when there
98 // is an active menu that wouldn't close automatically when a new one is
99 // opened.
100 // Returns true if a menu was closed, false otherwise.
101 bool CloseActiveMenuIfNeeded();
102
103 // Cleans up after the popup. If |close_widget| is true, this will call
104 // Widget::Close() on the popup's widget; otherwise it assumes the popup is
105 // already closing.
106 void CleanupPopup(bool close_widget);
107
108 ToolbarActionViewDelegateViews* GetDelegateViews() const;
109
110 // The owning ExtensionActionViewController.
111 ExtensionActionViewController* controller_;
112
113 // Responsible for running the menu.
114 scoped_ptr<views::MenuRunner> menu_runner_;
115
116 // The browser action's popup, if it is visible; NULL otherwise.
117 ExtensionPopup* popup_;
118
119 // The extension key binding accelerator this extension action is listening
120 // for (to show the popup).
121 scoped_ptr<ui::Accelerator> action_keybinding_;
122
123 // If non-NULL, this is the next ExtensionActionViewController context menu
124 // which wants to run once the current owner (this one) is done.
125 base::Closure followup_context_menu_task_;
126
127 content::NotificationRegistrar registrar_;
128
129 base::WeakPtrFactory<ExtensionActionPlatformDelegateViews> weak_factory_;
130
131 DISALLOW_COPY_AND_ASSIGN(ExtensionActionPlatformDelegateViews);
132 };
133
134 #endif // CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_ACTION_PLATFORM_DELEGATE _VIEWS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698