Commit 3d4c6fda authored by Allen Bauer's avatar Allen Bauer Committed by Commit Bot

Favor AddChildView<T> using std::unique_ptr<T>.

Bug: 648382
Change-Id: Ic87f156e9661efc832bf054d4f901895bb9671b0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2067258Reviewed-by: default avatarTao Wu <wutao@chromium.org>
Commit-Queue: Allen Bauer <kylixrd@chromium.org>
Cr-Commit-Position: refs/heads/master@{#743319}
parent fdce6b60
......@@ -57,9 +57,8 @@ BubbleView::~BubbleView() = default;
void BubbleView::SetIcon(const gfx::VectorIcon& icon) {
if (!icon_) {
icon_ = new views::ImageView();
// |icon_| is always the first child view.
AddChildViewAt(icon_, 0);
icon_ = AddChildViewAt(std::make_unique<views::ImageView>(), 0);
}
constexpr int kIconSize = 16;
......@@ -70,14 +69,13 @@ void BubbleView::SetIcon(const gfx::VectorIcon& icon) {
void BubbleView::SetText(const base::string16& text) {
if (!text_) {
text_ = new views::Label();
text_ = AddChildView(std::make_unique<views::Label>());
text_->SetEnabledColor(gfx::kGoogleGrey700);
text_->SetElideBehavior(gfx::NO_ELIDE);
constexpr int kLabelFontSizeDelta = 1;
text_->SetFontList(
ui::ResourceBundle::GetSharedInstance().GetFontListWithDelta(
kLabelFontSizeDelta, gfx::Font::NORMAL, gfx::Font::Weight::MEDIUM));
AddChildView(text_);
}
text_->SetText(text);
}
......
......@@ -68,7 +68,7 @@ void KeyboardShortcutItemListView::AddCategoryLabel(
constexpr int kLabelBottomPadding = 20;
constexpr SkColor kLabelColor = SkColorSetARGB(0xFF, 0x42, 0x85, 0xF4);
views::Label* category_label = new views::Label(text);
auto category_label = std::make_unique<views::Label>(text);
category_label->SetHorizontalAlignment(gfx::ALIGN_TO_HEAD);
category_label->SetBorder(views::CreateEmptyBorder(
gfx::Insets(kLabelTopPadding, 0, kLabelBottomPadding, 0)));
......@@ -77,11 +77,11 @@ void KeyboardShortcutItemListView::AddCategoryLabel(
category_label->SetFontList(
ui::ResourceBundle::GetSharedInstance().GetFontListWithDelta(
kLabelFontSizeDelta, gfx::Font::NORMAL, gfx::Font::Weight::BOLD));
AddChildView(category_label);
AddChildView(std::move(category_label));
}
void KeyboardShortcutItemListView::AddHorizontalSeparator() {
AddChildView(new HorizontalSeparator(bounds().width()));
AddChildView(std::make_unique<HorizontalSeparator>(bounds().width()));
}
} // namespace keyboard_shortcut_viewer
......@@ -60,14 +60,13 @@ KeyboardShortcutItemView::KeyboardShortcutItemView(
const KeyboardShortcutItem& item,
ShortcutCategory category)
: shortcut_item_(&item), category_(category) {
description_label_view_ = new views::StyledLabel(
l10n_util::GetStringUTF16(item.description_message_id), nullptr);
description_label_view_ = AddChildView(std::make_unique<views::StyledLabel>(
l10n_util::GetStringUTF16(item.description_message_id), nullptr));
// StyledLabel will flip the alignment if UI layout is right-to-left.
// Flip the alignment here in order to make |description_label_view_| always
// align to left.
description_label_view_->SetHorizontalAlignment(
base::i18n::IsRTL() ? gfx::ALIGN_RIGHT : gfx::ALIGN_LEFT);
AddChildView(description_label_view_);
std::vector<size_t> offsets;
std::vector<base::string16> replacement_strings;
......@@ -114,7 +113,8 @@ KeyboardShortcutItemView::KeyboardShortcutItemView(
accessible_string = l10n_util::GetStringFUTF16(
item.shortcut_message_id, accessible_names, /*offsets=*/nullptr);
}
shortcut_label_view_ = new views::StyledLabel(shortcut_string, nullptr);
shortcut_label_view_ = AddChildView(
std::make_unique<views::StyledLabel>(shortcut_string, nullptr));
// StyledLabel will flip the alignment if UI layout is right-to-left.
// Flip the alignment here in order to make |shortcut_label_view_| always
// align to right.
......@@ -138,7 +138,6 @@ KeyboardShortcutItemView::KeyboardShortcutItemView(
gfx::Range(offsets[i], offsets[i] + replacement_strings[i].length()),
style_info);
}
AddChildView(shortcut_label_view_);
constexpr int kVerticalPadding = 10;
SetBorder(views::CreateEmptyBorder(
......
......@@ -79,22 +79,23 @@ void SetupSearchIllustrationView(views::View* illustration_view,
views::BoxLayout::Orientation::kVertical,
gfx::Insets(kTopPadding, 0, 0, 0)));
layout->set_main_axis_alignment(views::BoxLayout::MainAxisAlignment::kStart);
views::ImageView* image_view = new views::ImageView();
auto image_view = std::make_unique<views::ImageView>();
image_view->SetImage(
gfx::CreateVectorIcon(icon, kSearchIllustrationIconColor));
image_view->SetImageSize(
gfx::Size(kSearchIllustrationIconSize, kSearchIllustrationIconSize));
illustration_view->AddChildView(image_view);
illustration_view->AddChildView(std::move(image_view));
constexpr SkColor kSearchIllustrationTextColor =
SkColorSetARGB(0xFF, 0x20, 0x21, 0x24);
views::Label* text = new views::Label(l10n_util::GetStringUTF16(message_id));
auto text =
std::make_unique<views::Label>(l10n_util::GetStringUTF16(message_id));
text->SetEnabledColor(kSearchIllustrationTextColor);
constexpr int kLabelFontSizeDelta = 1;
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
text->SetFontList(rb.GetFontListWithDelta(
kLabelFontSizeDelta, gfx::Font::NORMAL, gfx::Font::Weight::NORMAL));
illustration_view->AddChildView(text);
illustration_view->AddChildView(std::move(text));
}
class ShortcutsListScrollView : public views::ScrollView {
......@@ -367,11 +368,10 @@ void KeyboardShortcutView::InitViews() {
kKsvSearchNoResultIcon, IDS_KSV_SEARCH_NO_RESULT);
// Init search results container view.
search_results_container_ = new views::View();
search_results_container_ = AddChildView(std::make_unique<views::View>());
search_results_container_->SetLayoutManager(
std::make_unique<views::FillLayout>());
search_results_container_->SetVisible(false);
AddChildView(search_results_container_);
// Init views of KeyboardShortcutItemView.
// TODO(https://crbug.com/843394): Observe changes in keyboard layout and
......@@ -396,10 +396,9 @@ void KeyboardShortcutView::InitViews() {
});
// Init views of |categories_tabbed_pane_| and KeyboardShortcutItemListViews.
categories_tabbed_pane_ =
new views::TabbedPane(views::TabbedPane::Orientation::kVertical,
views::TabbedPane::TabStripStyle::kHighlight);
AddChildView(categories_tabbed_pane_);
categories_tabbed_pane_ = AddChildView(std::make_unique<views::TabbedPane>(
views::TabbedPane::Orientation::kVertical,
views::TabbedPane::TabStripStyle::kHighlight));
// Initial Layout of KeyboardShortcutItemView is time consuming. To speed up
// the startup time, we only initialize the first category pane, which is
......
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