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

Side by Side Diff: chrome/browser/ui/views/toolbar/browser_action_view.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
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_BROWSER_ACTION_VIEW_H_
6 #define CHROME_BROWSER_UI_VIEWS_TOOLBAR_BROWSER_ACTION_VIEW_H_ 6 #define CHROME_BROWSER_UI_VIEWS_TOOLBAR_BROWSER_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_views.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 // BrowserActionView
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 // Despite its name, this class can handle any type of toolbar action, including
32 // extension actions (browser and page actions) and component actions. 32 // extension actions (browser and page actions) and component actions.
33 // TODO(devlin): Rename this and BrowserActionsContainer when more of the 33 // TODO(devlin): Rename this and BrowserActionsContainer when more of the
34 // toolbar redesign is done. 34 // toolbar redesign is done.
35 class BrowserActionView : public views::MenuButton, 35 class BrowserActionView : public views::MenuButton,
36 public ToolbarActionViewDelegate, 36 public ToolbarActionViewDelegateViews,
37 public views::ButtonListener, 37 public views::ButtonListener,
38 public content::NotificationObserver { 38 public content::NotificationObserver {
39 public: 39 public:
40 // Need DragController here because BrowserActionView could be 40 // Need DragController here because BrowserActionView could be
41 // dragged/dropped. 41 // dragged/dropped.
42 class Delegate : public views::DragController { 42 class Delegate : public views::DragController {
43 public: 43 public:
44 // Returns the current web contents. 44 // Returns the current web contents.
45 virtual content::WebContents* GetCurrentWebContents() = 0; 45 virtual content::WebContents* GetCurrentWebContents() = 0;
46 46
(...skipping 23 matching lines...) Expand all
70 70
71 protected: 71 protected:
72 ~Delegate() override {} 72 ~Delegate() override {}
73 }; 73 };
74 74
75 BrowserActionView(scoped_ptr<ToolbarActionViewController> view_controller, 75 BrowserActionView(scoped_ptr<ToolbarActionViewController> view_controller,
76 Browser* browser, 76 Browser* browser,
77 Delegate* delegate); 77 Delegate* delegate);
78 ~BrowserActionView() override; 78 ~BrowserActionView() override;
79 79
80 // Called to update the display to match the browser action's state.
81 void UpdateState();
82
83 // Overridden from views::View: 80 // Overridden from views::View:
84 void GetAccessibleState(ui::AXViewState* state) override; 81 void GetAccessibleState(ui::AXViewState* state) override;
85 82
86 // Overridden from views::ButtonListener: 83 // Overridden from views::ButtonListener:
87 void ButtonPressed(views::Button* sender, const ui::Event& event) override; 84 void ButtonPressed(views::Button* sender, const ui::Event& event) override;
88 85
89 // Overridden from content::NotificationObserver: 86 // Overridden from content::NotificationObserver:
90 void Observe(int type, 87 void Observe(int type,
91 const content::NotificationSource& source, 88 const content::NotificationSource& source,
92 const content::NotificationDetails& details) override; 89 const content::NotificationDetails& details) override;
93 90
94 // MenuButton behavior overrides. These methods all default to LabelButton 91 // MenuButton behavior overrides. These methods all default to LabelButton
95 // behavior unless this button is a popup. In that case, it uses MenuButton 92 // behavior unless this button is a popup. In that case, it uses MenuButton
96 // behavior. MenuButton has the notion of a child popup being shown where the 93 // behavior. MenuButton has the notion of a child popup being shown where the
97 // button will stay in the pushed state until the "menu" (a popup in this 94 // button will stay in the pushed state until the "menu" (a popup in this
98 // case) is dismissed. 95 // case) is dismissed.
99 bool Activate() override; 96 bool Activate() override;
100 bool OnMousePressed(const ui::MouseEvent& event) override; 97 bool OnMousePressed(const ui::MouseEvent& event) override;
101 void OnMouseReleased(const ui::MouseEvent& event) override; 98 void OnMouseReleased(const ui::MouseEvent& event) override;
102 void OnMouseExited(const ui::MouseEvent& event) override; 99 void OnMouseExited(const ui::MouseEvent& event) override;
103 bool OnKeyReleased(const ui::KeyEvent& event) override; 100 bool OnKeyReleased(const ui::KeyEvent& event) override;
104 void OnGestureEvent(ui::GestureEvent* event) override; 101 void OnGestureEvent(ui::GestureEvent* event) override;
105 scoped_ptr<views::LabelButtonBorder> CreateDefaultBorder() const override; 102 scoped_ptr<views::LabelButtonBorder> CreateDefaultBorder() const override;
106 103
107 // ToolbarActionViewDelegate: (public because called by others). 104 // ToolbarActionViewDelegate: (public because called by others).
105 void UpdateState() override;
108 content::WebContents* GetCurrentWebContents() const override; 106 content::WebContents* GetCurrentWebContents() const override;
109 107
110 ToolbarActionViewController* view_controller() { 108 ToolbarActionViewController* view_controller() {
111 return view_controller_.get(); 109 return view_controller_.get();
112 } 110 }
113 Browser* browser() { return browser_; } 111 Browser* browser() { return browser_; }
114 112
115 // Returns button icon so it can be accessed during tests. 113 // Returns button icon so it can be accessed during tests.
116 gfx::ImageSkia GetIconForTest(); 114 gfx::ImageSkia GetIconForTest();
117 115
118 private: 116 private:
119 // Overridden from views::View: 117 // Overridden from views::View:
120 void ViewHierarchyChanged( 118 void ViewHierarchyChanged(
121 const ViewHierarchyChangedDetails& details) override; 119 const ViewHierarchyChangedDetails& details) override;
122 void OnDragDone() override; 120 void OnDragDone() override;
123 gfx::Size GetPreferredSize() const override; 121 gfx::Size GetPreferredSize() const override;
124 void PaintChildren(gfx::Canvas* canvas, 122 void PaintChildren(gfx::Canvas* canvas,
125 const views::CullSet& cull_set) override; 123 const views::CullSet& cull_set) override;
126 124
127 // ToolbarActionViewDelegate: 125 // ToolbarActionViewDelegateViews:
128 views::View* GetAsView() override; 126 views::View* GetAsView() override;
129 bool IsShownInMenu() override; 127 bool IsShownInMenu() override;
130 views::FocusManager* GetFocusManagerForAccelerator() override; 128 views::FocusManager* GetFocusManagerForAccelerator() override;
131 views::Widget* GetParentForContextMenu() override; 129 views::Widget* GetParentForContextMenu() override;
132 ToolbarActionViewController* GetPreferredPopupViewController() override; 130 ToolbarActionViewController* GetPreferredPopupViewController() override;
133 views::View* GetReferenceViewForPopup() override; 131 views::View* GetReferenceViewForPopup() override;
134 views::MenuButton* GetContextMenuButton() override; 132 views::MenuButton* GetContextMenuButton() override;
135 void HideActivePopup() override; 133 void HideActivePopup() override;
136 void OnIconUpdated() override;
137 void OnPopupShown(bool grant_tab_permissions) override; 134 void OnPopupShown(bool grant_tab_permissions) override;
138 void CleanupPopup() override; 135 void CleanupPopup() override;
139 136
140 // A lock to keep the MenuButton pressed when a menu or popup is visible. 137 // A lock to keep the MenuButton pressed when a menu or popup is visible.
141 // This needs to be destroyed after |view_controller_|, because 138 // This needs to be destroyed after |view_controller_|, because
142 // |view_controller_|'s destructor can call CleanupPopup(), which uses this 139 // |view_controller_|'s destructor can call CleanupPopup(), which uses this
143 // object. 140 // object.
144 scoped_ptr<views::MenuButton::PressedLock> pressed_lock_; 141 scoped_ptr<views::MenuButton::PressedLock> pressed_lock_;
145 142
146 // The controller for this toolbar action view. 143 // The controller for this toolbar action view.
147 scoped_ptr<ToolbarActionViewController> view_controller_; 144 scoped_ptr<ToolbarActionViewController> view_controller_;
148 145
149 // The associated browser. 146 // The associated browser.
150 Browser* browser_; 147 Browser* browser_;
151 148
152 // Delegate that usually represents a container for BrowserActionView. 149 // Delegate that usually represents a container for BrowserActionView.
153 Delegate* delegate_; 150 Delegate* delegate_;
154 151
155 // Used to make sure we only register the command once. 152 // Used to make sure we only register the command once.
156 bool called_register_command_; 153 bool called_register_command_;
157 154
158 content::NotificationRegistrar registrar_; 155 content::NotificationRegistrar registrar_;
159 156
160 DISALLOW_COPY_AND_ASSIGN(BrowserActionView); 157 DISALLOW_COPY_AND_ASSIGN(BrowserActionView);
161 }; 158 };
162 159
163 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_BROWSER_ACTION_VIEW_H_ 160 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_BROWSER_ACTION_VIEW_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698