diff options
author | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-19 18:36:47 +0000 |
---|---|---|
committer | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-19 18:36:47 +0000 |
commit | 85a6aab738a98be3b473dfe117053251a3865734 (patch) | |
tree | dae8937683bbb2d0152c8008533d5bacd41b9673 | |
parent | 3bb078951654ca9161207ac6afd375210beaddbb (diff) | |
download | chromium_src-85a6aab738a98be3b473dfe117053251a3865734.zip chromium_src-85a6aab738a98be3b473dfe117053251a3865734.tar.gz chromium_src-85a6aab738a98be3b473dfe117053251a3865734.tar.bz2 |
Makes sure widget is created at right size before showing
it. Previously if we were going to maximize the window we would first
create it at the restored size, then maximize it. On slower machines
this could result in a noticeable relayout of the web page.
BUG=11229
TEST=see bug.
R=ben@chromium.org
Review URL: http://codereview.chromium.org/7358005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@93067 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/chromeos/frame/browser_view.cc | 1 | ||||
-rw-r--r-- | chrome/browser/ui/views/frame/browser_frame.cc | 7 | ||||
-rw-r--r-- | views/widget/native_widget_gtk.cc | 8 | ||||
-rw-r--r-- | views/widget/native_widget_gtk.h | 4 | ||||
-rw-r--r-- | views/widget/native_widget_private.h | 5 | ||||
-rw-r--r-- | views/widget/native_widget_views.cc | 8 | ||||
-rw-r--r-- | views/widget/native_widget_views.h | 4 | ||||
-rw-r--r-- | views/widget/native_widget_win.cc | 13 | ||||
-rw-r--r-- | views/widget/native_widget_win.h | 4 | ||||
-rw-r--r-- | views/widget/widget.cc | 75 | ||||
-rw-r--r-- | views/widget/widget.h | 10 |
11 files changed, 97 insertions, 42 deletions
diff --git a/chrome/browser/chromeos/frame/browser_view.cc b/chrome/browser/chromeos/frame/browser_view.cc index 5332539..cee5b18 100644 --- a/chrome/browser/chromeos/frame/browser_view.cc +++ b/chrome/browser/chromeos/frame/browser_view.cc @@ -22,7 +22,6 @@ #include "chrome/browser/themes/theme_service_factory.h" #include "chrome/browser/themes/theme_service.h" #include "chrome/browser/ui/gtk/gtk_util.h" -#include "chrome/browser/ui/views/frame/browser_frame_gtk.h" #include "chrome/browser/ui/views/frame/browser_view.h" #include "chrome/browser/ui/views/frame/browser_view_layout.h" #include "chrome/browser/ui/views/tabs/tab.h" diff --git a/chrome/browser/ui/views/frame/browser_frame.cc b/chrome/browser/ui/views/frame/browser_frame.cc index 62c66b6..acaf68f 100644 --- a/chrome/browser/ui/views/frame/browser_frame.cc +++ b/chrome/browser/ui/views/frame/browser_frame.cc @@ -7,6 +7,7 @@ #include "base/command_line.h" #include "chrome/browser/themes/theme_service.h" #include "chrome/browser/themes/theme_service_factory.h" +#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser_list.h" #include "chrome/browser/ui/views/frame/browser_non_client_frame_view.h" #include "chrome/browser/ui/views/frame/browser_root_view.h" @@ -43,6 +44,12 @@ void BrowserFrame::InitBrowserFrame() { views::Widget::InitParams params; params.delegate = browser_view_; params.native_widget = native_browser_frame_->AsNativeWidget(); + if (browser_view_->browser()->is_type_tabbed()) { + // Typed panel/popup can only return a size once the widget has been + // created. + params.bounds = browser_view_->browser()->GetSavedWindowBounds(); + params.maximize = browser_view_->browser()->GetSavedMaximizedState(); + } Init(params); #if defined(OS_CHROMEOS) // On ChromeOS we always want top-level windows to appear active. diff --git a/views/widget/native_widget_gtk.cc b/views/widget/native_widget_gtk.cc index 50e9b97..474648a 100644 --- a/views/widget/native_widget_gtk.cc +++ b/views/widget/native_widget_gtk.cc @@ -1194,7 +1194,13 @@ void NativeWidgetGtk::Hide() { } } -void NativeWidgetGtk::ShowNativeWidget(ShowState state) { +void NativeWidgetGtk::ShowMaximizedWithBounds( + const gfx::Rect& restored_bounds) { + // TODO: when we add maximization support update this. + Show(); +} + +void NativeWidgetGtk::ShowWithState(ShowState state) { // No concept of maximization (yet) on ChromeOS. if (state == internal::NativeWidgetPrivate::SHOW_INACTIVE) gtk_window_set_focus_on_map(GetNativeWindow(), false); diff --git a/views/widget/native_widget_gtk.h b/views/widget/native_widget_gtk.h index 4555691..3b38113 100644 --- a/views/widget/native_widget_gtk.h +++ b/views/widget/native_widget_gtk.h @@ -196,7 +196,9 @@ class NativeWidgetGtk : public internal::NativeWidgetPrivate, virtual void EnableClose(bool enable) OVERRIDE; virtual void Show() OVERRIDE; virtual void Hide() OVERRIDE; - virtual void ShowNativeWidget(ShowState state) OVERRIDE; + virtual void ShowMaximizedWithBounds( + const gfx::Rect& restored_bounds) OVERRIDE; + virtual void ShowWithState(ShowState state) OVERRIDE; virtual bool IsVisible() const OVERRIDE; virtual void Activate() OVERRIDE; virtual void Deactivate() OVERRIDE; diff --git a/views/widget/native_widget_private.h b/views/widget/native_widget_private.h index 5139c1f..8062d8f 100644 --- a/views/widget/native_widget_private.h +++ b/views/widget/native_widget_private.h @@ -190,7 +190,10 @@ class NativeWidgetPrivate : public NativeWidget { virtual void EnableClose(bool enable) = 0; virtual void Show() = 0; virtual void Hide() = 0; - virtual void ShowNativeWidget(ShowState state) = 0; + // Invoked if the initial show should maximize the window. |restored_bounds| + // is the bounds of the window when not maximized. + virtual void ShowMaximizedWithBounds(const gfx::Rect& restored_bounds) = 0; + virtual void ShowWithState(ShowState state) = 0; virtual bool IsVisible() const = 0; virtual void Activate() = 0; virtual void Deactivate() = 0; diff --git a/views/widget/native_widget_views.cc b/views/widget/native_widget_views.cc index 3bc341d..fd4a571 100644 --- a/views/widget/native_widget_views.cc +++ b/views/widget/native_widget_views.cc @@ -346,7 +346,13 @@ void NativeWidgetViews::Hide() { view_->SetVisible(false); } -void NativeWidgetViews::ShowNativeWidget(ShowState state) { +void NativeWidgetViews::ShowWithState(ShowState state) { + Show(); +} + +void NativeWidgetViews::ShowMaximizedWithBounds( + const gfx::Rect& restored_bounds) { + Show(); } bool NativeWidgetViews::IsVisible() const { diff --git a/views/widget/native_widget_views.h b/views/widget/native_widget_views.h index 5ac14eb..aee7df1 100644 --- a/views/widget/native_widget_views.h +++ b/views/widget/native_widget_views.h @@ -99,7 +99,9 @@ class NativeWidgetViews : public internal::NativeWidgetPrivate, virtual void EnableClose(bool enable) OVERRIDE; virtual void Show() OVERRIDE; virtual void Hide() OVERRIDE; - virtual void ShowNativeWidget(ShowState state) OVERRIDE; + virtual void ShowMaximizedWithBounds( + const gfx::Rect& restored_bounds) OVERRIDE; + virtual void ShowWithState(ShowState state) OVERRIDE; virtual bool IsVisible() const OVERRIDE; virtual void Activate() OVERRIDE; virtual void Deactivate() OVERRIDE; diff --git a/views/widget/native_widget_win.cc b/views/widget/native_widget_win.cc index 6d6f141..914afaa 100644 --- a/views/widget/native_widget_win.cc +++ b/views/widget/native_widget_win.cc @@ -894,7 +894,16 @@ void NativeWidgetWin::Hide() { } } -void NativeWidgetWin::ShowNativeWidget(ShowState state) { +void NativeWidgetWin::ShowMaximizedWithBounds( + const gfx::Rect& restored_bounds) { + WINDOWPLACEMENT placement = { 0 }; + placement.length = sizeof(WINDOWPLACEMENT); + placement.showCmd = SW_SHOWMAXIMIZED; + placement.rcNormalPosition = restored_bounds.ToRECT(); + SetWindowPlacement(hwnd(), &placement); +} + +void NativeWidgetWin::ShowWithState(ShowState state) { DWORD native_show_state; switch (state) { case SHOW_INACTIVE: @@ -2213,6 +2222,8 @@ void NativeWidgetWin::SetInitParams(const Widget::InitParams& params) { // Set type-independent style attributes. if (params.child) style |= WS_CHILD | WS_VISIBLE; + if (params.maximize) + style |= WS_MAXIMIZE; if (!params.accept_events) ex_style |= WS_EX_TRANSPARENT; if (!params.can_activate) diff --git a/views/widget/native_widget_win.h b/views/widget/native_widget_win.h index ea89239..4298fe5 100644 --- a/views/widget/native_widget_win.h +++ b/views/widget/native_widget_win.h @@ -246,7 +246,9 @@ class NativeWidgetWin : public ui::WindowImpl, virtual void EnableClose(bool enable) OVERRIDE; virtual void Show() OVERRIDE; virtual void Hide() OVERRIDE; - virtual void ShowNativeWidget(ShowState state) OVERRIDE; + virtual void ShowMaximizedWithBounds( + const gfx::Rect& restored_bounds) OVERRIDE; + virtual void ShowWithState(ShowState state) OVERRIDE; virtual bool IsVisible() const OVERRIDE; virtual void Activate() OVERRIDE; virtual void Deactivate() OVERRIDE; diff --git a/views/widget/widget.cc b/views/widget/widget.cc index 628efb4..5411869 100644 --- a/views/widget/widget.cc +++ b/views/widget/widget.cc @@ -99,6 +99,7 @@ Widget::InitParams::InitParams() ownership(NATIVE_WIDGET_OWNS_WIDGET), mirror_origin_in_rtl(false), has_dropshadow(false), + maximize(false), double_buffer(false), parent(NULL), parent_widget(NULL), @@ -117,6 +118,7 @@ Widget::InitParams::InitParams(Type type) ownership(NATIVE_WIDGET_OWNS_WIDGET), mirror_origin_in_rtl(false), has_dropshadow(false), + maximize(false), double_buffer(false), parent(NULL), parent_widget(NULL), @@ -438,9 +440,13 @@ void Widget::EnableClose(bool enable) { void Widget::Show() { if (non_client_view_) { - native_widget_->ShowNativeWidget( - saved_maximized_state_ ? internal::NativeWidgetPrivate::SHOW_MAXIMIZED - : internal::NativeWidgetPrivate::SHOW_RESTORED); + if (saved_maximized_state_ && !initial_restored_bounds_.IsEmpty()) { + native_widget_->ShowMaximizedWithBounds(initial_restored_bounds_); + } else { + native_widget_->ShowWithState(saved_maximized_state_ ? + internal::NativeWidgetPrivate::SHOW_MAXIMIZED : + internal::NativeWidgetPrivate::SHOW_RESTORED); + } // |saved_maximized_state_| only applies the first time the window is shown. // If we don't reset the value the window will be shown maximized every time // it is subsequently shown after being hidden. @@ -455,8 +461,7 @@ void Widget::Hide() { } void Widget::ShowInactive() { - native_widget_->ShowNativeWidget( - internal::NativeWidgetPrivate::SHOW_INACTIVE); + native_widget_->ShowWithState(internal::NativeWidgetPrivate::SHOW_INACTIVE); } void Widget::Activate() { @@ -1012,49 +1017,51 @@ void Widget::SetInitialBounds(const gfx::Rect& bounds) { if (!non_client_view_) return; + gfx::Rect saved_bounds; + if (GetSavedBounds(&saved_bounds, &saved_maximized_state_)) { + if (saved_maximized_state_) { + // If we're going to maximize, wait until Show is invoked to set the + // bounds. That way we avoid a noticable resize. + initial_restored_bounds_ = saved_bounds; + } else { + SetBounds(saved_bounds); + } + } else { + if (bounds.IsEmpty()) { + // No initial bounds supplied, so size the window to its content and + // center over its parent. + native_widget_->CenterWindow(non_client_view_->GetPreferredSize()); + } else { + // Use the supplied initial bounds. + SetBoundsConstrained(bounds, NULL); + } + } +} + +bool Widget::GetSavedBounds(gfx::Rect* bounds, bool* maximize) { // First we obtain the window's saved show-style and store it. We need to do // this here, rather than in Show() because by the time Show() is called, // the window's size will have been reset (below) and the saved maximized // state will have been lost. Sadly there's no way to tell on Windows when // a window is restored from maximized state, so we can't more accurately // track maximized state independently of sizing information. - widget_delegate_->GetSavedMaximizedState(&saved_maximized_state_); + widget_delegate_->GetSavedMaximizedState(maximize); // Restore the window's placement from the controller. - gfx::Rect saved_bounds = bounds; - if (widget_delegate_->GetSavedWindowBounds(&saved_bounds)) { + if (widget_delegate_->GetSavedWindowBounds(bounds)) { if (!widget_delegate_->ShouldRestoreWindowSize()) { - saved_bounds.set_size(non_client_view_->GetPreferredSize()); + bounds->set_size(non_client_view_->GetPreferredSize()); } else { // Make sure the bounds are at least the minimum size. - if (saved_bounds.width() < minimum_size_.width()) { - saved_bounds.SetRect(saved_bounds.x(), saved_bounds.y(), - saved_bounds.right() + minimum_size_.width() - - saved_bounds.width(), - saved_bounds.bottom()); - } + if (bounds->width() < minimum_size_.width()) + bounds->set_width(minimum_size_.width()); - if (saved_bounds.height() < minimum_size_.height()) { - saved_bounds.SetRect(saved_bounds.x(), saved_bounds.y(), - saved_bounds.right(), - saved_bounds.bottom() + minimum_size_.height() - - saved_bounds.height()); - } - } - - // Widget's SetBounds method does not further modify the bounds that are - // passed to it. - SetBounds(saved_bounds); - } else { - if (bounds.IsEmpty()) { - // No initial bounds supplied, so size the window to its content and - // center over its parent. - native_widget_->CenterWindow(non_client_view_->GetPreferredSize()); - } else { - // Use the supplied initial bounds. - SetBoundsConstrained(bounds, NULL); + if (bounds->height() < minimum_size_.height()) + bounds->set_height(minimum_size_.height()); } + return true; } + return false; } namespace internal { diff --git a/views/widget/widget.h b/views/widget/widget.h index 1f8f72b..448a43f 100644 --- a/views/widget/widget.h +++ b/views/widget/widget.h @@ -143,6 +143,8 @@ class Widget : public internal::NativeWidgetDelegate, Ownership ownership; bool mirror_origin_in_rtl; bool has_dropshadow; + // Whether the widget should be maximized. + bool maximize; // Should the widget be double buffered? Default is false. bool double_buffer; gfx::NativeView parent; @@ -621,6 +623,10 @@ class Widget : public internal::NativeWidgetDelegate, // Sizes and positions the window just after it is created. void SetInitialBounds(const gfx::Rect& bounds); + // Returns the bounds and maximized state from the delegate. Returns true if + // the delegate wants to use a specified bounds. + bool GetSavedBounds(gfx::Rect* bounds, bool* maximize); + internal::NativeWidgetPrivate* native_widget_; ObserverList<Observer> observers_; @@ -677,6 +683,10 @@ class Widget : public internal::NativeWidgetDelegate, // that explains why we save this. bool saved_maximized_state_; + // The restored bounds used for the initial show. This is only used if + // |saved_maximized_state_| is true. + gfx::Rect initial_restored_bounds_; + // The smallest size the window can be. gfx::Size minimum_size_; |