| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 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 UI_GFX_COMPOSITOR_LAYER_ANIMATION_SEQUENCE_H_ | |
| 6 #define UI_GFX_COMPOSITOR_LAYER_ANIMATION_SEQUENCE_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include <vector> | |
| 10 | |
| 11 #include "base/gtest_prod_util.h" | |
| 12 #include "base/memory/linked_ptr.h" | |
| 13 #include "base/observer_list.h" | |
| 14 #include "base/time.h" | |
| 15 #include "ui/gfx/compositor/compositor_export.h" | |
| 16 #include "ui/gfx/compositor/layer_animation_element.h" | |
| 17 | |
| 18 namespace ui { | |
| 19 | |
| 20 class LayerAnimationDelegate; | |
| 21 class LayerAnimationObserver; | |
| 22 | |
| 23 // Contains a collection of layer animation elements to be played one after | |
| 24 // another. Although it has a similar interface to LayerAnimationElement, it is | |
| 25 // not a LayerAnimationElement (i.e., it is not permitted to have a sequence in | |
| 26 // a sequence). Sequences own their elements, and sequences are themselves owned | |
| 27 // by a LayerAnimator. | |
| 28 // | |
| 29 // TODO(vollick) Create a 'blended' sequence for transitioning between | |
| 30 // sequences. | |
| 31 class COMPOSITOR_EXPORT LayerAnimationSequence { | |
| 32 public: | |
| 33 LayerAnimationSequence(); | |
| 34 // Takes ownership of the given element and adds it to the sequence. | |
| 35 explicit LayerAnimationSequence(LayerAnimationElement* element); | |
| 36 virtual ~LayerAnimationSequence(); | |
| 37 | |
| 38 // Updates the delegate to the appropriate value for |elapsed|, which is in | |
| 39 // the range [0, Duration()]. If the animation is not aborted, it is | |
| 40 // guaranteed that Animate will be called with elapsed = Duration(). | |
| 41 // Returns true if a redraw is required. | |
| 42 bool Progress(base::TimeDelta elapsed, LayerAnimationDelegate* delegate); | |
| 43 | |
| 44 // Sets the target value to the value that would have been set had | |
| 45 // the sequence completed. Does nothing if the sequence is cyclic. | |
| 46 void GetTargetValue(LayerAnimationElement::TargetValue* target) const; | |
| 47 | |
| 48 // Aborts the given animation. | |
| 49 void Abort(); | |
| 50 | |
| 51 // All properties modified by the sequence. | |
| 52 const LayerAnimationElement::AnimatableProperties& properties() const { | |
| 53 return properties_; | |
| 54 } | |
| 55 | |
| 56 // The total, finite duration of one cycle of the sequence. | |
| 57 base::TimeDelta duration() const { | |
| 58 return duration_; | |
| 59 } | |
| 60 | |
| 61 // Adds an element to the sequence. The sequences takes ownership of this | |
| 62 // element. | |
| 63 void AddElement(LayerAnimationElement* element); | |
| 64 | |
| 65 // Sequences can be looped indefinitely. | |
| 66 void set_is_cyclic(bool is_cyclic) { is_cyclic_ = is_cyclic; } | |
| 67 bool is_cyclic() const { return is_cyclic_; } | |
| 68 | |
| 69 // Returns true if this sequence has at least one element affecting a | |
| 70 // property in |other|. | |
| 71 bool HasCommonProperty( | |
| 72 const LayerAnimationElement::AnimatableProperties& other) const; | |
| 73 | |
| 74 // These functions are used for adding or removing observers from the observer | |
| 75 // list. The observers are notified when animations end. | |
| 76 void AddObserver(LayerAnimationObserver* observer); | |
| 77 void RemoveObserver(LayerAnimationObserver* observer); | |
| 78 | |
| 79 // Called when the animator schedules this sequence. | |
| 80 void OnScheduled(); | |
| 81 | |
| 82 // Called when the animator is destroyed. | |
| 83 void OnAnimatorDestroyed(); | |
| 84 | |
| 85 private: | |
| 86 typedef std::vector<linked_ptr<LayerAnimationElement> > Elements; | |
| 87 | |
| 88 FRIEND_TEST_ALL_PREFIXES(LayerAnimatorTest, | |
| 89 ObserverReleasedBeforeAnimationSequenceEnds); | |
| 90 | |
| 91 // Notifies the observers that this sequence has been scheduled. | |
| 92 void NotifyScheduled(); | |
| 93 | |
| 94 // Notifies the observers that this sequence has ended. | |
| 95 void NotifyEnded(); | |
| 96 | |
| 97 // Notifies the observers that this sequence has been aborted. | |
| 98 void NotifyAborted(); | |
| 99 | |
| 100 // The sum of the durations of all the elements in the sequence. | |
| 101 base::TimeDelta duration_; | |
| 102 | |
| 103 // The union of all the properties modified by all elements in the sequence. | |
| 104 LayerAnimationElement::AnimatableProperties properties_; | |
| 105 | |
| 106 // The elements in the sequence. | |
| 107 Elements elements_; | |
| 108 | |
| 109 // True if the sequence should be looped forever. | |
| 110 bool is_cyclic_; | |
| 111 | |
| 112 // These are used when animating to efficiently find the next element. | |
| 113 size_t last_element_; | |
| 114 base::TimeDelta last_start_; | |
| 115 | |
| 116 // These parties are notified when layer animations end. | |
| 117 ObserverList<LayerAnimationObserver> observers_; | |
| 118 | |
| 119 DISALLOW_COPY_AND_ASSIGN(LayerAnimationSequence); | |
| 120 }; | |
| 121 | |
| 122 } // namespace ui | |
| 123 | |
| 124 #endif // UI_GFX_COMPOSITOR_LAYER_ANIMATION_SEQUENCE_H_ | |
| OLD | NEW |