Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / ui / app_list / views / image_shadow_animator.cc
blob577c07587cb1c330b795cc3310f5e70fc80b82fd
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"
11 using gfx::Tween;
13 namespace {
15 // Tweens between two ShadowValues.
16 gfx::ShadowValue LinearShadowValueBetween(double progress,
17 const gfx::ShadowValue& start,
18 const gfx::ShadowValue& end) {
19 gfx::Vector2d offset(
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.
25 int blur =
26 Tween::LinearIntValueBetween(progress, start.blur() / 2, end.blur() / 2) *
29 return gfx::ShadowValue(
30 offset, blur,
31 Tween::ColorValueBetween(progress, start.color(), end.color()));
34 } // namespace
36 namespace app_list {
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;
47 animation_.Reset();
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) {
69 shadows.push_back(
70 LinearShadowValueBetween(progress, start_shadow_[i], end_shadow_[i]));
72 return shadows;
75 void ImageShadowAnimator::UpdateShadowImageForProgress(double progress) {
76 shadow_image_ = gfx::ImageSkiaOperations::CreateImageWithDropShadow(
77 original_image_, GetShadowValuesForProgress(progress));
79 if (delegate_)
80 delegate_->ImageShadowAnimationProgressed(this);
83 } // namespace app_list