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

Side by Side Diff: views/widget/widget.cc

Issue 7358005: Makes sure widget is created at right size before showing (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix comment Created 9 years, 5 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « views/widget/widget.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "views/widget/widget.h" 5 #include "views/widget/widget.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "ui/base/l10n/l10n_font_util.h" 10 #include "ui/base/l10n/l10n_font_util.h"
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 delegate(NULL), 89 delegate(NULL),
90 child(false), 90 child(false),
91 transient(false), 91 transient(false),
92 transparent(false), 92 transparent(false),
93 accept_events(true), 93 accept_events(true),
94 can_activate(true), 94 can_activate(true),
95 keep_on_top(false), 95 keep_on_top(false),
96 ownership(NATIVE_WIDGET_OWNS_WIDGET), 96 ownership(NATIVE_WIDGET_OWNS_WIDGET),
97 mirror_origin_in_rtl(false), 97 mirror_origin_in_rtl(false),
98 has_dropshadow(false), 98 has_dropshadow(false),
99 maximize(false),
99 double_buffer(false), 100 double_buffer(false),
100 parent(NULL), 101 parent(NULL),
101 parent_widget(NULL), 102 parent_widget(NULL),
102 native_widget(NULL) { 103 native_widget(NULL) {
103 } 104 }
104 105
105 Widget::InitParams::InitParams(Type type) 106 Widget::InitParams::InitParams(Type type)
106 : type(type), 107 : type(type),
107 delegate(NULL), 108 delegate(NULL),
108 child(type == TYPE_CONTROL), 109 child(type == TYPE_CONTROL),
109 transient(type == TYPE_POPUP || type == TYPE_MENU), 110 transient(type == TYPE_POPUP || type == TYPE_MENU),
110 transparent(false), 111 transparent(false),
111 accept_events(true), 112 accept_events(true),
112 can_activate(type != TYPE_POPUP && type != TYPE_MENU), 113 can_activate(type != TYPE_POPUP && type != TYPE_MENU),
113 keep_on_top(type == TYPE_MENU), 114 keep_on_top(type == TYPE_MENU),
114 ownership(NATIVE_WIDGET_OWNS_WIDGET), 115 ownership(NATIVE_WIDGET_OWNS_WIDGET),
115 mirror_origin_in_rtl(false), 116 mirror_origin_in_rtl(false),
116 has_dropshadow(false), 117 has_dropshadow(false),
118 maximize(false),
117 double_buffer(false), 119 double_buffer(false),
118 parent(NULL), 120 parent(NULL),
119 parent_widget(NULL), 121 parent_widget(NULL),
120 native_widget(NULL) { 122 native_widget(NULL) {
121 } 123 }
122 124
123 //////////////////////////////////////////////////////////////////////////////// 125 ////////////////////////////////////////////////////////////////////////////////
124 // Widget, public: 126 // Widget, public:
125 127
126 // static 128 // static
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 } 420 }
419 421
420 void Widget::EnableClose(bool enable) { 422 void Widget::EnableClose(bool enable) {
421 if (non_client_view_) 423 if (non_client_view_)
422 non_client_view_->EnableClose(enable); 424 non_client_view_->EnableClose(enable);
423 native_widget_->EnableClose(enable); 425 native_widget_->EnableClose(enable);
424 } 426 }
425 427
426 void Widget::Show() { 428 void Widget::Show() {
427 if (non_client_view_) { 429 if (non_client_view_) {
428 native_widget_->ShowNativeWidget( 430 if (saved_maximized_state_ && !initial_restored_bounds_.IsEmpty()) {
429 saved_maximized_state_ ? internal::NativeWidgetPrivate::SHOW_MAXIMIZED 431 native_widget_->ShowMaximizedWithBounds(initial_restored_bounds_);
430 : internal::NativeWidgetPrivate::SHOW_RESTORED); 432 } else {
433 native_widget_->ShowWithState(saved_maximized_state_ ?
434 internal::NativeWidgetPrivate::SHOW_MAXIMIZED :
435 internal::NativeWidgetPrivate::SHOW_RESTORED);
436 }
431 // |saved_maximized_state_| only applies the first time the window is shown. 437 // |saved_maximized_state_| only applies the first time the window is shown.
432 // If we don't reset the value the window will be shown maximized every time 438 // If we don't reset the value the window will be shown maximized every time
433 // it is subsequently shown after being hidden. 439 // it is subsequently shown after being hidden.
434 saved_maximized_state_ = false; 440 saved_maximized_state_ = false;
435 } else { 441 } else {
436 native_widget_->Show(); 442 native_widget_->Show();
437 } 443 }
438 } 444 }
439 445
440 void Widget::Hide() { 446 void Widget::Hide() {
441 native_widget_->Hide(); 447 native_widget_->Hide();
442 } 448 }
443 449
444 void Widget::ShowInactive() { 450 void Widget::ShowInactive() {
445 native_widget_->ShowNativeWidget( 451 native_widget_->ShowWithState(internal::NativeWidgetPrivate::SHOW_INACTIVE);
446 internal::NativeWidgetPrivate::SHOW_INACTIVE);
447 } 452 }
448 453
449 void Widget::Activate() { 454 void Widget::Activate() {
450 native_widget_->Activate(); 455 native_widget_->Activate();
451 } 456 }
452 457
453 void Widget::Deactivate() { 458 void Widget::Deactivate() {
454 native_widget_->Deactivate(); 459 native_widget_->Deactivate();
455 } 460 }
456 461
(...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after
992 bool maximized; 997 bool maximized;
993 gfx::Rect bounds; 998 gfx::Rect bounds;
994 native_widget_->GetWindowBoundsAndMaximizedState(&bounds, &maximized); 999 native_widget_->GetWindowBoundsAndMaximizedState(&bounds, &maximized);
995 widget_delegate_->SaveWindowPlacement(bounds, maximized); 1000 widget_delegate_->SaveWindowPlacement(bounds, maximized);
996 } 1001 }
997 1002
998 void Widget::SetInitialBounds(const gfx::Rect& bounds) { 1003 void Widget::SetInitialBounds(const gfx::Rect& bounds) {
999 if (!non_client_view_) 1004 if (!non_client_view_)
1000 return; 1005 return;
1001 1006
1002 // First we obtain the window's saved show-style and store it. We need to do 1007 gfx::Rect saved_bounds;
1003 // this here, rather than in Show() because by the time Show() is called, 1008 if (GetSavedBounds(&saved_bounds, &saved_maximized_state_)) {
1004 // the window's size will have been reset (below) and the saved maximized 1009 if (saved_maximized_state_) {
1005 // state will have been lost. Sadly there's no way to tell on Windows when 1010 // If we're going to maximize, wait until Show is invoked to set the
1006 // a window is restored from maximized state, so we can't more accurately 1011 // bounds. That way we avoid a noticable resize.
1007 // track maximized state independently of sizing information. 1012 initial_restored_bounds_ = saved_bounds;
1008 widget_delegate_->GetSavedMaximizedState(&saved_maximized_state_);
1009
1010 // Restore the window's placement from the controller.
1011 gfx::Rect saved_bounds = bounds;
1012 if (widget_delegate_->GetSavedWindowBounds(&saved_bounds)) {
1013 if (!widget_delegate_->ShouldRestoreWindowSize()) {
1014 saved_bounds.set_size(non_client_view_->GetPreferredSize());
1015 } else { 1013 } else {
1016 // Make sure the bounds are at least the minimum size. 1014 SetBounds(saved_bounds);
1017 if (saved_bounds.width() < minimum_size_.width()) {
1018 saved_bounds.SetRect(saved_bounds.x(), saved_bounds.y(),
1019 saved_bounds.right() + minimum_size_.width() -
1020 saved_bounds.width(),
1021 saved_bounds.bottom());
1022 }
1023
1024 if (saved_bounds.height() < minimum_size_.height()) {
1025 saved_bounds.SetRect(saved_bounds.x(), saved_bounds.y(),
1026 saved_bounds.right(),
1027 saved_bounds.bottom() + minimum_size_.height() -
1028 saved_bounds.height());
1029 }
1030 } 1015 }
1031
1032 // Widget's SetBounds method does not further modify the bounds that are
1033 // passed to it.
1034 SetBounds(saved_bounds);
1035 } else { 1016 } else {
1036 if (bounds.IsEmpty()) { 1017 if (bounds.IsEmpty()) {
1037 // No initial bounds supplied, so size the window to its content and 1018 // No initial bounds supplied, so size the window to its content and
1038 // center over its parent. 1019 // center over its parent.
1039 native_widget_->CenterWindow(non_client_view_->GetPreferredSize()); 1020 native_widget_->CenterWindow(non_client_view_->GetPreferredSize());
1040 } else { 1021 } else {
1041 // Use the supplied initial bounds. 1022 // Use the supplied initial bounds.
1042 SetBoundsConstrained(bounds, NULL); 1023 SetBoundsConstrained(bounds, NULL);
1043 } 1024 }
1044 } 1025 }
1045 } 1026 }
1046 1027
1028 bool Widget::GetSavedBounds(gfx::Rect* bounds, bool* maximize) {
1029 // First we obtain the window's saved show-style and store it. We need to do
1030 // this here, rather than in Show() because by the time Show() is called,
1031 // the window's size will have been reset (below) and the saved maximized
1032 // state will have been lost. Sadly there's no way to tell on Windows when
1033 // a window is restored from maximized state, so we can't more accurately
1034 // track maximized state independently of sizing information.
1035 widget_delegate_->GetSavedMaximizedState(maximize);
oshima 2011/07/19 16:23:44 no need to change in this CL, but looks like all t
1036
1037 // Restore the window's placement from the controller.
1038 if (widget_delegate_->GetSavedWindowBounds(bounds)) {
1039 if (!widget_delegate_->ShouldRestoreWindowSize()) {
1040 bounds->set_size(non_client_view_->GetPreferredSize());
1041 } else {
1042 // Make sure the bounds are at least the minimum size.
1043 if (bounds->width() < minimum_size_.width())
1044 bounds->set_width(minimum_size_.width());
1045
1046 if (bounds->height() < minimum_size_.height())
1047 bounds->set_height(minimum_size_.height());
1048 }
1049 return true;
1050 }
1051 return false;
1052 }
1053
1047 namespace internal { 1054 namespace internal {
1048 1055
1049 //////////////////////////////////////////////////////////////////////////////// 1056 ////////////////////////////////////////////////////////////////////////////////
1050 // internal::NativeWidgetPrivate, NativeWidget implementation: 1057 // internal::NativeWidgetPrivate, NativeWidget implementation:
1051 1058
1052 internal::NativeWidgetPrivate* NativeWidgetPrivate::AsNativeWidgetPrivate() { 1059 internal::NativeWidgetPrivate* NativeWidgetPrivate::AsNativeWidgetPrivate() {
1053 return this; 1060 return this;
1054 } 1061 }
1055 1062
1056 } // namespace internal 1063 } // namespace internal
1057 } // namespace views 1064 } // namespace views
OLDNEW
« no previous file with comments | « views/widget/widget.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698