| OLD | NEW |
| 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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 delegate(NULL), | 94 delegate(NULL), |
| 95 child(false), | 95 child(false), |
| 96 transient(false), | 96 transient(false), |
| 97 transparent(false), | 97 transparent(false), |
| 98 accept_events(true), | 98 accept_events(true), |
| 99 can_activate(true), | 99 can_activate(true), |
| 100 keep_on_top(false), | 100 keep_on_top(false), |
| 101 ownership(NATIVE_WIDGET_OWNS_WIDGET), | 101 ownership(NATIVE_WIDGET_OWNS_WIDGET), |
| 102 mirror_origin_in_rtl(false), | 102 mirror_origin_in_rtl(false), |
| 103 has_dropshadow(false), | 103 has_dropshadow(false), |
| 104 maximize(false), | 104 show_state(ui::SHOW_STATE_DEFAULT), |
| 105 double_buffer(false), | 105 double_buffer(false), |
| 106 parent(NULL), | 106 parent(NULL), |
| 107 parent_widget(NULL), | 107 parent_widget(NULL), |
| 108 native_widget(NULL), | 108 native_widget(NULL), |
| 109 top_level(false) { | 109 top_level(false) { |
| 110 } | 110 } |
| 111 | 111 |
| 112 Widget::InitParams::InitParams(Type type) | 112 Widget::InitParams::InitParams(Type type) |
| 113 : type(type), | 113 : type(type), |
| 114 delegate(NULL), | 114 delegate(NULL), |
| 115 child(type == TYPE_CONTROL), | 115 child(type == TYPE_CONTROL), |
| 116 transient(type == TYPE_POPUP || type == TYPE_MENU), | 116 transient(type == TYPE_POPUP || type == TYPE_MENU), |
| 117 transparent(false), | 117 transparent(false), |
| 118 accept_events(true), | 118 accept_events(true), |
| 119 can_activate(type != TYPE_POPUP && type != TYPE_MENU), | 119 can_activate(type != TYPE_POPUP && type != TYPE_MENU), |
| 120 keep_on_top(type == TYPE_MENU), | 120 keep_on_top(type == TYPE_MENU), |
| 121 ownership(NATIVE_WIDGET_OWNS_WIDGET), | 121 ownership(NATIVE_WIDGET_OWNS_WIDGET), |
| 122 mirror_origin_in_rtl(false), | 122 mirror_origin_in_rtl(false), |
| 123 has_dropshadow(false), | 123 has_dropshadow(false), |
| 124 maximize(false), | 124 show_state(ui::SHOW_STATE_DEFAULT), |
| 125 double_buffer(false), | 125 double_buffer(false), |
| 126 parent(NULL), | 126 parent(NULL), |
| 127 parent_widget(NULL), | 127 parent_widget(NULL), |
| 128 native_widget(NULL), | 128 native_widget(NULL), |
| 129 top_level(false) { | 129 top_level(false) { |
| 130 } | 130 } |
| 131 | 131 |
| 132 //////////////////////////////////////////////////////////////////////////////// | 132 //////////////////////////////////////////////////////////////////////////////// |
| 133 // Widget, public: | 133 // Widget, public: |
| 134 | 134 |
| 135 // static | 135 // static |
| 136 Widget::InitParams Widget::WindowInitParams() { | 136 Widget::InitParams Widget::WindowInitParams() { |
| 137 return InitParams(InitParams::TYPE_WINDOW); | 137 return InitParams(InitParams::TYPE_WINDOW); |
| 138 } | 138 } |
| 139 | 139 |
| 140 Widget::Widget() | 140 Widget::Widget() |
| 141 : is_mouse_button_pressed_(false), | 141 : is_mouse_button_pressed_(false), |
| 142 last_mouse_event_was_move_(false), | 142 last_mouse_event_was_move_(false), |
| 143 native_widget_(NULL), | 143 native_widget_(NULL), |
| 144 widget_delegate_(NULL), | 144 widget_delegate_(NULL), |
| 145 non_client_view_(NULL), | 145 non_client_view_(NULL), |
| 146 dragged_view_(NULL), | 146 dragged_view_(NULL), |
| 147 event_stack_(), | 147 event_stack_(), |
| 148 ownership_(InitParams::NATIVE_WIDGET_OWNS_WIDGET), | 148 ownership_(InitParams::NATIVE_WIDGET_OWNS_WIDGET), |
| 149 is_secondary_widget_(true), | 149 is_secondary_widget_(true), |
| 150 frame_type_(FRAME_TYPE_DEFAULT), | 150 frame_type_(FRAME_TYPE_DEFAULT), |
| 151 disable_inactive_rendering_(false), | 151 disable_inactive_rendering_(false), |
| 152 widget_closed_(false), | 152 widget_closed_(false), |
| 153 saved_maximized_state_(false), | 153 saved_show_state_(ui::SHOW_STATE_DEFAULT), |
| 154 minimum_size_(100, 100), | 154 minimum_size_(100, 100), |
| 155 focus_on_creation_(true), | 155 focus_on_creation_(true), |
| 156 is_top_level_(false), | 156 is_top_level_(false), |
| 157 destroy_state_(DESTROY_STATE_NONE) { | 157 destroy_state_(DESTROY_STATE_NONE), |
| 158 native_widget_created_(false) { |
| 158 } | 159 } |
| 159 | 160 |
| 160 Widget::~Widget() { | 161 Widget::~Widget() { |
| 161 destroy_state_ = DESTROY_STATE_DELETED; | 162 destroy_state_ = DESTROY_STATE_DELETED; |
| 162 | 163 |
| 163 while (!event_stack_.empty()) { | 164 while (!event_stack_.empty()) { |
| 164 event_stack_.top()->reset(); | 165 event_stack_.top()->reset(); |
| 165 event_stack_.pop(); | 166 event_stack_.pop(); |
| 166 } | 167 } |
| 167 | 168 |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 } | 300 } |
| 300 native_widget_->InitNativeWidget(params); | 301 native_widget_->InitNativeWidget(params); |
| 301 if (params.type == InitParams::TYPE_WINDOW) { | 302 if (params.type == InitParams::TYPE_WINDOW) { |
| 302 non_client_view_ = new NonClientView; | 303 non_client_view_ = new NonClientView; |
| 303 non_client_view_->SetFrameView(CreateNonClientFrameView()); | 304 non_client_view_->SetFrameView(CreateNonClientFrameView()); |
| 304 // Create the ClientView, add it to the NonClientView and add the | 305 // Create the ClientView, add it to the NonClientView and add the |
| 305 // NonClientView to the RootView. This will cause everything to be parented. | 306 // NonClientView to the RootView. This will cause everything to be parented. |
| 306 non_client_view_->set_client_view(widget_delegate_->CreateClientView(this)); | 307 non_client_view_->set_client_view(widget_delegate_->CreateClientView(this)); |
| 307 SetContentsView(non_client_view_); | 308 SetContentsView(non_client_view_); |
| 308 SetInitialBounds(params.bounds); | 309 SetInitialBounds(params.bounds); |
| 309 if (params.maximize) | 310 if (params.show_state == ui::SHOW_STATE_MAXIMIZED) |
| 310 Maximize(); | 311 Maximize(); |
| 312 else if (params.show_state == ui::SHOW_STATE_MINIMIZED) |
| 313 Minimize(); |
| 311 UpdateWindowTitle(); | 314 UpdateWindowTitle(); |
| 312 } | 315 } |
| 313 } | 316 } |
| 314 | 317 |
| 315 // Unconverted methods (see header) -------------------------------------------- | 318 // Unconverted methods (see header) -------------------------------------------- |
| 316 | 319 |
| 317 gfx::NativeView Widget::GetNativeView() const { | 320 gfx::NativeView Widget::GetNativeView() const { |
| 318 return native_widget_->GetNativeView(); | 321 return native_widget_->GetNativeView(); |
| 319 } | 322 } |
| 320 | 323 |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 // It appears we can hit this code path if you close a modal dialog then | 437 // It appears we can hit this code path if you close a modal dialog then |
| 435 // close the last browser before the destructor is hit, which triggers | 438 // close the last browser before the destructor is hit, which triggers |
| 436 // invoking Close again. | 439 // invoking Close again. |
| 437 return; | 440 return; |
| 438 } | 441 } |
| 439 | 442 |
| 440 bool can_close = true; | 443 bool can_close = true; |
| 441 if (non_client_view_) | 444 if (non_client_view_) |
| 442 can_close = non_client_view_->CanClose(); | 445 can_close = non_client_view_->CanClose(); |
| 443 if (can_close) { | 446 if (can_close) { |
| 444 SaveWindowPosition(); | 447 SaveWindowPlacement(); |
| 445 | 448 |
| 446 // During tear-down the top-level focus manager becomes unavailable to | 449 // During tear-down the top-level focus manager becomes unavailable to |
| 447 // GTK tabbed panes and their children, so normal deregistration via | 450 // GTK tabbed panes and their children, so normal deregistration via |
| 448 // |FormManager::ViewRemoved()| calls are fouled. We clear focus here | 451 // |FormManager::ViewRemoved()| calls are fouled. We clear focus here |
| 449 // to avoid these redundant steps and to avoid accessing deleted views | 452 // to avoid these redundant steps and to avoid accessing deleted views |
| 450 // that may have been in focus. | 453 // that may have been in focus. |
| 451 if (is_top_level() && focus_manager_.get()) | 454 if (is_top_level() && focus_manager_.get()) |
| 452 focus_manager_->SetFocusedView(NULL); | 455 focus_manager_->SetFocusedView(NULL); |
| 453 | 456 |
| 454 native_widget_->Close(); | 457 native_widget_->Close(); |
| 455 widget_closed_ = true; | 458 widget_closed_ = true; |
| 456 } | 459 } |
| 457 } | 460 } |
| 458 | 461 |
| 459 void Widget::CloseNow() { | 462 void Widget::CloseNow() { |
| 460 native_widget_->CloseNow(); | 463 native_widget_->CloseNow(); |
| 461 } | 464 } |
| 462 | 465 |
| 463 void Widget::EnableClose(bool enable) { | 466 void Widget::EnableClose(bool enable) { |
| 464 if (non_client_view_) | 467 if (non_client_view_) |
| 465 non_client_view_->EnableClose(enable); | 468 non_client_view_->EnableClose(enable); |
| 466 native_widget_->EnableClose(enable); | 469 native_widget_->EnableClose(enable); |
| 467 } | 470 } |
| 468 | 471 |
| 469 void Widget::Show() { | 472 void Widget::Show() { |
| 470 if (non_client_view_) { | 473 if (non_client_view_) { |
| 471 if (saved_maximized_state_ && !initial_restored_bounds_.IsEmpty()) { | 474 if (saved_show_state_ == ui::SHOW_STATE_MAXIMIZED && |
| 475 !initial_restored_bounds_.IsEmpty()) { |
| 472 native_widget_->ShowMaximizedWithBounds(initial_restored_bounds_); | 476 native_widget_->ShowMaximizedWithBounds(initial_restored_bounds_); |
| 473 } else { | 477 } else { |
| 474 native_widget_->ShowWithState(saved_maximized_state_ ? | 478 native_widget_->ShowWithWindowState(saved_show_state_); |
| 475 internal::NativeWidgetPrivate::SHOW_MAXIMIZED : | |
| 476 internal::NativeWidgetPrivate::SHOW_RESTORED); | |
| 477 } | 479 } |
| 478 // |saved_maximized_state_| only applies the first time the window is shown. | 480 // |saved_show_state_| only applies the first time the window is shown. |
| 479 // If we don't reset the value the window will be shown maximized every time | 481 // If we don't reset the value the window may be shown maximized every time |
| 480 // it is subsequently shown after being hidden. | 482 // it is subsequently shown after being hidden. |
| 481 saved_maximized_state_ = false; | 483 saved_show_state_ = ui::SHOW_STATE_NORMAL; |
| 482 } else { | 484 } else { |
| 483 native_widget_->Show(); | 485 native_widget_->Show(); |
| 484 } | 486 } |
| 485 } | 487 } |
| 486 | 488 |
| 487 void Widget::Hide() { | 489 void Widget::Hide() { |
| 488 native_widget_->Hide(); | 490 native_widget_->Hide(); |
| 489 } | 491 } |
| 490 | 492 |
| 491 void Widget::ShowInactive() { | 493 void Widget::ShowInactive() { |
| 492 // If this gets called with saved_maximized_state_ == true, call SetBounds() | 494 // If this gets called with saved_show_state_ == ui::SHOW_STATE_MAXIMIZED, |
| 493 // with the restored bounds to set the correct size. This normally should | 495 // call SetBounds()with the restored bounds to set the correct size. This |
| 494 // not happen, but if it does we should avoid showing unsized windows. | 496 // normally should not happen, but if it does we should avoid showing unsized |
| 495 if (saved_maximized_state_ && !initial_restored_bounds_.IsEmpty()) { | 497 // windows. |
| 498 if (saved_show_state_ == ui::SHOW_STATE_MAXIMIZED && |
| 499 !initial_restored_bounds_.IsEmpty()) { |
| 496 SetBounds(initial_restored_bounds_); | 500 SetBounds(initial_restored_bounds_); |
| 497 saved_maximized_state_ = false; | 501 saved_show_state_ = ui::SHOW_STATE_NORMAL; |
| 498 } | 502 } |
| 499 native_widget_->ShowWithState(internal::NativeWidgetPrivate::SHOW_INACTIVE); | 503 native_widget_->ShowWithWindowState(ui::SHOW_STATE_INACTIVE); |
| 500 } | 504 } |
| 501 | 505 |
| 502 void Widget::Activate() { | 506 void Widget::Activate() { |
| 503 native_widget_->Activate(); | 507 native_widget_->Activate(); |
| 504 } | 508 } |
| 505 | 509 |
| 506 void Widget::Deactivate() { | 510 void Widget::Deactivate() { |
| 507 native_widget_->Deactivate(); | 511 native_widget_->Deactivate(); |
| 508 } | 512 } |
| 509 | 513 |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 813 } | 817 } |
| 814 | 818 |
| 815 void Widget::EnableInactiveRendering() { | 819 void Widget::EnableInactiveRendering() { |
| 816 disable_inactive_rendering_ = false; | 820 disable_inactive_rendering_ = false; |
| 817 if (non_client_view_) | 821 if (non_client_view_) |
| 818 non_client_view_->DisableInactiveRendering(false); | 822 non_client_view_->DisableInactiveRendering(false); |
| 819 } | 823 } |
| 820 | 824 |
| 821 void Widget::OnNativeWidgetActivationChanged(bool active) { | 825 void Widget::OnNativeWidgetActivationChanged(bool active) { |
| 822 if (!active) { | 826 if (!active) { |
| 823 SaveWindowPosition(); | 827 SaveWindowPlacement(); |
| 824 | 828 |
| 825 // Close any open menus. | 829 // Close any open menus. |
| 826 MenuController* menu_controller = MenuController::GetActiveInstance(); | 830 MenuController* menu_controller = MenuController::GetActiveInstance(); |
| 827 if (menu_controller) | 831 if (menu_controller) |
| 828 menu_controller->OnWidgetActivationChanged(); | 832 menu_controller->OnWidgetActivationChanged(); |
| 829 } | 833 } |
| 830 | 834 |
| 831 FOR_EACH_OBSERVER(Observer, observers_, | 835 FOR_EACH_OBSERVER(Observer, observers_, |
| 832 OnWidgetActivationChanged(this, active)); | 836 OnWidgetActivationChanged(this, active)); |
| 833 } | 837 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 854 if (is_top_level()) | 858 if (is_top_level()) |
| 855 focus_manager_.reset(FocusManagerFactory::Create(this)); | 859 focus_manager_.reset(FocusManagerFactory::Create(this)); |
| 856 | 860 |
| 857 native_widget_->SetAccessibleRole( | 861 native_widget_->SetAccessibleRole( |
| 858 widget_delegate_->GetAccessibleWindowRole()); | 862 widget_delegate_->GetAccessibleWindowRole()); |
| 859 native_widget_->SetAccessibleState( | 863 native_widget_->SetAccessibleState( |
| 860 widget_delegate_->GetAccessibleWindowState()); | 864 widget_delegate_->GetAccessibleWindowState()); |
| 861 | 865 |
| 862 if (widget_delegate_->IsModal()) | 866 if (widget_delegate_->IsModal()) |
| 863 native_widget_->BecomeModal(); | 867 native_widget_->BecomeModal(); |
| 868 |
| 869 native_widget_created_ = true; |
| 864 } | 870 } |
| 865 | 871 |
| 866 void Widget::OnNativeWidgetDestroying() { | 872 void Widget::OnNativeWidgetDestroying() { |
| 867 FOR_EACH_OBSERVER(Observer, observers_, OnWidgetClosing(this)); | 873 FOR_EACH_OBSERVER(Observer, observers_, OnWidgetClosing(this)); |
| 868 if (destroy_state_ == DESTROY_STATE_NONE) | 874 if (destroy_state_ == DESTROY_STATE_NONE) |
| 869 destroy_state_ = DESTROY_STATE_IN_DESTROYING; | 875 destroy_state_ = DESTROY_STATE_IN_DESTROYING; |
| 870 if (non_client_view_) | 876 if (non_client_view_) |
| 871 non_client_view_->WindowClosing(); | 877 non_client_view_->WindowClosing(); |
| 872 widget_delegate_->WindowClosing(); | 878 widget_delegate_->WindowClosing(); |
| 873 } | 879 } |
| 874 | 880 |
| 875 void Widget::OnNativeWidgetDestroyed() { | 881 void Widget::OnNativeWidgetDestroyed() { |
| 876 if (destroy_state_ == DESTROY_STATE_IN_DESTROYING || | 882 if (destroy_state_ == DESTROY_STATE_IN_DESTROYING || |
| 877 destroy_state_ == DESTROY_STATE_NONE) | 883 destroy_state_ == DESTROY_STATE_NONE) |
| 878 destroy_state_ = DESTROY_STATE_DESTROYED; | 884 destroy_state_ = DESTROY_STATE_DESTROYED; |
| 879 widget_delegate_->DeleteDelegate(); | 885 widget_delegate_->DeleteDelegate(); |
| 880 widget_delegate_ = NULL; | 886 widget_delegate_ = NULL; |
| 881 } | 887 } |
| 882 | 888 |
| 883 gfx::Size Widget::GetMinimumSize() { | 889 gfx::Size Widget::GetMinimumSize() { |
| 884 return non_client_view_ ? non_client_view_->GetMinimumSize() : gfx::Size(); | 890 return non_client_view_ ? non_client_view_->GetMinimumSize() : gfx::Size(); |
| 885 } | 891 } |
| 886 | 892 |
| 887 void Widget::OnNativeWidgetSizeChanged(const gfx::Size& new_size) { | 893 void Widget::OnNativeWidgetSizeChanged(const gfx::Size& new_size) { |
| 888 root_view_->SetSize(new_size); | 894 root_view_->SetSize(new_size); |
| 895 |
| 896 // Size changed notifications can fire prior to full initialization |
| 897 // i.e. during session restore. Avoid saving session state during these |
| 898 // startup procedures. |
| 899 if (native_widget_created_) |
| 900 SaveWindowPlacement(); |
| 889 } | 901 } |
| 890 | 902 |
| 891 void Widget::OnNativeWidgetBeginUserBoundsChange() { | 903 void Widget::OnNativeWidgetBeginUserBoundsChange() { |
| 892 widget_delegate_->OnWindowBeginUserBoundsChange(); | 904 widget_delegate_->OnWindowBeginUserBoundsChange(); |
| 893 } | 905 } |
| 894 | 906 |
| 895 void Widget::OnNativeWidgetEndUserBoundsChange() { | 907 void Widget::OnNativeWidgetEndUserBoundsChange() { |
| 896 widget_delegate_->OnWindowEndUserBoundsChange(); | 908 widget_delegate_->OnWindowEndUserBoundsChange(); |
| 897 } | 909 } |
| 898 | 910 |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1048 //////////////////////////////////////////////////////////////////////////////// | 1060 //////////////////////////////////////////////////////////////////////////////// |
| 1049 // Widget, private: | 1061 // Widget, private: |
| 1050 | 1062 |
| 1051 // static | 1063 // static |
| 1052 ui::Compositor*(*Widget::compositor_factory_)() = NULL; | 1064 ui::Compositor*(*Widget::compositor_factory_)() = NULL; |
| 1053 | 1065 |
| 1054 bool Widget::ShouldReleaseCaptureOnMouseReleased() const { | 1066 bool Widget::ShouldReleaseCaptureOnMouseReleased() const { |
| 1055 return true; | 1067 return true; |
| 1056 } | 1068 } |
| 1057 | 1069 |
| 1058 void Widget::SaveWindowPosition() { | 1070 void Widget::SaveWindowPlacement() { |
| 1059 // The window delegate does the actual saving for us. It seems like (judging | 1071 // The window delegate does the actual saving for us. It seems like (judging |
| 1060 // by go/crash) that in some circumstances we can end up here after | 1072 // by go/crash) that in some circumstances we can end up here after |
| 1061 // WM_DESTROY, at which point the window delegate is likely gone. So just | 1073 // WM_DESTROY, at which point the window delegate is likely gone. So just |
| 1062 // bail. | 1074 // bail. |
| 1063 if (!widget_delegate_) | 1075 if (!widget_delegate_) |
| 1064 return; | 1076 return; |
| 1065 | 1077 |
| 1066 bool maximized = false; | 1078 ui::WindowShowState show_state = ui::SHOW_STATE_NORMAL; |
| 1067 gfx::Rect bounds; | 1079 gfx::Rect bounds; |
| 1068 native_widget_->GetWindowBoundsAndMaximizedState(&bounds, &maximized); | 1080 native_widget_->GetWindowPlacement(&bounds, &show_state); |
| 1069 widget_delegate_->SaveWindowPlacement(bounds, maximized); | 1081 widget_delegate_->SaveWindowPlacement(bounds, show_state); |
| 1070 } | 1082 } |
| 1071 | 1083 |
| 1072 void Widget::SetInitialBounds(const gfx::Rect& bounds) { | 1084 void Widget::SetInitialBounds(const gfx::Rect& bounds) { |
| 1073 if (!non_client_view_) | 1085 if (!non_client_view_) |
| 1074 return; | 1086 return; |
| 1075 | 1087 |
| 1076 gfx::Rect saved_bounds; | 1088 gfx::Rect saved_bounds; |
| 1077 if (GetSavedBounds(&saved_bounds, &saved_maximized_state_)) { | 1089 if (GetSavedWindowPlacement(&saved_bounds, &saved_show_state_)) { |
| 1078 if (saved_maximized_state_) { | 1090 if (saved_show_state_ == ui::SHOW_STATE_MAXIMIZED) { |
| 1079 // If we're going to maximize, wait until Show is invoked to set the | 1091 // If we're going to maximize, wait until Show is invoked to set the |
| 1080 // bounds. That way we avoid a noticable resize. | 1092 // bounds. That way we avoid a noticable resize. |
| 1081 initial_restored_bounds_ = saved_bounds; | 1093 initial_restored_bounds_ = saved_bounds; |
| 1082 } else { | 1094 } else { |
| 1083 SetBounds(saved_bounds); | 1095 SetBounds(saved_bounds); |
| 1084 } | 1096 } |
| 1085 } else { | 1097 } else { |
| 1086 if (bounds.IsEmpty()) { | 1098 if (bounds.IsEmpty()) { |
| 1087 // No initial bounds supplied, so size the window to its content and | 1099 // No initial bounds supplied, so size the window to its content and |
| 1088 // center over its parent. | 1100 // center over its parent. |
| 1089 native_widget_->CenterWindow(non_client_view_->GetPreferredSize()); | 1101 native_widget_->CenterWindow(non_client_view_->GetPreferredSize()); |
| 1090 } else { | 1102 } else { |
| 1091 // Use the supplied initial bounds. | 1103 // Use the supplied initial bounds. |
| 1092 SetBoundsConstrained(bounds, NULL); | 1104 SetBoundsConstrained(bounds, NULL); |
| 1093 } | 1105 } |
| 1094 } | 1106 } |
| 1095 } | 1107 } |
| 1096 | 1108 |
| 1097 bool Widget::GetSavedBounds(gfx::Rect* bounds, bool* maximize) { | 1109 bool Widget::GetSavedWindowPlacement(gfx::Rect* bounds, |
| 1110 ui::WindowShowState* show_state) { |
| 1098 // First we obtain the window's saved show-style and store it. We need to do | 1111 // First we obtain the window's saved show-style and store it. We need to do |
| 1099 // this here, rather than in Show() because by the time Show() is called, | 1112 // this here, rather than in Show() because by the time Show() is called, |
| 1100 // the window's size will have been reset (below) and the saved maximized | 1113 // the window's size will have been reset (below) and the saved maximized |
| 1101 // state will have been lost. Sadly there's no way to tell on Windows when | 1114 // state will have been lost. Sadly there's no way to tell on Windows when |
| 1102 // a window is restored from maximized state, so we can't more accurately | 1115 // a window is restored from maximized state, so we can't more accurately |
| 1103 // track maximized state independently of sizing information. | 1116 // track maximized state independently of sizing information. |
| 1104 widget_delegate_->GetSavedMaximizedState(maximize); | |
| 1105 | 1117 |
| 1106 // Restore the window's placement from the controller. | 1118 // Restore the window's placement from the controller. |
| 1107 if (widget_delegate_->GetSavedWindowBounds(bounds)) { | 1119 if (widget_delegate_->GetSavedWindowPlacement(bounds, show_state)) { |
| 1108 if (!widget_delegate_->ShouldRestoreWindowSize()) { | 1120 if (!widget_delegate_->ShouldRestoreWindowSize()) { |
| 1109 bounds->set_size(non_client_view_->GetPreferredSize()); | 1121 bounds->set_size(non_client_view_->GetPreferredSize()); |
| 1110 } else { | 1122 } else { |
| 1111 // Make sure the bounds are at least the minimum size. | 1123 // Make sure the bounds are at least the minimum size. |
| 1112 if (bounds->width() < minimum_size_.width()) | 1124 if (bounds->width() < minimum_size_.width()) |
| 1113 bounds->set_width(minimum_size_.width()); | 1125 bounds->set_width(minimum_size_.width()); |
| 1114 | 1126 |
| 1115 if (bounds->height() < minimum_size_.height()) | 1127 if (bounds->height() < minimum_size_.height()) |
| 1116 bounds->set_height(minimum_size_.height()); | 1128 bounds->set_height(minimum_size_.height()); |
| 1117 } | 1129 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1134 | 1146 |
| 1135 //////////////////////////////////////////////////////////////////////////////// | 1147 //////////////////////////////////////////////////////////////////////////////// |
| 1136 // internal::NativeWidgetPrivate, NativeWidget implementation: | 1148 // internal::NativeWidgetPrivate, NativeWidget implementation: |
| 1137 | 1149 |
| 1138 internal::NativeWidgetPrivate* NativeWidgetPrivate::AsNativeWidgetPrivate() { | 1150 internal::NativeWidgetPrivate* NativeWidgetPrivate::AsNativeWidgetPrivate() { |
| 1139 return this; | 1151 return this; |
| 1140 } | 1152 } |
| 1141 | 1153 |
| 1142 } // namespace internal | 1154 } // namespace internal |
| 1143 } // namespace views | 1155 } // namespace views |
| OLD | NEW |