Add a minor text member to ui::MenuModel.
[chromium-blink-merge.git] / chrome / browser / ui / views / toolbar_view.h
blob9bf3cc4d79f65c8d74317cf41de5889c094a2a14
1 // Copyright (c) 2012 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_VIEW_H_
6 #define CHROME_BROWSER_UI_VIEWS_TOOLBAR_VIEW_H_
8 #include <set>
9 #include <string>
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 "chrome/browser/ui/views/reload_button.h"
18 #include "ui/base/accelerators/accelerator.h"
19 #include "ui/base/animation/slide_animation.h"
20 #include "ui/views/accessible_pane_view.h"
21 #include "ui/views/controls/button/menu_button.h"
22 #include "ui/views/controls/button/menu_button_listener.h"
23 #include "ui/views/view.h"
25 class BrowserActionsContainer;
26 class Browser;
27 class HomeImageButton;
28 class WrenchMenu;
29 class WrenchMenuModel;
30 class WrenchToolbarButton;
32 namespace views {
33 class MenuListener;
36 // The Browser Window's toolbar.
37 class ToolbarView : public views::AccessiblePaneView,
38 public views::MenuButtonListener,
39 public ui::AcceleratorProvider,
40 public LocationBarView::Delegate,
41 public content::NotificationObserver,
42 public CommandObserver,
43 public views::ButtonListener,
44 public views::WidgetObserver {
45 public:
46 // The view class name.
47 static const char kViewClassName[];
49 explicit ToolbarView(Browser* browser);
50 virtual ~ToolbarView();
52 // Create the contents of the Browser Toolbar.
53 void Init();
55 // Forces the toolbar (and transitively the location bar) to update its
56 // current state. If |tab| is non-NULL, we're switching (back?) to this tab
57 // and should restore any previous location bar state (such as user editing)
58 // as well.
59 void Update(content::WebContents* tab);
61 // Set focus to the toolbar with complete keyboard access, with the
62 // focus initially set to the app menu. Focus will be restored
63 // to the last focused view if the user escapes.
64 void SetPaneFocusAndFocusAppMenu();
66 // Returns true if the app menu is focused.
67 bool IsAppMenuFocused();
69 // Add a listener to receive a callback when the menu opens.
70 void AddMenuListener(views::MenuListener* listener);
72 // Remove a menu listener.
73 void RemoveMenuListener(views::MenuListener* listener);
75 virtual bool GetAcceleratorInfo(int id, ui::Accelerator* accel);
77 // Returns the view to which the bookmark bubble should be anchored.
78 views::View* GetBookmarkBubbleAnchor();
80 // Accessors...
81 Browser* browser() const { return browser_; }
82 BrowserActionsContainer* browser_actions() const { return browser_actions_; }
83 ReloadButton* reload_button() const { return reload_; }
84 LocationBarView* location_bar() const { return location_bar_; }
85 views::MenuButton* app_menu() const;
87 // Overridden from AccessiblePaneView
88 virtual bool SetPaneFocus(View* initial_focus) OVERRIDE;
89 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE;
91 // Overridden from views::MenuButtonListener:
92 virtual void OnMenuButtonClicked(views::View* source,
93 const gfx::Point& point) OVERRIDE;
95 // Overridden from LocationBarView::Delegate:
96 virtual content::WebContents* GetWebContents() OVERRIDE;
97 virtual ToolbarModel* GetToolbarModel() OVERRIDE;
98 virtual const ToolbarModel* GetToolbarModel() const OVERRIDE;
99 virtual InstantController* GetInstant() OVERRIDE;
100 virtual views::Widget* CreateViewsBubble(
101 views::BubbleDelegateView* bubble_delegate) OVERRIDE;
102 virtual PageActionImageView* CreatePageActionImageView(
103 LocationBarView* owner, ExtensionAction* action) OVERRIDE;
104 virtual ContentSettingBubbleModelDelegate*
105 GetContentSettingBubbleModelDelegate() OVERRIDE;
106 virtual void ShowWebsiteSettings(content::WebContents* web_contents,
107 const GURL& url,
108 const content::SSLStatus& ssl) OVERRIDE;
109 virtual void OnInputInProgress(bool in_progress) OVERRIDE;
111 // Overridden from CommandObserver:
112 virtual void EnabledStateChangedForCommand(int id, bool enabled) OVERRIDE;
114 // Overridden from views::ButtonListener:
115 virtual void ButtonPressed(views::Button* sender,
116 const ui::Event& event) OVERRIDE;
118 // Overridden from content::NotificationObserver:
119 virtual void Observe(int type,
120 const content::NotificationSource& source,
121 const content::NotificationDetails& details) OVERRIDE;
123 // Overridden from ui::AcceleratorProvider:
124 virtual bool GetAcceleratorForCommandId(
125 int command_id, ui::Accelerator* accelerator) OVERRIDE;
127 // Overridden from views::View:
128 virtual gfx::Size GetPreferredSize() OVERRIDE;
129 virtual void Layout() OVERRIDE;
130 virtual bool HitTestRect(const gfx::Rect& rect) const OVERRIDE;
131 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
132 virtual bool GetDropFormats(
133 int* formats,
134 std::set<OSExchangeData::CustomFormat>* custom_formats) OVERRIDE;
135 virtual bool CanDrop(const ui::OSExchangeData& data) OVERRIDE;
136 virtual int OnDragUpdated(const ui::DropTargetEvent& event) OVERRIDE;
137 virtual int OnPerformDrop(const ui::DropTargetEvent& event) OVERRIDE;
138 virtual void OnThemeChanged() OVERRIDE;
139 virtual const char* GetClassName() const OVERRIDE;
140 virtual bool AcceleratorPressed(const ui::Accelerator& acc) OVERRIDE;
142 // Whether the wrench/hotdogs menu is currently showing.
143 bool IsWrenchMenuShowing() const;
145 // The apparent horizontal space between most items, and the vertical padding
146 // above and below them.
147 static const int kStandardSpacing;
148 // The top of the toolbar has an edge we have to skip over in addition to the
149 // standard spacing.
150 static const int kVertSpacing;
152 protected:
153 // Overridden from AccessiblePaneView
154 virtual bool SetPaneFocusAndFocusDefault() OVERRIDE;
155 virtual void RemovePaneFocus() OVERRIDE;
157 private:
158 // Types of display mode this toolbar can have.
159 enum DisplayMode {
160 DISPLAYMODE_NORMAL, // Normal toolbar with buttons, etc.
161 DISPLAYMODE_LOCATION // Slimline toolbar showing only compact location
162 // bar, used for popups.
165 // Returns true if we should show the upgrade recommended dot.
166 bool ShouldShowUpgradeRecommended();
168 // Returns true if we should show the background page badge.
169 bool ShouldShowBackgroundPageBadge();
171 // Returns true if we should show the warning for incompatible software.
172 bool ShouldShowIncompatibilityWarning();
174 // Returns the number of pixels above the location bar in non-normal display.
175 int PopupTopSpacing() const;
177 // Loads the images for all the child views.
178 void LoadImages();
180 bool is_display_mode_normal() const {
181 return display_mode_ == DISPLAYMODE_NORMAL;
184 // Shows the critical notification bubble against the wrench menu.
185 void ShowCriticalNotification();
187 // Shows the outdated install notification bubble against the wrench menu.
188 void ShowOutdatedInstallNotification();
190 // Updates the badge and the accessible name of the app menu (Wrench).
191 void UpdateAppMenuState();
193 // Updates the severity level on the wrench menu button.
194 void UpdateWrenchButtonSeverity();
196 void OnShowHomeButtonChanged();
198 int content_shadow_height() const;
200 // Controls
201 views::ImageButton* back_;
202 views::ImageButton* forward_;
203 ReloadButton* reload_;
204 HomeImageButton* home_;
205 LocationBarView* location_bar_;
206 BrowserActionsContainer* browser_actions_;
207 WrenchToolbarButton* app_menu_;
208 Browser* browser_;
210 // Controls whether or not a home button should be shown on the toolbar.
211 BooleanPrefMember show_home_button_;
213 // The display mode used when laying out the toolbar.
214 DisplayMode display_mode_;
216 // Wrench model and menu.
217 // Note that the menu should be destroyed before the model it uses, so the
218 // menu should be listed later.
219 scoped_ptr<WrenchMenuModel> wrench_menu_model_;
220 scoped_ptr<WrenchMenu> wrench_menu_;
222 // A list of listeners to call when the menu opens.
223 ObserverList<views::MenuListener> menu_listeners_;
225 content::NotificationRegistrar registrar_;
227 DISALLOW_IMPLICIT_CONSTRUCTORS(ToolbarView);
230 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_VIEW_H_