Add google_apis_unittests, midi_unittests to GN swarming.
[chromium-blink-merge.git] / ash / rotator / screen_rotation_animation.cc
blobd4ca5193c46ec5414ef2163c49277e053e40aae5
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"
15 namespace ash {
17 ScreenRotationAnimation::ScreenRotationAnimation(
18 ui::Layer* layer,
19 int start_degrees,
20 int end_degrees,
21 float initial_opacity,
22 float target_opacity,
23 const gfx::Point3F& initial_scale,
24 const gfx::Point3F& target_scale,
25 gfx::Point pivot,
26 base::TimeDelta duration,
27 gfx::Tween::Type tween_type)
28 : ui::LayerAnimationElement(
29 LayerAnimationElement::TRANSFORM | LayerAnimationElement::OPACITY,
30 duration),
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_));
63 return true;
66 void ScreenRotationAnimation::OnGetTarget(TargetValue* target) const {
67 target->transform = interpolated_transform_->Interpolate(1.0);
70 void ScreenRotationAnimation::OnAbort(ui::LayerAnimationDelegate* delegate) {
73 } // namespace ash