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

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

Issue 2712383002: Only perform dialog Layout() once during Widget::Init(). (Closed)
Patch Set: selfnits Created 3 years, 9 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
« no previous file with comments | « ui/views/widget/root_view_unittest.cc ('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) 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/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 internal::NativeWidgetPrivate::IsMouseButtonDown(); 336 internal::NativeWidgetPrivate::IsMouseButtonDown();
337 } 337 }
338 native_widget_->InitNativeWidget(params); 338 native_widget_->InitNativeWidget(params);
339 if (RequiresNonClientView(params.type)) { 339 if (RequiresNonClientView(params.type)) {
340 non_client_view_ = new NonClientView; 340 non_client_view_ = new NonClientView;
341 non_client_view_->SetFrameView(CreateNonClientFrameView()); 341 non_client_view_->SetFrameView(CreateNonClientFrameView());
342 // Create the ClientView, add it to the NonClientView and add the 342 // Create the ClientView, add it to the NonClientView and add the
343 // NonClientView to the RootView. This will cause everything to be parented. 343 // NonClientView to the RootView. This will cause everything to be parented.
344 non_client_view_->set_client_view(widget_delegate_->CreateClientView(this)); 344 non_client_view_->set_client_view(widget_delegate_->CreateClientView(this));
345 non_client_view_->SetOverlayView(widget_delegate_->CreateOverlayView()); 345 non_client_view_->SetOverlayView(widget_delegate_->CreateOverlayView());
346 SetContentsView(non_client_view_); 346
347 // Bypass the Layout() that happens in Widget::SetContentsView(). Layout()
348 // will occur after setting the initial bounds below. The RootView's size is
349 // not valid until that happens.
350 root_view_->SetContentsView(non_client_view_);
351
347 // Initialize the window's icon and title before setting the window's 352 // Initialize the window's icon and title before setting the window's
348 // initial bounds; the frame view's preferred height may depend on the 353 // initial bounds; the frame view's preferred height may depend on the
349 // presence of an icon or a title. 354 // presence of an icon or a title.
350 UpdateWindowIcon(); 355 UpdateWindowIcon();
351 UpdateWindowTitle(); 356 UpdateWindowTitle();
352 non_client_view_->ResetWindowControls(); 357 non_client_view_->ResetWindowControls();
353 SetInitialBounds(params.bounds); 358 SetInitialBounds(params.bounds);
359
360 // Perform the initial layout. This handles the case where the size might
361 // not actually change when setting the initial bounds. If it did, child
362 // views won't have a dirty Layout state, so won't do any work.
363 root_view_->Layout();
364
354 if (params.show_state == ui::SHOW_STATE_MAXIMIZED) { 365 if (params.show_state == ui::SHOW_STATE_MAXIMIZED) {
355 Maximize(); 366 Maximize();
356 } else if (params.show_state == ui::SHOW_STATE_MINIMIZED) { 367 } else if (params.show_state == ui::SHOW_STATE_MINIMIZED) {
357 Minimize(); 368 Minimize();
358 saved_show_state_ = ui::SHOW_STATE_MINIMIZED; 369 saved_show_state_ = ui::SHOW_STATE_MINIMIZED;
359 } 370 }
360 } else if (params.delegate) { 371 } else if (params.delegate) {
361 SetContentsView(params.delegate->GetContentsView()); 372 SetContentsView(params.delegate->GetContentsView());
362 SetInitialBoundsForFramelessWindow(params.bounds); 373 SetInitialBoundsForFramelessWindow(params.bounds);
363 } 374 }
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 // property is gone after gobject gets deleted. Short circuit here 461 // property is gone after gobject gets deleted. Short circuit here
451 // for toplevel so that InputMethod can remove itself from 462 // for toplevel so that InputMethod can remove itself from
452 // focus manager. 463 // focus manager.
453 return is_top_level() ? this : native_widget_->GetTopLevelWidget(); 464 return is_top_level() ? this : native_widget_->GetTopLevelWidget();
454 } 465 }
455 466
456 void Widget::SetContentsView(View* view) { 467 void Widget::SetContentsView(View* view) {
457 // Do not SetContentsView() again if it is already set to the same view. 468 // Do not SetContentsView() again if it is already set to the same view.
458 if (view == GetContentsView()) 469 if (view == GetContentsView())
459 return; 470 return;
471
460 root_view_->SetContentsView(view); 472 root_view_->SetContentsView(view);
473
474 // Force a layout now, since the attached hierarchy won't be ready for the
475 // containing window's bounds. Note that we call Layout directly rather than
476 // calling the widget's size changed handler, since the RootView's bounds may
477 // not have changed, which will cause the Layout not to be done otherwise.
478 root_view_->Layout();
479
461 if (non_client_view_ != view) { 480 if (non_client_view_ != view) {
462 // |non_client_view_| can only be non-NULL here if RequiresNonClientView() 481 // |non_client_view_| can only be non-NULL here if RequiresNonClientView()
463 // was true when the widget was initialized. Creating widgets with non 482 // was true when the widget was initialized. Creating widgets with non
464 // client views and then setting the contents view can cause subtle 483 // client views and then setting the contents view can cause subtle
465 // problems on Windows, where the native widget thinks there is still a 484 // problems on Windows, where the native widget thinks there is still a
466 // |non_client_view_|. If you get this error, either use a different type 485 // |non_client_view_|. If you get this error, either use a different type
467 // when initializing the widget, or don't call SetContentsView(). 486 // when initializing the widget, or don't call SetContentsView().
468 DCHECK(!non_client_view_); 487 DCHECK(!non_client_view_);
469 non_client_view_ = NULL; 488 non_client_view_ = NULL;
470 } 489 }
(...skipping 1084 matching lines...) Expand 10 before | Expand all | Expand 10 after
1555 1574
1556 //////////////////////////////////////////////////////////////////////////////// 1575 ////////////////////////////////////////////////////////////////////////////////
1557 // internal::NativeWidgetPrivate, NativeWidget implementation: 1576 // internal::NativeWidgetPrivate, NativeWidget implementation:
1558 1577
1559 internal::NativeWidgetPrivate* NativeWidgetPrivate::AsNativeWidgetPrivate() { 1578 internal::NativeWidgetPrivate* NativeWidgetPrivate::AsNativeWidgetPrivate() {
1560 return this; 1579 return this;
1561 } 1580 }
1562 1581
1563 } // namespace internal 1582 } // namespace internal
1564 } // namespace views 1583 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/widget/root_view_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698