diff options
author | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-11 02:56:32 +0000 |
---|---|---|
committer | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-11 02:56:32 +0000 |
commit | eaf001143552fc19fba063c1b179d92cc35a2b43 (patch) | |
tree | 88f0dc0f0ea98ede7ce374c590ba982a46478fee | |
parent | 0e7e8c0e6ee3def09065c18385daa0fce8f45ff8 (diff) | |
download | chromium_src-eaf001143552fc19fba063c1b179d92cc35a2b43.zip chromium_src-eaf001143552fc19fba063c1b179d92cc35a2b43.tar.gz chromium_src-eaf001143552fc19fba063c1b179d92cc35a2b43.tar.bz2 |
Make BrowserFrame concrete, create NativeBrowserFrame and NativeBrowserFrameDelegate.
BUG=72040
TEST=none
TBR=sky
Review URL: http://codereview.chromium.org/6677003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@77773 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/ui/views/frame/browser_frame.h | 53 | ||||
-rw-r--r-- | chrome/browser/ui/views/frame/browser_frame_gtk.cc | 49 | ||||
-rw-r--r-- | chrome/browser/ui/views/frame/browser_frame_gtk.h | 33 | ||||
-rw-r--r-- | chrome/browser/ui/views/frame/browser_frame_win.cc | 144 | ||||
-rw-r--r-- | chrome/browser/ui/views/frame/browser_frame_win.h | 30 | ||||
-rw-r--r-- | chrome/chrome_browser.gypi | 3 | ||||
-rw-r--r-- | views/window/native_window.h | 11 | ||||
-rw-r--r-- | views/window/window_gtk.cc | 4 | ||||
-rw-r--r-- | views/window/window_gtk.h | 1 |
9 files changed, 193 insertions, 135 deletions
diff --git a/chrome/browser/ui/views/frame/browser_frame.h b/chrome/browser/ui/views/frame/browser_frame.h index 3be0ddd..d58a16a 100644 --- a/chrome/browser/ui/views/frame/browser_frame.h +++ b/chrome/browser/ui/views/frame/browser_frame.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -6,33 +6,32 @@ #define CHROME_BROWSER_UI_VIEWS_FRAME_BROWSER_FRAME_H_ #pragma once +#include "base/logging.h" #include "build/build_config.h" -#include "views/window/non_client_view.h" +#include "chrome/browser/ui/views/frame/native_browser_frame_delegate.h" class BrowserView; +class NativeBrowserFrame; class Profile; namespace gfx { class Font; class Rect; -} // namespace gfx +} namespace ui { class ThemeProvider; } namespace views { +class View; class Window; - -#if defined(OS_WIN) -class WindowWin; -#endif -} // namespace views +} // This is a virtual interface that allows system specific browser frames. -class BrowserFrame { +class BrowserFrame : public NativeBrowserFrameDelegate { public: - virtual ~BrowserFrame() {} + virtual ~BrowserFrame(); // Creates the appropriate BrowserFrame for this platform. The returned // object is owned by the caller. @@ -40,40 +39,54 @@ class BrowserFrame { static const gfx::Font& GetTitleFont(); - // Returns the Window associated with this frame. Guraranteed non-NULL after + // Returns the Window associated with this frame. Guaranteed non-NULL after // construction. - virtual views::Window* GetWindow() = 0; + views::Window* GetWindow(); // Determine the distance of the left edge of the minimize button from the // left edge of the window. Used in our Non-Client View's Layout. - virtual int GetMinimizeButtonOffset() const = 0; + int GetMinimizeButtonOffset() const; // Retrieves the bounds, in non-client view coordinates for the specified // TabStrip view. - virtual gfx::Rect GetBoundsForTabStrip(views::View* tabstrip) const = 0; + gfx::Rect GetBoundsForTabStrip(views::View* tabstrip) const; // Returns the y coordinate within the window at which the horizontal TabStrip // begins (or would begin). If |restored| is true, this is calculated as if // we were in restored mode regardless of the current mode. - virtual int GetHorizontalTabStripVerticalOffset(bool restored) const = 0; + int GetHorizontalTabStripVerticalOffset(bool restored) const; // Tells the frame to update the throbber. - virtual void UpdateThrobber(bool running) = 0; + void UpdateThrobber(bool running); // Returns the theme provider for this frame. - virtual ui::ThemeProvider* GetThemeProviderForFrame() const = 0; + ui::ThemeProvider* GetThemeProviderForFrame() const; // Returns true if the window should use the native frame view. This is true // if there are no themes applied on Vista, or if there are themes applied and // this browser window is an app or popup. - virtual bool AlwaysUseNativeFrame() const = 0; + bool AlwaysUseNativeFrame() const; // Returns the NonClientFrameView of this frame. - virtual views::View* GetFrameView() const = 0; + views::View* GetFrameView() const; // Notifies the frame that the tab strip display mode changed so it can update // its frame treatment if necessary. - virtual void TabStripDisplayModeChanged() = 0; + void TabStripDisplayModeChanged(); + + protected: + // TODO(beng): Temporarily provided as a way to associate the subclass' + // implementation of NativeBrowserFrame with this. + void set_native_browser_frame(NativeBrowserFrame* native_browser_frame) { + native_browser_frame_ = native_browser_frame; + } + + BrowserFrame(); + + private: + NativeBrowserFrame* native_browser_frame_; + + DISALLOW_COPY_AND_ASSIGN(BrowserFrame); }; #endif // CHROME_BROWSER_UI_VIEWS_FRAME_BROWSER_FRAME_H_ diff --git a/chrome/browser/ui/views/frame/browser_frame_gtk.cc b/chrome/browser/ui/views/frame/browser_frame_gtk.cc index 6c8da688..b7d3888 100644 --- a/chrome/browser/ui/views/frame/browser_frame_gtk.cc +++ b/chrome/browser/ui/views/frame/browser_frame_gtk.cc @@ -38,6 +38,7 @@ BrowserFrameGtk::BrowserFrameGtk(BrowserView* browser_view, Profile* profile) browser_frame_view_(NULL), root_view_(NULL), profile_(profile) { + set_native_browser_frame(this); browser_view_->set_frame(this); } @@ -54,7 +55,33 @@ void BrowserFrameGtk::InitBrowserFrame() { // Don't focus anything on creation, selecting a tab will set the focus. } -views::Window* BrowserFrameGtk::GetWindow() { +ThemeProvider* BrowserFrameGtk::GetThemeProvider() const { + return profile_->GetThemeProvider(); +} + +views::RootView* BrowserFrameGtk::CreateRootView() { + root_view_ = new BrowserRootView(browser_view_, this); + return root_view_; +} + +void BrowserFrameGtk::IsActiveChanged() { + GetRootView()->SchedulePaint(); + browser_view_->ActivationChanged(IsActive()); + views::WidgetGtk::IsActiveChanged(); +} + +void BrowserFrameGtk::SetInitialFocus() { + browser_view_->RestoreFocus(); +} + +//////////////////////////////////////////////////////////////////////////////// +// BrowserFrameGtk, NativeBrowserFrame implementation: + +views::NativeWindow* BrowserFrameGtk::AsNativeWindow() { + return this; +} + +const views::NativeWindow* BrowserFrameGtk::AsNativeWindow() const { return this; } @@ -97,24 +124,8 @@ void BrowserFrameGtk::TabStripDisplayModeChanged() { GetRootView()->Layout(); } -ThemeProvider* BrowserFrameGtk::GetThemeProvider() const { - return profile_->GetThemeProvider(); -} - -views::RootView* BrowserFrameGtk::CreateRootView() { - root_view_ = new BrowserRootView(browser_view_, this); - return root_view_; -} - -void BrowserFrameGtk::IsActiveChanged() { - GetRootView()->SchedulePaint(); - browser_view_->ActivationChanged(IsActive()); - views::WidgetGtk::IsActiveChanged(); -} - -void BrowserFrameGtk::SetInitialFocus() { - browser_view_->RestoreFocus(); -} +//////////////////////////////////////////////////////////////////////////////// +// BrowserFrameGtk, private: bool BrowserFrameGtk::GetAccelerator(int cmd_id, ui::Accelerator* accelerator) { diff --git a/chrome/browser/ui/views/frame/browser_frame_gtk.h b/chrome/browser/ui/views/frame/browser_frame_gtk.h index 109a6a0..6bec934 100644 --- a/chrome/browser/ui/views/frame/browser_frame_gtk.h +++ b/chrome/browser/ui/views/frame/browser_frame_gtk.h @@ -8,13 +8,15 @@ #include "base/basictypes.h" #include "chrome/browser/ui/views/frame/browser_frame.h" +#include "chrome/browser/ui/views/frame/native_browser_frame.h" #include "views/window/window_gtk.h" class BrowserNonClientFrameView; class BrowserRootView; class BrowserFrameGtk : public BrowserFrame, - public views::WindowGtk { + public views::WindowGtk, + public NativeBrowserFrame { public: // Normally you will create this class by calling BrowserFrame::Create. // Init must be called before using this class, which Create will do for you. @@ -27,23 +29,24 @@ class BrowserFrameGtk : public BrowserFrame, // constructor. virtual void InitBrowserFrame(); - // Overridden from BrowserFrame: - virtual views::Window* GetWindow(); - virtual int GetMinimizeButtonOffset() const; - virtual gfx::Rect GetBoundsForTabStrip(views::View* tabstrip) const; - virtual int GetHorizontalTabStripVerticalOffset(bool restored) const; - virtual void UpdateThrobber(bool running); - virtual ui::ThemeProvider* GetThemeProviderForFrame() const; - virtual bool AlwaysUseNativeFrame() const; - virtual views::View* GetFrameView() const; - virtual void TabStripDisplayModeChanged(); - // Overridden from views::Widget: - virtual ui::ThemeProvider* GetThemeProvider() const; - virtual void IsActiveChanged(); - virtual void SetInitialFocus(); + virtual ui::ThemeProvider* GetThemeProvider() const OVERRIDE; + virtual void IsActiveChanged() OVERRIDE; + virtual void SetInitialFocus() OVERRIDE; protected: + // Overridden from NativeBrowserFrame: + virtual views::NativeWindow* AsNativeWindow() OVERRIDE; + virtual const views::NativeWindow* AsNativeWindow() const OVERRIDE; + virtual int GetMinimizeButtonOffset() const OVERRIDE; + virtual gfx::Rect GetBoundsForTabStrip(views::View* tabstrip) const OVERRIDE; + virtual int GetHorizontalTabStripVerticalOffset(bool restored) const OVERRIDE; + virtual void UpdateThrobber(bool running) OVERRIDE; + virtual ui::ThemeProvider* GetThemeProviderForFrame() const OVERRIDE; + virtual bool AlwaysUseNativeFrame() const OVERRIDE; + virtual views::View* GetFrameView() const OVERRIDE; + virtual void TabStripDisplayModeChanged() OVERRIDE; + void set_browser_frame_view(BrowserNonClientFrameView* browser_frame_view) { browser_frame_view_ = browser_frame_view; } diff --git a/chrome/browser/ui/views/frame/browser_frame_win.cc b/chrome/browser/ui/views/frame/browser_frame_win.cc index 139007a..a51eb25 100644 --- a/chrome/browser/ui/views/frame/browser_frame_win.cc +++ b/chrome/browser/ui/views/frame/browser_frame_win.cc @@ -47,7 +47,9 @@ BrowserFrame* BrowserFrame::Create(BrowserView* browser_view, BrowserFrameWin::BrowserFrameWin(BrowserView* browser_view, Profile* profile) : WindowWin(browser_view), browser_view_(browser_view), - root_view_(NULL) { + root_view_(NULL), + ALLOW_THIS_IN_INITIALIZER_LIST(delegate_(this)) { + set_native_browser_frame(this); browser_view_->set_frame(this); non_client_view()->SetFrameView(CreateFrameViewForWindow()); // Don't focus anything on creation, selecting a tab will set the focus. @@ -66,74 +68,6 @@ void BrowserFrameWin::SetShowState(int state) { explicit_show_state = state; } -//////////////////////////////////////////////////////////////////////////////// -// BrowserFrameWin, BrowserFrame implementation: - -views::Window* BrowserFrameWin::GetWindow() { - return this; -} - -int BrowserFrameWin::GetMinimizeButtonOffset() const { - TITLEBARINFOEX titlebar_info; - titlebar_info.cbSize = sizeof(TITLEBARINFOEX); - SendMessage(GetNativeView(), WM_GETTITLEBARINFOEX, 0, (WPARAM)&titlebar_info); - - CPoint minimize_button_corner(titlebar_info.rgrect[2].left, - titlebar_info.rgrect[2].top); - MapWindowPoints(HWND_DESKTOP, GetNativeView(), &minimize_button_corner, 1); - - return minimize_button_corner.x; -} - -gfx::Rect BrowserFrameWin::GetBoundsForTabStrip(views::View* tabstrip) const { - return browser_frame_view_->GetBoundsForTabStrip(tabstrip); -} - -int BrowserFrameWin::GetHorizontalTabStripVerticalOffset(bool restored) const { - return browser_frame_view_->GetHorizontalTabStripVerticalOffset(restored); -} - -void BrowserFrameWin::UpdateThrobber(bool running) { - browser_frame_view_->UpdateThrobber(running); -} - -ThemeProvider* BrowserFrameWin::GetThemeProviderForFrame() const { - // This is implemented for a different interface than GetThemeProvider is, - // but they mean the same things. - return GetThemeProvider(); -} - -bool BrowserFrameWin::AlwaysUseNativeFrame() const { - // App panel windows draw their own frame. - if (browser_view_->IsBrowserTypePanel()) - return false; - - // We don't theme popup or app windows, so regardless of whether or not a - // theme is active for normal browser windows, we don't want to use the custom - // frame for popups/apps. - if (!browser_view_->IsBrowserTypeNormal() && - views::WidgetWin::IsAeroGlassEnabled()) - return true; - - // Otherwise, we use the native frame when we're told we should by the theme - // provider (e.g. no custom theme is active). - return GetThemeProvider()->ShouldUseNativeFrame(); -} - -views::View* BrowserFrameWin::GetFrameView() const { - return browser_frame_view_; -} - -void BrowserFrameWin::TabStripDisplayModeChanged() { - if (GetRootView()->has_children()) { - // Make sure the child of the root view gets Layout again. - GetRootView()->GetChildViewAt(0)->InvalidateLayout(); - } - GetRootView()->Layout(); - - UpdateDWMFrame(); -} - /////////////////////////////////////////////////////////////////////////////// // BrowserFrameWin, views::WindowWin overrides: @@ -287,6 +221,78 @@ views::RootView* BrowserFrameWin::CreateRootView() { return root_view_; } +//////////////////////////////////////////////////////////////////////////////// +// BrowserFrameWin, NativeBrowserFrame implementation: + +views::NativeWindow* BrowserFrameWin::AsNativeWindow() { + return this; +} + +const views::NativeWindow* BrowserFrameWin::AsNativeWindow() const { + return this; +} + +int BrowserFrameWin::GetMinimizeButtonOffset() const { + TITLEBARINFOEX titlebar_info; + titlebar_info.cbSize = sizeof(TITLEBARINFOEX); + SendMessage(GetNativeView(), WM_GETTITLEBARINFOEX, 0, (WPARAM)&titlebar_info); + + CPoint minimize_button_corner(titlebar_info.rgrect[2].left, + titlebar_info.rgrect[2].top); + MapWindowPoints(HWND_DESKTOP, GetNativeView(), &minimize_button_corner, 1); + + return minimize_button_corner.x; +} + +gfx::Rect BrowserFrameWin::GetBoundsForTabStrip(views::View* tabstrip) const { + return browser_frame_view_->GetBoundsForTabStrip(tabstrip); +} + +int BrowserFrameWin::GetHorizontalTabStripVerticalOffset(bool restored) const { + return browser_frame_view_->GetHorizontalTabStripVerticalOffset(restored); +} + +void BrowserFrameWin::UpdateThrobber(bool running) { + browser_frame_view_->UpdateThrobber(running); +} + +ui::ThemeProvider* BrowserFrameWin::GetThemeProviderForFrame() const { + // This is implemented for a different interface than GetThemeProvider is, + // but they mean the same things. + return GetThemeProvider(); +} + +bool BrowserFrameWin::AlwaysUseNativeFrame() const { + // App panel windows draw their own frame. + if (browser_view_->IsBrowserTypePanel()) + return false; + + // We don't theme popup or app windows, so regardless of whether or not a + // theme is active for normal browser windows, we don't want to use the custom + // frame for popups/apps. + if (!browser_view_->IsBrowserTypeNormal() && + views::WidgetWin::IsAeroGlassEnabled()) + return true; + + // Otherwise, we use the native frame when we're told we should by the theme + // provider (e.g. no custom theme is active). + return GetThemeProvider()->ShouldUseNativeFrame(); +} + +views::View* BrowserFrameWin::GetFrameView() const { + return browser_frame_view_; +} + +void BrowserFrameWin::TabStripDisplayModeChanged() { + if (GetRootView()->has_children()) { + // Make sure the child of the root view gets Layout again. + GetRootView()->GetChildViewAt(0)->InvalidateLayout(); + } + GetRootView()->Layout(); + + UpdateDWMFrame(); +} + /////////////////////////////////////////////////////////////////////////////// // BrowserFrameWin, private: diff --git a/chrome/browser/ui/views/frame/browser_frame_win.h b/chrome/browser/ui/views/frame/browser_frame_win.h index 068f21f..d0a1e88 100644 --- a/chrome/browser/ui/views/frame/browser_frame_win.h +++ b/chrome/browser/ui/views/frame/browser_frame_win.h @@ -8,6 +8,7 @@ #include "base/basictypes.h" #include "chrome/browser/ui/views/frame/browser_frame.h" +#include "chrome/browser/ui/views/frame/native_browser_frame.h" #include "views/window/window_win.h" class AeroGlassNonClientView; @@ -23,7 +24,9 @@ class Profile; // BrowserFrame is a WindowWin subclass that provides the window frame for the // Chrome browser window. // -class BrowserFrameWin : public BrowserFrame, public views::WindowWin { +class BrowserFrameWin : public BrowserFrame, + public views::WindowWin, + public NativeBrowserFrame { public: // Normally you will create this class by calling BrowserFrame::Create. // Init must be called before using this class, which Create will do for you. @@ -41,17 +44,6 @@ class BrowserFrameWin : public BrowserFrame, public views::WindowWin { // otherwise. static void SetShowState(int state); - // Overridden from BrowserFrame: - virtual views::Window* GetWindow() OVERRIDE; - virtual int GetMinimizeButtonOffset() const OVERRIDE; - virtual gfx::Rect GetBoundsForTabStrip(views::View* tabstrip) const OVERRIDE; - virtual int GetHorizontalTabStripVerticalOffset(bool restored) const OVERRIDE; - virtual void UpdateThrobber(bool running) OVERRIDE; - virtual ui::ThemeProvider* GetThemeProviderForFrame() const OVERRIDE; - virtual bool AlwaysUseNativeFrame() const OVERRIDE; - virtual views::View* GetFrameView() const OVERRIDE; - virtual void TabStripDisplayModeChanged() OVERRIDE; - protected: // Overridden from views::WindowWin: virtual int GetShowState() const OVERRIDE; @@ -82,6 +74,18 @@ class BrowserFrameWin : public BrowserFrame, public views::WindowWin { virtual void UpdateFrameAfterFrameChange() OVERRIDE; virtual views::RootView* CreateRootView() OVERRIDE; + // Overridden from NativeBrowserFrame: + virtual views::NativeWindow* AsNativeWindow() OVERRIDE; + virtual const views::NativeWindow* AsNativeWindow() const OVERRIDE; + virtual int GetMinimizeButtonOffset() const OVERRIDE; + virtual gfx::Rect GetBoundsForTabStrip(views::View* tabstrip) const OVERRIDE; + virtual int GetHorizontalTabStripVerticalOffset(bool restored) const OVERRIDE; + virtual void UpdateThrobber(bool running) OVERRIDE; + virtual ui::ThemeProvider* GetThemeProviderForFrame() const OVERRIDE; + virtual bool AlwaysUseNativeFrame() const OVERRIDE; + virtual views::View* GetFrameView() const OVERRIDE; + virtual void TabStripDisplayModeChanged() OVERRIDE; + private: // Updates the DWM with the frame bounds. void UpdateDWMFrame(); @@ -97,6 +101,8 @@ class BrowserFrameWin : public BrowserFrame, public views::WindowWin { // functions that only exist on BrowserRootView (versus RootView). BrowserRootView* root_view_; + NativeBrowserFrameDelegate* delegate_; + DISALLOW_COPY_AND_ASSIGN(BrowserFrameWin); }; diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 6dd5391..7c3a2a1 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -2925,6 +2925,7 @@ 'browser/ui/views/frame/app_panel_browser_frame_view.h', 'browser/ui/views/frame/browser_bubble_host.cc', 'browser/ui/views/frame/browser_bubble_host.h', + 'browser/ui/views/frame/browser_frame.cc', 'browser/ui/views/frame/browser_frame.h', 'browser/ui/views/frame/browser_frame_gtk.cc', 'browser/ui/views/frame/browser_frame_gtk.h', @@ -2943,6 +2944,8 @@ 'browser/ui/views/frame/contents_container.h', 'browser/ui/views/frame/glass_browser_frame_view.cc', 'browser/ui/views/frame/glass_browser_frame_view.h', + 'browser/ui/views/frame/native_browser_frame.h', + 'browser/ui/views/frame/native_browser_frame_delegate.h', 'browser/ui/views/frame/opaque_browser_frame_view.cc', 'browser/ui/views/frame/opaque_browser_frame_view.h', 'browser/ui/views/frame/popup_non_client_frame_view.cc', diff --git a/views/window/native_window.h b/views/window/native_window.h index 6275e1a..9236689 100644 --- a/views/window/native_window.h +++ b/views/window/native_window.h @@ -6,10 +6,19 @@ #define VIEWS_WIDGET_NATIVE_WINDOW_H_ #pragma once +#include "ui/gfx/native_widget_types.h" #include "views/accessibility/accessibility_types.h" +class SkBitmap; + +namespace gfx { +class Rect; +class Size; +} + namespace views { +class NativeWidget; class NonClientFrameView; //////////////////////////////////////////////////////////////////////////////// @@ -26,6 +35,8 @@ class NativeWindow { virtual ~NativeWindow() {} + virtual Window* GetWindow() = 0; + protected: friend class Window; diff --git a/views/window/window_gtk.cc b/views/window/window_gtk.cc index a24ce61..5e625a6 100644 --- a/views/window/window_gtk.cc +++ b/views/window/window_gtk.cc @@ -300,6 +300,10 @@ const NativeWidget* WindowGtk::AsNativeWidget() const { return this; } +Window* WindowGtk::GetWindow() { + return this; +} + void WindowGtk::SetWindowBounds(const gfx::Rect& bounds, gfx::NativeWindow other_window) { // TODO: need to deal with other_window. diff --git a/views/window/window_gtk.h b/views/window/window_gtk.h index 1797bf8..5e9915a 100644 --- a/views/window/window_gtk.h +++ b/views/window/window_gtk.h @@ -60,6 +60,7 @@ class WindowGtk : public WidgetGtk, public NativeWindow, public Window { virtual void SetAccessibleState(AccessibilityTypes::State state) OVERRIDE; virtual NativeWidget* AsNativeWidget() OVERRIDE; virtual const NativeWidget* AsNativeWidget() const OVERRIDE; + virtual Window* GetWindow() OVERRIDE; virtual void SetWindowBounds(const gfx::Rect& bounds, gfx::NativeWindow other_window) OVERRIDE; virtual void HideWindow() OVERRIDE; |