browser_frame.h revision 5d1f7b1de12d16ceb2c938c56701a3e8bfa558f7
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.
4
5#ifndef CHROME_BROWSER_UI_VIEWS_FRAME_BROWSER_FRAME_H_
6#define CHROME_BROWSER_UI_VIEWS_FRAME_BROWSER_FRAME_H_
7
8#include "base/compiler_specific.h"
9#include "base/logging.h"
10#include "base/prefs/pref_member.h"
11#include "build/build_config.h"
12#include "chrome/browser/ui/views/frame/browser_non_client_frame_view.h"
13#include "ui/views/context_menu_controller.h"
14#include "ui/views/widget/widget.h"
15
16class AvatarMenuButton;
17class BrowserRootView;
18class BrowserView;
19class NativeBrowserFrame;
20class NewAvatarButton;
21class NonClientFrameView;
22class SystemMenuModelBuilder;
23
24namespace gfx {
25class FontList;
26class Rect;
27}
28
29namespace ui {
30class MenuModel;
31class ThemeProvider;
32}
33
34namespace views {
35class MenuRunner;
36class View;
37}
38
39// This is a virtual interface that allows system specific browser frames.
40class BrowserFrame
41    : public views::Widget,
42      public views::ContextMenuController {
43 public:
44  explicit BrowserFrame(BrowserView* browser_view);
45  virtual ~BrowserFrame();
46
47  static const gfx::FontList& GetTitleFontList();
48
49  // Initialize the frame (creates the underlying native window).
50  void InitBrowserFrame();
51
52  // Sets the ThemeProvider returned from GetThemeProvider().
53  void SetThemeProvider(scoped_ptr<ui::ThemeProvider> provider);
54
55  // Determine the distance of the left edge of the minimize button from the
56  // left edge of the window. Used in our Non-Client View's Layout.
57  int GetMinimizeButtonOffset() const;
58
59  // Retrieves the bounds, in non-client view coordinates for the specified
60  // TabStrip view.
61  gfx::Rect GetBoundsForTabStrip(views::View* tabstrip) const;
62
63  // Returns the inset of the topmost view in the client view from the top of
64  // the non-client view. The topmost view depends on the window type. The
65  // topmost view is the tab strip for tabbed browser windows, the toolbar for
66  // popups, the web contents for app windows and varies for fullscreen windows
67  int GetTopInset() const;
68
69  // Returns the amount that the theme background should be inset.
70  int GetThemeBackgroundXInset() const;
71
72  // Tells the frame to update the throbber.
73  void UpdateThrobber(bool running);
74
75  // Returns the NonClientFrameView of this frame.
76  views::View* GetFrameView() const;
77
78  // Returns |true| if we should use the custom frame.
79  bool UseCustomFrame() const;
80
81  // Overridden from views::Widget:
82  virtual views::internal::RootView* CreateRootView() OVERRIDE;
83  virtual views::NonClientFrameView* CreateNonClientFrameView() OVERRIDE;
84  virtual bool GetAccelerator(int command_id,
85                              ui::Accelerator* accelerator) OVERRIDE;
86  virtual ui::ThemeProvider* GetThemeProvider() const OVERRIDE;
87  virtual void SchedulePaintInRect(const gfx::Rect& rect) OVERRIDE;
88  virtual void OnNativeWidgetActivationChanged(bool active) OVERRIDE;
89
90  // Overridden from views::ContextMenuController:
91  virtual void ShowContextMenuForView(views::View* source,
92                                      const gfx::Point& p,
93                                      ui::MenuSourceType source_type) OVERRIDE;
94
95  // Returns true if we should leave any offset at the frame caption. Typically
96  // when the frame is maximized/full screen we want to leave no offset at the
97  // top.
98  bool ShouldLeaveOffsetNearTopBorder();
99
100  AvatarMenuButton* GetAvatarMenuButton();
101
102  NewAvatarButton* GetNewAvatarMenuButton();
103
104  // Returns the menu model. BrowserFrame owns the returned model.
105  // Note that in multi user mode this will upon each call create a new model.
106  ui::MenuModel* GetSystemMenuModel();
107
108 private:
109  // Called when the preference changes.
110  void OnUseCustomChromeFrameChanged();
111
112  NativeBrowserFrame* native_browser_frame_;
113
114  // A weak reference to the root view associated with the window. We save a
115  // copy as a BrowserRootView to avoid evil casting later, when we need to call
116  // functions that only exist on BrowserRootView (versus RootView).
117  BrowserRootView* root_view_;
118
119  // A pointer to our NonClientFrameView as a BrowserNonClientFrameView.
120  BrowserNonClientFrameView* browser_frame_view_;
121
122  // The BrowserView is our ClientView. This is a pointer to it.
123  BrowserView* browser_view_;
124
125  scoped_ptr<SystemMenuModelBuilder> menu_model_builder_;
126
127  // Used to show the system menu. Only used if
128  // NativeBrowserFrame::UsesNativeSystemMenu() returns false.
129  scoped_ptr<views::MenuRunner> menu_runner_;
130
131  // SetThemeProvider() triggers setting both |owned_theme_provider_| and
132  // |theme_provider_|. Initially |theme_provider_| is set to the ThemeService
133  // and |owned_theme_provider_| is NULL (as ThemeServices lifetime is managed
134  // externally).
135  scoped_ptr<ui::ThemeProvider> owned_theme_provider_;
136  ui::ThemeProvider* theme_provider_;
137
138  // Whether the custom Chrome frame preference is set.
139  BooleanPrefMember use_custom_frame_pref_;
140
141  DISALLOW_COPY_AND_ASSIGN(BrowserFrame);
142};
143
144#endif  // CHROME_BROWSER_UI_VIEWS_FRAME_BROWSER_FRAME_H_
145