| 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_COMPOSITOR_LAYER_ANIMATION_OBSERVER_H_ | |
| 6 #define UI_COMPOSITOR_LAYER_ANIMATION_OBSERVER_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 #include <set> | |
| 10 | |
| 11 #include "base/basictypes.h" | |
| 12 #include "base/compiler_specific.h" | |
| 13 #include "ui/compositor/compositor_export.h" | |
| 14 #include "ui/compositor/layer_animation_element.h" | |
| 15 | |
| 16 namespace ui { | |
| 17 | |
| 18 class LayerAnimationSequence; | |
| 19 class ScopedLayerAnimationSettings; | |
| 20 class ImplicitAnimationObserver; | |
| 21 | |
| 22 // LayerAnimationObservers are notified when animations complete. | |
| 23 class COMPOSITOR_EXPORT LayerAnimationObserver { | |
| 24 public: | |
| 25 // Called when the |sequence| ends. Not called if |sequence| is aborted. | |
| 26 virtual void OnLayerAnimationEnded( | |
| 27 LayerAnimationSequence* sequence) = 0; | |
| 28 | |
| 29 // Called if |sequence| is aborted for any reason. Should never do anything | |
| 30 // that may cause another animation to be started. | |
| 31 virtual void OnLayerAnimationAborted( | |
| 32 LayerAnimationSequence* sequence) = 0; | |
| 33 | |
| 34 // Called when the animation is scheduled. | |
| 35 virtual void OnLayerAnimationScheduled( | |
| 36 LayerAnimationSequence* sequence) = 0; | |
| 37 | |
| 38 protected: | |
| 39 typedef std::set<LayerAnimationSequence*> AttachedSequences; | |
| 40 | |
| 41 LayerAnimationObserver(); | |
| 42 virtual ~LayerAnimationObserver(); | |
| 43 | |
| 44 // If the animator is destroyed during an animation, the animations are | |
| 45 // aborted. The resulting NotifyAborted notifications will NOT be sent to | |
| 46 // this observer if this function returns false. NOTE: IF YOU override THIS | |
| 47 // FUNCTION TO RETURN TRUE, YOU MUST REMEMBER TO REMOVE YOURSELF AS AN | |
| 48 // OBSERVER WHEN YOU ARE DESTROYED. | |
| 49 virtual bool RequiresNotificationWhenAnimatorDestroyed() const; | |
| 50 | |
| 51 // Called when |this| is added to |sequence|'s observer list. | |
| 52 virtual void OnAttachedToSequence(LayerAnimationSequence* sequence); | |
| 53 | |
| 54 // Called when |this| is removed to |sequence|'s observer list. | |
| 55 virtual void OnDetachedFromSequence(LayerAnimationSequence* sequence); | |
| 56 | |
| 57 // Detaches this observer from all sequences it is currently observing. | |
| 58 void StopObserving(); | |
| 59 | |
| 60 const AttachedSequences& attached_sequences() const { | |
| 61 return attached_sequences_; | |
| 62 } | |
| 63 | |
| 64 private: | |
| 65 friend class LayerAnimationSequence; | |
| 66 | |
| 67 // Called when |this| is added to |sequence|'s observer list. | |
| 68 void AttachedToSequence(LayerAnimationSequence* sequence); | |
| 69 | |
| 70 // Called when |this| is removed to |sequence|'s observer list. | |
| 71 // This will only result in notifications if |send_notification| is true. | |
| 72 void DetachedFromSequence(LayerAnimationSequence* sequence, | |
| 73 bool send_notification); | |
| 74 | |
| 75 AttachedSequences attached_sequences_; | |
| 76 }; | |
| 77 | |
| 78 // An implicit animation observer is intended to be used in conjunction with a | |
| 79 // ScopedLayerAnimationSettings object in order to receive a notification when | |
| 80 // all implicit animations complete. | |
| 81 class COMPOSITOR_EXPORT ImplicitAnimationObserver | |
| 82 : public LayerAnimationObserver { | |
| 83 public: | |
| 84 ImplicitAnimationObserver(); | |
| 85 ~ImplicitAnimationObserver() override; | |
| 86 | |
| 87 // Called when the first animation sequence has started. | |
| 88 virtual void OnImplicitAnimationsScheduled() {} | |
| 89 | |
| 90 virtual void OnImplicitAnimationsCompleted() = 0; | |
| 91 | |
| 92 protected: | |
| 93 // Deactivates the observer and clears the collection of animations it is | |
| 94 // waiting for. | |
| 95 void StopObservingImplicitAnimations(); | |
| 96 | |
| 97 // Returns whether animation for |property| was aborted. | |
| 98 // Note that if the property wasn't animated, then it couldn't have been | |
| 99 // aborted, so this will return false for that property. | |
| 100 bool WasAnimationAbortedForProperty( | |
| 101 LayerAnimationElement::AnimatableProperty property) const; | |
| 102 | |
| 103 // Returns whether animation for |property| was completed successfully. | |
| 104 // Note that if the property wasn't animated, then it couldn't have been | |
| 105 // completed, so this will return false for that property. | |
| 106 bool WasAnimationCompletedForProperty( | |
| 107 LayerAnimationElement::AnimatableProperty property) const; | |
| 108 | |
| 109 private: | |
| 110 enum AnimationStatus { | |
| 111 ANIMATION_STATUS_UNKNOWN, | |
| 112 ANIMATION_STATUS_COMPLETED, | |
| 113 ANIMATION_STATUS_ABORTED, | |
| 114 }; | |
| 115 | |
| 116 friend class ScopedLayerAnimationSettings; | |
| 117 | |
| 118 // LayerAnimationObserver implementation | |
| 119 void OnLayerAnimationEnded(LayerAnimationSequence* sequence) override; | |
| 120 void OnLayerAnimationAborted(LayerAnimationSequence* sequence) override; | |
| 121 void OnLayerAnimationScheduled(LayerAnimationSequence* sequence) override; | |
| 122 void OnAttachedToSequence(LayerAnimationSequence* sequence) override; | |
| 123 void OnDetachedFromSequence(LayerAnimationSequence* sequence) override; | |
| 124 | |
| 125 // OnImplicitAnimationsCompleted is not fired unless the observer is active. | |
| 126 bool active() const { return active_; } | |
| 127 void SetActive(bool active); | |
| 128 | |
| 129 void CheckCompleted(); | |
| 130 | |
| 131 void UpdatePropertyAnimationStatus(LayerAnimationSequence* sequence, | |
| 132 AnimationStatus status); | |
| 133 AnimationStatus AnimationStatusForProperty( | |
| 134 LayerAnimationElement::AnimatableProperty property) const; | |
| 135 | |
| 136 bool active_; | |
| 137 | |
| 138 // Set to true in the destructor (if non-NULL). Used to detect deletion while | |
| 139 // calling out. | |
| 140 bool* destroyed_; | |
| 141 | |
| 142 typedef std::map<LayerAnimationElement::AnimatableProperty, | |
| 143 AnimationStatus> PropertyAnimationStatusMap; | |
| 144 PropertyAnimationStatusMap property_animation_status_; | |
| 145 | |
| 146 // True if OnLayerAnimationScheduled() has been called at least once. | |
| 147 bool first_sequence_scheduled_; | |
| 148 }; | |
| 149 | |
| 150 } // namespace ui | |
| 151 | |
| 152 #endif // UI_COMPOSITOR_LAYER_ANIMATION_OBSERVER_H_ | |
| OLD | NEW |