| OLD | NEW | 
|    1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |    1 // Copyright (c) 2011 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 "ui/aura/screen_rotation.h" |    5 #include "ui/gfx/compositor/screen_rotation.h" | 
|    6  |    6  | 
|    7 #include "base/debug/trace_event.h" |    7 #include "base/debug/trace_event.h" | 
|    8 #include "base/time.h" |    8 #include "base/time.h" | 
|    9 #include "ui/gfx/compositor/layer_animation_delegate.h" |    9 #include "ui/gfx/compositor/layer_animation_delegate.h" | 
|   10 #include "ui/gfx/interpolated_transform.h" |   10 #include "ui/gfx/interpolated_transform.h" | 
|   11 #include "ui/gfx/rect.h" |   11 #include "ui/gfx/rect.h" | 
|   12 #include "ui/gfx/transform.h" |   12 #include "ui/gfx/transform.h" | 
|   13  |   13  | 
 |   14 namespace ui { | 
 |   15  | 
|   14 namespace { |   16 namespace { | 
|   15  |   17  | 
|   16 const int k90DegreeTransitionDurationMs = 350; |   18 const int k90DegreeTransitionDurationMs = 350; | 
|   17 const int k180DegreeTransitionDurationMs = 550; |   19 const int k180DegreeTransitionDurationMs = 550; | 
|   18  |   20  | 
|   19 base::TimeDelta GetTransitionDuration(int degrees) { |   21 base::TimeDelta GetTransitionDuration(int degrees) { | 
|   20   if (degrees == 180) |   22   if (degrees == 180) | 
|   21     return base::TimeDelta::FromMilliseconds(k180DegreeTransitionDurationMs); |   23     return base::TimeDelta::FromMilliseconds(k180DegreeTransitionDurationMs); | 
|   22   else if (degrees == 0) |   24   else if (degrees == 0) | 
|   23     return base::TimeDelta::FromMilliseconds(0); |   25     return base::TimeDelta::FromMilliseconds(0); | 
|   24   return base::TimeDelta::FromMilliseconds(k90DegreeTransitionDurationMs); |   26   return base::TimeDelta::FromMilliseconds(k90DegreeTransitionDurationMs); | 
|   25 } |   27 } | 
|   26  |   28  | 
|   27 }  // namespace |   29 }  // namespace | 
|   28  |   30  | 
|   29 ScreenRotation::ScreenRotation(int degrees) |   31 ScreenRotation::ScreenRotation(int degrees) | 
|   30     : ui::LayerAnimationElement(GetProperties(), |   32     : LayerAnimationElement(GetProperties(), GetTransitionDuration(degrees)), | 
|   31                                 GetTransitionDuration(degrees)), |  | 
|   32       degrees_(degrees) { |   33       degrees_(degrees) { | 
|   33 } |   34 } | 
|   34  |   35  | 
|   35 ScreenRotation::~ScreenRotation() { |   36 ScreenRotation::~ScreenRotation() { | 
|   36 } |   37 } | 
|   37  |   38  | 
|   38 void ScreenRotation::OnStart(ui::LayerAnimationDelegate* delegate) { |   39 void ScreenRotation::OnStart(LayerAnimationDelegate* delegate) { | 
|   39   //TRACE_EVENT0("ScreenRotation", "init"); |  | 
|   40  |  | 
|   41   // No rotation required. |   40   // No rotation required. | 
|   42   if (degrees_ == 0) |   41   if (degrees_ == 0) | 
|   43     return; |   42     return; | 
|   44  |   43  | 
|   45   const ui::Transform& current_transform = delegate->GetTransformForAnimation(); |   44   const Transform& current_transform = delegate->GetTransformForAnimation(); | 
|   46   const gfx::Rect& bounds = delegate->GetBoundsForAnimation(); |   45   const gfx::Rect& bounds = delegate->GetBoundsForAnimation(); | 
|   47  |   46  | 
|   48   gfx::Point old_pivot; |   47   gfx::Point old_pivot; | 
|   49   gfx::Point new_pivot; |   48   gfx::Point new_pivot; | 
|   50  |   49  | 
|   51   int width = bounds.width(); |   50   int width = bounds.width(); | 
|   52   int height = bounds.height(); |   51   int height = bounds.height(); | 
|   53  |   52  | 
|   54   switch (degrees_) { |   53   switch (degrees_) { | 
|   55     case 90: |   54     case 90: | 
|   56       new_origin_ = new_pivot = gfx::Point(width, 0); |   55       new_origin_ = new_pivot = gfx::Point(width, 0); | 
|   57       break; |   56       break; | 
|   58     case -90: |   57     case -90: | 
|   59       new_origin_ = new_pivot = gfx::Point(0, height); |   58       new_origin_ = new_pivot = gfx::Point(0, height); | 
|   60       break; |   59       break; | 
|   61     case 180: |   60     case 180: | 
|   62       new_pivot = old_pivot = gfx::Point(width / 2, height / 2); |   61       new_pivot = old_pivot = gfx::Point(width / 2, height / 2); | 
|   63       new_origin_.SetPoint(width, height); |   62       new_origin_.SetPoint(width, height); | 
|   64       break; |   63       break; | 
|   65   } |   64   } | 
|   66  |   65  | 
|   67   // Convert points to world space. |   66   // Convert points to world space. | 
|   68   current_transform.TransformPoint(old_pivot); |   67   current_transform.TransformPoint(old_pivot); | 
|   69   current_transform.TransformPoint(new_pivot); |   68   current_transform.TransformPoint(new_pivot); | 
|   70   current_transform.TransformPoint(new_origin_); |   69   current_transform.TransformPoint(new_origin_); | 
|   71  |   70  | 
|   72   scoped_ptr<ui::InterpolatedTransform> rotation( |   71   scoped_ptr<InterpolatedTransform> rotation( | 
|   73       new ui::InterpolatedTransformAboutPivot( |   72       new InterpolatedTransformAboutPivot( | 
|   74           old_pivot, |   73           old_pivot, | 
|   75           new ui::InterpolatedRotation(0, degrees_))); |   74           new InterpolatedRotation(0, degrees_))); | 
|   76  |   75  | 
|   77   scoped_ptr<ui::InterpolatedTransform> translation( |   76   scoped_ptr<InterpolatedTransform> translation( | 
|   78       new ui::InterpolatedTranslation( |   77       new InterpolatedTranslation( | 
|   79           gfx::Point(0, 0), |   78           gfx::Point(0, 0), | 
|   80           gfx::Point(new_pivot.x() - old_pivot.x(), |   79           gfx::Point(new_pivot.x() - old_pivot.x(), | 
|   81                      new_pivot.y() - old_pivot.y()))); |   80                      new_pivot.y() - old_pivot.y()))); | 
|   82  |   81  | 
|   83   float scale_factor = 0.9f; |   82   float scale_factor = 0.9f; | 
|   84   scoped_ptr<ui::InterpolatedTransform> scale_down( |   83   scoped_ptr<InterpolatedTransform> scale_down( | 
|   85       new ui::InterpolatedScale(1.0f, scale_factor, 0.0f, 0.5f)); |   84       new InterpolatedScale(1.0f, scale_factor, 0.0f, 0.5f)); | 
|   86  |   85  | 
|   87   scoped_ptr<ui::InterpolatedTransform> scale_up( |   86   scoped_ptr<InterpolatedTransform> scale_up( | 
|   88       new ui::InterpolatedScale(1.0f, 1.0f / scale_factor, 0.5f, 1.0f)); |   87       new InterpolatedScale(1.0f, 1.0f / scale_factor, 0.5f, 1.0f)); | 
|   89  |   88  | 
|   90   interpolated_transform_.reset( |   89   interpolated_transform_.reset( | 
|   91       new ui::InterpolatedConstantTransform(current_transform)); |   90       new InterpolatedConstantTransform(current_transform)); | 
|   92  |   91  | 
|   93   scale_up->SetChild(scale_down.release()); |   92   scale_up->SetChild(scale_down.release()); | 
|   94   translation->SetChild(scale_up.release()); |   93   translation->SetChild(scale_up.release()); | 
|   95   rotation->SetChild(translation.release()); |   94   rotation->SetChild(translation.release()); | 
|   96   interpolated_transform_->SetChild(rotation.release()); |   95   interpolated_transform_->SetChild(rotation.release()); | 
|   97 } |   96 } | 
|   98  |   97  | 
|   99 void ScreenRotation::OnProgress(double t, |   98 void ScreenRotation::OnProgress(double t, | 
|  100                                 ui::LayerAnimationDelegate* delegate) { |   99                                 LayerAnimationDelegate* delegate) { | 
|  101   //TRACE_EVENT0("ScreenRotation", "Progress"); |  | 
|  102   delegate->SetTransformFromAnimation(interpolated_transform_->Interpolate(t)); |  100   delegate->SetTransformFromAnimation(interpolated_transform_->Interpolate(t)); | 
|  103   delegate->ScheduleDrawForAnimation(); |  101   delegate->ScheduleDrawForAnimation(); | 
|  104 } |  102 } | 
|  105  |  103  | 
|  106 void ScreenRotation::OnGetTarget(TargetValue* target) const { |  104 void ScreenRotation::OnGetTarget(TargetValue* target) const { | 
|  107   target->transform = interpolated_transform_->Interpolate(1.0); |  105   target->transform = interpolated_transform_->Interpolate(1.0); | 
|  108 } |  106 } | 
|  109  |  107  | 
|  110 void ScreenRotation::OnAbort() { |  108 void ScreenRotation::OnAbort() { | 
|  111 } |  109 } | 
|  112  |  110  | 
|  113 // static |  111 // static | 
|  114 const ui::LayerAnimationElement::AnimatableProperties& |  112 const LayerAnimationElement::AnimatableProperties& | 
|  115 ScreenRotation::GetProperties() { |  113 ScreenRotation::GetProperties() { | 
|  116   static LayerAnimationElement::AnimatableProperties properties; |  114   static LayerAnimationElement::AnimatableProperties properties; | 
|  117   if (properties.empty()) |  115   if (properties.empty()) | 
|  118     properties.insert(LayerAnimationElement::TRANSFORM); |  116     properties.insert(LayerAnimationElement::TRANSFORM); | 
|  119   return properties; |  117   return properties; | 
|  120 } |  118 } | 
 |  119  | 
 |  120 }  // namespace ui | 
| OLD | NEW |