| 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_OBSERVER_H_ | |
| 6 #define UI_GFX_COMPOSITOR_LAYER_ANIMATION_OBSERVER_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include <set> | |
| 10 | |
| 11 #include "base/basictypes.h" | |
| 12 #include "base/compiler_specific.h" | |
| 13 #include "ui/gfx/compositor/compositor_export.h" | |
| 14 | |
| 15 namespace ui { | |
| 16 | |
| 17 class LayerAnimationSequence; | |
| 18 class ScopedLayerAnimationSettings; | |
| 19 class ImplicitAnimationObserver; | |
| 20 | |
| 21 // LayerAnimationObservers are notified when animations complete. | |
| 22 class COMPOSITOR_EXPORT LayerAnimationObserver { | |
| 23 public: | |
| 24 // Called when the |sequence| ends. Not called if |sequence| is aborted. | |
| 25 virtual void OnLayerAnimationEnded( | |
| 26 LayerAnimationSequence* sequence) = 0; | |
| 27 | |
| 28 // Called if |sequence| is aborted for any reason. Should never do anything | |
| 29 // that may cause another animation to be started. | |
| 30 virtual void OnLayerAnimationAborted( | |
| 31 LayerAnimationSequence* sequence) = 0; | |
| 32 | |
| 33 // Called when the animation is scheduled. | |
| 34 virtual void OnLayerAnimationScheduled( | |
| 35 LayerAnimationSequence* sequence) = 0; | |
| 36 | |
| 37 protected: | |
| 38 typedef std::set<LayerAnimationSequence*> AttachedSequences; | |
| 39 | |
| 40 LayerAnimationObserver(); | |
| 41 virtual ~LayerAnimationObserver(); | |
| 42 | |
| 43 // If the animator is destroyed during an animation, the animations are | |
| 44 // aborted. The resulting NotifyAborted notifications will NOT be sent to | |
| 45 // this observer if this function returns false. NOTE: IF YOU OVERRIDE THIS | |
| 46 // FUNCTION TO RETURN TRUE, YOU MUST REMEMBER TO REMOVE YOURSELF AS AN | |
| 47 // OBSERVER WHEN YOU ARE DESTROYED. | |
| 48 virtual bool RequiresNotificationWhenAnimatorDestroyed() const; | |
| 49 | |
| 50 // Called when |this| is added to |sequence|'s observer list. | |
| 51 virtual void OnAttachedToSequence(LayerAnimationSequence* sequence); | |
| 52 | |
| 53 // Called when |this| is removed to |sequence|'s observer list. | |
| 54 virtual void OnDetachedFromSequence(LayerAnimationSequence* sequence); | |
| 55 | |
| 56 // Detaches this observer from all sequences it is currently observing. | |
| 57 void StopObserving(); | |
| 58 | |
| 59 const AttachedSequences& attached_sequences() const { | |
| 60 return attached_sequences_; | |
| 61 } | |
| 62 | |
| 63 private: | |
| 64 friend class LayerAnimationSequence; | |
| 65 | |
| 66 // Called when |this| is added to |sequence|'s observer list. | |
| 67 void AttachedToSequence(LayerAnimationSequence* sequence); | |
| 68 | |
| 69 // Called when |this| is removed to |sequence|'s observer list. | |
| 70 // This will only result in notifications if |send_notification| is true. | |
| 71 void DetachedFromSequence(LayerAnimationSequence* sequence, | |
| 72 bool send_notification); | |
| 73 | |
| 74 AttachedSequences attached_sequences_; | |
| 75 }; | |
| 76 | |
| 77 // An implicit animation observer is intended to be used in conjunction with a | |
| 78 // ScopedLayerAnimationSettings object in order to receive a notification when | |
| 79 // all implicit animations complete. | |
| 80 class COMPOSITOR_EXPORT ImplicitAnimationObserver | |
| 81 : public LayerAnimationObserver { | |
| 82 public: | |
| 83 ImplicitAnimationObserver(); | |
| 84 virtual ~ImplicitAnimationObserver(); | |
| 85 | |
| 86 virtual void OnImplicitAnimationsCompleted() = 0; | |
| 87 | |
| 88 protected: | |
| 89 // Deactivates the observer and clears the collection of animations it is | |
| 90 // waiting for. | |
| 91 void StopObservingImplicitAnimations(); | |
| 92 | |
| 93 private: | |
| 94 friend class ScopedLayerAnimationSettings; | |
| 95 | |
| 96 // LayerAnimationObserver implementation | |
| 97 virtual void OnLayerAnimationEnded( | |
| 98 LayerAnimationSequence* sequence) OVERRIDE; | |
| 99 virtual void OnLayerAnimationAborted( | |
| 100 LayerAnimationSequence* sequence) OVERRIDE; | |
| 101 virtual void OnLayerAnimationScheduled( | |
| 102 LayerAnimationSequence* sequence) OVERRIDE; | |
| 103 virtual void OnAttachedToSequence( | |
| 104 LayerAnimationSequence* sequence) OVERRIDE; | |
| 105 virtual void OnDetachedFromSequence( | |
| 106 LayerAnimationSequence* sequence) OVERRIDE; | |
| 107 | |
| 108 // OnImplicitAnimationsCompleted is not fired unless the observer is active. | |
| 109 bool active() const { return active_; } | |
| 110 void SetActive(bool active); | |
| 111 | |
| 112 void CheckCompleted(); | |
| 113 | |
| 114 bool active_; | |
| 115 }; | |
| 116 | |
| 117 } // namespace ui | |
| 118 | |
| 119 #endif // UI_GFX_COMPOSITOR_LAYER_ANIMATION_OBSERVER_H_ | |
| OLD | NEW |