Index: chrome/browser/ui/touch/animation/screen_rotation_animator.cc |
diff --git a/chrome/browser/ui/touch/animation/screen_rotation_setter.cc b/chrome/browser/ui/touch/animation/screen_rotation_animator.cc |
similarity index 59% |
rename from chrome/browser/ui/touch/animation/screen_rotation_setter.cc |
rename to chrome/browser/ui/touch/animation/screen_rotation_animator.cc |
index a20774bd116b01a97d74505b5d82424d43e39447..9457760f51318d98ca90e8c25cf434cc7a01b817 100644 |
--- a/chrome/browser/ui/touch/animation/screen_rotation_setter.cc |
+++ b/chrome/browser/ui/touch/animation/screen_rotation_animator.cc |
@@ -2,13 +2,12 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#include "chrome/browser/ui/touch/animation/screen_rotation_setter.h" |
+#include "chrome/browser/ui/touch/animation/screen_rotation_animator.h" |
#include "base/memory/scoped_ptr.h" |
#include "chrome/browser/ui/touch/animation/screen_rotation.h" |
#include "ui/gfx/compositor/layer.h" |
#include "ui/gfx/interpolated_transform.h" |
-#include "views/layer_property_setter.h" |
#include "views/view.h" |
namespace { |
@@ -20,26 +19,25 @@ static int SymmetricRound(float x) { |
: std::ceil(x - 0.5f)); |
} |
-// A screen rotation setter is a LayerPropertySetter that initiates screen |
+// A screen rotation animator is a LayerAnimator that initiates screen |
// rotations in response to calls to |SetTransform|. Calls to |SetBounds| are |
// applied to the layer immediately. |
-class ScreenRotationSetter : public views::LayerPropertySetter, |
- public ScreenRotationListener { |
+class ScreenRotationAnimator : public ui::LayerAnimator, |
+ public ScreenRotationListener { |
public: |
- explicit ScreenRotationSetter(views::View* view); |
+ explicit ScreenRotationAnimator(views::View* view); |
+ virtual ~ScreenRotationAnimator(); |
- // implementation of LayerPropertySetter |
- virtual void Installed(ui::Layer* layer) OVERRIDE; |
- virtual void Uninstalled(ui::Layer* layer) OVERRIDE; |
- virtual void SetTransform(ui::Layer* layer, |
- const ui::Transform& transform) OVERRIDE; |
- virtual void SetBounds(ui::Layer* layer, const gfx::Rect& bounds) OVERRIDE; |
+ private: |
+ // implementation of LayerAnimator |
+ virtual void SetLayer(ui::Layer* layer) OVERRIDE; |
+ virtual void SetTransform(const ui::Transform& transform) OVERRIDE; |
+ virtual void SetBounds(const gfx::Rect& bounds) OVERRIDE; |
// implementation of ScreenRotationListener |
virtual void OnScreenRotationCompleted(const ui::Transform& final_transform, |
const gfx::Rect& final_rect) OVERRIDE; |
- private: |
// This is the currently animating rotation. We hang onto it so that if a |
// call to |SetTransform| is made during the rotation, we can update the |
// target orientation of this rotation. |
@@ -55,36 +53,41 @@ class ScreenRotationSetter : public views::LayerPropertySetter, |
// call to SetTransform will have any effect. |
scoped_ptr<ui::Transform> pending_transform_; |
- // The screen rotation setter is associated with a view so that the view's |
+ // The screen rotation animator is associated with a view so that the view's |
// bounds may be set when the animation completes. |
views::View* view_; |
- DISALLOW_COPY_AND_ASSIGN(ScreenRotationSetter); |
+ DISALLOW_COPY_AND_ASSIGN(ScreenRotationAnimator); |
}; |
-ScreenRotationSetter::ScreenRotationSetter(views::View* view) : view_(view) { |
+ScreenRotationAnimator::ScreenRotationAnimator(views::View* view) |
+ : ui::LayerAnimator(base::TimeDelta::FromMilliseconds(0)), |
+ view_(view) { |
} |
-void ScreenRotationSetter::Installed(ui::Layer* layer) OVERRIDE { |
+ScreenRotationAnimator::~ScreenRotationAnimator() { |
} |
-void ScreenRotationSetter::Uninstalled(ui::Layer* layer) OVERRIDE { |
- if (rotation_.get()) |
+void ScreenRotationAnimator::SetLayer(ui::Layer* layer) { |
+ if (!layer && rotation_.get()) |
rotation_->Stop(); |
+ |
+ DCHECK(!layer || layer == view_->layer()); |
+ ui::LayerAnimator::SetDelegate(layer); |
} |
-void ScreenRotationSetter::SetTransform(ui::Layer* layer, |
- const ui::Transform& transform) { |
+void ScreenRotationAnimator::SetTransform(const ui::Transform& transform) { |
if (rotation_.get()) { |
pending_transform_.reset(new ui::Transform(transform)); |
} else { |
float new_degrees, old_degrees; |
- if (ui::InterpolatedTransform::FactorTRS(transform, |
- NULL, &new_degrees, NULL) && |
- ui::InterpolatedTransform::FactorTRS(layer->transform(), |
- NULL, &old_degrees, NULL)) { |
+ if (ui::InterpolatedTransform::FactorTRS( |
+ transform, NULL, &new_degrees, NULL) && |
+ ui::InterpolatedTransform::FactorTRS( |
+ delegate()->GetTransformForAnimation(), NULL, &old_degrees, NULL)) { |
rotation_.reset(new ScreenRotation(view_, |
+ delegate(), |
this, |
SymmetricRound(old_degrees), |
SymmetricRound(new_degrees))); |
@@ -92,25 +95,24 @@ void ScreenRotationSetter::SetTransform(ui::Layer* layer, |
} |
} |
-void ScreenRotationSetter::SetBounds(ui::Layer* layer, |
- const gfx::Rect& bounds) { |
+void ScreenRotationAnimator::SetBounds(const gfx::Rect& bounds) { |
// cache bounds changes during an animation. |
if (rotation_.get()) |
pending_bounds_.reset(new gfx::Rect(bounds)); |
else |
- layer->SetBounds(bounds); |
+ delegate()->SetBoundsFromAnimation(bounds); |
} |
-void ScreenRotationSetter::OnScreenRotationCompleted( |
+void ScreenRotationAnimator::OnScreenRotationCompleted( |
const ui::Transform& final_transform, |
const gfx::Rect& final_bounds) { |
// destroy the animation. |
rotation_.reset(); |
- if (pending_bounds_.get() && view_->layer()) { |
+ if (pending_bounds_.get() && delegate()) { |
// If there are any pending bounds changes, they will have already been |
// applied to the view, and are waiting to be applied to the layer. |
- view_->layer()->SetBounds(*pending_bounds_); |
+ delegate()->SetBoundsFromAnimation(*pending_bounds_); |
pending_bounds_.reset(); |
} else if (!final_bounds.IsEmpty()) { |
// Otherwise we may have new bounds as the result of the completed screen |
@@ -118,17 +120,16 @@ void ScreenRotationSetter::OnScreenRotationCompleted( |
view_->SetBoundsRect(final_bounds); |
} |
- if (pending_transform_.get() && view_->layer()) { |
+ if (pending_transform_.get() && delegate()) { |
// If there is a pending transformation, we need to initiate another |
// animation. |
- SetTransform(view_->layer(), *pending_transform_); |
+ SetTransform(*pending_transform_); |
pending_transform_.reset(); |
} |
} |
} // namespace |
-views::LayerPropertySetter* ScreenRotationSetterFactory::Create( |
- views::View* view) { |
- return new ScreenRotationSetter(view); |
+ui::LayerAnimator* ScreenRotationAnimatorFactory::Create(views::View* view) { |
+ return new ScreenRotationAnimator(view); |
} |