OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2014 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. |
| 4 |
| 5 #include "ui/app_list/views/top_icon_animation_view.h" |
| 6 |
| 7 #include "ui/app_list/app_list_constants.h" |
| 8 #include "ui/compositor/scoped_layer_animation_settings.h" |
| 9 #include "ui/gfx/image/image_skia_operations.h" |
| 10 #include "ui/views/controls/image_view.h" |
| 11 |
| 12 namespace app_list { |
| 13 |
| 14 TopIconAnimationView::TopIconAnimationView(const gfx::ImageSkia& icon, |
| 15 const gfx::Rect& scaled_rect, |
| 16 bool open_folder) |
| 17 : icon_size_(kPreferredIconDimension, kPreferredIconDimension), |
| 18 icon_(new views::ImageView), |
| 19 scaled_rect_(scaled_rect), |
| 20 open_folder_(open_folder) { |
| 21 DCHECK(!icon.isNull()); |
| 22 gfx::ImageSkia resized(gfx::ImageSkiaOperations::CreateResizedImage( |
| 23 icon, |
| 24 skia::ImageOperations::RESIZE_BEST, icon_size_)); |
| 25 icon_->SetImage(resized); |
| 26 AddChildView(icon_); |
| 27 |
| 28 SetPaintToLayer(true); |
| 29 SetFillsBoundsOpaquely(false); |
| 30 } |
| 31 |
| 32 TopIconAnimationView::~TopIconAnimationView() { |
| 33 } |
| 34 |
| 35 void TopIconAnimationView::AddObserver(TopIconAnimationObserver* observer) { |
| 36 observers_.AddObserver(observer); |
| 37 } |
| 38 |
| 39 void TopIconAnimationView::RemoveObserver(TopIconAnimationObserver* observer) { |
| 40 observers_.RemoveObserver(observer); |
| 41 } |
| 42 |
| 43 void TopIconAnimationView::TransformView() { |
| 44 // Transform used for scaling down the icon and move it back inside to the |
| 45 // original folder icon. |
| 46 const float kIconTransformScale = 0.33333f; |
| 47 gfx::Transform transform; |
| 48 transform.Translate(scaled_rect_.x() - layer()->bounds().x(), |
| 49 scaled_rect_.y() - layer()->bounds().y()); |
| 50 transform.Scale(kIconTransformScale, kIconTransformScale); |
| 51 |
| 52 if (open_folder_) { |
| 53 // Transform to a scaled down icon inside the original folder icon. |
| 54 layer()->SetTransform(transform); |
| 55 } |
| 56 |
| 57 // Animate the icon to its target location and scale when opening or |
| 58 // closing a folder. |
| 59 ui::ScopedLayerAnimationSettings settings(layer()->GetAnimator()); |
| 60 settings.AddObserver(this); |
| 61 settings.SetTransitionDuration( |
| 62 base::TimeDelta::FromMilliseconds(kFolderTransitionInDurationMs)); |
| 63 layer()->SetTransform(open_folder_ ? gfx::Transform() : transform); |
| 64 } |
| 65 |
| 66 gfx::Size TopIconAnimationView::GetPreferredSize() { |
| 67 return icon_size_; |
| 68 } |
| 69 |
| 70 void TopIconAnimationView::Layout() { |
| 71 icon_->SetBoundsRect(GetContentsBounds()); |
| 72 } |
| 73 |
| 74 void TopIconAnimationView::OnImplicitAnimationsCompleted() { |
| 75 SetVisible(false); |
| 76 FOR_EACH_OBSERVER(TopIconAnimationObserver, |
| 77 observers_, |
| 78 OnTopIconAnimationsComplete()); |
| 79 delete this; |
| 80 } |
| 81 |
| 82 } // namespace app_list |
OLD | NEW |