Infobar material design refresh: layout
[chromium-blink-merge.git] / chrome / browser / ui / views / toolbar / toolbar_view.h
blob931892c0e2a6ebf6f8e5c45af425b6879dc63cfc
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.
5 #ifndef CHROME_BROWSER_UI_VIEWS_TOOLBAR_TOOLBAR_VIEW_H_
6 #define CHROME_BROWSER_UI_VIEWS_TOOLBAR_TOOLBAR_VIEW_H_
8 #include "base/memory/scoped_ptr.h"
9 #include "base/observer_list.h"
10 #include "base/prefs/pref_member.h"
11 #include "chrome/browser/command_observer.h"
12 #include "chrome/browser/ui/toolbar/back_forward_menu_model.h"
13 #include "chrome/browser/ui/toolbar/wrench_menu_badge_controller.h"
14 #include "chrome/browser/ui/views/location_bar/location_bar_view.h"
15 #include "ui/base/accelerators/accelerator.h"
16 #include "ui/views/accessible_pane_view.h"
17 #include "ui/views/controls/button/menu_button.h"
18 #include "ui/views/controls/button/menu_button_listener.h"
19 #include "ui/views/view.h"
21 class BackButton;
22 class BrowserActionsContainer;
23 class Browser;
24 class HomeButton;
25 class ReloadButton;
26 class ToolbarButton;
27 class WrenchMenu;
28 class WrenchMenuModel;
29 class WrenchToolbarButton;
31 namespace extensions {
32 class Command;
33 class Extension;
36 namespace views {
37 class MenuListener;
40 // The Browser Window's toolbar.
41 class ToolbarView : public views::AccessiblePaneView,
42 public views::MenuButtonListener,
43 public ui::AcceleratorProvider,
44 public LocationBarView::Delegate,
45 public content::NotificationObserver,
46 public CommandObserver,
47 public views::ButtonListener,
48 public views::WidgetObserver,
49 public views::ViewTargeterDelegate,
50 public WrenchMenuBadgeController::Delegate {
51 public:
52 // The view class name.
53 static const char kViewClassName[];
55 explicit ToolbarView(Browser* browser);
56 ~ToolbarView() override;
58 // Create the contents of the Browser Toolbar.
59 void Init();
61 // Forces the toolbar (and transitively the location bar) to update its
62 // current state. If |tab| is non-NULL, we're switching (back?) to this tab
63 // and should restore any previous location bar state (such as user editing)
64 // as well.
65 void Update(content::WebContents* tab);
67 // Clears the current state for |tab|.
68 void ResetTabState(content::WebContents* tab);
70 // Set focus to the toolbar with complete keyboard access, with the
71 // focus initially set to the app menu. Focus will be restored
72 // to the last focused view if the user escapes.
73 void SetPaneFocusAndFocusAppMenu();
75 // Returns true if the app menu is focused.
76 bool IsAppMenuFocused();
78 // Add a listener to receive a callback when the menu opens.
79 void AddMenuListener(views::MenuListener* listener);
81 // Remove a menu listener.
82 void RemoveMenuListener(views::MenuListener* listener);
84 virtual bool GetAcceleratorInfo(int id, ui::Accelerator* accel);
86 // Returns the view to which the bookmark bubble should be anchored.
87 views::View* GetBookmarkBubbleAnchor();
89 // Returns the view to which the Translate bubble should be anchored.
90 views::View* GetTranslateBubbleAnchor();
92 // Executes |command| registered by |extension|.
93 void ExecuteExtensionCommand(const extensions::Extension* extension,
94 const extensions::Command& command);
96 // Shows the app (wrench) menu. |for_drop| indicates whether the menu is
97 // opened for a drag-and-drop operation.
98 void ShowAppMenu(bool for_drop);
100 // Closes the App Menu, if it's open.
101 void CloseAppMenu();
103 // Accessors.
104 Browser* browser() const { return browser_; }
105 BrowserActionsContainer* browser_actions() const { return browser_actions_; }
106 ReloadButton* reload_button() const { return reload_; }
107 LocationBarView* location_bar() const { return location_bar_; }
108 WrenchToolbarButton* app_menu() const { return app_menu_; }
109 HomeButton* home_button() const { return home_; }
110 WrenchMenuBadgeController* wrench_menu_badge_controller() {
111 return &badge_controller_;
114 // AccessiblePaneView:
115 bool SetPaneFocus(View* initial_focus) override;
116 void GetAccessibleState(ui::AXViewState* state) override;
118 // views::MenuButtonListener:
119 void OnMenuButtonClicked(views::View* source,
120 const gfx::Point& point) override;
122 // LocationBarView::Delegate:
123 content::WebContents* GetWebContents() override;
124 ToolbarModel* GetToolbarModel() override;
125 const ToolbarModel* GetToolbarModel() const override;
126 views::Widget* CreateViewsBubble(
127 views::BubbleDelegateView* bubble_delegate) override;
128 PageActionImageView* CreatePageActionImageView(
129 LocationBarView* owner,
130 ExtensionAction* action) override;
131 ContentSettingBubbleModelDelegate* GetContentSettingBubbleModelDelegate()
132 override;
133 void ShowWebsiteSettings(content::WebContents* web_contents,
134 const GURL& url,
135 const content::SSLStatus& ssl) override;
137 // CommandObserver:
138 void EnabledStateChangedForCommand(int id, bool enabled) override;
140 // views::ButtonListener:
141 void ButtonPressed(views::Button* sender, const ui::Event& event) override;
143 // views::WidgetObserver:
144 void OnWidgetActivationChanged(views::Widget* widget, bool active) override;
146 // content::NotificationObserver:
147 void Observe(int type,
148 const content::NotificationSource& source,
149 const content::NotificationDetails& details) override;
151 // ui::AcceleratorProvider:
152 bool GetAcceleratorForCommandId(int command_id,
153 ui::Accelerator* accelerator) override;
155 // views::View:
156 gfx::Size GetPreferredSize() const override;
157 gfx::Size GetMinimumSize() const override;
158 void Layout() override;
159 void OnPaint(gfx::Canvas* canvas) override;
160 void OnThemeChanged() override;
161 const char* GetClassName() const override;
162 bool AcceleratorPressed(const ui::Accelerator& acc) override;
164 // Whether the wrench/hotdogs menu is currently showing.
165 bool IsWrenchMenuShowing() const;
167 // Whether the toolbar view needs its background painted by the
168 // BrowserNonClientFrameView.
169 bool ShouldPaintBackground() const;
171 enum {
172 // The apparent horizontal space between most items, and the vertical
173 // padding above and below them.
174 kStandardSpacing = 3,
176 // The top of the toolbar has an edge we have to skip over in addition to
177 // the standard spacing.
178 kVertSpacing = 5,
181 WrenchMenu* wrench_menu_for_testing() { return wrench_menu_.get(); }
183 protected:
184 // AccessiblePaneView:
185 bool SetPaneFocusAndFocusDefault() override;
186 void RemovePaneFocus() override;
188 private:
189 // Types of display mode this toolbar can have.
190 enum DisplayMode {
191 DISPLAYMODE_NORMAL, // Normal toolbar with buttons, etc.
192 DISPLAYMODE_LOCATION // Slimline toolbar showing only compact location
193 // bar, used for popups.
196 // views::ViewTargeterDelegate:
197 bool DoesIntersectRect(const views::View* target,
198 const gfx::Rect& rect) const override;
200 // WrenchMenuBadgeController::Delegate:
201 void UpdateBadgeSeverity(WrenchMenuBadgeController::BadgeType type,
202 WrenchIconPainter::Severity severity,
203 bool animate) override;
205 // Returns the number of pixels above the location bar in non-normal display.
206 int PopupTopSpacing() const;
208 // Given toolbar contents of size |size|, returns the total toolbar size.
209 gfx::Size SizeForContentSize(gfx::Size size) const;
211 // Loads the images for all the child views.
212 void LoadImages();
214 bool is_display_mode_normal() const {
215 return display_mode_ == DISPLAYMODE_NORMAL;
218 // Shows the critical notification bubble against the wrench menu.
219 void ShowCriticalNotification();
221 // Shows the outdated install notification bubble against the wrench menu.
222 // |auto_update_enabled| is set to true when auto-upate is on.
223 void ShowOutdatedInstallNotification(bool auto_update_enabled);
225 void OnShowHomeButtonChanged();
227 int content_shadow_height() const;
229 // Controls
230 BackButton* back_;
231 ToolbarButton* forward_;
232 ReloadButton* reload_;
233 HomeButton* home_;
234 LocationBarView* location_bar_;
235 BrowserActionsContainer* browser_actions_;
236 WrenchToolbarButton* app_menu_;
237 Browser* browser_;
239 WrenchMenuBadgeController badge_controller_;
241 // Controls whether or not a home button should be shown on the toolbar.
242 BooleanPrefMember show_home_button_;
244 // The display mode used when laying out the toolbar.
245 DisplayMode display_mode_;
247 // Wrench model and menu.
248 // Note that the menu should be destroyed before the model it uses, so the
249 // menu should be listed later.
250 scoped_ptr<WrenchMenuModel> wrench_menu_model_;
251 scoped_ptr<WrenchMenu> wrench_menu_;
253 // A list of listeners to call when the menu opens.
254 base::ObserverList<views::MenuListener> menu_listeners_;
256 content::NotificationRegistrar registrar_;
258 DISALLOW_IMPLICIT_CONSTRUCTORS(ToolbarView);
261 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_TOOLBAR_VIEW_H_