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_
11 #include "base/memory/scoped_ptr.h"
12 #include "base/observer_list.h"
13 #include "base/prefs/pref_member.h"
14 #include "chrome/browser/command_observer.h"
15 #include "chrome/browser/ui/toolbar/back_forward_menu_model.h"
16 #include "chrome/browser/ui/toolbar/wrench_menu_badge_controller.h"
17 #include "chrome/browser/ui/views/location_bar/location_bar_view.h"
18 #include "ui/base/accelerators/accelerator.h"
19 #include "ui/views/accessible_pane_view.h"
20 #include "ui/views/controls/button/menu_button.h"
21 #include "ui/views/controls/button/menu_button_listener.h"
22 #include "ui/views/view.h"
25 class BrowserActionsContainer;
31 class WrenchMenuModel;
32 class WrenchToolbarButton;
34 namespace extensions {
37 class ExtensionMessageBubbleFactory;
44 // The Browser Window's toolbar.
45 class ToolbarView : public views::AccessiblePaneView,
46 public views::MenuButtonListener,
47 public ui::AcceleratorProvider,
48 public LocationBarView::Delegate,
49 public content::NotificationObserver,
50 public CommandObserver,
51 public views::ButtonListener,
52 public views::WidgetObserver,
53 public views::ViewTargeterDelegate,
54 public WrenchMenuBadgeController::Delegate {
56 // The view class name.
57 static const char kViewClassName[];
59 explicit ToolbarView(Browser* browser);
60 virtual ~ToolbarView();
62 // Create the contents of the Browser Toolbar.
65 // Forces the toolbar (and transitively the location bar) to update its
66 // current state. If |tab| is non-NULL, we're switching (back?) to this tab
67 // and should restore any previous location bar state (such as user editing)
69 void Update(content::WebContents* tab);
71 // Set focus to the toolbar with complete keyboard access, with the
72 // focus initially set to the app menu. Focus will be restored
73 // to the last focused view if the user escapes.
74 void SetPaneFocusAndFocusAppMenu();
76 // Returns true if the app menu is focused.
77 bool IsAppMenuFocused();
79 // Add a listener to receive a callback when the menu opens.
80 void AddMenuListener(views::MenuListener* listener);
82 // Remove a menu listener.
83 void RemoveMenuListener(views::MenuListener* listener);
85 virtual bool GetAcceleratorInfo(int id, ui::Accelerator* accel);
87 // Returns the view to which the bookmark bubble should be anchored.
88 views::View* GetBookmarkBubbleAnchor();
90 // Returns the view to which the Translate bubble should be anchored.
91 views::View* GetTranslateBubbleAnchor();
93 // Executes |command| registered by |extension|.
94 void ExecuteExtensionCommand(const extensions::Extension* extension,
95 const extensions::Command& command);
97 // Shows the app (wrench) menu. |for_drop| indicates whether the menu is
98 // opened for a drag-and-drop operation.
99 void ShowAppMenu(bool for_drop);
102 Browser* browser() const { return browser_; }
103 BrowserActionsContainer* browser_actions() const { return browser_actions_; }
104 ReloadButton* reload_button() const { return reload_; }
105 LocationBarView* location_bar() const { return location_bar_; }
106 views::MenuButton* app_menu() const;
107 HomeButton* home_button() const { return home_; }
109 // AccessiblePaneView:
110 virtual bool SetPaneFocus(View* initial_focus) OVERRIDE;
111 virtual void GetAccessibleState(ui::AXViewState* state) OVERRIDE;
113 // views::MenuButtonListener:
114 virtual void OnMenuButtonClicked(views::View* source,
115 const gfx::Point& point) OVERRIDE;
117 // LocationBarView::Delegate:
118 virtual content::WebContents* GetWebContents() OVERRIDE;
119 virtual ToolbarModel* GetToolbarModel() OVERRIDE;
120 virtual const ToolbarModel* GetToolbarModel() const OVERRIDE;
121 virtual InstantController* GetInstant() OVERRIDE;
122 virtual views::Widget* CreateViewsBubble(
123 views::BubbleDelegateView* bubble_delegate) OVERRIDE;
124 virtual PageActionImageView* CreatePageActionImageView(
125 LocationBarView* owner, ExtensionAction* action) OVERRIDE;
126 virtual ContentSettingBubbleModelDelegate*
127 GetContentSettingBubbleModelDelegate() OVERRIDE;
128 virtual void ShowWebsiteSettings(content::WebContents* web_contents,
130 const content::SSLStatus& ssl) OVERRIDE;
133 virtual void EnabledStateChangedForCommand(int id, bool enabled) OVERRIDE;
135 // views::ButtonListener:
136 virtual void ButtonPressed(views::Button* sender,
137 const ui::Event& event) OVERRIDE;
139 // views::WidgetObserver:
140 virtual void OnWidgetVisibilityChanged(views::Widget* widget,
141 bool visible) OVERRIDE;
142 virtual void OnWidgetActivationChanged(views::Widget* widget,
143 bool active) OVERRIDE;
145 // content::NotificationObserver:
146 virtual void Observe(int type,
147 const content::NotificationSource& source,
148 const content::NotificationDetails& details) OVERRIDE;
150 // ui::AcceleratorProvider:
151 virtual bool GetAcceleratorForCommandId(
152 int command_id, ui::Accelerator* accelerator) OVERRIDE;
155 virtual gfx::Size GetPreferredSize() const OVERRIDE;
156 virtual gfx::Size GetMinimumSize() const OVERRIDE;
157 virtual void Layout() OVERRIDE;
158 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
159 virtual void OnThemeChanged() OVERRIDE;
160 virtual const char* GetClassName() const OVERRIDE;
161 virtual bool AcceleratorPressed(const ui::Accelerator& acc) OVERRIDE;
163 // Whether the wrench/hotdogs menu is currently showing.
164 bool IsWrenchMenuShowing() const;
166 // Whether the toolbar view needs its background painted by the
167 // BrowserNonClientFrameView.
168 bool ShouldPaintBackground() const;
171 // The apparent horizontal space between most items, and the vertical
172 // padding above and below them.
173 kStandardSpacing = 3,
175 // The top of the toolbar has an edge we have to skip over in addition to
176 // the standard spacing.
181 // AccessiblePaneView:
182 virtual bool SetPaneFocusAndFocusDefault() OVERRIDE;
183 virtual void RemovePaneFocus() OVERRIDE;
186 // Types of display mode this toolbar can have.
188 DISPLAYMODE_NORMAL, // Normal toolbar with buttons, etc.
189 DISPLAYMODE_LOCATION // Slimline toolbar showing only compact location
190 // bar, used for popups.
193 // views::ViewTargeterDelegate:
194 virtual bool DoesIntersectRect(const views::View* target,
195 const gfx::Rect& rect) const OVERRIDE;
197 // WrenchMenuBadgeController::Delegate:
198 virtual void UpdateBadgeSeverity(WrenchMenuBadgeController::BadgeType type,
199 WrenchIconPainter::Severity severity,
200 bool animate) OVERRIDE;
202 // Returns the number of pixels above the location bar in non-normal display.
203 int PopupTopSpacing() const;
205 // Given toolbar contents of size |size|, returns the total toolbar size.
206 gfx::Size SizeForContentSize(gfx::Size size) const;
208 // Loads the images for all the child views.
211 bool is_display_mode_normal() const {
212 return display_mode_ == DISPLAYMODE_NORMAL;
215 // Shows the critical notification bubble against the wrench menu.
216 void ShowCriticalNotification();
218 // Shows the outdated install notification bubble against the wrench menu.
219 // |auto_update_enabled| is set to true when auto-upate is on.
220 void ShowOutdatedInstallNotification(bool auto_update_enabled);
222 void OnShowHomeButtonChanged();
224 int content_shadow_height() const;
228 ToolbarButton* forward_;
229 ReloadButton* reload_;
231 LocationBarView* location_bar_;
232 BrowserActionsContainer* browser_actions_;
233 WrenchToolbarButton* app_menu_;
236 WrenchMenuBadgeController badge_controller_;
238 // Controls whether or not a home button should be shown on the toolbar.
239 BooleanPrefMember show_home_button_;
241 // The display mode used when laying out the toolbar.
242 DisplayMode display_mode_;
244 // Wrench model and menu.
245 // Note that the menu should be destroyed before the model it uses, so the
246 // menu should be listed later.
247 scoped_ptr<WrenchMenuModel> wrench_menu_model_;
248 scoped_ptr<WrenchMenu> wrench_menu_;
250 // The factory to create bubbles to warn about dangerous/suspicious
252 scoped_ptr<extensions::ExtensionMessageBubbleFactory>
253 extension_message_bubble_factory_;
255 // A list of listeners to call when the menu opens.
256 ObserverList<views::MenuListener> menu_listeners_;
258 content::NotificationRegistrar registrar_;
260 DISALLOW_IMPLICIT_CONSTRUCTORS(ToolbarView);
263 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_TOOLBAR_VIEW_H_