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 "ash/rotator/screen_rotation_animation.h"
7 #include "base/time/time.h"
8 #include "ui/compositor/layer.h"
9 #include "ui/compositor/layer_animation_delegate.h"
10 #include "ui/gfx/animation/tween.h"
11 #include "ui/gfx/geometry/point.h"
12 #include "ui/gfx/interpolated_transform.h"
13 #include "ui/gfx/transform.h"
17 ScreenRotationAnimation::ScreenRotationAnimation(
21 float initial_opacity
,
23 const gfx::Point3F
& initial_scale
,
24 const gfx::Point3F
& target_scale
,
26 base::TimeDelta duration
,
27 gfx::Tween::Type tween_type
)
28 : ui::LayerAnimationElement(
29 LayerAnimationElement::TRANSFORM
| LayerAnimationElement::OPACITY
,
31 tween_type_(tween_type
),
32 initial_opacity_(initial_opacity
),
33 target_opacity_(target_opacity
) {
34 scoped_ptr
<ui::InterpolatedTransform
> scale(
35 new ui::InterpolatedTransformAboutPivot(
36 pivot
, new ui::InterpolatedScale(initial_scale
, target_scale
)));
38 scoped_ptr
<ui::InterpolatedTransform
> rotation(
39 new ui::InterpolatedTransformAboutPivot(
40 pivot
, new ui::InterpolatedRotation(start_degrees
, end_degrees
)));
42 // Use the target transform/bounds in case the layer is already animating.
43 gfx::Transform current_transform
= layer
->GetTargetTransform();
44 interpolated_transform_
.reset(
45 new ui::InterpolatedConstantTransform(current_transform
));
46 scale
->SetChild(rotation
.release());
47 interpolated_transform_
->SetChild(scale
.release());
50 ScreenRotationAnimation::~ScreenRotationAnimation() {
53 void ScreenRotationAnimation::OnStart(ui::LayerAnimationDelegate
* delegate
) {
56 bool ScreenRotationAnimation::OnProgress(double current
,
57 ui::LayerAnimationDelegate
* delegate
) {
58 const double tweened
= gfx::Tween::CalculateValue(tween_type_
, current
);
59 delegate
->SetTransformFromAnimation(
60 interpolated_transform_
->Interpolate(tweened
));
61 delegate
->SetOpacityFromAnimation(gfx::Tween::FloatValueBetween(
62 tweened
, initial_opacity_
, target_opacity_
));
66 void ScreenRotationAnimation::OnGetTarget(TargetValue
* target
) const {
67 target
->transform
= interpolated_transform_
->Interpolate(1.0);
70 void ScreenRotationAnimation::OnAbort(ui::LayerAnimationDelegate
* delegate
) {