diff options
author | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-08 18:40:39 +0000 |
---|---|---|
committer | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-08 18:40:39 +0000 |
commit | f353bede76468b89fc69f3b823e567e6da87d3f7 (patch) | |
tree | 0e3550b90e475f534a70406111e87d6adabebfca | |
parent | 88e9e51b775961260b013139c965504749359b5c (diff) | |
download | chromium_src-f353bede76468b89fc69f3b823e567e6da87d3f7.zip chromium_src-f353bede76468b89fc69f3b823e567e6da87d3f7.tar.gz chromium_src-f353bede76468b89fc69f3b823e567e6da87d3f7.tar.bz2 |
Consolidate some more stuff in Window. PreferredSize obtaining.
Move GetShowState to BrowserFrameWin rather than needlessly delegate to BrowserView. This removes a small amount of WIndows-specific code from BrowserView.
BUG=72040
TEST=none
Review URL: http://codereview.chromium.org/6627079
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@77306 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/ui/views/constrained_window_win.cc | 2 | ||||
-rw-r--r-- | chrome/browser/ui/views/frame/browser_frame_win.cc | 63 | ||||
-rw-r--r-- | chrome/browser/ui/views/frame/browser_frame_win.h | 80 | ||||
-rw-r--r-- | chrome/browser/ui/views/frame/browser_view.cc | 24 | ||||
-rw-r--r-- | chrome/browser/ui/views/frame/browser_view.h | 9 | ||||
-rw-r--r-- | chrome/test/in_process_browser_test.cc | 6 | ||||
-rw-r--r-- | views/window/native_window_delegate.h | 3 | ||||
-rw-r--r-- | views/window/window.cc | 4 | ||||
-rw-r--r-- | views/window/window.h | 1 | ||||
-rw-r--r-- | views/window/window_gtk.cc | 4 | ||||
-rw-r--r-- | views/window/window_win.cc | 22 | ||||
-rw-r--r-- | views/window/window_win.h | 20 |
12 files changed, 117 insertions, 121 deletions
diff --git a/chrome/browser/ui/views/constrained_window_win.cc b/chrome/browser/ui/views/constrained_window_win.cc index e078fc3..fe30134 100644 --- a/chrome/browser/ui/views/constrained_window_win.cc +++ b/chrome/browser/ui/views/constrained_window_win.cc @@ -366,7 +366,7 @@ void ConstrainedWindowFrameView::OnThemeChanged() { void ConstrainedWindowFrameView::ButtonPressed( views::Button* sender, const views::Event& event) { if (sender == close_button_) - container_->ExecuteSystemMenuCommand(SC_CLOSE); + container_->Close(); } //////////////////////////////////////////////////////////////////////////////// diff --git a/chrome/browser/ui/views/frame/browser_frame_win.cc b/chrome/browser/ui/views/frame/browser_frame_win.cc index 54b6e41..d60b767 100644 --- a/chrome/browser/ui/views/frame/browser_frame_win.cc +++ b/chrome/browser/ui/views/frame/browser_frame_win.cc @@ -30,6 +30,8 @@ static const int kTabDragWindowAlpha = 200; // We need to offset the DWMFrame into the toolbar so that the blackness // doesn't show up on our rounded corners. static const int kDWMFrameTopOffset = 3; +// If not -1, windows are shown with this state. +static int explicit_show_state = -1; // static (Factory method.) BrowserFrame* BrowserFrame::Create(BrowserView* browser_view, @@ -39,35 +41,34 @@ BrowserFrame* BrowserFrame::Create(BrowserView* browser_view, return frame; } -// static -const gfx::Font& BrowserFrame::GetTitleFont() { - static gfx::Font* title_font = - new gfx::Font(views::WindowWin::GetWindowTitleFont()); - return *title_font; -} - /////////////////////////////////////////////////////////////////////////////// -// BrowserFrame, public: +// BrowserFrameWin, public: BrowserFrameWin::BrowserFrameWin(BrowserView* browser_view, Profile* profile) : WindowWin(browser_view), browser_view_(browser_view), - root_view_(NULL), - frame_initialized_(false), - profile_(profile) { + root_view_(NULL) { browser_view_->set_frame(this); non_client_view()->SetFrameView(CreateFrameViewForWindow()); // Don't focus anything on creation, selecting a tab will set the focus. set_focus_on_creation(false); } +BrowserFrameWin::~BrowserFrameWin() { +} + void BrowserFrameWin::InitBrowserFrame() { WindowWin::Init(NULL, gfx::Rect()); } -BrowserFrameWin::~BrowserFrameWin() { +// static +void BrowserFrameWin::SetShowState(int state) { + explicit_show_state = state; } +//////////////////////////////////////////////////////////////////////////////// +// BrowserFrameWin, BrowserFrame implementation: + views::Window* BrowserFrameWin::GetWindow() { return this; } @@ -134,7 +135,18 @@ void BrowserFrameWin::TabStripDisplayModeChanged() { } /////////////////////////////////////////////////////////////////////////////// -// BrowserFrame, views::WindowWin overrides: +// BrowserFrameWin, views::WindowWin overrides: + +int BrowserFrameWin::GetShowState() const { + if (explicit_show_state != -1) + return explicit_show_state; + + STARTUPINFO si = {0}; + si.cb = sizeof(si); + si.dwFlags = STARTF_USESHOWWINDOW; + GetStartupInfo(&si); + return si.wShowWindow; +} gfx::Insets BrowserFrameWin::GetClientAreaInsets() const { // Use the default client insets for an opaque frame or a glass popup/app @@ -176,8 +188,8 @@ void BrowserFrameWin::OnInitMenuPopup(HMENU menu, UINT position, browser_view_->PrepareToRunSystemMenu(menu); } -LRESULT BrowserFrameWin::OnMouseActivate(HWND window, UINT hittest_code, - UINT message) { +LRESULT BrowserFrameWin::OnMouseActivate(UINT message, WPARAM w_param, + LPARAM l_param) { return browser_view_->ActivateAppModalDialog() ? MA_NOACTIVATEANDEAT : MA_ACTIVATE; } @@ -230,7 +242,7 @@ void BrowserFrameWin::OnWindowPosChanged(WINDOWPOS* window_pos) { } ThemeProvider* BrowserFrameWin::GetThemeProvider() const { - return profile_->GetThemeProvider(); + return browser_view_->browser()->profile()->GetThemeProvider(); } void BrowserFrameWin::OnScreenReaderDetected() { @@ -239,11 +251,7 @@ void BrowserFrameWin::OnScreenReaderDetected() { } /////////////////////////////////////////////////////////////////////////////// -// BrowserFrame, views::CustomFrameWindow overrides: - -int BrowserFrameWin::GetShowState() const { - return browser_view_->GetShowState(); -} +// BrowserFrameWin, views::Window overrides: void BrowserFrameWin::Activate() { // When running under remote desktop, if the remote desktop client is not @@ -279,7 +287,7 @@ views::RootView* BrowserFrameWin::CreateRootView() { } /////////////////////////////////////////////////////////////////////////////// -// BrowserFrame, private: +// BrowserFrameWin, private: void BrowserFrameWin::UpdateDWMFrame() { // Nothing to do yet, or we're not showing a DWM frame. @@ -310,3 +318,14 @@ void BrowserFrameWin::UpdateDWMFrame() { } DwmExtendFrameIntoClientArea(GetNativeView(), &margins); } + +//////////////////////////////////////////////////////////////////////////////// +// BrowserFrame, public: + +// static +const gfx::Font& BrowserFrame::GetTitleFont() { + static gfx::Font* title_font = + new gfx::Font(views::WindowWin::GetWindowTitleFont()); + return *title_font; +} + diff --git a/chrome/browser/ui/views/frame/browser_frame_win.h b/chrome/browser/ui/views/frame/browser_frame_win.h index 0d5e29b..e2fbaa1 100644 --- a/chrome/browser/ui/views/frame/browser_frame_win.h +++ b/chrome/browser/ui/views/frame/browser_frame_win.h @@ -36,43 +36,49 @@ class BrowserFrameWin : public BrowserFrame, public views::WindowWin { BrowserView* browser_view() const { return browser_view_; } - // BrowserFrame implementation. - 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(); + // Explicitly sets how windows are shown. Use a value of -1 to give the + // default behavior. This is used during testing and not generally useful + // 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 gfx::Insets GetClientAreaInsets() const; - virtual bool GetAccelerator(int cmd_id, ui::Accelerator* accelerator); - virtual void OnEndSession(BOOL ending, UINT logoff); - virtual void OnEnterSizeMove(); - virtual void OnExitSizeMove(); - virtual void OnInitMenuPopup(HMENU menu, UINT position, BOOL is_system_menu); - virtual LRESULT OnMouseActivate(HWND window, - UINT hittest_code, - UINT message); - virtual void OnMove(const CPoint& point); - virtual void OnMoving(UINT param, LPRECT new_bounds); - virtual LRESULT OnNCActivate(BOOL active); - virtual LRESULT OnNCHitTest(const CPoint& pt); - virtual void OnWindowPosChanged(WINDOWPOS* window_pos); - virtual ui::ThemeProvider* GetThemeProvider() const; - virtual void OnScreenReaderDetected(); + virtual int GetShowState() const OVERRIDE; + virtual gfx::Insets GetClientAreaInsets() const OVERRIDE; + virtual bool GetAccelerator(int cmd_id, ui::Accelerator* accelerator) + OVERRIDE; + virtual void OnEndSession(BOOL ending, UINT logoff) OVERRIDE; + virtual void OnEnterSizeMove() OVERRIDE; + virtual void OnExitSizeMove() OVERRIDE; + virtual void OnInitMenuPopup(HMENU menu, UINT position, BOOL is_system_menu) + OVERRIDE; + virtual LRESULT OnMouseActivate(UINT message, WPARAM w_param, LPARAM l_param) + OVERRIDE; + virtual void OnMove(const CPoint& point) OVERRIDE; + virtual void OnMoving(UINT param, LPRECT new_bounds) OVERRIDE; + virtual LRESULT OnNCActivate(BOOL active) OVERRIDE; + virtual LRESULT OnNCHitTest(const CPoint& pt) OVERRIDE; + virtual void OnWindowPosChanged(WINDOWPOS* window_pos) OVERRIDE; + virtual ui::ThemeProvider* GetThemeProvider() const OVERRIDE; + virtual void OnScreenReaderDetected() OVERRIDE; // Overridden from views::Window: - virtual int GetShowState() const; - virtual void Activate(); - virtual bool IsAppWindow() const { return true; } - virtual views::NonClientFrameView* CreateFrameViewForWindow(); - virtual void UpdateFrameAfterFrameChange(); - virtual views::RootView* CreateRootView(); + virtual void Activate() OVERRIDE; + virtual bool IsAppWindow() const OVERRIDE { return true; } + virtual views::NonClientFrameView* CreateFrameViewForWindow() OVERRIDE; + virtual void UpdateFrameAfterFrameChange() OVERRIDE; + virtual views::RootView* CreateRootView() OVERRIDE; private: // Updates the DWM with the frame bounds. @@ -84,15 +90,11 @@ class BrowserFrameWin : public BrowserFrame, public views::WindowWin { // A pointer to our NonClientFrameView as a BrowserNonClientFrameView. BrowserNonClientFrameView* browser_frame_view_; - // An unowning reference to the root view associated with the window. We save - // a copy as a BrowserRootView to avoid evil casting later, when we need to - // call functions that only exist on BrowserRootView (versus RootView). + // A weak reference to the root view associated with the window. We save a + // copy as a BrowserRootView to avoid evil casting later, when we need to call + // functions that only exist on BrowserRootView (versus RootView). BrowserRootView* root_view_; - bool frame_initialized_; - - Profile* profile_; - DISALLOW_COPY_AND_ASSIGN(BrowserFrameWin); }; diff --git a/chrome/browser/ui/views/frame/browser_view.cc b/chrome/browser/ui/views/frame/browser_view.cc index 1b54898..bdbe180 100644 --- a/chrome/browser/ui/views/frame/browser_view.cc +++ b/chrome/browser/ui/views/frame/browser_view.cc @@ -118,9 +118,6 @@ static const int kLoadingAnimationFrameTimeMs = 30; // The amount of space we expect the window border to take up. static const int kWindowBorderWidth = 5; -// If not -1, windows are shown with this state. -static int explicit_show_state = -1; - // How round the 'new tab' style bookmarks bar is. static const int kNewtabBarRoundness = 5; // ------------ @@ -421,11 +418,6 @@ class DownloadInProgressConfirmDialogDelegate : public views::DialogDelegate, /////////////////////////////////////////////////////////////////////////////// // BrowserView, public: -// static -void BrowserView::SetShowState(int state) { - explicit_show_state = state; -} - BrowserView::BrowserView(Browser* browser) : views::ClientView(NULL, NULL), last_focused_view_storage_id_( @@ -506,22 +498,6 @@ BrowserView* BrowserView::GetBrowserViewForNativeWindow( return NULL; } -int BrowserView::GetShowState() const { - if (explicit_show_state != -1) - return explicit_show_state; - -#if defined(OS_WIN) - STARTUPINFO si = {0}; - si.cb = sizeof(si); - si.dwFlags = STARTF_USESHOWWINDOW; - GetStartupInfo(&si); - return si.wShowWindow; -#else - NOTIMPLEMENTED(); - return 0; -#endif -} - void BrowserView::WindowMoved() { // Cancel any tabstrip animations, some of them may be invalidated by the // window being repositioned. diff --git a/chrome/browser/ui/views/frame/browser_view.h b/chrome/browser/ui/views/frame/browser_view.h index f2eaa27..911febc 100644 --- a/chrome/browser/ui/views/frame/browser_view.h +++ b/chrome/browser/ui/views/frame/browser_view.h @@ -88,11 +88,6 @@ class BrowserView : public BrowserBubbleHost, // The browser view's class name. static const char kViewClassName[]; - // Explicitly sets how windows are shown. Use a value of -1 to give the - // default behavior. This is used during testing and not generally useful - // otherwise. - static void SetShowState(int state); - explicit BrowserView(Browser* browser); virtual ~BrowserView(); @@ -107,10 +102,6 @@ class BrowserView : public BrowserBubbleHost, // Returns a Browser instance of this view. Browser* browser() const { return browser_.get(); } - // Returns the show flag that should be used to show the frame containing - // this view. - int GetShowState() const; - // Called by the frame to notify the BrowserView that it was moved, and that // any dependent popup windows should be repositioned. void WindowMoved(); diff --git a/chrome/test/in_process_browser_test.cc b/chrome/test/in_process_browser_test.cc index 87fa591..b2e03e7 100644 --- a/chrome/test/in_process_browser_test.cc +++ b/chrome/test/in_process_browser_test.cc @@ -45,7 +45,7 @@ #endif #if defined(OS_WIN) -#include "chrome/browser/ui/views/frame/browser_view.h" +#include "chrome/browser/ui/views/frame/browser_frame_win.h" #endif namespace { @@ -165,7 +165,7 @@ void InProcessBrowserTest::PrepareTestCommandLine(CommandLine* command_line) { #if defined(OS_WIN) // Hide windows on show. if (!command_line->HasSwitch(kUnitTestShowWindows) && !show_window_) - BrowserView::SetShowState(SW_HIDE); + BrowserFrameWin::SetShowState(SW_HIDE); #endif if (dom_automation_enabled_) @@ -227,7 +227,7 @@ void InProcessBrowserTest::TearDown() { browser_shutdown::delete_resources_on_shutdown = true; #if defined(OS_WIN) - BrowserView::SetShowState(-1); + BrowserFrameWin::SetShowState(-1); #endif } diff --git a/views/window/native_window_delegate.h b/views/window/native_window_delegate.h index 4668de4..8e963ce 100644 --- a/views/window/native_window_delegate.h +++ b/views/window/native_window_delegate.h @@ -19,6 +19,9 @@ class NativeWindowDelegate { public: virtual ~NativeWindowDelegate() {} + // Returns the window's preferred size. + virtual gfx::Size GetPreferredSize() const = 0; + // Called just before the native window is destroyed. This is the delegate's // last chance to do anything with the native window handle. virtual void OnWindowDestroying() = 0; diff --git a/views/window/window.cc b/views/window/window.cc index 5531cff..5fbb222 100644 --- a/views/window/window.cc +++ b/views/window/window.cc @@ -173,6 +173,10 @@ void Window::FrameTypeChanged() { //////////////////////////////////////////////////////////////////////////////// // Window, internal::NativeWindowDelegate implementation: +gfx::Size Window::GetPreferredSize() const { + return non_client_view_->GetPreferredSize(); +} + void Window::OnWindowDestroying() { non_client_view_->WindowClosing(); window_delegate_->WindowClosing(); diff --git a/views/window/window.h b/views/window/window.h index 7bc9406..ba7ed98 100644 --- a/views/window/window.h +++ b/views/window/window.h @@ -218,6 +218,7 @@ class Window : public internal::NativeWindowDelegate { } // Overridden from NativeWindowDelegate: + virtual gfx::Size GetPreferredSize() const; virtual void OnWindowDestroying(); virtual void OnWindowDestroyed(); diff --git a/views/window/window_gtk.cc b/views/window/window_gtk.cc index 06feab3..5eaea00 100644 --- a/views/window/window_gtk.cc +++ b/views/window/window_gtk.cc @@ -459,7 +459,7 @@ void WindowGtk::SetInitialBounds(GtkWindow* parent, gfx::Rect saved_bounds(create_bounds.ToGdkRectangle()); if (GetWindow()->window_delegate()->GetSavedWindowBounds(&saved_bounds)) { if (!GetWindow()->window_delegate()->ShouldRestoreWindowSize()) - saved_bounds.set_size(GetWindow()->non_client_view()->GetPreferredSize()); + saved_bounds.set_size(delegate_->GetPreferredSize()); WidgetGtk::SetBounds(saved_bounds); } else { if (create_bounds.IsEmpty()) { @@ -486,7 +486,7 @@ void WindowGtk::SizeWindowToDefault(GtkWindow* parent) { // We have no parent window, center over the screen. center_rect = Screen::GetMonitorWorkAreaNearestWindow(GetNativeView()); } - gfx::Size size = GetWindow()->non_client_view()->GetPreferredSize(); + gfx::Size size = delegate_->GetPreferredSize(); gfx::Rect bounds(center_rect.x() + (center_rect.width() - size.width()) / 2, center_rect.y() + (center_rect.height() - size.height()) / 2, size.width(), size.height()); diff --git a/views/window/window_win.cc b/views/window/window_win.cc index 30e98ec..59d062a 100644 --- a/views/window/window_win.cc +++ b/views/window/window_win.cc @@ -293,15 +293,6 @@ void WindowWin::PopForceHidden() { } } -int WindowWin::GetShowState() const { - return SW_SHOWNORMAL; -} - -void WindowWin::ExecuteSystemMenuCommand(int command) { - if (command) - SendMessage(GetNativeView(), WM_SYSCOMMAND, command, 0); -} - namespace { static BOOL CALLBACK SendDwmCompositionChanged(HWND window, LPARAM param) { SendMessage(window, WM_DWMCOMPOSITIONCHANGED, 0, 0); @@ -677,7 +668,7 @@ void WindowWin::Init(gfx::NativeView parent, const gfx::Rect& bounds) { void WindowWin::SizeWindowToDefault() { ui::CenterAndSizeWindow(owning_window(), GetNativeView(), - GetWindow()->non_client_view()->GetPreferredSize(), + delegate_->GetPreferredSize(), false); } @@ -708,6 +699,10 @@ gfx::Insets WindowWin::GetClientAreaInsets() const { return gfx::Insets(0, 0, IsFullscreen() ? 0 : 1, 0); } +int WindowWin::GetShowState() const { + return SW_SHOWNORMAL; +} + /////////////////////////////////////////////////////////////////////////////// // WindowWin, WidgetWin overrides: @@ -1263,7 +1258,7 @@ void WindowWin::SetInitialBounds(const gfx::Rect& create_bounds) { gfx::Rect saved_bounds(create_bounds.ToRECT()); if (GetWindow()->window_delegate()->GetSavedWindowBounds(&saved_bounds)) { if (!GetWindow()->window_delegate()->ShouldRestoreWindowSize()) { - saved_bounds.set_size(GetWindow()->non_client_view()->GetPreferredSize()); + saved_bounds.set_size(delegate_->GetPreferredSize()); } else { // Make sure the bounds are at least the minimum size. if (saved_bounds.width() < minimum_size_.width()) { @@ -1462,6 +1457,11 @@ LRESULT WindowWin::CallDefaultNCActivateHandler(BOOL active) { return DefWindowProc(GetNativeView(), WM_NCACTIVATE, active, 0); } +void WindowWin::ExecuteSystemMenuCommand(int command) { + if (command) + SendMessage(GetNativeView(), WM_SYSCOMMAND, command, 0); +} + void WindowWin::GetWindowBoundsAndMaximizedState(gfx::Rect* bounds, bool* maximized) const { WINDOWPLACEMENT wp; diff --git a/views/window/window_win.h b/views/window/window_win.h index bb833ae..ff85b4c 100644 --- a/views/window/window_win.h +++ b/views/window/window_win.h @@ -49,16 +49,6 @@ class WindowWin : public WidgetWin, // Show the window with the specified show command. void Show(int show_state); - // Retrieve the show state of the window. This is one of the SW_SHOW* flags - // passed into Windows' ShowWindow method. For normal windows this defaults - // to SW_SHOWNORMAL, however windows (e.g. the main window) can override this - // method to provide different values (e.g. retrieve the user's specified - // show state from the shortcut starutp info). - virtual int GetShowState() const; - - // Executes the specified SC_command. - void ExecuteSystemMenuCommand(int command); - // Accessors and setters for various properties. HWND owning_window() const { return owning_hwnd_; } void set_focus_on_creation(bool focus_on_creation) { @@ -123,6 +113,13 @@ class WindowWin : public WidgetWin, // crazily complicated. virtual gfx::Insets GetClientAreaInsets() const; + // Retrieve the show state of the window. This is one of the SW_SHOW* flags + // passed into Windows' ShowWindow method. For normal windows this defaults + // to SW_SHOWNORMAL, however windows (e.g. the main window) can override this + // method to provide different values (e.g. retrieve the user's specified + // show state from the shortcut starutp info). + virtual int GetShowState() const; + // Overridden from WidgetWin: virtual void OnActivate(UINT action, BOOL minimized, HWND window) OVERRIDE; virtual void OnActivateApp(BOOL active, DWORD thread_id) OVERRIDE; @@ -220,6 +217,9 @@ class WindowWin : public WidgetWin, // flicker. LRESULT CallDefaultNCActivateHandler(BOOL active); + // Executes the specified SC_command. + void ExecuteSystemMenuCommand(int command); + // Returns the normal bounds of the window in screen coordinates and // whether the window is maximized. The arguments can be NULL. void GetWindowBoundsAndMaximizedState(gfx::Rect* bounds, |