Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(197)

Side by Side Diff: ui/compositor/layer_animation_observer.h

Issue 1369393002: Added a CallbackLayerAnimationObserver. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed concerns from patch set 8. Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/compositor/compositor.gyp ('k') | ui/compositor/test/layer_animation_observer_test_api.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef UI_COMPOSITOR_LAYER_ANIMATION_OBSERVER_H_ 5 #ifndef UI_COMPOSITOR_LAYER_ANIMATION_OBSERVER_H_
6 #define UI_COMPOSITOR_LAYER_ANIMATION_OBSERVER_H_ 6 #define UI_COMPOSITOR_LAYER_ANIMATION_OBSERVER_H_
7 7
8 #include <map> 8 #include <map>
9 #include <set> 9 #include <set>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
13 #include "ui/compositor/compositor_export.h" 13 #include "ui/compositor/compositor_export.h"
14 #include "ui/compositor/layer_animation_element.h" 14 #include "ui/compositor/layer_animation_element.h"
15 15
16 namespace ui { 16 namespace ui {
17 17
18 namespace test {
19 class LayerAnimationObserverTestApi;
20 } // namespace test
21
18 class LayerAnimationSequence; 22 class LayerAnimationSequence;
19 class ScopedLayerAnimationSettings; 23 class ScopedLayerAnimationSettings;
20 class ImplicitAnimationObserver; 24 class ImplicitAnimationObserver;
21 25
22 // LayerAnimationObservers are notified when animations complete. 26 // LayerAnimationObservers are notified when animations complete.
23 class COMPOSITOR_EXPORT LayerAnimationObserver { 27 class COMPOSITOR_EXPORT LayerAnimationObserver {
24 public: 28 public:
25 // Called when the |sequence| starts. 29 // Called when the |sequence| starts.
26 virtual void OnLayerAnimationStarted(LayerAnimationSequence* sequence); 30 virtual void OnLayerAnimationStarted(LayerAnimationSequence* sequence);
27 31
28 // Called when the |sequence| ends. Not called if |sequence| is aborted. 32 // Called when the |sequence| ends. Not called if |sequence| is aborted.
29 virtual void OnLayerAnimationEnded( 33 virtual void OnLayerAnimationEnded(
30 LayerAnimationSequence* sequence) = 0; 34 LayerAnimationSequence* sequence) = 0;
31 35
32 // Called if |sequence| is aborted for any reason. Should never do anything 36 // Called if |sequence| is aborted for any reason. Should never do anything
33 // that may cause another animation to be started. 37 // that may cause another animation to be started.
34 virtual void OnLayerAnimationAborted( 38 virtual void OnLayerAnimationAborted(
35 LayerAnimationSequence* sequence) = 0; 39 LayerAnimationSequence* sequence) = 0;
36 40
37 // Called when the animation is scheduled. 41 // Called when the animation is scheduled.
38 virtual void OnLayerAnimationScheduled( 42 virtual void OnLayerAnimationScheduled(
39 LayerAnimationSequence* sequence) = 0; 43 LayerAnimationSequence* sequence) = 0;
40 44
41 protected: 45 protected:
42 typedef std::set<LayerAnimationSequence*> AttachedSequences; 46 typedef std::set<LayerAnimationSequence*> AttachedSequences;
43 47
44 LayerAnimationObserver(); 48 LayerAnimationObserver();
45 virtual ~LayerAnimationObserver(); 49 virtual ~LayerAnimationObserver();
46 50
47 // If the animator is destroyed during an animation, the animations are 51 // If the LayerAnimator is destroyed during an animation, the animations are
48 // aborted. The resulting NotifyAborted notifications will NOT be sent to 52 // aborted. The resulting NotifyAborted notifications will NOT be sent to
49 // this observer if this function returns false. NOTE: IF YOU override THIS 53 // this observer if this function returns false. An observer who wants to
50 // FUNCTION TO RETURN TRUE, YOU MUST REMEMBER TO REMOVE YOURSELF AS AN 54 // receive the NotifyAborted notifications during destruction can override
51 // OBSERVER WHEN YOU ARE DESTROYED. 55 // this function to return true.
56 //
57 // *** IMPORTANT ***: If a class overrides this function to return true and
58 // that class is a direct or indirect owner of the LayerAnimationSequence
59 // being observed, then the class must explicitly remove itself as an
60 // observer during destruction of the LayerAnimationObserver! This is to
61 // ensure that a partially destroyed observer isn't notified with an
62 // OnLayerAnimationAborted() call when the LayerAnimator is destroyed.
63 //
64 // This opt-in pattern is used because it is common for a class to be the
65 // observer of a LayerAnimationSequence that it owns indirectly because it
66 // owns the Layer which owns the LayerAnimator which owns the
67 // LayerAnimationSequence.
52 virtual bool RequiresNotificationWhenAnimatorDestroyed() const; 68 virtual bool RequiresNotificationWhenAnimatorDestroyed() const;
53 69
54 // Called when |this| is added to |sequence|'s observer list. 70 // Called when |this| is added to |sequence|'s observer list.
55 virtual void OnAttachedToSequence(LayerAnimationSequence* sequence); 71 virtual void OnAttachedToSequence(LayerAnimationSequence* sequence);
56 72
57 // Called when |this| is removed to |sequence|'s observer list. 73 // Called when |this| is removed to |sequence|'s observer list.
58 virtual void OnDetachedFromSequence(LayerAnimationSequence* sequence); 74 virtual void OnDetachedFromSequence(LayerAnimationSequence* sequence);
59 75
60 // Detaches this observer from all sequences it is currently observing. 76 // Detaches this observer from all sequences it is currently observing.
61 void StopObserving(); 77 void StopObserving();
62 78
63 const AttachedSequences& attached_sequences() const { 79 const AttachedSequences& attached_sequences() const {
64 return attached_sequences_; 80 return attached_sequences_;
65 } 81 }
66 82
67 private: 83 private:
68 friend class LayerAnimationSequence; 84 friend class LayerAnimationSequence;
85 friend class test::LayerAnimationObserverTestApi;
69 86
70 // Called when |this| is added to |sequence|'s observer list. 87 // Called when |this| is added to |sequence|'s observer list.
71 void AttachedToSequence(LayerAnimationSequence* sequence); 88 void AttachedToSequence(LayerAnimationSequence* sequence);
72 89
73 // Called when |this| is removed to |sequence|'s observer list. 90 // Called when |this| is removed to |sequence|'s observer list.
74 // This will only result in notifications if |send_notification| is true. 91 // This will only result in notifications if |send_notification| is true.
75 void DetachedFromSequence(LayerAnimationSequence* sequence, 92 void DetachedFromSequence(LayerAnimationSequence* sequence,
76 bool send_notification); 93 bool send_notification);
77 94
78 AttachedSequences attached_sequences_; 95 AttachedSequences attached_sequences_;
79 }; 96 };
80 97
81 // An implicit animation observer is intended to be used in conjunction with a 98 // An implicit animation observer is intended to be used in conjunction with a
82 // ScopedLayerAnimationSettings object in order to receive a notification when 99 // ScopedLayerAnimationSettings object in order to receive a notification when
83 // all implicit animations complete. 100 // all implicit animations complete.
101 // TODO(bruthig): Unify the ImplicitAnimationObserver with the
102 // CallbackLayerAnimationObserver. (See www.crbug.com/542825).
84 class COMPOSITOR_EXPORT ImplicitAnimationObserver 103 class COMPOSITOR_EXPORT ImplicitAnimationObserver
85 : public LayerAnimationObserver { 104 : public LayerAnimationObserver {
86 public: 105 public:
87 ImplicitAnimationObserver(); 106 ImplicitAnimationObserver();
88 ~ImplicitAnimationObserver() override; 107 ~ImplicitAnimationObserver() override;
89 108
90 // Called when the first animation sequence has started. 109 // Called when the first animation sequence has started.
91 virtual void OnImplicitAnimationsScheduled() {} 110 virtual void OnImplicitAnimationsScheduled() {}
92 111
93 virtual void OnImplicitAnimationsCompleted() = 0; 112 virtual void OnImplicitAnimationsCompleted() = 0;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 AnimationStatus> PropertyAnimationStatusMap; 165 AnimationStatus> PropertyAnimationStatusMap;
147 PropertyAnimationStatusMap property_animation_status_; 166 PropertyAnimationStatusMap property_animation_status_;
148 167
149 // True if OnLayerAnimationScheduled() has been called at least once. 168 // True if OnLayerAnimationScheduled() has been called at least once.
150 bool first_sequence_scheduled_; 169 bool first_sequence_scheduled_;
151 }; 170 };
152 171
153 } // namespace ui 172 } // namespace ui
154 173
155 #endif // UI_COMPOSITOR_LAYER_ANIMATION_OBSERVER_H_ 174 #endif // UI_COMPOSITOR_LAYER_ANIMATION_OBSERVER_H_
OLDNEW
« no previous file with comments | « ui/compositor/compositor.gyp ('k') | ui/compositor/test/layer_animation_observer_test_api.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698