| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ash/rotator/screen_rotation.h" | 5 #include "ash/rotator/window_rotation.h" |
| 6 | 6 |
| 7 #include "base/time/time.h" | 7 #include "base/time/time.h" |
| 8 #include "ui/compositor/layer.h" | 8 #include "ui/compositor/layer.h" |
| 9 #include "ui/gfx/geometry/rect.h" | 9 #include "ui/gfx/geometry/rect.h" |
| 10 #include "ui/gfx/interpolated_transform.h" | 10 #include "ui/gfx/interpolated_transform.h" |
| 11 #include "ui/gfx/transform.h" | 11 #include "ui/gfx/transform.h" |
| 12 | 12 |
| 13 namespace ash { | 13 namespace ash { |
| 14 | 14 |
| 15 namespace { | 15 namespace { |
| 16 | 16 |
| 17 const int k90DegreeTransitionDurationMs = 350; | 17 const int k90DegreeTransitionDurationMs = 350; |
| 18 const int k180DegreeTransitionDurationMs = 550; | 18 const int k180DegreeTransitionDurationMs = 550; |
| 19 const int k360DegreeTransitionDurationMs = 750; | 19 const int k360DegreeTransitionDurationMs = 750; |
| 20 | 20 |
| 21 base::TimeDelta GetTransitionDuration(int degrees) { | 21 base::TimeDelta GetTransitionDuration(int degrees) { |
| 22 if (degrees == 360) | 22 if (degrees == 360) |
| 23 return base::TimeDelta::FromMilliseconds(k360DegreeTransitionDurationMs); | 23 return base::TimeDelta::FromMilliseconds(k360DegreeTransitionDurationMs); |
| 24 if (degrees == 180) | 24 if (degrees == 180) |
| 25 return base::TimeDelta::FromMilliseconds(k180DegreeTransitionDurationMs); | 25 return base::TimeDelta::FromMilliseconds(k180DegreeTransitionDurationMs); |
| 26 if (degrees == 0) | 26 if (degrees == 0) |
| 27 return base::TimeDelta::FromMilliseconds(0); | 27 return base::TimeDelta::FromMilliseconds(0); |
| 28 return base::TimeDelta::FromMilliseconds(k90DegreeTransitionDurationMs); | 28 return base::TimeDelta::FromMilliseconds(k90DegreeTransitionDurationMs); |
| 29 } | 29 } |
| 30 | 30 |
| 31 } // namespace | 31 } // namespace |
| 32 | 32 |
| 33 ScreenRotation::ScreenRotation(int degrees, ui::Layer* layer) | 33 WindowRotation::WindowRotation(int degrees, ui::Layer* layer) |
| 34 : ui::LayerAnimationElement(LayerAnimationElement::TRANSFORM, | 34 : ui::LayerAnimationElement(LayerAnimationElement::TRANSFORM, |
| 35 GetTransitionDuration(degrees)), | 35 GetTransitionDuration(degrees)), |
| 36 degrees_(degrees) { | 36 degrees_(degrees) { |
| 37 InitTransform(layer); | 37 InitTransform(layer); |
| 38 } | 38 } |
| 39 | 39 |
| 40 ScreenRotation::~ScreenRotation() { | 40 WindowRotation::~WindowRotation() { |
| 41 } | 41 } |
| 42 | 42 |
| 43 void ScreenRotation::InitTransform(ui::Layer* layer) { | 43 void WindowRotation::InitTransform(ui::Layer* layer) { |
| 44 // No rotation required, use the identity transform. | 44 // No rotation required, use the identity transform. |
| 45 if (degrees_ == 0) { | 45 if (degrees_ == 0) { |
| 46 interpolated_transform_.reset( | 46 interpolated_transform_.reset( |
| 47 new ui::InterpolatedConstantTransform(gfx::Transform())); | 47 new ui::InterpolatedConstantTransform(gfx::Transform())); |
| 48 return; | 48 return; |
| 49 } | 49 } |
| 50 | 50 |
| 51 // Use the target transform/bounds in case the layer is already animating. | 51 // Use the target transform/bounds in case the layer is already animating. |
| 52 const gfx::Transform& current_transform = layer->GetTargetTransform(); | 52 const gfx::Transform& current_transform = layer->GetTargetTransform(); |
| 53 const gfx::Rect& bounds = layer->GetTargetBounds(); | 53 const gfx::Rect& bounds = layer->GetTargetBounds(); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 72 break; | 72 break; |
| 73 } | 73 } |
| 74 | 74 |
| 75 // Convert points to world space. | 75 // Convert points to world space. |
| 76 current_transform.TransformPoint(&old_pivot); | 76 current_transform.TransformPoint(&old_pivot); |
| 77 current_transform.TransformPoint(&new_pivot); | 77 current_transform.TransformPoint(&new_pivot); |
| 78 current_transform.TransformPoint(&new_origin_); | 78 current_transform.TransformPoint(&new_origin_); |
| 79 | 79 |
| 80 scoped_ptr<ui::InterpolatedTransform> rotation( | 80 scoped_ptr<ui::InterpolatedTransform> rotation( |
| 81 new ui::InterpolatedTransformAboutPivot( | 81 new ui::InterpolatedTransformAboutPivot( |
| 82 old_pivot, | 82 old_pivot, new ui::InterpolatedRotation(0, degrees_))); |
| 83 new ui::InterpolatedRotation(0, degrees_))); | |
| 84 | 83 |
| 85 scoped_ptr<ui::InterpolatedTransform> translation( | 84 scoped_ptr<ui::InterpolatedTransform> translation( |
| 86 new ui::InterpolatedTranslation( | 85 new ui::InterpolatedTranslation( |
| 87 gfx::Point(0, 0), | 86 gfx::Point(0, 0), gfx::Point(new_pivot.x() - old_pivot.x(), |
| 88 gfx::Point(new_pivot.x() - old_pivot.x(), | 87 new_pivot.y() - old_pivot.y()))); |
| 89 new_pivot.y() - old_pivot.y()))); | |
| 90 | 88 |
| 91 float scale_factor = 0.9f; | 89 float scale_factor = 0.9f; |
| 92 scoped_ptr<ui::InterpolatedTransform> scale_down( | 90 scoped_ptr<ui::InterpolatedTransform> scale_down( |
| 93 new ui::InterpolatedScale(1.0f, scale_factor, 0.0f, 0.5f)); | 91 new ui::InterpolatedScale(1.0f, scale_factor, 0.0f, 0.5f)); |
| 94 | 92 |
| 95 scoped_ptr<ui::InterpolatedTransform> scale_up( | 93 scoped_ptr<ui::InterpolatedTransform> scale_up( |
| 96 new ui::InterpolatedScale(1.0f, 1.0f / scale_factor, 0.5f, 1.0f)); | 94 new ui::InterpolatedScale(1.0f, 1.0f / scale_factor, 0.5f, 1.0f)); |
| 97 | 95 |
| 98 interpolated_transform_.reset( | 96 interpolated_transform_.reset( |
| 99 new ui::InterpolatedConstantTransform(current_transform)); | 97 new ui::InterpolatedConstantTransform(current_transform)); |
| 100 | 98 |
| 101 scale_up->SetChild(scale_down.release()); | 99 scale_up->SetChild(scale_down.release()); |
| 102 translation->SetChild(scale_up.release()); | 100 translation->SetChild(scale_up.release()); |
| 103 rotation->SetChild(translation.release()); | 101 rotation->SetChild(translation.release()); |
| 104 interpolated_transform_->SetChild(rotation.release()); | 102 interpolated_transform_->SetChild(rotation.release()); |
| 105 } | 103 } |
| 106 | 104 |
| 107 void ScreenRotation::OnStart(ui::LayerAnimationDelegate* delegate) { | 105 void WindowRotation::OnStart(ui::LayerAnimationDelegate* delegate) { |
| 108 } | 106 } |
| 109 | 107 |
| 110 bool ScreenRotation::OnProgress(double t, | 108 bool WindowRotation::OnProgress(double t, |
| 111 ui::LayerAnimationDelegate* delegate) { | 109 ui::LayerAnimationDelegate* delegate) { |
| 112 delegate->SetTransformFromAnimation(interpolated_transform_->Interpolate(t)); | 110 delegate->SetTransformFromAnimation(interpolated_transform_->Interpolate(t)); |
| 113 return true; | 111 return true; |
| 114 } | 112 } |
| 115 | 113 |
| 116 void ScreenRotation::OnGetTarget(TargetValue* target) const { | 114 void WindowRotation::OnGetTarget(TargetValue* target) const { |
| 117 target->transform = interpolated_transform_->Interpolate(1.0); | 115 target->transform = interpolated_transform_->Interpolate(1.0); |
| 118 } | 116 } |
| 119 | 117 |
| 120 void ScreenRotation::OnAbort(ui::LayerAnimationDelegate* delegate) { | 118 void WindowRotation::OnAbort(ui::LayerAnimationDelegate* delegate) { |
| 121 } | 119 } |
| 122 | 120 |
| 123 } // namespace ash | 121 } // namespace ash |
| OLD | NEW |