Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(105)

Unified Diff: ui/gfx/compositor/layer.cc

Issue 8362006: Reland r107720 - Enable the new layer animation framework. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge with parent patch Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/gfx/compositor/layer.cc
diff --git a/ui/gfx/compositor/layer.cc b/ui/gfx/compositor/layer.cc
index 3fae936a1655571fd5dbcee66712f888a51f284f..cbfadf7325e6cb84aa313a77fd9175671a01d39e 100644
--- a/ui/gfx/compositor/layer.cc
+++ b/ui/gfx/compositor/layer.cc
@@ -8,8 +8,7 @@
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
-#include "ui/base/animation/animation.h"
-#include "ui/gfx/compositor/layer_animation_manager.h"
+#include "ui/gfx/compositor/layer_animator.h"
#include "ui/gfx/canvas_skia.h"
#include "ui/gfx/interpolated_transform.h"
#include "ui/gfx/point3.h"
@@ -106,49 +105,54 @@ bool Layer::Contains(const Layer* other) const {
return false;
}
-void Layer::SetAnimation(Animation* animation) {
- if (animation) {
- if (!animator_.get())
- animator_.reset(new LayerAnimationManager(this));
- animation->Start();
- animator_->SetAnimation(animation);
- } else {
- animator_.reset();
- }
+void Layer::SetAnimator(LayerAnimator* animator) {
+ animator->SetDelegate(this);
sky 2011/10/20 20:30:30 Seems like you should allow NULL here to reset to
+ animator_.reset(animator);
+}
+
+LayerAnimator* Layer::GetAnimator() {
+ if (!animator_.get())
+ SetAnimator(LayerAnimator::CreateDefaultAnimator());
+ return animator_.get();
}
void Layer::SetTransform(const ui::Transform& transform) {
- StopAnimatingIfNecessary(LayerAnimationManager::TRANSFORM);
- if (animator_.get() && animator_->IsRunning()) {
- animator_->AnimateTransform(transform);
- return;
- }
- SetTransformImmediately(transform);
+ if (animator_.get())
+ animator_->SetTransform(transform);
+ else
+ SetTransformImmediately(transform);
+}
+
+Transform Layer::GetTargetTransform() const {
+ if (animator_.get() && animator_->is_animating())
+ return animator_->GetTargetTransform();
+ return transform_;
}
void Layer::SetBounds(const gfx::Rect& bounds) {
- StopAnimatingIfNecessary(LayerAnimationManager::LOCATION);
- if (animator_.get() && animator_->IsRunning() &&
- bounds.size() == bounds_.size()) {
- animator_->AnimateToPoint(bounds.origin());
- return;
- }
- SetBoundsImmediately(bounds);
+ if (animator_.get())
+ animator_->SetBounds(bounds);
+ else
+ SetBoundsImmediately(bounds);
}
gfx::Rect Layer::GetTargetBounds() const {
- if (animator_.get() && animator_->IsRunning())
- return gfx::Rect(animator_->GetTargetPoint(), bounds_.size());
+ if (animator_.get() && animator_->is_animating())
+ return animator_->GetTargetBounds();
return bounds_;
}
void Layer::SetOpacity(float opacity) {
- StopAnimatingIfNecessary(LayerAnimationManager::OPACITY);
- if (animator_.get() && animator_->IsRunning()) {
- animator_->AnimateOpacity(opacity);
- return;
- }
- SetOpacityImmediately(opacity);
+ if (animator_.get())
+ animator_->SetOpacity(opacity);
+ else
+ SetOpacityImmediately(opacity);
+}
+
+float Layer::GetTargetOpacity() const {
+ if (animator_.get() && animator_->is_animating())
+ return animator_->GetTargetOpacity();
+ return opacity_;
}
void Layer::SetVisible(bool visible) {
@@ -438,29 +442,6 @@ bool Layer::GetTransformRelativeTo(const Layer* ancestor,
return p == ancestor;
}
-void Layer::StopAnimatingIfNecessary(
- LayerAnimationManager::AnimationProperty property) {
- if (!animator_.get() || !animator_->IsRunning() ||
- !animator_->got_initial_tick()) {
- return;
- }
-
- if (property != LayerAnimationManager::LOCATION &&
- animator_->IsAnimating(LayerAnimationManager::LOCATION)) {
- SetBoundsImmediately(
- gfx::Rect(animator_->GetTargetPoint(), bounds_.size()));
- }
- if (property != LayerAnimationManager::OPACITY &&
- animator_->IsAnimating(LayerAnimationManager::OPACITY)) {
- SetOpacityImmediately(animator_->GetTargetOpacity());
- }
- if (property != LayerAnimationManager::TRANSFORM &&
- animator_->IsAnimating(LayerAnimationManager::TRANSFORM)) {
- SetTransformImmediately(animator_->GetTargetTransform());
- }
- animator_.reset();
-}
-
void Layer::SetBoundsImmediately(const gfx::Rect& bounds) {
bounds_ = bounds;
@@ -497,16 +478,32 @@ void Layer::SetOpacityImmediately(float opacity) {
}
}
-void Layer::SetBoundsFromAnimator(const gfx::Rect& bounds) {
+void Layer::SetBoundsFromAnimation(const gfx::Rect& bounds) {
SetBoundsImmediately(bounds);
}
-void Layer::SetTransformFromAnimator(const Transform& transform) {
+void Layer::SetTransformFromAnimation(const Transform& transform) {
SetTransformImmediately(transform);
}
-void Layer::SetOpacityFromAnimator(float opacity) {
+void Layer::SetOpacityFromAnimation(float opacity) {
SetOpacityImmediately(opacity);
}
+void Layer::ScheduleDrawForAnimation() {
+ ScheduleDraw();
+}
+
+const gfx::Rect& Layer::GetBoundsForAnimation() const {
+ return bounds();
+}
+
+const Transform& Layer::GetTransformForAnimation() const {
+ return transform();
+}
+
+float Layer::GetOpacityForAnimation() const {
+ return opacity();
+}
+
} // namespace ui

Powered by Google App Engine
This is Rietveld 408576698