Commit 985129b4 authored by Allen Bauer's avatar Allen Bauer Committed by Commit Bot

Use std::unique_ptr<T> version of AddChildView.

Bug: 648382
Change-Id: I0e97983c8a5509e99bb7d33f7dab7e43be74d95d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2017667
Commit-Queue: Alex Newcomer <newcomer@chromium.org>
Reviewed-by: default avatarTao Wu <wutao@chromium.org>
Reviewed-by: default avatarAlex Newcomer <newcomer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#735068}
parent d5448ed4
...@@ -158,35 +158,33 @@ void AppListAssistantMainStage::InitLayout() { ...@@ -158,35 +158,33 @@ void AppListAssistantMainStage::InitLayout() {
layout->set_cross_axis_alignment( layout->set_cross_axis_alignment(
views::BoxLayout::CrossAxisAlignment::kCenter); views::BoxLayout::CrossAxisAlignment::kCenter);
auto* content_layout_container = CreateContentLayoutContainer(); layout->SetFlexForView(AddChildView(CreateContentLayoutContainer()), 1);
AddChildView(content_layout_container);
layout->SetFlexForView(content_layout_container, 1);
AddChildView(CreateFooterLayoutContainer()); AddChildView(CreateFooterLayoutContainer());
} }
views::View* AppListAssistantMainStage::CreateContentLayoutContainer() { std::unique_ptr<views::View>
AppListAssistantMainStage::CreateContentLayoutContainer() {
// The content layout container stacks two views. // The content layout container stacks two views.
// On top is a main content container including the line separator, progress // On top is a main content container including the line separator, progress
// indicator query view and |ui_element_container_|. // indicator query view and |ui_element_container_|.
// |greeting_label_| is laid out above of the main content container. As // |greeting_label_| is laid out above of the main content container. As
// such, it floats above and does not cause repositioning to any of content // such, it floats above and does not cause repositioning to any of content
// layout's underlying views. // layout's underlying views.
views::View* content_layout_container = new views::View(); auto content_layout_container = std::make_unique<views::View>();
auto* stack_layout = content_layout_container->SetLayoutManager( auto* stack_layout = content_layout_container->SetLayoutManager(
std::make_unique<StackLayout>()); std::make_unique<StackLayout>());
auto* main_content_layout_container = CreateMainContentLayoutContainer(); auto* main_content_layout_container = content_layout_container->AddChildView(
content_layout_container->AddChildView(main_content_layout_container); CreateMainContentLayoutContainer());
// Do not respect height, otherwise bounds will not be set correctly for // Do not respect height, otherwise bounds will not be set correctly for
// scrolling. // scrolling.
stack_layout->SetRespectDimensionForView( stack_layout->SetRespectDimensionForView(
main_content_layout_container, StackLayout::RespectDimension::kWidth); main_content_layout_container, StackLayout::RespectDimension::kWidth);
InitGreetingLabel(); greeting_label_ = content_layout_container->AddChildView(InitGreetingLabel());
content_layout_container->AddChildView(greeting_label_);
// We need to stretch |greeting_label_| to match its parent so that it // We need to stretch |greeting_label_| to match its parent so that it
// won't use heuristics in Label to infer line breaking, which seems to cause // won't use heuristics in Label to infer line breaking, which seems to cause
...@@ -199,26 +197,27 @@ views::View* AppListAssistantMainStage::CreateContentLayoutContainer() { ...@@ -199,26 +197,27 @@ views::View* AppListAssistantMainStage::CreateContentLayoutContainer() {
return content_layout_container; return content_layout_container;
} }
void AppListAssistantMainStage::InitGreetingLabel() { std::unique_ptr<views::Label> AppListAssistantMainStage::InitGreetingLabel() {
// Greeting label, which will be animated on its own layer. // Greeting label, which will be animated on its own layer.
greeting_label_ = new views::Label( auto greeting_label = std::make_unique<views::Label>(
l10n_util::GetStringUTF16(IDS_ASH_ASSISTANT_PROMPT_DEFAULT)); l10n_util::GetStringUTF16(IDS_ASH_ASSISTANT_PROMPT_DEFAULT));
greeting_label_->SetID(AssistantViewID::kGreetingLabel); greeting_label->SetID(AssistantViewID::kGreetingLabel);
greeting_label_->SetAutoColorReadabilityEnabled(false); greeting_label->SetAutoColorReadabilityEnabled(false);
greeting_label_->SetEnabledColor(kTextColorPrimary); greeting_label->SetEnabledColor(kTextColorPrimary);
greeting_label_->SetFontList( greeting_label->SetFontList(assistant::ui::GetDefaultFontList()
assistant::ui::GetDefaultFontList()
.DeriveWithSizeDelta(8) .DeriveWithSizeDelta(8)
.DeriveWithWeight(gfx::Font::Weight::MEDIUM)); .DeriveWithWeight(gfx::Font::Weight::MEDIUM));
greeting_label_->SetHorizontalAlignment( greeting_label->SetHorizontalAlignment(
gfx::HorizontalAlignment::ALIGN_CENTER); gfx::HorizontalAlignment::ALIGN_CENTER);
greeting_label_->SetMultiLine(true); greeting_label->SetMultiLine(true);
greeting_label_->SetPaintToLayer(); greeting_label->SetPaintToLayer();
greeting_label_->SetBackground(views::CreateSolidBackground(SK_ColorWHITE)); greeting_label->SetBackground(views::CreateSolidBackground(SK_ColorWHITE));
return greeting_label;
} }
views::View* AppListAssistantMainStage::CreateMainContentLayoutContainer() { std::unique_ptr<views::View>
views::View* content_layout_container = new views::View(); AppListAssistantMainStage::CreateMainContentLayoutContainer() {
auto content_layout_container = std::make_unique<views::View>();
views::BoxLayout* content_layout = content_layout_container->SetLayoutManager( views::BoxLayout* content_layout = content_layout_container->SetLayoutManager(
std::make_unique<views::BoxLayout>( std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kVertical)); views::BoxLayout::Orientation::kVertical));
...@@ -230,62 +229,64 @@ views::View* AppListAssistantMainStage::CreateMainContentLayoutContainer() { ...@@ -230,62 +229,64 @@ views::View* AppListAssistantMainStage::CreateMainContentLayoutContainer() {
content_layout_container->AddChildView(CreateDividerLayoutContainer()); content_layout_container->AddChildView(CreateDividerLayoutContainer());
// Query view. Will be animated on its own layer. // Query view. Will be animated on its own layer.
query_view_ = new AssistantQueryView(); query_view_ = content_layout_container->AddChildView(
std::make_unique<AssistantQueryView>());
query_view_->SetPaintToLayer(); query_view_->SetPaintToLayer();
query_view_->SetBackground(views::CreateSolidBackground(SK_ColorWHITE)); query_view_->SetBackground(views::CreateSolidBackground(SK_ColorWHITE));
query_view_->AddObserver(this); query_view_->AddObserver(this);
content_layout_container->AddChildView(query_view_);
// UI element container. // UI element container.
ui_element_container_ = new UiElementContainerView(delegate_); ui_element_container_ = content_layout_container->AddChildView(
std::make_unique<UiElementContainerView>(delegate_));
ui_element_container_->AddObserver(this); ui_element_container_->AddObserver(this);
content_layout_container->AddChildView(ui_element_container_);
content_layout->SetFlexForView(ui_element_container_, 1, content_layout->SetFlexForView(ui_element_container_, 1,
/*use_min_size=*/true); /*use_min_size=*/true);
return content_layout_container; return content_layout_container;
} }
views::View* AppListAssistantMainStage::CreateDividerLayoutContainer() { std::unique_ptr<views::View>
AppListAssistantMainStage::CreateDividerLayoutContainer() {
// Dividers: the progress indicator and the horizontal separator will be the // Dividers: the progress indicator and the horizontal separator will be the
// separator when querying and showing the results, respectively. // separator when querying and showing the results, respectively.
views::View* divider_container = new views::View(); auto divider_container = std::make_unique<views::View>();
divider_container->SetLayoutManager(std::make_unique<StackLayout>()); divider_container->SetLayoutManager(std::make_unique<StackLayout>());
// Progress indicator, which will be animated on its own layer. // Progress indicator, which will be animated on its own layer.
progress_indicator_ = new AssistantProgressIndicator(); progress_indicator_ = divider_container->AddChildView(
std::make_unique<AssistantProgressIndicator>());
progress_indicator_->SetPaintToLayer(); progress_indicator_->SetPaintToLayer();
progress_indicator_->layer()->SetFillsBoundsOpaquely(false); progress_indicator_->layer()->SetFillsBoundsOpaquely(false);
divider_container->AddChildView(progress_indicator_);
// Horizontal separator, which will be animated on its own layer. // Horizontal separator, which will be animated on its own layer.
horizontal_separator_ = new HorizontalSeparator( horizontal_separator_ =
kSeparatorWidthDip, progress_indicator_->GetPreferredSize().height()); divider_container->AddChildView(std::make_unique<HorizontalSeparator>(
kSeparatorWidthDip,
progress_indicator_->GetPreferredSize().height()));
horizontal_separator_->SetPaintToLayer(); horizontal_separator_->SetPaintToLayer();
horizontal_separator_->layer()->SetFillsBoundsOpaquely(false); horizontal_separator_->layer()->SetFillsBoundsOpaquely(false);
divider_container->AddChildView(horizontal_separator_);
return divider_container; return divider_container;
} }
views::View* AppListAssistantMainStage::CreateFooterLayoutContainer() { std::unique_ptr<views::View>
AppListAssistantMainStage::CreateFooterLayoutContainer() {
// Footer. // Footer.
// Note that the |footer_| is placed within its own view container so that as // Note that the |footer_| is placed within its own view container so that as
// its visibility changes, its parent container will still reserve the same // its visibility changes, its parent container will still reserve the same
// layout space. This prevents jank that would otherwise occur due to // layout space. This prevents jank that would otherwise occur due to
// |ui_element_container_| claiming that empty space. // |ui_element_container_| claiming that empty space.
views::View* footer_container = new views::View(); auto footer_container = std::make_unique<views::View>();
footer_container->SetLayoutManager(std::make_unique<views::FillLayout>()); footer_container->SetLayoutManager(std::make_unique<views::FillLayout>());
footer_ = new AssistantFooterView(delegate_); footer_ = footer_container->AddChildView(
std::make_unique<AssistantFooterView>(delegate_));
footer_->AddObserver(this); footer_->AddObserver(this);
// The footer will be animated on its own layer. // The footer will be animated on its own layer.
footer_->SetPaintToLayer(); footer_->SetPaintToLayer();
footer_->layer()->SetFillsBoundsOpaquely(false); footer_->layer()->SetFillsBoundsOpaquely(false);
footer_container->AddChildView(footer_);
return footer_container; return footer_container;
} }
......
...@@ -60,11 +60,11 @@ class APP_LIST_EXPORT AppListAssistantMainStage ...@@ -60,11 +60,11 @@ class APP_LIST_EXPORT AppListAssistantMainStage
private: private:
void InitLayout(); void InitLayout();
views::View* CreateContentLayoutContainer(); std::unique_ptr<views::View> CreateContentLayoutContainer();
void InitGreetingLabel(); std::unique_ptr<views::Label> InitGreetingLabel();
views::View* CreateMainContentLayoutContainer(); std::unique_ptr<views::View> CreateMainContentLayoutContainer();
views::View* CreateDividerLayoutContainer(); std::unique_ptr<views::View> CreateDividerLayoutContainer();
views::View* CreateFooterLayoutContainer(); std::unique_ptr<views::View> CreateFooterLayoutContainer();
void AnimateInGreetingLabel(); void AnimateInGreetingLabel();
void AnimateInFooter(); void AnimateInFooter();
......
...@@ -114,14 +114,14 @@ void AssistantMainView::InitLayout() { ...@@ -114,14 +114,14 @@ void AssistantMainView::InitLayout() {
views::BoxLayout::CrossAxisAlignment::kCenter); views::BoxLayout::CrossAxisAlignment::kCenter);
// Dialog plate, which will be animated on its own layer. // Dialog plate, which will be animated on its own layer.
dialog_plate_ = new AssistantDialogPlate(delegate_); dialog_plate_ =
AddChildView(std::make_unique<AssistantDialogPlate>(delegate_));
dialog_plate_->SetPaintToLayer(); dialog_plate_->SetPaintToLayer();
dialog_plate_->layer()->SetFillsBoundsOpaquely(false); dialog_plate_->layer()->SetFillsBoundsOpaquely(false);
AddChildView(dialog_plate_);
// Main stage. // Main stage.
main_stage_ = new AppListAssistantMainStage(delegate_); main_stage_ =
AddChildView(main_stage_); AddChildView(std::make_unique<AppListAssistantMainStage>(delegate_));
layout->SetFlexForView(main_stage_, 1); layout->SetFlexForView(main_stage_, 1);
} }
......
...@@ -110,8 +110,7 @@ void PrivacyInfoView::StyledLabelLinkClicked(views::StyledLabel* label, ...@@ -110,8 +110,7 @@ void PrivacyInfoView::StyledLabelLinkClicked(views::StyledLabel* label,
void PrivacyInfoView::InitLayout() { void PrivacyInfoView::InitLayout() {
SetLayoutManager(std::make_unique<views::FillLayout>()); SetLayoutManager(std::make_unique<views::FillLayout>());
SetBorder(views::CreateEmptyBorder(gfx::Insets(kRowMarginDip))); SetBorder(views::CreateEmptyBorder(gfx::Insets(kRowMarginDip)));
row_container_ = new views::View(); row_container_ = AddChildView(std::make_unique<views::View>());
AddChildView(row_container_);
constexpr int kVerticalPaddingDip = 0; constexpr int kVerticalPaddingDip = 0;
auto* layout_manager = auto* layout_manager =
...@@ -135,20 +134,19 @@ void PrivacyInfoView::InitLayout() { ...@@ -135,20 +134,19 @@ void PrivacyInfoView::InitLayout() {
InitText(); InitText();
// Spacer. // Spacer.
views::View* spacer = new views::View(); layout_manager->SetFlexForView(
row_container_->AddChildView(spacer); row_container_->AddChildView(std::make_unique<views::View>()), 1);
layout_manager->SetFlexForView(spacer, 1);
// Close button. // Close button.
InitCloseButton(); InitCloseButton();
} }
void PrivacyInfoView::InitInfoIcon() { void PrivacyInfoView::InitInfoIcon() {
info_icon_ = new views::ImageView(); info_icon_ =
row_container_->AddChildView(std::make_unique<views::ImageView>());
info_icon_->SetImageSize(gfx::Size(kIconSizeDip, kIconSizeDip)); info_icon_->SetImageSize(gfx::Size(kIconSizeDip, kIconSizeDip));
info_icon_->SetImage(gfx::CreateVectorIcon(views::kInfoIcon, kIconSizeDip, info_icon_->SetImage(gfx::CreateVectorIcon(views::kInfoIcon, kIconSizeDip,
gfx::kGoogleBlue600)); gfx::kGoogleBlue600));
row_container_->AddChildView(info_icon_);
} }
void PrivacyInfoView::InitText() { void PrivacyInfoView::InitText() {
...@@ -157,51 +155,51 @@ void PrivacyInfoView::InitText() { ...@@ -157,51 +155,51 @@ void PrivacyInfoView::InitText() {
size_t offset; size_t offset;
const base::string16 text = l10n_util::GetStringFUTF16( const base::string16 text = l10n_util::GetStringFUTF16(
IDS_APP_LIST_ASSISTANT_PRIVACY_INFO, link, &offset); IDS_APP_LIST_ASSISTANT_PRIVACY_INFO, link, &offset);
text_view_ = new views::StyledLabel(text, this); auto text_view = std::make_unique<views::StyledLabel>(text, this);
views::StyledLabel::RangeStyleInfo style; views::StyledLabel::RangeStyleInfo style;
style.custom_font = text_view_->GetDefaultFontList().Derive( style.custom_font = text_view->GetDefaultFontList().Derive(
0, gfx::Font::FontStyle::NORMAL, gfx::Font::Weight::NORMAL); 0, gfx::Font::FontStyle::NORMAL, gfx::Font::Weight::NORMAL);
style.override_color = gfx::kGoogleGrey900; style.override_color = gfx::kGoogleGrey900;
text_view_->AddStyleRange(gfx::Range(0, offset), style); text_view->AddStyleRange(gfx::Range(0, offset), style);
views::StyledLabel::RangeStyleInfo link_style = views::StyledLabel::RangeStyleInfo link_style =
views::StyledLabel::RangeStyleInfo::CreateForLink(); views::StyledLabel::RangeStyleInfo::CreateForLink();
link_style.override_color = gfx::kGoogleBlue700; link_style.override_color = gfx::kGoogleBlue700;
text_view_->AddStyleRange(gfx::Range(offset, offset + link.length()), text_view->AddStyleRange(gfx::Range(offset, offset + link.length()),
link_style); link_style);
text_view_->SetAutoColorReadabilityEnabled(false); text_view->SetAutoColorReadabilityEnabled(false);
row_container_->AddChildView(text_view_); text_view_ = row_container_->AddChildView(std::move(text_view));
} }
void PrivacyInfoView::InitCloseButton() { void PrivacyInfoView::InitCloseButton() {
close_button_ = new views::ImageButton(this); auto close_button = std::make_unique<views::ImageButton>(this);
close_button_->SetImage(views::ImageButton::STATE_NORMAL, close_button->SetImage(views::ImageButton::STATE_NORMAL,
gfx::CreateVectorIcon(views::kCloseIcon, kIconSizeDip, gfx::CreateVectorIcon(views::kCloseIcon, kIconSizeDip,
gfx::kGoogleGrey700)); gfx::kGoogleGrey700));
close_button_->SetImageHorizontalAlignment(views::ImageButton::ALIGN_CENTER); close_button->SetImageHorizontalAlignment(views::ImageButton::ALIGN_CENTER);
close_button_->SetImageVerticalAlignment(views::ImageButton::ALIGN_MIDDLE); close_button->SetImageVerticalAlignment(views::ImageButton::ALIGN_MIDDLE);
base::string16 close_button_label( base::string16 close_button_label(
l10n_util::GetStringUTF16(IDS_APP_LIST_ASSISTANT_PRIVACY_INFO_CLOSE)); l10n_util::GetStringUTF16(IDS_APP_LIST_ASSISTANT_PRIVACY_INFO_CLOSE));
close_button_->SetAccessibleName(close_button_label); close_button->SetAccessibleName(close_button_label);
close_button_->SetTooltipText(close_button_label); close_button->SetTooltipText(close_button_label);
close_button_->SetFocusBehavior(FocusBehavior::ALWAYS); close_button->SetFocusBehavior(FocusBehavior::ALWAYS);
constexpr int kImageButtonSizeDip = 40; constexpr int kImageButtonSizeDip = 40;
constexpr int kIconMarginDip = (kImageButtonSizeDip - kIconSizeDip) / 2; constexpr int kIconMarginDip = (kImageButtonSizeDip - kIconSizeDip) / 2;
close_button_->SetBorder( close_button->SetBorder(
views::CreateEmptyBorder(gfx::Insets(kIconMarginDip))); views::CreateEmptyBorder(gfx::Insets(kIconMarginDip)));
close_button_->SizeToPreferredSize(); close_button->SizeToPreferredSize();
// Ink ripple. // Ink ripple.
close_button_->SetInkDropMode(views::InkDropHostView::InkDropMode::ON); close_button->SetInkDropMode(views::InkDropHostView::InkDropMode::ON);
constexpr SkColor kInkDropBaseColor = gfx::kGoogleGrey900; constexpr SkColor kInkDropBaseColor = gfx::kGoogleGrey900;
constexpr float kInkDropVisibleOpacity = 0.06f; constexpr float kInkDropVisibleOpacity = 0.06f;
constexpr float kInkDropHighlightOpacity = 0.08f; constexpr float kInkDropHighlightOpacity = 0.08f;
close_button_->set_ink_drop_visible_opacity(kInkDropVisibleOpacity); close_button->set_ink_drop_visible_opacity(kInkDropVisibleOpacity);
close_button_->set_ink_drop_highlight_opacity(kInkDropHighlightOpacity); close_button->set_ink_drop_highlight_opacity(kInkDropHighlightOpacity);
close_button_->set_ink_drop_base_color(kInkDropBaseColor); close_button->set_ink_drop_base_color(kInkDropBaseColor);
close_button_->set_has_ink_drop_action_on_click(true); close_button->set_has_ink_drop_action_on_click(true);
views::InstallCircleHighlightPathGenerator(close_button_); views::InstallCircleHighlightPathGenerator(close_button.get());
row_container_->AddChildView(close_button_); close_button_ = row_container_->AddChildView(std::move(close_button));
} }
} // namespace ash } // namespace ash
...@@ -111,8 +111,8 @@ void ContentsView::Init(AppListModel* model) { ...@@ -111,8 +111,8 @@ void ContentsView::Init(AppListModel* model) {
search_result_answer_card_view_); search_result_answer_card_view_);
} }
expand_arrow_view_ = new ExpandArrowView(this, app_list_view_); expand_arrow_view_ =
AddChildView(expand_arrow_view_); AddChildView(std::make_unique<ExpandArrowView>(this, app_list_view_));
search_result_tile_item_list_view_ = new SearchResultTileItemListView( search_result_tile_item_list_view_ = new SearchResultTileItemListView(
search_results_page_view_, GetSearchBoxView()->search_box(), search_results_page_view_, GetSearchBoxView()->search_box(),
......
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