Refactor WebsiteSettings to operate on a SecurityInfo
[chromium-blink-merge.git] / chrome / browser / ui / views / toolbar / toolbar_view.h
blobfd3de8eee2910ff0970a369063b0ab1c4269176d
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(
134 content::WebContents* web_contents,
135 const GURL& url,
136 const SecurityStateModel::SecurityInfo& security_info) override;
138 // CommandObserver:
139 void EnabledStateChangedForCommand(int id, bool enabled) override;
141 // views::ButtonListener:
142 void ButtonPressed(views::Button* sender, const ui::Event& event) override;
144 // views::WidgetObserver:
145 void OnWidgetActivationChanged(views::Widget* widget, bool active) override;
147 // content::NotificationObserver:
148 void Observe(int type,
149 const content::NotificationSource& source,
150 const content::NotificationDetails& details) override;
152 // ui::AcceleratorProvider:
153 bool GetAcceleratorForCommandId(int command_id,
154 ui::Accelerator* accelerator) override;
156 // views::View:
157 gfx::Size GetPreferredSize() const override;
158 gfx::Size GetMinimumSize() const override;
159 void Layout() override;
160 void OnPaint(gfx::Canvas* canvas) override;
161 void OnThemeChanged() override;
162 const char* GetClassName() const override;
163 bool AcceleratorPressed(const ui::Accelerator& acc) override;
165 // Whether the wrench/hotdogs menu is currently showing.
166 bool IsWrenchMenuShowing() const;
168 // Whether the toolbar view needs its background painted by the
169 // BrowserNonClientFrameView.
170 bool ShouldPaintBackground() const;
172 enum {
173 // The apparent horizontal space between most items, and the vertical
174 // padding above and below them.
175 kStandardSpacing = 3,
177 // The top of the toolbar has an edge we have to skip over in addition to
178 // the standard spacing.
179 kVertSpacing = 5,
182 WrenchMenu* wrench_menu_for_testing() { return wrench_menu_.get(); }
184 protected:
185 // AccessiblePaneView:
186 bool SetPaneFocusAndFocusDefault() override;
187 void RemovePaneFocus() override;
189 private:
190 // Types of display mode this toolbar can have.
191 enum DisplayMode {
192 DISPLAYMODE_NORMAL, // Normal toolbar with buttons, etc.
193 DISPLAYMODE_LOCATION // Slimline toolbar showing only compact location
194 // bar, used for popups.
197 // views::ViewTargeterDelegate:
198 bool DoesIntersectRect(const views::View* target,
199 const gfx::Rect& rect) const override;
201 // WrenchMenuBadgeController::Delegate:
202 void UpdateBadgeSeverity(WrenchMenuBadgeController::BadgeType type,
203 WrenchIconPainter::Severity severity,
204 bool animate) override;
206 // Returns the number of pixels above the location bar in non-normal display.
207 int PopupTopSpacing() const;
209 // Given toolbar contents of size |size|, returns the total toolbar size.
210 gfx::Size SizeForContentSize(gfx::Size size) const;
212 // Loads the images for all the child views.
213 void LoadImages();
215 bool is_display_mode_normal() const {
216 return display_mode_ == DISPLAYMODE_NORMAL;
219 // Shows the critical notification bubble against the wrench menu.
220 void ShowCriticalNotification();
222 // Shows the outdated install notification bubble against the wrench menu.
223 // |auto_update_enabled| is set to true when auto-upate is on.
224 void ShowOutdatedInstallNotification(bool auto_update_enabled);
226 void OnShowHomeButtonChanged();
228 int content_shadow_height() const;
230 // Controls
231 BackButton* back_;
232 ToolbarButton* forward_;
233 ReloadButton* reload_;
234 HomeButton* home_;
235 LocationBarView* location_bar_;
236 BrowserActionsContainer* browser_actions_;
237 WrenchToolbarButton* app_menu_;
238 Browser* browser_;
240 WrenchMenuBadgeController badge_controller_;
242 // Controls whether or not a home button should be shown on the toolbar.
243 BooleanPrefMember show_home_button_;
245 // The display mode used when laying out the toolbar.
246 DisplayMode display_mode_;
248 // Wrench model and menu.
249 // Note that the menu should be destroyed before the model it uses, so the
250 // menu should be listed later.
251 scoped_ptr<WrenchMenuModel> wrench_menu_model_;
252 scoped_ptr<WrenchMenu> wrench_menu_;
254 // A list of listeners to call when the menu opens.
255 base::ObserverList<views::MenuListener> menu_listeners_;
257 content::NotificationRegistrar registrar_;
259 DISALLOW_IMPLICIT_CONSTRUCTORS(ToolbarView);
262 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_TOOLBAR_VIEW_H_