Commit 4f601867 authored by Allen Bauer's avatar Allen Bauer Committed by Commit Bot

Prefer AddChildView<T> with std::unique_ptr<>

Bug: 648382
Change-Id: I4db6eb8cfd081c1dde3998db2f1264f0adf42cd1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2065350
Commit-Queue: Allen Bauer <kylixrd@chromium.org>
Reviewed-by: default avatarTao Wu <wutao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#743177}
parent 7422bc45
......@@ -57,9 +57,8 @@ void MicView::InitLayout() {
SetLayoutManager(std::make_unique<views::FillLayout>());
// Logo view container.
views::View* logo_view_container = new views::View();
auto logo_view_container = std::make_unique<views::View>();
logo_view_container->set_can_process_events_within_subtree(false);
AddChildView(logo_view_container);
views::BoxLayout* layout_manager =
logo_view_container->SetLayoutManager(std::make_unique<views::BoxLayout>(
......@@ -75,6 +74,8 @@ void MicView::InitLayout() {
logo_view_ = logo_view_container->AddChildView(LogoView::Create());
logo_view_->SetPreferredSize(gfx::Size(kIconSizeDip, kIconSizeDip));
AddChildView(std::move(logo_view_container));
// Initialize state.
UpdateState(/*animate=*/false);
}
......
......@@ -175,7 +175,7 @@ void AssistantProgressIndicator::InitLayout() {
// Initialize dots.
for (int i = 0; i < kDotCount; ++i) {
views::View* dot_view = new views::View();
auto dot_view = std::make_unique<views::View>();
dot_view->SetBackground(std::make_unique<DotBackground>());
dot_view->SetPreferredSize(gfx::Size(kDotSmallSizeDip, kDotSmallSizeDip));
......@@ -183,7 +183,7 @@ void AssistantProgressIndicator::InitLayout() {
dot_view->SetPaintToLayer();
dot_view->layer()->SetFillsBoundsOpaquely(false);
AddChildView(dot_view);
AddChildView(std::move(dot_view));
}
}
......
......@@ -243,8 +243,8 @@ void SuggestionContainerView::AddSuggestionChip(
params.icon = gfx::ImageSkia();
}
SuggestionChipView* suggestion_chip_view =
new SuggestionChipView(params, /*listener=*/this);
auto suggestion_chip_view =
std::make_unique<SuggestionChipView>(params, /*listener=*/this);
suggestion_chip_view->SetAccessibleName(params.text);
......@@ -258,13 +258,12 @@ void SuggestionContainerView::AddSuggestionChip(
// Given an id, we also want to be able to look up the corresponding
// suggestion chip view. This is used for handling icon download events.
suggestion_chip_views_[id] = suggestion_chip_view;
content_view()->AddChildView(suggestion_chip_view);
suggestion_chip_views_[id] =
content_view()->AddChildView(std::move(suggestion_chip_view));
// Set the animations for the suggestion chip.
AddElementAnimator(
std::make_unique<SuggestionChipAnimator>(suggestion_chip_view, this));
AddElementAnimator(std::make_unique<SuggestionChipAnimator>(
suggestion_chip_views_[id], this));
}
void SuggestionContainerView::OnSuggestionChipIconDownloaded(
......
......@@ -92,23 +92,23 @@ void ProactiveSuggestionsSimpleView::InitLayout() {
views::BoxLayout::CrossAxisAlignment::kCenter);
// Assistant icon.
views::ImageView* assistant_icon = new views::ImageView();
auto assistant_icon = std::make_unique<views::ImageView>();
assistant_icon->SetImage(gfx::CreateVectorIcon(
kAssistantIcon, kAssistantIconSizeDip, gfx::kPlaceholderColor));
assistant_icon->SetPreferredSize(
gfx::Size(kAssistantIconSizeDip, kAssistantIconSizeDip));
AddChildView(assistant_icon);
AddChildView(std::move(assistant_icon));
// Spacing.
// Note that we don't add similar spacing between |label_| and the
// |close_button_| as the latter has internal spacing between its icon and
// outer bounds so as to provide a larger hit rect to the user.
views::View* spacing = new views::View();
auto spacing = std::make_unique<views::View>();
spacing->SetPreferredSize(gfx::Size(kSpacingDip, kPreferredHeightDip));
AddChildView(spacing);
AddChildView(std::move(spacing));
// Label.
views::Label* label = new views::Label();
auto label = std::make_unique<views::Label>();
label->SetAutoColorReadabilityEnabled(false);
label->SetElideBehavior(gfx::ElideBehavior::FADE_TAIL);
label->SetEnabledColor(gfx::kGoogleGrey100);
......@@ -124,23 +124,21 @@ void ProactiveSuggestionsSimpleView::InitLayout() {
label->SetText(net::UnescapeForHTML(
base::UTF8ToUTF16(proactive_suggestions()->description())));
AddChildView(label);
// We impose a maximum width restriction on the proactive suggestions view.
// When restricting width, |label| should cede layout space to its siblings.
layout_manager->SetFlexForView(label, 1);
layout_manager->SetFlexForView(AddChildView(std::move(label)), 1);
// Close button.
close_button_ = new views::ImageButton(/*listener=*/this);
close_button_->SetImage(
auto close_button = std::make_unique<views::ImageButton>(/*listener=*/this);
close_button->SetImage(
views::ImageButton::ButtonState::STATE_NORMAL,
gfx::CreateVectorIcon(views::kIcCloseIcon, kCloseButtonIconSizeDip,
gfx::kGoogleGrey100));
close_button_->SetImageHorizontalAlignment(views::ImageButton::ALIGN_CENTER);
close_button_->SetImageVerticalAlignment(views::ImageButton::ALIGN_MIDDLE);
close_button_->SetPreferredSize(
close_button->SetImageHorizontalAlignment(views::ImageButton::ALIGN_CENTER);
close_button->SetImageVerticalAlignment(views::ImageButton::ALIGN_MIDDLE);
close_button->SetPreferredSize(
gfx::Size(kCloseButtonSizeDip, kCloseButtonSizeDip));
AddChildView(close_button_);
close_button_ = AddChildView(std::move(close_button));
}
} // namespace ash
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