Chromium Code Reviews| Index: views/widget/widget.cc |
| diff --git a/views/widget/widget.cc b/views/widget/widget.cc |
| index 9234483cf64353fb5b4e983ddb6a48f0fb2e13e6..b4e2d13b1247e21814769cd2250232009b0d2cca 100644 |
| --- a/views/widget/widget.cc |
| +++ b/views/widget/widget.cc |
| @@ -96,6 +96,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), |
| @@ -114,6 +115,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), |
| @@ -425,9 +427,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. |
| @@ -442,8 +448,7 @@ void Widget::Hide() { |
| } |
| void Widget::ShowInactive() { |
| - native_widget_->ShowNativeWidget( |
| - internal::NativeWidgetPrivate::SHOW_INACTIVE); |
| + native_widget_->ShowWithState(internal::NativeWidgetPrivate::SHOW_INACTIVE); |
| } |
| void Widget::Activate() { |
| @@ -999,49 +1004,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); |
|
oshima
2011/07/19 16:23:44
no need to change in this CL, but looks like all t
|
| // 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 { |