Index: ui/views/animation/animation_observer.h |
diff --git a/ui/views/animation/animation_observer.h b/ui/views/animation/animation_observer.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..f9ec839e7b7a9c02b461a0b06088e4e0a0c203f3 |
--- /dev/null |
+++ b/ui/views/animation/animation_observer.h |
@@ -0,0 +1,65 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef UI_VIEWS_ANIMATION_ANIMATION_OBSERVER_H_ |
+#define UI_VIEWS_ANIMATION_ANIMATION_OBSERVER_H_ |
+ |
+#include <string> |
+ |
+#include "base/logging.h" |
+#include "base/macros.h" |
+#include "ui/views/views_export.h" |
+ |
+namespace views { |
+ |
+// Templated observer class that can be used to observe animations. |
+template <typename ContextType> |
+class VIEWS_EXPORT AnimationObserver { |
+ public: |
+ // Enumeration of the different reasons why an animation has finished. |
+ enum AnimationEndedReason { |
+ // The animation was completed successfully. |
+ SUCCESS, |
+ // The animation was stopped prematurely before reaching its final state. |
+ PRE_EMPTED |
+ }; |
+ |
+ // Notifies the observer that an animation with the given |context| has |
+ // started. |
+ virtual void AnimationStarted(ContextType context) = 0; |
+ |
+ // Notifies the observer that an animation with the given |context| has |
+ // finished and the reason for completion is given by |reason|. If |reason| is |
+ // SUCCESS then the animation has progressed to its final frame however if |
+ // |reason| is |PRE_EMPTED| then the animation was stopped before its final |
+ // frame. |
+ virtual void AnimationEnded(ContextType context, |
+ AnimationEndedReason reason) = 0; |
+ |
+ protected: |
+ AnimationObserver() {} |
+ virtual ~AnimationObserver() {} |
+ |
+ private: |
+ DISALLOW_COPY_AND_ASSIGN(AnimationObserver); |
+}; |
+ |
+// Returns a human readable string for |reason|. Useful for logging. |
+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.
|
+std::string ToString( |
+ typename AnimationObserver<ContextType>::AnimationEndedReason reason) { |
+ switch (reason) { |
+ case AnimationObserver<ContextType>::SUCCESS: |
+ 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.
|
+ case AnimationObserver<ContextType>::PRE_EMPTED: |
+ return std::string("PRE_EMPTED"); |
+ } |
+ NOTREACHED() |
+ << "Should never be reached but is necessary for some compilers."; |
+ return std::string(); |
+} |
+ |
+} // namespace views |
+ |
+#endif // UI_VIEWS_ANIMATION_ANIMATION_OBSERVER_H_ |