1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
|
// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_ASSISTANT_UTIL_ANIMATION_UTIL_H_
#define ASH_ASSISTANT_UTIL_ANIMATION_UTIL_H_
#include <memory>
#include <optional>
#include <vector>
#include "base/component_export.h"
#include "base/functional/callback.h"
#include "ui/gfx/animation/tween.h"
namespace base {
class TimeDelta;
} // namespace base
namespace ui {
class LayerAnimationElement;
class LayerAnimationObserver;
class LayerAnimationSequence;
class LayerAnimator;
} // namespace ui
namespace views {
class View;
} // namespace views
namespace ash {
namespace assistant {
namespace util {
// Parameters for a LayerAnimationSequence.
struct LayerAnimationSequenceParams {
// True if the animation sequence should loop endlessly, false otherwise.
bool is_cyclic = false;
};
using AnimationSmoothnessCallback = base::RepeatingCallback<void(int)>;
// Creates a LayerAnimationSequence containing the specified
// LayerAnimationElements with the given |params|. The method caller assumes
// ownership of the returned pointer.
COMPONENT_EXPORT(ASSISTANT_UTIL)
::ui::LayerAnimationSequence* CreateLayerAnimationSequence(
std::unique_ptr<::ui::LayerAnimationElement> a,
const LayerAnimationSequenceParams& params = {});
// Creates a LayerAnimationSequence containing the specified
// LayerAnimationElements with the given |params|. The method caller assumes
// ownership of the returned pointer.
COMPONENT_EXPORT(ASSISTANT_UTIL)
::ui::LayerAnimationSequence* CreateLayerAnimationSequence(
std::unique_ptr<::ui::LayerAnimationElement> a,
std::unique_ptr<::ui::LayerAnimationElement> b,
const LayerAnimationSequenceParams& params = {});
// Creates a LayerAnimationSequence containing the specified
// LayerAnimationElements with the given |params|. The method caller assumes
// ownership of the returned pointer.
COMPONENT_EXPORT(ASSISTANT_UTIL)
::ui::LayerAnimationSequence* CreateLayerAnimationSequence(
std::unique_ptr<::ui::LayerAnimationElement> a,
std::unique_ptr<::ui::LayerAnimationElement> b,
std::unique_ptr<::ui::LayerAnimationElement> c,
const LayerAnimationSequenceParams& params = {});
// Creates a LayerAnimationSequence containing the specified
// LayerAnimationElements with the given |params|. The method caller assumes
// ownership of the returned pointer.
COMPONENT_EXPORT(ASSISTANT_UTIL)
::ui::LayerAnimationSequence* CreateLayerAnimationSequence(
std::unique_ptr<::ui::LayerAnimationElement> a,
std::unique_ptr<::ui::LayerAnimationElement> b,
std::unique_ptr<::ui::LayerAnimationElement> c,
std::unique_ptr<::ui::LayerAnimationElement> d,
const LayerAnimationSequenceParams& params = {});
// Creates a LayerAnimationElement to animate opacity with the given parameters.
COMPONENT_EXPORT(ASSISTANT_UTIL)
std::unique_ptr<::ui::LayerAnimationElement> CreateOpacityElement(
float opacity,
const base::TimeDelta& duration,
const gfx::Tween::Type& tween = gfx::Tween::Type::LINEAR);
// Creates a LayerAnimationElement to animate transform with the given
// parameters.
COMPONENT_EXPORT(ASSISTANT_UTIL)
std::unique_ptr<::ui::LayerAnimationElement> CreateTransformElement(
const gfx::Transform& transform,
const base::TimeDelta& duration,
const gfx::Tween::Type& tween = gfx::Tween::Type::LINEAR);
// Starts the specified |layer_animation_sequence| on the given
// |layer_animator|. If an optional |observer| is supplied, it will be added to
// the sequence. If an optional |smoothness_callback| is supplied, it
// will be attached to the animation to measure performance.
COMPONENT_EXPORT(ASSISTANT_UTIL)
void StartLayerAnimationSequence(
::ui::LayerAnimator* layer_animator,
::ui::LayerAnimationSequence* layer_animation_sequence,
::ui::LayerAnimationObserver* observer = nullptr,
std::optional<AnimationSmoothnessCallback> smoothness_callback =
std::nullopt);
// Starts the specified |layer_animation_sequence| on the layer of the given
// |view|. If an optional |observer| is supplied, it will be added to the
// sequence. If an optional |smoothness_callback| is supplied, it will be
// attached to the animation to measure performance.
COMPONENT_EXPORT(ASSISTANT_UTIL)
void StartLayerAnimationSequence(
views::View* view,
::ui::LayerAnimationSequence* layer_animation_sequence,
::ui::LayerAnimationObserver* observer = nullptr,
std::optional<AnimationSmoothnessCallback> animation_smoothness_callback =
std::nullopt);
// Starts the specified |layer_animation_sequences| together on the given
// |layer_animator|. If an optional |observer| is supplied, it will be added
// to each sequence in the animation set.
COMPONENT_EXPORT(ASSISTANT_UTIL)
void StartLayerAnimationSequencesTogether(
::ui::LayerAnimator* layer_animator,
const std::vector<::ui::LayerAnimationSequence*>& layer_animation_sequences,
::ui::LayerAnimationObserver* observer = nullptr);
// Starts the animation to fade out the given view, and hide it when the fadeout
// is completed.
COMPONENT_EXPORT(ASSISTANT_UTIL)
void FadeOutAndHide(views::View* view, base::TimeDelta fade_out_duration);
} // namespace util
} // namespace assistant
} // namespace ash
#endif // ASH_ASSISTANT_UTIL_ANIMATION_UTIL_H_
|