Commit 11b71811 authored by Allen Bauer's avatar Allen Bauer Committed by Commit Bot

Refactor to use GridLayout::AddView<T>.

Bug: 945335
Change-Id: I44a0f8d7339a045033822a4c09ddef0c9a2fb8c3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1660282Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarAlexander Alekseev <alemate@chromium.org>
Reviewed-by: default avatarVasilii Sukhanov <vasilii@chromium.org>
Reviewed-by: default avatarAllen Bauer <kylixrd@chromium.org>
Reviewed-by: default avatarMihai Sardarescu <msarda@chromium.org>
Reviewed-by: default avatarPeter Boström <pbos@chromium.org>
Commit-Queue: Allen Bauer <kylixrd@chromium.org>
Cr-Commit-Position: refs/heads/master@{#670062}
parent 043af69d
......@@ -197,9 +197,9 @@ void RequestPinView::Init() {
// 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 @@ void RequestPinView::Init() {
// 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 @@ void RequestPinView::Init() {
// 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) {
......
......@@ -155,7 +155,7 @@ gfx::Size EnrollmentDialogView::CalculatePreferredSize() const {
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 @@ void EnrollmentDialogView::InitDialog() {
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));
......
......@@ -65,27 +65,27 @@ ChosenObjectView::ChosenObjectView(
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 @@ ChosenObjectView::ChosenObjectView(
// 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 @@ ChosenObjectView::ChosenObjectView(
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);
}
......
......@@ -247,31 +247,34 @@ BubbleHeaderView::BubbleHeaderView(
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 @@ PageInfoBubbleView::PageInfoBubbleView(
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 @@ void PageInfoBubbleView::SetPermissionInfo(
// 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 @@ PageInfoBubbleView::CreateSecurityDescriptionForPasswordReuse(
}
#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(
......
......@@ -159,7 +159,7 @@ class PageInfoBubbleView : public PageInfoBubbleViewBase,
// 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);
......
......@@ -167,15 +167,14 @@ PermissionSelectorRow::PermissionSelectorRow(
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 @@ PermissionSelectorRow::PermissionSelectorRow(
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 @@ PermissionSelectorRow::PermissionSelectorRow(
// 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 @@ void PermissionSelectorRow::InitializeComboboxView(
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(
......
......@@ -50,20 +50,17 @@ class PasswordGenerationPopupViewViews::GeneratedPasswordBox
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) {
......
......@@ -204,8 +204,8 @@ void PasswordItemsView::PasswordRow::AddUndoRow(views::GridLayout* layout) {
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 @@ void PasswordItemsView::PasswordRow::AddPasswordRow(views::GridLayout* layout) {
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,
......
......@@ -91,10 +91,11 @@ void BuildColumnSet(views::GridLayout* layout,
// |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 @@ void BuildCredentialRows(views::GridLayout* layout,
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 @@ void BuildCredentialRows(views::GridLayout* layout,
: 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 @@ PasswordPendingView::PasswordPendingView(content::WebContents* web_contents,
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));
}
}
......
......@@ -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 @@ gfx::Insets GetDialogInsets() {
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 @@ views::Label* CreateText(const base::string16& message) {
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 @@ void EnterpriseStartupDialogView::DisplayLaunchingInformationWithThrobber(
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 @@ void EnterpriseStartupDialogView::ResetDialog(bool show_accept_button) {
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 @@ void EnterpriseStartupDialogView::SetupLayout(views::View* icon,
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();
......
......@@ -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 @@ class EnterpriseStartupDialogView : public views::DialogDelegateView {
// 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_;
......
......@@ -408,7 +408,7 @@ void ProfileMenuViewBase::RepopulateViewFromMenuItems() {
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.
......
......@@ -63,26 +63,26 @@ DiceSigninButtonView::DiceSigninButtonView(
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 @@ DiceSigninButtonView::DiceSigninButtonView(
// 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;
......@@ -96,20 +96,22 @@ void OneClickSigninDialogView::Init() {
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 {
......
......@@ -156,7 +156,7 @@ void ProfileSigninConfirmationDialogViews::ViewHierarchyChanged(
// 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 @@ void ProfileSigninConfirmationDialogViews::ViewHierarchyChanged(
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 @@ void ProfileSigninConfirmationDialogViews::ViewHierarchyChanged(
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 @@ void ProfileSigninConfirmationDialogViews::ViewHierarchyChanged(
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 @@ void ProfileSigninConfirmationDialogViews::ViewHierarchyChanged(
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 @@ void ProfileSigninConfirmationDialogViews::ViewHierarchyChanged(
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() {
......
......@@ -1121,9 +1121,8 @@ void TryChromeDialog::OnContextInitialized() {
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 @@ void TryChromeDialog::OnContextInitialized() {
// 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 @@ void TryChromeDialog::OnContextInitialized() {
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 @@ void TryChromeDialog::OnContextInitialized() {
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 @@ void TryChromeDialog::OnContextInitialized() {
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);
......
......@@ -65,8 +65,7 @@ AuthenticatorClientPinEntryView::AuthenticatorClientPinEntryView(
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 @@ AuthenticatorClientPinEntryView::AuthenticatorClientPinEntryView(
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 @@ AuthenticatorClientPinEntryView::AuthenticatorClientPinEntryView(
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;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment