Commit 362418a6 authored by Toni Barzic's avatar Toni Barzic Committed by Chromium LUCI CQ

Add bounce to tray icon preview drop animation

BUG=1142572

Change-Id: Iefc890de450ed2037e5755441f116df4aaeb01e5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2577726Reviewed-by: default avatarRobert Flack <flackr@chromium.org>
Reviewed-by: default avatarDavid Black <dmblack@google.com>
Commit-Queue: Toni Baržić <tbarzic@chromium.org>
Cr-Commit-Position: refs/heads/master@{#834876}
parent 767a05a5
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "ash/system/tray/tray_constants.h" #include "ash/system/tray/tray_constants.h"
#include "base/i18n/rtl.h" #include "base/i18n/rtl.h"
#include "ui/compositor/layer.h" #include "ui/compositor/layer.h"
#include "ui/compositor/layer_animation_sequence.h"
#include "ui/compositor/paint_recorder.h" #include "ui/compositor/paint_recorder.h"
#include "ui/compositor/scoped_layer_animation_settings.h" #include "ui/compositor/scoped_layer_animation_settings.h"
#include "ui/gfx/canvas.h" #include "ui/gfx/canvas.h"
...@@ -29,6 +30,15 @@ namespace { ...@@ -29,6 +30,15 @@ namespace {
// Appearance. // Appearance.
constexpr int kElevation = 2; constexpr int kElevation = 2;
// The duration of each of the preview icon bounce animation.
constexpr base::TimeDelta kBounceAnimationSegmentDuration =
base::TimeDelta::FromMilliseconds(250);
// The delay with which preview icon is dropped into the holding space tray
// icon.
constexpr base::TimeDelta kBounceAnimationBaseDelay =
base::TimeDelta::FromMilliseconds(150);
// Helpers --------------------------------------------------------------------- // Helpers ---------------------------------------------------------------------
// Returns the shadow details to use when painting elevation. // Returns the shadow details to use when painting elevation.
...@@ -191,10 +201,31 @@ void HoldingSpaceTrayIconPreview::AnimateIn(size_t index) { ...@@ -191,10 +201,31 @@ void HoldingSpaceTrayIconPreview::AnimateIn(size_t index) {
parent->StackBelow(layer_.get(), children[children.size() - index - 1]); parent->StackBelow(layer_.get(), children[children.size() - index - 1]);
} }
ui::ScopedLayerAnimationSettings animation_settings(layer_->GetAnimator()); gfx::Transform mid_transform(transform_);
SetUpAnimation(&animation_settings); mid_transform.Translate(0, kTrayItemSize * 0.25f);
layer_->SetTransform(transform_); ui::ScopedLayerAnimationSettings scoped_settings(layer_->GetAnimator());
scoped_settings.SetPreemptionStrategy(
ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
std::unique_ptr<ui::LayerAnimationSequence> sequence =
std::make_unique<ui::LayerAnimationSequence>();
sequence->AddElement(ui::LayerAnimationElement::CreatePauseElement(
ui::LayerAnimationElement::TRANSFORM, kBounceAnimationBaseDelay));
std::unique_ptr<ui::LayerAnimationElement> initial_drop =
ui::LayerAnimationElement::CreateTransformElement(
mid_transform, kBounceAnimationSegmentDuration);
initial_drop->set_tween_type(gfx::Tween::EASE_OUT_4);
sequence->AddElement(std::move(initial_drop));
std::unique_ptr<ui::LayerAnimationElement> rebound =
ui::LayerAnimationElement::CreateTransformElement(
transform_, kBounceAnimationSegmentDuration);
rebound->set_tween_type(gfx::Tween::FAST_OUT_SLOW_IN_3);
sequence->AddElement(std::move(rebound));
layer_->GetAnimator()->StartAnimation(sequence.release());
} }
void HoldingSpaceTrayIconPreview::AnimateOut( void HoldingSpaceTrayIconPreview::AnimateOut(
......
...@@ -45,6 +45,9 @@ double Tween::CalculateValue(Tween::Type type, double state) { ...@@ -45,6 +45,9 @@ double Tween::CalculateValue(Tween::Type type, double state) {
case EASE_OUT_3: case EASE_OUT_3:
return gfx::CubicBezier(0.6, 0, 0, 1).Solve(state); return gfx::CubicBezier(0.6, 0, 0, 1).Solve(state);
case EASE_OUT_4:
return gfx::CubicBezier(1, 0, 0.8, 1).Solve(state);
case LINEAR: case LINEAR:
return state; return state;
...@@ -63,6 +66,9 @@ double Tween::CalculateValue(Tween::Type type, double state) { ...@@ -63,6 +66,9 @@ double Tween::CalculateValue(Tween::Type type, double state) {
case FAST_OUT_SLOW_IN_2: case FAST_OUT_SLOW_IN_2:
return gfx::CubicBezier(0.2, 0, 0.2, 1).Solve(state); return gfx::CubicBezier(0.2, 0, 0.2, 1).Solve(state);
case FAST_OUT_SLOW_IN_3:
return gfx::CubicBezier(0.2, 0, 0, 1).Solve(state);
case LINEAR_OUT_SLOW_IN: case LINEAR_OUT_SLOW_IN:
return gfx::CubicBezier(0, 0, .2, 1).Solve(state); return gfx::CubicBezier(0, 0, .2, 1).Solve(state);
......
...@@ -26,6 +26,9 @@ class ANIMATION_EXPORT Tween { ...@@ -26,6 +26,9 @@ class ANIMATION_EXPORT Tween {
EASE_OUT, // Fast in, slow out (default). EASE_OUT, // Fast in, slow out (default).
EASE_OUT_2, // Variant of EASE_OUT that ends slower than EASE_OUT. EASE_OUT_2, // Variant of EASE_OUT that ends slower than EASE_OUT.
EASE_OUT_3, // Variant of EASE_OUT that ends slower than EASE_OUT_2. EASE_OUT_3, // Variant of EASE_OUT that ends slower than EASE_OUT_2.
EASE_OUT_4, // Variant of EASE_OUT that start slower than EASE_OUT_3,
// and ends faster. Best used to lead into a bounce
// animation.
EASE_IN, // Slow in, fast out. EASE_IN, // Slow in, fast out.
EASE_IN_2, // Variant of EASE_IN that starts out slower than EASE_IN_2, // Variant of EASE_IN that starts out slower than
// EASE_IN. // EASE_IN.
...@@ -36,6 +39,9 @@ class ANIMATION_EXPORT Tween { ...@@ -36,6 +39,9 @@ class ANIMATION_EXPORT Tween {
FAST_OUT_SLOW_IN, // Variant of EASE_IN_OUT which should be used in most FAST_OUT_SLOW_IN, // Variant of EASE_IN_OUT which should be used in most
// cases. // cases.
FAST_OUT_SLOW_IN_2, // Variant of FAST_OUT_SLOW_IN that starts out quicker. FAST_OUT_SLOW_IN_2, // Variant of FAST_OUT_SLOW_IN that starts out quicker.
FAST_OUT_SLOW_IN_3, // Variant of FAST_OUT_SLOW_IN that starts out quicker
// than FAST_OUT_SLOW_IN_2. Best used for rebound in
// bounce animation.
LINEAR_OUT_SLOW_IN, // Variant of EASE_OUT which should be used for LINEAR_OUT_SLOW_IN, // Variant of EASE_OUT which should be used for
// fading in from 0% or motion when entering a scene. // fading in from 0% or motion when entering a scene.
SLOW_OUT_LINEAR_IN, // Reverse of LINEAR_OUT_SLOW_IN which should be used SLOW_OUT_LINEAR_IN, // Reverse of LINEAR_OUT_SLOW_IN which should be used
......
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