Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Unified Diff: views/widget/widget.cc

Issue 7748036: Restoring a session should restore window minimization state on Windows (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: views/widget/widget.cc
diff --git a/views/widget/widget.cc b/views/widget/widget.cc
index 7a42923d6fc6aee1feef095bd245d0d6b8b208b4..9a924a85041165e277eaf590c8962c85eee4b180 100644
--- a/views/widget/widget.cc
+++ b/views/widget/widget.cc
@@ -101,7 +101,7 @@ Widget::InitParams::InitParams()
ownership(NATIVE_WIDGET_OWNS_WIDGET),
mirror_origin_in_rtl(false),
has_dropshadow(false),
- maximize(false),
+ show_state(ui::SHOW_STATE_DEFAULT),
double_buffer(false),
parent(NULL),
parent_widget(NULL),
@@ -121,7 +121,7 @@ Widget::InitParams::InitParams(Type type)
ownership(NATIVE_WIDGET_OWNS_WIDGET),
mirror_origin_in_rtl(false),
has_dropshadow(false),
- maximize(false),
+ show_state(ui::SHOW_STATE_DEFAULT),
double_buffer(false),
parent(NULL),
parent_widget(NULL),
@@ -150,7 +150,7 @@ Widget::Widget()
frame_type_(FRAME_TYPE_DEFAULT),
disable_inactive_rendering_(false),
widget_closed_(false),
- saved_maximized_state_(false),
+ saved_show_state_(ui::SHOW_STATE_DEFAULT),
minimum_size_(100, 100),
focus_on_creation_(true),
is_top_level_(false),
@@ -306,8 +306,10 @@ void Widget::Init(const InitParams& params) {
non_client_view_->set_client_view(widget_delegate_->CreateClientView(this));
SetContentsView(non_client_view_);
SetInitialBounds(params.bounds);
- if (params.maximize)
+ if (params.show_state == ui::SHOW_STATE_MAXIMIZED)
Maximize();
+ else if (params.show_state == ui::SHOW_STATE_MINIMIZED)
+ Minimize();
UpdateWindowTitle();
}
}
@@ -468,17 +470,16 @@ void Widget::EnableClose(bool enable) {
void Widget::Show() {
if (non_client_view_) {
- if (saved_maximized_state_ && !initial_restored_bounds_.IsEmpty()) {
+ if (saved_show_state_ == ui::SHOW_STATE_MAXIMIZED &&
+ !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);
+ native_widget_->ShowWithWindowState(saved_show_state_);
}
- // |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
+ // |saved_show_state_| only applies the first time the window is shown.
+ // If we don't reset the value the window may be shown maximized every time
// it is subsequently shown after being hidden.
- saved_maximized_state_ = false;
+ saved_show_state_ = ui::SHOW_STATE_NORMAL;
} else {
native_widget_->Show();
}
@@ -489,14 +490,16 @@ void Widget::Hide() {
}
void Widget::ShowInactive() {
- // If this gets called with saved_maximized_state_ == true, call SetBounds()
- // with the restored bounds to set the correct size. This normally should
- // not happen, but if it does we should avoid showing unsized windows.
- if (saved_maximized_state_ && !initial_restored_bounds_.IsEmpty()) {
+ // If this gets called with saved_show_state_ == ui::SHOW_STATE_MAXIMIZED,
+ // call SetBounds()with the restored bounds to set the correct size. This
+ // normally should not happen, but if it does we should avoid showing unsized
+ // windows.
+ if (saved_show_state_ == ui::SHOW_STATE_MAXIMIZED &&
+ !initial_restored_bounds_.IsEmpty()) {
SetBounds(initial_restored_bounds_);
- saved_maximized_state_ = false;
+ saved_show_state_ = ui::SHOW_STATE_NORMAL;
}
- native_widget_->ShowWithState(internal::NativeWidgetPrivate::SHOW_INACTIVE);
+ native_widget_->ShowWithWindowState(ui::SHOW_STATE_INACTIVE);
}
void Widget::Activate() {
@@ -886,6 +889,12 @@ gfx::Size Widget::GetMinimumSize() {
void Widget::OnNativeWidgetSizeChanged(const gfx::Size& new_size) {
root_view_->SetSize(new_size);
+ // Having a focus manager is a signal that proper initialization has taken
+ // place. Size changed notifications can fire prior to full initialization
+ // i.e. during session restore. Avoid saving session state during these
+ // startup procedures.
+ if (HasFocusManager())
sky 2011/08/26 16:26:20 This seems a bit fragile. Could you instead add an
dhollowa 2011/08/26 22:13:50 Done.
+ SaveWindowPosition();
}
void Widget::OnNativeWidgetBeginUserBoundsChange() {
@@ -1063,10 +1072,10 @@ void Widget::SaveWindowPosition() {
if (!widget_delegate_)
return;
- bool maximized = false;
+ ui::WindowShowState show_state = ui::SHOW_STATE_NORMAL;
gfx::Rect bounds;
- native_widget_->GetWindowBoundsAndMaximizedState(&bounds, &maximized);
- widget_delegate_->SaveWindowPlacement(bounds, maximized);
+ native_widget_->GetWindowBoundsAndShowState(&bounds, &show_state);
+ widget_delegate_->SaveWindowPlacement(bounds, show_state);
}
void Widget::SetInitialBounds(const gfx::Rect& bounds) {
@@ -1074,8 +1083,8 @@ void Widget::SetInitialBounds(const gfx::Rect& bounds) {
return;
gfx::Rect saved_bounds;
- if (GetSavedBounds(&saved_bounds, &saved_maximized_state_)) {
- if (saved_maximized_state_) {
+ if (GetSavedBounds(&saved_bounds, &saved_show_state_)) {
+ if (saved_show_state_ == ui::SHOW_STATE_MAXIMIZED) {
// 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;
@@ -1094,14 +1103,15 @@ void Widget::SetInitialBounds(const gfx::Rect& bounds) {
}
}
-bool Widget::GetSavedBounds(gfx::Rect* bounds, bool* maximize) {
+bool Widget::GetSavedBounds(gfx::Rect* bounds,
+ ui::WindowShowState* show_state) {
// 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(maximize);
+ widget_delegate_->GetSavedWindowShowState(show_state);
// Restore the window's placement from the controller.
if (widget_delegate_->GetSavedWindowBounds(bounds)) {

Powered by Google App Engine
This is Rietveld 408576698