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() {
layout->set_cross_axis_alignment(
views::BoxLayout::CrossAxisAlignment::kCenter);
auto* content_layout_container = CreateContentLayoutContainer();
AddChildView(content_layout_container);
layout->SetFlexForView(content_layout_container, 1);
layout->SetFlexForView(AddChildView(CreateContentLayoutContainer()), 1);
AddChildView(CreateFooterLayoutContainer());
}
views::View* AppListAssistantMainStage::CreateContentLayoutContainer() {
std::unique_ptr<views::View>
AppListAssistantMainStage::CreateContentLayoutContainer() {
// The content layout container stacks two views.
// On top is a main content container including the line separator, progress
// indicator query view and |ui_element_container_|.
// |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
// 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(
std::make_unique<StackLayout>());
auto* main_content_layout_container = CreateMainContentLayoutContainer();
content_layout_container->AddChildView(main_content_layout_container);
auto* main_content_layout_container = content_layout_container->AddChildView(
CreateMainContentLayoutContainer());
// Do not respect height, otherwise bounds will not be set correctly for
// scrolling.
stack_layout->SetRespectDimensionForView(
main_content_layout_container, StackLayout::RespectDimension::kWidth);
InitGreetingLabel();
content_layout_container->AddChildView(greeting_label_);
greeting_label_ = content_layout_container->AddChildView(InitGreetingLabel());
// 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
......@@ -199,26 +197,27 @@ views::View* AppListAssistantMainStage::CreateContentLayoutContainer() {
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_ = new views::Label(
auto greeting_label = std::make_unique<views::Label>(
l10n_util::GetStringUTF16(IDS_ASH_ASSISTANT_PROMPT_DEFAULT));
greeting_label_->SetID(AssistantViewID::kGreetingLabel);
greeting_label_->SetAutoColorReadabilityEnabled(false);
greeting_label_->SetEnabledColor(kTextColorPrimary);
greeting_label_->SetFontList(
assistant::ui::GetDefaultFontList()
greeting_label->SetID(AssistantViewID::kGreetingLabel);
greeting_label->SetAutoColorReadabilityEnabled(false);
greeting_label->SetEnabledColor(kTextColorPrimary);
greeting_label->SetFontList(assistant::ui::GetDefaultFontList()
.DeriveWithSizeDelta(8)
.DeriveWithWeight(gfx::Font::Weight::MEDIUM));
greeting_label_->SetHorizontalAlignment(
greeting_label->SetHorizontalAlignment(
gfx::HorizontalAlignment::ALIGN_CENTER);
greeting_label_->SetMultiLine(true);
greeting_label_->SetPaintToLayer();
greeting_label_->SetBackground(views::CreateSolidBackground(SK_ColorWHITE));
greeting_label->SetMultiLine(true);
greeting_label->SetPaintToLayer();
greeting_label->SetBackground(views::CreateSolidBackground(SK_ColorWHITE));
return greeting_label;
}
views::View* AppListAssistantMainStage::CreateMainContentLayoutContainer() {
views::View* content_layout_container = new views::View();
std::unique_ptr<views::View>
AppListAssistantMainStage::CreateMainContentLayoutContainer() {
auto content_layout_container = std::make_unique<views::View>();
views::BoxLayout* content_layout = content_layout_container->SetLayoutManager(
std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kVertical));
......@@ -230,62 +229,64 @@ views::View* AppListAssistantMainStage::CreateMainContentLayoutContainer() {
content_layout_container->AddChildView(CreateDividerLayoutContainer());
// 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_->SetBackground(views::CreateSolidBackground(SK_ColorWHITE));
query_view_->AddObserver(this);
content_layout_container->AddChildView(query_view_);
// 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);
content_layout_container->AddChildView(ui_element_container_);
content_layout->SetFlexForView(ui_element_container_, 1,
/*use_min_size=*/true);
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
// 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>());
// 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_->layer()->SetFillsBoundsOpaquely(false);
divider_container->AddChildView(progress_indicator_);
// Horizontal separator, which will be animated on its own layer.
horizontal_separator_ = new HorizontalSeparator(
kSeparatorWidthDip, progress_indicator_->GetPreferredSize().height());
horizontal_separator_ =
divider_container->AddChildView(std::make_unique<HorizontalSeparator>(
kSeparatorWidthDip,
progress_indicator_->GetPreferredSize().height()));
horizontal_separator_->SetPaintToLayer();
horizontal_separator_->layer()->SetFillsBoundsOpaquely(false);
divider_container->AddChildView(horizontal_separator_);
return divider_container;
}
views::View* AppListAssistantMainStage::CreateFooterLayoutContainer() {
std::unique_ptr<views::View>
AppListAssistantMainStage::CreateFooterLayoutContainer() {
// Footer.
// 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
// layout space. This prevents jank that would otherwise occur due to
// |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_ = new AssistantFooterView(delegate_);
footer_ = footer_container->AddChildView(
std::make_unique<AssistantFooterView>(delegate_));
footer_->AddObserver(this);
// The footer will be animated on its own layer.
footer_->SetPaintToLayer();
footer_->layer()->SetFillsBoundsOpaquely(false);
footer_container->AddChildView(footer_);
return footer_container;
}
......
......@@ -60,11 +60,11 @@ class APP_LIST_EXPORT AppListAssistantMainStage
private:
void InitLayout();
views::View* CreateContentLayoutContainer();
void InitGreetingLabel();
views::View* CreateMainContentLayoutContainer();
views::View* CreateDividerLayoutContainer();
views::View* CreateFooterLayoutContainer();
std::unique_ptr<views::View> CreateContentLayoutContainer();
std::unique_ptr<views::Label> InitGreetingLabel();
std::unique_ptr<views::View> CreateMainContentLayoutContainer();
std::unique_ptr<views::View> CreateDividerLayoutContainer();
std::unique_ptr<views::View> CreateFooterLayoutContainer();
void AnimateInGreetingLabel();
void AnimateInFooter();
......
......@@ -114,14 +114,14 @@ void AssistantMainView::InitLayout() {
views::BoxLayout::CrossAxisAlignment::kCenter);
// 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_->layer()->SetFillsBoundsOpaquely(false);
AddChildView(dialog_plate_);
// Main stage.
main_stage_ = new AppListAssistantMainStage(delegate_);
AddChildView(main_stage_);
main_stage_ =
AddChildView(std::make_unique<AppListAssistantMainStage>(delegate_));
layout->SetFlexForView(main_stage_, 1);
}
......
......@@ -110,8 +110,7 @@ void PrivacyInfoView::StyledLabelLinkClicked(views::StyledLabel* label,
void PrivacyInfoView::InitLayout() {
SetLayoutManager(std::make_unique<views::FillLayout>());
SetBorder(views::CreateEmptyBorder(gfx::Insets(kRowMarginDip)));
row_container_ = new views::View();
AddChildView(row_container_);
row_container_ = AddChildView(std::make_unique<views::View>());
constexpr int kVerticalPaddingDip = 0;
auto* layout_manager =
......@@ -135,20 +134,19 @@ void PrivacyInfoView::InitLayout() {
InitText();
// Spacer.
views::View* spacer = new views::View();
row_container_->AddChildView(spacer);
layout_manager->SetFlexForView(spacer, 1);
layout_manager->SetFlexForView(
row_container_->AddChildView(std::make_unique<views::View>()), 1);
// Close button.
InitCloseButton();
}
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_->SetImage(gfx::CreateVectorIcon(views::kInfoIcon, kIconSizeDip,
gfx::kGoogleBlue600));
row_container_->AddChildView(info_icon_);
}
void PrivacyInfoView::InitText() {
......@@ -157,51 +155,51 @@ void PrivacyInfoView::InitText() {
size_t offset;
const base::string16 text = l10n_util::GetStringFUTF16(
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;
style.custom_font = text_view_->GetDefaultFontList().Derive(
style.custom_font = text_view->GetDefaultFontList().Derive(
0, gfx::Font::FontStyle::NORMAL, gfx::Font::Weight::NORMAL);
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::CreateForLink();
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);
text_view_->SetAutoColorReadabilityEnabled(false);
row_container_->AddChildView(text_view_);
text_view->SetAutoColorReadabilityEnabled(false);
text_view_ = row_container_->AddChildView(std::move(text_view));
}
void PrivacyInfoView::InitCloseButton() {
close_button_ = new views::ImageButton(this);
close_button_->SetImage(views::ImageButton::STATE_NORMAL,
auto close_button = std::make_unique<views::ImageButton>(this);
close_button->SetImage(views::ImageButton::STATE_NORMAL,
gfx::CreateVectorIcon(views::kCloseIcon, kIconSizeDip,
gfx::kGoogleGrey700));
close_button_->SetImageHorizontalAlignment(views::ImageButton::ALIGN_CENTER);
close_button_->SetImageVerticalAlignment(views::ImageButton::ALIGN_MIDDLE);
close_button->SetImageHorizontalAlignment(views::ImageButton::ALIGN_CENTER);
close_button->SetImageVerticalAlignment(views::ImageButton::ALIGN_MIDDLE);
base::string16 close_button_label(
l10n_util::GetStringUTF16(IDS_APP_LIST_ASSISTANT_PRIVACY_INFO_CLOSE));
close_button_->SetAccessibleName(close_button_label);
close_button_->SetTooltipText(close_button_label);
close_button_->SetFocusBehavior(FocusBehavior::ALWAYS);
close_button->SetAccessibleName(close_button_label);
close_button->SetTooltipText(close_button_label);
close_button->SetFocusBehavior(FocusBehavior::ALWAYS);
constexpr int kImageButtonSizeDip = 40;
constexpr int kIconMarginDip = (kImageButtonSizeDip - kIconSizeDip) / 2;
close_button_->SetBorder(
close_button->SetBorder(
views::CreateEmptyBorder(gfx::Insets(kIconMarginDip)));
close_button_->SizeToPreferredSize();
close_button->SizeToPreferredSize();
// Ink ripple.
close_button_->SetInkDropMode(views::InkDropHostView::InkDropMode::ON);
close_button->SetInkDropMode(views::InkDropHostView::InkDropMode::ON);
constexpr SkColor kInkDropBaseColor = gfx::kGoogleGrey900;
constexpr float kInkDropVisibleOpacity = 0.06f;
constexpr float kInkDropHighlightOpacity = 0.08f;
close_button_->set_ink_drop_visible_opacity(kInkDropVisibleOpacity);
close_button_->set_ink_drop_highlight_opacity(kInkDropHighlightOpacity);
close_button_->set_ink_drop_base_color(kInkDropBaseColor);
close_button_->set_has_ink_drop_action_on_click(true);
views::InstallCircleHighlightPathGenerator(close_button_);
row_container_->AddChildView(close_button_);
close_button->set_ink_drop_visible_opacity(kInkDropVisibleOpacity);
close_button->set_ink_drop_highlight_opacity(kInkDropHighlightOpacity);
close_button->set_ink_drop_base_color(kInkDropBaseColor);
close_button->set_has_ink_drop_action_on_click(true);
views::InstallCircleHighlightPathGenerator(close_button.get());
close_button_ = row_container_->AddChildView(std::move(close_button));
}
} // namespace ash
......@@ -111,8 +111,8 @@ void ContentsView::Init(AppListModel* model) {
search_result_answer_card_view_);
}
expand_arrow_view_ = new ExpandArrowView(this, app_list_view_);
AddChildView(expand_arrow_view_);
expand_arrow_view_ =
AddChildView(std::make_unique<ExpandArrowView>(this, app_list_view_));
search_result_tile_item_list_view_ = new SearchResultTileItemListView(
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