Chromium Code Reviews| Index: ui/app_list/views/top_icon_animation_view.cc |
| diff --git a/ui/app_list/views/top_icon_animation_view.cc b/ui/app_list/views/top_icon_animation_view.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..466b3584fbf83556335acb782ae9fa481f94025f |
| --- /dev/null |
| +++ b/ui/app_list/views/top_icon_animation_view.cc |
| @@ -0,0 +1,90 @@ |
| +// Copyright (c) 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| + |
|
xiyuan
2014/02/06 22:45:12
nit: nuke one empty line
jennyz
2014/02/07 00:03:10
Done.
|
| +#include "ui/app_list/views/top_icon_animation_view.h" |
| + |
| +#include "ui/app_list/app_list_constants.h" |
| +#include "ui/compositor/scoped_layer_animation_settings.h" |
| +#include "ui/gfx/image/image_skia_operations.h" |
| +#include "ui/views/controls/image_view.h" |
| + |
| +namespace app_list { |
| + |
| +TopIconAnimationView::TopIconAnimationView(const gfx::ImageSkia& icon, |
| + const gfx::Rect& scaled_rect, |
| + bool open_folder, |
| + bool self_clean) |
| + : icon_size_(kPreferredIconDimension, kPreferredIconDimension), |
| + icon_(new views::ImageView), |
| + scaled_rect_(scaled_rect), |
| + open_folder_(open_folder), |
| + self_clean_(self_clean) { |
| + DCHECK(!icon.isNull()); |
| + gfx::ImageSkia resized(gfx::ImageSkiaOperations::CreateResizedImage( |
| + icon, |
| + skia::ImageOperations::RESIZE_BEST, icon_size_)); |
| + icon_->SetImage(resized); |
| + AddChildView(icon_); |
| + |
| +#if defined(USE_AURA) |
|
xiyuan
2014/02/06 22:45:12
nit: Not sure if we still need this any more.
jennyz
2014/02/07 00:03:10
Remove them, will watch if it breaks any compiler.
|
| + SetPaintToLayer(true); |
| + SetFillsBoundsOpaquely(false); |
| +#endif |
| + } |
| + |
| +TopIconAnimationView::~TopIconAnimationView() { |
| +} |
| + |
| +void TopIconAnimationView::AddObserver(TopIconAnimationObserver* observer) { |
| + observers_.AddObserver(observer); |
| +} |
| + |
| +void TopIconAnimationView::RemoveObserver(TopIconAnimationObserver* observer) { |
| + observers_.RemoveObserver(observer); |
| +} |
| + |
| +void TopIconAnimationView::TransformView() { |
| + // Transform used for scaling down the icon and move it back inside to the |
| + // original folder icon. |
| + const float kIconTransformScale = 0.33333f; |
| + gfx::Transform transform; |
| + transform.Translate(scaled_rect_.x() - layer()->bounds().x(), |
| + scaled_rect_.y() - layer()->bounds().y()); |
| + transform.Scale(kIconTransformScale, kIconTransformScale); |
| + |
| + if (open_folder_) { |
| + // Transform to a scaled down icon inside the original folder icon. |
| + layer()->SetTransform(transform); |
| + } |
| + |
| + // Animate the icon to its target location and scale when opening or |
| + // closing a folder. |
| + ui::ScopedLayerAnimationSettings settings(layer()->GetAnimator()); |
| + settings.AddObserver(this); |
| + settings.SetTransitionDuration( |
| + base::TimeDelta::FromMilliseconds(kFolderTransitionInDurationMs)); |
| + layer()->SetTransform(open_folder_ ? gfx::Transform() : transform); |
| +} |
| + |
| +gfx::Size TopIconAnimationView::GetPreferredSize() { |
| + return icon_size_; |
| +} |
| + |
| +void TopIconAnimationView::Layout() { |
| + icon_->SetBoundsRect(GetContentsBounds()); |
| +} |
| + |
| +void TopIconAnimationView::OnImplicitAnimationsCompleted() { |
| + SetVisible(false); |
| + |
| + if (self_clean_) |
| + delete this; |
|
xiyuan
2014/02/06 22:45:12
This would cause use-after-free for the FOR_EACH_O
jennyz
2014/02/07 00:03:10
Yes, this's wrong. Now make TopIconAnimation alway
|
| + |
| + FOR_EACH_OBSERVER(TopIconAnimationObserver, |
| + observers_, |
| + OnTopIconAnimationsComplete(this)); |
| +} |
| + |
| +} // namespace app_list |