Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "cc/animation/animation_timeline.h" | 5 #include "cc/animation/animation_timeline.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "cc/animation/animation_id_provider.h" | |
| 9 #include "cc/animation/animation_player.h" | 10 #include "cc/animation/animation_player.h" |
| 10 #include "cc/animation/animation_registrar.h" | 11 #include "cc/animation/animation_registrar.h" |
| 12 #include "cc/animation/scroll_offset_animation_curve.h" | |
| 13 #include "cc/animation/timing_function.h" | |
| 11 #include "ui/gfx/geometry/box_f.h" | 14 #include "ui/gfx/geometry/box_f.h" |
| 15 #include "ui/gfx/geometry/scroll_offset.h" | |
| 12 | 16 |
| 13 namespace cc { | 17 namespace cc { |
| 14 | 18 |
| 15 scoped_refptr<AnimationTimeline> AnimationTimeline::Create() { | 19 scoped_refptr<AnimationTimeline> AnimationTimeline::Create() { |
| 16 return make_scoped_refptr(new AnimationTimeline()); | 20 return make_scoped_refptr(new AnimationTimeline()); |
| 17 } | 21 } |
| 18 | 22 |
| 19 AnimationTimeline::AnimationTimeline() | 23 AnimationTimeline::AnimationTimeline() |
| 20 : animation_registrar_(AnimationRegistrar::Create()), | 24 : animation_registrar_(AnimationRegistrar::Create()), |
| 21 layer_tree_mutators_client_() { | 25 layer_tree_mutators_client_() { |
| 26 scroll_offset_animation_player_ = | |
| 27 AnimationPlayer::Create(AnimationIdProvider::NextPlayerId()); | |
| 28 AttachPlayer(scroll_offset_animation_player_.get()); | |
| 22 } | 29 } |
| 23 | 30 |
| 24 AnimationTimeline::~AnimationTimeline() { | 31 AnimationTimeline::~AnimationTimeline() { |
| 25 DCHECK(!layer_tree_mutators_client()); | 32 DCHECK(!layer_tree_mutators_client()); |
| 26 | 33 |
| 34 DetachPlayer(scroll_offset_animation_player_.get()); | |
| 35 | |
| 27 for (auto& player : players_) | 36 for (auto& player : players_) |
| 28 player->SetAnimationTimeline(nullptr); | 37 player->SetAnimationTimeline(nullptr); |
| 29 } | 38 } |
| 30 | 39 |
| 31 void AnimationTimeline::AttachPlayer(AnimationPlayer* player) { | 40 void AnimationTimeline::AttachPlayer(AnimationPlayer* player) { |
| 32 player->SetAnimationTimeline(this); | 41 player->SetAnimationTimeline(this); |
| 33 players_.push_back(player); | 42 players_.push_back(player); |
| 34 } | 43 } |
| 35 | 44 |
| 36 void AnimationTimeline::DetachPlayer(AnimationPlayer* player) { | 45 void AnimationTimeline::DetachPlayer(AnimationPlayer* player) { |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 319 return player ? player->layer_animation_controller()->has_any_animation() | 328 return player ? player->layer_animation_controller()->has_any_animation() |
| 320 : false; | 329 : false; |
| 321 } | 330 } |
| 322 | 331 |
| 323 bool AnimationTimeline::HasActiveAnimation(int layer_id) const { | 332 bool AnimationTimeline::HasActiveAnimation(int layer_id) const { |
| 324 AnimationPlayer* player = GetPlayerForLayerId(layer_id); | 333 AnimationPlayer* player = GetPlayerForLayerId(layer_id); |
| 325 return player ? player->layer_animation_controller()->HasActiveAnimation() | 334 return player ? player->layer_animation_controller()->HasActiveAnimation() |
| 326 : false; | 335 : false; |
| 327 } | 336 } |
| 328 | 337 |
| 338 void AnimationTimeline::ScrollAnimationCreate( | |
| 339 int layer_id, | |
| 340 const gfx::ScrollOffset& target_offset, | |
| 341 const gfx::ScrollOffset& current_offset) { | |
| 342 scoped_ptr<ScrollOffsetAnimationCurve> curve = | |
| 343 ScrollOffsetAnimationCurve::Create(target_offset, | |
| 344 EaseInOutTimingFunction::Create()); | |
| 345 curve->SetInitialValue(current_offset); | |
| 346 | |
| 347 scoped_ptr<Animation> animation = Animation::Create( | |
| 348 curve.Pass(), AnimationIdProvider::NextAnimationId(), | |
| 349 AnimationIdProvider::NextGroupId(), Animation::SCROLL_OFFSET); | |
| 350 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.
| |
| 351 | |
| 352 scroll_offset_animation_player_->AttachLayer(layer_id); | |
| 353 scroll_offset_animation_player_->AddAnimation(animation.Pass()); | |
| 354 } | |
| 355 | |
| 356 bool AnimationTimeline::ScrollAnimationUpdateTarget( | |
| 357 int layer_id, | |
| 358 const gfx::Vector2dF& scroll_delta, | |
| 359 const gfx::ScrollOffset& max_scroll_offset, | |
| 360 base::TimeTicks frame_monotonic_time) { | |
| 361 DCHECK(scroll_offset_animation_player_.get()); | |
| 362 DCHECK_EQ(layer_id, scroll_offset_animation_player_->layer_id()); | |
| 363 | |
| 364 Animation* animation = | |
| 365 scroll_offset_animation_player_->layer_animation_controller() | |
| 366 ->GetAnimation(Animation::SCROLL_OFFSET); | |
| 367 if (!animation) { | |
| 368 scroll_offset_animation_player_->DetachLayer(); | |
| 369 return false; | |
| 370 } | |
| 371 | |
| 372 ScrollOffsetAnimationCurve* curve = | |
| 373 animation->curve()->ToScrollOffsetAnimationCurve(); | |
| 374 | |
| 375 gfx::ScrollOffset new_target = | |
| 376 gfx::ScrollOffsetWithDelta(curve->target_value(), scroll_delta); | |
| 377 new_target.SetToMax(gfx::ScrollOffset()); | |
| 378 new_target.SetToMin(max_scroll_offset); | |
| 379 | |
| 380 curve->UpdateTarget( | |
| 381 animation->TrimTimeToCurrentIteration(frame_monotonic_time).InSecondsF(), | |
| 382 new_target); | |
| 383 | |
| 384 return true; | |
| 385 } | |
| 386 | |
| 329 } // namespace cc | 387 } // namespace cc |
| OLD | NEW |