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
,
24 base::TimeDelta duration
,
25 gfx::Tween::Type tween_type
)
26 : ui::LayerAnimationElement(
27 LayerAnimationElement::TRANSFORM
| LayerAnimationElement::OPACITY
,
29 tween_type_(tween_type
),
30 initial_opacity_(initial_opacity
),
31 target_opacity_(target_opacity
) {
32 scoped_ptr
<ui::InterpolatedTransform
> rotation(
33 new ui::InterpolatedTransformAboutPivot(
34 pivot
, new ui::InterpolatedRotation(start_degrees
, end_degrees
)));
36 // Use the target transform/bounds in case the layer is already animating.
37 gfx::Transform current_transform
= layer
->GetTargetTransform();
38 interpolated_transform_
.reset(
39 new ui::InterpolatedConstantTransform(current_transform
));
40 interpolated_transform_
->SetChild(rotation
.release());
43 ScreenRotationAnimation::~ScreenRotationAnimation() {
46 void ScreenRotationAnimation::OnStart(ui::LayerAnimationDelegate
* delegate
) {
49 bool ScreenRotationAnimation::OnProgress(double current
,
50 ui::LayerAnimationDelegate
* delegate
) {
51 const double tweened
= gfx::Tween::CalculateValue(tween_type_
, current
);
52 delegate
->SetTransformFromAnimation(
53 interpolated_transform_
->Interpolate(tweened
));
54 delegate
->SetOpacityFromAnimation(gfx::Tween::FloatValueBetween(
55 tweened
, initial_opacity_
, target_opacity_
));
59 void ScreenRotationAnimation::OnGetTarget(TargetValue
* target
) const {
60 target
->transform
= interpolated_transform_
->Interpolate(1.0);
63 void ScreenRotationAnimation::OnAbort(ui::LayerAnimationDelegate
* delegate
) {