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

Side by Side Diff: chrome/browser/ui/views/toolbar/browser_action_view.h

Issue 673503002: Rename BrowserActionView to ToolbarActionView (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 months 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 2013 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_TOOLBAR_BROWSER_ACTION_VIEW_H_
6 #define CHROME_BROWSER_UI_VIEWS_TOOLBAR_BROWSER_ACTION_VIEW_H_
7
8 #include "chrome/browser/ui/views/toolbar/toolbar_action_view_delegate.h"
9 #include "content/public/browser/notification_observer.h"
10 #include "content/public/browser/notification_registrar.h"
11 #include "ui/views/controls/button/menu_button.h"
12 #include "ui/views/controls/button/menu_button_listener.h"
13 #include "ui/views/drag_controller.h"
14 #include "ui/views/view.h"
15
16 class Browser;
17 class ExtensionAction;
18
19 namespace extensions {
20 class Extension;
21 }
22
23 namespace gfx {
24 class Image;
25 }
26
27 ////////////////////////////////////////////////////////////////////////////////
28 // BrowserActionView
29 // A wrapper around a ToolbarActionViewController to display a toolbar action
30 // action in the BrowserActionsContainer.
31 // Despite its name, this class can handle any type of toolbar action, including
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,
37 public views::ButtonListener,
38 public content::NotificationObserver {
39 public:
40 // Need DragController here because BrowserActionView could be
41 // dragged/dropped.
42 class Delegate : public views::DragController {
43 public:
44 // Returns the current web contents.
45 virtual content::WebContents* GetCurrentWebContents() = 0;
46
47 // Whether the container for this button is shown inside a menu.
48 virtual bool ShownInsideMenu() const = 0;
49
50 // Notifies that a drag completed. Note this will only happen if the view
51 // wasn't removed during the drag-and-drop process (i.e., not when there
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
56 // Returns the view of the browser actions overflow menu to use as a
57 // reference point for a popup when this view isn't visible.
58 virtual views::MenuButton* GetOverflowReferenceView() = 0;
59
60 // Sets the delegate's active popup owner to be |popup_owner|.
61 virtual void SetPopupOwner(BrowserActionView* popup_owner) = 0;
62
63 // Hides the active popup of the delegate, if one exists.
64 virtual void HideActivePopup() = 0;
65
66 // Returns the primary BrowserActionView associated with the given
67 // |extension|.
68 virtual BrowserActionView* GetMainViewForAction(
69 BrowserActionView* view) = 0;
70
71 protected:
72 virtual ~Delegate() {}
73 };
74
75 BrowserActionView(scoped_ptr<ToolbarActionViewController> view_controller,
76 Browser* browser,
77 Delegate* delegate);
78 virtual ~BrowserActionView();
79
80 // Called to update the display to match the browser action's state.
81 void UpdateState();
82
83 // Overridden from views::View:
84 virtual void GetAccessibleState(ui::AXViewState* state) override;
85
86 // Overridden from views::ButtonListener:
87 virtual void ButtonPressed(views::Button* sender,
88 const ui::Event& event) override;
89
90 // Overridden from content::NotificationObserver:
91 virtual void Observe(int type,
92 const content::NotificationSource& source,
93 const content::NotificationDetails& details) override;
94
95 // MenuButton behavior overrides. These methods all default to LabelButton
96 // behavior unless this button is a popup. In that case, it uses MenuButton
97 // behavior. MenuButton has the notion of a child popup being shown where the
98 // button will stay in the pushed state until the "menu" (a popup in this
99 // case) is dismissed.
100 virtual bool Activate() override;
101 virtual bool OnMousePressed(const ui::MouseEvent& event) override;
102 virtual void OnMouseReleased(const ui::MouseEvent& event) override;
103 virtual void OnMouseExited(const ui::MouseEvent& event) override;
104 virtual bool OnKeyReleased(const ui::KeyEvent& event) override;
105 virtual void OnGestureEvent(ui::GestureEvent* event) override;
106 virtual scoped_ptr<views::LabelButtonBorder> CreateDefaultBorder() const
107 override;
108
109 // ToolbarActionViewDelegate: (public because called by others).
110 virtual content::WebContents* GetCurrentWebContents() const override;
111
112 ToolbarActionViewController* view_controller() {
113 return view_controller_.get();
114 }
115 Browser* browser() { return browser_; }
116
117 // Returns button icon so it can be accessed during tests.
118 gfx::ImageSkia GetIconForTest();
119
120 private:
121 // Overridden from views::View:
122 virtual void ViewHierarchyChanged(
123 const ViewHierarchyChangedDetails& details) override;
124 virtual void OnDragDone() override;
125 virtual gfx::Size GetPreferredSize() const override;
126 virtual void PaintChildren(gfx::Canvas* canvas,
127 const views::CullSet& cull_set) override;
128
129 // ToolbarActionViewDelegate:
130 virtual views::View* GetAsView() override;
131 virtual bool IsShownInMenu() override;
132 virtual views::FocusManager* GetFocusManagerForAccelerator() override;
133 virtual views::Widget* GetParentForContextMenu() override;
134 virtual ToolbarActionViewController* GetPreferredPopupViewController()
135 override;
136 virtual views::View* GetReferenceViewForPopup() override;
137 virtual views::MenuButton* GetContextMenuButton() override;
138 virtual void HideActivePopup() override;
139 virtual void OnIconUpdated() override;
140 virtual void OnPopupShown(bool grant_tab_permissions) override;
141 virtual void CleanupPopup() override;
142
143 // A lock to keep the MenuButton pressed when a menu or popup is visible.
144 // This needs to be destroyed after |view_controller_|, because
145 // |view_controller_|'s destructor can call CleanupPopup(), which uses this
146 // object.
147 scoped_ptr<views::MenuButton::PressedLock> pressed_lock_;
148
149 // The controller for this toolbar action view.
150 scoped_ptr<ToolbarActionViewController> view_controller_;
151
152 // The associated browser.
153 Browser* browser_;
154
155 // Delegate that usually represents a container for BrowserActionView.
156 Delegate* delegate_;
157
158 // Used to make sure we only register the command once.
159 bool called_register_command_;
160
161 content::NotificationRegistrar registrar_;
162
163 DISALLOW_COPY_AND_ASSIGN(BrowserActionView);
164 };
165
166 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_BROWSER_ACTION_VIEW_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698