Commit 628da15c authored by David Black's avatar David Black Committed by Commit Bot

Clean up AssistantUiElementView and UiElementContainerView.

Removes logic pertaining to standalone Assistant UI.

Bug: b:148080975, b:141947227
Change-Id: I276c3270cf28c0639230067cea08a101c90fce78
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2033666
Commit-Queue: David Black <dmblack@google.com>
Reviewed-by: default avatarXiaohui Chen <xiaohuic@chromium.org>
Cr-Commit-Position: refs/heads/master@{#737649}
parent 3e439752
......@@ -6,7 +6,6 @@
#include "ash/assistant/ui/main_stage/element_animator.h"
#include "ash/assistant/util/animation_util.h"
#include "ash/public/cpp/app_list/app_list_features.h"
#include "ui/compositor/callback_layer_animation_observer.h"
#include "ui/compositor/layer_animation_element.h"
#include "ui/compositor/layer_animator.h"
......@@ -21,22 +20,14 @@ using assistant::util::CreateTransformElement;
using assistant::util::StartLayerAnimationSequence;
using assistant::util::StartLayerAnimationSequencesTogether;
// Main UI animation.
constexpr base::TimeDelta kMainUiElementAnimationFadeInDelay =
base::TimeDelta::FromMilliseconds(83);
constexpr base::TimeDelta kMainUiElementAnimationFadeInDuration =
base::TimeDelta::FromMilliseconds(250);
constexpr base::TimeDelta kMainUiElementAnimationFadeOutDuration =
base::TimeDelta::FromMilliseconds(167);
// Embedded UI animation.
constexpr base::TimeDelta kEmbeddedUiElementAnimationFadeInDuration =
base::TimeDelta::FromMilliseconds(250);
constexpr base::TimeDelta kEmbeddedUiElementAnimationFadeOutDuration =
// Animation.
constexpr base::TimeDelta kAnimateOutDuration =
base::TimeDelta::FromMilliseconds(200);
constexpr base::TimeDelta kEmbeddedUiElementAnimationTranslateUpDuration =
constexpr base::TimeDelta kFadeInDuration =
base::TimeDelta::FromMilliseconds(250);
constexpr base::TimeDelta kTranslateUpDuration =
base::TimeDelta::FromMilliseconds(250);
constexpr int kEmbeddedUiElementAnimationTranslateUpDistanceDip = 32;
constexpr int kTranslateUpDistanceDip = 32;
// AssistantUiElementViewAnimator ----------------------------------------------
......@@ -52,86 +43,43 @@ class AssistantUiElementViewAnimator : public ElementAnimator {
// ElementAnimator:
void AnimateIn(ui::CallbackLayerAnimationObserver* observer) override {
if (app_list_features::IsAssistantLauncherUIEnabled()) {
// As part of the animation we will translate the element up from the
// bottom so we need to start by translating it down.
TranslateDown();
StartLayerAnimationSequencesTogether(layer()->GetAnimator(),
{
CreateFadeInAnimation(),
CreateTranslateUpAnimation(),
},
observer);
} else {
StartLayerAnimationSequence(
layer()->GetAnimator(),
CreateLayerAnimationSequence(
ui::LayerAnimationElement::CreatePauseElement(
ui::LayerAnimationElement::AnimatableProperty::OPACITY,
kMainUiElementAnimationFadeInDelay),
CreateOpacityElement(1.f, kMainUiElementAnimationFadeInDuration)),
observer);
}
// As part of the animation we will translate the element up from the
// bottom so we need to start by translating it down.
TranslateDown();
StartLayerAnimationSequencesTogether(layer()->GetAnimator(),
{
CreateFadeInAnimation(),
CreateTranslateUpAnimation(),
},
observer);
}
void AnimateOut(ui::CallbackLayerAnimationObserver* observer) override {
if (app_list_features::IsAssistantLauncherUIEnabled()) {
StartLayerAnimationSequence(
layer()->GetAnimator(),
CreateLayerAnimationSequence(
CreateOpacityElement(kMinimumAnimateOutOpacity,
kEmbeddedUiElementAnimationFadeOutDuration)),
observer);
} else {
StartLayerAnimationSequence(
layer()->GetAnimator(),
CreateLayerAnimationSequence(CreateOpacityElement(
kMinimumAnimateOutOpacity, kMainUiElementAnimationFadeOutDuration,
gfx::Tween::Type::FAST_OUT_SLOW_IN)),
observer);
}
}
// TODO(dmblack): Remove this override after deprecating standalone UI. It
// handles a one-off case for standalone UI that didn't seem worth abstracting
// out given that standalone UI is soon to be removed from the code base.
void FadeOut(ui::CallbackLayerAnimationObserver* observer) override {
if (!app_list_features::IsAssistantLauncherUIEnabled() &&
strcmp(view_->GetClassName(), "AssistantTextElementView") == 0) {
// Text elements in standalone UI must fade out completely as the thinking
// dots will appear in the location of the first text element.
StartLayerAnimationSequence(
layer()->GetAnimator(),
assistant::util::CreateLayerAnimationSequence(
assistant::util::CreateOpacityElement(0.f, kFadeOutDuration)),
observer);
} else {
ElementAnimator::FadeOut(observer);
}
StartLayerAnimationSequence(
layer()->GetAnimator(),
CreateLayerAnimationSequence(CreateOpacityElement(
kMinimumAnimateOutOpacity, kAnimateOutDuration)),
observer);
}
ui::Layer* layer() const override { return view_->GetLayerForAnimating(); }
private:
void TranslateDown() const {
DCHECK(app_list_features::IsAssistantLauncherUIEnabled());
gfx::Transform transform;
transform.Translate(0, kEmbeddedUiElementAnimationTranslateUpDistanceDip);
transform.Translate(0, kTranslateUpDistanceDip);
layer()->SetTransform(transform);
}
ui::LayerAnimationSequence* CreateFadeInAnimation() const {
DCHECK(app_list_features::IsAssistantLauncherUIEnabled());
return CreateLayerAnimationSequence(
CreateOpacityElement(1.f, kEmbeddedUiElementAnimationFadeInDuration,
gfx::Tween::Type::FAST_OUT_SLOW_IN));
return CreateLayerAnimationSequence(CreateOpacityElement(
1.f, kFadeInDuration, gfx::Tween::Type::FAST_OUT_SLOW_IN));
}
ui::LayerAnimationSequence* CreateTranslateUpAnimation() const {
DCHECK(app_list_features::IsAssistantLauncherUIEnabled());
return CreateLayerAnimationSequence(CreateTransformElement(
gfx::Transform(), kEmbeddedUiElementAnimationTranslateUpDuration,
gfx::Tween::Type::FAST_OUT_SLOW_IN));
return CreateLayerAnimationSequence(
CreateTransformElement(gfx::Transform(), kTranslateUpDuration,
gfx::Tween::Type::FAST_OUT_SLOW_IN));
}
AssistantUiElementView* const view_;
......
......@@ -8,16 +8,14 @@
#include "ash/assistant/model/assistant_interaction_model_observer.h"
#include "ash/assistant/model/assistant_response.h"
#include "ash/assistant/model/ui/assistant_card_element.h"
#include "ash/assistant/model/ui/assistant_ui_element.h"
#include "ash/assistant/ui/assistant_ui_constants.h"
#include "ash/assistant/ui/assistant_view_delegate.h"
#include "ash/assistant/ui/assistant_view_ids.h"
#include "ash/assistant/ui/main_stage/animated_container_view.h"
#include "ash/assistant/ui/main_stage/assistant_card_element_view.h"
#include "ash/assistant/ui/main_stage/assistant_ui_element_view.h"
#include "ash/assistant/ui/main_stage/assistant_ui_element_view_factory.h"
#include "ash/assistant/ui/main_stage/element_animator.h"
#include "ash/public/cpp/app_list/app_list_features.h"
#include "base/callback.h"
#include "base/time/time.h"
#include "cc/base/math_util.h"
......@@ -31,26 +29,9 @@ namespace ash {
namespace {
// Appearance.
constexpr int kEmbeddedUiFirstCardMarginTopDip = 8;
constexpr int kEmbeddedUiPaddingBottomDip = 8;
constexpr int kMainUiFirstCardMarginTopDip = 40;
constexpr int kMainUiPaddingBottomDip = 24;
constexpr int kPaddingBottomDip = 8;
constexpr int kScrollIndicatorHeightDip = 1;
// Helpers ---------------------------------------------------------------------
int GetFirstCardMarginTopDip() {
return app_list_features::IsAssistantLauncherUIEnabled()
? kEmbeddedUiFirstCardMarginTopDip
: kMainUiFirstCardMarginTopDip;
}
int GetPaddingBottomDip() {
return app_list_features::IsAssistantLauncherUIEnabled()
? kEmbeddedUiPaddingBottomDip
: kMainUiPaddingBottomDip;
}
} // namespace
// UiElementContainerView ------------------------------------------------------
......@@ -107,7 +88,7 @@ void UiElementContainerView::InitLayout() {
// Content.
content_view()->SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kVertical,
gfx::Insets(0, kUiElementHorizontalMarginDip, GetPaddingBottomDip(),
gfx::Insets(0, kUiElementHorizontalMarginDip, kPaddingBottomDip,
kUiElementHorizontalMarginDip),
kSpacingDip));
......@@ -137,67 +118,30 @@ void UiElementContainerView::OnCommittedQueryChanged(
const AssistantQuery& query) {
// Scroll to the top to play nice with the transition animation.
ScrollToPosition(vertical_scroll_bar(), 0);
AnimatedContainerView::OnCommittedQueryChanged(query);
}
void UiElementContainerView::HandleResponse(const AssistantResponse& response) {
for (const auto& ui_element : response.GetUiElements()) {
// TODO(dmblack): Remove after deprecating standalone UI.
if (ui_element->type() == AssistantUiElementType::kCard) {
OnCardElementAdded(
static_cast<const AssistantCardElement*>(ui_element.get()));
continue;
}
// Add a new view for the |ui_element| to the view hierarchy, bind an
// animator to handle all of its animations, and prepare its animation layer
// for the initial fade-in.
// Create a new view for the |ui_element|.
auto view = view_factory_->Create(ui_element.get());
// If the first UI element is a card, it has a unique margin requirement.
const bool is_card = ui_element->type() == AssistantUiElementType::kCard;
const bool is_first_ui_element = content_view()->children().empty();
if (is_card && is_first_ui_element) {
constexpr int kMarginTopDip = 24;
view->SetBorder(views::CreateEmptyBorder(kMarginTopDip, 0, 0, 0));
}
// Add the view to the view hierarchy and bind an animator to handle all of
// its animations. Note that we prepare its animation layer for entry.
auto* view_ptr = content_view()->AddChildView(std::move(view));
AddElementAnimator(view_ptr->CreateAnimator());
view_ptr->GetLayerForAnimating()->SetOpacity(0.f);
}
}
// TODO(dmblack): Remove after deprecating standalone UI.
void UiElementContainerView::OnCardElementAdded(
const AssistantCardElement* card_element) {
// The card, for some reason, is not embeddable so we'll have to ignore it.
if (!card_element->contents_view())
return;
auto* card_element_view =
new AssistantCardElementView(delegate(), card_element);
if (is_first_card_) {
is_first_card_ = false;
// The first card requires a top margin of |GetFirstCardMarginTopDip()|, but
// we need to account for child spacing because the first card is not
// necessarily the first UI element.
const int top_margin_dip =
GetFirstCardMarginTopDip() - (children().empty() ? 0 : kSpacingDip);
// We effectively create a top margin by applying an empty border.
card_element_view->SetBorder(
views::CreateEmptyBorder(top_margin_dip, 0, 0, 0));
}
content_view()->AddChildView(card_element_view);
// The view will be animated on its own layer, so we need to do some initial
// layer setup. We're going to fade the view in, so hide it.
card_element_view->native_view()->layer()->SetFillsBoundsOpaquely(false);
card_element_view->native_view()->layer()->SetOpacity(0.f);
// We set the animator to handle all animations for this view.
AddElementAnimator(card_element_view->CreateAnimator());
}
void UiElementContainerView::OnAllViewsRemoved() {
// Reset state for the next response.
is_first_card_ = true;
}
void UiElementContainerView::OnAllViewsAnimatedIn() {
// Let screen reader read the query result. This includes the text response
// and the card fallback text, but webview result is not included.
......
......@@ -19,7 +19,6 @@
namespace ash {
class AssistantResponse;
class AssistantCardElement;
class AssistantUiElementViewFactory;
class AssistantViewDelegate;
......@@ -46,7 +45,6 @@ class COMPONENT_EXPORT(ASSISTANT_UI) UiElementContainerView
// AnimatedContainerView:
void HandleResponse(const AssistantResponse& response) override;
void OnAllViewsRemoved() override;
void OnAllViewsAnimatedIn() override;
void OnScrollBarUpdated(views::ScrollBar* scroll_bar,
int viewport_size,
......@@ -55,8 +53,6 @@ class COMPONENT_EXPORT(ASSISTANT_UI) UiElementContainerView
void OnScrollBarVisibilityChanged(views::ScrollBar* scroll_bar,
bool is_visible) override;
void OnCardElementAdded(const AssistantCardElement* card_element);
void UpdateScrollIndicator(bool can_scroll);
views::View* scroll_indicator_ = nullptr; // Owned by view hierarchy.
......@@ -64,10 +60,6 @@ class COMPONENT_EXPORT(ASSISTANT_UI) UiElementContainerView
// Factory instance used to construct views for modeled UI elements.
std::unique_ptr<AssistantUiElementViewFactory> view_factory_;
// Whether or not the card we are adding is the first card for the current
// Assistant response. The first card requires the addition of a top margin.
bool is_first_card_ = true;
DISALLOW_COPY_AND_ASSIGN(UiElementContainerView);
};
......
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