Commit 7511f14a authored by David Black's avatar David Black Committed by Commit Bot

Remove animator implementations from UiElementContainerView.

This is part of a multi-CL effort to clean up the Assistant UI element
modeling/rendering pipeline. This CL simply moves the ElementAnimator
implementations that were previously in UiElementContaienrView into
AssistantUiElement. In the future, UiElementContainerView will have no
concept of AssistantTextElementView or AssistantCardElementView, it
will only understand AssistantUiElementView.

More details of the effort in the bug.

Bug: b:145003512
Change-Id: I0228556d5837f5466ca8fd5f9fc59c6ffd1239a3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1954666
Commit-Queue: David Black <dmblack@google.com>
Reviewed-by: default avatarXiaohui Chen <xiaohuic@chromium.org>
Cr-Commit-Position: refs/heads/master@{#726636}
parent 14d4b735
...@@ -89,6 +89,7 @@ component("ui") { ...@@ -89,6 +89,7 @@ component("ui") {
"main_stage/assistant_query_view.h", "main_stage/assistant_query_view.h",
"main_stage/assistant_text_element_view.cc", "main_stage/assistant_text_element_view.cc",
"main_stage/assistant_text_element_view.h", "main_stage/assistant_text_element_view.h",
"main_stage/assistant_ui_element_view.cc",
"main_stage/assistant_ui_element_view.h", "main_stage/assistant_ui_element_view.h",
"main_stage/element_animator.cc", "main_stage/element_animator.cc",
"main_stage/element_animator.h", "main_stage/element_animator.h",
......
...@@ -74,6 +74,10 @@ const char* AssistantCardElementView::GetClassName() const { ...@@ -74,6 +74,10 @@ const char* AssistantCardElementView::GetClassName() const {
return "AssistantCardElementView"; return "AssistantCardElementView";
} }
ui::Layer* AssistantCardElementView::GetLayerForAnimating() {
return native_view()->layer();
}
void AssistantCardElementView::AddedToWidget() { void AssistantCardElementView::AddedToWidget() {
aura::Window* const top_level_window = native_view()->GetToplevelWindow(); aura::Window* const top_level_window = native_view()->GetToplevelWindow();
......
...@@ -28,6 +28,7 @@ class COMPONENT_EXPORT(ASSISTANT_UI) AssistantCardElementView ...@@ -28,6 +28,7 @@ class COMPONENT_EXPORT(ASSISTANT_UI) AssistantCardElementView
// AssistantUiElementView: // AssistantUiElementView:
const char* GetClassName() const override; const char* GetClassName() const override;
ui::Layer* GetLayerForAnimating() override;
void AddedToWidget() override; void AddedToWidget() override;
void ChildPreferredSizeChanged(views::View* child) override; void ChildPreferredSizeChanged(views::View* child) override;
void AboutToRequestFocusFromTabTraversal(bool reverse) override; void AboutToRequestFocusFromTabTraversal(bool reverse) override;
......
...@@ -28,6 +28,10 @@ const char* AssistantTextElementView::GetClassName() const { ...@@ -28,6 +28,10 @@ const char* AssistantTextElementView::GetClassName() const {
return "AssistantTextElementView"; return "AssistantTextElementView";
} }
ui::Layer* AssistantTextElementView::GetLayerForAnimating() {
return layer();
}
void AssistantTextElementView::ChildPreferredSizeChanged(views::View* child) { void AssistantTextElementView::ChildPreferredSizeChanged(views::View* child) {
PreferredSizeChanged(); PreferredSizeChanged();
} }
......
...@@ -23,6 +23,7 @@ class COMPONENT_EXPORT(ASSISTANT_UI) AssistantTextElementView ...@@ -23,6 +23,7 @@ class COMPONENT_EXPORT(ASSISTANT_UI) AssistantTextElementView
// AssistantUiElementView: // AssistantUiElementView:
const char* GetClassName() const override; const char* GetClassName() const override;
ui::Layer* GetLayerForAnimating() override;
void ChildPreferredSizeChanged(views::View* child) override; void ChildPreferredSizeChanged(views::View* child) override;
private: private:
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/assistant/ui/main_stage/assistant_ui_element_view.h"
#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"
namespace ash {
namespace {
using assistant::util::CreateLayerAnimationSequence;
using assistant::util::CreateOpacityElement;
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 =
base::TimeDelta::FromMilliseconds(200);
constexpr base::TimeDelta kEmbeddedUiElementAnimationTranslateUpDuration =
base::TimeDelta::FromMilliseconds(250);
constexpr int kEmbeddedUiElementAnimationTranslateUpDistanceDip = 32;
// AssistantUiElementViewAnimator ----------------------------------------------
class AssistantUiElementViewAnimator : public ElementAnimator {
public:
explicit AssistantUiElementViewAnimator(AssistantUiElementView* view)
: ElementAnimator(view), view_(view) {}
explicit AssistantUiElementViewAnimator(
AssistantUiElementViewAnimator& copy) = delete;
AssistantUiElementViewAnimator& operator=(
AssistantUiElementViewAnimator& assign) = delete;
~AssistantUiElementViewAnimator() override = default;
// 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);
}
}
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);
}
}
ui::Layer* layer() const override { return view_->GetLayerForAnimating(); }
private:
void TranslateDown() const {
DCHECK(app_list_features::IsAssistantLauncherUIEnabled());
gfx::Transform transform;
transform.Translate(0, kEmbeddedUiElementAnimationTranslateUpDistanceDip);
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));
}
ui::LayerAnimationSequence* CreateTranslateUpAnimation() const {
DCHECK(app_list_features::IsAssistantLauncherUIEnabled());
return CreateLayerAnimationSequence(CreateTransformElement(
gfx::Transform(), kEmbeddedUiElementAnimationTranslateUpDuration,
gfx::Tween::Type::FAST_OUT_SLOW_IN));
}
AssistantUiElementView* const view_;
};
} // namespace
// AssistantUiElementView ------------------------------------------------------
AssistantUiElementView::AssistantUiElementView() = default;
AssistantUiElementView::~AssistantUiElementView() = default;
const char* AssistantUiElementView::GetClassName() const {
return "AssistantUiElementView";
}
std::unique_ptr<ElementAnimator> AssistantUiElementView::CreateAnimator() {
return std::make_unique<AssistantUiElementViewAnimator>(this);
}
} // namespace ash
...@@ -5,11 +5,15 @@ ...@@ -5,11 +5,15 @@
#ifndef ASH_ASSISTANT_UI_MAIN_STAGE_ASSISTANT_UI_ELEMENT_VIEW_H_ #ifndef ASH_ASSISTANT_UI_MAIN_STAGE_ASSISTANT_UI_ELEMENT_VIEW_H_
#define ASH_ASSISTANT_UI_MAIN_STAGE_ASSISTANT_UI_ELEMENT_VIEW_H_ #define ASH_ASSISTANT_UI_MAIN_STAGE_ASSISTANT_UI_ELEMENT_VIEW_H_
#include <memory>
#include "base/component_export.h" #include "base/component_export.h"
#include "ui/views/view.h" #include "ui/views/view.h"
namespace ash { namespace ash {
class ElementAnimator;
// Base class for a visual representation of an AssistantUiElement. It is a // Base class for a visual representation of an AssistantUiElement. It is a
// child view of UiElementContainerView. // child view of UiElementContainerView.
class COMPONENT_EXPORT(ASSISTANT_UI) AssistantUiElementView class COMPONENT_EXPORT(ASSISTANT_UI) AssistantUiElementView
...@@ -17,10 +21,20 @@ class COMPONENT_EXPORT(ASSISTANT_UI) AssistantUiElementView ...@@ -17,10 +21,20 @@ class COMPONENT_EXPORT(ASSISTANT_UI) AssistantUiElementView
public: public:
explicit AssistantUiElementView(AssistantUiElementView& copy) = delete; explicit AssistantUiElementView(AssistantUiElementView& copy) = delete;
AssistantUiElementView& operator=(AssistantUiElementView& assign) = delete; AssistantUiElementView& operator=(AssistantUiElementView& assign) = delete;
~AssistantUiElementView() override = default; ~AssistantUiElementView() override;
// views::View:
const char* GetClassName() const override;
// Returns the layer that should be used when animating this view.
virtual ui::Layer* GetLayerForAnimating() = 0;
// Returns a newly created animator which is used by UiElementContainerView
// to animate this view on/off stage in sync with Assistant response events.
virtual std::unique_ptr<ElementAnimator> CreateAnimator();
protected: protected:
AssistantUiElementView() = default; AssistantUiElementView();
}; };
} // namespace ash } // namespace ash
......
...@@ -18,14 +18,10 @@ ...@@ -18,14 +18,10 @@
#include "ash/assistant/ui/main_stage/assistant_card_element_view.h" #include "ash/assistant/ui/main_stage/assistant_card_element_view.h"
#include "ash/assistant/ui/main_stage/assistant_text_element_view.h" #include "ash/assistant/ui/main_stage/assistant_text_element_view.h"
#include "ash/assistant/ui/main_stage/element_animator.h" #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 "ash/public/cpp/app_list/app_list_features.h"
#include "base/callback.h" #include "base/callback.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "ui/aura/window.h" #include "ui/aura/window.h"
#include "ui/compositor/callback_layer_animation_observer.h"
#include "ui/compositor/layer_animation_element.h"
#include "ui/compositor/layer_animator.h"
#include "ui/views/border.h" #include "ui/views/border.h"
#include "ui/views/layout/box_layout.h" #include "ui/views/layout/box_layout.h"
...@@ -33,37 +29,12 @@ namespace ash { ...@@ -33,37 +29,12 @@ namespace ash {
namespace { namespace {
using assistant::util::CreateLayerAnimationSequence;
using assistant::util::CreateOpacityElement;
using assistant::util::CreateTransformElement;
using assistant::util::StartLayerAnimationSequence;
// Appearance. // Appearance.
constexpr int kEmbeddedUiFirstCardMarginTopDip = 8; constexpr int kEmbeddedUiFirstCardMarginTopDip = 8;
constexpr int kEmbeddedUiPaddingBottomDip = 8; constexpr int kEmbeddedUiPaddingBottomDip = 8;
constexpr int kMainUiFirstCardMarginTopDip = 40; constexpr int kMainUiFirstCardMarginTopDip = 40;
constexpr int kMainUiPaddingBottomDip = 24; constexpr int kMainUiPaddingBottomDip = 24;
// Main UI element 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);
// Text elements must fade out to 0 as the thinking dots will appear in the
// location of the first text element.
constexpr float kMainUiTextElementAnimationFadeOutOpacity = 0.f;
// Embedded UI element animation.
constexpr base::TimeDelta kEmbeddedUiElementAnimationFadeInDuration =
base::TimeDelta::FromMilliseconds(250);
constexpr base::TimeDelta kEmbeddedUiElementAnimationMoveUpDuration =
base::TimeDelta::FromMilliseconds(250);
constexpr base::TimeDelta kEmbeddedUiElementAnimationFadeOutDuration =
base::TimeDelta::FromMilliseconds(200);
constexpr int kEmbeddedUiElementAnimationMoveUpDistanceDip = 32;
// Helpers --------------------------------------------------------------------- // Helpers ---------------------------------------------------------------------
int GetFirstCardMarginTopDip() { int GetFirstCardMarginTopDip() {
...@@ -78,159 +49,6 @@ int GetPaddingBottomDip() { ...@@ -78,159 +49,6 @@ int GetPaddingBottomDip() {
: kMainUiPaddingBottomDip; : kMainUiPaddingBottomDip;
} }
// Animator for elements in the main (non-embedded) UI.
class MainUiAnimator : public ElementAnimator {
public:
using ElementAnimator::ElementAnimator;
~MainUiAnimator() override = default;
// ElementAnimator:
void AnimateOut(ui::CallbackLayerAnimationObserver* observer) override {
StartLayerAnimationSequence(
layer()->GetAnimator(),
CreateLayerAnimationSequence(CreateOpacityElement(
kMinimumAnimateOutOpacity, kMainUiElementAnimationFadeOutDuration,
gfx::Tween::Type::FAST_OUT_SLOW_IN)),
observer);
}
void AnimateIn(ui::CallbackLayerAnimationObserver* observer) override {
// We fade in the views to full opacity after a slight delay.
assistant::util::StartLayerAnimationSequence(
layer()->GetAnimator(),
CreateLayerAnimationSequence(
ui::LayerAnimationElement::CreatePauseElement(
ui::LayerAnimationElement::AnimatableProperty::OPACITY,
kMainUiElementAnimationFadeInDelay),
CreateOpacityElement(1.f, kMainUiElementAnimationFadeInDuration)),
observer);
}
private:
DISALLOW_COPY_AND_ASSIGN(MainUiAnimator);
};
// Animator used for card elements in the main (non-embedded) UI.
class MainUiCardAnimator : public MainUiAnimator {
public:
// Constructor used for card elements.
explicit MainUiCardAnimator(AssistantCardElementView* element)
: MainUiAnimator(element), element_(element) {}
ui::Layer* layer() const override { return element_->native_view()->layer(); }
private:
AssistantCardElementView* const element_;
DISALLOW_COPY_AND_ASSIGN(MainUiCardAnimator);
};
// Animator used for text elements in the main (non-embedded) UI.
class MainUiTextAnimator : public MainUiAnimator {
public:
// Constructor used for text elements.
explicit MainUiTextAnimator(AssistantTextElementView* element)
: MainUiAnimator(element) {}
void FadeOut(ui::CallbackLayerAnimationObserver* observer) override {
assistant::util::StartLayerAnimationSequence(
layer()->GetAnimator(),
assistant::util::CreateLayerAnimationSequence(
assistant::util::CreateOpacityElement(
kMainUiTextElementAnimationFadeOutOpacity, kFadeOutDuration)),
observer);
}
private:
DISALLOW_COPY_AND_ASSIGN(MainUiTextAnimator);
};
// Animator for elements in the embedded UI.
class EmbeddedUiAnimator : public ElementAnimator {
public:
using ElementAnimator::ElementAnimator;
~EmbeddedUiAnimator() override = default;
// ElementAnimator:
void AnimateOut(ui::CallbackLayerAnimationObserver* observer) override {
StartLayerAnimationSequence(
layer()->GetAnimator(),
CreateLayerAnimationSequence(
CreateOpacityElement(kMinimumAnimateOutOpacity,
kEmbeddedUiElementAnimationFadeOutDuration)),
observer);
}
void AnimateIn(ui::CallbackLayerAnimationObserver* observer) override {
// As part of the animation we will move up the element from the bottom
// so we need to start by moving it down.
MoveElementDown();
assistant::util::StartLayerAnimationSequencesTogether(
layer()->GetAnimator(),
{
CreateFadeInAnimation(),
CreateMoveUpAnimation(),
},
observer);
}
private:
void MoveElementDown() const {
gfx::Transform transform;
transform.Translate(0, kEmbeddedUiElementAnimationMoveUpDistanceDip);
layer()->SetTransform(transform);
}
ui::LayerAnimationSequence* CreateFadeInAnimation() const {
return CreateLayerAnimationSequence(
CreateOpacityElement(1.f, kEmbeddedUiElementAnimationFadeInDuration,
gfx::Tween::Type::FAST_OUT_SLOW_IN));
}
ui::LayerAnimationSequence* CreateMoveUpAnimation() const {
return CreateLayerAnimationSequence(CreateTransformElement(
gfx::Transform(), kEmbeddedUiElementAnimationMoveUpDuration,
gfx::Tween::Type::FAST_OUT_SLOW_IN));
}
DISALLOW_COPY_AND_ASSIGN(EmbeddedUiAnimator);
};
// Animator for card elements in the embedded UI.
class EmbeddedUiCardAnimator : public EmbeddedUiAnimator {
public:
// Constructor used for card elements.
explicit EmbeddedUiCardAnimator(AssistantCardElementView* element)
: EmbeddedUiAnimator(element), element_(element) {}
ui::Layer* layer() const override { return element_->native_view()->layer(); }
private:
AssistantCardElementView* const element_;
DISALLOW_COPY_AND_ASSIGN(EmbeddedUiCardAnimator);
};
// Animator for text elements in the embedded UI.
using EmbeddedUiTextAnimator = EmbeddedUiAnimator;
std::unique_ptr<ElementAnimator> CreateCardAnimator(
AssistantCardElementView* card_element) {
if (app_list_features::IsAssistantLauncherUIEnabled())
return std::make_unique<EmbeddedUiCardAnimator>(card_element);
else
return std::make_unique<MainUiCardAnimator>(card_element);
}
std::unique_ptr<ElementAnimator> CreateTextAnimator(
AssistantTextElementView* text_element) {
if (app_list_features::IsAssistantLauncherUIEnabled())
return std::make_unique<EmbeddedUiTextAnimator>(text_element);
else
return std::make_unique<MainUiTextAnimator>(text_element);
}
} // namespace } // namespace
// UiElementContainerView ------------------------------------------------------ // UiElementContainerView ------------------------------------------------------
...@@ -335,7 +153,7 @@ void UiElementContainerView::OnCardElementAdded( ...@@ -335,7 +153,7 @@ void UiElementContainerView::OnCardElementAdded(
card_element_view->native_view()->layer()->SetOpacity(0.f); card_element_view->native_view()->layer()->SetOpacity(0.f);
// We set the animator to handle all animations for this view. // We set the animator to handle all animations for this view.
AddElementAnimator(CreateCardAnimator(card_element_view)); AddElementAnimator(card_element_view->CreateAnimator());
} }
void UiElementContainerView::OnTextElementAdded( void UiElementContainerView::OnTextElementAdded(
...@@ -351,7 +169,7 @@ void UiElementContainerView::OnTextElementAdded( ...@@ -351,7 +169,7 @@ void UiElementContainerView::OnTextElementAdded(
content_view()->AddChildView(text_element_view); content_view()->AddChildView(text_element_view);
// We set the animator to handle all animations for this view. // We set the animator to handle all animations for this view.
AddElementAnimator(CreateTextAnimator(text_element_view)); AddElementAnimator(text_element_view->CreateAnimator());
} }
void UiElementContainerView::OnAllViewsRemoved() { void UiElementContainerView::OnAllViewsRemoved() {
......
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