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