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