| 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 #include "ui/gfx/compositor/layer_animation_element.h" | 5 #include "ui/gfx/compositor/layer_animation_element.h" |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "ui/base/animation/tween.h" | 8 #include "ui/base/animation/tween.h" |
| 9 #include "ui/gfx/compositor/layer_animation_delegate.h" | 9 #include "ui/gfx/compositor/layer_animation_delegate.h" |
| 10 #include "ui/gfx/rect.h" |
| 11 #include "ui/gfx/transform.h" |
| 10 | 12 |
| 11 namespace ui { | 13 namespace ui { |
| 12 | 14 |
| 13 namespace { | 15 namespace { |
| 14 | 16 |
| 15 // Pause ----------------------------------------------------------------------- | 17 // Pause ----------------------------------------------------------------------- |
| 16 class Pause : public LayerAnimationElement { | 18 class Pause : public LayerAnimationElement { |
| 17 public: | 19 public: |
| 18 Pause(const AnimatableProperties& properties, base::TimeDelta duration) | 20 Pause(const AnimatableProperties& properties, base::TimeDelta duration) |
| 19 : LayerAnimationElement(properties, duration) { | 21 : LayerAnimationElement(properties, duration) { |
| 20 } | 22 } |
| 21 virtual ~Pause() {} | 23 virtual ~Pause() {} |
| 22 | 24 |
| 23 private: | 25 private: |
| 24 virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE {} | 26 virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE {} |
| 25 virtual void OnProgress(double t, | 27 virtual void OnProgress(double t, |
| 26 LayerAnimationDelegate* delegate) OVERRIDE {} | 28 LayerAnimationDelegate* delegate) OVERRIDE {} |
| 27 virtual void OnGetTarget(TargetValue* target) const OVERRIDE {} | |
| 28 virtual void OnAbort() OVERRIDE {} | 29 virtual void OnAbort() OVERRIDE {} |
| 29 | 30 |
| 30 DISALLOW_COPY_AND_ASSIGN(Pause); | 31 DISALLOW_COPY_AND_ASSIGN(Pause); |
| 31 }; | 32 }; |
| 32 | 33 |
| 33 // TransformTransition --------------------------------------------------------- | 34 // TransformTransition --------------------------------------------------------- |
| 34 | 35 |
| 35 class TransformTransition : public LayerAnimationElement { | 36 class TransformTransition : public LayerAnimationElement { |
| 36 public: | 37 public: |
| 37 TransformTransition(const Transform& target, base::TimeDelta duration) | 38 TransformTransition(const Transform& target, base::TimeDelta duration) |
| 38 : LayerAnimationElement(GetProperties(), duration), | 39 : LayerAnimationElement(GetProperties(), duration), |
| 39 target_(target) { | 40 target_(target) { |
| 40 } | 41 } |
| 41 virtual ~TransformTransition() {} | 42 virtual ~TransformTransition() {} |
| 42 | 43 |
| 43 protected: | 44 protected: |
| 44 virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE { | 45 virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE { |
| 45 start_ = delegate->GetTransformForAnimation(); | 46 start_ = delegate->GetTransformForAnimation(); |
| 46 } | 47 } |
| 47 | 48 |
| 48 virtual void OnProgress(double t, LayerAnimationDelegate* delegate) OVERRIDE { | 49 virtual void OnProgress(double t, LayerAnimationDelegate* delegate) OVERRIDE { |
| 49 delegate->SetTransformFromAnimation( | 50 delegate->SetTransformFromAnimation( |
| 50 Tween::ValueBetween(t, start_, target_)); | 51 Tween::ValueBetween(t, start_, target_)); |
| 51 } | 52 } |
| 52 | 53 |
| 53 virtual void OnGetTarget(TargetValue* target) const OVERRIDE { | |
| 54 target->transform = target_; | |
| 55 } | |
| 56 | |
| 57 virtual void OnAbort() OVERRIDE {} | 54 virtual void OnAbort() OVERRIDE {} |
| 58 | 55 |
| 59 private: | 56 private: |
| 60 static const AnimatableProperties& GetProperties() { | 57 static const AnimatableProperties& GetProperties() { |
| 61 static AnimatableProperties properties; | 58 static AnimatableProperties properties; |
| 62 if (properties.size() == 0) | 59 if (properties.size() == 0) |
| 63 properties.insert(LayerAnimationElement::TRANSFORM); | 60 properties.insert(LayerAnimationElement::TRANSFORM); |
| 64 return properties; | 61 return properties; |
| 65 } | 62 } |
| 66 | 63 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 82 | 79 |
| 83 protected: | 80 protected: |
| 84 virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE { | 81 virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE { |
| 85 start_ = delegate->GetBoundsForAnimation(); | 82 start_ = delegate->GetBoundsForAnimation(); |
| 86 } | 83 } |
| 87 | 84 |
| 88 virtual void OnProgress(double t, LayerAnimationDelegate* delegate) OVERRIDE { | 85 virtual void OnProgress(double t, LayerAnimationDelegate* delegate) OVERRIDE { |
| 89 delegate->SetBoundsFromAnimation(Tween::ValueBetween(t, start_, target_)); | 86 delegate->SetBoundsFromAnimation(Tween::ValueBetween(t, start_, target_)); |
| 90 } | 87 } |
| 91 | 88 |
| 92 virtual void OnGetTarget(TargetValue* target) const OVERRIDE { | |
| 93 target->bounds = target_; | |
| 94 } | |
| 95 | |
| 96 virtual void OnAbort() OVERRIDE {} | 89 virtual void OnAbort() OVERRIDE {} |
| 97 | 90 |
| 98 private: | 91 private: |
| 99 static const AnimatableProperties& GetProperties() { | 92 static const AnimatableProperties& GetProperties() { |
| 100 static AnimatableProperties properties; | 93 static AnimatableProperties properties; |
| 101 if (properties.size() == 0) | 94 if (properties.size() == 0) |
| 102 properties.insert(LayerAnimationElement::BOUNDS); | 95 properties.insert(LayerAnimationElement::BOUNDS); |
| 103 return properties; | 96 return properties; |
| 104 } | 97 } |
| 105 | 98 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 119 | 112 |
| 120 protected: | 113 protected: |
| 121 virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE { | 114 virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE { |
| 122 start_ = delegate->GetOpacityForAnimation(); | 115 start_ = delegate->GetOpacityForAnimation(); |
| 123 } | 116 } |
| 124 | 117 |
| 125 virtual void OnProgress(double t, LayerAnimationDelegate* delegate) OVERRIDE { | 118 virtual void OnProgress(double t, LayerAnimationDelegate* delegate) OVERRIDE { |
| 126 delegate->SetOpacityFromAnimation(Tween::ValueBetween(t, start_, target_)); | 119 delegate->SetOpacityFromAnimation(Tween::ValueBetween(t, start_, target_)); |
| 127 } | 120 } |
| 128 | 121 |
| 129 virtual void OnGetTarget(TargetValue* target) const OVERRIDE { | |
| 130 target->opacity = target_; | |
| 131 } | |
| 132 | |
| 133 virtual void OnAbort() OVERRIDE {} | 122 virtual void OnAbort() OVERRIDE {} |
| 134 | 123 |
| 135 private: | 124 private: |
| 136 static const AnimatableProperties& GetProperties() { | 125 static const AnimatableProperties& GetProperties() { |
| 137 static AnimatableProperties properties; | 126 static AnimatableProperties properties; |
| 138 if (properties.size() == 0) | 127 if (properties.size() == 0) |
| 139 properties.insert(LayerAnimationElement::OPACITY); | 128 properties.insert(LayerAnimationElement::OPACITY); |
| 140 return properties; | 129 return properties; |
| 141 } | 130 } |
| 142 | 131 |
| 143 float start_; | 132 float start_; |
| 144 const float target_; | 133 const float target_; |
| 145 | 134 |
| 146 DISALLOW_COPY_AND_ASSIGN(OpacityTransition); | 135 DISALLOW_COPY_AND_ASSIGN(OpacityTransition); |
| 147 }; | 136 }; |
| 148 | 137 |
| 149 } // namespace | 138 } // namespace |
| 150 | 139 |
| 151 // LayerAnimationElement::TargetValue ------------------------------------------ | |
| 152 | |
| 153 LayerAnimationElement::TargetValue::TargetValue() : opacity(0.0f) { | |
| 154 } | |
| 155 | |
| 156 // LayerAnimationElement ------------------------------------------------------- | 140 // LayerAnimationElement ------------------------------------------------------- |
| 157 | 141 |
| 158 LayerAnimationElement::LayerAnimationElement( | 142 LayerAnimationElement::LayerAnimationElement( |
| 159 const AnimatableProperties& properties, | 143 const AnimatableProperties& properties, |
| 160 base::TimeDelta duration) | 144 base::TimeDelta duration) |
| 161 : first_frame_(true), | 145 : first_frame_(true), |
| 162 properties_(properties), | 146 properties_(properties), |
| 163 duration_(duration) { | 147 duration_(duration) { |
| 164 } | 148 } |
| 165 | 149 |
| 166 LayerAnimationElement::~LayerAnimationElement() { | 150 LayerAnimationElement::~LayerAnimationElement() { |
| 167 } | 151 } |
| 168 | 152 |
| 169 void LayerAnimationElement::Progress(double t, | 153 void LayerAnimationElement::Progress(double t, |
| 170 LayerAnimationDelegate* delegate) { | 154 LayerAnimationDelegate* delegate) { |
| 171 if (first_frame_) | 155 if (first_frame_) |
| 172 OnStart(delegate); | 156 OnStart(delegate); |
| 173 OnProgress(t, delegate); | 157 OnProgress(t, delegate); |
| 174 delegate->ScheduleDrawForAnimation(); | |
| 175 first_frame_ = t == 1.0; | 158 first_frame_ = t == 1.0; |
| 176 } | 159 } |
| 177 | 160 |
| 178 void LayerAnimationElement::GetTargetValue(TargetValue* target) const { | |
| 179 OnGetTarget(target); | |
| 180 } | |
| 181 | |
| 182 void LayerAnimationElement::Abort() { | 161 void LayerAnimationElement::Abort() { |
| 183 first_frame_ = true; | 162 first_frame_ = true; |
| 184 OnAbort(); | 163 OnAbort(); |
| 185 } | 164 } |
| 186 | 165 |
| 187 // static | 166 // static |
| 188 LayerAnimationElement* LayerAnimationElement::CreateTransformElement( | 167 LayerAnimationElement* LayerAnimationElement::CreateTransformElement( |
| 189 const Transform& transform, base::TimeDelta duration) { | 168 const Transform& transform, base::TimeDelta duration) { |
| 190 return new TransformTransition(transform, duration); | 169 return new TransformTransition(transform, duration); |
| 191 } | 170 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 202 return new OpacityTransition(opacity, duration); | 181 return new OpacityTransition(opacity, duration); |
| 203 } | 182 } |
| 204 | 183 |
| 205 // static | 184 // static |
| 206 LayerAnimationElement* LayerAnimationElement::CreatePauseElement( | 185 LayerAnimationElement* LayerAnimationElement::CreatePauseElement( |
| 207 const AnimatableProperties& properties, base::TimeDelta duration) { | 186 const AnimatableProperties& properties, base::TimeDelta duration) { |
| 208 return new Pause(properties, duration); | 187 return new Pause(properties, duration); |
| 209 } | 188 } |
| 210 | 189 |
| 211 } // namespace ui | 190 } // namespace ui |
| OLD | NEW |