OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef UI_GFX_COMPOSITOR_LAYER_ANIMATION_ELEMENT_H_ |
| 6 #define UI_GFX_COMPOSITOR_LAYER_ANIMATION_ELEMENT_H_ |
| 7 #pragma once |
| 8 |
| 9 #include <set> |
| 10 |
| 11 #include "base/time.h" |
| 12 #include "ui/gfx/compositor/compositor_export.h" |
| 13 |
| 14 namespace gfx { |
| 15 class Rect; |
| 16 } // gfx |
| 17 |
| 18 namespace ui { |
| 19 |
| 20 class LayerAnimationDelegate; |
| 21 class Transform; |
| 22 |
| 23 // LayerAnimationElements represent one segment of an animation between two |
| 24 // keyframes. They know how to update a LayerAnimationDelegate given a value |
| 25 // between 0 and 1 (0 for initial, and 1 for final). |
| 26 class COMPOSITOR_EXPORT LayerAnimationElement { |
| 27 public: |
| 28 enum AnimatableProperty { |
| 29 TRANSFORM = 0, |
| 30 BOUNDS, |
| 31 OPACITY |
| 32 }; |
| 33 |
| 34 typedef std::set<AnimatableProperty> AnimatableProperties; |
| 35 |
| 36 LayerAnimationElement(const AnimatableProperties& properties, |
| 37 base::TimeDelta duration); |
| 38 virtual ~LayerAnimationElement(); |
| 39 |
| 40 // Creates an element that transitions to the given transform. The caller owns |
| 41 // the return value. |
| 42 static LayerAnimationElement* CreateTransformElement( |
| 43 const Transform& transform, |
| 44 base::TimeDelta duration); |
| 45 |
| 46 // Creates an element that transitions to the given bounds. The caller owns |
| 47 // the return value. |
| 48 static LayerAnimationElement* CreateBoundsElement( |
| 49 const gfx::Rect& bounds, |
| 50 base::TimeDelta duration); |
| 51 |
| 52 // Creates an element that transitions to the given opacity. The caller owns |
| 53 // the return value. |
| 54 static LayerAnimationElement* CreateOpacityElement( |
| 55 float opacity, |
| 56 base::TimeDelta duration); |
| 57 |
| 58 // Creates an element that pauses the given properties. The caller owns the |
| 59 // return value. |
| 60 static LayerAnimationElement* CreatePauseElement( |
| 61 const AnimatableProperties& properties, |
| 62 base::TimeDelta duration); |
| 63 |
| 64 // 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 |
| 66 // aborted, it is guaranteed that Progress will eventually be called with |
| 67 // t = 1.0. |
| 68 void Progress(double t, LayerAnimationDelegate* delegate); |
| 69 |
| 70 // Called if the animation is not allowed to complete. This may be called |
| 71 // before OnStarted or Progress. |
| 72 void Abort(); |
| 73 |
| 74 // The properties that the element modifies. |
| 75 const AnimatableProperties& properties() const { return properties_; } |
| 76 |
| 77 // The duration of the animation |
| 78 base::TimeDelta duration() const { return duration_; } |
| 79 |
| 80 protected: |
| 81 // Called once each time the animation element is run before any call to |
| 82 // OnProgress. |
| 83 virtual void OnStart(LayerAnimationDelegate* delegate) = 0; |
| 84 virtual void OnProgress(double t, LayerAnimationDelegate* delegate) = 0; |
| 85 virtual void OnAbort() = 0; |
| 86 |
| 87 private: |
| 88 bool first_frame_; |
| 89 const AnimatableProperties properties_; |
| 90 const base::TimeDelta duration_; |
| 91 |
| 92 DISALLOW_COPY_AND_ASSIGN(LayerAnimationElement); |
| 93 }; |
| 94 |
| 95 } // namespace ui |
| 96 |
| 97 #endif // UI_GFX_COMPOSITOR_LAYER_ANIMATION_ELEMENT_H_ |
OLD | NEW |