| 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 DCHECK(scroll_offset_animation_player_); |
| 99 if (element_id != scroll_offset_animation_player_->element_id()) |
| 100 return; |
| 101 |
| 102 if (!scroll_offset_animation_player_->element_animations()) |
| 103 return; |
| 104 |
| 105 Animation* animation = |
| 106 scroll_offset_animation_player_->element_animations()->GetAnimation( |
| 107 TargetProperty::SCROLL_OFFSET); |
| 108 if (!animation) |
| 109 return; |
| 110 |
| 111 std::unique_ptr<ScrollOffsetAnimationCurve> new_curve = |
| 112 animation->curve() |
| 113 ->ToScrollOffsetAnimationCurve() |
| 114 ->CloneToScrollOffsetAnimationCurve(); |
| 115 new_curve->ApplyAdjustment(adjustment); |
| 116 |
| 117 std::unique_ptr<Animation> new_animation = Animation::Create( |
| 118 std::move(new_curve), AnimationIdProvider::NextAnimationId(), |
| 119 AnimationIdProvider::NextGroupId(), TargetProperty::SCROLL_OFFSET); |
| 120 new_animation->set_start_time(animation->start_time()); |
| 121 new_animation->set_is_impl_only(true); |
| 122 new_animation->set_affects_active_elements(false); |
| 123 |
| 124 // Abort the old animation. |
| 125 ScrollAnimationAbort(/* needs_completion */ false); |
| 126 |
| 127 // Start a new one with the adjusment. |
| 128 scroll_offset_animation_player_->AddAnimation(std::move(new_animation)); |
| 129 } |
| 130 |
| 95 void ScrollOffsetAnimationsImpl::ScrollAnimationAbort(bool needs_completion) { | 131 void ScrollOffsetAnimationsImpl::ScrollAnimationAbort(bool needs_completion) { |
| 96 DCHECK(scroll_offset_animation_player_); | 132 DCHECK(scroll_offset_animation_player_); |
| 97 scroll_offset_animation_player_->AbortAnimations( | 133 scroll_offset_animation_player_->AbortAnimations( |
| 98 TargetProperty::SCROLL_OFFSET, needs_completion); | 134 TargetProperty::SCROLL_OFFSET, needs_completion); |
| 99 } | 135 } |
| 100 | 136 |
| 101 void ScrollOffsetAnimationsImpl::NotifyAnimationFinished( | 137 void ScrollOffsetAnimationsImpl::NotifyAnimationFinished( |
| 102 base::TimeTicks monotonic_time, | 138 base::TimeTicks monotonic_time, |
| 103 TargetProperty::Type target_property, | 139 TargetProperty::Type target_property, |
| 104 int group) { | 140 int group) { |
| 105 DCHECK_EQ(target_property, TargetProperty::SCROLL_OFFSET); | 141 DCHECK_EQ(target_property, TargetProperty::SCROLL_OFFSET); |
| 106 DCHECK(animation_host_->mutator_host_client()); | 142 DCHECK(animation_host_->mutator_host_client()); |
| 107 animation_host_->mutator_host_client()->ScrollOffsetAnimationFinished(); | 143 animation_host_->mutator_host_client()->ScrollOffsetAnimationFinished(); |
| 108 } | 144 } |
| 109 | 145 |
| 110 void ScrollOffsetAnimationsImpl::ReattachScrollOffsetPlayerIfNeeded( | 146 void ScrollOffsetAnimationsImpl::ReattachScrollOffsetPlayerIfNeeded( |
| 111 ElementId element_id) { | 147 ElementId element_id) { |
| 112 if (scroll_offset_animation_player_->element_id() != element_id) { | 148 if (scroll_offset_animation_player_->element_id() != element_id) { |
| 113 if (scroll_offset_animation_player_->element_id()) | 149 if (scroll_offset_animation_player_->element_id()) |
| 114 scroll_offset_animation_player_->DetachElement(); | 150 scroll_offset_animation_player_->DetachElement(); |
| 115 if (element_id) | 151 if (element_id) |
| 116 scroll_offset_animation_player_->AttachElement(element_id); | 152 scroll_offset_animation_player_->AttachElement(element_id); |
| 117 } | 153 } |
| 118 } | 154 } |
| 119 | 155 |
| 120 } // namespace cc | 156 } // namespace cc |
| OLD | NEW |