This source file includes following definitions.
- open_folder_
- AddObserver
- RemoveObserver
- TransformView
- GetPreferredSize
- Layout
- OnImplicitAnimationsCompleted
#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)
: icon_size_(kPreferredIconDimension, kPreferredIconDimension),
icon_(new views::ImageView),
scaled_rect_(scaled_rect),
open_folder_(open_folder) {
DCHECK(!icon.isNull());
gfx::ImageSkia resized(gfx::ImageSkiaOperations::CreateResizedImage(
icon,
skia::ImageOperations::RESIZE_BEST, icon_size_));
icon_->SetImage(resized);
AddChildView(icon_);
SetPaintToLayer(true);
SetFillsBoundsOpaquely(false);
}
TopIconAnimationView::~TopIconAnimationView() {
}
void TopIconAnimationView::AddObserver(TopIconAnimationObserver* observer) {
observers_.AddObserver(observer);
}
void TopIconAnimationView::RemoveObserver(TopIconAnimationObserver* observer) {
observers_.RemoveObserver(observer);
}
void TopIconAnimationView::TransformView() {
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_) {
layer()->SetTransform(transform);
}
ui::ScopedLayerAnimationSettings settings(layer()->GetAnimator());
settings.AddObserver(this);
settings.SetTweenType(gfx::Tween::FAST_OUT_SLOW_IN);
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);
FOR_EACH_OBSERVER(TopIconAnimationObserver,
observers_,
OnTopIconAnimationsComplete());
delete this;
}
}