| OLD | NEW |
| (Empty) | |
| 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. |
| 4 |
| 5 #ifndef COMPONENTS_MUS_WS_SCHEDULED_ANIMATION_GROUP_H_ |
| 6 #define COMPONENTS_MUS_WS_SCHEDULED_ANIMATION_GROUP_H_ |
| 7 |
| 8 #include <memory> |
| 9 #include <vector> |
| 10 |
| 11 #include "base/time/time.h" |
| 12 #include "components/mus/public/interfaces/animations.mojom.h" |
| 13 #include "ui/gfx/animation/tween.h" |
| 14 #include "ui/gfx/transform.h" |
| 15 |
| 16 namespace mus { |
| 17 namespace ws { |
| 18 |
| 19 class ServerWindow; |
| 20 |
| 21 struct ScheduledAnimationValue { |
| 22 ScheduledAnimationValue(); |
| 23 ~ScheduledAnimationValue(); |
| 24 |
| 25 float float_value; |
| 26 gfx::Transform transform; |
| 27 }; |
| 28 |
| 29 struct ScheduledAnimationElement { |
| 30 ScheduledAnimationElement(); |
| 31 // Needed because we call resize() vector of elements. |
| 32 ScheduledAnimationElement(const ScheduledAnimationElement& other); |
| 33 ~ScheduledAnimationElement(); |
| 34 |
| 35 mojom::AnimationProperty property; |
| 36 base::TimeDelta duration; |
| 37 gfx::Tween::Type tween_type; |
| 38 bool is_start_valid; |
| 39 ScheduledAnimationValue start_value; |
| 40 ScheduledAnimationValue target_value; |
| 41 // Start time is based on scheduled time and relative to any other elements |
| 42 // in the sequence. |
| 43 base::TimeTicks start_time; |
| 44 }; |
| 45 |
| 46 struct ScheduledAnimationSequence { |
| 47 ScheduledAnimationSequence(); |
| 48 // Needed because we call resize() and erase() on vector of sequences. |
| 49 ScheduledAnimationSequence(const ScheduledAnimationSequence& other); |
| 50 ~ScheduledAnimationSequence(); |
| 51 |
| 52 bool run_until_stopped; |
| 53 std::vector<ScheduledAnimationElement> elements; |
| 54 |
| 55 // Sum of the duration of all elements. This does not take into account |
| 56 // |cycle_count|. |
| 57 base::TimeDelta duration; |
| 58 |
| 59 // The following values are updated as the animation progresses. |
| 60 |
| 61 // Number of cycles remaining. This is only used if |run_until_stopped| is |
| 62 // false. |
| 63 uint32_t cycle_count; |
| 64 |
| 65 // Index into |elements| of the element currently animating. |
| 66 size_t current_index; |
| 67 }; |
| 68 |
| 69 // Corresponds to a mojom::AnimationGroup and is responsible for running the |
| 70 // actual animation. |
| 71 class ScheduledAnimationGroup { |
| 72 public: |
| 73 ~ScheduledAnimationGroup(); |
| 74 |
| 75 // Returns a new ScheduledAnimationGroup from the supplied parameters, or |
| 76 // null if |transport_group| isn't valid. |
| 77 static std::unique_ptr<ScheduledAnimationGroup> Create( |
| 78 ServerWindow* window, |
| 79 base::TimeTicks now, |
| 80 uint32_t id, |
| 81 const mojom::AnimationGroup& transport_group); |
| 82 |
| 83 uint32_t id() const { return id_; } |
| 84 |
| 85 // Gets the start value for any elements that don't have an explicit start. |
| 86 // value. |
| 87 void ObtainStartValues(); |
| 88 |
| 89 // Sets the values of any properties that are not in |other| to their final |
| 90 // value. |
| 91 void SetValuesToTargetValuesForPropertiesNotIn( |
| 92 const ScheduledAnimationGroup& other); |
| 93 |
| 94 // Advances the group. |time| is the current time. Returns true if the group |
| 95 // is done (nothing left to animate). |
| 96 bool Tick(base::TimeTicks time); |
| 97 |
| 98 ServerWindow* window() { return window_; } |
| 99 |
| 100 private: |
| 101 ScheduledAnimationGroup(ServerWindow* window, |
| 102 uint32_t id, |
| 103 base::TimeTicks time_scheduled); |
| 104 |
| 105 ServerWindow* window_; |
| 106 const uint32_t id_; |
| 107 base::TimeTicks time_scheduled_; |
| 108 std::vector<ScheduledAnimationSequence> sequences_; |
| 109 |
| 110 DISALLOW_COPY_AND_ASSIGN(ScheduledAnimationGroup); |
| 111 }; |
| 112 |
| 113 } // namespace ws |
| 114 } // namespace mus |
| 115 |
| 116 #endif // COMPONENTS_MUS_WS_SCHEDULED_ANIMATION_GROUP_H_ |
| OLD | NEW |