Commit 32f7d24a authored by Allen Bauer's avatar Allen Bauer Committed by Commit Bot

Clarify view ownership in the assistant dialog.

Bug: 648382
Change-Id: I89d44f2b4ed34827d0451db4cbfa801a6c6cf3fb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2013512Reviewed-by: default avatarTao Wu <wutao@chromium.org>
Commit-Queue: Allen Bauer <kylixrd@chromium.org>
Cr-Commit-Position: refs/heads/master@{#734122}
parent ee954935
...@@ -296,13 +296,13 @@ void AssistantDialogPlate::InitLayout() { ...@@ -296,13 +296,13 @@ void AssistantDialogPlate::InitLayout() {
/*animate=*/false); /*animate=*/false);
// Input modality layout container. // Input modality layout container.
input_modality_layout_container_ = new views::View(); input_modality_layout_container_ =
AddChildView(std::make_unique<views::View>());
input_modality_layout_container_->SetLayoutManager( input_modality_layout_container_->SetLayoutManager(
std::make_unique<views::FillLayout>()); std::make_unique<views::FillLayout>());
input_modality_layout_container_->SetPaintToLayer(); input_modality_layout_container_->SetPaintToLayer();
input_modality_layout_container_->layer()->SetFillsBoundsOpaquely(false); input_modality_layout_container_->layer()->SetFillsBoundsOpaquely(false);
input_modality_layout_container_->layer()->SetMasksToBounds(true); input_modality_layout_container_->layer()->SetMasksToBounds(true);
AddChildView(input_modality_layout_container_);
layout_manager->SetFlexForView(input_modality_layout_container_, 1); layout_manager->SetFlexForView(input_modality_layout_container_, 1);
...@@ -314,14 +314,14 @@ void AssistantDialogPlate::InitLayout() { ...@@ -314,14 +314,14 @@ void AssistantDialogPlate::InitLayout() {
} }
void AssistantDialogPlate::InitKeyboardLayoutContainer() { void AssistantDialogPlate::InitKeyboardLayoutContainer() {
keyboard_layout_container_ = new views::View(); auto keyboard_layout_container = std::make_unique<views::View>();
keyboard_layout_container_->SetPaintToLayer(); keyboard_layout_container->SetPaintToLayer();
keyboard_layout_container_->layer()->SetFillsBoundsOpaquely(false); keyboard_layout_container->layer()->SetFillsBoundsOpaquely(false);
keyboard_layout_container_->layer()->SetOpacity(0.f); keyboard_layout_container->layer()->SetOpacity(0.f);
constexpr int kLeftPaddingDip = 16; constexpr int kLeftPaddingDip = 16;
views::BoxLayout* layout_manager = views::BoxLayout* layout_manager =
keyboard_layout_container_->SetLayoutManager( keyboard_layout_container->SetLayoutManager(
std::make_unique<views::BoxLayout>( std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kHorizontal, views::BoxLayout::Orientation::kHorizontal,
gfx::Insets(0, kLeftPaddingDip, 0, 0))); gfx::Insets(0, kLeftPaddingDip, 0, 0)));
...@@ -333,42 +333,44 @@ void AssistantDialogPlate::InitKeyboardLayoutContainer() { ...@@ -333,42 +333,44 @@ void AssistantDialogPlate::InitKeyboardLayoutContainer() {
assistant::ui::GetDefaultFontList().DeriveWithSizeDelta(2); assistant::ui::GetDefaultFontList().DeriveWithSizeDelta(2);
// Textfield. // Textfield.
textfield_ = new AssistantTextfield(); auto textfield = std::make_unique<AssistantTextfield>();
textfield_->SetBackgroundColor(SK_ColorTRANSPARENT); textfield->SetBackgroundColor(SK_ColorTRANSPARENT);
textfield_->SetBorder(views::NullBorder()); textfield->SetBorder(views::NullBorder());
textfield_->set_controller(this); textfield->set_controller(this);
textfield_->SetFontList(font_list); textfield->SetFontList(font_list);
textfield_->set_placeholder_font_list(font_list); textfield->set_placeholder_font_list(font_list);
auto textfield_hint = auto textfield_hint =
l10n_util::GetStringUTF16(IDS_ASH_ASSISTANT_DIALOG_PLATE_HINT); l10n_util::GetStringUTF16(IDS_ASH_ASSISTANT_DIALOG_PLATE_HINT);
textfield_->SetPlaceholderText(textfield_hint); textfield->SetPlaceholderText(textfield_hint);
textfield_->SetAccessibleName(textfield_hint); textfield->SetAccessibleName(textfield_hint);
textfield_->set_placeholder_text_color(kTextColorSecondary); textfield->set_placeholder_text_color(kTextColorSecondary);
textfield_->SetTextColor(kTextColorPrimary); textfield->SetTextColor(kTextColorPrimary);
keyboard_layout_container_->AddChildView(textfield_); textfield_ = keyboard_layout_container->AddChildView(std::move(textfield));
layout_manager->SetFlexForView(textfield_, 1); layout_manager->SetFlexForView(textfield_, 1);
// Voice input toggle. // Voice input toggle.
voice_input_toggle_ = std::unique_ptr<AssistantButton> voice_input_toggle =
AssistantButton::Create(this, kMicIcon, kButtonSizeDip, kIconSizeDip, AssistantButton::Create(this, kMicIcon, kButtonSizeDip, kIconSizeDip,
IDS_ASH_ASSISTANT_DIALOG_PLATE_MIC_ACCNAME, IDS_ASH_ASSISTANT_DIALOG_PLATE_MIC_ACCNAME,
AssistantButtonId::kVoiceInputToggle, AssistantButtonId::kVoiceInputToggle,
IDS_ASH_ASSISTANT_DIALOG_PLATE_MIC_TOOLTIP); IDS_ASH_ASSISTANT_DIALOG_PLATE_MIC_TOOLTIP);
voice_input_toggle_->SetID(AssistantViewID::kVoiceInputToggle); voice_input_toggle->SetID(AssistantViewID::kVoiceInputToggle);
keyboard_layout_container_->AddChildView(voice_input_toggle_); voice_input_toggle_ =
keyboard_layout_container->AddChildView(std::move(voice_input_toggle));
input_modality_layout_container_->AddChildView(keyboard_layout_container_); keyboard_layout_container_ = input_modality_layout_container_->AddChildView(
std::move(keyboard_layout_container));
} }
void AssistantDialogPlate::InitVoiceLayoutContainer() { void AssistantDialogPlate::InitVoiceLayoutContainer() {
voice_layout_container_ = new views::View(); auto voice_layout_container = std::make_unique<views::View>();
voice_layout_container_->SetPaintToLayer(); voice_layout_container->SetPaintToLayer();
voice_layout_container_->layer()->SetFillsBoundsOpaquely(false); voice_layout_container->layer()->SetFillsBoundsOpaquely(false);
voice_layout_container_->layer()->SetOpacity(0.f); voice_layout_container->layer()->SetOpacity(0.f);
views::BoxLayout* layout_manager = voice_layout_container_->SetLayoutManager( views::BoxLayout* layout_manager = voice_layout_container->SetLayoutManager(
std::make_unique<views::BoxLayout>( std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kHorizontal)); views::BoxLayout::Orientation::kHorizontal));
...@@ -382,38 +384,38 @@ void AssistantDialogPlate::InitVoiceLayoutContainer() { ...@@ -382,38 +384,38 @@ void AssistantDialogPlate::InitVoiceLayoutContainer() {
constexpr int difference = constexpr int difference =
/*keyboard_input_toggle_width=*/kButtonSizeDip - /*keyboard_input_toggle_width=*/kButtonSizeDip -
/*molecule_icon_width=*/kIconSizeDip; /*molecule_icon_width=*/kIconSizeDip;
views::View* offset = new views::View(); auto offset = std::make_unique<views::View>();
offset->SetPreferredSize(gfx::Size(difference, 1)); offset->SetPreferredSize(gfx::Size(difference, 1));
voice_layout_container_->AddChildView(offset); voice_layout_container->AddChildView(std::move(offset));
// Spacer. // Spacer.
views::View* spacer = new views::View(); auto spacer = std::make_unique<views::View>();
voice_layout_container_->AddChildView(spacer); layout_manager->SetFlexForView(
layout_manager->SetFlexForView(spacer, 1); voice_layout_container->AddChildView(std::move(spacer)), 1);
// Animated voice input toggle. // Animated voice input toggle.
animated_voice_input_toggle_ = auto animated_voice_input_toggle = std::make_unique<MicView>(
new MicView(this, delegate_, AssistantButtonId::kVoiceInputToggle); this, delegate_, AssistantButtonId::kVoiceInputToggle);
animated_voice_input_toggle_->SetID(AssistantViewID::kMicView); animated_voice_input_toggle->SetID(AssistantViewID::kMicView);
animated_voice_input_toggle_->SetAccessibleName( animated_voice_input_toggle->SetAccessibleName(
l10n_util::GetStringUTF16(IDS_ASH_ASSISTANT_DIALOG_PLATE_MIC_ACCNAME)); l10n_util::GetStringUTF16(IDS_ASH_ASSISTANT_DIALOG_PLATE_MIC_ACCNAME));
voice_layout_container_->AddChildView(animated_voice_input_toggle_); animated_voice_input_toggle_ = voice_layout_container->AddChildView(
std::move(animated_voice_input_toggle));
// Spacer. // Spacer.
spacer = new views::View(); layout_manager->SetFlexForView(
voice_layout_container_->AddChildView(spacer); voice_layout_container->AddChildView(std::make_unique<views::View>()), 1);
layout_manager->SetFlexForView(spacer, 1);
// Keyboard input toggle. // Keyboard input toggle.
keyboard_input_toggle_ = keyboard_input_toggle_ = voice_layout_container->AddChildView(
AssistantButton::Create(this, kKeyboardIcon, kButtonSizeDip, kIconSizeDip, AssistantButton::Create(this, kKeyboardIcon, kButtonSizeDip, kIconSizeDip,
IDS_ASH_ASSISTANT_DIALOG_PLATE_KEYBOARD_ACCNAME, IDS_ASH_ASSISTANT_DIALOG_PLATE_KEYBOARD_ACCNAME,
AssistantButtonId::kKeyboardInputToggle, AssistantButtonId::kKeyboardInputToggle,
IDS_ASH_ASSISTANT_DIALOG_PLATE_KEYBOARD_TOOLTIP); IDS_ASH_ASSISTANT_DIALOG_PLATE_KEYBOARD_TOOLTIP));
keyboard_input_toggle_->SetID(AssistantViewID::kKeyboardInputToggle); keyboard_input_toggle_->SetID(AssistantViewID::kKeyboardInputToggle);
voice_layout_container_->AddChildView(keyboard_input_toggle_);
input_modality_layout_container_->AddChildView(voice_layout_container_); voice_layout_container_ = input_modality_layout_container_->AddChildView(
std::move(voice_layout_container));
} }
void AssistantDialogPlate::UpdateModalityVisibility() { void AssistantDialogPlate::UpdateModalityVisibility() {
......
...@@ -90,14 +90,15 @@ class APP_LIST_EXPORT AssistantDialogPlate ...@@ -90,14 +90,15 @@ class APP_LIST_EXPORT AssistantDialogPlate
AssistantViewDelegate* const delegate_; AssistantViewDelegate* const delegate_;
LogoView* molecule_icon_; // Owned by view hierarchy. // The following views are all owned by the view hierarchy
views::View* input_modality_layout_container_; // Owned by view hierarchy. LogoView* molecule_icon_ = nullptr;
views::View* keyboard_layout_container_; // Owned by view hierarchy. views::View* input_modality_layout_container_ = nullptr;
views::View* voice_layout_container_; // Owned by view hierarchy. views::View* keyboard_layout_container_ = nullptr;
views::ImageButton* keyboard_input_toggle_; // Owned by view hierarchy. views::View* voice_layout_container_ = nullptr;
views::ImageButton* voice_input_toggle_; // Owned by view hierarchy. views::ImageButton* keyboard_input_toggle_ = nullptr;
MicView* animated_voice_input_toggle_; // Owned by view hierarchy. views::ImageButton* voice_input_toggle_ = nullptr;
views::Textfield* textfield_; // Owned by view hierarchy. MicView* animated_voice_input_toggle_ = nullptr;
views::Textfield* textfield_ = nullptr;
std::unique_ptr<ui::CallbackLayerAnimationObserver> animation_observer_; std::unique_ptr<ui::CallbackLayerAnimationObserver> animation_observer_;
std::unique_ptr<AssistantQueryHistory::Iterator> query_history_iterator_; std::unique_ptr<AssistantQueryHistory::Iterator> query_history_iterator_;
......
...@@ -51,15 +51,16 @@ AssistantButton::AssistantButton(AssistantButtonListener* listener, ...@@ -51,15 +51,16 @@ AssistantButton::AssistantButton(AssistantButtonListener* listener,
AssistantButton::~AssistantButton() = default; AssistantButton::~AssistantButton() = default;
// static // static
AssistantButton* AssistantButton::Create(AssistantButtonListener* listener, std::unique_ptr<AssistantButton> AssistantButton::Create(
const gfx::VectorIcon& icon, AssistantButtonListener* listener,
int size_in_dip, const gfx::VectorIcon& icon,
int icon_size_in_dip, int size_in_dip,
int accessible_name_id, int icon_size_in_dip,
AssistantButtonId button_id, int accessible_name_id,
base::Optional<int> tooltip_id, AssistantButtonId button_id,
SkColor icon_color) { base::Optional<int> tooltip_id,
auto* button = new AssistantButton(listener, button_id); SkColor icon_color) {
auto button = std::make_unique<AssistantButton>(listener, button_id);
button->SetAccessibleName(l10n_util::GetStringUTF16(accessible_name_id)); button->SetAccessibleName(l10n_util::GetStringUTF16(accessible_name_id));
if (tooltip_id) if (tooltip_id)
......
...@@ -36,14 +36,15 @@ class COMPONENT_EXPORT(ASSISTANT_UI) AssistantButton ...@@ -36,14 +36,15 @@ class COMPONENT_EXPORT(ASSISTANT_UI) AssistantButton
~AssistantButton() override; ~AssistantButton() override;
// Creates a button with the default Assistant styles. // Creates a button with the default Assistant styles.
static AssistantButton* Create(AssistantButtonListener* listener, static std::unique_ptr<AssistantButton> Create(
const gfx::VectorIcon& icon, AssistantButtonListener* listener,
int size_in_dip, const gfx::VectorIcon& icon,
int icon_size_in_dip, int size_in_dip,
int accessible_name_id, int icon_size_in_dip,
AssistantButtonId button_id, int accessible_name_id,
base::Optional<int> tooltip_id = base::nullopt, AssistantButtonId button_id,
SkColor icon_color = gfx::kGoogleGrey700); base::Optional<int> tooltip_id = base::nullopt,
SkColor icon_color = gfx::kGoogleGrey700);
AssistantButtonId GetAssistantButtonId() const { return id_; } AssistantButtonId GetAssistantButtonId() const { return id_; }
......
...@@ -29,10 +29,11 @@ constexpr int kVectorIconSizeDip = 12; ...@@ -29,10 +29,11 @@ constexpr int kVectorIconSizeDip = 12;
// CaptionButton --------------------------------------------------------------- // CaptionButton ---------------------------------------------------------------
AssistantButton* CreateCaptionButton(const gfx::VectorIcon& icon, std::unique_ptr<AssistantButton> CreateCaptionButton(
int accessible_name_id, const gfx::VectorIcon& icon,
AssistantButtonId button_id, int accessible_name_id,
AssistantButtonListener* listener) { AssistantButtonId button_id,
AssistantButtonListener* listener) {
return AssistantButton::Create(listener, icon, kCaptionButtonSizeDip, return AssistantButton::Create(listener, icon, kCaptionButtonSizeDip,
kVectorIconSizeDip, accessible_name_id, kVectorIconSizeDip, accessible_name_id,
button_id); button_id);
...@@ -123,10 +124,8 @@ void CaptionBar::InitLayout() { ...@@ -123,10 +124,8 @@ void CaptionBar::InitLayout() {
AssistantButtonId::kBack, this)); AssistantButtonId::kBack, this));
// Spacer. // Spacer.
views::View* spacer = new views::View(); auto spacer = std::make_unique<views::View>();
AddChildView(spacer); layout_manager->SetFlexForView(AddChildView(std::move(spacer)), 1);
layout_manager->SetFlexForView(spacer, 1);
// Minimize. // Minimize.
AddButton(CreateCaptionButton(views::kWindowControlMinimizeIcon, AddButton(CreateCaptionButton(views::kWindowControlMinimizeIcon,
...@@ -139,9 +138,9 @@ void CaptionBar::InitLayout() { ...@@ -139,9 +138,9 @@ void CaptionBar::InitLayout() {
AssistantButtonId::kClose, this)); AssistantButtonId::kClose, this));
} }
void CaptionBar::AddButton(AssistantButton* button) { void CaptionBar::AddButton(std::unique_ptr<AssistantButton> button) {
buttons_.push_back(button); buttons_.push_back(button.get());
AddChildView(button); AddChildView(std::move(button));
} }
void CaptionBar::HandleButton(AssistantButtonId id) { void CaptionBar::HandleButton(AssistantButtonId id) {
......
...@@ -69,7 +69,7 @@ class COMPONENT_EXPORT(ASSISTANT_UI) CaptionBar : public views::View, ...@@ -69,7 +69,7 @@ class COMPONENT_EXPORT(ASSISTANT_UI) CaptionBar : public views::View,
private: private:
void InitLayout(); void InitLayout();
void AddButton(AssistantButton* button); void AddButton(std::unique_ptr<AssistantButton> button);
void HandleButton(AssistantButtonId id); void HandleButton(AssistantButtonId id);
AssistantButton* GetButtonWithId(AssistantButtonId id); AssistantButton* GetButtonWithId(AssistantButtonId id);
......
...@@ -278,12 +278,11 @@ void DialogPlate::InitLayout() { ...@@ -278,12 +278,11 @@ void DialogPlate::InitLayout() {
InitVoiceLayoutContainer(); InitVoiceLayoutContainer();
// Settings. // Settings.
settings_button_ = AssistantButton::Create( settings_button_ = AddChildView(AssistantButton::Create(
this, kSettingsIcon, kButtonSizeDip, kIconSizeDip, this, kSettingsIcon, kButtonSizeDip, kIconSizeDip,
IDS_ASH_ASSISTANT_DIALOG_PLATE_SETTINGS_ACCNAME_TOOLTIP, IDS_ASH_ASSISTANT_DIALOG_PLATE_SETTINGS_ACCNAME_TOOLTIP,
AssistantButtonId::kSettings, AssistantButtonId::kSettings,
IDS_ASH_ASSISTANT_DIALOG_PLATE_SETTINGS_ACCNAME_TOOLTIP); IDS_ASH_ASSISTANT_DIALOG_PLATE_SETTINGS_ACCNAME_TOOLTIP));
AddChildView(settings_button_);
// Artificially trigger event to set initial state. // Artificially trigger event to set initial state.
OnInputModalityChanged(delegate_->GetInteractionModel()->input_modality()); OnInputModalityChanged(delegate_->GetInteractionModel()->input_modality());
...@@ -328,12 +327,11 @@ void DialogPlate::InitKeyboardLayoutContainer() { ...@@ -328,12 +327,11 @@ void DialogPlate::InitKeyboardLayoutContainer() {
layout_manager->SetFlexForView(textfield_, 1); layout_manager->SetFlexForView(textfield_, 1);
// Voice input toggle. // Voice input toggle.
voice_input_toggle_ = voice_input_toggle_ = keyboard_layout_container_->AddChildView(
AssistantButton::Create(this, kMicIcon, kButtonSizeDip, kIconSizeDip, AssistantButton::Create(this, kMicIcon, kButtonSizeDip, kIconSizeDip,
IDS_ASH_ASSISTANT_DIALOG_PLATE_MIC_ACCNAME, IDS_ASH_ASSISTANT_DIALOG_PLATE_MIC_ACCNAME,
AssistantButtonId::kVoiceInputToggle, AssistantButtonId::kVoiceInputToggle,
IDS_ASH_ASSISTANT_DIALOG_PLATE_MIC_TOOLTIP); IDS_ASH_ASSISTANT_DIALOG_PLATE_MIC_TOOLTIP));
keyboard_layout_container_->AddChildView(voice_input_toggle_);
input_modality_layout_container_->AddChildView(keyboard_layout_container_); input_modality_layout_container_->AddChildView(keyboard_layout_container_);
} }
...@@ -354,12 +352,11 @@ void DialogPlate::InitVoiceLayoutContainer() { ...@@ -354,12 +352,11 @@ void DialogPlate::InitVoiceLayoutContainer() {
views::BoxLayout::CrossAxisAlignment::kCenter); views::BoxLayout::CrossAxisAlignment::kCenter);
// Keyboard input toggle. // Keyboard input toggle.
keyboard_input_toggle_ = keyboard_input_toggle_ = voice_layout_container_->AddChildView(
AssistantButton::Create(this, kKeyboardIcon, kButtonSizeDip, kIconSizeDip, AssistantButton::Create(this, kKeyboardIcon, kButtonSizeDip, kIconSizeDip,
IDS_ASH_ASSISTANT_DIALOG_PLATE_KEYBOARD_ACCNAME, IDS_ASH_ASSISTANT_DIALOG_PLATE_KEYBOARD_ACCNAME,
AssistantButtonId::kKeyboardInputToggle, AssistantButtonId::kKeyboardInputToggle,
IDS_ASH_ASSISTANT_DIALOG_PLATE_KEYBOARD_TOOLTIP); IDS_ASH_ASSISTANT_DIALOG_PLATE_KEYBOARD_TOOLTIP));
voice_layout_container_->AddChildView(keyboard_input_toggle_);
// Spacer. // Spacer.
views::View* spacer = new views::View(); views::View* spacer = new views::View();
......
...@@ -76,7 +76,8 @@ void AssistantFooterView::InitLayout() { ...@@ -76,7 +76,8 @@ void AssistantFooterView::InitLayout() {
chromeos::assistant::prefs::ConsentStatus::kActivityControlAccepted; chromeos::assistant::prefs::ConsentStatus::kActivityControlAccepted;
// Suggestion container. // Suggestion container.
suggestion_container_ = new SuggestionContainerView(delegate_); suggestion_container_ =
AddChildView(std::make_unique<SuggestionContainerView>(delegate_));
suggestion_container_->set_can_process_events_within_subtree(consent_given); suggestion_container_->set_can_process_events_within_subtree(consent_given);
// Suggestion container will be animated on its own layer. // Suggestion container will be animated on its own layer.
...@@ -85,10 +86,9 @@ void AssistantFooterView::InitLayout() { ...@@ -85,10 +86,9 @@ void AssistantFooterView::InitLayout() {
suggestion_container_->layer()->SetOpacity(consent_given ? 1.f : 0.f); suggestion_container_->layer()->SetOpacity(consent_given ? 1.f : 0.f);
suggestion_container_->SetVisible(consent_given); suggestion_container_->SetVisible(consent_given);
AddChildView(suggestion_container_);
// Opt in view. // Opt in view.
opt_in_view_ = new AssistantOptInView(delegate_); opt_in_view_ = AddChildView(std::make_unique<AssistantOptInView>(delegate_));
opt_in_view_->set_can_process_events_within_subtree(!consent_given); opt_in_view_->set_can_process_events_within_subtree(!consent_given);
// Opt in view will be animated on its own layer. // Opt in view will be animated on its own layer.
...@@ -96,8 +96,6 @@ void AssistantFooterView::InitLayout() { ...@@ -96,8 +96,6 @@ void AssistantFooterView::InitLayout() {
opt_in_view_->layer()->SetFillsBoundsOpaquely(false); opt_in_view_->layer()->SetFillsBoundsOpaquely(false);
opt_in_view_->layer()->SetOpacity(consent_given ? 0.f : 1.f); opt_in_view_->layer()->SetOpacity(consent_given ? 0.f : 1.f);
opt_in_view_->SetVisible(!consent_given); opt_in_view_->SetVisible(!consent_given);
AddChildView(opt_in_view_);
} }
void AssistantFooterView::OnAssistantConsentStatusChanged(int consent_status) { void AssistantFooterView::OnAssistantConsentStatusChanged(int consent_status) {
......
...@@ -193,21 +193,20 @@ void AssistantMainStage::InitContentLayoutContainer() { ...@@ -193,21 +193,20 @@ void AssistantMainStage::InitContentLayoutContainer() {
// preferred size and visibility change events in AssistantMainStage. This is // preferred size and visibility change events in AssistantMainStage. This is
// necessary because |content_layout_container_| may not change size in // necessary because |content_layout_container_| may not change size in
// response to these events, necessitating an explicit layout pass. // response to these events, necessitating an explicit layout pass.
content_layout_container_ = new views::View(); auto content_layout_container = std::make_unique<views::View>();
views::BoxLayout* layout_manager = views::BoxLayout* layout_manager = content_layout_container->SetLayoutManager(
content_layout_container_->SetLayoutManager( std::make_unique<views::BoxLayout>(
std::make_unique<views::BoxLayout>( views::BoxLayout::Orientation::kVertical));
views::BoxLayout::Orientation::kVertical));
// Header. // Header.
header_ = new AssistantHeaderView(delegate_); header_ = content_layout_container->AddChildView(
content_layout_container_->AddChildView(header_); std::make_unique<AssistantHeaderView>(delegate_));
// 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_);
layout_manager->SetFlexForView(ui_element_container_, 1, layout_manager->SetFlexForView(ui_element_container_, 1,
/*use_min_size=*/true); /*use_min_size=*/true);
...@@ -217,20 +216,20 @@ void AssistantMainStage::InitContentLayoutContainer() { ...@@ -217,20 +216,20 @@ void AssistantMainStage::InitContentLayoutContainer() {
// 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_); content_layout_container->AddChildView(std::move(footer_container));
content_layout_container_->AddChildView(footer_container);
AddChildView(content_layout_container_); content_layout_container_ = AddChildView(std::move(content_layout_container));
} }
void AssistantMainStage::InitQueryLayoutContainer() { void AssistantMainStage::InitQueryLayoutContainer() {
...@@ -238,12 +237,10 @@ void AssistantMainStage::InitQueryLayoutContainer() { ...@@ -238,12 +237,10 @@ void AssistantMainStage::InitQueryLayoutContainer() {
// preferred size and visibility change events in AssistantMainStage. This is // preferred size and visibility change events in AssistantMainStage. This is
// necessary because |query_layout_container_| may not change size in response // necessary because |query_layout_container_| may not change size in response
// to these events, thereby requiring an explicit layout pass. // to these events, thereby requiring an explicit layout pass.
query_layout_container_ = new views::View(); query_layout_container_ = AddChildView(std::make_unique<views::View>());
query_layout_container_->AddObserver(this); query_layout_container_->AddObserver(this);
query_layout_container_->set_can_process_events_within_subtree(false); query_layout_container_->set_can_process_events_within_subtree(false);
query_layout_container_->SetLayoutManager(std::make_unique<StackLayout>()); query_layout_container_->SetLayoutManager(std::make_unique<StackLayout>());
AddChildView(query_layout_container_);
} }
void AssistantMainStage::InitOverlayLayoutContainer() { void AssistantMainStage::InitOverlayLayoutContainer() {
...@@ -251,32 +248,32 @@ void AssistantMainStage::InitOverlayLayoutContainer() { ...@@ -251,32 +248,32 @@ void AssistantMainStage::InitOverlayLayoutContainer() {
// the content and query layout containers. As such, its children appear over // the content and query layout containers. As such, its children appear over
// top of and do not cause repositioning to any of content/query layout's // top of and do not cause repositioning to any of content/query layout's
// underlying views. Events pass through the overlay layout container. // underlying views. Events pass through the overlay layout container.
overlay_layout_container_ = new views::View(); auto overlay_layout_container = std::make_unique<views::View>();
overlay_layout_container_->set_can_process_events_within_subtree(false); overlay_layout_container->set_can_process_events_within_subtree(false);
auto* stack_layout = overlay_layout_container_->SetLayoutManager( auto* stack_layout = overlay_layout_container->SetLayoutManager(
std::make_unique<StackLayout>()); std::make_unique<StackLayout>());
// Greeting label. // Greeting label.
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_->SetAutoColorReadabilityEnabled(false); greeting_label->SetAutoColorReadabilityEnabled(false);
greeting_label_->SetBorder( greeting_label->SetBorder(
views::CreateEmptyBorder(kGreetingLabelMarginTopDip, 0, 0, 0)); views::CreateEmptyBorder(kGreetingLabelMarginTopDip, 0, 0, 0));
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);
// The greeting label will be animated on its own layer. // The greeting label will be animated on its own layer.
greeting_label_->SetPaintToLayer(); greeting_label->SetPaintToLayer();
greeting_label_->SetBackground(views::CreateSolidBackground(SK_ColorWHITE)); greeting_label->SetBackground(views::CreateSolidBackground(SK_ColorWHITE));
overlay_layout_container_->AddChildView(greeting_label_); greeting_label_ =
overlay_layout_container->AddChildView(std::move(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
...@@ -285,18 +282,19 @@ void AssistantMainStage::InitOverlayLayoutContainer() { ...@@ -285,18 +282,19 @@ void AssistantMainStage::InitOverlayLayoutContainer() {
greeting_label_, StackLayout::RespectDimension::kHeight); greeting_label_, StackLayout::RespectDimension::kHeight);
// Progress indicator. // Progress indicator.
progress_indicator_ = new AssistantProgressIndicator(); auto progress_indicator = std::make_unique<AssistantProgressIndicator>();
progress_indicator_->SetBorder( progress_indicator->SetBorder(
views::CreateEmptyBorder(kProgressIndicatorMarginTopDip, 0, 0, 0)); views::CreateEmptyBorder(kProgressIndicatorMarginTopDip, 0, 0, 0));
// The progress indicator will be animated on its own layer. // The progress indicator will be animated on its own layer.
progress_indicator_->SetPaintToLayer(); progress_indicator->SetPaintToLayer();
progress_indicator_->layer()->SetFillsBoundsOpaquely(false); progress_indicator->layer()->SetFillsBoundsOpaquely(false);
progress_indicator_->layer()->SetOpacity(0.f); progress_indicator->layer()->SetOpacity(0.f);
overlay_layout_container_->AddChildView(progress_indicator_); progress_indicator_ =
overlay_layout_container->AddChildView(std::move(progress_indicator));
AddChildView(overlay_layout_container_); overlay_layout_container_ = AddChildView(std::move(overlay_layout_container));
} }
void AssistantMainStage::OnCommittedQueryChanged(const AssistantQuery& query) { void AssistantMainStage::OnCommittedQueryChanged(const AssistantQuery& query) {
...@@ -458,15 +456,14 @@ void AssistantMainStage::OnPendingQueryChanged(const AssistantQuery& query) { ...@@ -458,15 +456,14 @@ void AssistantMainStage::OnPendingQueryChanged(const AssistantQuery& query) {
} }
if (!pending_query_view_) { if (!pending_query_view_) {
pending_query_view_ = new AssistantQueryView(); pending_query_view_ = query_layout_container_->AddChildView(
std::make_unique<AssistantQueryView>());
pending_query_view_->AddObserver(this); pending_query_view_->AddObserver(this);
// The query view will be animated on its own layer. // The query view will be animated on its own layer.
pending_query_view_->SetPaintToLayer(); pending_query_view_->SetPaintToLayer();
pending_query_view_->layer()->SetFillsBoundsOpaquely(false); pending_query_view_->layer()->SetFillsBoundsOpaquely(false);
query_layout_container_->AddChildView(pending_query_view_);
// Starting from 0% opacity... // Starting from 0% opacity...
pending_query_view_->layer()->SetOpacity(0.f); pending_query_view_->layer()->SetOpacity(0.f);
......
...@@ -93,13 +93,13 @@ class COMPONENT_EXPORT(ASSISTANT_UI) AssistantMainStage ...@@ -93,13 +93,13 @@ class COMPONENT_EXPORT(ASSISTANT_UI) AssistantMainStage
AssistantViewDelegate* const delegate_; // Owned by Shell. AssistantViewDelegate* const delegate_; // Owned by Shell.
// Content layout container and children. Owned by view hierarchy. // Content layout container and children. Owned by view hierarchy.
AssistantHeaderView* header_; AssistantHeaderView* header_ = nullptr;
views::View* content_layout_container_; views::View* content_layout_container_ = nullptr;
UiElementContainerView* ui_element_container_; UiElementContainerView* ui_element_container_ = nullptr;
AssistantFooterView* footer_; AssistantFooterView* footer_ = nullptr;
// Query layout container and children. Owned by view hierarchy. // Query layout container and children. Owned by view hierarchy.
views::View* query_layout_container_; views::View* query_layout_container_ = nullptr;
AssistantQueryView* active_query_view_ = nullptr; AssistantQueryView* active_query_view_ = nullptr;
AssistantQueryView* committed_query_view_ = nullptr; AssistantQueryView* committed_query_view_ = nullptr;
AssistantQueryView* pending_query_view_ = nullptr; AssistantQueryView* pending_query_view_ = nullptr;
......
...@@ -134,7 +134,8 @@ void AssistantOptInView::InitLayout() { ...@@ -134,7 +134,8 @@ void AssistantOptInView::InitLayout() {
views::BoxLayout::MainAxisAlignment::kCenter); views::BoxLayout::MainAxisAlignment::kCenter);
// Container. // Container.
container_ = new AssistantOptInContainer(/*listener=*/this); container_ = AddChildView(
std::make_unique<AssistantOptInContainer>(/*listener=*/this));
layout_manager = layout_manager =
container_->SetLayoutManager(std::make_unique<views::BoxLayout>( container_->SetLayoutManager(std::make_unique<views::BoxLayout>(
...@@ -144,14 +145,12 @@ void AssistantOptInView::InitLayout() { ...@@ -144,14 +145,12 @@ void AssistantOptInView::InitLayout() {
layout_manager->set_cross_axis_alignment( layout_manager->set_cross_axis_alignment(
views::BoxLayout::CrossAxisAlignment::kCenter); views::BoxLayout::CrossAxisAlignment::kCenter);
AddChildView(container_);
// Label. // Label.
label_ = new views::StyledLabel(base::string16(), /*listener=*/nullptr); label_ = container_->AddChildView(std::make_unique<views::StyledLabel>(
base::string16(), /*listener=*/nullptr));
label_->SetAutoColorReadabilityEnabled(false); label_->SetAutoColorReadabilityEnabled(false);
label_->SetHorizontalAlignment(gfx::HorizontalAlignment::ALIGN_CENTER); label_->SetHorizontalAlignment(gfx::HorizontalAlignment::ALIGN_CENTER);
container_->AddChildView(label_);
container_->SetFocusForPlatform(); container_->SetFocusForPlatform();
UpdateLabel(AssistantState::Get()->consent_status().value_or( UpdateLabel(AssistantState::Get()->consent_status().value_or(
......
...@@ -80,12 +80,12 @@ void AssistantQueryView::InitLayout() { ...@@ -80,12 +80,12 @@ void AssistantQueryView::InitLayout() {
views::BoxLayout::CrossAxisAlignment::kStretch); views::BoxLayout::CrossAxisAlignment::kStretch);
// Label. // Label.
label_ = new views::StyledLabel(base::string16(), /*listener=*/nullptr); label_ = AddChildView(std::make_unique<views::StyledLabel>(
base::string16(), /*listener=*/nullptr));
label_->SetAutoColorReadabilityEnabled(false); label_->SetAutoColorReadabilityEnabled(false);
label_->SetHorizontalAlignment(gfx::HorizontalAlignment::ALIGN_CENTER); label_->SetHorizontalAlignment(gfx::HorizontalAlignment::ALIGN_CENTER);
label_->SetLineHeight(kLineHeightDip); label_->SetLineHeight(kLineHeightDip);
label_->SetBackground(views::CreateSolidBackground(SK_ColorWHITE)); label_->SetBackground(views::CreateSolidBackground(SK_ColorWHITE));
AddChildView(label_);
} }
void AssistantQueryView::SetQuery(const AssistantQuery& query) { void AssistantQueryView::SetQuery(const AssistantQuery& query) {
......
...@@ -44,9 +44,7 @@ SuggestionChipView::Params::~Params() = default; ...@@ -44,9 +44,7 @@ SuggestionChipView::Params::~Params() = default;
SuggestionChipView::SuggestionChipView(const Params& params, SuggestionChipView::SuggestionChipView(const Params& params,
views::ButtonListener* listener) views::ButtonListener* listener)
: Button(listener), : Button(listener) {
icon_view_(new views::ImageView()),
text_view_(new views::Label()) {
// Configure focus. Note that we don't install the default focus ring as we // Configure focus. Note that we don't install the default focus ring as we
// use custom highlighting instead. // use custom highlighting instead.
SetFocusBehavior(FocusBehavior::ALWAYS); SetFocusBehavior(FocusBehavior::ALWAYS);
...@@ -89,6 +87,7 @@ void SuggestionChipView::InitLayout(const Params& params) { ...@@ -89,6 +87,7 @@ void SuggestionChipView::InitLayout(const Params& params) {
views::BoxLayout::CrossAxisAlignment::kCenter); views::BoxLayout::CrossAxisAlignment::kCenter);
// Icon. // Icon.
icon_view_ = AddChildView(std::make_unique<views::ImageView>());
const int icon_size = const int icon_size =
AppListConfig::instance().suggestion_chip_icon_dimension(); AppListConfig::instance().suggestion_chip_icon_dimension();
icon_view_->SetImageSize(gfx::Size(icon_size, icon_size)); icon_view_->SetImageSize(gfx::Size(icon_size, icon_size));
...@@ -99,16 +98,14 @@ void SuggestionChipView::InitLayout(const Params& params) { ...@@ -99,16 +98,14 @@ void SuggestionChipView::InitLayout(const Params& params) {
else else
icon_view_->SetVisible(false); icon_view_->SetVisible(false);
AddChildView(icon_view_);
// Text. // Text.
text_view_ = AddChildView(std::make_unique<views::Label>());
text_view_->SetAutoColorReadabilityEnabled(false); text_view_->SetAutoColorReadabilityEnabled(false);
text_view_->SetEnabledColor(kTextColor); text_view_->SetEnabledColor(kTextColor);
text_view_->SetSubpixelRenderingEnabled(false); text_view_->SetSubpixelRenderingEnabled(false);
text_view_->SetFontList( text_view_->SetFontList(
assistant::ui::GetDefaultFontList().DeriveWithSizeDelta(1)); assistant::ui::GetDefaultFontList().DeriveWithSizeDelta(1));
SetText(params.text); SetText(params.text);
AddChildView(text_view_);
} }
void SuggestionChipView::OnPaintBackground(gfx::Canvas* canvas) { void SuggestionChipView::OnPaintBackground(gfx::Canvas* canvas) {
......
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