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 #include "ui/app_list/views/image_shadow_animator.h"
7 #include "ui/gfx/animation/animation_delegate.h"
8 #include "ui/gfx/animation/slide_animation.h"
9 #include "ui/gfx/image/image_skia_operations.h"
15 // Tweens between two ShadowValues.
16 gfx::ShadowValue
LinearShadowValueBetween(double progress
,
17 const gfx::ShadowValue
& start
,
18 const gfx::ShadowValue
& end
) {
20 Tween::LinearIntValueBetween(progress
, start
.x(), end
.x()),
21 Tween::LinearIntValueBetween(progress
, start
.y(), end
.y()));
23 // The blur must be clamped to even values in order to avoid offsets being
24 // incorrect when there are uneven margins.
26 Tween::LinearIntValueBetween(progress
, start
.blur() / 2, end
.blur() / 2) *
29 return gfx::ShadowValue(
31 Tween::ColorValueBetween(progress
, start
.color(), end
.color()));
38 ImageShadowAnimator::ImageShadowAnimator(Delegate
* delegate
)
39 : delegate_(delegate
), animation_(this) {
42 ImageShadowAnimator::~ImageShadowAnimator() {
45 void ImageShadowAnimator::SetOriginalImage(const gfx::ImageSkia
& image
) {
46 original_image_
= image
;
48 UpdateShadowImageForProgress(0);
51 void ImageShadowAnimator::SetStartAndEndShadows(
52 const gfx::ShadowValues
& start_shadow
,
53 const gfx::ShadowValues
& end_shadow
) {
54 start_shadow_
= start_shadow
;
55 end_shadow_
= end_shadow
;
58 void ImageShadowAnimator::AnimationProgressed(const gfx::Animation
* animation
) {
59 UpdateShadowImageForProgress(animation
->GetCurrentValue());
62 gfx::ShadowValues
ImageShadowAnimator::GetShadowValuesForProgress(
63 double progress
) const {
64 DCHECK_EQ(start_shadow_
.size(), end_shadow_
.size())
65 << "Only equally sized ShadowValues are supported";
67 gfx::ShadowValues shadows
;
68 for (size_t i
= 0; i
< start_shadow_
.size(); ++i
) {
70 LinearShadowValueBetween(progress
, start_shadow_
[i
], end_shadow_
[i
]));
75 void ImageShadowAnimator::UpdateShadowImageForProgress(double progress
) {
76 shadow_image_
= gfx::ImageSkiaOperations::CreateImageWithDropShadow(
77 original_image_
, GetShadowValuesForProgress(progress
));
80 delegate_
->ImageShadowAnimationProgressed(this);
83 } // namespace app_list