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/views/location_bar/location_bar_view.h"
17 #include "ui/base/accelerators/accelerator.h"
18 #include "ui/views/accessible_pane_view.h"
19 #include "ui/views/controls/button/menu_button.h"
20 #include "ui/views/controls/button/menu_button_listener.h"
21 #include "ui/views/view.h"
24 class BrowserActionsContainer
;
30 class WrenchMenuModel
;
31 class WrenchToolbarButton
;
33 namespace extensions
{
36 class ExtensionMessageBubbleFactory
;
43 // The Browser Window's toolbar.
44 class ToolbarView
: public views::AccessiblePaneView
,
45 public views::MenuButtonListener
,
46 public ui::AcceleratorProvider
,
47 public LocationBarView::Delegate
,
48 public content::NotificationObserver
,
49 public CommandObserver
,
50 public views::ButtonListener
,
51 public views::WidgetObserver
{
53 // The view class name.
54 static const char kViewClassName
[];
56 explicit ToolbarView(Browser
* browser
);
57 virtual ~ToolbarView();
59 // Create the contents of the Browser Toolbar.
62 // Forces the toolbar (and transitively the location bar) to update its
63 // current state. If |tab| is non-NULL, we're switching (back?) to this tab
64 // and should restore any previous location bar state (such as user editing)
66 void Update(content::WebContents
* tab
);
68 // Set focus to the toolbar with complete keyboard access, with the
69 // focus initially set to the app menu. Focus will be restored
70 // to the last focused view if the user escapes.
71 void SetPaneFocusAndFocusAppMenu();
73 // Returns true if the app menu is focused.
74 bool IsAppMenuFocused();
76 // Add a listener to receive a callback when the menu opens.
77 void AddMenuListener(views::MenuListener
* listener
);
79 // Remove a menu listener.
80 void RemoveMenuListener(views::MenuListener
* listener
);
82 virtual bool GetAcceleratorInfo(int id
, ui::Accelerator
* accel
);
84 // Returns the view to which the bookmark bubble should be anchored.
85 views::View
* GetBookmarkBubbleAnchor();
87 // Returns the view to which the Translate bubble should be anchored.
88 views::View
* GetTranslateBubbleAnchor();
90 // Executes |command| registered by |extension|.
91 void ExecuteExtensionCommand(const extensions::Extension
* extension
,
92 const extensions::Command
& command
);
94 // Shows the extension's page action, if present.
95 void ShowPageActionPopup(const extensions::Extension
* extension
);
97 // Shows the extension's browser action, if present.
98 void ShowBrowserActionPopup(const extensions::Extension
* extension
);
101 Browser
* browser() const { return browser_
; }
102 BrowserActionsContainer
* browser_actions() const { return browser_actions_
; }
103 ReloadButton
* reload_button() const { return reload_
; }
104 LocationBarView
* location_bar() const { return location_bar_
; }
105 views::MenuButton
* app_menu() const;
106 HomeButton
* home_button() const { return home_
; }
108 // Overridden from AccessiblePaneView
109 virtual bool SetPaneFocus(View
* initial_focus
) OVERRIDE
;
110 virtual void GetAccessibleState(ui::AXViewState
* state
) OVERRIDE
;
112 // Overridden from views::MenuButtonListener:
113 virtual void OnMenuButtonClicked(views::View
* source
,
114 const gfx::Point
& point
) OVERRIDE
;
116 // Overridden from LocationBarView::Delegate:
117 virtual content::WebContents
* GetWebContents() OVERRIDE
;
118 virtual ToolbarModel
* GetToolbarModel() OVERRIDE
;
119 virtual const ToolbarModel
* GetToolbarModel() const OVERRIDE
;
120 virtual InstantController
* GetInstant() OVERRIDE
;
121 virtual views::Widget
* CreateViewsBubble(
122 views::BubbleDelegateView
* bubble_delegate
) OVERRIDE
;
123 virtual PageActionImageView
* CreatePageActionImageView(
124 LocationBarView
* owner
, ExtensionAction
* action
) OVERRIDE
;
125 virtual ContentSettingBubbleModelDelegate
*
126 GetContentSettingBubbleModelDelegate() OVERRIDE
;
127 virtual void ShowWebsiteSettings(content::WebContents
* web_contents
,
129 const content::SSLStatus
& ssl
) OVERRIDE
;
131 // Overridden from CommandObserver:
132 virtual void EnabledStateChangedForCommand(int id
, bool enabled
) OVERRIDE
;
134 // Overridden from views::ButtonListener:
135 virtual void ButtonPressed(views::Button
* sender
,
136 const ui::Event
& event
) OVERRIDE
;
138 // Overridden from views::WidgetObserver:
139 virtual void OnWidgetVisibilityChanged(views::Widget
* widget
,
140 bool visible
) OVERRIDE
;
142 // Overridden from content::NotificationObserver:
143 virtual void Observe(int type
,
144 const content::NotificationSource
& source
,
145 const content::NotificationDetails
& details
) OVERRIDE
;
147 // Overridden from ui::AcceleratorProvider:
148 virtual bool GetAcceleratorForCommandId(
149 int command_id
, ui::Accelerator
* accelerator
) OVERRIDE
;
151 // Overridden from views::View:
152 virtual gfx::Size
GetPreferredSize() const OVERRIDE
;
153 virtual gfx::Size
GetMinimumSize() const OVERRIDE
;
154 virtual void Layout() OVERRIDE
;
155 virtual bool HitTestRect(const gfx::Rect
& rect
) const OVERRIDE
;
156 virtual void OnPaint(gfx::Canvas
* canvas
) OVERRIDE
;
157 virtual void OnThemeChanged() OVERRIDE
;
158 virtual const char* GetClassName() const OVERRIDE
;
159 virtual bool AcceleratorPressed(const ui::Accelerator
& acc
) OVERRIDE
;
161 // Whether the wrench/hotdogs menu is currently showing.
162 bool IsWrenchMenuShowing() const;
164 // Whether the toolbar view needs its background painted by the
165 // BrowserNonClientFrameView.
166 bool ShouldPaintBackground() const;
169 // The apparent horizontal space between most items, and the vertical
170 // padding above and below them.
171 kStandardSpacing
= 3,
173 // The top of the toolbar has an edge we have to skip over in addition to
174 // the standard spacing.
179 // Overridden from AccessiblePaneView
180 virtual bool SetPaneFocusAndFocusDefault() OVERRIDE
;
181 virtual void RemovePaneFocus() OVERRIDE
;
184 // Types of display mode this toolbar can have.
186 DISPLAYMODE_NORMAL
, // Normal toolbar with buttons, etc.
187 DISPLAYMODE_LOCATION
// Slimline toolbar showing only compact location
188 // bar, used for popups.
191 // Returns true if we should show the upgrade recommended dot.
192 bool ShouldShowUpgradeRecommended();
194 // Returns true if we should show the background page badge.
195 bool ShouldShowBackgroundPageBadge();
197 // Returns true if we should show the warning for incompatible software.
198 bool ShouldShowIncompatibilityWarning();
200 // Returns the number of pixels above the location bar in non-normal display.
201 int PopupTopSpacing() const;
203 // Given toolbar contents of size |size|, returns the total toolbar size.
204 gfx::Size
SizeForContentSize(gfx::Size size
) const;
206 // Loads the images for all the child views.
209 bool is_display_mode_normal() const {
210 return display_mode_
== DISPLAYMODE_NORMAL
;
213 // Shows the critical notification bubble against the wrench menu.
214 void ShowCriticalNotification();
216 // Shows the outdated install notification bubble against the wrench menu.
217 // |auto_update_enabled| is set to true when auto-upate is on.
218 void ShowOutdatedInstallNotification(bool auto_update_enabled
);
220 // Updates the badge and the accessible name of the app menu (Wrench).
221 void UpdateAppMenuState();
223 // Updates the severity level on the wrench menu button.
224 void UpdateWrenchButtonSeverity();
226 void OnShowHomeButtonChanged();
228 int content_shadow_height() const;
232 ToolbarButton
* forward_
;
233 ReloadButton
* reload_
;
235 LocationBarView
* location_bar_
;
236 BrowserActionsContainer
* browser_actions_
;
237 WrenchToolbarButton
* app_menu_
;
240 // Controls whether or not a home button should be shown on the toolbar.
241 BooleanPrefMember show_home_button_
;
243 // The display mode used when laying out the toolbar.
244 DisplayMode display_mode_
;
246 // Wrench model and menu.
247 // Note that the menu should be destroyed before the model it uses, so the
248 // menu should be listed later.
249 scoped_ptr
<WrenchMenuModel
> wrench_menu_model_
;
250 scoped_ptr
<WrenchMenu
> wrench_menu_
;
252 // The factory to create bubbles to warn about dangerous/suspicious
254 scoped_ptr
<extensions::ExtensionMessageBubbleFactory
>
255 extension_message_bubble_factory_
;
257 // A list of listeners to call when the menu opens.
258 ObserverList
<views::MenuListener
> menu_listeners_
;
260 content::NotificationRegistrar registrar_
;
262 DISALLOW_IMPLICIT_CONSTRUCTORS(ToolbarView
);
265 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_TOOLBAR_VIEW_H_