Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / views / toolbar / toolbar_view.h
blobd38aa17615eead1ef9ad1d675cad230dd5414807
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 <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 "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"
23 class BackButton;
24 class BrowserActionsContainer;
25 class Browser;
26 class HomeButton;
27 class ReloadButton;
28 class SiteChipView;
29 class ToolbarButton;
30 class WrenchMenu;
31 class WrenchMenuModel;
32 class WrenchToolbarButton;
34 namespace views {
35 class MenuListener;
38 // The Browser Window's toolbar.
39 class ToolbarView : public views::AccessiblePaneView,
40 public views::MenuButtonListener,
41 public ui::AcceleratorProvider,
42 public LocationBarView::Delegate,
43 public content::NotificationObserver,
44 public CommandObserver,
45 public views::ButtonListener,
46 public views::WidgetObserver {
47 public:
48 // The view class name.
49 static const char kViewClassName[];
51 explicit ToolbarView(Browser* browser);
52 virtual ~ToolbarView();
54 // Create the contents of the Browser Toolbar.
55 void Init();
57 // Forces the toolbar (and transitively the location bar) to update its
58 // current state. If |tab| is non-NULL, we're switching (back?) to this tab
59 // and should restore any previous location bar state (such as user editing)
60 // as well.
61 void Update(content::WebContents* tab);
63 // Set focus to the toolbar with complete keyboard access, with the
64 // focus initially set to the app menu. Focus will be restored
65 // to the last focused view if the user escapes.
66 void SetPaneFocusAndFocusAppMenu();
68 // Returns true if the app menu is focused.
69 bool IsAppMenuFocused();
71 // Add a listener to receive a callback when the menu opens.
72 void AddMenuListener(views::MenuListener* listener);
74 // Remove a menu listener.
75 void RemoveMenuListener(views::MenuListener* listener);
77 virtual bool GetAcceleratorInfo(int id, ui::Accelerator* accel);
79 // Returns the view to which the bookmark bubble should be anchored.
80 views::View* GetBookmarkBubbleAnchor();
82 // Returns the view to which the Translate bubble should be anchored.
83 views::View* GetTranslateBubbleAnchor();
85 // Accessors...
86 Browser* browser() const { return browser_; }
87 BrowserActionsContainer* browser_actions() const { return browser_actions_; }
88 ReloadButton* reload_button() const { return reload_; }
89 LocationBarView* location_bar() const { return location_bar_; }
90 SiteChipView* site_chip() const { return site_chip_view_; }
91 views::MenuButton* app_menu() const;
93 // Overridden from AccessiblePaneView
94 virtual bool SetPaneFocus(View* initial_focus) OVERRIDE;
95 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE;
97 // Overridden from views::MenuButtonListener:
98 virtual void OnMenuButtonClicked(views::View* source,
99 const gfx::Point& point) OVERRIDE;
101 // Overridden from LocationBarView::Delegate:
102 virtual content::WebContents* GetWebContents() OVERRIDE;
103 virtual ToolbarModel* GetToolbarModel() OVERRIDE;
104 virtual const ToolbarModel* GetToolbarModel() const OVERRIDE;
105 virtual InstantController* GetInstant() OVERRIDE;
106 virtual views::Widget* CreateViewsBubble(
107 views::BubbleDelegateView* bubble_delegate) OVERRIDE;
108 virtual PageActionImageView* CreatePageActionImageView(
109 LocationBarView* owner, ExtensionAction* action) OVERRIDE;
110 virtual ContentSettingBubbleModelDelegate*
111 GetContentSettingBubbleModelDelegate() OVERRIDE;
112 virtual void ShowWebsiteSettings(content::WebContents* web_contents,
113 const GURL& url,
114 const content::SSLStatus& ssl) OVERRIDE;
116 // Overridden from CommandObserver:
117 virtual void EnabledStateChangedForCommand(int id, bool enabled) OVERRIDE;
119 // Overridden from views::ButtonListener:
120 virtual void ButtonPressed(views::Button* sender,
121 const ui::Event& event) OVERRIDE;
123 // Overridden from views::WidgetObserver:
124 virtual void OnWidgetVisibilityChanged(views::Widget* widget,
125 bool visible) OVERRIDE;
127 // Overridden from content::NotificationObserver:
128 virtual void Observe(int type,
129 const content::NotificationSource& source,
130 const content::NotificationDetails& details) OVERRIDE;
132 // Overridden from ui::AcceleratorProvider:
133 virtual bool GetAcceleratorForCommandId(
134 int command_id, ui::Accelerator* accelerator) OVERRIDE;
136 // Overridden from views::View:
137 virtual gfx::Size GetPreferredSize() OVERRIDE;
138 virtual void Layout() OVERRIDE;
139 virtual bool HitTestRect(const gfx::Rect& rect) const OVERRIDE;
140 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
141 virtual void OnThemeChanged() OVERRIDE;
142 virtual const char* GetClassName() const OVERRIDE;
143 virtual bool AcceleratorPressed(const ui::Accelerator& acc) OVERRIDE;
145 // Whether the wrench/hotdogs menu is currently showing.
146 bool IsWrenchMenuShowing() const;
148 // Whether the toolbar view needs its background painted by the
149 // BrowserNonClientFrameView.
150 bool ShouldPaintBackground() const;
152 enum {
153 // The apparent horizontal space between most items, and the vertical
154 // padding above and below them.
155 kStandardSpacing = 3,
157 // The top of the toolbar has an edge we have to skip over in addition to
158 // the standard spacing.
159 kVertSpacing = 5,
162 protected:
163 // Overridden from AccessiblePaneView
164 virtual bool SetPaneFocusAndFocusDefault() OVERRIDE;
165 virtual void RemovePaneFocus() OVERRIDE;
167 private:
168 // Types of display mode this toolbar can have.
169 enum DisplayMode {
170 DISPLAYMODE_NORMAL, // Normal toolbar with buttons, etc.
171 DISPLAYMODE_LOCATION // Slimline toolbar showing only compact location
172 // bar, used for popups.
175 // Returns true if we should show the upgrade recommended dot.
176 bool ShouldShowUpgradeRecommended();
178 // Returns true if we should show the background page badge.
179 bool ShouldShowBackgroundPageBadge();
181 // Returns true if we should show the warning for incompatible software.
182 bool ShouldShowIncompatibilityWarning();
184 // Returns the number of pixels above the location bar in non-normal display.
185 int PopupTopSpacing() const;
187 // Loads the images for all the child views.
188 void LoadImages();
190 bool is_display_mode_normal() const {
191 return display_mode_ == DISPLAYMODE_NORMAL;
194 // Shows the critical notification bubble against the wrench menu.
195 void ShowCriticalNotification();
197 // Shows the outdated install notification bubble against the wrench menu.
198 void ShowOutdatedInstallNotification();
200 // Updates the badge and the accessible name of the app menu (Wrench).
201 void UpdateAppMenuState();
203 // Updates the severity level on the wrench menu button.
204 void UpdateWrenchButtonSeverity();
206 void OnShowHomeButtonChanged();
208 int content_shadow_height() const;
210 // Controls
211 BackButton* back_;
212 ToolbarButton* forward_;
213 ReloadButton* reload_;
214 HomeButton* home_;
215 LocationBarView* location_bar_;
216 SiteChipView* site_chip_view_;
217 BrowserActionsContainer* browser_actions_;
218 WrenchToolbarButton* app_menu_;
219 Browser* browser_;
221 // Controls whether or not a home button should be shown on the toolbar.
222 BooleanPrefMember show_home_button_;
224 // The display mode used when laying out the toolbar.
225 DisplayMode display_mode_;
227 // Wrench model and menu.
228 // Note that the menu should be destroyed before the model it uses, so the
229 // menu should be listed later.
230 scoped_ptr<WrenchMenuModel> wrench_menu_model_;
231 scoped_ptr<WrenchMenu> wrench_menu_;
233 // A list of listeners to call when the menu opens.
234 ObserverList<views::MenuListener> menu_listeners_;
236 content::NotificationRegistrar registrar_;
238 DISALLOW_IMPLICIT_CONSTRUCTORS(ToolbarView);
241 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_TOOLBAR_VIEW_H_