OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ui/views/widget/widget.h" | 5 #include "ui/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/hit_test.h" | 10 #include "ui/base/hit_test.h" |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 // Create the ClientView, add it to the NonClientView and add the | 329 // Create the ClientView, add it to the NonClientView and add the |
330 // NonClientView to the RootView. This will cause everything to be parented. | 330 // NonClientView to the RootView. This will cause everything to be parented. |
331 non_client_view_->set_client_view(widget_delegate_->CreateClientView(this)); | 331 non_client_view_->set_client_view(widget_delegate_->CreateClientView(this)); |
332 SetContentsView(non_client_view_); | 332 SetContentsView(non_client_view_); |
333 SetInitialBounds(params.bounds); | 333 SetInitialBounds(params.bounds); |
334 if (params.show_state == ui::SHOW_STATE_MAXIMIZED) | 334 if (params.show_state == ui::SHOW_STATE_MAXIMIZED) |
335 Maximize(); | 335 Maximize(); |
336 else if (params.show_state == ui::SHOW_STATE_MINIMIZED) | 336 else if (params.show_state == ui::SHOW_STATE_MINIMIZED) |
337 Minimize(); | 337 Minimize(); |
338 UpdateWindowTitle(); | 338 UpdateWindowTitle(); |
| 339 } else if (params.delegate) { |
| 340 SetContentsView(params.delegate->GetContentsView()); |
| 341 SetInitialBoundsForFramelessWindow(params.bounds); |
339 } | 342 } |
340 native_widget_initialized_ = true; | 343 native_widget_initialized_ = true; |
341 } | 344 } |
342 | 345 |
343 // Unconverted methods (see header) -------------------------------------------- | 346 // Unconverted methods (see header) -------------------------------------------- |
344 | 347 |
345 gfx::NativeView Widget::GetNativeView() const { | 348 gfx::NativeView Widget::GetNativeView() const { |
346 return native_widget_->GetNativeView(); | 349 return native_widget_->GetNativeView(); |
347 } | 350 } |
348 | 351 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 | 402 |
400 const Widget* Widget::GetTopLevelWidget() const { | 403 const Widget* Widget::GetTopLevelWidget() const { |
401 // GetTopLevelNativeWidget doesn't work during destruction because | 404 // GetTopLevelNativeWidget doesn't work during destruction because |
402 // property is gone after gobject gets deleted. Short circuit here | 405 // property is gone after gobject gets deleted. Short circuit here |
403 // for toplevel so that InputMethod can remove itself from | 406 // for toplevel so that InputMethod can remove itself from |
404 // focus manager. | 407 // focus manager. |
405 return is_top_level() ? this : native_widget_->GetTopLevelWidget(); | 408 return is_top_level() ? this : native_widget_->GetTopLevelWidget(); |
406 } | 409 } |
407 | 410 |
408 void Widget::SetContentsView(View* view) { | 411 void Widget::SetContentsView(View* view) { |
| 412 // Do not SetContentsView() again if it is already set to the same view. |
| 413 if (view == GetContentsView()) |
| 414 return; |
409 root_view_->SetContentsView(view); | 415 root_view_->SetContentsView(view); |
410 if (non_client_view_ != view) | 416 if (non_client_view_ != view) |
411 non_client_view_ = NULL; | 417 non_client_view_ = NULL; |
412 } | 418 } |
413 | 419 |
414 View* Widget::GetContentsView() { | 420 View* Widget::GetContentsView() { |
415 return root_view_->GetContentsView(); | 421 return root_view_->GetContentsView(); |
416 } | 422 } |
417 | 423 |
418 gfx::Rect Widget::GetWindowScreenBounds() const { | 424 gfx::Rect Widget::GetWindowScreenBounds() const { |
(...skipping 778 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1197 // No initial bounds supplied, so size the window to its content and | 1203 // No initial bounds supplied, so size the window to its content and |
1198 // center over its parent. | 1204 // center over its parent. |
1199 native_widget_->CenterWindow(non_client_view_->GetPreferredSize()); | 1205 native_widget_->CenterWindow(non_client_view_->GetPreferredSize()); |
1200 } else { | 1206 } else { |
1201 // Use the supplied initial bounds. | 1207 // Use the supplied initial bounds. |
1202 SetBoundsConstrained(bounds); | 1208 SetBoundsConstrained(bounds); |
1203 } | 1209 } |
1204 } | 1210 } |
1205 } | 1211 } |
1206 | 1212 |
| 1213 void Widget::SetInitialBoundsForFramelessWindow(const gfx::Rect& bounds) { |
| 1214 if (bounds.IsEmpty()) { |
| 1215 View* contents_view = GetContentsView(); |
| 1216 DCHECK(contents_view); |
| 1217 // No initial bounds supplied, so size the window to its content and |
| 1218 // center over its parent if preferred size is provided. |
| 1219 gfx::Size size = contents_view->GetPreferredSize(); |
| 1220 if (!size.IsEmpty()) |
| 1221 native_widget_->CenterWindow(size); |
| 1222 } else { |
| 1223 // Use the supplied initial bounds. |
| 1224 SetBoundsConstrained(bounds); |
| 1225 } |
| 1226 } |
| 1227 |
1207 bool Widget::GetSavedWindowPlacement(gfx::Rect* bounds, | 1228 bool Widget::GetSavedWindowPlacement(gfx::Rect* bounds, |
1208 ui::WindowShowState* show_state) { | 1229 ui::WindowShowState* show_state) { |
1209 // First we obtain the window's saved show-style and store it. We need to do | 1230 // First we obtain the window's saved show-style and store it. We need to do |
1210 // this here, rather than in Show() because by the time Show() is called, | 1231 // this here, rather than in Show() because by the time Show() is called, |
1211 // the window's size will have been reset (below) and the saved maximized | 1232 // the window's size will have been reset (below) and the saved maximized |
1212 // state will have been lost. Sadly there's no way to tell on Windows when | 1233 // state will have been lost. Sadly there's no way to tell on Windows when |
1213 // a window is restored from maximized state, so we can't more accurately | 1234 // a window is restored from maximized state, so we can't more accurately |
1214 // track maximized state independently of sizing information. | 1235 // track maximized state independently of sizing information. |
1215 | 1236 |
1216 // Restore the window's placement from the controller. | 1237 // Restore the window's placement from the controller. |
(...skipping 28 matching lines...) Expand all Loading... |
1245 | 1266 |
1246 //////////////////////////////////////////////////////////////////////////////// | 1267 //////////////////////////////////////////////////////////////////////////////// |
1247 // internal::NativeWidgetPrivate, NativeWidget implementation: | 1268 // internal::NativeWidgetPrivate, NativeWidget implementation: |
1248 | 1269 |
1249 internal::NativeWidgetPrivate* NativeWidgetPrivate::AsNativeWidgetPrivate() { | 1270 internal::NativeWidgetPrivate* NativeWidgetPrivate::AsNativeWidgetPrivate() { |
1250 return this; | 1271 return this; |
1251 } | 1272 } |
1252 | 1273 |
1253 } // namespace internal | 1274 } // namespace internal |
1254 } // namespace views | 1275 } // namespace views |
OLD | NEW |