0

Delete GridLayout::CreatePanel.

Reland of chromium-review.googlesource.com/c/chromium/src/+/627096

Subclasses of DialogDelegate now call set_margin. Other usages
explicitly set a border on themselves. This decouples GridLayout
creation and actual layout declaration.

Also made GridLayout call SetLayoutManager on the host when
constructed, since we never want to not call it.

TBR=sky@chromium.org,xiyuan@chromium.org,dgozman@chromium.org

Bug: 733040
Change-Id: I837800b914218c8677e0b3550d41632218e9b041
Reviewed-on: https://chromium-review.googlesource.com/647030
Commit-Queue: Bret Sepulveda <bsep@chromium.org>
Reviewed-by: Bret Sepulveda <bsep@chromium.org>
Cr-Commit-Position: refs/heads/master@{#499115}
This commit is contained in:
Bret Sepulveda
2017-09-01 02:39:46 +00:00
committed by Commit Bot
parent c67da227a4
commit 01402a48c7
87 changed files with 502 additions and 511 deletions
ash
chrome/browser
chromeos
ui
views
accessibility
apps
bookmarks
certificate_selector.cccollected_cookies_views.ccconfirm_bubble_views.ccconfirm_bubble_views_unittest.cccontent_setting_bubble_contents.cccookie_info_view.cccreate_application_shortcut_view.cccrypto_module_password_dialog_view.cc
desktop_ios_promotion
download
extensions
first_run_bubble.ccfirst_run_dialog.ccglobal_error_bubble_view.cchung_renderer_view.cc
ime
intent_picker_bubble_view.cclogin_view.cc
page_info
passwords
payments
profiles
proximity_auth
sad_tab_view.cc
safe_browsing
session_crashed_bubble_view.cc
sync
translate
try_chrome_dialog.ccuninstall_view.cc
content/shell/browser
mash
catalog_viewer
example
window_type_launcher
ui

@ -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,

@ -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);

@ -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;

@ -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.

@ -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,

@ -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();

@ -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_;

@ -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);

@ -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);

@ -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();
}

@ -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);

@ -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_);

@ -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);

@ -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;

@ -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;

@ -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<std::string> provider_names;
@ -197,7 +200,7 @@ void CertificateSelector::Show() {
void CertificateSelector::InitWithText(
std::unique_ptr<views::View> 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);

@ -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);

@ -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<ConfirmBubbleModel> 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;

@ -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());

@ -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);

@ -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);

@ -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);

@ -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(

@ -40,8 +40,7 @@ DesktopIOSPromotionBubbleView::DesktopIOSPromotionBubbleView(
base::MakeUnique<DesktopIOSPromotionBubbleController>(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,

@ -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,

@ -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);

@ -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<MockChooserController>();
mock_chooser_controller_ = mock_chooser_controller.get();
std::unique_ptr<ChooserDialogView> 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:

@ -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,

@ -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);

@ -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));

@ -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,

@ -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);

@ -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;

@ -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;

@ -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();

@ -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);

@ -17,8 +17,7 @@
ChosenObjectRow::ChosenObjectRow(
std::unique_ptr<PageInfoUI::ChosenObjectInfo> 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,

@ -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_);

@ -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.

@ -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<PasswordFormRow>& row : password_forms_rows_) {
if (row != password_forms_rows_[0])

@ -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()) {

@ -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<views::GridLayout> combobox_layout =
base::MakeUnique<views::GridLayout>(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.

@ -155,8 +155,7 @@ base::string16 CvcUnmaskViewController::GetSheetTitle() {
}
void CvcUnmaskViewController::FillContentView(views::View* content_view) {
std::unique_ptr<views::GridLayout> layout =
base::MakeUnique<views::GridLayout>(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<views::Button> CvcUnmaskViewController::CreatePrimaryButton() {

@ -251,8 +251,8 @@ std::unique_ptr<views::View> EditorViewController::CreateEditorView() {
constexpr int kShortFieldMinimumWidth = 176;
constexpr int kLongFieldMinimumWidth = 272;
std::unique_ptr<views::GridLayout> editor_layout =
base::MakeUnique<views::GridLayout>(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<views::View> 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<views::View> EditorViewController::CreateEditorView() {
l10n_util::GetStringUTF16(IDS_PAYMENTS_REQUIRED_FIELD_MESSAGE))
.release());
editor_view->SetLayoutManager(editor_layout.release());
return editor_view;
}

@ -57,8 +57,7 @@ std::unique_ptr<views::View> 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<views::View> CreateLineItemView(const base::string16& label,
std::unique_ptr<views::View> amount_wrapper = base::MakeUnique<views::View>();
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<views::View> CreateLineItemView(const base::string16& label,
currency_text->set_id(static_cast<int>(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());

@ -344,8 +344,8 @@ void PaymentRequestDialogView::SetupSpinnerOverlay() {
// would be under it.
throbber_overlay_.SetBackground(views::CreateSolidBackground(SK_ColorWHITE));
std::unique_ptr<views::GridLayout> layout =
base::MakeUnique<views::GridLayout>(&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_);
}

@ -63,8 +63,7 @@ void PaymentRequestItemList::Item::Init() {
std::unique_ptr<views::View> 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);

@ -218,8 +218,7 @@ std::unique_ptr<views::View> 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<views::View> 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<views::View> 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,

@ -184,8 +184,8 @@ std::unique_ptr<views::View> CreateSheetHeaderView(
const base::string16& title,
views::ButtonListener* listener) {
std::unique_ptr<views::View> container = base::MakeUnique<views::View>();
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;

@ -150,7 +150,7 @@ std::unique_ptr<PaymentRequestRowView> CreatePaymentSheetRow(
kPaymentRequestRowVerticalInsets, trailing_inset);
std::unique_ptr<PaymentRequestRowView> row =
base::MakeUnique<PaymentRequestRowView>(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<views::View> CreateInlineCurrencyAmountItem(
bool bold) {
std::unique_ptr<views::View> item_amount_line =
base::MakeUnique<views::View>();
std::unique_ptr<views::GridLayout> item_amount_layout =
base::MakeUnique<views::GridLayout>(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<views::View> 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<PaymentRequestRowView>
PaymentSheetViewController::CreatePaymentSheetSummaryRow() {
std::unique_ptr<views::View> inline_summary = base::MakeUnique<views::View>();
std::unique_ptr<views::GridLayout> layout =
base::MakeUnique<views::GridLayout>(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<views::View> content_view = base::MakeUnique<views::View>();
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,

@ -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.

@ -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.

@ -94,7 +94,7 @@ void ProximityAuthErrorBubbleView::Init() {
// ----------------------------
// | icon | padding | message |
// ----------------------------
std::unique_ptr<views::GridLayout> 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() {}

@ -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);

@ -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);

@ -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;

@ -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);

@ -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,

@ -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;

@ -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;

@ -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;

@ -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);

@ -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,

@ -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,

@ -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);

@ -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);

@ -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);

@ -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);

@ -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<base::string16> 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;

@ -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 =

@ -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);

@ -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,

@ -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,

@ -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"));

@ -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,

@ -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,

@ -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,

@ -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);

@ -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);

@ -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<ui::TableColumn> columns;
columns.push_back(TestTableColumn(0, "Fruit"));

@ -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);

@ -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,

@ -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);

@ -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.

@ -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

@ -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();

@ -326,14 +326,14 @@ DialogClientView::GetButtonRowViews() {
void DialogClientView::SetupLayout() {
base::AutoReset<bool> 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<View*, kNumButtons> views = GetButtonRowViews();