OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 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_VIEWS_ANIMATION_ANIMATION_OBSERVER_H_ | |
6 #define UI_VIEWS_ANIMATION_ANIMATION_OBSERVER_H_ | |
7 | |
8 #include <string> | |
9 | |
10 #include "base/logging.h" | |
11 #include "base/macros.h" | |
12 #include "ui/views/views_export.h" | |
13 | |
14 namespace views { | |
15 | |
16 // Templated observer class that can be used to observe animations. | |
17 template <typename ContextType> | |
18 class VIEWS_EXPORT AnimationObserver { | |
19 public: | |
20 // Enumeration of the different reasons why an animation has finished. | |
21 enum AnimationEndedReason { | |
22 // The animation was completed successfully. | |
23 SUCCESS, | |
24 // The animation was stopped prematurely before reaching its final state. | |
25 PRE_EMPTED | |
26 }; | |
27 | |
28 // Notifies the observer that an animation with the given |context| has | |
29 // started. | |
30 virtual void AnimationStarted(ContextType context) = 0; | |
31 | |
32 // Notifies the observer that an animation with the given |context| has | |
33 // finished and the reason for completion is given by |reason|. If |reason| is | |
34 // SUCCESS then the animation has progressed to its final frame however if | |
35 // |reason| is |PRE_EMPTED| then the animation was stopped before its final | |
36 // frame. | |
37 virtual void AnimationEnded(ContextType context, | |
38 AnimationEndedReason reason) = 0; | |
39 | |
40 protected: | |
41 AnimationObserver() {} | |
42 virtual ~AnimationObserver() {} | |
43 | |
44 private: | |
45 DISALLOW_COPY_AND_ASSIGN(AnimationObserver); | |
46 }; | |
47 | |
48 // Returns a human readable string for |reason|. Useful for logging. | |
49 template <typename ContextType> | |
sky
2016/04/20 19:38:47
Seems like the only reason you need the template p
bruthig
2016/04/20 21:20:08
Done.
| |
50 std::string ToString( | |
51 typename AnimationObserver<ContextType>::AnimationEndedReason reason) { | |
52 switch (reason) { | |
53 case AnimationObserver<ContextType>::SUCCESS: | |
54 return std::string("SUCCESS"); | |
sky
2016/04/20 19:38:47
nit: no std::string(), just "SUCCESS".
bruthig
2016/04/20 21:20:08
Done.
| |
55 case AnimationObserver<ContextType>::PRE_EMPTED: | |
56 return std::string("PRE_EMPTED"); | |
57 } | |
58 NOTREACHED() | |
59 << "Should never be reached but is necessary for some compilers."; | |
60 return std::string(); | |
61 } | |
62 | |
63 } // namespace views | |
64 | |
65 #endif // UI_VIEWS_ANIMATION_ANIMATION_OBSERVER_H_ | |
OLD | NEW |