Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_GFX_COMPOSITOR_LAYER_ANIMATION_ELEMENT_H_ | 5 #ifndef UI_GFX_COMPOSITOR_LAYER_ANIMATION_ELEMENT_H_ |
| 6 #define UI_GFX_COMPOSITOR_LAYER_ANIMATION_ELEMENT_H_ | 6 #define UI_GFX_COMPOSITOR_LAYER_ANIMATION_ELEMENT_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <set> | 9 #include <set> |
| 10 | 10 |
| 11 #include "base/time.h" | 11 #include "base/time.h" |
| 12 #include "ui/gfx/compositor/compositor_export.h" | 12 #include "ui/gfx/compositor/compositor_export.h" |
| 13 | 13 #include "ui/gfx/rect.h" |
| 14 namespace gfx { | 14 #include "ui/gfx/transform.h" |
| 15 class Rect; | |
| 16 } // gfx | |
| 17 | 15 |
| 18 namespace ui { | 16 namespace ui { |
| 19 | 17 |
| 20 class LayerAnimationDelegate; | 18 class LayerAnimationDelegate; |
| 21 class Transform; | 19 class Transform; |
| 22 | 20 |
| 23 // LayerAnimationElements represent one segment of an animation between two | 21 // LayerAnimationElements represent one segment of an animation between two |
| 24 // keyframes. They know how to update a LayerAnimationDelegate given a value | 22 // keyframes. They know how to update a LayerAnimationDelegate given a value |
| 25 // between 0 and 1 (0 for initial, and 1 for final). | 23 // between 0 and 1 (0 for initial, and 1 for final). |
| 26 class COMPOSITOR_EXPORT LayerAnimationElement { | 24 class COMPOSITOR_EXPORT LayerAnimationElement { |
| 27 public: | 25 public: |
| 28 enum AnimatableProperty { | 26 enum AnimatableProperty { |
| 29 TRANSFORM = 0, | 27 TRANSFORM = 0, |
| 30 BOUNDS, | 28 BOUNDS, |
| 31 OPACITY | 29 OPACITY |
| 32 }; | 30 }; |
| 33 | 31 |
| 32 struct TargetValue { | |
| 33 gfx::Rect bounds; | |
| 34 Transform transform; | |
| 35 float opacity; | |
|
sky
2011/10/20 23:31:35
initialize opacity to 0.
| |
| 36 }; | |
| 37 | |
| 34 typedef std::set<AnimatableProperty> AnimatableProperties; | 38 typedef std::set<AnimatableProperty> AnimatableProperties; |
| 35 | 39 |
| 36 LayerAnimationElement(const AnimatableProperties& properties, | 40 LayerAnimationElement(const AnimatableProperties& properties, |
| 37 base::TimeDelta duration); | 41 base::TimeDelta duration); |
| 38 virtual ~LayerAnimationElement(); | 42 virtual ~LayerAnimationElement(); |
| 39 | 43 |
| 40 // Creates an element that transitions to the given transform. The caller owns | 44 // Creates an element that transitions to the given transform. The caller owns |
| 41 // the return value. | 45 // the return value. |
| 42 static LayerAnimationElement* CreateTransformElement( | 46 static LayerAnimationElement* CreateTransformElement( |
| 43 const Transform& transform, | 47 const Transform& transform, |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 64 // Updates the delegate to the appropriate value for |t|, which is in the | 68 // Updates the delegate to the appropriate value for |t|, which is in the |
| 65 // range [0, 1] (0 for initial, and 1 for final). If the animation is not | 69 // range [0, 1] (0 for initial, and 1 for final). If the animation is not |
| 66 // aborted, it is guaranteed that Progress will eventually be called with | 70 // aborted, it is guaranteed that Progress will eventually be called with |
| 67 // t = 1.0. | 71 // t = 1.0. |
| 68 void Progress(double t, LayerAnimationDelegate* delegate); | 72 void Progress(double t, LayerAnimationDelegate* delegate); |
| 69 | 73 |
| 70 // Called if the animation is not allowed to complete. This may be called | 74 // Called if the animation is not allowed to complete. This may be called |
| 71 // before OnStarted or Progress. | 75 // before OnStarted or Progress. |
| 72 void Abort(); | 76 void Abort(); |
| 73 | 77 |
| 78 // Assigns the target value to |target|. | |
| 79 void GetTargetValue(TargetValue* target) const; | |
| 80 | |
| 74 // The properties that the element modifies. | 81 // The properties that the element modifies. |
| 75 const AnimatableProperties& properties() const { return properties_; } | 82 const AnimatableProperties& properties() const { return properties_; } |
| 76 | 83 |
| 77 // The duration of the animation | 84 // The duration of the animation |
| 78 base::TimeDelta duration() const { return duration_; } | 85 base::TimeDelta duration() const { return duration_; } |
| 79 | 86 |
| 80 protected: | 87 protected: |
| 81 // Called once each time the animation element is run before any call to | 88 // Called once each time the animation element is run before any call to |
| 82 // OnProgress. | 89 // OnProgress. |
| 83 virtual void OnStart(LayerAnimationDelegate* delegate) = 0; | 90 virtual void OnStart(LayerAnimationDelegate* delegate) = 0; |
| 84 virtual void OnProgress(double t, LayerAnimationDelegate* delegate) = 0; | 91 virtual void OnProgress(double t, LayerAnimationDelegate* delegate) = 0; |
| 92 virtual void OnGetTarget(TargetValue* target) const = 0; | |
| 85 virtual void OnAbort() = 0; | 93 virtual void OnAbort() = 0; |
| 86 | 94 |
| 87 private: | 95 private: |
| 88 bool first_frame_; | 96 bool first_frame_; |
| 89 const AnimatableProperties properties_; | 97 const AnimatableProperties properties_; |
| 90 const base::TimeDelta duration_; | 98 const base::TimeDelta duration_; |
| 91 | 99 |
| 92 DISALLOW_COPY_AND_ASSIGN(LayerAnimationElement); | 100 DISALLOW_COPY_AND_ASSIGN(LayerAnimationElement); |
| 93 }; | 101 }; |
| 94 | 102 |
| 95 } // namespace ui | 103 } // namespace ui |
| 96 | 104 |
| 97 #endif // UI_GFX_COMPOSITOR_LAYER_ANIMATION_ELEMENT_H_ | 105 #endif // UI_GFX_COMPOSITOR_LAYER_ANIMATION_ELEMENT_H_ |
| OLD | NEW |