| Index: views/widget/widget.cc
|
| diff --git a/views/widget/widget.cc b/views/widget/widget.cc
|
| index d3099176a6747f9ea08ae3ff0d4fa59fa0dbe3e0..1df8c725c253dee81442f8766d25b600620a2e3c 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),
|
| @@ -270,12 +272,23 @@ void Widget::Init(const InitParams& params) {
|
| is_mouse_button_pressed_ =
|
| internal::NativeWidgetPrivate::IsMouseButtonDown();
|
| }
|
| - native_widget_->InitNativeWidget(params);
|
| + InitParams params_copy(params);
|
| + if (params.type == InitParams::TYPE_WINDOW) {
|
| + // If we're creating a window see if the delegate wants us to use a size
|
| + // different than that supplied to the constructor.
|
| + gfx::Rect saved_bounds;
|
| + bool saved_maximized_state;
|
| + if (GetSavedBounds(&saved_bounds, &saved_maximized_state)) {
|
| + params_copy.maximize = saved_maximized_state;
|
| + params_copy.bounds = saved_bounds;
|
| + }
|
| + }
|
| + native_widget_->InitNativeWidget(params_copy);
|
| if (params.type == InitParams::TYPE_WINDOW) {
|
| - non_client_view_ = new NonClientView;
|
| - non_client_view_->SetFrameView(CreateNonClientFrameView());
|
| // Create the ClientView, add it to the NonClientView and add the
|
| // NonClientView to the RootView. This will cause everything to be parented.
|
| + non_client_view_ = new NonClientView;
|
| + non_client_view_->SetFrameView(CreateNonClientFrameView());
|
| non_client_view_->set_client_view(widget_delegate_->CreateClientView(this));
|
| SetContentsView(non_client_view_);
|
| SetInitialBounds(params.bounds);
|
| @@ -412,9 +425,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_->ShowMaximized(initial_restored_bounds_);
|
| + } else {
|
| + native_widget_->ShowNativeWidget(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.
|
| @@ -972,50 +989,55 @@ 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());
|
| + if (!non_client_view_) {
|
| + // This may be invoked before the non_client_view_ is created.
|
| + return false;
|
| + }
|
| + 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 {
|
|
|