diff --git a/ash/shell/window_type_launcher.cc b/ash/shell/window_type_launcher.cc index bc8e9f4b35b5be..0b46e903fd09be 100644 --- a/ash/shell/window_type_launcher.cc +++ b/ash/shell/window_type_launcher.cc @@ -210,8 +210,7 @@ WindowTypeLauncher::WindowTypeLauncher( this, base::ASCIIToUTF16("Show a web/app notification"))), show_views_examples_callback_(show_views_examples_callback) { - views::GridLayout* layout = new views::GridLayout(this); - SetLayoutManager(layout); + views::GridLayout* layout = views::GridLayout::CreateAndInstall(this); SetBorder(views::CreateEmptyBorder(gfx::Insets(5))); views::ColumnSet* column_set = layout->AddColumnSet(0); column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER, diff --git a/ash/system/date/date_view.cc b/ash/system/date/date_view.cc index 213b25eb84ef84..434e34a0033340 100644 --- a/ash/system/date/date_view.cc +++ b/ash/system/date/date_view.cc @@ -262,8 +262,7 @@ void TimeView::UpdateClockLayout(ClockLayout clock_layout) { AddChildView(horizontal_label_.get()); } else { RemoveChildView(horizontal_label_.get()); - views::GridLayout* layout = new views::GridLayout(this); - SetLayoutManager(layout); + views::GridLayout* layout = views::GridLayout::CreateAndInstall(this); const int kColumnId = 0; views::ColumnSet* columns = layout->AddColumnSet(kColumnId); columns->AddPaddingColumn(0, kVerticalClockLeftPadding); diff --git a/ash/system/status_area_widget_delegate.cc b/ash/system/status_area_widget_delegate.cc index 3c44e5f9096ccc..ab5e6056f478af 100644 --- a/ash/system/status_area_widget_delegate.cc +++ b/ash/system/status_area_widget_delegate.cc @@ -139,8 +139,7 @@ void StatusAreaWidgetDelegate::AddTray(views::View* tray) { void StatusAreaWidgetDelegate::UpdateLayout() { // Use a grid layout so that the trays can be centered in each cell, and // so that the widget gets laid out correctly when tray sizes change. - views::GridLayout* layout = new views::GridLayout(this); - SetLayoutManager(layout); + views::GridLayout* layout = views::GridLayout::CreateAndInstall(this); // Update tray border based on layout. bool is_child_on_edge = true; diff --git a/chrome/browser/chromeos/enrollment_dialog_view.cc b/chrome/browser/chromeos/enrollment_dialog_view.cc index 75d6357ee6a941..08920554765e64 100644 --- a/chrome/browser/chromeos/enrollment_dialog_view.cc +++ b/chrome/browser/chromeos/enrollment_dialog_view.cc @@ -94,6 +94,8 @@ EnrollmentDialogView::EnrollmentDialogView(const std::string& network_name, target_uri_(target_uri), connect_(connect), added_cert_(false) { + set_margins(ChromeLayoutProvider::Get()->GetInsetsMetric( + views::INSETS_DIALOG_CONTENTS)); chrome::RecordDialogCreation(chrome::DialogIdentifier::ENROLLMENT); } @@ -164,7 +166,7 @@ void EnrollmentDialogView::InitDialog() { label->SetMultiLine(true); label->SetAllowCharacterBreak(true); - views::GridLayout* grid_layout = views::GridLayout::CreatePanel(this); + views::GridLayout* grid_layout = views::GridLayout::CreateAndInstall(this); views::ColumnSet* columns = grid_layout->AddColumnSet(0); columns->AddColumn(views::GridLayout::FILL, // Horizontal resize. diff --git a/chrome/browser/chromeos/login/ui/simple_web_view_dialog.cc b/chrome/browser/chromeos/login/ui/simple_web_view_dialog.cc index 5d55bc35d09a7a..439f4328bbec32 100644 --- a/chrome/browser/chromeos/login/ui/simple_web_view_dialog.cc +++ b/chrome/browser/chromeos/login/ui/simple_web_view_dialog.cc @@ -67,8 +67,7 @@ class ToolbarRowView : public views::View { views::View* forward, views::View* reload, views::View* location_bar) { - GridLayout* layout = new GridLayout(this); - SetLayoutManager(layout); + GridLayout* layout = GridLayout::CreateAndInstall(this); const int related_horizontal_spacing = ChromeLayoutProvider::Get()->GetDistanceMetric( @@ -210,8 +209,7 @@ void SimpleWebViewDialog::Init() { toolbar_row->Init(back_, forward_, reload_, location_bar_); // Layout. - GridLayout* layout = new GridLayout(this); - SetLayoutManager(layout); + GridLayout* layout = GridLayout::CreateAndInstall(this); views::ColumnSet* column_set = layout->AddColumnSet(0); column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, diff --git a/chrome/browser/chromeos/options/vpn_config_view.cc b/chrome/browser/chromeos/options/vpn_config_view.cc index d0635f6b8def03..ee3ed01b4d6c05 100644 --- a/chrome/browser/chromeos/options/vpn_config_view.cc +++ b/chrome/browser/chromeos/options/vpn_config_view.cc @@ -31,6 +31,7 @@ #include "ui/base/l10n/l10n_util.h" #include "ui/base/models/combobox_model.h" #include "ui/events/event.h" +#include "ui/views/border.h" #include "ui/views/controls/button/checkbox.h" #include "ui/views/controls/combobox/combobox.h" #include "ui/views/controls/label.h" @@ -236,7 +237,6 @@ VPNConfigView::VPNConfigView(NetworkConfigView* parent, enable_group_name_(false), user_passphrase_required_(false), title_(0), - layout_(NULL), server_textfield_(NULL), service_text_(NULL), service_textfield_(NULL), @@ -495,6 +495,10 @@ std::string VPNConfigView::GetProviderTypeString() const { } void VPNConfigView::Init() { + const views::LayoutProvider* provider = views::LayoutProvider::Get(); + SetBorder(views::CreateEmptyBorder( + provider->GetInsetsMetric(views::INSETS_DIALOG_CONTENTS))); + const NetworkState* vpn = NULL; if (!service_path_.empty()) { vpn = NetworkHandler::Get()->network_state_handler()-> @@ -502,13 +506,12 @@ void VPNConfigView::Init() { DCHECK(vpn && vpn->type() == shill::kTypeVPN); } - layout_ = views::GridLayout::CreatePanel(this); - views::LayoutProvider* provider = views::LayoutProvider::Get(); + views::GridLayout* layout = views::GridLayout::CreateAndInstall(this); // Observer any changes to the certificate list. CertLibrary::Get()->AddObserver(this); - views::ColumnSet* column_set = layout_->AddColumnSet(0); + views::ColumnSet* column_set = layout->AddColumnSet(0); // Label. column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, 1, views::GridLayout::USE_PREF, 0, 0); @@ -538,15 +541,15 @@ void VPNConfigView::Init() { enable_group_name_ = true; // Server label and input. - layout_->StartRow(0, 0); + layout->StartRow(0, 0); views::View* server_label = new views::Label(l10n_util::GetStringUTF16( IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_VPN_SERVER_HOSTNAME)); - layout_->AddView(server_label); + layout->AddView(server_label); server_textfield_ = new views::Textfield(); server_textfield_->set_controller(this); - layout_->AddView(server_textfield_); - layout_->AddPaddingRow( + layout->AddView(server_textfield_); + layout->AddPaddingRow( 0, provider->GetDistanceMetric(views::DISTANCE_RELATED_CONTROL_VERTICAL)); if (!service_path_.empty()) { server_label->SetEnabled(false); @@ -554,26 +557,26 @@ void VPNConfigView::Init() { } // Service label and name or input. - layout_->StartRow(0, 0); - layout_->AddView(new views::Label(l10n_util::GetStringUTF16( + layout->StartRow(0, 0); + layout->AddView(new views::Label(l10n_util::GetStringUTF16( IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_VPN_SERVICE_NAME))); if (service_path_.empty()) { service_textfield_ = new views::Textfield(); service_textfield_->set_controller(this); - layout_->AddView(service_textfield_); + layout->AddView(service_textfield_); service_text_ = NULL; } else { service_text_ = new views::Label(); service_text_->SetHorizontalAlignment(gfx::ALIGN_LEFT); - layout_->AddView(service_text_); + layout->AddView(service_text_); service_textfield_ = NULL; } - layout_->AddPaddingRow( + layout->AddPaddingRow( 0, provider->GetDistanceMetric(views::DISTANCE_RELATED_CONTROL_VERTICAL)); // Provider type label and select. - layout_->StartRow(0, 0); - layout_->AddView(new views::Label(l10n_util::GetStringUTF16( + layout->StartRow(0, 0); + layout->AddView(new views::Label(l10n_util::GetStringUTF16( IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_VPN_PROVIDER_TYPE))); if (service_path_.empty()) { provider_type_combobox_model_.reset( @@ -581,131 +584,129 @@ void VPNConfigView::Init() { provider_type_combobox_ = new views::Combobox( provider_type_combobox_model_.get()); provider_type_combobox_->set_listener(this); - layout_->AddView(provider_type_combobox_); + layout->AddView(provider_type_combobox_); provider_type_text_label_ = NULL; } else { provider_type_text_label_ = new views::Label(); provider_type_text_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); - layout_->AddView(provider_type_text_label_); + layout->AddView(provider_type_text_label_); provider_type_combobox_ = NULL; } - layout_->AddPaddingRow( + layout->AddPaddingRow( 0, provider->GetDistanceMetric(views::DISTANCE_RELATED_CONTROL_VERTICAL)); // PSK passphrase label, input and visible button. - layout_->StartRow(0, 0); + layout->StartRow(0, 0); psk_passphrase_label_ = new views::Label(l10n_util::GetStringUTF16( IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_VPN_PSK_PASSPHRASE)); - layout_->AddView(psk_passphrase_label_); + layout->AddView(psk_passphrase_label_); psk_passphrase_textfield_ = new PassphraseTextfield(); psk_passphrase_textfield_->set_controller(this); - layout_->AddView(psk_passphrase_textfield_); - layout_->AddView( - new ControlledSettingIndicatorView(psk_passphrase_ui_data_)); - layout_->AddPaddingRow( + layout->AddView(psk_passphrase_textfield_); + layout->AddView(new ControlledSettingIndicatorView(psk_passphrase_ui_data_)); + layout->AddPaddingRow( 0, provider->GetDistanceMetric(views::DISTANCE_RELATED_CONTROL_VERTICAL)); // Server CA certificate if (service_path_.empty()) { - layout_->StartRow(0, 0); + layout->StartRow(0, 0); server_ca_cert_label_ = new views::Label(l10n_util::GetStringUTF16( IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CERT_SERVER_CA)); - layout_->AddView(server_ca_cert_label_); + layout->AddView(server_ca_cert_label_); server_ca_cert_combobox_model_.reset( new internal::VpnServerCACertComboboxModel()); server_ca_cert_combobox_ = new views::Combobox( server_ca_cert_combobox_model_.get()); - layout_->AddView(server_ca_cert_combobox_); - layout_->AddView(new ControlledSettingIndicatorView(ca_cert_ui_data_)); - layout_->AddPaddingRow(0, provider->GetDistanceMetric( - views::DISTANCE_RELATED_CONTROL_VERTICAL)); + layout->AddView(server_ca_cert_combobox_); + layout->AddView(new ControlledSettingIndicatorView(ca_cert_ui_data_)); + layout->AddPaddingRow(0, provider->GetDistanceMetric( + views::DISTANCE_RELATED_CONTROL_VERTICAL)); } else { server_ca_cert_label_ = NULL; server_ca_cert_combobox_ = NULL; } // User certificate label and input. - layout_->StartRow(0, 0); + layout->StartRow(0, 0); user_cert_label_ = new views::Label(l10n_util::GetStringUTF16( IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_VPN_USER_CERT)); - layout_->AddView(user_cert_label_); + layout->AddView(user_cert_label_); user_cert_combobox_model_.reset( new internal::VpnUserCertComboboxModel()); user_cert_combobox_ = new views::Combobox(user_cert_combobox_model_.get()); user_cert_combobox_->set_listener(this); - layout_->AddView(user_cert_combobox_); - layout_->AddView(new ControlledSettingIndicatorView(user_cert_ui_data_)); - layout_->AddPaddingRow( + layout->AddView(user_cert_combobox_); + layout->AddView(new ControlledSettingIndicatorView(user_cert_ui_data_)); + layout->AddPaddingRow( 0, provider->GetDistanceMetric(views::DISTANCE_RELATED_CONTROL_VERTICAL)); // Username label and input. - layout_->StartRow(0, 0); - layout_->AddView(new views::Label(l10n_util::GetStringUTF16( + layout->StartRow(0, 0); + layout->AddView(new views::Label(l10n_util::GetStringUTF16( IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_VPN_USERNAME))); username_textfield_ = new views::Textfield(); username_textfield_->set_controller(this); username_textfield_->SetEnabled(username_ui_data_.IsEditable()); - layout_->AddView(username_textfield_); - layout_->AddView(new ControlledSettingIndicatorView(username_ui_data_)); - layout_->AddPaddingRow( + layout->AddView(username_textfield_); + layout->AddView(new ControlledSettingIndicatorView(username_ui_data_)); + layout->AddPaddingRow( 0, provider->GetDistanceMetric(views::DISTANCE_RELATED_CONTROL_VERTICAL)); // User passphrase label, input and visble button. - layout_->StartRow(0, 0); - layout_->AddView(new views::Label(l10n_util::GetStringUTF16( + layout->StartRow(0, 0); + layout->AddView(new views::Label(l10n_util::GetStringUTF16( IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_VPN_USER_PASSPHRASE))); user_passphrase_textfield_ = new PassphraseTextfield(); user_passphrase_textfield_->set_controller(this); user_passphrase_textfield_->SetEnabled(user_passphrase_ui_data_.IsEditable()); - layout_->AddView(user_passphrase_textfield_); - layout_->AddView( - new ControlledSettingIndicatorView(user_passphrase_ui_data_)); - layout_->AddPaddingRow( + layout->AddView(user_passphrase_textfield_); + layout->AddView(new ControlledSettingIndicatorView(user_passphrase_ui_data_)); + layout->AddPaddingRow( 0, provider->GetDistanceMetric(views::DISTANCE_RELATED_CONTROL_VERTICAL)); // OTP label and input. - layout_->StartRow(0, 0); + layout->StartRow(0, 0); otp_label_ = new views::Label(l10n_util::GetStringUTF16( IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_VPN_OTP)); - layout_->AddView(otp_label_); + layout->AddView(otp_label_); otp_textfield_ = new views::Textfield(); otp_textfield_->set_controller(this); - layout_->AddView(otp_textfield_); - layout_->AddPaddingRow( + layout->AddView(otp_textfield_); + layout->AddPaddingRow( 0, provider->GetDistanceMetric(views::DISTANCE_RELATED_CONTROL_VERTICAL)); // Group Name label and input. - layout_->StartRow(0, 0); + layout->StartRow(0, 0); group_name_label_ = new views::Label(l10n_util::GetStringUTF16( IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_VPN_GROUP_NAME)); - layout_->AddView(group_name_label_); + layout->AddView(group_name_label_); group_name_textfield_ = new views::Textfield(); group_name_textfield_->set_controller(this); - layout_->AddView(group_name_textfield_); - layout_->AddView(new ControlledSettingIndicatorView(group_name_ui_data_)); - layout_->AddPaddingRow( + layout->AddView(group_name_textfield_); + layout->AddView(new ControlledSettingIndicatorView(group_name_ui_data_)); + layout->AddPaddingRow( 0, provider->GetDistanceMetric(views::DISTANCE_RELATED_CONTROL_VERTICAL)); // Save credentials - layout_->StartRow(0, 0); + layout->StartRow(0, 0); save_credentials_checkbox_ = new views::Checkbox( l10n_util::GetStringUTF16( IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_SAVE_CREDENTIALS)); save_credentials_checkbox_->SetEnabled( save_credentials_ui_data_.IsEditable()); - layout_->SkipColumns(1); - layout_->AddView(save_credentials_checkbox_); - layout_->AddView( + layout->SkipColumns(1); + layout->AddView(save_credentials_checkbox_); + layout->AddView( new ControlledSettingIndicatorView(save_credentials_ui_data_)); // Error label. - layout_->StartRow(0, 0); - layout_->SkipColumns(1); + layout->StartRow(0, 0); + layout->SkipColumns(1); error_label_ = new views::Label(); error_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); error_label_->SetEnabledColor(SK_ColorRED); - layout_->AddView(error_label_); + layout->AddView(error_label_); // Set or hide the UI, update comboboxes and error labels. Refresh(); diff --git a/chrome/browser/chromeos/options/vpn_config_view.h b/chrome/browser/chromeos/options/vpn_config_view.h index b583a73161c541..03d9b4a44b90b4 100644 --- a/chrome/browser/chromeos/options/vpn_config_view.h +++ b/chrome/browser/chromeos/options/vpn_config_view.h @@ -26,7 +26,6 @@ class DictionaryValue; namespace views { class Checkbox; -class GridLayout; class Label; } @@ -159,7 +158,6 @@ class VPNConfigView : public ChildNetworkConfigView, int title_; - views::GridLayout* layout_; views::Textfield* server_textfield_; views::Label* service_text_; views::Textfield* service_textfield_; diff --git a/chrome/browser/chromeos/options/wifi_config_view.cc b/chrome/browser/chromeos/options/wifi_config_view.cc index e537dfcf03c7c2..dcea9564b9712b 100644 --- a/chrome/browser/chromeos/options/wifi_config_view.cc +++ b/chrome/browser/chromeos/options/wifi_config_view.cc @@ -36,6 +36,7 @@ #include "ui/base/material_design/material_design_controller.h" #include "ui/base/resource/resource_bundle.h" #include "ui/events/event.h" +#include "ui/views/border.h" #include "ui/views/controls/button/checkbox.h" #include "ui/views/controls/button/image_button.h" #include "ui/views/controls/combobox/combobox.h" @@ -904,6 +905,10 @@ void WifiConfigView::Cancel() { } void WifiConfigView::Init(bool show_8021x) { + views::LayoutProvider* provider = views::LayoutProvider::Get(); + SetBorder(views::CreateEmptyBorder( + provider->GetInsetsMetric(views::INSETS_DIALOG_CONTENTS))); + const NetworkState* network = GetNetworkState(); if (network) { if (network->type() == shill::kTypeWifi) { @@ -938,8 +943,7 @@ void WifiConfigView::Init(bool show_8021x) { ParseUIProperty(&passphrase_ui_data_, network, ::onc::wifi::kPassphrase); } - views::GridLayout* layout = views::GridLayout::CreatePanel(this); - views::LayoutProvider* provider = views::LayoutProvider::Get(); + views::GridLayout* layout = views::GridLayout::CreateAndInstall(this); const int column_view_set_id = 0; views::ColumnSet* column_set = layout->AddColumnSet(column_view_set_id); diff --git a/chrome/browser/chromeos/options/wimax_config_view.cc b/chrome/browser/chromeos/options/wimax_config_view.cc index 00c0e9255dc8dc..26ef1e51828281 100644 --- a/chrome/browser/chromeos/options/wimax_config_view.cc +++ b/chrome/browser/chromeos/options/wimax_config_view.cc @@ -27,6 +27,7 @@ #include "ui/base/l10n/l10n_util.h" #include "ui/base/resource/resource_bundle.h" #include "ui/events/event.h" +#include "ui/views/border.h" #include "ui/views/controls/button/checkbox.h" #include "ui/views/controls/button/image_button.h" #include "ui/views/controls/label.h" @@ -196,6 +197,10 @@ void WimaxConfigView::Cancel() { } void WimaxConfigView::Init() { + const views::LayoutProvider* provider = views::LayoutProvider::Get(); + SetBorder(views::CreateEmptyBorder( + provider->GetInsetsMetric(views::INSETS_DIALOG_CONTENTS))); + const NetworkState* wimax = NetworkHandler::Get()->network_state_handler()-> GetNetworkState(service_path_); DCHECK(wimax && wimax->type() == shill::kTypeWimax); @@ -207,8 +212,7 @@ void WimaxConfigView::Init() { WifiConfigView::ParseUIProperty( &passphrase_ui_data_, wimax, ::onc::wifi::kPassphrase); - views::GridLayout* layout = views::GridLayout::CreatePanel(this); - views::LayoutProvider* provider = views::LayoutProvider::Get(); + views::GridLayout* layout = views::GridLayout::CreateAndInstall(this); const int column_view_set_id = 0; views::ColumnSet* column_set = layout->AddColumnSet(column_view_set_id); diff --git a/chrome/browser/chromeos/profiles/multiprofiles_session_aborted_dialog.cc b/chrome/browser/chromeos/profiles/multiprofiles_session_aborted_dialog.cc index 3ed1efe5223172..8d742ca2741e5a 100644 --- a/chrome/browser/chromeos/profiles/multiprofiles_session_aborted_dialog.cc +++ b/chrome/browser/chromeos/profiles/multiprofiles_session_aborted_dialog.cc @@ -118,8 +118,7 @@ void MultiprofilesSessionAbortedView::InitDialog( constexpr int kTopInset = 10; constexpr int kOtherInset = 40; // Create the views and layout manager and set them up. - views::GridLayout* grid_layout = new views::GridLayout(this); - SetLayoutManager(grid_layout); + views::GridLayout* grid_layout = views::GridLayout::CreateAndInstall(this); SetBorder(views::CreateEmptyBorder(kTopInset, kOtherInset, kOtherInset, kOtherInset)); @@ -148,7 +147,6 @@ void MultiprofilesSessionAbortedView::InitDialog( grid_layout->StartRow(0, 0); grid_layout->AddView(label); - SetLayoutManager(grid_layout); Layout(); } diff --git a/chrome/browser/chromeos/ui/request_pin_view.cc b/chrome/browser/chromeos/ui/request_pin_view.cc index fbb20009661e69..2179479738569e 100644 --- a/chrome/browser/chromeos/ui/request_pin_view.cc +++ b/chrome/browser/chromeos/ui/request_pin_view.cc @@ -162,7 +162,10 @@ void RequestPinView::UpdateHeaderText() { } void RequestPinView::Init() { - views::GridLayout* layout = views::GridLayout::CreatePanel(this); + set_margins(ChromeLayoutProvider::Get()->GetInsetsMetric( + views::INSETS_DIALOG_CONTENTS)); + + views::GridLayout* layout = views::GridLayout::CreateAndInstall(this); int column_view_set_id = 0; views::ColumnSet* column_set = layout->AddColumnSet(column_view_set_id); diff --git a/chrome/browser/ui/views/accessibility/invert_bubble_view.cc b/chrome/browser/ui/views/accessibility/invert_bubble_view.cc index 441bbec0afb53b..d87f871a7c7ecb 100644 --- a/chrome/browser/ui/views/accessibility/invert_bubble_view.cc +++ b/chrome/browser/ui/views/accessibility/invert_bubble_view.cc @@ -81,6 +81,10 @@ int InvertBubbleView::GetDialogButtons() const { } void InvertBubbleView::Init() { + const ChromeLayoutProvider* provider = ChromeLayoutProvider::Get(); + SetBorder(views::CreateEmptyBorder( + provider->GetInsetsMetric(views::INSETS_DIALOG_CONTENTS))); + ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); const gfx::FontList& original_font_list = rb.GetFontList(ui::ResourceBundle::MediumFont); @@ -108,7 +112,7 @@ void InvertBubbleView::Init() { close_->SetFontList(original_font_list); close_->set_listener(this); - views::GridLayout* layout = views::GridLayout::CreatePanel(this); + views::GridLayout* layout = views::GridLayout::CreateAndInstall(this); views::ColumnSet* columns = layout->AddColumnSet(0); for (int i = 0; i < 4; i++) { @@ -119,9 +123,9 @@ void InvertBubbleView::Init() { layout->StartRow(0, 0); layout->AddView(title, 4, 1); - layout->StartRowWithPadding(0, 0, 0, - ChromeLayoutProvider::Get()->GetDistanceMetric( - DISTANCE_RELATED_CONTROL_VERTICAL_SMALL)); + layout->StartRowWithPadding( + 0, 0, 0, + provider->GetDistanceMetric(DISTANCE_RELATED_CONTROL_VERTICAL_SMALL)); layout->AddView(high_contrast_); layout->AddView(dark_theme_); layout->AddView(learn_more_); diff --git a/chrome/browser/ui/views/apps/app_info_dialog/app_info_permissions_panel.cc b/chrome/browser/ui/views/apps/app_info_dialog/app_info_permissions_panel.cc index ab3da0f9278d2d..063c51bf06bcaf 100644 --- a/chrome/browser/ui/views/apps/app_info_dialog/app_info_permissions_panel.cc +++ b/chrome/browser/ui/views/apps/app_info_dialog/app_info_permissions_panel.cc @@ -90,8 +90,7 @@ class RevokeButton : public views::ImageButton, public views::ButtonListener { class BulletedPermissionsList : public views::View { public: BulletedPermissionsList() { - layout_ = new views::GridLayout(this); - SetLayoutManager(layout_); + layout_ = views::GridLayout::CreateAndInstall(this); // Create 3 columns: the bullet, the bullet text, and the revoke button. views::ColumnSet* column_set = layout_->AddColumnSet(kBulletColumnSetId); diff --git a/chrome/browser/ui/views/bookmarks/bookmark_bubble_view.cc b/chrome/browser/ui/views/bookmarks/bookmark_bubble_view.cc index 001abcf75ff21f..d97d71e67f7af4 100644 --- a/chrome/browser/ui/views/bookmarks/bookmark_bubble_view.cc +++ b/chrome/browser/ui/views/bookmarks/bookmark_bubble_view.cc @@ -296,8 +296,7 @@ void BookmarkBubbleView::Init() { SetLayoutManager(new views::FillLayout()); bookmark_contents_view_ = new views::View(); - GridLayout* layout = new GridLayout(bookmark_contents_view_); - bookmark_contents_view_->SetLayoutManager(layout); + GridLayout* layout = GridLayout::CreateAndInstall(bookmark_contents_view_); // This column set is used for the labels and textfields. constexpr int kColumnId = 0; diff --git a/chrome/browser/ui/views/bookmarks/bookmark_editor_view.cc b/chrome/browser/ui/views/bookmarks/bookmark_editor_view.cc index 8e849590f0aca8..b4779906dba628 100644 --- a/chrome/browser/ui/views/bookmarks/bookmark_editor_view.cc +++ b/chrome/browser/ui/views/bookmarks/bookmark_editor_view.cc @@ -72,6 +72,8 @@ BookmarkEditorView::BookmarkEditorView( DCHECK(profile); DCHECK(bb_model_); DCHECK(bb_model_->client()->CanBeEditedByUser(parent)); + set_margins(ChromeLayoutProvider::Get()->GetInsetsMetric( + views::INSETS_DIALOG_CONTENTS)); Init(); chrome::RecordDialogCreation(chrome::DialogIdentifier::BOOKMARK_EDITOR); } @@ -335,7 +337,7 @@ void BookmarkEditorView::Init() { new_folder_button_->SetEnabled(false); } - GridLayout* layout = GridLayout::CreatePanel(this); + GridLayout* layout = GridLayout::CreateAndInstall(this); ChromeLayoutProvider* provider = ChromeLayoutProvider::Get(); const int labels_column_set_id = 0; diff --git a/chrome/browser/ui/views/certificate_selector.cc b/chrome/browser/ui/views/certificate_selector.cc index dc75b6eb7d89e7..34450c7143009d 100644 --- a/chrome/browser/ui/views/certificate_selector.cc +++ b/chrome/browser/ui/views/certificate_selector.cc @@ -118,6 +118,9 @@ CertificateSelector::CertificateSelector(net::ClientCertIdentityList identities, : web_contents_(web_contents) { CHECK(web_contents_); + set_margins(ChromeLayoutProvider::Get()->GetInsetsMetric( + views::INSETS_DIALOG_CONTENTS)); + // |provider_names| and |identities_| are parallel arrays. // The entry at index |i| is the provider name for |identities_[i]|. std::vector provider_names; @@ -197,7 +200,7 @@ void CertificateSelector::Show() { void CertificateSelector::InitWithText( std::unique_ptr text_label) { - views::GridLayout* const layout = views::GridLayout::CreatePanel(this); + views::GridLayout* const layout = views::GridLayout::CreateAndInstall(this); const int kColumnSetId = 0; views::ColumnSet* const column_set = layout->AddColumnSet(kColumnSetId); diff --git a/chrome/browser/ui/views/collected_cookies_views.cc b/chrome/browser/ui/views/collected_cookies_views.cc index b45cd14150946d..e168893410279c 100644 --- a/chrome/browser/ui/views/collected_cookies_views.cc +++ b/chrome/browser/ui/views/collected_cookies_views.cc @@ -313,13 +313,12 @@ CollectedCookiesViews::~CollectedCookiesViews() { void CollectedCookiesViews::Init() { using views::GridLayout; - GridLayout* layout = new GridLayout(this); + GridLayout* layout = GridLayout::CreateAndInstall(this); ChromeLayoutProvider* provider = ChromeLayoutProvider::Get(); if (provider->UseExtraDialogPadding()) { SetBorder( views::CreateEmptyBorder(gfx::Insets(kTabbedPaneTopPadding, 0, 0, 0))); } - SetLayoutManager(layout); const int single_column_layout_id = 0; views::ColumnSet* column_set = layout->AddColumnSet(single_column_layout_id); @@ -387,7 +386,10 @@ views::View* CollectedCookiesViews::CreateAllowedPane() { using views::GridLayout; views::View* pane = new views::View(); - GridLayout* layout = GridLayout::CreatePanel(pane); + GridLayout* layout = GridLayout::CreateAndInstall(pane); + pane->SetBorder( + views::CreateEmptyBorder(ChromeLayoutProvider::Get()->GetInsetsMetric( + views::INSETS_DIALOG_CONTENTS))); int unrelated_vertical_distance = ChromeLayoutProvider::Get()->GetDistanceMetric( views::DISTANCE_UNRELATED_CONTROL_VERTICAL); @@ -451,7 +453,10 @@ views::View* CollectedCookiesViews::CreateBlockedPane() { using views::GridLayout; views::View* pane = new views::View(); - GridLayout* layout = GridLayout::CreatePanel(pane); + GridLayout* layout = GridLayout::CreateAndInstall(pane); + pane->SetBorder( + views::CreateEmptyBorder(ChromeLayoutProvider::Get()->GetInsetsMetric( + views::INSETS_DIALOG_CONTENTS))); int unrelated_vertical_distance = ChromeLayoutProvider::Get()->GetDistanceMetric( views::DISTANCE_UNRELATED_CONTROL_VERTICAL); diff --git a/chrome/browser/ui/views/confirm_bubble_views.cc b/chrome/browser/ui/views/confirm_bubble_views.cc index 161a1f861395eb..dd8199afce398d 100644 --- a/chrome/browser/ui/views/confirm_bubble_views.cc +++ b/chrome/browser/ui/views/confirm_bubble_views.cc @@ -9,6 +9,7 @@ #include "chrome/browser/ui/browser_dialogs.h" #include "chrome/browser/ui/confirm_bubble.h" #include "chrome/browser/ui/confirm_bubble_model.h" +#include "chrome/browser/ui/views/harmony/chrome_layout_provider.h" #include "components/constrained_window/constrained_window_views.h" #include "ui/base/ui_features.h" #include "ui/views/controls/label.h" @@ -19,7 +20,9 @@ ConfirmBubbleViews::ConfirmBubbleViews( std::unique_ptr model) : model_(std::move(model)), link_(NULL) { - views::GridLayout* layout = views::GridLayout::CreatePanel(this); + set_margins(ChromeLayoutProvider::Get()->GetInsetsMetric( + views::INSETS_DIALOG_CONTENTS)); + views::GridLayout* layout = views::GridLayout::CreateAndInstall(this); // Use a fixed maximum message width, so longer messages will wrap. const int kMaxMessageWidth = 400; diff --git a/chrome/browser/ui/views/confirm_bubble_views_unittest.cc b/chrome/browser/ui/views/confirm_bubble_views_unittest.cc index bd22c207ebae36..0fb9855d282eec 100644 --- a/chrome/browser/ui/views/confirm_bubble_views_unittest.cc +++ b/chrome/browser/ui/views/confirm_bubble_views_unittest.cc @@ -9,14 +9,14 @@ #include "chrome/browser/ui/confirm_bubble.h" #include "chrome/browser/ui/test/test_confirm_bubble_model.h" #include "chrome/browser/ui/views/chrome_constrained_window_views_client.h" +#include "chrome/test/views/chrome_views_test_base.h" #include "components/constrained_window/constrained_window_views.h" #include "testing/gtest/include/gtest/gtest.h" -#include "ui/views/test/views_test_base.h" #include "ui/views/widget/widget.h" using views::Widget; -typedef views::ViewsTestBase ConfirmBubbleViewsTest; +typedef ChromeViewsTestBase ConfirmBubbleViewsTest; TEST_F(ConfirmBubbleViewsTest, CreateAndClose) { SetConstrainedWindowViewsClient(CreateChromeConstrainedWindowViewsClient()); diff --git a/chrome/browser/ui/views/content_setting_bubble_contents.cc b/chrome/browser/ui/views/content_setting_bubble_contents.cc index 3bc6f4bb153fad..06e97b29ecbcaf 100644 --- a/chrome/browser/ui/views/content_setting_bubble_contents.cc +++ b/chrome/browser/ui/views/content_setting_bubble_contents.cc @@ -249,8 +249,7 @@ int ContentSettingBubbleContents::ListItemContainer::GetRowIndexOf( void ContentSettingBubbleContents::ListItemContainer::ResetLayout() { using views::GridLayout; - GridLayout* layout = new GridLayout(this); - SetLayoutManager(layout); + GridLayout* layout = GridLayout::CreateAndInstall(this); views::ColumnSet* item_list_column_set = layout->AddColumnSet(0); item_list_column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 0, GridLayout::USE_PREF, 0, 0); @@ -344,8 +343,7 @@ void ContentSettingBubbleContents::OnNativeThemeChanged( void ContentSettingBubbleContents::Init() { using views::GridLayout; - GridLayout* layout = new views::GridLayout(this); - SetLayoutManager(layout); + GridLayout* layout = views::GridLayout::CreateAndInstall(this); const ChromeLayoutProvider* provider = ChromeLayoutProvider::Get(); const int related_control_horizontal_spacing = provider->GetDistanceMetric(views::DISTANCE_RELATED_CONTROL_HORIZONTAL); diff --git a/chrome/browser/ui/views/cookie_info_view.cc b/chrome/browser/ui/views/cookie_info_view.cc index da53a2466a71fb..67fdaa8d202dbf 100644 --- a/chrome/browser/ui/views/cookie_info_view.cc +++ b/chrome/browser/ui/views/cookie_info_view.cc @@ -146,8 +146,7 @@ void CookieInfoView::Init() { l10n_util::GetStringUTF16(IDS_COOKIES_COOKIE_EXPIRES_LABEL)); expires_value_field_ = new views::Textfield; - views::GridLayout* layout = new views::GridLayout(this); - SetLayoutManager(layout); + views::GridLayout* layout = views::GridLayout::CreateAndInstall(this); ChromeLayoutProvider* provider = ChromeLayoutProvider::Get(); const gfx::Insets& dialog_insets = provider->GetInsetsMetric(views::INSETS_DIALOG); diff --git a/chrome/browser/ui/views/create_application_shortcut_view.cc b/chrome/browser/ui/views/create_application_shortcut_view.cc index 6f8039614d0802..0ea459a34d310d 100644 --- a/chrome/browser/ui/views/create_application_shortcut_view.cc +++ b/chrome/browser/ui/views/create_application_shortcut_view.cc @@ -51,6 +51,8 @@ CreateChromeApplicationShortcutView::CreateChromeApplicationShortcutView( menu_check_box_(nullptr), quick_launch_check_box_(nullptr), weak_ptr_factory_(this) { + set_margins(ChromeLayoutProvider::Get()->GetInsetsMetric( + views::INSETS_DIALOG_CONTENTS)); InitControls(); // Get shortcut and icon information; needed for creating the shortcut. @@ -106,7 +108,7 @@ void CreateChromeApplicationShortcutView::InitControls() { ChromeLayoutProvider* provider = ChromeLayoutProvider::Get(); // Layout controls - views::GridLayout* layout = views::GridLayout::CreatePanel(this); + views::GridLayout* layout = views::GridLayout::CreateAndInstall(this); static const int kHeaderColumnSetId = 0; views::ColumnSet* column_set = layout->AddColumnSet(kHeaderColumnSetId); diff --git a/chrome/browser/ui/views/crypto_module_password_dialog_view.cc b/chrome/browser/ui/views/crypto_module_password_dialog_view.cc index 256c7eaf59a154..d3029032c6810b 100644 --- a/chrome/browser/ui/views/crypto_module_password_dialog_view.cc +++ b/chrome/browser/ui/views/crypto_module_password_dialog_view.cc @@ -27,6 +27,8 @@ CryptoModulePasswordDialogView::CryptoModulePasswordDialogView( const std::string& hostname, const CryptoModulePasswordCallback& callback) : callback_(callback) { + set_margins(ChromeLayoutProvider::Get()->GetInsetsMetric( + views::INSETS_DIALOG_CONTENTS)); Init(hostname, slot_name, reason); chrome::RecordDialogCreation(chrome::DialogIdentifier::CRYPTO_PASSWORD); } @@ -125,7 +127,7 @@ void CryptoModulePasswordDialogView::Init(const std::string& hostname, ChromeLayoutProvider* provider = ChromeLayoutProvider::Get(); - views::GridLayout* layout = views::GridLayout::CreatePanel(this); + views::GridLayout* layout = views::GridLayout::CreateAndInstall(this); views::ColumnSet* reason_column_set = layout->AddColumnSet(0); reason_column_set->AddColumn( diff --git a/chrome/browser/ui/views/desktop_ios_promotion/desktop_ios_promotion_bubble_view.cc b/chrome/browser/ui/views/desktop_ios_promotion/desktop_ios_promotion_bubble_view.cc index a3273db77b4e69..0639acffcb18bd 100644 --- a/chrome/browser/ui/views/desktop_ios_promotion/desktop_ios_promotion_bubble_view.cc +++ b/chrome/browser/ui/views/desktop_ios_promotion/desktop_ios_promotion_bubble_view.cc @@ -40,8 +40,7 @@ DesktopIOSPromotionBubbleView::DesktopIOSPromotionBubbleView( base::MakeUnique(profile, this, entry_point)) { - views::GridLayout* layout = new views::GridLayout(this); - SetLayoutManager(layout); + views::GridLayout* layout = views::GridLayout::CreateAndInstall(this); ChromeLayoutProvider* provider = ChromeLayoutProvider::Get(); SetBorder(views::CreateEmptyBorder( 0, diff --git a/chrome/browser/ui/views/download/download_danger_prompt_views.cc b/chrome/browser/ui/views/download/download_danger_prompt_views.cc index a9fc68d62f89ca..9f170f99301ae3 100644 --- a/chrome/browser/ui/views/download/download_danger_prompt_views.cc +++ b/chrome/browser/ui/views/download/download_danger_prompt_views.cc @@ -8,6 +8,7 @@ #include "chrome/browser/download/download_stats.h" #include "chrome/browser/extensions/api/experience_sampling_private/experience_sampling.h" #include "chrome/browser/ui/browser_dialogs.h" +#include "chrome/browser/ui/views/harmony/chrome_layout_provider.h" #include "chrome/grit/chromium_strings.h" #include "chrome/grit/generated_resources.h" #include "components/constrained_window/constrained_window_views.h" @@ -95,7 +96,10 @@ DownloadDangerPromptViews::DownloadDangerPromptViews( contents_view_ = new views::View; - views::GridLayout* layout = views::GridLayout::CreatePanel(contents_view_); + set_margins(ChromeLayoutProvider::Get()->GetInsetsMetric( + views::INSETS_DIALOG_CONTENTS)); + views::GridLayout* layout = + views::GridLayout::CreateAndInstall(contents_view_); views::ColumnSet* column_set = layout->AddColumnSet(0); column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1, diff --git a/chrome/browser/ui/views/extensions/bookmark_app_confirmation_view.cc b/chrome/browser/ui/views/extensions/bookmark_app_confirmation_view.cc index 425ddfa59ac00c..865bd1879d1fe8 100644 --- a/chrome/browser/ui/views/extensions/bookmark_app_confirmation_view.cc +++ b/chrome/browser/ui/views/extensions/bookmark_app_confirmation_view.cc @@ -65,7 +65,8 @@ BookmarkAppConfirmationView::BookmarkAppConfirmationView( open_as_window_checkbox_(nullptr), title_tf_(nullptr) { const ChromeLayoutProvider* layout_provider = ChromeLayoutProvider::Get(); - views::GridLayout* layout = views::GridLayout::CreatePanel(this); + set_margins(layout_provider->GetInsetsMetric(views::INSETS_DIALOG_CONTENTS)); + views::GridLayout* layout = views::GridLayout::CreateAndInstall(this); const int column_set_id = 0; views::ColumnSet* column_set = layout->AddColumnSet(column_set_id); diff --git a/chrome/browser/ui/views/extensions/chooser_dialog_view_unittest.cc b/chrome/browser/ui/views/extensions/chooser_dialog_view_unittest.cc index c2e0000892f636..fc82abdca187f1 100644 --- a/chrome/browser/ui/views/extensions/chooser_dialog_view_unittest.cc +++ b/chrome/browser/ui/views/extensions/chooser_dialog_view_unittest.cc @@ -11,28 +11,25 @@ #include "base/strings/utf_string_conversions.h" #include "chrome/browser/chooser_controller/mock_chooser_controller.h" #include "chrome/browser/ui/views/device_chooser_content_view.h" -#include "chrome/browser/ui/views/harmony/chrome_layout_provider.h" #include "chrome/grit/generated_resources.h" +#include "chrome/test/views/chrome_views_test_base.h" #include "testing/gmock/include/gmock/gmock.h" #include "ui/base/l10n/l10n_util.h" #include "ui/views/controls/button/label_button.h" #include "ui/views/controls/styled_label.h" #include "ui/views/controls/table/table_view.h" #include "ui/views/test/native_widget_factory.h" -#include "ui/views/test/views_test_base.h" #include "ui/views/widget/widget.h" #include "ui/views/window/dialog_client_view.h" -class ChooserDialogViewTest : public views::ViewsTestBase { +class ChooserDialogViewTest : public ChromeViewsTestBase { public: ChooserDialogViewTest() {} ~ChooserDialogViewTest() override {} - // views::ViewsTestBase: + // ChromeViewsTestBase: void SetUp() override { - views::ViewsTestBase::SetUp(); - test_views_delegate()->set_layout_provider( - ChromeLayoutProvider::CreateLayoutProvider()); + ChromeViewsTestBase::SetUp(); auto mock_chooser_controller = base::MakeUnique(); mock_chooser_controller_ = mock_chooser_controller.get(); std::unique_ptr chooser_dialog_view( @@ -62,11 +59,11 @@ class ChooserDialogViewTest : public views::ViewsTestBase { ASSERT_TRUE(cancel_button_); } - // views::ViewsTestBase: + // ChromeViewsTestBase: void TearDown() override { dialog_->CloseNow(); parent_widget_->CloseNow(); - views::ViewsTestBase::TearDown(); + ChromeViewsTestBase::TearDown(); } protected: diff --git a/chrome/browser/ui/views/extensions/extension_install_dialog_view.cc b/chrome/browser/ui/views/extensions/extension_install_dialog_view.cc index 6f62003ddf3bc5..3a00480428cd70 100644 --- a/chrome/browser/ui/views/extensions/extension_install_dialog_view.cc +++ b/chrome/browser/ui/views/extensions/extension_install_dialog_view.cc @@ -156,8 +156,7 @@ class CustomScrollableView : public views::View { } // namespace BulletedView::BulletedView(views::View* view) { - views::GridLayout* layout = new views::GridLayout(this); - SetLayoutManager(layout); + views::GridLayout* layout = views::GridLayout::CreateAndInstall(this); views::ColumnSet* column_set = layout->AddColumnSet(0); column_set->AddColumn(views::GridLayout::CENTER, views::GridLayout::LEADING, @@ -290,8 +289,8 @@ void ExtensionInstallDialogView::InitView() { // Create the scrollable view which will contain the permissions and retained // files/devices. It will span the full content width. CustomScrollableView* scrollable = new CustomScrollableView(); - views::GridLayout* scroll_layout = new views::GridLayout(scrollable); - scrollable->SetLayoutManager(scroll_layout); + views::GridLayout* scroll_layout = + views::GridLayout::CreateAndInstall(scrollable); views::ColumnSet* scrollable_column_set = scroll_layout->AddColumnSet(column_set_id); @@ -455,8 +454,7 @@ views::GridLayout* ExtensionInstallDialogView::CreateLayout( // done so that the extension icon can be shown on the right of the dialog // title, but on the same y-axis, and the scroll view used to contain other // content can have its scrollbar aligned with the right edge of the dialog. - views::GridLayout* layout = new views::GridLayout(container_); - container_->SetLayoutManager(layout); + views::GridLayout* layout = views::GridLayout::CreateAndInstall(container_); container_->SetBorder(views::CreateEmptyBorder(0, content_insets.left(), content_insets.bottom(), 0)); AddChildView(container_); @@ -630,9 +628,7 @@ void ExtensionInstallDialogView::UpdateInstallResultHistogram(bool accepted) ExpandableContainerView::DetailsView::DetailsView(int horizontal_space, bool parent_bulleted) - : layout_(new views::GridLayout(this)), - state_(0) { - SetLayoutManager(layout_); + : layout_(views::GridLayout::CreateAndInstall(this)), state_(0) { views::ColumnSet* column_set = layout_->AddColumnSet(0); const int padding = GetLeftPaddingForBulletedItems(parent_bulleted); column_set->AddPaddingColumn(0, padding); @@ -675,8 +671,7 @@ ExpandableContainerView::ExpandableContainerView( more_details_(NULL), arrow_toggle_(NULL), expanded_(false) { - views::GridLayout* layout = new views::GridLayout(this); - SetLayoutManager(layout); + views::GridLayout* layout = views::GridLayout::CreateAndInstall(this); int column_set_id = 0; views::ColumnSet* column_set = layout->AddColumnSet(column_set_id); column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::LEADING, diff --git a/chrome/browser/ui/views/extensions/media_galleries_dialog_views.cc b/chrome/browser/ui/views/extensions/media_galleries_dialog_views.cc index a2a3adc30618e5..7b2f4fedd0803a 100644 --- a/chrome/browser/ui/views/extensions/media_galleries_dialog_views.cc +++ b/chrome/browser/ui/views/extensions/media_galleries_dialog_views.cc @@ -99,9 +99,12 @@ void MediaGalleriesDialogViews::InitChildViews() { contents_->RemoveAllChildViews(true); checkbox_map_.clear(); - int dialog_content_width = views::Widget::GetLocalizedContentsWidth( + const int dialog_content_width = views::Widget::GetLocalizedContentsWidth( IDS_MEDIA_GALLERIES_DIALOG_CONTENT_WIDTH_CHARS); - views::GridLayout* layout = views::GridLayout::CreatePanel(contents_); + views::GridLayout* layout = views::GridLayout::CreateAndInstall(contents_); + contents_->SetBorder( + views::CreateEmptyBorder(ChromeLayoutProvider::Get()->GetInsetsMetric( + views::INSETS_DIALOG_CONTENTS))); int column_set_id = 0; views::ColumnSet* columns = layout->AddColumnSet(column_set_id); diff --git a/chrome/browser/ui/views/first_run_bubble.cc b/chrome/browser/ui/views/first_run_bubble.cc index 2e8d4f249f993b..539e4a7833aeb1 100644 --- a/chrome/browser/ui/views/first_run_bubble.cc +++ b/chrome/browser/ui/views/first_run_bubble.cc @@ -68,7 +68,7 @@ void FirstRunBubble::Init() { views::Label* subtext = new views::Label( l10n_util::GetStringUTF16(IDS_FR_BUBBLE_SUBTEXT), {original_font_list}); - views::GridLayout* layout = views::GridLayout::CreatePanel(this); + views::GridLayout* layout = views::GridLayout::CreateAndInstall(this); SetBorder(views::CreateEmptyBorder(kTopInset, kLeftInset, kBottomInset, kRightInset)); diff --git a/chrome/browser/ui/views/first_run_dialog.cc b/chrome/browser/ui/views/first_run_dialog.cc index d90bd935c8e6a6..b409d21f6a3ef4 100644 --- a/chrome/browser/ui/views/first_run_dialog.cc +++ b/chrome/browser/ui/views/first_run_dialog.cc @@ -80,7 +80,9 @@ FirstRunDialog::FirstRunDialog(Profile* profile) : profile_(profile), make_default_(NULL), report_crashes_(NULL) { - GridLayout* layout = GridLayout::CreatePanel(this); + set_margins(ChromeLayoutProvider::Get()->GetInsetsMetric( + views::INSETS_DIALOG_CONTENTS)); + GridLayout* layout = GridLayout::CreateAndInstall(this); views::ColumnSet* column_set = layout->AddColumnSet(0); column_set->AddColumn(GridLayout::FILL, GridLayout::CENTER, 0, diff --git a/chrome/browser/ui/views/global_error_bubble_view.cc b/chrome/browser/ui/views/global_error_bubble_view.cc index 6b63fad6868b24..3d16cba4608996 100644 --- a/chrome/browser/ui/views/global_error_bubble_view.cc +++ b/chrome/browser/ui/views/global_error_bubble_view.cc @@ -116,8 +116,7 @@ void GlobalErrorBubbleView::Init() { message_labels.push_back(message_label); } - views::GridLayout* layout = new views::GridLayout(this); - SetLayoutManager(layout); + views::GridLayout* layout = views::GridLayout::CreateAndInstall(this); // First row, message labels. views::ColumnSet* cs = layout->AddColumnSet(0); diff --git a/chrome/browser/ui/views/hung_renderer_view.cc b/chrome/browser/ui/views/hung_renderer_view.cc index ea381adabf9c2e..30b272771c40a9 100644 --- a/chrome/browser/ui/views/hung_renderer_view.cc +++ b/chrome/browser/ui/views/hung_renderer_view.cc @@ -223,6 +223,8 @@ bool HungRendererDialogView::IsFrameActive(WebContents* contents) { HungRendererDialogView::HungRendererDialogView() : info_label_(nullptr), hung_pages_table_(nullptr), initialized_(false) { + set_margins(ChromeLayoutProvider::Get()->GetInsetsMetric( + views::INSETS_DIALOG_CONTENTS)); chrome::RecordDialogCreation(chrome::DialogIdentifier::HUNG_RENDERER); } @@ -415,7 +417,7 @@ void HungRendererDialogView::Init() { using views::GridLayout; - GridLayout* layout = GridLayout::CreatePanel(this); + GridLayout* layout = GridLayout::CreateAndInstall(this); ChromeLayoutProvider* provider = ChromeLayoutProvider::Get(); constexpr int kColumnSetId = 0; diff --git a/chrome/browser/ui/views/ime/ime_warning_bubble_view.cc b/chrome/browser/ui/views/ime/ime_warning_bubble_view.cc index 01aad4c80dc476..a4f7893c839f46 100644 --- a/chrome/browser/ui/views/ime/ime_warning_bubble_view.cc +++ b/chrome/browser/ui/views/ime/ime_warning_bubble_view.cc @@ -159,8 +159,7 @@ void ImeWarningBubbleView::InitLayout() { // ----------------------------------------- // - views::GridLayout* layout = new views::GridLayout(this); - SetLayoutManager(layout); + views::GridLayout* layout = views::GridLayout::CreateAndInstall(this); int cs_id = 0; diff --git a/chrome/browser/ui/views/intent_picker_bubble_view.cc b/chrome/browser/ui/views/intent_picker_bubble_view.cc index 03995b6a13c280..f9b98b41ed9fc0 100644 --- a/chrome/browser/ui/views/intent_picker_bubble_view.cc +++ b/chrome/browser/ui/views/intent_picker_bubble_view.cc @@ -163,8 +163,7 @@ bool IntentPickerBubbleView::Close() { } void IntentPickerBubbleView::Init() { - views::GridLayout* layout = new views::GridLayout(this); - SetLayoutManager(layout); + views::GridLayout* layout = views::GridLayout::CreateAndInstall(this); // Creates a view to hold the views for each app. views::View* scrollable_view = new views::View(); diff --git a/chrome/browser/ui/views/login_view.cc b/chrome/browser/ui/views/login_view.cc index 109a75b65759bb..c2a7dbd9a9fb37 100644 --- a/chrome/browser/ui/views/login_view.cc +++ b/chrome/browser/ui/views/login_view.cc @@ -9,6 +9,7 @@ #include "chrome/browser/ui/views/harmony/textfield_layout.h" #include "components/strings/grit/components_strings.h" #include "ui/base/l10n/l10n_util.h" +#include "ui/views/border.h" #include "ui/views/controls/label.h" #include "ui/views/controls/textfield/textfield.h" #include "ui/views/layout/grid_layout.h" @@ -48,9 +49,11 @@ LoginView::LoginView(const base::string16& authority, // to textfield_layout.h to decide. constexpr int kMessageWidth = 320; ChromeLayoutProvider* provider = ChromeLayoutProvider::Get(); + SetBorder(views::CreateEmptyBorder( + provider->GetInsetsMetric(views::INSETS_DIALOG_CONTENTS))); // Initialize the Grid Layout Manager used for this dialog box. - GridLayout* layout = GridLayout::CreatePanel(this); + GridLayout* layout = GridLayout::CreateAndInstall(this); views::ColumnSet* column_set = layout->AddColumnSet(kHeaderColumnSetId); column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, kStretchy, GridLayout::FIXED, kMessageWidth, 0); diff --git a/chrome/browser/ui/views/page_info/chosen_object_row.cc b/chrome/browser/ui/views/page_info/chosen_object_row.cc index b4cbcb9a057957..3333d9453e421d 100644 --- a/chrome/browser/ui/views/page_info/chosen_object_row.cc +++ b/chrome/browser/ui/views/page_info/chosen_object_row.cc @@ -17,8 +17,7 @@ ChosenObjectRow::ChosenObjectRow( std::unique_ptr info) : info_(std::move(info)) { - views::GridLayout* layout = new views::GridLayout(this); - SetLayoutManager(layout); + views::GridLayout* layout = views::GridLayout::CreateAndInstall(this); const int column_set_id = 0; views::ColumnSet* column_set = layout->AddColumnSet(column_set_id); column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1, diff --git a/chrome/browser/ui/views/page_info/page_info_bubble_view.cc b/chrome/browser/ui/views/page_info/page_info_bubble_view.cc index 251d1464a43d56..477f003e6955c3 100644 --- a/chrome/browser/ui/views/page_info/page_info_bubble_view.cc +++ b/chrome/browser/ui/views/page_info/page_info_bubble_view.cc @@ -137,8 +137,7 @@ views::View* CreateInspectLinkSection(const gfx::ImageSkia& image_icon, views::Link* link) { views::View* new_view = new views::View(); - views::GridLayout* layout = new views::GridLayout(new_view); - new_view->SetLayoutManager(layout); + views::GridLayout* layout = views::GridLayout::CreateAndInstall(new_view); const int column = 0; views::ColumnSet* column_set = layout->AddColumnSet(column); @@ -260,8 +259,7 @@ BubbleHeaderView::BubbleHeaderView( password_reuse_button_container_(nullptr), change_password_button_(nullptr), whitelist_password_reuse_button_(nullptr) { - views::GridLayout* layout = new views::GridLayout(this); - SetLayoutManager(layout); + views::GridLayout* layout = views::GridLayout::CreateAndInstall(this); const int label_column_status = 1; AddColumnWithSideMargin(layout, side_margin, label_column_status); @@ -515,8 +513,7 @@ PageInfoBubbleView::PageInfoBubbleView( // below the dialog title. set_margins(gfx::Insets(0, 0, margins().bottom(), 0)); - views::GridLayout* layout = new views::GridLayout(this); - SetLayoutManager(layout); + views::GridLayout* layout = views::GridLayout::CreateAndInstall(this); // Use a single ColumnSet here. Otherwise the preferred width doesn't properly // propagate up to the dialog width. @@ -697,8 +694,8 @@ void PageInfoBubbleView::SetPermissionInfo( } permissions_view_ = new views::View(); - views::GridLayout* layout = new views::GridLayout(permissions_view_); - permissions_view_->SetLayoutManager(layout); + views::GridLayout* layout = + views::GridLayout::CreateAndInstall(permissions_view_); site_settings_view_->AddChildView(permissions_view_); diff --git a/chrome/browser/ui/views/passwords/credentials_selection_view.cc b/chrome/browser/ui/views/passwords/credentials_selection_view.cc index 540120350b2889..8b43b95376e498 100644 --- a/chrome/browser/ui/views/passwords/credentials_selection_view.cc +++ b/chrome/browser/ui/views/passwords/credentials_selection_view.cc @@ -38,7 +38,7 @@ CredentialsSelectionView::CredentialsSelectionView( DCHECK(!password_forms_->empty()); // Layout. - views::GridLayout* layout = new views::GridLayout(this); + views::GridLayout* layout = views::GridLayout::CreateAndInstall(this); SetLayoutManager(layout); // ColumnSet. diff --git a/chrome/browser/ui/views/passwords/manage_password_items_view.cc b/chrome/browser/ui/views/passwords/manage_password_items_view.cc index cb6285d15e684a..92931eb9b3b967 100644 --- a/chrome/browser/ui/views/passwords/manage_password_items_view.cc +++ b/chrome/browser/ui/views/passwords/manage_password_items_view.cc @@ -284,7 +284,7 @@ ManagePasswordItemsView::~ManagePasswordItemsView() = default; void ManagePasswordItemsView::AddRows() { const int vertical_padding = ChromeLayoutProvider::Get()->GetDistanceMetric( views::DISTANCE_RELATED_CONTROL_VERTICAL); - views::GridLayout* layout = new views::GridLayout(this); + views::GridLayout* layout = views::GridLayout::CreateAndInstall(this); SetLayoutManager(layout); for (const std::unique_ptr& row : password_forms_rows_) { if (row != password_forms_rows_[0]) diff --git a/chrome/browser/ui/views/passwords/manage_passwords_bubble_view.cc b/chrome/browser/ui/views/passwords/manage_passwords_bubble_view.cc index 1c475572dc316b..15d2324cc888b3 100644 --- a/chrome/browser/ui/views/passwords/manage_passwords_bubble_view.cc +++ b/chrome/browser/ui/views/passwords/manage_passwords_bubble_view.cc @@ -378,9 +378,8 @@ ManagePasswordsBubbleView::PendingView::PendingView( } void ManagePasswordsBubbleView::PendingView::CreateAndSetLayout() { - views::GridLayout* layout = new views::GridLayout(this); + views::GridLayout* layout = views::GridLayout::CreateAndInstall(this); layout->set_minimum_size(gfx::Size(kDesiredBubbleWidth, 0)); - SetLayoutManager(layout); // Create the edit, save and never buttons. if (!edit_button_ && @@ -557,9 +556,8 @@ class ManagePasswordsBubbleView::ManageView : public views::View, ManagePasswordsBubbleView::ManageView::ManageView( ManagePasswordsBubbleView* parent) : parent_(parent) { - views::GridLayout* layout = new views::GridLayout(this); + views::GridLayout* layout = views::GridLayout::CreateAndInstall(this); layout->set_minimum_size(gfx::Size(kDesiredBubbleWidth, 0)); - SetLayoutManager(layout); BuildColumnSet(layout, SINGLE_VIEW_COLUMN_SET); layout->StartRow(0, SINGLE_VIEW_COLUMN_SET); @@ -650,9 +648,8 @@ class ManagePasswordsBubbleView::SaveConfirmationView ManagePasswordsBubbleView::SaveConfirmationView::SaveConfirmationView( ManagePasswordsBubbleView* parent) : parent_(parent) { - views::GridLayout* layout = new views::GridLayout(this); + views::GridLayout* layout = views::GridLayout::CreateAndInstall(this); layout->set_minimum_size(gfx::Size(kDesiredBubbleWidth, 0)); - SetLayoutManager(layout); views::StyledLabel* confirmation = new views::StyledLabel(parent_->model()->save_confirmation_text(), this); @@ -724,9 +721,8 @@ class ManagePasswordsBubbleView::SignInPromoView ManagePasswordsBubbleView::SignInPromoView::SignInPromoView( ManagePasswordsBubbleView* parent) : parent_(parent) { - views::GridLayout* layout = new views::GridLayout(this); + views::GridLayout* layout = views::GridLayout::CreateAndInstall(this); layout->set_minimum_size(gfx::Size(kDesiredBubbleWidth, 0)); - SetLayoutManager(layout); signin_button_ = views::MdTextButton::CreateSecondaryUiBlueButton( this, @@ -792,9 +788,8 @@ ManagePasswordsBubbleView::UpdatePendingView::UpdatePendingView( ManagePasswordsBubbleView* parent) : parent_(parent), selection_view_(nullptr) { ChromeLayoutProvider* layout_provider = ChromeLayoutProvider::Get(); - views::GridLayout* layout = new views::GridLayout(this); + views::GridLayout* layout = views::GridLayout::CreateAndInstall(this); layout->set_minimum_size(gfx::Size(kDesiredBubbleWidth, 0)); - SetLayoutManager(layout); // Credential row. if (parent->model()->ShouldShowMultipleAccountUpdateUI()) { diff --git a/chrome/browser/ui/views/payments/credit_card_editor_view_controller.cc b/chrome/browser/ui/views/payments/credit_card_editor_view_controller.cc index ae740ce5cec2eb..2ba676f60cd2e2 100644 --- a/chrome/browser/ui/views/payments/credit_card_editor_view_controller.cc +++ b/chrome/browser/ui/views/payments/credit_card_editor_view_controller.cc @@ -293,8 +293,8 @@ CreditCardEditorViewController::CreateCustomFieldView( view = std::move(exp_label); } else { // Two comboboxes, one for month and the other for year. - std::unique_ptr combobox_layout = - base::MakeUnique(view.get()); + views::GridLayout* combobox_layout = + views::GridLayout::CreateAndInstall(view.get()); views::ColumnSet* columns = combobox_layout->AddColumnSet(0); columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER, 1, views::GridLayout::USE_PREF, 0, 0); @@ -328,7 +328,6 @@ CreditCardEditorViewController::CreateCustomFieldView( combobox_layout->AddView(year_combobox.release(), 1, 1, views::GridLayout::FILL, views::GridLayout::FILL, 0, kInputFieldHeight); - view->SetLayoutManager(combobox_layout.release()); } // Set the initial validity of the custom view. diff --git a/chrome/browser/ui/views/payments/cvc_unmask_view_controller.cc b/chrome/browser/ui/views/payments/cvc_unmask_view_controller.cc index 27a11bcc1c14ce..c75d1252a0ba15 100644 --- a/chrome/browser/ui/views/payments/cvc_unmask_view_controller.cc +++ b/chrome/browser/ui/views/payments/cvc_unmask_view_controller.cc @@ -155,8 +155,7 @@ base::string16 CvcUnmaskViewController::GetSheetTitle() { } void CvcUnmaskViewController::FillContentView(views::View* content_view) { - std::unique_ptr layout = - base::MakeUnique(content_view); + views::GridLayout* layout = views::GridLayout::CreateAndInstall(content_view); content_view->SetBorder(views::CreateEmptyBorder( kPaymentRequestRowVerticalInsets, kPaymentRequestRowHorizontalInsets, kPaymentRequestRowVerticalInsets, kPaymentRequestRowHorizontalInsets)); @@ -272,8 +271,6 @@ void CvcUnmaskViewController::FillContentView(views::View* content_view) { error_label->SetVisible(false); layout->AddView(error_label.release()); - - content_view->SetLayoutManager(layout.release()); } std::unique_ptr CvcUnmaskViewController::CreatePrimaryButton() { diff --git a/chrome/browser/ui/views/payments/editor_view_controller.cc b/chrome/browser/ui/views/payments/editor_view_controller.cc index 1c83e1deec1c7d..cdb7c7d8b3fba3 100644 --- a/chrome/browser/ui/views/payments/editor_view_controller.cc +++ b/chrome/browser/ui/views/payments/editor_view_controller.cc @@ -251,8 +251,8 @@ std::unique_ptr EditorViewController::CreateEditorView() { constexpr int kShortFieldMinimumWidth = 176; constexpr int kLongFieldMinimumWidth = 272; - std::unique_ptr editor_layout = - base::MakeUnique(editor_view.get()); + views::GridLayout* editor_layout = + views::GridLayout::CreateAndInstall(editor_view.get()); // Column set for short fields. views::ColumnSet* columns_short = editor_layout->AddColumnSet(0); columns_short->AddColumn(views::GridLayout::LEADING, @@ -307,7 +307,7 @@ std::unique_ptr EditorViewController::CreateEditorView() { for (const auto& field : GetFieldDefinitions()) { bool valid = false; views::View* focusable_field = - CreateInputField(editor_layout.get(), field, &valid); + CreateInputField(editor_layout, field, &valid); if (!first_field) first_field = focusable_field; if (!initial_focus_field_view_ && !valid) @@ -331,8 +331,6 @@ std::unique_ptr EditorViewController::CreateEditorView() { l10n_util::GetStringUTF16(IDS_PAYMENTS_REQUIRED_FIELD_MESSAGE)) .release()); - editor_view->SetLayoutManager(editor_layout.release()); - return editor_view; } diff --git a/chrome/browser/ui/views/payments/order_summary_view_controller.cc b/chrome/browser/ui/views/payments/order_summary_view_controller.cc index 0c16806096105f..334700a301d23c 100644 --- a/chrome/browser/ui/views/payments/order_summary_view_controller.cc +++ b/chrome/browser/ui/views/payments/order_summary_view_controller.cc @@ -57,8 +57,7 @@ std::unique_ptr CreateLineItemView(const base::string16& label, ui::NativeTheme::kColorId_SeparatorColor), row_insets)); - views::GridLayout* layout = new views::GridLayout(row.get()); - row->SetLayoutManager(layout); + views::GridLayout* layout = views::GridLayout::CreateAndInstall(row.get()); views::ColumnSet* columns = layout->AddColumnSet(0); // The first column has resize_percent = 1 so that it stretches all the way @@ -96,7 +95,7 @@ std::unique_ptr CreateLineItemView(const base::string16& label, std::unique_ptr amount_wrapper = base::MakeUnique(); views::GridLayout* wrapper_layout = - new views::GridLayout(amount_wrapper.get()); + views::GridLayout::CreateAndInstall(amount_wrapper.get()); views::ColumnSet* wrapper_columns = wrapper_layout->AddColumnSet(0); wrapper_columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER, 0, @@ -109,7 +108,6 @@ std::unique_ptr CreateLineItemView(const base::string16& label, currency_text->set_id(static_cast(currency_label_id)); wrapper_layout->AddView(currency_text.release()); wrapper_layout->AddView(amount_text.release()); - amount_wrapper->SetLayoutManager(wrapper_layout); layout->AddView(label_text.release()); layout->AddView(amount_wrapper.release()); diff --git a/chrome/browser/ui/views/payments/payment_request_dialog_view.cc b/chrome/browser/ui/views/payments/payment_request_dialog_view.cc index ca2e17c6fbbe5e..a5479621868904 100644 --- a/chrome/browser/ui/views/payments/payment_request_dialog_view.cc +++ b/chrome/browser/ui/views/payments/payment_request_dialog_view.cc @@ -344,8 +344,8 @@ void PaymentRequestDialogView::SetupSpinnerOverlay() { // would be under it. throbber_overlay_.SetBackground(views::CreateSolidBackground(SK_ColorWHITE)); - std::unique_ptr layout = - base::MakeUnique(&throbber_overlay_); + views::GridLayout* layout = + views::GridLayout::CreateAndInstall(&throbber_overlay_); views::ColumnSet* throbber_columns = layout->AddColumnSet(0); throbber_columns->AddPaddingColumn(0.5, 0); throbber_columns->AddColumn(views::GridLayout::Alignment::CENTER, @@ -367,7 +367,6 @@ void PaymentRequestDialogView::SetupSpinnerOverlay() { layout->AddView(new views::Label( l10n_util::GetStringUTF16(IDS_PAYMENTS_PROCESSING_MESSAGE))); - throbber_overlay_.SetLayoutManager(layout.release()); AddChildView(&throbber_overlay_); } diff --git a/chrome/browser/ui/views/payments/payment_request_item_list.cc b/chrome/browser/ui/views/payments/payment_request_item_list.cc index d55367a51efb12..e476ce9471d30b 100644 --- a/chrome/browser/ui/views/payments/payment_request_item_list.cc +++ b/chrome/browser/ui/views/payments/payment_request_item_list.cc @@ -63,8 +63,7 @@ void PaymentRequestItemList::Item::Init() { std::unique_ptr content = CreateContentView(&accessible_item_description_); - views::GridLayout* layout = new views::GridLayout(this); - SetLayoutManager(layout); + views::GridLayout* layout = views::GridLayout::CreateAndInstall(this); // Add a column for the item's content view. views::ColumnSet* columns = layout->AddColumnSet(0); diff --git a/chrome/browser/ui/views/payments/payment_request_sheet_controller.cc b/chrome/browser/ui/views/payments/payment_request_sheet_controller.cc index 07436a91c7897b..7c7b96fdcbbd73 100644 --- a/chrome/browser/ui/views/payments/payment_request_sheet_controller.cc +++ b/chrome/browser/ui/views/payments/payment_request_sheet_controller.cc @@ -218,8 +218,7 @@ std::unique_ptr PaymentRequestSheetController::CreateView() { // layer) won't do proper clipping. view->SetPaintToLayer(); - views::GridLayout* layout = new views::GridLayout(view.get()); - view->SetLayoutManager(layout); + views::GridLayout* layout = views::GridLayout::CreateAndInstall(view.get()); // Note: each view is responsible for its own padding (insets). views::ColumnSet* columns = layout->AddColumnSet(0); @@ -237,13 +236,12 @@ std::unique_ptr PaymentRequestSheetController::CreateView() { // otherwise it'll be sized to the ScrollView's viewport height, preventing // the scroll bar from ever being shown. pane_ = new views::View; - views::GridLayout* pane_layout = new views::GridLayout(pane_); + views::GridLayout* pane_layout = views::GridLayout::CreateAndInstall(pane_); views::ColumnSet* pane_columns = pane_layout->AddColumnSet(0); pane_columns->AddColumn(views::GridLayout::Alignment::FILL, views::GridLayout::Alignment::LEADING, 0, views::GridLayout::SizeType::FIXED, GetActualDialogWidth(), GetActualDialogWidth()); - pane_->SetLayoutManager(pane_layout); pane_layout->StartRow(0, 0); // This is owned by its parent. It's the container passed to FillContentView. content_view_ = new views::View; @@ -345,8 +343,8 @@ std::unique_ptr PaymentRequestSheetController::CreateFooterView() { container->SetBorder( views::CreateEmptyBorder(kInset, kInset, kInset, kInset)); - views::GridLayout* layout = new views::GridLayout(container.get()); - container->SetLayoutManager(layout); + views::GridLayout* layout = + views::GridLayout::CreateAndInstall(container.get()); views::ColumnSet* columns = layout->AddColumnSet(0); columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER, diff --git a/chrome/browser/ui/views/payments/payment_request_views_util.cc b/chrome/browser/ui/views/payments/payment_request_views_util.cc index c79047e40efd40..de8452bf0d96c6 100644 --- a/chrome/browser/ui/views/payments/payment_request_views_util.cc +++ b/chrome/browser/ui/views/payments/payment_request_views_util.cc @@ -184,8 +184,8 @@ std::unique_ptr CreateSheetHeaderView( const base::string16& title, views::ButtonListener* listener) { std::unique_ptr container = base::MakeUnique(); - views::GridLayout* layout = new views::GridLayout(container.get()); - container->SetLayoutManager(layout); + views::GridLayout* layout = + views::GridLayout::CreateAndInstall(container.get()); constexpr int kHeaderTopVerticalInset = 14; constexpr int kHeaderBottomVerticalInset = 8; diff --git a/chrome/browser/ui/views/payments/payment_sheet_view_controller.cc b/chrome/browser/ui/views/payments/payment_sheet_view_controller.cc index 1c4e99fe89f02d..e9262b935a7d32 100644 --- a/chrome/browser/ui/views/payments/payment_sheet_view_controller.cc +++ b/chrome/browser/ui/views/payments/payment_sheet_view_controller.cc @@ -150,7 +150,7 @@ std::unique_ptr CreatePaymentSheetRow( kPaymentRequestRowVerticalInsets, trailing_inset); std::unique_ptr row = base::MakeUnique(listener, clickable, row_insets); - views::GridLayout* layout = new views::GridLayout(row.get()); + views::GridLayout* layout = views::GridLayout::CreateAndInstall(row.get()); row->SetLayoutManager(layout); views::ColumnSet* columns = layout->AddColumnSet(0); @@ -211,8 +211,8 @@ std::unique_ptr CreateInlineCurrencyAmountItem( bool bold) { std::unique_ptr item_amount_line = base::MakeUnique(); - std::unique_ptr item_amount_layout = - base::MakeUnique(item_amount_line.get()); + views::GridLayout* item_amount_layout = + views::GridLayout::CreateAndInstall(item_amount_line.get()); views::ColumnSet* item_amount_columns = item_amount_layout->AddColumnSet(0); item_amount_columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::LEADING, 0, @@ -240,7 +240,6 @@ std::unique_ptr CreateInlineCurrencyAmountItem( item_amount_layout->AddView(currency_label.release()); item_amount_layout->AddView(amount_label.release()); - item_amount_line->SetLayoutManager(item_amount_layout.release()); return item_amount_line; } @@ -413,7 +412,7 @@ base::string16 PaymentSheetViewController::GetSheetTitle() { } void PaymentSheetViewController::FillContentView(views::View* content_view) { - views::GridLayout* layout = new views::GridLayout(content_view); + views::GridLayout* layout = views::GridLayout::CreateAndInstall(content_view); content_view->SetLayoutManager(layout); views::ColumnSet* columns = layout->AddColumnSet(0); columns->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER, 1, @@ -563,8 +562,8 @@ void PaymentSheetViewController::UpdatePayButtonState(bool enabled) { std::unique_ptr PaymentSheetViewController::CreatePaymentSheetSummaryRow() { std::unique_ptr inline_summary = base::MakeUnique(); - std::unique_ptr layout = - base::MakeUnique(inline_summary.get()); + views::GridLayout* layout = + views::GridLayout::CreateAndInstall(inline_summary.get()); views::ColumnSet* columns = layout->AddColumnSet(0); columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::LEADING, 1, views::GridLayout::USE_PREF, 0, 0); @@ -636,8 +635,6 @@ PaymentSheetViewController::CreatePaymentSheetSummaryRow() { false, true) .release()); - inline_summary->SetLayoutManager(layout.release()); - PaymentSheetRowBuilder builder( this, l10n_util::GetStringUTF16(IDS_PAYMENTS_ORDER_SUMMARY_LABEL)); builder.Tag(PaymentSheetViewControllerTags::SHOW_ORDER_SUMMARY_BUTTON) @@ -731,7 +728,8 @@ PaymentSheetViewController::CreatePaymentMethodRow() { if (selected_instrument) { std::unique_ptr content_view = base::MakeUnique(); - views::GridLayout* layout = new views::GridLayout(content_view.get()); + views::GridLayout* layout = + views::GridLayout::CreateAndInstall(content_view.get()); content_view->SetLayoutManager(layout); views::ColumnSet* columns = layout->AddColumnSet(0); columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER, 1, diff --git a/chrome/browser/ui/views/profiles/forced_reauthentication_dialog_view.cc b/chrome/browser/ui/views/profiles/forced_reauthentication_dialog_view.cc index 997d433a7ceed9..b15420e871d748 100644 --- a/chrome/browser/ui/views/profiles/forced_reauthentication_dialog_view.cc +++ b/chrome/browser/ui/views/profiles/forced_reauthentication_dialog_view.cc @@ -208,7 +208,7 @@ void ForcedReauthenticationDialogView::AddedToWidget() { provider->GetInsetsMetric(views::INSETS_DIALOG_CONTENTS); SetBorder(views::CreateEmptyBorder(dialog_insets.top(), 0, dialog_insets.bottom(), 0)); - views::GridLayout* dialog_layout = new views::GridLayout(this); + views::GridLayout* dialog_layout = views::GridLayout::CreateAndInstall(this); SetLayoutManager(dialog_layout); // Use a column set with no padding. diff --git a/chrome/browser/ui/views/profiles/profile_chooser_view.cc b/chrome/browser/ui/views/profiles/profile_chooser_view.cc index 76f0f4b974e8e6..7920a6a2b5dbde 100644 --- a/chrome/browser/ui/views/profiles/profile_chooser_view.cc +++ b/chrome/browser/ui/views/profiles/profile_chooser_view.cc @@ -124,8 +124,7 @@ bool IsProfileChooser(profiles::BubbleViewMode mode) { // Creates a GridLayout with a single column. This ensures that all the child // views added get auto-expanded to fill the full width of the bubble. views::GridLayout* CreateSingleColumnLayout(views::View* view, int width) { - views::GridLayout* layout = new views::GridLayout(view); - view->SetLayoutManager(layout); + views::GridLayout* layout = views::GridLayout::CreateAndInstall(view); views::ColumnSet* columns = layout->AddColumnSet(0); columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 0, @@ -452,8 +451,8 @@ class TitleCard : public views::View { TitleCard* title_card, int width) { views::View* titled_view = new views::View(); - views::GridLayout* layout = new views::GridLayout(titled_view); - titled_view->SetLayoutManager(layout); + views::GridLayout* layout = + views::GridLayout::CreateAndInstall(titled_view); ChromeLayoutProvider* provider = ChromeLayoutProvider::Get(); const gfx::Insets dialog_insets = @@ -1114,8 +1113,8 @@ views::View* ProfileChooserView::CreateCurrentProfileView( // Container for the profile photo and avatar/user name. BackgroundColorHoverButton* current_profile_card = new BackgroundColorHoverButton(this, base::string16()); - views::GridLayout* grid_layout = new views::GridLayout(current_profile_card); - current_profile_card->SetLayoutManager(grid_layout); + views::GridLayout* grid_layout = + views::GridLayout::CreateAndInstall(current_profile_card); views::ColumnSet* columns = grid_layout->AddColumnSet(0); // BackgroundColorHoverButton has already accounted for the left and right // margins. diff --git a/chrome/browser/ui/views/proximity_auth/proximity_auth_error_bubble_view.cc b/chrome/browser/ui/views/proximity_auth/proximity_auth_error_bubble_view.cc index 223f1a29df9b20..5fc2d8d3373a19 100644 --- a/chrome/browser/ui/views/proximity_auth/proximity_auth_error_bubble_view.cc +++ b/chrome/browser/ui/views/proximity_auth/proximity_auth_error_bubble_view.cc @@ -94,7 +94,7 @@ void ProximityAuthErrorBubbleView::Init() { // ---------------------------- // | icon | padding | message | // ---------------------------- - std::unique_ptr layout(new views::GridLayout(this)); + views::GridLayout* layout = views::GridLayout::CreateAndInstall(this); views::ColumnSet* columns = layout->AddColumnSet(0); columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::LEADING, 0, views::GridLayout::USE_PREF, 0, 0); @@ -120,7 +120,6 @@ void ProximityAuthErrorBubbleView::Init() { layout->StartRow(0, 0); layout->AddView(warning_icon.release()); layout->AddView(label.release()); - SetLayoutManager(layout.release()); } ProximityAuthErrorBubbleView::~ProximityAuthErrorBubbleView() {} diff --git a/chrome/browser/ui/views/sad_tab_view.cc b/chrome/browser/ui/views/sad_tab_view.cc index 93e78f2f467313..493763b62eecbf 100644 --- a/chrome/browser/ui/views/sad_tab_view.cc +++ b/chrome/browser/ui/views/sad_tab_view.cc @@ -55,8 +55,7 @@ SadTabView::SadTabView(content::WebContents* web_contents, SetBackground(views::CreateThemedSolidBackground( this, ui::NativeTheme::kColorId_DialogBackground)); - views::GridLayout* layout = new views::GridLayout(this); - SetLayoutManager(layout); + views::GridLayout* layout = views::GridLayout::CreateAndInstall(this); const int column_set_id = 0; views::ColumnSet* columns = layout->AddColumnSet(column_set_id); diff --git a/chrome/browser/ui/views/safe_browsing/password_reuse_modal_warning_dialog.cc b/chrome/browser/ui/views/safe_browsing/password_reuse_modal_warning_dialog.cc index a85c3dca89bb97..21bfc08c2c1028 100644 --- a/chrome/browser/ui/views/safe_browsing/password_reuse_modal_warning_dialog.cc +++ b/chrome/browser/ui/views/safe_browsing/password_reuse_modal_warning_dialog.cc @@ -7,6 +7,7 @@ #include "base/strings/utf_string_conversions.h" #include "build/build_config.h" #include "chrome/app/vector_icons/vector_icons.h" +#include "chrome/browser/ui/views/harmony/chrome_layout_provider.h" #include "chrome/browser/ui/views/harmony/chrome_typography.h" #include "components/constrained_window/constrained_window_views.h" #include "components/strings/grit/components_strings.h" @@ -36,8 +37,11 @@ PasswordReuseModalWarningDialog::PasswordReuseModalWarningDialog( : show_softer_warning_( PasswordProtectionService::ShouldShowSofterWarning()), done_callback_(std::move(done_callback)) { + set_margins(ChromeLayoutProvider::Get()->GetInsetsMetric( + views::INSETS_DIALOG_CONTENTS)); + // TODO(jialiul): Dialog message should align with title. - views::GridLayout* layout = views::GridLayout::CreatePanel(this); + views::GridLayout* layout = views::GridLayout::CreateAndInstall(this); views::ColumnSet* column_set = layout->AddColumnSet(0); column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1, views::GridLayout::FIXED, 400, 0); diff --git a/chrome/browser/ui/views/session_crashed_bubble_view.cc b/chrome/browser/ui/views/session_crashed_bubble_view.cc index 876d5bafd9b7c9..223d5c62db093a 100644 --- a/chrome/browser/ui/views/session_crashed_bubble_view.cc +++ b/chrome/browser/ui/views/session_crashed_bubble_view.cc @@ -247,7 +247,7 @@ views::View* SessionCrashedBubbleView::CreateFootnoteView() { // Create a view to hold the checkbox and the text. views::View* uma_view = new views::View(); - GridLayout* uma_layout = new GridLayout(uma_view); + GridLayout* uma_layout = GridLayout::CreateAndInstall(uma_view); uma_view->SetLayoutManager(uma_layout); const int kReportColumnSetId = 0; diff --git a/chrome/browser/ui/views/sync/one_click_signin_dialog_view.cc b/chrome/browser/ui/views/sync/one_click_signin_dialog_view.cc index c62185f5ebc817..1f22a9effc0dc1 100644 --- a/chrome/browser/ui/views/sync/one_click_signin_dialog_view.cc +++ b/chrome/browser/ui/views/sync/one_click_signin_dialog_view.cc @@ -88,8 +88,7 @@ OneClickSigninDialogView::~OneClickSigninDialogView() { } void OneClickSigninDialogView::Init() { - views::GridLayout* layout = new views::GridLayout(this); - SetLayoutManager(layout); + views::GridLayout* layout = views::GridLayout::CreateAndInstall(this); // Column set for descriptive text and link. views::ColumnSet* cs = layout->AddColumnSet(0); diff --git a/chrome/browser/ui/views/sync/profile_signin_confirmation_dialog_views.cc b/chrome/browser/ui/views/sync/profile_signin_confirmation_dialog_views.cc index cab51a4ddb9dff..0d3d229de825b3 100644 --- a/chrome/browser/ui/views/sync/profile_signin_confirmation_dialog_views.cc +++ b/chrome/browser/ui/views/sync/profile_signin_confirmation_dialog_views.cc @@ -14,6 +14,7 @@ #include "chrome/browser/ui/browser_navigator.h" #include "chrome/browser/ui/browser_navigator_params.h" #include "chrome/browser/ui/browser_window.h" +#include "chrome/browser/ui/views/harmony/chrome_layout_provider.h" #include "chrome/grit/chromium_strings.h" #include "chrome/grit/generated_resources.h" #include "components/constrained_window/constrained_window_views.h" @@ -205,11 +206,14 @@ void ProfileSigninConfirmationDialogViews::ViewHierarchyChanged( // insets. SetBorder(views::CreateEmptyBorder(content_insets.top(), 0, content_insets.bottom(), 0)); - views::GridLayout* dialog_layout = new views::GridLayout(this); - SetLayoutManager(dialog_layout); + views::GridLayout* dialog_layout = views::GridLayout::CreateAndInstall(this); // Use GridLayout inside the prompt bar because StyledLabel requires it. - views::GridLayout* prompt_layout = views::GridLayout::CreatePanel(prompt_bar); + views::GridLayout* prompt_layout = + views::GridLayout::CreateAndInstall(prompt_bar); + prompt_bar->SetBorder( + views::CreateEmptyBorder(ChromeLayoutProvider::Get()->GetInsetsMetric( + views::INSETS_DIALOG_CONTENTS))); constexpr int kPromptBarColumnSetId = 0; prompt_layout->AddColumnSet(kPromptBarColumnSetId) ->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER, 100, diff --git a/chrome/browser/ui/views/translate/translate_bubble_view.cc b/chrome/browser/ui/views/translate/translate_bubble_view.cc index e1a0a5f81d14f4..1b338b9eb998b1 100644 --- a/chrome/browser/ui/views/translate/translate_bubble_view.cc +++ b/chrome/browser/ui/views/translate/translate_bubble_view.cc @@ -544,8 +544,7 @@ views::View* TranslateBubbleView::CreateViewBeforeTranslate() { } views::View* view = new views::View(); - views::GridLayout* layout = new views::GridLayout(view); - view->SetLayoutManager(layout); + views::GridLayout* layout = views::GridLayout::CreateAndInstall(view); using views::GridLayout; @@ -673,8 +672,7 @@ views::View* TranslateBubbleView::CreateViewTranslating() { l10n_util::GetStringUTF16(IDS_TRANSLATE_BUBBLE_TRANSLATING)); views::View* view = new views::View(); - views::GridLayout* layout = new views::GridLayout(view); - view->SetLayoutManager(layout); + views::GridLayout* layout = views::GridLayout::CreateAndInstall(view); using views::GridLayout; @@ -725,8 +723,7 @@ views::View* TranslateBubbleView::CreateViewAfterTranslate() { l10n_util::GetStringUTF16(IDS_TRANSLATE_BUBBLE_TRANSLATED)); views::View* view = new views::View(); - views::GridLayout* layout = new views::GridLayout(view); - view->SetLayoutManager(layout); + views::GridLayout* layout = views::GridLayout::CreateAndInstall(view); using views::GridLayout; @@ -776,8 +773,7 @@ views::View* TranslateBubbleView::CreateViewError() { l10n_util::GetStringUTF16(IDS_TRANSLATE_BUBBLE_COULD_NOT_TRANSLATE)); views::View* view = new views::View(); - views::GridLayout* layout = new views::GridLayout(view); - view->SetLayoutManager(layout); + views::GridLayout* layout = views::GridLayout::CreateAndInstall(view); using views::GridLayout; @@ -857,8 +853,7 @@ views::View* TranslateBubbleView::CreateViewAdvanced() { } views::View* view = new views::View(); - views::GridLayout* layout = new views::GridLayout(view); - view->SetLayoutManager(layout); + views::GridLayout* layout = views::GridLayout::CreateAndInstall(view); using views::GridLayout; diff --git a/chrome/browser/ui/views/try_chrome_dialog.cc b/chrome/browser/ui/views/try_chrome_dialog.cc index b4687b02173102..7b4ce00fead570 100644 --- a/chrome/browser/ui/views/try_chrome_dialog.cc +++ b/chrome/browser/ui/views/try_chrome_dialog.cc @@ -9,6 +9,7 @@ #include "base/logging.h" #include "base/strings/string16.h" #include "chrome/app/vector_icons/vector_icons.h" +#include "chrome/browser/ui/views/harmony/chrome_layout_provider.h" #include "chrome/browser/ui/views/harmony/chrome_typography.h" #include "chrome/grit/chromium_strings.h" #include "chrome/grit/generated_resources.h" @@ -156,7 +157,10 @@ TryChromeDialog::Result TryChromeDialog::ShowDialog( views::View* root_view = popup_->GetRootView(); root_view->SetBackground(views::CreateSolidBackground(kBackgroundColor)); - views::GridLayout* layout = views::GridLayout::CreatePanel(root_view); + views::GridLayout* layout = views::GridLayout::CreateAndInstall(root_view); + root_view->SetBorder( + views::CreateEmptyBorder(ChromeLayoutProvider::Get()->GetInsetsMetric( + views::INSETS_DIALOG_CONTENTS))); layout->set_minimum_size(gfx::Size(kToastWidth, 0)); views::ColumnSet* columns; diff --git a/chrome/browser/ui/views/uninstall_view.cc b/chrome/browser/ui/views/uninstall_view.cc index 5569240bbe120e..ad6b948a6e94ab 100644 --- a/chrome/browser/ui/views/uninstall_view.cc +++ b/chrome/browser/ui/views/uninstall_view.cc @@ -30,6 +30,8 @@ UninstallView::UninstallView(int* user_selection, browsers_combo_(NULL), user_selection_(*user_selection), quit_closure_(quit_closure) { + set_margins(ChromeLayoutProvider::Get()->GetInsetsMetric( + views::INSETS_DIALOG_CONTENTS)); SetupControls(); } @@ -45,7 +47,7 @@ void UninstallView::SetupControls() { using views::ColumnSet; using views::GridLayout; - GridLayout* layout = GridLayout::CreatePanel(this); + GridLayout* layout = GridLayout::CreateAndInstall(this); // Message to confirm uninstallation. int column_set_id = 0; diff --git a/content/shell/browser/shell_views.cc b/content/shell/browser/shell_views.cc index bd20d90dcbe129..c513c703086605 100644 --- a/content/shell/browser/shell_views.cc +++ b/content/shell/browser/shell_views.cc @@ -115,8 +115,7 @@ class ShellWindowDelegateView : public views::WidgetDelegateView, void InitShellWindow() { SetBackground(views::CreateStandardPanelBackground()); - views::GridLayout* layout = new views::GridLayout(this); - SetLayoutManager(layout); + views::GridLayout* layout = views::GridLayout::CreateAndInstall(this); views::ColumnSet* column_set = layout->AddColumnSet(0); column_set->AddPaddingColumn(0, 2); @@ -129,8 +128,8 @@ class ShellWindowDelegateView : public views::WidgetDelegateView, // Add toolbar buttons and URL text field { layout->StartRow(0, 0); - views::GridLayout* toolbar_layout = new views::GridLayout(toolbar_view_); - toolbar_view_->SetLayoutManager(toolbar_layout); + views::GridLayout* toolbar_layout = + views::GridLayout::CreateAndInstall(toolbar_view_); views::ColumnSet* toolbar_column_set = toolbar_layout->AddColumnSet(0); diff --git a/mash/catalog_viewer/catalog_viewer.cc b/mash/catalog_viewer/catalog_viewer.cc index 5439b0518ca021..3d8c40689eaa42 100644 --- a/mash/catalog_viewer/catalog_viewer.cc +++ b/mash/catalog_viewer/catalog_viewer.cc @@ -53,8 +53,7 @@ class CatalogViewerContents : public views::WidgetDelegateView, SetBorder(views::CreateEmptyBorder(gfx::Insets(kPadding))); SetBackground(views::CreateStandardPanelBackground()); - views::GridLayout* layout = new views::GridLayout(this); - SetLayoutManager(layout); + views::GridLayout* layout = views::GridLayout::CreateAndInstall(this); views::ColumnSet* columns = layout->AddColumnSet(0); columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 0, diff --git a/mash/example/window_type_launcher/window_type_launcher.cc b/mash/example/window_type_launcher/window_type_launcher.cc index 0a9f0be74f3a9e..6ad2aa3e539f79 100644 --- a/mash/example/window_type_launcher/window_type_launcher.cc +++ b/mash/example/window_type_launcher/window_type_launcher.cc @@ -275,8 +275,7 @@ class WindowTypeLauncherView : public views::WidgetDelegateView, MdTextButton::Create(this, base::ASCIIToUTF16("Jank for (s):"))), jank_duration_field_(new views::Textfield) { SetBorder(views::CreateEmptyBorder(gfx::Insets(5))); - views::GridLayout* layout = new views::GridLayout(this); - SetLayoutManager(layout); + views::GridLayout* layout = views::GridLayout::CreateAndInstall(this); views::ColumnSet* column_set = layout->AddColumnSet(0); column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER, diff --git a/ui/app_list/views/suggestions_container_view.cc b/ui/app_list/views/suggestions_container_view.cc index ee04a7a88e5b87..c86ac21cde97d9 100644 --- a/ui/app_list/views/suggestions_container_view.cc +++ b/ui/app_list/views/suggestions_container_view.cc @@ -133,7 +133,8 @@ views::View* SuggestionsContainerView::GetSelectedView() const { void SuggestionsContainerView::CreateAppsGrid(int apps_num) { DCHECK(search_result_tile_views_.empty()); - views::GridLayout* tiles_layout_manager = new views::GridLayout(this); + views::GridLayout* tiles_layout_manager = + views::GridLayout::CreateAndInstall(this); SetLayoutManager(tiles_layout_manager); views::ColumnSet* column_set = tiles_layout_manager->AddColumnSet(0); diff --git a/ui/message_center/views/message_center_button_bar.cc b/ui/message_center/views/message_center_button_bar.cc index 95500a59060a9a..116d3b8446d6df 100644 --- a/ui/message_center/views/message_center_button_bar.cc +++ b/ui/message_center/views/message_center_button_bar.cc @@ -159,8 +159,7 @@ MessageCenterButtonBar::MessageCenterButtonBar( } void MessageCenterButtonBar::ViewVisibilityChanged() { - views::GridLayout* layout = new views::GridLayout(this); - SetLayoutManager(layout); + views::GridLayout* layout = views::GridLayout::CreateAndInstall(this); views::ColumnSet* column = layout->AddColumnSet(0); constexpr int kFooterLeftMargin = 4; column->AddPaddingColumn(0, kFooterLeftMargin); diff --git a/ui/message_center/views/notifier_settings_view.cc b/ui/message_center/views/notifier_settings_view.cc index 639c3341439bc3..f52755685469cc 100644 --- a/ui/message_center/views/notifier_settings_view.cc +++ b/ui/message_center/views/notifier_settings_view.cc @@ -362,8 +362,7 @@ void NotifierSettingsView::NotifierButton::GridChanged(bool has_learn_more, using views::ColumnSet; using views::GridLayout; - GridLayout* layout = new GridLayout(this); - SetLayoutManager(layout); + GridLayout* layout = GridLayout::CreateAndInstall(this); ColumnSet* cs = layout->AddColumnSet(0); // Add a column for the checkbox. cs->AddPaddingColumn(0, kInnateCheckboxRightPadding); diff --git a/ui/views/color_chooser/color_chooser_view.cc b/ui/views/color_chooser/color_chooser_view.cc index df8d0cf2b61437..531e12170a0981 100644 --- a/ui/views/color_chooser/color_chooser_view.cc +++ b/ui/views/color_chooser/color_chooser_view.cc @@ -377,8 +377,7 @@ ColorChooserView::ColorChooserView(ColorChooserListener* listener, AddChildView(container); View* container2 = new View(); - GridLayout* layout = new GridLayout(container2); - container2->SetLayoutManager(layout); + GridLayout* layout = GridLayout::CreateAndInstall(container2); ColumnSet* columns = layout->AddColumnSet(0); columns->AddColumn( GridLayout::LEADING, GridLayout::FILL, 0, GridLayout::USE_PREF, 0, 0); diff --git a/ui/views/controls/message_box_view.cc b/ui/views/controls/message_box_view.cc index 2445444a1a6904..af7b8062e0b248 100644 --- a/ui/views/controls/message_box_view.cc +++ b/ui/views/controls/message_box_view.cc @@ -14,6 +14,7 @@ #include "ui/base/clipboard/clipboard.h" #include "ui/base/clipboard/scoped_clipboard_writer.h" #include "ui/gfx/geometry/insets.h" +#include "ui/views/border.h" #include "ui/views/controls/button/checkbox.h" #include "ui/views/controls/label.h" #include "ui/views/controls/link.h" @@ -178,6 +179,9 @@ const char* MessageBoxView::GetClassName() const { // MessageBoxView, private: void MessageBoxView::Init(const InitParams& params) { + SetBorder(CreateEmptyBorder( + LayoutProvider::Get()->GetInsetsMetric(INSETS_DIALOG_CONTENTS))); + if (params.options & DETECT_DIRECTIONALITY) { std::vector texts; SplitStringIntoParagraphs(params.message, &texts); @@ -213,8 +217,7 @@ void MessageBoxView::Init(const InitParams& params) { void MessageBoxView::ResetLayoutManager() { // Initialize the Grid Layout Manager used for this dialog box. - GridLayout* layout = GridLayout::CreatePanel(this); - SetLayoutManager(layout); + GridLayout* layout = GridLayout::CreateAndInstall(this); // Add the column set for the message displayed at the top of the dialog box. const int message_column_view_set_id = 0; diff --git a/ui/views/examples/button_sticker_sheet.cc b/ui/views/examples/button_sticker_sheet.cc index 9b32de4f2e927b..eb8044088987e7 100644 --- a/ui/views/examples/button_sticker_sheet.cc +++ b/ui/views/examples/button_sticker_sheet.cc @@ -31,7 +31,7 @@ GridLayout* MakeStretchyGridLayout(View* host, int ncols) { const GridLayout::SizeType kColumnUsesFixedSize = GridLayout::FIXED; const int kColumnWidth = 96; - GridLayout* layout = new GridLayout(host); + GridLayout* layout = GridLayout::CreateAndInstall(host); ColumnSet* columns = layout->AddColumnSet(kStretchyGridColumnSetId); for (int i = 0; i < ncols; ++i) { if (i != 0) @@ -89,7 +89,6 @@ ButtonStickerSheet::~ButtonStickerSheet() {} void ButtonStickerSheet::CreateExampleView(View* container) { GridLayout* layout = MakeStretchyGridLayout(container, 3); - container->SetLayoutManager(layout); if (!ui::MaterialDesignController::IsSecondaryUiMaterial()) { const char* kNeedsMdWarning = diff --git a/ui/views/examples/dialog_example.cc b/ui/views/examples/dialog_example.cc index 2318b01bd0b958..f5f348f0df4aaf 100644 --- a/ui/views/examples/dialog_example.cc +++ b/ui/views/examples/dialog_example.cc @@ -133,8 +133,7 @@ void DialogExample::CreateExampleView(View* container) { views::LayoutProvider* provider = views::LayoutProvider::Get(); const int horizontal_spacing = provider->GetDistanceMetric(views::DISTANCE_RELATED_BUTTON_HORIZONTAL); - GridLayout* layout = GridLayout::CreatePanel(container); - container->SetLayoutManager(layout); + GridLayout* layout = GridLayout::CreateAndInstall(container); ColumnSet* column_set = layout->AddColumnSet(kFieldsColumnId); column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, kFixed, GridLayout::USE_PREF, 0, 0); diff --git a/ui/views/examples/examples_window.cc b/ui/views/examples/examples_window.cc index ae5e2ab998c8b2..a81925f573638c 100644 --- a/ui/views/examples/examples_window.cc +++ b/ui/views/examples/examples_window.cc @@ -143,8 +143,7 @@ class ExamplesWindowContents : public WidgetDelegateView, combobox_->ModelChanged(); SetBackground(CreateStandardPanelBackground()); - GridLayout* layout = new GridLayout(this); - SetLayoutManager(layout); + GridLayout* layout = GridLayout::CreateAndInstall(this); ColumnSet* column_set = layout->AddColumnSet(0); column_set->AddPaddingColumn(0, 5); column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, diff --git a/ui/views/examples/label_example.cc b/ui/views/examples/label_example.cc index 3244135ff578d3..dbc89326f622ec 100644 --- a/ui/views/examples/label_example.cc +++ b/ui/views/examples/label_example.cc @@ -163,8 +163,7 @@ void LabelExample::AddCustomLabel(View* container) { View* control_container = new View(); control_container->SetBorder(CreateSolidBorder(2, SK_ColorGRAY)); control_container->SetBackground(CreateSolidBackground(SK_ColorLTGRAY)); - GridLayout* layout = GridLayout::CreatePanel(control_container); - control_container->SetLayoutManager(layout); + GridLayout* layout = GridLayout::CreateAndInstall(control_container); ColumnSet* column_set = layout->AddColumnSet(0); column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, diff --git a/ui/views/examples/message_box_example.cc b/ui/views/examples/message_box_example.cc index cb9e924fbf624c..3327ff9bd1b09b 100644 --- a/ui/views/examples/message_box_example.cc +++ b/ui/views/examples/message_box_example.cc @@ -27,8 +27,7 @@ void MessageBoxExample::CreateExampleView(View* container) { status_ = new LabelButton(this, ASCIIToUTF16("Show Status")); toggle_ = new LabelButton(this, ASCIIToUTF16("Toggle Checkbox")); - GridLayout* layout = new GridLayout(container); - container->SetLayoutManager(layout); + GridLayout* layout = GridLayout::CreateAndInstall(container); message_box_view_->SetCheckBoxLabel(ASCIIToUTF16("Check Box")); diff --git a/ui/views/examples/multiline_example.cc b/ui/views/examples/multiline_example.cc index c92800f67d9c3d..e4d2461868205c 100644 --- a/ui/views/examples/multiline_example.cc +++ b/ui/views/examples/multiline_example.cc @@ -159,8 +159,7 @@ void MultilineExample::CreateExampleView(View* container) { textfield_->set_controller(this); textfield_->SetText(kTestString); - GridLayout* layout = new GridLayout(container); - container->SetLayoutManager(layout); + GridLayout* layout = GridLayout::CreateAndInstall(container); ColumnSet* column_set = layout->AddColumnSet(0); column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, diff --git a/ui/views/examples/progress_bar_example.cc b/ui/views/examples/progress_bar_example.cc index 4cb75a156e76d6..c9d826655d47ef 100644 --- a/ui/views/examples/progress_bar_example.cc +++ b/ui/views/examples/progress_bar_example.cc @@ -36,8 +36,7 @@ ProgressBarExample::~ProgressBarExample() { } void ProgressBarExample::CreateExampleView(View* container) { - GridLayout* layout = new GridLayout(container); - container->SetLayoutManager(layout); + GridLayout* layout = GridLayout::CreateAndInstall(container); ColumnSet* column_set = layout->AddColumnSet(0); column_set->AddColumn(GridLayout::TRAILING, GridLayout::CENTER, 0, diff --git a/ui/views/examples/radio_button_example.cc b/ui/views/examples/radio_button_example.cc index 38072ef46bf229..e0daa38f436f8c 100644 --- a/ui/views/examples/radio_button_example.cc +++ b/ui/views/examples/radio_button_example.cc @@ -38,8 +38,7 @@ void RadioButtonExample::CreateExampleView(View* container) { radio_buttons_[i]->set_listener(this); } - GridLayout* layout = new GridLayout(container); - container->SetLayoutManager(layout); + GridLayout* layout = GridLayout::CreateAndInstall(container); ColumnSet* column_set = layout->AddColumnSet(0); column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, diff --git a/ui/views/examples/scroll_view_example.cc b/ui/views/examples/scroll_view_example.cc index 39ffd8fb5d5a1b..ef6ff4109d3819 100644 --- a/ui/views/examples/scroll_view_example.cc +++ b/ui/views/examples/scroll_view_example.cc @@ -87,8 +87,7 @@ void ScrollViewExample::CreateExampleView(View* container) { scrollable_->SetBounds(0, 0, 1000, 100); scrollable_->SetColor(SK_ColorYELLOW, SK_ColorCYAN); - GridLayout* layout = new GridLayout(container); - container->SetLayoutManager(layout); + GridLayout* layout = GridLayout::CreateAndInstall(container); // Add scroll view. ColumnSet* column_set = layout->AddColumnSet(0); diff --git a/ui/views/examples/tabbed_pane_example.cc b/ui/views/examples/tabbed_pane_example.cc index 524fec6c99a7d1..2623c10b3a0d49 100644 --- a/ui/views/examples/tabbed_pane_example.cc +++ b/ui/views/examples/tabbed_pane_example.cc @@ -27,8 +27,7 @@ void TabbedPaneExample::CreateExampleView(View* container) { add_at_ = new LabelButton(this, ASCIIToUTF16("Add At 1")); select_at_ = new LabelButton(this, ASCIIToUTF16("Select At 1")); - GridLayout* layout = new GridLayout(container); - container->SetLayoutManager(layout); + GridLayout* layout = GridLayout::CreateAndInstall(container); const int tabbed_pane_column = 0; ColumnSet* column_set = layout->AddColumnSet(tabbed_pane_column); diff --git a/ui/views/examples/table_example.cc b/ui/views/examples/table_example.cc index 041270a4156672..f3bd42624c9ede 100644 --- a/ui/views/examples/table_example.cc +++ b/ui/views/examples/table_example.cc @@ -58,8 +58,7 @@ void TableExample::CreateExampleView(View* container) { column4_visible_checkbox_->SetChecked(true); column4_visible_checkbox_->set_listener(this); - GridLayout* layout = new GridLayout(container); - container->SetLayoutManager(layout); + GridLayout* layout = GridLayout::CreateAndInstall(container); std::vector columns; columns.push_back(TestTableColumn(0, "Fruit")); diff --git a/ui/views/examples/text_example.cc b/ui/views/examples/text_example.cc index 6869b07604692b..37b1ef11df9cc3 100644 --- a/ui/views/examples/text_example.cc +++ b/ui/views/examples/text_example.cc @@ -160,8 +160,7 @@ Combobox* TextExample::AddCombobox(GridLayout* layout, void TextExample::CreateExampleView(View* container) { text_view_ = new TextExampleView; text_view_->SetBorder(CreateSolidBorder(1, SK_ColorGRAY)); - GridLayout* layout = new GridLayout(container); - container->SetLayoutManager(layout); + GridLayout* layout = GridLayout::CreateAndInstall(container); layout->AddPaddingRow(0, 8); ColumnSet* column_set = layout->AddColumnSet(0); diff --git a/ui/views/examples/textfield_example.cc b/ui/views/examples/textfield_example.cc index 6f3c5f2d956c8a..e166ac0d7fc415 100644 --- a/ui/views/examples/textfield_example.cc +++ b/ui/views/examples/textfield_example.cc @@ -61,8 +61,7 @@ void TextfieldExample::CreateExampleView(View* container) { name_->set_controller(this); password_->set_controller(this); - GridLayout* layout = new GridLayout(container); - container->SetLayoutManager(layout); + GridLayout* layout = GridLayout::CreateAndInstall(container); ColumnSet* column_set = layout->AddColumnSet(0); column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, diff --git a/ui/views/examples/tree_view_example.cc b/ui/views/examples/tree_view_example.cc index 8e0f6a1f236143..4ecdd6d301ec1d 100644 --- a/ui/views/examples/tree_view_example.cc +++ b/ui/views/examples/tree_view_example.cc @@ -54,8 +54,7 @@ void TreeViewExample::CreateExampleView(View* container) { change_title_->SetFocusForPlatform(); change_title_->set_request_focus_on_press(true); - GridLayout* layout = new GridLayout(container); - container->SetLayoutManager(layout); + GridLayout* layout = GridLayout::CreateAndInstall(container); const int tree_view_column = 0; ColumnSet* column_set = layout->AddColumnSet(tree_view_column); diff --git a/ui/views/layout/grid_layout.cc b/ui/views/layout/grid_layout.cc index eff652752baca2..0775b73b05ea42 100644 --- a/ui/views/layout/grid_layout.cc +++ b/ui/views/layout/grid_layout.cc @@ -632,29 +632,16 @@ void ColumnSet::Resize(int delta) { // GridLayout ------------------------------------------------------------- -GridLayout::GridLayout(View* host) - : host_(host), - calculated_master_columns_(false), - remaining_row_span_(0), - current_row_(-1), - next_column_(0), - current_row_col_set_(nullptr), - adding_view_(false) { - DCHECK(host); +// static +GridLayout* GridLayout::CreateAndInstall(View* host) { + GridLayout* result = new GridLayout(host); + host->SetLayoutManager(result); + return result; } GridLayout::~GridLayout() { } -// static -GridLayout* GridLayout::CreatePanel(View* host) { - GridLayout* layout = new GridLayout(host); - host->SetBorder(CreateEmptyBorder( - LayoutProvider::Get()->GetInsetsMetric(INSETS_DIALOG_CONTENTS))); - host->SetLayoutManager(layout); - return layout; -} - ColumnSet* GridLayout::AddColumnSet(int id) { DCHECK(GetColumnSet(id) == nullptr); column_sets_.push_back(base::WrapUnique(new ColumnSet(id))); @@ -810,6 +797,17 @@ int GridLayout::GetPreferredHeightForWidth(const View* host, int width) const { return pref.height(); } +GridLayout::GridLayout(View* host) + : host_(host), + calculated_master_columns_(false), + remaining_row_span_(0), + current_row_(-1), + next_column_(0), + current_row_col_set_(nullptr), + adding_view_(false) { + DCHECK(host); +} + void GridLayout::SizeRowsAndColumns(bool layout, int width, int height, gfx::Size* pref) const { // Protect against clients asking for metrics during the addition of a View. diff --git a/ui/views/layout/grid_layout.h b/ui/views/layout/grid_layout.h index 66d9f65a99591e..a2521d4517d672 100644 --- a/ui/views/layout/grid_layout.h +++ b/ui/views/layout/grid_layout.h @@ -100,12 +100,10 @@ class VIEWS_EXPORT GridLayout : public LayoutManager { USE_PREF }; - explicit GridLayout(View* host); - ~GridLayout() override; + // Creates a new GridLayout and installs it as the LayoutManager for |host|. + static GridLayout* CreateAndInstall(View* host); - // Creates a GridLayout, assigns it as the LayoutManager of |host|, and gives - // it a INSETS_PANEL-sized padding border. - static GridLayout* CreatePanel(View* host); + ~GridLayout() override; // Creates a new column set with the specified id and returns it. // The id is later used when starting a new row. @@ -180,6 +178,8 @@ class VIEWS_EXPORT GridLayout : public LayoutManager { void set_minimum_size(const gfx::Size& size) { minimum_size_ = size; } private: + explicit GridLayout(View* host); + // As both Layout and GetPreferredSize need to do nearly the same thing, // they both call into this method. This sizes the Columns/Rows as // appropriate. If layout is true, width/height give the width/height the diff --git a/ui/views/layout/grid_layout_unittest.cc b/ui/views/layout/grid_layout_unittest.cc index ac58f08e217097..686eefb8d2ce14 100644 --- a/ui/views/layout/grid_layout_unittest.cc +++ b/ui/views/layout/grid_layout_unittest.cc @@ -78,50 +78,54 @@ class FlexibleView : public View { class GridLayoutTest : public testing::Test { public: - GridLayoutTest() : layout(&host) {} + GridLayoutTest() : layout_(GridLayout::CreateAndInstall(&host_)) {} void RemoveAll() { - for (int i = host.child_count() - 1; i >= 0; i--) - host.RemoveChildView(host.child_at(i)); + for (int i = host_.child_count() - 1; i >= 0; i--) + host_.RemoveChildView(host_.child_at(i)); } - void GetPreferredSize() { - pref = layout.GetPreferredSize(&host); - } + gfx::Size GetPreferredSize() { return layout_->GetPreferredSize(&host_); } - gfx::Size pref; - gfx::Rect bounds; - View host; - GridLayout layout; + View& host() { return host_; } + GridLayout* layout() { return layout_; } + + private: + View host_; + GridLayout* layout_; }; class GridLayoutAlignmentTest : public testing::Test { public: - GridLayoutAlignmentTest() : layout(&host) { - v1.SetPreferredSize(gfx::Size(10, 20)); + GridLayoutAlignmentTest() : layout_(GridLayout::CreateAndInstall(&host_)) { + v1_.SetPreferredSize(gfx::Size(10, 20)); } void RemoveAll() { - for (int i = host.child_count() - 1; i >= 0; i--) - host.RemoveChildView(host.child_at(i)); + for (int i = host_.child_count() - 1; i >= 0; i--) + host_.RemoveChildView(host_.child_at(i)); } void TestAlignment(GridLayout::Alignment alignment, gfx::Rect* bounds) { - ColumnSet* c1 = layout.AddColumnSet(0); + ColumnSet* c1 = layout_->AddColumnSet(0); c1->AddColumn(alignment, alignment, 1, GridLayout::USE_PREF, 0, 0); - layout.StartRow(1, 0); - layout.AddView(&v1); - gfx::Size pref = layout.GetPreferredSize(&host); + layout_->StartRow(1, 0); + layout_->AddView(&v1_); + gfx::Size pref = layout_->GetPreferredSize(&host_); EXPECT_EQ(gfx::Size(10, 20), pref); - host.SetBounds(0, 0, 100, 100); - layout.Layout(&host); - *bounds = v1.bounds(); + host_.SetBounds(0, 0, 100, 100); + layout_->Layout(&host_); + *bounds = v1_.bounds(); RemoveAll(); } - View host; - View v1; - GridLayout layout; + View& host() { return host_; } + GridLayout* layout() { return layout_; } + + private: + View host_; + View v1_; + GridLayout* layout_; }; TEST_F(GridLayoutAlignmentTest, Fill) { @@ -153,20 +157,20 @@ TEST_F(GridLayoutTest, TwoColumns) { v1.SetPreferredSize(gfx::Size(10, 20)); View v2; v2.SetPreferredSize(gfx::Size(20, 20)); - ColumnSet* c1 = layout.AddColumnSet(0); + ColumnSet* c1 = layout()->AddColumnSet(0); c1->AddColumn(GridLayout::LEADING, GridLayout::LEADING, 0, GridLayout::USE_PREF, 0, 0); c1->AddColumn(GridLayout::LEADING, GridLayout::LEADING, 0, GridLayout::USE_PREF, 0, 0); - layout.StartRow(0, 0); - layout.AddView(&v1); - layout.AddView(&v2); + layout()->StartRow(0, 0); + layout()->AddView(&v1); + layout()->AddView(&v2); - GetPreferredSize(); + gfx::Size pref = GetPreferredSize(); EXPECT_EQ(gfx::Size(30, 20), pref); - host.SetBounds(0, 0, pref.width(), pref.height()); - layout.Layout(&host); + host().SetBounds(0, 0, pref.width(), pref.height()); + layout()->Layout(&host()); ExpectViewBoundsEquals(0, 0, 10, 20, &v1); ExpectViewBoundsEquals(10, 0, 20, 20, &v2); @@ -181,7 +185,7 @@ TEST_F(GridLayoutTest, LinkedSizes) { v2.SetPreferredSize(gfx::Size(20, 20)); View v3; v3.SetPreferredSize(gfx::Size(0, 20)); - ColumnSet* c1 = layout.AddColumnSet(0); + ColumnSet* c1 = layout()->AddColumnSet(0); // Fill widths. c1->AddColumn(GridLayout::FILL, GridLayout::LEADING, 0, GridLayout::USE_PREF, @@ -191,29 +195,30 @@ TEST_F(GridLayoutTest, LinkedSizes) { c1->AddColumn(GridLayout::FILL, GridLayout::LEADING, 0, GridLayout::USE_PREF, 0, 0); - layout.StartRow(0, 0); - layout.AddView(&v1); - layout.AddView(&v2); - layout.AddView(&v3); + layout()->StartRow(0, 0); + layout()->AddView(&v1); + layout()->AddView(&v2); + layout()->AddView(&v3); // Link all the columns. c1->LinkColumnSizes(0, 1, 2, -1); - GetPreferredSize(); + gfx::Size pref = GetPreferredSize(); // |v1| and |v3| should obtain the same width as |v2|, since |v2| is largest. + pref = GetPreferredSize(); EXPECT_EQ(gfx::Size(20 + 20 + 20, 20), pref); - host.SetBounds(0, 0, pref.width(), pref.height()); - layout.Layout(&host); + host().SetBounds(0, 0, pref.width(), pref.height()); + layout()->Layout(&host()); ExpectViewBoundsEquals(0, 0, 20, 20, &v1); ExpectViewBoundsEquals(20, 0, 20, 20, &v2); ExpectViewBoundsEquals(40, 0, 20, 20, &v3); // If the limit is zero, behaves as though the columns are not linked. c1->set_linked_column_size_limit(0); - GetPreferredSize(); + pref = GetPreferredSize(); EXPECT_EQ(gfx::Size(10 + 20 + 0, 20), pref); - host.SetBounds(0, 0, pref.width(), pref.height()); - layout.Layout(&host); + host().SetBounds(0, 0, pref.width(), pref.height()); + layout()->Layout(&host()); ExpectViewBoundsEquals(0, 0, 10, 20, &v1); ExpectViewBoundsEquals(10, 0, 20, 20, &v2); ExpectViewBoundsEquals(30, 0, 0, 20, &v3); @@ -221,12 +226,12 @@ TEST_F(GridLayoutTest, LinkedSizes) { // Set a size limit. c1->set_linked_column_size_limit(40); v1.SetPreferredSize(gfx::Size(35, 20)); - GetPreferredSize(); // |v1| now dominates, but it is still below the limit. + pref = GetPreferredSize(); EXPECT_EQ(gfx::Size(35 + 35 + 35, 20), pref); - host.SetBounds(0, 0, pref.width(), pref.height()); - layout.Layout(&host); + host().SetBounds(0, 0, pref.width(), pref.height()); + layout()->Layout(&host()); ExpectViewBoundsEquals(0, 0, 35, 20, &v1); ExpectViewBoundsEquals(35, 0, 35, 20, &v2); ExpectViewBoundsEquals(70, 0, 35, 20, &v3); @@ -234,10 +239,10 @@ TEST_F(GridLayoutTest, LinkedSizes) { // Go over the limit. |v1| shouldn't influence size at all, but the others // should still be linked to the next largest width. v1.SetPreferredSize(gfx::Size(45, 20)); - GetPreferredSize(); + pref = GetPreferredSize(); EXPECT_EQ(gfx::Size(45 + 20 + 20, 20), pref); - host.SetBounds(0, 0, pref.width(), pref.height()); - layout.Layout(&host); + host().SetBounds(0, 0, pref.width(), pref.height()); + layout()->Layout(&host()); ExpectViewBoundsEquals(0, 0, 45, 20, &v1); ExpectViewBoundsEquals(45, 0, 20, 20, &v2); ExpectViewBoundsEquals(65, 0, 20, 20, &v3); @@ -250,21 +255,21 @@ TEST_F(GridLayoutTest, ColSpan1) { v1.SetPreferredSize(gfx::Size(100, 20)); View v2; v2.SetPreferredSize(gfx::Size(10, 40)); - ColumnSet* c1 = layout.AddColumnSet(0); + ColumnSet* c1 = layout()->AddColumnSet(0); c1->AddColumn(GridLayout::LEADING, GridLayout::LEADING, 0, GridLayout::USE_PREF, 0, 0); c1->AddColumn(GridLayout::LEADING, GridLayout::LEADING, 1, GridLayout::USE_PREF, 0, 0); - layout.StartRow(0, 0); - layout.AddView(&v1, 2, 1); - layout.StartRow(0, 0); - layout.AddView(&v2); + layout()->StartRow(0, 0); + layout()->AddView(&v1, 2, 1); + layout()->StartRow(0, 0); + layout()->AddView(&v2); - GetPreferredSize(); + gfx::Size pref = GetPreferredSize(); EXPECT_EQ(gfx::Size(100, 60), pref); - host.SetBounds(0, 0, pref.width(), pref.height()); - layout.Layout(&host); + host().SetBounds(0, 0, pref.width(), pref.height()); + layout()->Layout(&host()); ExpectViewBoundsEquals(0, 0, 100, 20, &v1); ExpectViewBoundsEquals(0, 20, 10, 40, &v2); @@ -276,22 +281,22 @@ TEST_F(GridLayoutTest, ColSpan2) { v1.SetPreferredSize(gfx::Size(100, 20)); View v2; v2.SetPreferredSize(gfx::Size(10, 20)); - ColumnSet* c1 = layout.AddColumnSet(0); + ColumnSet* c1 = layout()->AddColumnSet(0); c1->AddColumn(GridLayout::LEADING, GridLayout::LEADING, 1, GridLayout::USE_PREF, 0, 0); c1->AddColumn(GridLayout::LEADING, GridLayout::LEADING, 0, GridLayout::USE_PREF, 0, 0); - layout.StartRow(0, 0); - layout.AddView(&v1, 2, 1); - layout.StartRow(0, 0); - layout.SkipColumns(1); - layout.AddView(&v2); + layout()->StartRow(0, 0); + layout()->AddView(&v1, 2, 1); + layout()->StartRow(0, 0); + layout()->SkipColumns(1); + layout()->AddView(&v2); - GetPreferredSize(); + gfx::Size pref = GetPreferredSize(); EXPECT_EQ(gfx::Size(100, 40), pref); - host.SetBounds(0, 0, pref.width(), pref.height()); - layout.Layout(&host); + host().SetBounds(0, 0, pref.width(), pref.height()); + layout()->Layout(&host()); ExpectViewBoundsEquals(0, 0, 100, 20, &v1); ExpectViewBoundsEquals(90, 20, 10, 20, &v2); @@ -305,22 +310,22 @@ TEST_F(GridLayoutTest, ColSpan3) { v2.SetPreferredSize(gfx::Size(10, 20)); View v3; v3.SetPreferredSize(gfx::Size(10, 20)); - ColumnSet* c1 = layout.AddColumnSet(0); + ColumnSet* c1 = layout()->AddColumnSet(0); c1->AddColumn(GridLayout::LEADING, GridLayout::LEADING, 0, GridLayout::USE_PREF, 0, 0); c1->AddColumn(GridLayout::LEADING, GridLayout::LEADING, 0, GridLayout::USE_PREF, 0, 0); - layout.StartRow(0, 0); - layout.AddView(&v1, 2, 1); - layout.StartRow(0, 0); - layout.AddView(&v2); - layout.AddView(&v3); + layout()->StartRow(0, 0); + layout()->AddView(&v1, 2, 1); + layout()->StartRow(0, 0); + layout()->AddView(&v2); + layout()->AddView(&v3); - GetPreferredSize(); + gfx::Size pref = GetPreferredSize(); EXPECT_EQ(gfx::Size(100, 40), pref); - host.SetBounds(0, 0, pref.width(), pref.height()); - layout.Layout(&host); + host().SetBounds(0, 0, pref.width(), pref.height()); + layout()->Layout(&host()); ExpectViewBoundsEquals(0, 0, 100, 20, &v1); ExpectViewBoundsEquals(0, 20, 10, 20, &v2); ExpectViewBoundsEquals(50, 20, 10, 20, &v3); @@ -330,7 +335,7 @@ TEST_F(GridLayoutTest, ColSpan3) { TEST_F(GridLayoutTest, ColSpan4) { - ColumnSet* set = layout.AddColumnSet(0); + ColumnSet* set = layout()->AddColumnSet(0); set->AddColumn(GridLayout::LEADING, GridLayout::LEADING, 0, GridLayout::USE_PREF, 0, 0); @@ -343,17 +348,17 @@ TEST_F(GridLayoutTest, ColSpan4) { v2.SetPreferredSize(gfx::Size(10, 10)); View v3; v3.SetPreferredSize(gfx::Size(25, 20)); - layout.StartRow(0, 0); - layout.AddView(&v1); - layout.AddView(&v2); - layout.StartRow(0, 0); - layout.AddView(&v3, 2, 1); + layout()->StartRow(0, 0); + layout()->AddView(&v1); + layout()->AddView(&v2); + layout()->StartRow(0, 0); + layout()->AddView(&v3, 2, 1); - GetPreferredSize(); + gfx::Size pref = GetPreferredSize(); EXPECT_EQ(gfx::Size(25, 30), pref); - host.SetBounds(0, 0, pref.width(), pref.height()); - layout.Layout(&host); + host().SetBounds(0, 0, pref.width(), pref.height()); + layout()->Layout(&host()); ExpectViewBoundsEquals(0, 0, 10, 10, &v1); ExpectViewBoundsEquals(12, 0, 10, 10, &v2); ExpectViewBoundsEquals(0, 10, 25, 20, &v3); @@ -364,7 +369,7 @@ TEST_F(GridLayoutTest, ColSpan4) { // Verifies the sizing of a view that doesn't start in the first column // and has a column span > 1 (crbug.com/254092). TEST_F(GridLayoutTest, ColSpanStartSecondColumn) { - ColumnSet* set = layout.AddColumnSet(0); + ColumnSet* set = layout()->AddColumnSet(0); set->AddColumn(GridLayout::FILL, GridLayout::FILL, 0, GridLayout::USE_PREF, 0, 0); @@ -378,15 +383,15 @@ TEST_F(GridLayoutTest, ColSpanStartSecondColumn) { View v2; v2.SetPreferredSize(gfx::Size(20, 10)); - layout.StartRow(0, 0); - layout.AddView(&v1); - layout.AddView(&v2, 2, 1); + layout()->StartRow(0, 0); + layout()->AddView(&v1); + layout()->AddView(&v2, 2, 1); - GetPreferredSize(); + gfx::Size pref = GetPreferredSize(); EXPECT_EQ(gfx::Size(30, 10), pref); - host.SetBounds(0, 0, pref.width(), pref.height()); - layout.Layout(&host); + host().SetBounds(0, 0, pref.width(), pref.height()); + layout()->Layout(&host()); ExpectViewBoundsEquals(0, 0, 10, 10, &v1); ExpectViewBoundsEquals(10, 0, 20, 10, &v2); @@ -398,21 +403,21 @@ TEST_F(GridLayoutTest, SameSizeColumns) { v1.SetPreferredSize(gfx::Size(50, 20)); View v2; v2.SetPreferredSize(gfx::Size(10, 10)); - ColumnSet* c1 = layout.AddColumnSet(0); + ColumnSet* c1 = layout()->AddColumnSet(0); c1->AddColumn(GridLayout::LEADING, GridLayout::LEADING, 0, GridLayout::USE_PREF, 0, 0); c1->AddColumn(GridLayout::LEADING, GridLayout::LEADING, 0, GridLayout::USE_PREF, 0, 0); c1->LinkColumnSizes(0, 1, -1); - layout.StartRow(0, 0); - layout.AddView(&v1); - layout.AddView(&v2); + layout()->StartRow(0, 0); + layout()->AddView(&v1); + layout()->AddView(&v2); - gfx::Size pref = layout.GetPreferredSize(&host); + gfx::Size pref = GetPreferredSize(); EXPECT_EQ(gfx::Size(100, 20), pref); - host.SetBounds(0, 0, pref.width(), pref.height()); - layout.Layout(&host); + host().SetBounds(0, 0, pref.width(), pref.height()); + layout()->Layout(&host()); ExpectViewBoundsEquals(0, 0, 50, 20, &v1); ExpectViewBoundsEquals(50, 0, 10, 10, &v2); @@ -424,17 +429,17 @@ TEST_F(GridLayoutTest, HorizontalResizeTest1) { v1.SetPreferredSize(gfx::Size(50, 20)); View v2; v2.SetPreferredSize(gfx::Size(10, 10)); - ColumnSet* c1 = layout.AddColumnSet(0); + ColumnSet* c1 = layout()->AddColumnSet(0); c1->AddColumn(GridLayout::FILL, GridLayout::LEADING, 1, GridLayout::USE_PREF, 0, 0); c1->AddColumn(GridLayout::LEADING, GridLayout::LEADING, 0, GridLayout::USE_PREF, 0, 0); - layout.StartRow(0, 0); - layout.AddView(&v1); - layout.AddView(&v2); + layout()->StartRow(0, 0); + layout()->AddView(&v1); + layout()->AddView(&v2); - host.SetBounds(0, 0, 110, 20); - layout.Layout(&host); + host().SetBounds(0, 0, 110, 20); + layout()->Layout(&host()); ExpectViewBoundsEquals(0, 0, 100, 20, &v1); ExpectViewBoundsEquals(100, 0, 10, 10, &v2); @@ -446,17 +451,17 @@ TEST_F(GridLayoutTest, HorizontalResizeTest2) { v1.SetPreferredSize(gfx::Size(50, 20)); View v2; v2.SetPreferredSize(gfx::Size(10, 10)); - ColumnSet* c1 = layout.AddColumnSet(0); + ColumnSet* c1 = layout()->AddColumnSet(0); c1->AddColumn(GridLayout::FILL, GridLayout::LEADING, 1, GridLayout::USE_PREF, 0, 0); c1->AddColumn(GridLayout::TRAILING, GridLayout::LEADING, 1, GridLayout::USE_PREF, 0, 0); - layout.StartRow(0, 0); - layout.AddView(&v1); - layout.AddView(&v2); + layout()->StartRow(0, 0); + layout()->AddView(&v1); + layout()->AddView(&v2); - host.SetBounds(0, 0, 120, 20); - layout.Layout(&host); + host().SetBounds(0, 0, 120, 20); + layout()->Layout(&host()); ExpectViewBoundsEquals(0, 0, 80, 20, &v1); ExpectViewBoundsEquals(110, 0, 10, 10, &v2); @@ -472,20 +477,20 @@ TEST_F(GridLayoutTest, HorizontalResizeTest3) { v2.SetPreferredSize(gfx::Size(10, 10)); View v3; v3.SetPreferredSize(gfx::Size(10, 10)); - ColumnSet* c1 = layout.AddColumnSet(0); + ColumnSet* c1 = layout()->AddColumnSet(0); c1->AddColumn(GridLayout::FILL, GridLayout::LEADING, 1, GridLayout::USE_PREF, 0, 0); c1->AddColumn(GridLayout::FILL, GridLayout::LEADING, 1, GridLayout::USE_PREF, 0, 0); c1->AddColumn(GridLayout::TRAILING, GridLayout::LEADING, 0, GridLayout::USE_PREF, 0, 0); - layout.StartRow(0, 0); - layout.AddView(&v1); - layout.AddView(&v2); - layout.AddView(&v3); + layout()->StartRow(0, 0); + layout()->AddView(&v1); + layout()->AddView(&v2); + layout()->AddView(&v3); - host.SetBounds(0, 0, 31, 10); - layout.Layout(&host); + host().SetBounds(0, 0, 31, 10); + layout()->Layout(&host()); ExpectViewBoundsEquals(0, 0, 10, 10, &v1); ExpectViewBoundsEquals(10, 0, 11, 10, &v2); ExpectViewBoundsEquals(21, 0, 10, 10, &v3); @@ -498,19 +503,19 @@ TEST_F(GridLayoutTest, TestVerticalResize1) { v1.SetPreferredSize(gfx::Size(50, 20)); View v2; v2.SetPreferredSize(gfx::Size(10, 10)); - ColumnSet* c1 = layout.AddColumnSet(0); + ColumnSet* c1 = layout()->AddColumnSet(0); c1->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, GridLayout::USE_PREF, 0, 0); - layout.StartRow(1, 0); - layout.AddView(&v1); - layout.StartRow(0, 0); - layout.AddView(&v2); + layout()->StartRow(1, 0); + layout()->AddView(&v1); + layout()->StartRow(0, 0); + layout()->AddView(&v2); - GetPreferredSize(); + gfx::Size pref = GetPreferredSize(); EXPECT_EQ(gfx::Size(50, 30), pref); - host.SetBounds(0, 0, 50, 100); - layout.Layout(&host); + host().SetBounds(0, 0, 50, 100); + layout()->Layout(&host()); ExpectViewBoundsEquals(0, 0, 50, 90, &v1); ExpectViewBoundsEquals(0, 90, 50, 10, &v2); @@ -518,29 +523,29 @@ TEST_F(GridLayoutTest, TestVerticalResize1) { } TEST_F(GridLayoutTest, Border) { - host.SetBorder(CreateEmptyBorder(1, 2, 3, 4)); + host().SetBorder(CreateEmptyBorder(1, 2, 3, 4)); View v1; v1.SetPreferredSize(gfx::Size(10, 20)); - ColumnSet* c1 = layout.AddColumnSet(0); + ColumnSet* c1 = layout()->AddColumnSet(0); c1->AddColumn(GridLayout::LEADING, GridLayout::LEADING, 0, GridLayout::USE_PREF, 0, 0); - layout.StartRow(0, 0); - layout.AddView(&v1); + layout()->StartRow(0, 0); + layout()->AddView(&v1); - GetPreferredSize(); + gfx::Size pref = GetPreferredSize(); EXPECT_EQ(gfx::Size(16, 24), pref); - host.SetBounds(0, 0, pref.width(), pref.height()); - layout.Layout(&host); + host().SetBounds(0, 0, pref.width(), pref.height()); + layout()->Layout(&host()); ExpectViewBoundsEquals(2, 1, 10, 20, &v1); RemoveAll(); } TEST_F(GridLayoutTest, FixedSize) { - host.SetBorder(CreateEmptyBorder(2, 2, 2, 2)); + host().SetBorder(CreateEmptyBorder(2, 2, 2, 2)); - ColumnSet* set = layout.AddColumnSet(0); + ColumnSet* set = layout()->AddColumnSet(0); int column_count = 4; int title_width = 100; @@ -558,17 +563,17 @@ TEST_F(GridLayoutTest, FixedSize) { } for (int row = 0; row < row_count; ++row) { - layout.StartRow(0, 0); + layout()->StartRow(0, 0); for (int col = 0; col < column_count; ++col) { - layout.AddView(CreateSizedView(gfx::Size(pref_width, pref_height))); + layout()->AddView(CreateSizedView(gfx::Size(pref_width, pref_height))); } } - layout.Layout(&host); + layout()->Layout(&host()); for (int i = 0; i < column_count; ++i) { for (int row = 0; row < row_count; ++row) { - View* view = host.child_at(row * column_count + i); + View* view = host().child_at(row * column_count + i); ExpectViewBoundsEquals( 2 + title_width * i + (title_width - pref_width) / 2, 2 + pref_height * row, @@ -577,13 +582,13 @@ TEST_F(GridLayoutTest, FixedSize) { } } - GetPreferredSize(); + gfx::Size pref = GetPreferredSize(); EXPECT_EQ(gfx::Size(column_count * title_width + 4, row_count * pref_height + 4), pref); } TEST_F(GridLayoutTest, RowSpanWithPaddingRow) { - ColumnSet* set = layout.AddColumnSet(0); + ColumnSet* set = layout()->AddColumnSet(0); set->AddColumn(GridLayout::CENTER, GridLayout::CENTER, @@ -592,13 +597,13 @@ TEST_F(GridLayoutTest, RowSpanWithPaddingRow) { 10, 10); - layout.StartRow(0, 0); - layout.AddView(CreateSizedView(gfx::Size(10, 10)), 1, 2); - layout.AddPaddingRow(0, 10); + layout()->StartRow(0, 0); + layout()->AddView(CreateSizedView(gfx::Size(10, 10)), 1, 2); + layout()->AddPaddingRow(0, 10); } TEST_F(GridLayoutTest, RowSpan) { - ColumnSet* set = layout.AddColumnSet(0); + ColumnSet* set = layout()->AddColumnSet(0); set->AddColumn(GridLayout::LEADING, GridLayout::LEADING, @@ -613,112 +618,114 @@ TEST_F(GridLayoutTest, RowSpan) { 0, 0); - layout.StartRow(0, 0); - layout.AddView(CreateSizedView(gfx::Size(20, 10))); - layout.AddView(CreateSizedView(gfx::Size(20, 40)), 1, 2); - layout.StartRow(1, 0); + layout()->StartRow(0, 0); + layout()->AddView(CreateSizedView(gfx::Size(20, 10))); + layout()->AddView(CreateSizedView(gfx::Size(20, 40)), 1, 2); + layout()->StartRow(1, 0); View* s3 = CreateSizedView(gfx::Size(20, 10)); - layout.AddView(s3); + layout()->AddView(s3); - GetPreferredSize(); + gfx::Size pref = GetPreferredSize(); EXPECT_EQ(gfx::Size(40, 40), pref); - host.SetBounds(0, 0, pref.width(), pref.height()); - layout.Layout(&host); + host().SetBounds(0, 0, pref.width(), pref.height()); + layout()->Layout(&host()); ExpectViewBoundsEquals(0, 10, 20, 10, s3); } TEST_F(GridLayoutTest, RowSpan2) { - ColumnSet* set = layout.AddColumnSet(0); + ColumnSet* set = layout()->AddColumnSet(0); set->AddColumn(GridLayout::LEADING, GridLayout::LEADING, 0, GridLayout::USE_PREF, 0, 0); set->AddColumn(GridLayout::LEADING, GridLayout::LEADING, 0,GridLayout::USE_PREF, 0, 0); - layout.StartRow(0, 0); - layout.AddView(CreateSizedView(gfx::Size(20, 20))); + layout()->StartRow(0, 0); + layout()->AddView(CreateSizedView(gfx::Size(20, 20))); View* s3 = CreateSizedView(gfx::Size(64, 64)); - layout.AddView(s3, 1, 3); + layout()->AddView(s3, 1, 3); - layout.AddPaddingRow(0, 10); + layout()->AddPaddingRow(0, 10); - layout.StartRow(0, 0); - layout.AddView(CreateSizedView(gfx::Size(10, 20))); + layout()->StartRow(0, 0); + layout()->AddView(CreateSizedView(gfx::Size(10, 20))); - GetPreferredSize(); + gfx::Size pref = GetPreferredSize(); EXPECT_EQ(gfx::Size(84, 64), pref); - host.SetBounds(0, 0, pref.width(), pref.height()); - layout.Layout(&host); + host().SetBounds(0, 0, pref.width(), pref.height()); + layout()->Layout(&host()); ExpectViewBoundsEquals(20, 0, 64, 64, s3); } TEST_F(GridLayoutTest, FixedViewWidth) { - ColumnSet* set = layout.AddColumnSet(0); + ColumnSet* set = layout()->AddColumnSet(0); set->AddColumn(GridLayout::LEADING, GridLayout::LEADING, 0, GridLayout::USE_PREF, 0, 0); set->AddColumn(GridLayout::LEADING, GridLayout::LEADING, 0,GridLayout::USE_PREF, 0, 0); - layout.StartRow(0, 0); + layout()->StartRow(0, 0); View* view = CreateSizedView(gfx::Size(30, 40)); - layout.AddView(view, 1, 1, GridLayout::LEADING, GridLayout::LEADING, 10, 0); + layout()->AddView(view, 1, 1, GridLayout::LEADING, GridLayout::LEADING, 10, + 0); - GetPreferredSize(); + gfx::Size pref = GetPreferredSize(); EXPECT_EQ(10, pref.width()); EXPECT_EQ(40, pref.height()); - host.SetBounds(0, 0, pref.width(), pref.height()); - layout.Layout(&host); + host().SetBounds(0, 0, pref.width(), pref.height()); + layout()->Layout(&host()); ExpectViewBoundsEquals(0, 0, 10, 40, view); } TEST_F(GridLayoutTest, FixedViewHeight) { - ColumnSet* set = layout.AddColumnSet(0); + ColumnSet* set = layout()->AddColumnSet(0); set->AddColumn(GridLayout::LEADING, GridLayout::LEADING, 0, GridLayout::USE_PREF, 0, 0); set->AddColumn(GridLayout::LEADING, GridLayout::LEADING, 0,GridLayout::USE_PREF, 0, 0); - layout.StartRow(0, 0); + layout()->StartRow(0, 0); View* view = CreateSizedView(gfx::Size(30, 40)); - layout.AddView(view, 1, 1, GridLayout::LEADING, GridLayout::LEADING, 0, 10); + layout()->AddView(view, 1, 1, GridLayout::LEADING, GridLayout::LEADING, 0, + 10); - GetPreferredSize(); + gfx::Size pref = GetPreferredSize(); EXPECT_EQ(30, pref.width()); EXPECT_EQ(10, pref.height()); - host.SetBounds(0, 0, pref.width(), pref.height()); - layout.Layout(&host); + host().SetBounds(0, 0, pref.width(), pref.height()); + layout()->Layout(&host()); ExpectViewBoundsEquals(0, 0, 30, 10, view); } // Make sure that for views that span columns the underlying columns are resized // based on the resize percent of the column. TEST_F(GridLayoutTest, ColumnSpanResizing) { - ColumnSet* set = layout.AddColumnSet(0); + ColumnSet* set = layout()->AddColumnSet(0); set->AddColumn(GridLayout::FILL, GridLayout::CENTER, 2, GridLayout::USE_PREF, 0, 0); set->AddColumn(GridLayout::FILL, GridLayout::CENTER, 4, GridLayout::USE_PREF, 0, 0); - layout.StartRow(0, 0); + layout()->StartRow(0, 0); // span_view spans two columns and is twice as big the views added below. View* span_view = CreateSizedView(gfx::Size(12, 40)); - layout.AddView(span_view, 2, 1, GridLayout::LEADING, GridLayout::LEADING); + layout()->AddView(span_view, 2, 1, GridLayout::LEADING, GridLayout::LEADING); - layout.StartRow(0, 0); + layout()->StartRow(0, 0); View* view1 = CreateSizedView(gfx::Size(2, 40)); View* view2 = CreateSizedView(gfx::Size(4, 40)); - layout.AddView(view1); - layout.AddView(view2); + layout()->AddView(view1); + layout()->AddView(view2); - host.SetBounds(0, 0, 12, 80); - layout.Layout(&host); + host().SetBounds(0, 0, 12, 80); + layout()->Layout(&host()); ExpectViewBoundsEquals(0, 0, 12, 40, span_view); @@ -736,55 +743,55 @@ TEST_F(GridLayoutTest, ColumnSpanResizing) { // there is additional space in the case we have column sets of different // preferred sizes. TEST_F(GridLayoutTest, ColumnResizingOnGetPreferredSize) { - ColumnSet* set = layout.AddColumnSet(0); + ColumnSet* set = layout()->AddColumnSet(0); set->AddColumn(GridLayout::FILL, GridLayout::CENTER, 1, GridLayout::USE_PREF, 0, 0); - set = layout.AddColumnSet(1); + set = layout()->AddColumnSet(1); set->AddColumn(GridLayout::FILL, GridLayout::CENTER, 1, GridLayout::USE_PREF, 0, 0); - set = layout.AddColumnSet(2); + set = layout()->AddColumnSet(2); set->AddColumn(GridLayout::FILL, GridLayout::CENTER, 1, GridLayout::USE_PREF, 0, 0); // Make a row containing a flexible view that trades width for height. - layout.StartRow(0, 0); + layout()->StartRow(0, 0); View* view1 = new FlexibleView(100); - layout.AddView(view1, 1, 1, GridLayout::FILL, GridLayout::LEADING); + layout()->AddView(view1, 1, 1, GridLayout::FILL, GridLayout::LEADING); // The second row contains a view of fixed size that will enforce a column // width of 20 pixels. - layout.StartRow(0, 1); + layout()->StartRow(0, 1); View* view2 = CreateSizedView(gfx::Size(20, 20)); - layout.AddView(view2, 1, 1, GridLayout::FILL, GridLayout::LEADING); + layout()->AddView(view2, 1, 1, GridLayout::FILL, GridLayout::LEADING); // Add another flexible view in row three in order to ensure column set // ordering doesn't influence sizing behaviour. - layout.StartRow(0, 2); + layout()->StartRow(0, 2); View* view3 = new FlexibleView(40); - layout.AddView(view3, 1, 1, GridLayout::FILL, GridLayout::LEADING); + layout()->AddView(view3, 1, 1, GridLayout::FILL, GridLayout::LEADING); // We expect a height of 50: 30 from the variable width view in the first row // plus 20 from the statically sized view in the second row. The flexible // view in the third row should contribute no height. - EXPECT_EQ(gfx::Size(20, 50), layout.GetPreferredSize(&host)); + EXPECT_EQ(gfx::Size(20, 50), GetPreferredSize()); } TEST_F(GridLayoutTest, MinimumPreferredSize) { View v1; v1.SetPreferredSize(gfx::Size(10, 20)); - ColumnSet* set = layout.AddColumnSet(0); + ColumnSet* set = layout()->AddColumnSet(0); set->AddColumn(GridLayout::FILL, GridLayout::FILL, 0, GridLayout::USE_PREF, 0, 0); - layout.StartRow(0, 0); - layout.AddView(&v1); + layout()->StartRow(0, 0); + layout()->AddView(&v1); - GetPreferredSize(); + gfx::Size pref = GetPreferredSize(); EXPECT_EQ(gfx::Size(10, 20), pref); - layout.set_minimum_size(gfx::Size(40, 40)); - GetPreferredSize(); + layout()->set_minimum_size(gfx::Size(40, 40)); + pref = GetPreferredSize(); EXPECT_EQ(gfx::Size(40, 40), pref); RemoveAll(); @@ -801,22 +808,18 @@ TEST_F(GridLayoutTest, LayoutOnAddDeath) { if (PlatformTestHelper::IsMus()) return; - // Don't use the |layout| data member from the test harness, otherwise - // SetLayoutManager() can take not take ownership. - GridLayout* grid_layout = new GridLayout(&host); - host.SetLayoutManager(grid_layout); - ColumnSet* set = grid_layout->AddColumnSet(0); + ColumnSet* set = layout()->AddColumnSet(0); set->AddColumn(GridLayout::FILL, GridLayout::FILL, 0, GridLayout::USE_PREF, 0, 0); - grid_layout->StartRow(0, 0); + layout()->StartRow(0, 0); LayoutOnAddView view; - EXPECT_DCHECK_DEATH(grid_layout->AddView(&view)); + EXPECT_DCHECK_DEATH(layout()->AddView(&view)); // Death tests use fork(), so nothing should be added here. EXPECT_FALSE(view.parent()); // If the View has nothing to change, adding should succeed. view.set_target_size(view.GetPreferredSize()); - grid_layout->AddView(&view); + layout()->AddView(&view); EXPECT_TRUE(view.parent()); RemoveAll(); diff --git a/ui/views/window/dialog_client_view.cc b/ui/views/window/dialog_client_view.cc index 256ba5dcc0dc26..7cd77e42fef18c 100644 --- a/ui/views/window/dialog_client_view.cc +++ b/ui/views/window/dialog_client_view.cc @@ -326,14 +326,14 @@ DialogClientView::GetButtonRowViews() { void DialogClientView::SetupLayout() { base::AutoReset auto_reset(&adding_or_removing_views_, true); - GridLayout* layout = new GridLayout(button_row_container_); - layout->set_minimum_size(minimum_size_); FocusManager* focus_manager = GetFocusManager(); ViewTracker view_tracker(focus_manager->GetFocusedView()); // Clobber any existing LayoutManager since it has weak references to child // Views which may be removed by SetupViews(). - button_row_container_->SetLayoutManager(layout); + GridLayout* layout = GridLayout::CreateAndInstall(button_row_container_); + layout->set_minimum_size(minimum_size_); + SetupViews(); const std::array views = GetButtonRowViews();