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

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

Issue 8362006: Reland r107720 - Enable the new layer animation framework. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge 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
« no previous file with comments | « ui/gfx/compositor/layer_animator.h ('k') | ui/gfx/compositor/layer_animator_delegate.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/compositor/layer_animator.cc
diff --git a/ui/gfx/compositor/layer_animator.cc b/ui/gfx/compositor/layer_animator.cc
index e737377c86c600ca0674470eba190fc75b18ee7f..8004c5cdea2d08439903dcbcbde340f8e4605d5b 100644
--- a/ui/gfx/compositor/layer_animator.cc
+++ b/ui/gfx/compositor/layer_animator.cc
@@ -10,7 +10,7 @@
#include "ui/base/animation/animation_container.h"
#include "ui/gfx/compositor/compositor.h"
#include "ui/gfx/compositor/layer.h"
-#include "ui/gfx/compositor/layer_animation_delegate.h"
+#include "ui/gfx/compositor/layer_animator_delegate.h"
#include "ui/gfx/compositor/layer_animation_sequence.h"
namespace ui {
@@ -20,7 +20,7 @@ class LayerAnimator;
namespace {
static const base::TimeDelta kDefaultTransitionDuration =
- base::TimeDelta::FromMilliseconds(250);
+ base::TimeDelta::FromMilliseconds(200);
static const base::TimeDelta kTimerInterval =
base::TimeDelta::FromMilliseconds(10);
@@ -55,30 +55,45 @@ void LayerAnimator::SetTransform(const Transform& transform) {
if (transition_duration_ == base::TimeDelta())
delegate_->SetTransformFromAnimation(transform);
else
- StartAnimation(new LayerAnimationSequence(
- LayerAnimationElement::CreateTransformElement(transform,
- transition_duration_)));
+ StartAnimationElement(LayerAnimationElement::CreateTransformElement(
+ transform, transition_duration_));
+}
+
+Transform LayerAnimator::GetTargetTransform() const {
+ LayerAnimationElement::TargetValue target;
+ GetTargetValue(&target);
+ return target.transform;
}
void LayerAnimator::SetBounds(const gfx::Rect& bounds) {
if (transition_duration_ == base::TimeDelta())
delegate_->SetBoundsFromAnimation(bounds);
else
- StartAnimation(new LayerAnimationSequence(
- LayerAnimationElement::CreateBoundsElement(bounds,
- transition_duration_)));
+ StartAnimationElement(LayerAnimationElement::CreateBoundsElement(
+ bounds, transition_duration_));
+}
+
+gfx::Rect LayerAnimator::GetTargetBounds() const {
+ LayerAnimationElement::TargetValue target;
+ GetTargetValue(&target);
+ return target.bounds;
}
void LayerAnimator::SetOpacity(float opacity) {
if (transition_duration_ == base::TimeDelta())
delegate_->SetOpacityFromAnimation(opacity);
else
- StartAnimation(new LayerAnimationSequence(
- LayerAnimationElement::CreateOpacityElement(opacity,
- transition_duration_)));
+ StartAnimationElement(LayerAnimationElement::CreateOpacityElement(
+ opacity, transition_duration_));
}
-void LayerAnimator::SetDelegate(LayerAnimationDelegate* delegate) {
+float LayerAnimator::GetTargetOpacity() const {
+ LayerAnimationElement::TargetValue target;
+ GetTargetValue(&target);
+ return target.opacity;
+}
+
+void LayerAnimator::SetDelegate(LayerAnimatorDelegate* delegate) {
DCHECK(delegate);
delegate_ = delegate;
}
@@ -107,6 +122,7 @@ void LayerAnimator::StartAnimation(LayerAnimationSequence* animation) {
}
}
FinishAnyAnimationWithZeroDuration();
+ UpdateAnimationState();
}
void LayerAnimator::ScheduleAnimation(LayerAnimationSequence* animation) {
@@ -116,6 +132,7 @@ void LayerAnimator::ScheduleAnimation(LayerAnimationSequence* animation) {
} else {
StartSequenceImmediately(animation);
}
+ UpdateAnimationState();
}
void LayerAnimator::ScheduleTogether(
@@ -141,6 +158,24 @@ void LayerAnimator::ScheduleTogether(
for (iter = animations.begin(); iter != animations.end(); ++iter) {
ScheduleAnimation(*iter);
}
+
+ UpdateAnimationState();
+}
+
+void LayerAnimator::StartAnimationElement(LayerAnimationElement* animation) {
+ StartAnimation(new LayerAnimationSequence(animation));
+}
+
+void LayerAnimator::ScheduleAnimationElement(LayerAnimationElement* animation) {
+ ScheduleAnimation(new LayerAnimationSequence(animation));
+}
+
+void LayerAnimator::ScheduleElementsTogether(
+ const std::vector<LayerAnimationElement*>& animations) {
+ std::vector<LayerAnimationSequence*> sequences;
+ for (size_t i = 0; i < animations.size(); ++i)
+ sequences.push_back(new LayerAnimationSequence(animations[i]));
+ ScheduleTogether(sequences);
}
void LayerAnimator::StopAnimatingProperty(
@@ -158,10 +193,24 @@ void LayerAnimator::StopAnimating() {
FinishAnimation(running_animations_[0].sequence);
}
+LayerAnimator::ScopedSettings::ScopedSettings(LayerAnimator* animator)
+ : animator_(animator),
+ old_transition_duration_(animator->transition_duration_) {
+ SetTransitionDuration(kDefaultTransitionDuration);
+}
+
+LayerAnimator::ScopedSettings::~ScopedSettings() {
+ animator_->transition_duration_ = old_transition_duration_;
+}
+
+void LayerAnimator::ScopedSettings::SetTransitionDuration(
+ base::TimeDelta duration) {
+ animator_->transition_duration_ = duration;
+}
+
// LayerAnimator private -------------------------------------------------------
void LayerAnimator::Step(base::TimeTicks now) {
- TRACE_EVENT0("LayerAnimator", "Step");
last_step_time_ = now;
std::vector<LayerAnimationSequence*> to_finish;
for (RunningAnimations::iterator iter = running_animations_.begin();
@@ -228,6 +277,7 @@ void LayerAnimator::RemoveAnimation(LayerAnimationSequence* sequence) {
void LayerAnimator::FinishAnimation(LayerAnimationSequence* sequence) {
sequence->Progress(sequence->duration(), delegate());
+ delegate()->OnLayerAnimationEnded(sequence);
RemoveAnimation(sequence);
ProcessQueue();
UpdateAnimationState();
@@ -243,6 +293,7 @@ void LayerAnimator::FinishAnyAnimationWithZeroDuration() {
if (running_animations_[i].sequence->duration() == base::TimeDelta()) {
running_animations_[i].sequence->Progress(
running_animations_[i].sequence->duration(), delegate());
+ delegate()->OnLayerAnimationEnded(running_animations_[i].sequence);
RemoveAnimation(running_animations_[i].sequence);
} else {
++i;
@@ -300,11 +351,13 @@ void LayerAnimator::RemoveAllAnimationsWithACommonProperty(
if (running_animations_[i].sequence->HasCommonProperty(
sequence->properties())) {
// Finish the animation.
- if (abort)
+ if (abort){
running_animations_[i].sequence->Abort();
- else
+ } else {
running_animations_[i].sequence->Progress(
running_animations_[i].sequence->duration(), delegate());
+ delegate()->OnLayerAnimationEnded(running_animations_[i].sequence);
+ }
RemoveAnimation(running_animations_[i].sequence);
} else {
++i;
@@ -331,6 +384,7 @@ void LayerAnimator::ImmediatelySetNewTarget(LayerAnimationSequence* sequence) {
const bool abort = false;
RemoveAllAnimationsWithACommonProperty(sequence, abort);
sequence->Progress(sequence->duration(), delegate());
+ delegate()->OnLayerAnimationEnded(sequence);
RemoveAnimation(sequence);
}
@@ -377,10 +431,8 @@ void LayerAnimator::ProcessQueue() {
bool started_sequence = false;
do {
started_sequence = false;
-
// Build a list of all currently animated properties.
LayerAnimationElement::AnimatableProperties animated;
-
for (RunningAnimations::const_iterator iter = running_animations_.begin();
iter != running_animations_.end(); ++iter) {
animated.insert((*iter).sequence->properties().begin(),
@@ -440,4 +492,12 @@ bool LayerAnimator::StartSequenceImmediately(LayerAnimationSequence* sequence) {
return true;
}
+void LayerAnimator::GetTargetValue(
+ LayerAnimationElement::TargetValue* target) const {
+ for (RunningAnimations::const_iterator iter = running_animations_.begin();
+ iter != running_animations_.end(); ++iter) {
+ (*iter).sequence->GetTargetValue(target);
+ }
+}
+
} // namespace ui
« no previous file with comments | « ui/gfx/compositor/layer_animator.h ('k') | ui/gfx/compositor/layer_animator_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698