From e81480f1fd21a75545b1c5dda31a1e7c8abf847f Mon Sep 17 00:00:00 2001 From: "sky@chromium.org" Date: Thu, 11 Oct 2012 23:06:45 +0000 Subject: Adds ability to animate the color of a layer. BUG=155179 TEST=none R=vollick@chromium.org Review URL: https://codereview.chromium.org/11103037 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@161432 0039d316-1c4b-4281-b951-d872f2087c98 --- ui/compositor/layer_animation_element.cc | 90 ++++++++++++++++++++++++++++---- 1 file changed, 80 insertions(+), 10 deletions(-) (limited to 'ui/compositor/layer_animation_element.cc') diff --git a/ui/compositor/layer_animation_element.cc b/ui/compositor/layer_animation_element.cc index 98326d2..c48a81c 100644 --- a/ui/compositor/layer_animation_element.cc +++ b/ui/compositor/layer_animation_element.cc @@ -314,6 +314,59 @@ class GrayscaleTransition : public LayerAnimationElement { DISALLOW_COPY_AND_ASSIGN(GrayscaleTransition); }; +// ColorTransition ------------------------------------------------------------- + +class ColorTransition : public LayerAnimationElement { + public: + ColorTransition(SkColor target, base::TimeDelta duration) + : LayerAnimationElement(GetProperties(), duration), + start_(SK_ColorBLACK), + target_(target) { + } + virtual ~ColorTransition() {} + + protected: + virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE { + start_ = delegate->GetColorForAnimation(); + } + + virtual bool OnProgress(double t, LayerAnimationDelegate* delegate) OVERRIDE { + delegate->SetColorFromAnimation( + SkColorSetARGB( + Tween::ValueBetween(t, + static_cast(SkColorGetA(start_)), + static_cast(SkColorGetA(target_))), + Tween::ValueBetween(t, + static_cast(SkColorGetR(start_)), + static_cast(SkColorGetR(target_))), + Tween::ValueBetween(t, + static_cast(SkColorGetG(start_)), + static_cast(SkColorGetG(target_))), + Tween::ValueBetween(t, + static_cast(SkColorGetB(start_)), + static_cast(SkColorGetB(target_))))); + return true; + } + + virtual void OnGetTarget(TargetValue* target) const OVERRIDE { + target->color = target_; + } + + virtual void OnAbort() OVERRIDE {} + + private: + static AnimatableProperties GetProperties() { + AnimatableProperties properties; + properties.insert(LayerAnimationElement::COLOR); + return properties; + } + + SkColor start_; + const SkColor target_; + + DISALLOW_COPY_AND_ASSIGN(ColorTransition); +}; + } // namespace // LayerAnimationElement::TargetValue ------------------------------------------ @@ -322,7 +375,8 @@ LayerAnimationElement::TargetValue::TargetValue() : opacity(0.0f), visibility(false), brightness(0.0f), - grayscale(0.0f) { + grayscale(0.0f), + color(SK_ColorBLACK) { } LayerAnimationElement::TargetValue::TargetValue( @@ -332,7 +386,8 @@ LayerAnimationElement::TargetValue::TargetValue( opacity(delegate ? delegate->GetOpacityForAnimation() : 0.0f), visibility(delegate ? delegate->GetVisibilityForAnimation() : false), brightness(delegate ? delegate->GetBrightnessForAnimation() : 0.0f), - grayscale(delegate ? delegate->GetGrayscaleForAnimation() : 0.0f) { + grayscale(delegate ? delegate->GetGrayscaleForAnimation() : 0.0f), + color(delegate ? delegate->GetColorForAnimation() : 0.0f) { } // LayerAnimationElement ------------------------------------------------------- @@ -381,51 +436,66 @@ base::TimeDelta LayerAnimationElement::GetEffectiveDuration( // static LayerAnimationElement* LayerAnimationElement::CreateTransformElement( - const Transform& transform, base::TimeDelta duration) { + const Transform& transform, + base::TimeDelta duration) { return new TransformTransition(transform, duration); } // static LayerAnimationElement* LayerAnimationElement::CreateInterpolatedTransformElement( - InterpolatedTransform* interpolated_transform, base::TimeDelta duration) { + InterpolatedTransform* interpolated_transform, + base::TimeDelta duration) { return new InterpolatedTransformTransition(interpolated_transform, duration); } // static LayerAnimationElement* LayerAnimationElement::CreateBoundsElement( - const gfx::Rect& bounds, base::TimeDelta duration) { + const gfx::Rect& bounds, + base::TimeDelta duration) { return new BoundsTransition(bounds, duration); } // static LayerAnimationElement* LayerAnimationElement::CreateOpacityElement( - float opacity, base::TimeDelta duration) { + float opacity, + base::TimeDelta duration) { return new OpacityTransition(opacity, duration); } // static LayerAnimationElement* LayerAnimationElement::CreateVisibilityElement( - bool visibility, base::TimeDelta duration) { + bool visibility, + base::TimeDelta duration) { return new VisibilityTransition(visibility, duration); } // static LayerAnimationElement* LayerAnimationElement::CreateBrightnessElement( - float brightness, base::TimeDelta duration) { + float brightness, + base::TimeDelta duration) { return new BrightnessTransition(brightness, duration); } // static LayerAnimationElement* LayerAnimationElement::CreateGrayscaleElement( - float grayscale, base::TimeDelta duration) { + float grayscale, + base::TimeDelta duration) { return new GrayscaleTransition(grayscale, duration); } // static LayerAnimationElement* LayerAnimationElement::CreatePauseElement( - const AnimatableProperties& properties, base::TimeDelta duration) { + const AnimatableProperties& properties, + base::TimeDelta duration) { return new Pause(properties, duration); } +// static +LayerAnimationElement* LayerAnimationElement::CreateColorElement( + SkColor color, + base::TimeDelta duration) { + return new ColorTransition(color, duration); +} + } // namespace ui -- cgit v1.1