1 // Copyright 2015 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.
5 #ifndef UI_APP_LIST_VIEWS_IMAGE_SHADOW_ANIMATOR_H_
6 #define UI_APP_LIST_VIEWS_IMAGE_SHADOW_ANIMATOR_H_
8 #include "ui/app_list/app_list_export.h"
9 #include "ui/gfx/animation/animation_delegate.h"
10 #include "ui/gfx/animation/slide_animation.h"
11 #include "ui/gfx/image/image_skia.h"
12 #include "ui/gfx/shadow_value.h"
17 class ImageShadowAnimatorTest
;
20 // A helper class that animates an image's shadow between two shadow values.
21 class APP_LIST_EXPORT ImageShadowAnimator
: public gfx::AnimationDelegate
{
25 // Called when |shadow_image_| is updated.
26 virtual void ImageShadowAnimationProgressed(
27 ImageShadowAnimator
* animator
) = 0;
30 explicit ImageShadowAnimator(Delegate
* delegate
);
31 ~ImageShadowAnimator() override
;
33 // Sets the image that will have its shadow animated. Synchronously calls the
34 // Delegate's ImageShadowAnimationProgressed() method.
35 void SetOriginalImage(const gfx::ImageSkia
& image
);
37 // Sets the shadow values to animate between.
38 void SetStartAndEndShadows(const gfx::ShadowValues
& start_shadow
,
39 const gfx::ShadowValues
& end_shadow
);
41 gfx::SlideAnimation
* animation() { return &animation_
; }
43 const gfx::ImageSkia
& shadow_image() const { return shadow_image_
; }
45 // Overridden from gfx::AnimationDelegate:
46 void AnimationProgressed(const gfx::Animation
* animation
) override
;
49 friend test::ImageShadowAnimatorTest
;
51 // Returns shadow values for a tween between |start_shadow_| and |end_shadow_|
53 gfx::ShadowValues
GetShadowValuesForProgress(double progress
) const;
55 // Updates |shadow_image_| and notifies the delegate.
56 void UpdateShadowImageForProgress(double progress
);
58 Delegate
* const delegate_
;
60 // The image to paint a drop shadow for.
61 gfx::ImageSkia original_image_
;
63 // The image with a drop shadow painted. This stays current with the progress
65 gfx::ImageSkia shadow_image_
;
67 // The animation that controls the progress of the shadow tween.
68 gfx::SlideAnimation animation_
;
70 // The shadow value to tween from.
71 gfx::ShadowValues start_shadow_
;
73 // The shadow value to tween to.
74 gfx::ShadowValues end_shadow_
;
76 DISALLOW_COPY_AND_ASSIGN(ImageShadowAnimator
);
79 } // namespace app_list
81 #endif // UI_APP_LIST_VIEWS_IMAGE_SHADOW_ANIMATOR_H_