Chromium Code Reviews| Index: cc/animation/animation_timeline.cc |
| diff --git a/cc/animation/animation_timeline.cc b/cc/animation/animation_timeline.cc |
| index b1b25b4b0cf59866580a3e7535a6dca4f7ce32a2..52dc2afe6d67d5cec0b09203c534c28122504135 100644 |
| --- a/cc/animation/animation_timeline.cc |
| +++ b/cc/animation/animation_timeline.cc |
| @@ -6,9 +6,13 @@ |
| #include <algorithm> |
| +#include "cc/animation/animation_id_provider.h" |
| #include "cc/animation/animation_player.h" |
| #include "cc/animation/animation_registrar.h" |
| +#include "cc/animation/scroll_offset_animation_curve.h" |
| +#include "cc/animation/timing_function.h" |
| #include "ui/gfx/geometry/box_f.h" |
| +#include "ui/gfx/geometry/scroll_offset.h" |
| namespace cc { |
| @@ -19,11 +23,16 @@ scoped_refptr<AnimationTimeline> AnimationTimeline::Create() { |
| AnimationTimeline::AnimationTimeline() |
| : animation_registrar_(AnimationRegistrar::Create()), |
| layer_tree_mutators_client_() { |
| + scroll_offset_animation_player_ = |
| + AnimationPlayer::Create(AnimationIdProvider::NextPlayerId()); |
| + AttachPlayer(scroll_offset_animation_player_.get()); |
| } |
| AnimationTimeline::~AnimationTimeline() { |
| DCHECK(!layer_tree_mutators_client()); |
| + DetachPlayer(scroll_offset_animation_player_.get()); |
| + |
| for (auto& player : players_) |
| player->SetAnimationTimeline(nullptr); |
| } |
| @@ -326,4 +335,53 @@ bool AnimationTimeline::HasActiveAnimation(int layer_id) const { |
| : false; |
| } |
| +void AnimationTimeline::ScrollAnimationCreate( |
| + int layer_id, |
| + const gfx::ScrollOffset& target_offset, |
| + const gfx::ScrollOffset& current_offset) { |
| + scoped_ptr<ScrollOffsetAnimationCurve> curve = |
| + ScrollOffsetAnimationCurve::Create(target_offset, |
| + EaseInOutTimingFunction::Create()); |
| + curve->SetInitialValue(current_offset); |
| + |
| + scoped_ptr<Animation> animation = Animation::Create( |
| + curve.Pass(), AnimationIdProvider::NextAnimationId(), |
| + AnimationIdProvider::NextGroupId(), Animation::SCROLL_OFFSET); |
| + animation->set_is_impl_only(true); |
|
ajuma
2015/03/24 13:37:23
Not all scroll animations are impl-only, so this m
loyso (OOO)
2015/04/13 07:38:24
Done.
|
| + |
| + scroll_offset_animation_player_->AttachLayer(layer_id); |
| + scroll_offset_animation_player_->AddAnimation(animation.Pass()); |
| +} |
| + |
| +bool AnimationTimeline::ScrollAnimationUpdateTarget( |
| + int layer_id, |
| + const gfx::Vector2dF& scroll_delta, |
| + const gfx::ScrollOffset& max_scroll_offset, |
| + base::TimeTicks frame_monotonic_time) { |
| + DCHECK(scroll_offset_animation_player_.get()); |
| + DCHECK_EQ(layer_id, scroll_offset_animation_player_->layer_id()); |
| + |
| + Animation* animation = |
| + scroll_offset_animation_player_->layer_animation_controller() |
| + ->GetAnimation(Animation::SCROLL_OFFSET); |
| + if (!animation) { |
| + scroll_offset_animation_player_->DetachLayer(); |
| + return false; |
| + } |
| + |
| + ScrollOffsetAnimationCurve* curve = |
| + animation->curve()->ToScrollOffsetAnimationCurve(); |
| + |
| + gfx::ScrollOffset new_target = |
| + gfx::ScrollOffsetWithDelta(curve->target_value(), scroll_delta); |
| + new_target.SetToMax(gfx::ScrollOffset()); |
| + new_target.SetToMin(max_scroll_offset); |
| + |
| + curve->UpdateTarget( |
| + animation->TrimTimeToCurrentIteration(frame_monotonic_time).InSecondsF(), |
| + new_target); |
| + |
| + return true; |
| +} |
| + |
| } // namespace cc |