browser_frame.h revision 2a99a7e74a7f215066514fe81d2bfa6639d9eddd
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 "build/build_config.h"
11#include "chrome/browser/ui/views/frame/browser_non_client_frame_view.h"
12#include "ui/views/context_menu_controller.h"
13#include "ui/views/widget/widget.h"
14
15class AvatarMenuButton;
16class BrowserRootView;
17class BrowserView;
18class NativeBrowserFrame;
19class NonClientFrameView;
20class SystemMenuModelBuilder;
21
22namespace gfx {
23class Font;
24class Rect;
25}
26
27namespace ui {
28class MenuModel;
29class ThemeProvider;
30}
31
32namespace views {
33class MenuRunner;
34class View;
35}
36
37// This is a virtual interface that allows system specific browser frames.
38class BrowserFrame
39    : public views::Widget,
40      public views::ContextMenuController {
41 public:
42  explicit BrowserFrame(BrowserView* browser_view);
43  virtual ~BrowserFrame();
44
45  static const gfx::Font& GetTitleFont();
46
47  // Initialize the frame (creates the underlying native window).
48  void InitBrowserFrame();
49
50  // Sets the ThemeProvider returned from GetThemeProvider().
51  void SetThemeProvider(scoped_ptr<ui::ThemeProvider> provider);
52
53  // Determine the distance of the left edge of the minimize button from the
54  // left edge of the window. Used in our Non-Client View's Layout.
55  int GetMinimizeButtonOffset() const;
56
57  // Retrieves the bounds, in non-client view coordinates for the specified
58  // TabStrip view.
59  gfx::Rect GetBoundsForTabStrip(views::View* tabstrip) const;
60
61  // Returns the y coordinate within the window at which the horizontal TabStrip
62  // begins (or would begin).  If |force_restored| is true, this is calculated
63  // as if we were in restored mode regardless of the current mode.
64  BrowserNonClientFrameView::TabStripInsets GetTabStripInsets(
65      bool force_restored) const;
66
67  // Returns the amount that the theme background should be inset.
68  int GetThemeBackgroundXInset() const;
69
70  // Tells the frame to update the throbber.
71  void UpdateThrobber(bool running);
72
73  // Returns the NonClientFrameView of this frame.
74  views::View* GetFrameView() const;
75
76  // Notifies the frame that the tab strip display mode changed so it can update
77  // its frame treatment if necessary.
78  void TabStripDisplayModeChanged();
79
80  // Overridden from views::Widget:
81  virtual views::internal::RootView* CreateRootView() OVERRIDE;
82  virtual views::NonClientFrameView* CreateNonClientFrameView() OVERRIDE;
83  virtual bool GetAccelerator(int command_id,
84                              ui::Accelerator* accelerator) OVERRIDE;
85  virtual ui::ThemeProvider* GetThemeProvider() const OVERRIDE;
86  virtual void OnNativeWidgetActivationChanged(bool active) OVERRIDE;
87
88  // Overridden from views::ContextMenuController:
89  virtual void ShowContextMenuForView(views::View* source,
90                                      const gfx::Point& p) OVERRIDE;
91
92  // Returns true if we should leave any offset at the frame caption. Typically
93  // when the frame is maximized/full screen we want to leave no offset at the
94  // top.
95  bool ShouldLeaveOffsetNearTopBorder();
96
97  AvatarMenuButton* GetAvatarMenuButton();
98
99  // Returns the menu model. BrowserFrame owns the returned model.
100  ui::MenuModel* GetSystemMenuModel();
101
102 private:
103  NativeBrowserFrame* native_browser_frame_;
104
105  // A weak reference to the root view associated with the window. We save a
106  // copy as a BrowserRootView to avoid evil casting later, when we need to call
107  // functions that only exist on BrowserRootView (versus RootView).
108  BrowserRootView* root_view_;
109
110  // A pointer to our NonClientFrameView as a BrowserNonClientFrameView.
111  BrowserNonClientFrameView* browser_frame_view_;
112
113  // The BrowserView is our ClientView. This is a pointer to it.
114  BrowserView* browser_view_;
115
116  scoped_ptr<SystemMenuModelBuilder> menu_model_builder_;
117
118  // Used to show the system menu. Only used if
119  // NativeBrowserFrame::UsesNativeSystemMenu() returns false.
120  scoped_ptr<views::MenuRunner> menu_runner_;
121
122  // SetThemeProvider() triggers setting both |owned_theme_provider_| and
123  // |theme_provider_|. Initially |theme_provider_| is set to the ThemeService
124  // and |owned_theme_provider_| is NULL (as ThemeServices lifetime is managed
125  // externally).
126  scoped_ptr<ui::ThemeProvider> owned_theme_provider_;
127  ui::ThemeProvider* theme_provider_;
128
129  DISALLOW_COPY_AND_ASSIGN(BrowserFrame);
130};
131
132#endif  // CHROME_BROWSER_UI_VIEWS_FRAME_BROWSER_FRAME_H_
133