1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef COMPONENTS_VIEW_MANAGER_SCHEDULED_ANIMATION_GROUP_H_
6 #define COMPONENTS_VIEW_MANAGER_SCHEDULED_ANIMATION_GROUP_H_
10 #include "base/memory/scoped_ptr.h"
11 #include "base/time/time.h"
12 #include "components/view_manager/public/interfaces/animations.mojom.h"
13 #include "ui/gfx/animation/tween.h"
14 #include "ui/gfx/transform.h"
16 namespace view_manager
{
20 struct ScheduledAnimationValue
{
21 ScheduledAnimationValue();
22 ~ScheduledAnimationValue();
25 gfx::Transform transform
;
28 struct ScheduledAnimationElement
{
29 ScheduledAnimationElement();
30 ~ScheduledAnimationElement();
32 mojo::AnimationProperty property
;
33 base::TimeDelta duration
;
34 gfx::Tween::Type tween_type
;
36 ScheduledAnimationValue start_value
;
37 ScheduledAnimationValue target_value
;
38 // Start time is based on scheduled time and relative to any other elements
40 base::TimeTicks start_time
;
43 struct ScheduledAnimationSequence
{
44 ScheduledAnimationSequence();
45 ~ScheduledAnimationSequence();
47 bool run_until_stopped
;
48 std::vector
<ScheduledAnimationElement
> elements
;
50 // Sum of the duration of all elements. This does not take into account
52 base::TimeDelta duration
;
54 // The following values are updated as the animation progresses.
56 // Number of cycles remaining. This is only used if |run_until_stopped| is
60 // Index into |elements| of the element currently animating.
64 // Corresponds to a mojo::AnimationGroup and is responsible for running the
66 class ScheduledAnimationGroup
{
68 ~ScheduledAnimationGroup();
70 // Returns a new ScheduledAnimationGroup from the supplied parameters, or
71 // null if |transport_group| isn't valid.
72 static scoped_ptr
<ScheduledAnimationGroup
> Create(
76 const mojo::AnimationGroup
& transport_group
);
78 uint32_t id() const { return id_
; }
80 // Gets the start value for any elements that don't have an explicit start.
82 void ObtainStartValues();
84 // Sets the values of any properties that are not in |other| to their final
86 void SetValuesToTargetValuesForPropertiesNotIn(
87 const ScheduledAnimationGroup
& other
);
89 // Advances the group. |time| is the current time. Returns true if the group
90 // is done (nothing left to animate).
91 bool Tick(base::TimeTicks time
);
93 ServerView
* view() { return view_
; }
96 ScheduledAnimationGroup(ServerView
* view
,
98 base::TimeTicks time_scheduled
);
102 base::TimeTicks time_scheduled_
;
103 std::vector
<ScheduledAnimationSequence
> sequences_
;
105 DISALLOW_COPY_AND_ASSIGN(ScheduledAnimationGroup
);
108 } // namespace view_manager
110 #endif // COMPONENTS_VIEW_MANAGER_SCHEDULED_ANIMATION_GROUP_H_