OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #ifndef CHROME_BROWSER_UI_VIEWS_TOOLBAR_BROWSER_ACTION_VIEW_H_ | 5 #ifndef CHROME_BROWSER_UI_VIEWS_TOOLBAR_TOOLBAR_ACTION_VIEW_H_ |
6 #define CHROME_BROWSER_UI_VIEWS_TOOLBAR_BROWSER_ACTION_VIEW_H_ | 6 #define CHROME_BROWSER_UI_VIEWS_TOOLBAR_TOOLBAR_ACTION_VIEW_H_ |
7 | 7 |
8 #include "chrome/browser/ui/views/toolbar/toolbar_action_view_delegate.h" | 8 #include "chrome/browser/ui/views/toolbar/toolbar_action_view_delegate.h" |
9 #include "content/public/browser/notification_observer.h" | 9 #include "content/public/browser/notification_observer.h" |
10 #include "content/public/browser/notification_registrar.h" | 10 #include "content/public/browser/notification_registrar.h" |
11 #include "ui/views/controls/button/menu_button.h" | 11 #include "ui/views/controls/button/menu_button.h" |
12 #include "ui/views/controls/button/menu_button_listener.h" | 12 #include "ui/views/controls/button/menu_button_listener.h" |
13 #include "ui/views/drag_controller.h" | 13 #include "ui/views/drag_controller.h" |
14 #include "ui/views/view.h" | 14 #include "ui/views/view.h" |
15 | 15 |
16 class Browser; | 16 class Browser; |
17 class ExtensionAction; | 17 class ExtensionAction; |
18 | 18 |
19 namespace extensions { | 19 namespace extensions { |
20 class Extension; | 20 class Extension; |
21 } | 21 } |
22 | 22 |
23 namespace gfx { | 23 namespace gfx { |
24 class Image; | 24 class Image; |
25 } | 25 } |
26 | 26 |
27 //////////////////////////////////////////////////////////////////////////////// | 27 //////////////////////////////////////////////////////////////////////////////// |
28 // BrowserActionView | 28 // ToolbarActionView |
29 // A wrapper around a ToolbarActionViewController to display a toolbar action | 29 // A wrapper around a ToolbarActionViewController to display a toolbar action |
30 // action in the BrowserActionsContainer. | 30 // action in the BrowserActionsContainer. |
31 // Despite its name, this class can handle any type of toolbar action, including | 31 class ToolbarActionView : public views::MenuButton, |
32 // extension actions (browser and page actions) and component actions. | |
33 // TODO(devlin): Rename this and BrowserActionsContainer when more of the | |
34 // toolbar redesign is done. | |
35 class BrowserActionView : public views::MenuButton, | |
36 public ToolbarActionViewDelegate, | 32 public ToolbarActionViewDelegate, |
37 public views::ButtonListener, | 33 public views::ButtonListener, |
38 public content::NotificationObserver { | 34 public content::NotificationObserver { |
39 public: | 35 public: |
40 // Need DragController here because BrowserActionView could be | 36 // Need DragController here because ToolbarActionView could be |
41 // dragged/dropped. | 37 // dragged/dropped. |
42 class Delegate : public views::DragController { | 38 class Delegate : public views::DragController { |
43 public: | 39 public: |
44 // Returns the current web contents. | 40 // Returns the current web contents. |
45 virtual content::WebContents* GetCurrentWebContents() = 0; | 41 virtual content::WebContents* GetCurrentWebContents() = 0; |
46 | 42 |
47 // Whether the container for this button is shown inside a menu. | 43 // Whether the container for this button is shown inside a menu. |
48 virtual bool ShownInsideMenu() const = 0; | 44 virtual bool ShownInsideMenu() const = 0; |
49 | 45 |
50 // Notifies that a drag completed. Note this will only happen if the view | 46 // Notifies that a drag completed. |
51 // wasn't removed during the drag-and-drop process (i.e., not when there | 47 virtual void OnToolbarActionViewDragDone() = 0; |
52 // was a move in the browser actions, since we re-create the views each | |
53 // time we re-order the browser actions). | |
54 virtual void OnBrowserActionViewDragDone() = 0; | |
55 | 48 |
56 // Returns the view of the browser actions overflow menu to use as a | 49 // Returns the view of the toolbar actions overflow menu to use as a |
57 // reference point for a popup when this view isn't visible. | 50 // reference point for a popup when this view isn't visible. |
58 virtual views::MenuButton* GetOverflowReferenceView() = 0; | 51 virtual views::MenuButton* GetOverflowReferenceView() = 0; |
59 | 52 |
60 // Sets the delegate's active popup owner to be |popup_owner|. | 53 // Sets the delegate's active popup owner to be |popup_owner|. |
61 virtual void SetPopupOwner(BrowserActionView* popup_owner) = 0; | 54 virtual void SetPopupOwner(ToolbarActionView* popup_owner) = 0; |
62 | 55 |
63 // Hides the active popup of the delegate, if one exists. | 56 // Hides the active popup of the delegate, if one exists. |
64 virtual void HideActivePopup() = 0; | 57 virtual void HideActivePopup() = 0; |
65 | 58 |
66 // Returns the primary BrowserActionView associated with the given | 59 // Returns the primary ToolbarActionView associated with the given |
67 // |extension|. | 60 // |extension|. |
68 virtual BrowserActionView* GetMainViewForAction( | 61 virtual ToolbarActionView* GetMainViewForAction( |
69 BrowserActionView* view) = 0; | 62 ToolbarActionView* view) = 0; |
70 | 63 |
71 protected: | 64 protected: |
72 ~Delegate() override {} | 65 ~Delegate() override {} |
73 }; | 66 }; |
74 | 67 |
75 BrowserActionView(scoped_ptr<ToolbarActionViewController> view_controller, | 68 ToolbarActionView(scoped_ptr<ToolbarActionViewController> view_controller, |
76 Browser* browser, | 69 Browser* browser, |
77 Delegate* delegate); | 70 Delegate* delegate); |
78 ~BrowserActionView() override; | 71 ~ToolbarActionView() override; |
79 | 72 |
80 // Called to update the display to match the browser action's state. | 73 // Called to update the display to match the toolbar action's state. |
81 void UpdateState(); | 74 void UpdateState(); |
82 | 75 |
83 // Overridden from views::View: | 76 // Overridden from views::View: |
84 void GetAccessibleState(ui::AXViewState* state) override; | 77 void GetAccessibleState(ui::AXViewState* state) override; |
85 | 78 |
86 // Overridden from views::ButtonListener: | 79 // Overridden from views::ButtonListener: |
87 void ButtonPressed(views::Button* sender, const ui::Event& event) override; | 80 void ButtonPressed(views::Button* sender, const ui::Event& event) override; |
88 | 81 |
89 // Overridden from content::NotificationObserver: | 82 // Overridden from content::NotificationObserver: |
90 void Observe(int type, | 83 void Observe(int type, |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 // |view_controller_|'s destructor can call CleanupPopup(), which uses this | 135 // |view_controller_|'s destructor can call CleanupPopup(), which uses this |
143 // object. | 136 // object. |
144 scoped_ptr<views::MenuButton::PressedLock> pressed_lock_; | 137 scoped_ptr<views::MenuButton::PressedLock> pressed_lock_; |
145 | 138 |
146 // The controller for this toolbar action view. | 139 // The controller for this toolbar action view. |
147 scoped_ptr<ToolbarActionViewController> view_controller_; | 140 scoped_ptr<ToolbarActionViewController> view_controller_; |
148 | 141 |
149 // The associated browser. | 142 // The associated browser. |
150 Browser* browser_; | 143 Browser* browser_; |
151 | 144 |
152 // Delegate that usually represents a container for BrowserActionView. | 145 // Delegate that usually represents a container for ToolbarActionView. |
153 Delegate* delegate_; | 146 Delegate* delegate_; |
154 | 147 |
155 // Used to make sure we only register the command once. | 148 // Used to make sure we only register the command once. |
156 bool called_register_command_; | 149 bool called_register_command_; |
157 | 150 |
158 content::NotificationRegistrar registrar_; | 151 content::NotificationRegistrar registrar_; |
159 | 152 |
160 DISALLOW_COPY_AND_ASSIGN(BrowserActionView); | 153 DISALLOW_COPY_AND_ASSIGN(ToolbarActionView); |
161 }; | 154 }; |
162 | 155 |
163 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_BROWSER_ACTION_VIEW_H_ | 156 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_TOOLBAR_ACTION_VIEW_H_ |
OLD | NEW |