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