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 { | |
Ben Goodger (Google)
2012/01/31 00:14:19
} else if (params.delegate) {
jennyz
2012/01/31 00:24:03
Done.
| |
340 if (params.delegate != NULL) { | |
341 SetContentsView(params.delegate->GetContentsView()); | |
342 SetInitialBoundsForFramelessWindow(params.bounds); | |
343 } | |
339 } | 344 } |
340 native_widget_initialized_ = true; | 345 native_widget_initialized_ = true; |
341 } | 346 } |
342 | 347 |
343 // Unconverted methods (see header) -------------------------------------------- | 348 // Unconverted methods (see header) -------------------------------------------- |
344 | 349 |
345 gfx::NativeView Widget::GetNativeView() const { | 350 gfx::NativeView Widget::GetNativeView() const { |
346 return native_widget_->GetNativeView(); | 351 return native_widget_->GetNativeView(); |
347 } | 352 } |
348 | 353 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
399 | 404 |
400 const Widget* Widget::GetTopLevelWidget() const { | 405 const Widget* Widget::GetTopLevelWidget() const { |
401 // GetTopLevelNativeWidget doesn't work during destruction because | 406 // GetTopLevelNativeWidget doesn't work during destruction because |
402 // property is gone after gobject gets deleted. Short circuit here | 407 // property is gone after gobject gets deleted. Short circuit here |
403 // for toplevel so that InputMethod can remove itself from | 408 // for toplevel so that InputMethod can remove itself from |
404 // focus manager. | 409 // focus manager. |
405 return is_top_level() ? this : native_widget_->GetTopLevelWidget(); | 410 return is_top_level() ? this : native_widget_->GetTopLevelWidget(); |
406 } | 411 } |
407 | 412 |
408 void Widget::SetContentsView(View* view) { | 413 void Widget::SetContentsView(View* view) { |
414 // Do not SetContentsView() again if it is already set to the same view. | |
415 if (view == GetContentsView()) | |
416 return; | |
409 root_view_->SetContentsView(view); | 417 root_view_->SetContentsView(view); |
410 if (non_client_view_ != view) | 418 if (non_client_view_ != view) |
411 non_client_view_ = NULL; | 419 non_client_view_ = NULL; |
412 } | 420 } |
413 | 421 |
414 View* Widget::GetContentsView() { | 422 View* Widget::GetContentsView() { |
415 return root_view_->GetContentsView(); | 423 return root_view_->GetContentsView(); |
416 } | 424 } |
417 | 425 |
418 gfx::Rect Widget::GetWindowScreenBounds() const { | 426 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 | 1205 // No initial bounds supplied, so size the window to its content and |
1198 // center over its parent. | 1206 // center over its parent. |
1199 native_widget_->CenterWindow(non_client_view_->GetPreferredSize()); | 1207 native_widget_->CenterWindow(non_client_view_->GetPreferredSize()); |
1200 } else { | 1208 } else { |
1201 // Use the supplied initial bounds. | 1209 // Use the supplied initial bounds. |
1202 SetBoundsConstrained(bounds); | 1210 SetBoundsConstrained(bounds); |
1203 } | 1211 } |
1204 } | 1212 } |
1205 } | 1213 } |
1206 | 1214 |
1215 void Widget::SetInitialBoundsForFramelessWindow(const gfx::Rect& bounds) { | |
1216 View* contents_view = GetContentsView(); | |
1217 DCHECK(contents_view != NULL); | |
mazda
2012/01/30 23:26:29
DCHECK(contents_view);
jennyz
2012/01/31 00:24:03
Done.
| |
1218 if (bounds.IsEmpty()) { | |
1219 // No initial bounds supplied, so size the window to its content and | |
1220 // center over its parent. | |
1221 native_widget_->CenterWindow(contents_view->GetPreferredSize()); | |
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 |