| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/scroll_offset_animations_impl.h" | 5 #include "cc/animation/scroll_offset_animations_impl.h" |
| 6 | 6 |
| 7 #include "cc/animation/animation_events.h" | 7 #include "cc/animation/animation_events.h" |
| 8 #include "cc/animation/animation_host.h" | 8 #include "cc/animation/animation_host.h" |
| 9 #include "cc/animation/animation_id_provider.h" | 9 #include "cc/animation/animation_id_provider.h" |
| 10 #include "cc/animation/animation_player.h" | 10 #include "cc/animation/animation_player.h" |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 new_target.SetToMax(gfx::ScrollOffset()); | 85 new_target.SetToMax(gfx::ScrollOffset()); |
| 86 new_target.SetToMin(max_scroll_offset); | 86 new_target.SetToMin(max_scroll_offset); |
| 87 | 87 |
| 88 curve->UpdateTarget( | 88 curve->UpdateTarget( |
| 89 animation->TrimTimeToCurrentIteration(frame_monotonic_time).InSecondsF(), | 89 animation->TrimTimeToCurrentIteration(frame_monotonic_time).InSecondsF(), |
| 90 new_target); | 90 new_target); |
| 91 | 91 |
| 92 return true; | 92 return true; |
| 93 } | 93 } |
| 94 | 94 |
| 95 void ScrollOffsetAnimationsImpl::ScrollAnimationApplyAdjustment( |
| 96 ElementId element_id, |
| 97 const gfx::Vector2dF& adjustment, |
| 98 base::TimeTicks frame_monotonic_time) { |
| 99 DCHECK(scroll_offset_animation_player_); |
| 100 if (element_id != scroll_offset_animation_player_->element_id()) |
| 101 return; |
| 102 |
| 103 if (!scroll_offset_animation_player_->element_animations()) |
| 104 return; |
| 105 |
| 106 Animation* animation = |
| 107 scroll_offset_animation_player_->element_animations()->GetAnimation( |
| 108 TargetProperty::SCROLL_OFFSET); |
| 109 if (!animation) |
| 110 return; |
| 111 |
| 112 // Abort the old animation. |
| 113 ScrollAnimationAbort(/* needs_completion */ false); |
| 114 |
| 115 // Start a new one with the adjusment. |
| 116 std::unique_ptr<ScrollOffsetAnimationCurve> new_curve = |
| 117 animation->curve() |
| 118 ->ToScrollOffsetAnimationCurve() |
| 119 ->CloneToScrollOffsetAnimationCurve(); |
| 120 new_curve->ApplyAdjustment( |
| 121 animation->TrimTimeToCurrentIteration(frame_monotonic_time), adjustment); |
| 122 |
| 123 std::unique_ptr<Animation> new_animation = Animation::Create( |
| 124 std::move(new_curve), AnimationIdProvider::NextAnimationId(), |
| 125 AnimationIdProvider::NextGroupId(), TargetProperty::SCROLL_OFFSET); |
| 126 new_animation->set_is_impl_only(true); |
| 127 new_animation->set_affects_active_elements(false); |
| 128 |
| 129 scroll_offset_animation_player_->AddAnimation(std::move(new_animation)); |
| 130 } |
| 131 |
| 95 void ScrollOffsetAnimationsImpl::ScrollAnimationAbort(bool needs_completion) { | 132 void ScrollOffsetAnimationsImpl::ScrollAnimationAbort(bool needs_completion) { |
| 96 DCHECK(scroll_offset_animation_player_); | 133 DCHECK(scroll_offset_animation_player_); |
| 97 scroll_offset_animation_player_->AbortAnimations( | 134 scroll_offset_animation_player_->AbortAnimations( |
| 98 TargetProperty::SCROLL_OFFSET, needs_completion); | 135 TargetProperty::SCROLL_OFFSET, needs_completion); |
| 99 } | 136 } |
| 100 | 137 |
| 101 void ScrollOffsetAnimationsImpl::NotifyAnimationFinished( | 138 void ScrollOffsetAnimationsImpl::NotifyAnimationFinished( |
| 102 base::TimeTicks monotonic_time, | 139 base::TimeTicks monotonic_time, |
| 103 TargetProperty::Type target_property, | 140 TargetProperty::Type target_property, |
| 104 int group) { | 141 int group) { |
| 105 DCHECK_EQ(target_property, TargetProperty::SCROLL_OFFSET); | 142 DCHECK_EQ(target_property, TargetProperty::SCROLL_OFFSET); |
| 106 DCHECK(animation_host_->mutator_host_client()); | 143 DCHECK(animation_host_->mutator_host_client()); |
| 107 animation_host_->mutator_host_client()->ScrollOffsetAnimationFinished(); | 144 animation_host_->mutator_host_client()->ScrollOffsetAnimationFinished(); |
| 108 } | 145 } |
| 109 | 146 |
| 110 void ScrollOffsetAnimationsImpl::ReattachScrollOffsetPlayerIfNeeded( | 147 void ScrollOffsetAnimationsImpl::ReattachScrollOffsetPlayerIfNeeded( |
| 111 ElementId element_id) { | 148 ElementId element_id) { |
| 112 if (scroll_offset_animation_player_->element_id() != element_id) { | 149 if (scroll_offset_animation_player_->element_id() != element_id) { |
| 113 if (scroll_offset_animation_player_->element_id()) | 150 if (scroll_offset_animation_player_->element_id()) |
| 114 scroll_offset_animation_player_->DetachElement(); | 151 scroll_offset_animation_player_->DetachElement(); |
| 115 if (element_id) | 152 if (element_id) |
| 116 scroll_offset_animation_player_->AttachElement(element_id); | 153 scroll_offset_animation_player_->AttachElement(element_id); |
| 117 } | 154 } |
| 118 } | 155 } |
| 119 | 156 |
| 120 } // namespace cc | 157 } // namespace cc |
| OLD | NEW |