Refactor to use GridLayout::AddView<T>.
Bug: 945335
Change-Id: I44a0f8d7339a045033822a4c09ddef0c9a2fb8c3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1660282
Reviewed-by: Scott Violet <sky@chromium.org>
Reviewed-by: Alexander Alekseev <alemate@chromium.org>
Reviewed-by: Vasilii Sukhanov <vasilii@chromium.org>
Reviewed-by: Allen Bauer <kylixrd@chromium.org>
Reviewed-by: Mihai Sardarescu <msarda@chromium.org>
Reviewed-by: Peter Boström <pbos@chromium.org>
Commit-Queue: Allen Bauer <kylixrd@chromium.org>
Cr-Commit-Position: refs/heads/master@{#670062}
diff --git a/chrome/browser/chromeos/ui/request_pin_view.cc b/chrome/browser/chromeos/ui/request_pin_view.cc
index 2a8d5b4..88feacc 100644
--- a/chrome/browser/chromeos/ui/request_pin_view.cc
+++ b/chrome/browser/chromeos/ui/request_pin_view.cc
@@ -197,9 +197,9 @@
// Infomation label.
int label_text_id = IDS_REQUEST_PIN_DIALOG_HEADER;
base::string16 label_text = l10n_util::GetStringUTF16(label_text_id);
- header_label_ = new views::Label(label_text);
- header_label_->SetEnabled(true);
- layout->AddView(header_label_);
+ auto header_label = std::make_unique<views::Label>(label_text);
+ header_label->SetEnabled(true);
+ header_label_ = layout->AddView(std::move(header_label));
const int related_vertical_spacing =
provider->GetDistanceMetric(views::DISTANCE_RELATED_CONTROL_VERTICAL);
@@ -212,12 +212,13 @@
// Textfield to enter the PIN/PUK.
layout->StartRow(0, column_view_set_id);
- textfield_ = new PassphraseTextfield();
- textfield_->set_controller(this);
- textfield_->SetEnabled(true);
- textfield_->SetAssociatedLabel(header_label_);
- layout->AddView(textfield_, 1, 1, views::GridLayout::LEADING,
- views::GridLayout::FILL, kDefaultTextWidth, 0);
+ auto textfield = std::make_unique<PassphraseTextfield>();
+ textfield->set_controller(this);
+ textfield->SetEnabled(true);
+ textfield->SetAssociatedLabel(header_label_);
+ textfield_ =
+ layout->AddView(std::move(textfield), 1, 1, views::GridLayout::LEADING,
+ views::GridLayout::FILL, kDefaultTextWidth, 0);
layout->AddPaddingRow(0, related_vertical_spacing);
@@ -228,10 +229,10 @@
// Error label.
layout->StartRow(0, column_view_set_id);
- error_label_ = new views::Label();
- error_label_->SetVisible(false);
- error_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
- layout->AddView(error_label_);
+ auto error_label = std::make_unique<views::Label>();
+ error_label->SetVisible(false);
+ error_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
+ error_label_ = layout->AddView(std::move(error_label));
}
void RequestPinView::SetAcceptInput(bool accept_input) {
diff --git a/chrome/browser/ui/ash/network/enrollment_dialog_view.cc b/chrome/browser/ui/ash/network/enrollment_dialog_view.cc
index 0f723cb..4e54afb 100644
--- a/chrome/browser/ui/ash/network/enrollment_dialog_view.cc
+++ b/chrome/browser/ui/ash/network/enrollment_dialog_view.cc
@@ -155,7 +155,7 @@
void EnrollmentDialogView::InitDialog() {
added_cert_ = false;
// Create the views and layout manager and set them up.
- views::Label* label = new views::Label(
+ auto label = std::make_unique<views::Label>(
l10n_util::GetStringFUTF16(IDS_NETWORK_ENROLLMENT_HANDLER_INSTRUCTIONS,
base::UTF8ToUTF16(network_name_)));
label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
@@ -187,7 +187,7 @@
0); // Minimum size.
grid_layout->StartRow(views::GridLayout::kFixedSize, 0);
- grid_layout->AddView(label);
+ grid_layout->AddView(std::move(label));
grid_layout->AddPaddingRow(
views::GridLayout::kFixedSize,
provider->GetDistanceMetric(views::DISTANCE_UNRELATED_CONTROL_VERTICAL));
diff --git a/chrome/browser/ui/views/page_info/chosen_object_view.cc b/chrome/browser/ui/views/page_info/chosen_object_view.cc
index eddac546..ca2da014 100644
--- a/chrome/browser/ui/views/page_info/chosen_object_view.cc
+++ b/chrome/browser/ui/views/page_info/chosen_object_view.cc
@@ -65,27 +65,27 @@
layout->StartRowWithPadding(1.0, column_set_id, views::GridLayout::kFixedSize,
list_item_padding);
// Create the chosen object icon.
- icon_ = new views::ImageView();
- layout->AddView(icon_);
+ icon_ = layout->AddView(std::make_unique<views::ImageView>());
// Create the label that displays the chosen object name.
- views::Label* label = new views::Label(
+ auto label = std::make_unique<views::Label>(
PageInfoUI::ChosenObjectToUIString(*info_), CONTEXT_BODY_TEXT_LARGE);
icon_->SetImage(
PageInfoUI::GetChosenObjectIcon(*info_, false, label->enabled_color()));
- layout->AddView(label);
+ layout->AddView(std::move(label));
// Create the delete button.
- delete_button_ = views::CreateVectorImageButton(this).release();
+ std::unique_ptr<views::ImageButton> delete_button =
+ views::CreateVectorImageButton(this);
views::SetImageFromVectorIcon(
- delete_button_, vector_icons::kCloseRoundedIcon,
+ delete_button.get(), vector_icons::kCloseRoundedIcon,
views::style::GetColor(*this, CONTEXT_BODY_TEXT_LARGE,
views::style::STYLE_PRIMARY));
- delete_button_->SetFocusForPlatform();
- delete_button_->set_request_focus_on_press(true);
- delete_button_->SetTooltipText(
+ delete_button->SetFocusForPlatform();
+ delete_button->set_request_focus_on_press(true);
+ delete_button->SetTooltipText(
l10n_util::GetStringUTF16(info_->ui_info.delete_tooltip_string_id));
- layout->AddView(delete_button_);
+ delete_button_ = layout->AddView(std::move(delete_button));
// Display secondary text underneath the name of the chosen object to describe
// what the chosen object actually is.
@@ -94,14 +94,14 @@
// Disable the delete button for policy controlled objects and display the
// allowed by policy string below for |secondary_label|.
- views::Label* secondary_label = nullptr;
+ std::unique_ptr<views::Label> secondary_label;
if (info_->chooser_object->source ==
content_settings::SettingSource::SETTING_SOURCE_POLICY) {
delete_button_->SetEnabled(false);
- secondary_label = new views::Label(l10n_util::GetStringUTF16(
+ secondary_label = std::make_unique<views::Label>(l10n_util::GetStringUTF16(
info_->ui_info.allowed_by_policy_description_string_id));
} else {
- secondary_label = new views::Label(
+ secondary_label = std::make_unique<views::Label>(
l10n_util::GetStringUTF16(info_->ui_info.description_string_id));
}
@@ -114,11 +114,11 @@
int preferred_width = secondary_label->GetPreferredSize().width();
constexpr int kMaxSecondaryLabelWidth = 140;
if (preferred_width > kMaxSecondaryLabelWidth) {
- layout->AddView(secondary_label, /*col_span=*/1, /*row_span=*/1,
+ layout->AddView(std::move(secondary_label), /*col_span=*/1, /*row_span=*/1,
views::GridLayout::LEADING, views::GridLayout::CENTER,
kMaxSecondaryLabelWidth, /*pref_height=*/0);
} else {
- layout->AddView(secondary_label, /*col_span=*/1, /*row_span=*/1,
+ layout->AddView(std::move(secondary_label), /*col_span=*/1, /*row_span=*/1,
views::GridLayout::FILL, views::GridLayout::CENTER);
}
diff --git a/chrome/browser/ui/views/page_info/page_info_bubble_view.cc b/chrome/browser/ui/views/page_info/page_info_bubble_view.cc
index f16f4a1f..fc55d5a 100644
--- a/chrome/browser/ui/views/page_info/page_info_bubble_view.cc
+++ b/chrome/browser/ui/views/page_info/page_info_bubble_view.cc
@@ -247,31 +247,34 @@
layout->StartRow(views::GridLayout::kFixedSize, label_column_status);
- security_details_label_ =
- new views::StyledLabel(base::string16(), styled_label_listener);
- security_details_label_->SetID(
+ auto security_details_label = std::make_unique<views::StyledLabel>(
+ base::string16(), styled_label_listener);
+ security_details_label->SetID(
PageInfoBubbleView::VIEW_ID_PAGE_INFO_LABEL_SECURITY_DETAILS);
- layout->AddView(security_details_label_, 1.0, 1.0, views::GridLayout::FILL,
- views::GridLayout::LEADING);
+ security_details_label_ =
+ layout->AddView(std::move(security_details_label), 1.0, 1.0,
+ views::GridLayout::FILL, views::GridLayout::LEADING);
layout->StartRow(views::GridLayout::kFixedSize, label_column_status);
- ev_certificate_label_container_ = new views::View();
- ev_certificate_label_container_->SetLayoutManager(
+ auto ev_certificate_label_container = std::make_unique<views::View>();
+ ev_certificate_label_container->SetLayoutManager(
std::make_unique<views::BoxLayout>(views::BoxLayout::kHorizontal));
- layout->AddView(ev_certificate_label_container_, 1.0, 1.0,
- views::GridLayout::FILL, views::GridLayout::LEADING);
+ ev_certificate_label_container_ =
+ layout->AddView(std::move(ev_certificate_label_container), 1.0, 1.0,
+ views::GridLayout::FILL, views::GridLayout::LEADING);
layout->StartRow(views::GridLayout::kFixedSize, label_column_status);
- reset_decisions_label_container_ = new views::View();
- reset_decisions_label_container_->SetLayoutManager(
+ auto reset_decisions_label_container = std::make_unique<views::View>();
+ reset_decisions_label_container->SetLayoutManager(
std::make_unique<views::BoxLayout>(views::BoxLayout::kHorizontal));
- layout->AddView(reset_decisions_label_container_, 1.0, 1.0,
- views::GridLayout::FILL, views::GridLayout::LEADING);
+ reset_decisions_label_container_ =
+ layout->AddView(std::move(reset_decisions_label_container), 1.0, 1.0,
+ views::GridLayout::FILL, views::GridLayout::LEADING);
layout->StartRow(views::GridLayout::kFixedSize, label_column_status);
- password_reuse_button_container_ = new views::View();
- layout->AddView(password_reuse_button_container_, 1, 1,
- views::GridLayout::FILL, views::GridLayout::LEADING);
+ password_reuse_button_container_ =
+ layout->AddView(std::make_unique<views::View>(), 1, 1,
+ views::GridLayout::FILL, views::GridLayout::LEADING);
}
BubbleHeaderView::~BubbleHeaderView() {}
@@ -539,32 +542,29 @@
views::GridLayout::USE_PREF, 0, 0);
layout->StartRow(views::GridLayout::kFixedSize, kColumnId);
- header_ = new BubbleHeaderView(this, this, side_margin);
- layout->AddView(header_);
+ header_ = layout->AddView(
+ std::make_unique<BubbleHeaderView>(this, this, side_margin));
layout->StartRow(views::GridLayout::kFixedSize, kColumnId);
- permissions_view_ = new views::View;
- layout->AddView(permissions_view_);
+ permissions_view_ = layout->AddView(std::make_unique<views::View>());
layout->StartRow(views::GridLayout::kFixedSize, kColumnId);
- layout->AddView(new views::Separator());
+ layout->AddView(std::make_unique<views::Separator>());
layout->StartRowWithPadding(views::GridLayout::kFixedSize, kColumnId,
views::GridLayout::kFixedSize,
hover_list_spacing);
- site_settings_view_ = CreateSiteSettingsView();
- layout->AddView(site_settings_view_);
+ site_settings_view_ = layout->AddView(CreateSiteSettingsView());
if (!profile->IsGuestSession()) {
layout->StartRowWithPadding(views::GridLayout::kFixedSize, kColumnId,
views::GridLayout::kFixedSize, 0);
- layout->AddView(CreateSiteSettingsLink(side_margin, this).release());
+ layout->AddView(CreateSiteSettingsLink(side_margin, this));
}
#if defined(OS_WIN) && BUILDFLAG(ENABLE_VR)
layout->StartRow(views::GridLayout::kFixedSize, kColumnId);
- page_feature_info_view_ = new views::View;
- layout->AddView(page_feature_info_view_);
+ page_feature_info_view_ = layout->AddView(std::make_unique<views::View>());
#endif
views::BubbleDialogDelegateView::CreateBubble(this);
@@ -789,7 +789,7 @@
// The view takes ownership of the object info.
auto object_view = std::make_unique<ChosenObjectView>(std::move(object));
object_view->AddObserver(this);
- layout->AddView(object_view.release());
+ layout->AddView(std::move(object_view));
}
layout->AddPaddingRow(views::GridLayout::kFixedSize, list_item_padding);
@@ -1002,8 +1002,8 @@
}
#endif
-views::View* PageInfoBubbleView::CreateSiteSettingsView() {
- views::View* site_settings_view = new views::View();
+std::unique_ptr<views::View> PageInfoBubbleView::CreateSiteSettingsView() {
+ auto site_settings_view = std::make_unique<views::View>();
auto* box_layout = site_settings_view->SetLayoutManager(
std::make_unique<views::BoxLayout>(views::BoxLayout::kVertical));
box_layout->set_cross_axis_alignment(
diff --git a/chrome/browser/ui/views/page_info/page_info_bubble_view.h b/chrome/browser/ui/views/page_info/page_info_bubble_view.h
index 385c0fa..d1f8f8a 100644
--- a/chrome/browser/ui/views/page_info/page_info_bubble_view.h
+++ b/chrome/browser/ui/views/page_info/page_info_bubble_view.h
@@ -159,7 +159,7 @@
// Creates the contents of the |site_settings_view_|. The ownership of the
// returned view is transferred to the caller.
- views::View* CreateSiteSettingsView() WARN_UNUSED_RESULT;
+ std::unique_ptr<views::View> CreateSiteSettingsView() WARN_UNUSED_RESULT;
// Posts a task to HandleMoreInfoRequestAsync() below.
void HandleMoreInfoRequest(views::View* source);
diff --git a/chrome/browser/ui/views/page_info/permission_selector_row.cc b/chrome/browser/ui/views/page_info/permission_selector_row.cc
index ed0449d..cf67130 100644
--- a/chrome/browser/ui/views/page_info/permission_selector_row.cc
+++ b/chrome/browser/ui/views/page_info/permission_selector_row.cc
@@ -167,15 +167,14 @@
views::GridLayout::kFixedSize, list_item_padding);
// Create the permission icon and label.
- icon_ = new NonAccessibleImageView();
- layout->AddView(icon_);
+ icon_ = layout->AddView(std::make_unique<NonAccessibleImageView>());
// Create the label that displays the permission type.
- label_ =
- new views::Label(PageInfoUI::PermissionTypeToUIString(permission.type),
- CONTEXT_BODY_TEXT_LARGE);
+ auto label = std::make_unique<views::Label>(
+ PageInfoUI::PermissionTypeToUIString(permission.type),
+ CONTEXT_BODY_TEXT_LARGE);
icon_->SetImage(
- PageInfoUI::GetPermissionIcon(permission, label_->enabled_color()));
- layout->AddView(label_);
+ PageInfoUI::GetPermissionIcon(permission, label->enabled_color()));
+ label_ = layout->AddView(std::move(label));
// Create the menu model.
menu_model_.reset(new PermissionMenuModel(
profile, url, permission,
@@ -191,7 +190,7 @@
if (!reason.empty()) {
layout->StartRow(1.0, PageInfoBubbleView::kPermissionColumnSetId);
layout->SkipColumns(1);
- views::Label* secondary_label = new views::Label(reason);
+ auto secondary_label = std::make_unique<views::Label>(reason);
secondary_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
secondary_label->SetEnabledColor(PageInfoUI::GetSecondaryTextColor());
// The |secondary_label| should wrap when it's too long instead of
@@ -212,11 +211,11 @@
// display.
constexpr int kMaxSecondaryLabelWidth = 140;
if (preferred_width > kMaxSecondaryLabelWidth) {
- layout->AddView(secondary_label, column_span, 1.0,
+ layout->AddView(std::move(secondary_label), column_span, 1.0,
views::GridLayout::LEADING, views::GridLayout::CENTER,
kMaxSecondaryLabelWidth, 0);
} else {
- layout->AddView(secondary_label, column_span, 1.0,
+ layout->AddView(std::move(secondary_label), column_span, 1.0,
views::GridLayout::FILL, views::GridLayout::CENTER);
}
}
@@ -272,13 +271,13 @@
permission.source == content_settings::SETTING_SOURCE_USER;
combobox_model_adapter_.reset(
new internal::ComboboxModelAdapter(menu_model_.get()));
- combobox_ = new internal::PermissionCombobox(combobox_model_adapter_.get(),
- button_enabled, true);
- combobox_->SetEnabled(button_enabled);
- combobox_->SetTooltipText(l10n_util::GetStringFUTF16(
+ auto combobox = std::make_unique<internal::PermissionCombobox>(
+ combobox_model_adapter_.get(), button_enabled, true);
+ combobox->SetEnabled(button_enabled);
+ combobox->SetTooltipText(l10n_util::GetStringFUTF16(
IDS_PAGE_INFO_SELECTOR_TOOLTIP,
PageInfoUI::PermissionTypeToUIString(permission.type)));
- layout->AddView(combobox_);
+ combobox_ = layout->AddView(std::move(combobox));
}
void PermissionSelectorRow::PermissionChanged(
diff --git a/chrome/browser/ui/views/passwords/password_generation_popup_view_views.cc b/chrome/browser/ui/views/passwords/password_generation_popup_view_views.cc
index b1afc55..d0bd4a3 100644
--- a/chrome/browser/ui/views/passwords/password_generation_popup_view_views.cc
+++ b/chrome/browser/ui/views/passwords/password_generation_popup_view_views.cc
@@ -50,20 +50,17 @@
BuildColumnSet(layout);
layout->StartRow(views::GridLayout::kFixedSize, 0);
- layout->AddView(
- autofill::CreateLabelWithColorReadabilityDisabled(
- suggestion, ChromeTextContext::CONTEXT_BODY_TEXT_LARGE,
- state == PasswordGenerationPopupController::kOfferGeneration
- ? views::style::STYLE_PRIMARY
- : STYLE_SECONDARY)
- .release());
+ layout->AddView(autofill::CreateLabelWithColorReadabilityDisabled(
+ suggestion, ChromeTextContext::CONTEXT_BODY_TEXT_LARGE,
+ state == PasswordGenerationPopupController::kOfferGeneration
+ ? views::style::STYLE_PRIMARY
+ : STYLE_SECONDARY));
DCHECK(!password_label_);
- password_label_ = autofill::CreateLabelWithColorReadabilityDisabled(
- password, ChromeTextContext::CONTEXT_BODY_TEXT_LARGE,
- STYLE_SECONDARY_MONOSPACED)
- .release();
- layout->AddView(password_label_);
+ password_label_ =
+ layout->AddView(autofill::CreateLabelWithColorReadabilityDisabled(
+ password, ChromeTextContext::CONTEXT_BODY_TEXT_LARGE,
+ STYLE_SECONDARY_MONOSPACED));
}
void UpdatePassword(const base::string16& password) {
diff --git a/chrome/browser/ui/views/passwords/password_items_view.cc b/chrome/browser/ui/views/passwords/password_items_view.cc
index ea90533..66ac926 100644
--- a/chrome/browser/ui/views/passwords/password_items_view.cc
+++ b/chrome/browser/ui/views/passwords/password_items_view.cc
@@ -204,8 +204,8 @@
CreateUndoButton(this, GetDisplayUsername(*password_form_));
StartRow(layout, UNDO_COLUMN_SET);
- layout->AddView(text.release());
- layout->AddView(undo_button.release());
+ layout->AddView(std::move(text));
+ layout->AddView(std::move(undo_button));
}
void PasswordItemsView::PasswordRow::AddPasswordRow(views::GridLayout* layout) {
@@ -216,9 +216,9 @@
std::unique_ptr<views::ImageButton> delete_button =
CreateDeleteButton(this, GetDisplayUsername(*password_form_));
StartRow(layout, PASSWORD_COLUMN_SET);
- layout->AddView(username_label.release());
- layout->AddView(password_label.release());
- layout->AddView(delete_button.release());
+ layout->AddView(std::move(username_label));
+ layout->AddView(std::move(password_label));
+ layout->AddView(std::move(delete_button));
}
void PasswordItemsView::PasswordRow::ButtonPressed(views::Button* sender,
diff --git a/chrome/browser/ui/views/passwords/password_pending_view.cc b/chrome/browser/ui/views/passwords/password_pending_view.cc
index 24b4227..fb92ff9 100644
--- a/chrome/browser/ui/views/passwords/password_pending_view.cc
+++ b/chrome/browser/ui/views/passwords/password_pending_view.cc
@@ -91,10 +91,11 @@
// |password_view_button| is an optional field. If it is a nullptr, a
// DOUBLE_VIEW_COLUMN_SET_PASSWORD will be used for password row instead of
// TRIPLE_VIEW_COLUMN_SET.
-void BuildCredentialRows(views::GridLayout* layout,
- views::View* username_field,
- views::View* password_field,
- views::ToggleImageButton* password_view_button) {
+void BuildCredentialRows(
+ views::GridLayout* layout,
+ std::unique_ptr<views::View> username_field,
+ std::unique_ptr<views::View> password_field,
+ std::unique_ptr<views::ToggleImageButton> password_view_button) {
// Username row.
BuildColumnSet(layout, DOUBLE_VIEW_COLUMN_SET_USERNAME);
layout->StartRow(views::GridLayout::kFixedSize,
@@ -112,9 +113,9 @@
int fields_height = std::max(username_field->GetPreferredSize().height(),
password_field->GetPreferredSize().height());
- layout->AddView(username_label.release(), 1, 1, views::GridLayout::LEADING,
+ layout->AddView(std::move(username_label), 1, 1, views::GridLayout::LEADING,
views::GridLayout::FILL, labels_width, 0);
- layout->AddView(username_field, 1, 1, views::GridLayout::FILL,
+ layout->AddView(std::move(username_field), 1, 1, views::GridLayout::FILL,
views::GridLayout::FILL, 0, fields_height);
layout->AddPaddingRow(views::GridLayout::kFixedSize,
@@ -127,13 +128,13 @@
: DOUBLE_VIEW_COLUMN_SET_PASSWORD;
BuildColumnSet(layout, type);
layout->StartRow(views::GridLayout::kFixedSize, type);
- layout->AddView(password_label.release(), 1, 1, views::GridLayout::LEADING,
+ layout->AddView(std::move(password_label), 1, 1, views::GridLayout::LEADING,
views::GridLayout::FILL, labels_width, 0);
- layout->AddView(password_field, 1, 1, views::GridLayout::FILL,
+ layout->AddView(std::move(password_field), 1, 1, views::GridLayout::FILL,
views::GridLayout::FILL, 0, fields_height);
// The eye icon is also added to the layout if it was passed.
if (password_view_button) {
- layout->AddView(password_view_button);
+ layout->AddView(std::move(password_view_button));
}
}
@@ -230,22 +231,25 @@
credential_view->SetEnabled(false);
AddChildView(credential_view);
} else {
- username_dropdown_ =
- CreateUsernameEditableCombobox(password_form).release();
- username_dropdown_->set_listener(this);
- password_dropdown_ =
- CreatePasswordEditableCombobox(password_form, are_passwords_revealed_)
- .release();
- password_dropdown_->set_listener(this);
+ std::unique_ptr<views::EditableCombobox> username_dropdown =
+ CreateUsernameEditableCombobox(password_form);
+ username_dropdown->set_listener(this);
+ std::unique_ptr<views::EditableCombobox> password_dropdown =
+ CreatePasswordEditableCombobox(password_form, are_passwords_revealed_);
+ password_dropdown->set_listener(this);
- password_view_button_ =
- CreatePasswordViewButton(this, are_passwords_revealed_).release();
+ std::unique_ptr<views::ToggleImageButton> password_view_button =
+ CreatePasswordViewButton(this, are_passwords_revealed_);
views::GridLayout* layout =
SetLayoutManager(std::make_unique<views::GridLayout>());
- BuildCredentialRows(layout, username_dropdown_, password_dropdown_,
- password_view_button_);
+ username_dropdown_ = username_dropdown.get();
+ password_dropdown_ = password_dropdown.get();
+ password_view_button_ = password_view_button.get();
+ BuildCredentialRows(layout, std::move(username_dropdown),
+ std::move(password_dropdown),
+ std::move(password_view_button));
}
}
diff --git a/chrome/browser/ui/views/policy/enterprise_startup_dialog_view.cc b/chrome/browser/ui/views/policy/enterprise_startup_dialog_view.cc
index 30b2e2f..66ebda7a 100644
--- a/chrome/browser/ui/views/policy/enterprise_startup_dialog_view.cc
+++ b/chrome/browser/ui/views/policy/enterprise_startup_dialog_view.cc
@@ -4,7 +4,6 @@
#include "chrome/browser/ui/views/policy/enterprise_startup_dialog_view.h"
-#include <memory>
#include <utility>
#include "base/bind.h"
@@ -53,8 +52,8 @@
views::CONTROL, views::TEXT);
}
-views::Label* CreateText(const base::string16& message) {
- views::Label* text = new views::Label(message);
+std::unique_ptr<views::Label> CreateText(const base::string16& message) {
+ auto text = std::make_unique<views::Label>(message);
text->SetFontList(gfx::FontList().Derive(kFontSizeDelta, gfx::Font::NORMAL,
gfx::Font::Weight::MEDIUM));
text->SetEnabledColor(gfx::kGoogleGrey700);
@@ -67,7 +66,6 @@
EnterpriseStartupDialogView::EnterpriseStartupDialogView(
EnterpriseStartupDialog::DialogResultCallback callback)
: callback_(std::move(callback)),
- can_show_browser_window_(false),
weak_factory_(this) {
SetBorder(views::CreateEmptyBorder(GetDialogInsets()));
CreateDialogWidget(this, nullptr, nullptr)->Show();
@@ -84,27 +82,27 @@
const base::string16& information) {
ResetDialog(false);
- views::Label* text = CreateText(information);
- views::Throbber* throbber = new views::Throbber();
+ std::unique_ptr<views::Label> text = CreateText(information);
+ auto throbber = std::make_unique<views::Throbber>();
gfx::Size throbber_size = gfx::Size(kIconSize, kIconSize);
throbber->SetPreferredSize(throbber_size);
throbber->Start();
- SetupLayout(throbber, text);
+ SetupLayout(std::move(throbber), std::move(text));
}
void EnterpriseStartupDialogView::DisplayErrorMessage(
const base::string16& error_message,
const base::Optional<base::string16>& accept_button) {
ResetDialog(accept_button.has_value());
- views::Label* text = CreateText(error_message);
- views::ImageView* error_icon = new views::ImageView();
+ std::unique_ptr<views::Label> text = CreateText(error_message);
+ auto error_icon = std::make_unique<views::ImageView>();
error_icon->SetImage(gfx::CreateVectorIcon(kBrowserToolsErrorIcon, kIconSize,
gfx::kGoogleRed700));
if (accept_button)
GetDialogClientView()->ok_button()->SetText(*accept_button);
- SetupLayout(error_icon, text);
+ SetupLayout(std::move(error_icon), std::move(text));
}
void EnterpriseStartupDialogView::CloseDialog() {
@@ -204,8 +202,9 @@
RemoveAllChildViews(true);
}
-void EnterpriseStartupDialogView::SetupLayout(views::View* icon,
- views::View* text) {
+void EnterpriseStartupDialogView::SetupLayout(
+ std::unique_ptr<views::View> icon,
+ std::unique_ptr<views::View> text) {
// Padding between icon and text
int text_padding = ChromeLayoutProvider::Get()->GetDistanceMetric(
views::DISTANCE_TEXTFIELD_HORIZONTAL_TEXT_PADDING);
@@ -226,8 +225,8 @@
layout->AddPaddingRow(1.0, 0);
layout->StartRow(views::GridLayout::kFixedSize, 0);
- layout->AddView(icon);
- layout->AddView(text);
+ layout->AddView(std::move(icon));
+ layout->AddView(std::move(text));
layout->AddPaddingRow(1.0, 0);
GetDialogClientView()->Layout();
diff --git a/chrome/browser/ui/views/policy/enterprise_startup_dialog_view.h b/chrome/browser/ui/views/policy/enterprise_startup_dialog_view.h
index 9a1a4f0..8950ce1 100644
--- a/chrome/browser/ui/views/policy/enterprise_startup_dialog_view.h
+++ b/chrome/browser/ui/views/policy/enterprise_startup_dialog_view.h
@@ -5,6 +5,7 @@
#ifndef CHROME_BROWSER_UI_VIEWS_POLICY_ENTERPRISE_STARTUP_DIALOG_VIEW_H_
#define CHROME_BROWSER_UI_VIEWS_POLICY_ENTERPRISE_STARTUP_DIALOG_VIEW_H_
+#include <memory>
#include <string>
#include "base/callback_forward.h"
@@ -58,10 +59,11 @@
// Remove all existing child views from the dialog, show/hide dialog buttons.
void ResetDialog(bool show_accept_button);
// Append child views to the content area, setup the layout.
- void SetupLayout(views::View* icon, views::View* text);
+ void SetupLayout(std::unique_ptr<views::View> icon,
+ std::unique_ptr<views::View> text);
EnterpriseStartupDialog::DialogResultCallback callback_;
- bool can_show_browser_window_;
+ bool can_show_browser_window_ = false;
base::WeakPtrFactory<EnterpriseStartupDialogView> weak_factory_;
diff --git a/chrome/browser/ui/views/profiles/profile_menu_view_base.cc b/chrome/browser/ui/views/profiles/profile_menu_view_base.cc
index 14ffd0342..c69cb2c 100644
--- a/chrome/browser/ui/views/profiles/profile_menu_view_base.cc
+++ b/chrome/browser/ui/views/profiles/profile_menu_view_base.cc
@@ -408,7 +408,7 @@
views::GridLayout::kFixedSize, views::GridLayout::FIXED,
menu_width_, menu_width_);
layout->StartRow(1.0, 0);
- layout->AddView(scroll_view.release());
+ layout->AddView(std::move(scroll_view));
if (GetBubbleFrameView()) {
SizeToContents();
// SizeToContents() will perform a layout, but only if the size changed.
diff --git a/chrome/browser/ui/views/sync/dice_signin_button_view.cc b/chrome/browser/ui/views/sync/dice_signin_button_view.cc
index 5a0230d..ec756b94 100644
--- a/chrome/browser/ui/views/sync/dice_signin_button_view.cc
+++ b/chrome/browser/ui/views/sync/dice_signin_button_view.cc
@@ -63,26 +63,26 @@
use_account_name_as_title
? base::UTF8ToUTF16(account.full_name)
: l10n_util::GetStringUTF16(IDS_PROFILES_DICE_NOT_SYNCING_TITLE);
- HoverButton* account_card =
- new HoverButton(button_listener, std::move(account_icon_view), card_title,
- base::ASCIIToUTF16(account_->email));
+ auto account_card = std::make_unique<HoverButton>(
+ button_listener, std::move(account_icon_view), card_title,
+ base::ASCIIToUTF16(account_->email));
account_card->SetBorder(nullptr);
account_card->SetEnabled(false);
- grid_layout->AddView(account_card);
+ grid_layout->AddView(std::move(account_card));
if (show_drop_down_arrow) {
// Add a non-stretching column for the the drop down arrow.
columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::FILL,
views::GridLayout::kFixedSize,
views::GridLayout::USE_PREF, 0, 0);
- arrow_ = new HoverButton(
+ auto arrow = std::make_unique<HoverButton>(
button_listener,
gfx::CreateVectorIcon(kSigninButtonDropDownArrowIcon,
kDropDownArrowIconSize, SK_ColorBLACK),
base::string16());
- arrow_->SetTooltipText(l10n_util::GetStringUTF16(
+ arrow->SetTooltipText(l10n_util::GetStringUTF16(
IDS_PROFILES_DICE_SIGNIN_WITH_ANOTHER_ACCOUNT_BUTTON));
- grid_layout->AddView(arrow_);
+ arrow_ = grid_layout->AddView(std::move(arrow));
}
grid_layout->AddPaddingRow(views::GridLayout::kFixedSize, 16);
@@ -92,12 +92,10 @@
// Add a stretching column for the sign in button.
columns->AddColumn(views::GridLayout::FILL, views::GridLayout::TRAILING, 1.0,
views::GridLayout::USE_PREF, 0, 0);
- auto button = views::MdTextButton::Create(
- button_listener,
- l10n_util::GetStringUTF16(IDS_PROFILES_DICE_SIGNIN_BUTTON));
- button->SetProminent(true);
- grid_layout->AddView(button.get());
- signin_button_ = button.release();
+ signin_button_ =
+ grid_layout->AddView(views::MdTextButton::CreateSecondaryUiBlueButton(
+ button_listener,
+ l10n_util::GetStringUTF16(IDS_PROFILES_DICE_SIGNIN_BUTTON)));
}
DiceSigninButtonView::~DiceSigninButtonView() = default;
diff --git a/chrome/browser/ui/views/sync/one_click_signin_dialog_view.cc b/chrome/browser/ui/views/sync/one_click_signin_dialog_view.cc
index bc1f90a6..ad1f705 100644
--- a/chrome/browser/ui/views/sync/one_click_signin_dialog_view.cc
+++ b/chrome/browser/ui/views/sync/one_click_signin_dialog_view.cc
@@ -96,20 +96,22 @@
layout->StartRow(views::GridLayout::kFixedSize, 0);
- views::Label* label = new views::Label(l10n_util::GetStringFUTF16(
+ auto label = std::make_unique<views::Label>(l10n_util::GetStringFUTF16(
IDS_ONE_CLICK_SIGNIN_DIALOG_MESSAGE_NEW, email_));
label->SetMultiLine(true);
label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
label->SizeToFit(kMinimumDialogLabelWidth);
- layout->AddView(label);
+ layout->AddView(std::move(label));
layout->StartRow(views::GridLayout::kFixedSize, 0);
- learn_more_link_ = new views::Link(l10n_util::GetStringUTF16(IDS_LEARN_MORE));
- learn_more_link_->set_listener(this);
- learn_more_link_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
- layout->AddView(learn_more_link_, 1, 1, views::GridLayout::TRAILING,
- views::GridLayout::CENTER);
+ auto learn_more_link =
+ std::make_unique<views::Link>(l10n_util::GetStringUTF16(IDS_LEARN_MORE));
+ learn_more_link->set_listener(this);
+ learn_more_link->SetHorizontalAlignment(gfx::ALIGN_LEFT);
+ learn_more_link_ =
+ layout->AddView(std::move(learn_more_link), 1, 1,
+ views::GridLayout::TRAILING, views::GridLayout::CENTER);
}
base::string16 OneClickSigninDialogView::GetWindowTitle() const {
diff --git a/chrome/browser/ui/views/sync/profile_signin_confirmation_dialog_views.cc b/chrome/browser/ui/views/sync/profile_signin_confirmation_dialog_views.cc
index 476d819..246e943 100644
--- a/chrome/browser/ui/views/sync/profile_signin_confirmation_dialog_views.cc
+++ b/chrome/browser/ui/views/sync/profile_signin_confirmation_dialog_views.cc
@@ -156,7 +156,7 @@
// Create business icon.
int business_icon_size = 20;
- views::ImageView* business_icon = new views::ImageView();
+ auto business_icon = std::make_unique<views::ImageView>();
business_icon->SetImage(gfx::CreateVectorIcon(gfx::IconDescription(
vector_icons::kBusinessIcon, business_icon_size, gfx::kChromeIconGrey,
base::TimeDelta(), gfx::kNoneIcon)));
@@ -170,7 +170,7 @@
l10n_util::GetStringFUTF16(
IDS_ENTERPRISE_SIGNIN_ALERT,
domain, &offset);
- views::StyledLabel* prompt_label = new views::StyledLabel(prompt_text, this);
+ auto prompt_label = std::make_unique<views::StyledLabel>(prompt_text, this);
prompt_label->SetDisplayedOnBackgroundColor(kPromptBarBackgroundColor);
views::StyledLabel::RangeStyleInfo bold_style;
@@ -179,7 +179,7 @@
gfx::Range(offset, offset + domain.size()), bold_style);
// Create the prompt bar.
- views::View* prompt_bar = new views::View;
+ auto prompt_bar = std::make_unique<views::View>();
prompt_bar->SetBorder(views::CreateSolidSidedBorder(
1, 0, 1, 0,
ui::GetSigninConfirmationPromptBarColor(GetNativeTheme(), 0x1F)));
@@ -195,8 +195,8 @@
IDS_ENTERPRISE_SIGNIN_EXPLANATION_WITH_PROFILE_CREATION :
IDS_ENTERPRISE_SIGNIN_EXPLANATION_WITHOUT_PROFILE_CREATION,
username, learn_more_text, &offsets);
- views::StyledLabel* explanation_label =
- new views::StyledLabel(signin_explanation_text, this);
+ auto explanation_label =
+ std::make_unique<views::StyledLabel>(signin_explanation_text, this);
explanation_label->AddStyleRange(
gfx::Range(offsets[1], offsets[1] + learn_more_text.size()),
views::StyledLabel::RangeStyleInfo::CreateForLink());
@@ -232,17 +232,16 @@
views::GridLayout::USE_PREF, 0, 0);
prompt_layout->StartRow(views::GridLayout::kFixedSize, kPromptBarColumnSetId);
- prompt_layout->AddView(business_icon);
- prompt_layout->AddView(prompt_label);
+ prompt_layout->AddView(std::move(business_icon));
+ prompt_layout->AddView(std::move(prompt_label));
// Use a column set with no padding.
dialog_layout->AddColumnSet(0)->AddColumn(views::GridLayout::FILL,
views::GridLayout::FILL, 1.0,
views::GridLayout::USE_PREF, 0, 0);
dialog_layout->StartRow(views::GridLayout::kFixedSize, 0);
- dialog_layout->AddView(
- prompt_bar, 1, 1,
- views::GridLayout::FILL, views::GridLayout::FILL, 0, 0);
+ dialog_layout->AddView(std::move(prompt_bar), 1, 1, views::GridLayout::FILL,
+ views::GridLayout::FILL, 0, 0);
// Use a new column set for the explanation label so we can add padding.
dialog_layout->AddPaddingRow(views::GridLayout::kFixedSize,
@@ -260,9 +259,11 @@
dialog_layout->StartRow(views::GridLayout::kFixedSize,
kExplanationColumnSetId);
const int kPreferredWidth = 440;
- dialog_layout->AddView(explanation_label, 1, 1, views::GridLayout::FILL,
- views::GridLayout::FILL, kPreferredWidth,
- explanation_label->GetHeightForWidth(kPreferredWidth));
+ int explanation_label_height =
+ explanation_label->GetHeightForWidth(kPreferredWidth);
+ dialog_layout->AddView(std::move(explanation_label), 1, 1,
+ views::GridLayout::FILL, views::GridLayout::FILL,
+ kPreferredWidth, explanation_label_height);
}
void ProfileSigninConfirmationDialogViews::WindowClosing() {
diff --git a/chrome/browser/ui/views/try_chrome_dialog_win/try_chrome_dialog.cc b/chrome/browser/ui/views/try_chrome_dialog_win/try_chrome_dialog.cc
index 6d47ae8..cca4fae 100644
--- a/chrome/browser/ui/views/try_chrome_dialog_win/try_chrome_dialog.cc
+++ b/chrome/browser/ui/views/try_chrome_dialog_win/try_chrome_dialog.cc
@@ -1121,9 +1121,8 @@
views::Button::STATE_NORMAL,
gfx::CreateVectorIcon(kInactiveToastCloseIcon, kBodyColor));
close_button->set_tag(static_cast<int>(ButtonTag::CLOSE_BUTTON));
- close_button_ = close_button.get();
DCHECK_EQ(close_button->GetPreferredSize().width(), kCloseButtonWidth);
- layout->AddView(close_button.release(), 1, 2);
+ close_button_ = layout->AddView(std::move(close_button), 1, 2);
close_button_->SetVisible(false);
} else {
layout->SkipColumns(1);
@@ -1131,7 +1130,7 @@
// Second row.
layout->StartRow(views::GridLayout::kFixedSize, 0);
- layout->AddView(logo.release());
+ layout->AddView(std::move(logo));
// All variants have a main header.
auto header = std::make_unique<views::Label>(
l10n_util::GetStringUTF16(kExperiments[group_].heading_id),
@@ -1140,7 +1139,7 @@
header->SetEnabledColor(kHeaderColor);
header->SetMultiLine(true);
header->SetHorizontalAlignment(gfx::ALIGN_LEFT);
- layout->AddView(header.release());
+ layout->AddView(std::move(header));
layout->SkipColumns(1);
// Third row: May have text or may be blank.
@@ -1153,7 +1152,7 @@
body_text->SetEnabledColor(kBodyColor);
body_text->SetMultiLine(true);
body_text->SetHorizontalAlignment(gfx::ALIGN_LEFT);
- layout->AddView(body_text.release());
+ layout->AddView(std::move(body_text));
}
// Fourth row: one or two buttons depending on group.
@@ -1179,10 +1178,10 @@
this, l10n_util::GetStringUTF16(IDS_WIN10_TOAST_NO_THANKS),
TryChromeButtonType::NO_THANKS);
no_thanks_button->set_tag(static_cast<int>(ButtonTag::NO_THANKS_BUTTON));
- buttons->AddChildView(no_thanks_button.release());
+ buttons->AddChildView(std::move(no_thanks_button));
}
- layout->AddView(buttons.release());
+ layout->AddView(std::move(buttons));
layout->AddPaddingRow(views::GridLayout::kFixedSize,
kTextButtonPadding - kTryChromeBorderThickness);
diff --git a/chrome/browser/ui/views/webauthn/authenticator_client_pin_entry_view.cc b/chrome/browser/ui/views/webauthn/authenticator_client_pin_entry_view.cc
index d8f17a20..d8d6948d 100644
--- a/chrome/browser/ui/views/webauthn/authenticator_client_pin_entry_view.cc
+++ b/chrome/browser/ui/views/webauthn/authenticator_client_pin_entry_view.cc
@@ -65,8 +65,7 @@
views::style::CONTEXT_LABEL, views::style::STYLE_PRIMARY);
pin_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
pin_label->SetEnabledColor(gfx::kGoogleBlue500);
- auto* pin_label_ptr = pin_label.get();
- layout->AddView(pin_label.release());
+ auto* pin_label_ptr = layout->AddView(std::move(pin_label));
views::View* confirmation_label_ptr = nullptr;
if (show_confirmation_text_field_) {
@@ -76,21 +75,19 @@
confirmation_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
confirmation_label->SetEnabledColor(gfx::kGoogleBlue500);
confirmation_label_ptr = confirmation_label.get();
- layout->AddView(confirmation_label.release());
+ layout->AddView(std::move(confirmation_label));
}
layout->StartRow(views::GridLayout::kFixedSize, 0);
- auto pin_text_field = MakePinTextField(this, pin_label_ptr);
- pin_text_field_ = pin_text_field.get();
- layout->AddView(pin_text_field.release());
+ pin_text_field_ = layout->AddView(MakePinTextField(this, pin_label_ptr));
if (show_confirmation_text_field_) {
DCHECK(confirmation_label_ptr);
auto confirmation_text_field =
MakePinTextField(this, confirmation_label_ptr);
confirmation_text_field_ = confirmation_text_field.get();
- layout->AddView(confirmation_text_field.release());
+ layout->AddView(std::move(confirmation_text_field));
}
layout->StartRow(views::GridLayout::kFixedSize, 0);
@@ -100,8 +97,8 @@
views::style::STYLE_PRIMARY);
error_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
error_label->SetEnabledColor(gfx::kGoogleRed500);
- error_label_ = error_label.get();
- layout->AddView(error_label.release(), 3 /* col_span */, 1 /* row_span */);
+ error_label_ = layout->AddView(std::move(error_label), 3 /* col_span */,
+ 1 /* row_span */);
}
AuthenticatorClientPinEntryView::~AuthenticatorClientPinEntryView() = default;