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 ReattachScrollOffsetPlayerIfNeeded(element_id); | |
loyso (OOO)
2016/05/06 01:04:38
element_id == scroll_offset_animation_player_->ele
ymalik
2016/05/06 05:41:49
You're right, no need to reattach.
We can't repla
| |
128 | |
129 scroll_offset_animation_player_->AddAnimation(std::move(new_animation)); | |
130 } | |
131 | |
93 void ScrollOffsetAnimationsImpl::ScrollAnimationAbort(bool needs_completion) { | 132 void ScrollOffsetAnimationsImpl::ScrollAnimationAbort(bool needs_completion) { |
94 DCHECK(scroll_offset_animation_player_); | 133 DCHECK(scroll_offset_animation_player_); |
95 scroll_offset_animation_player_->AbortAnimations( | 134 scroll_offset_animation_player_->AbortAnimations( |
96 TargetProperty::SCROLL_OFFSET, needs_completion); | 135 TargetProperty::SCROLL_OFFSET, needs_completion); |
97 } | 136 } |
98 | 137 |
99 void ScrollOffsetAnimationsImpl::NotifyAnimationFinished( | 138 void ScrollOffsetAnimationsImpl::NotifyAnimationFinished( |
100 base::TimeTicks monotonic_time, | 139 base::TimeTicks monotonic_time, |
101 TargetProperty::Type target_property, | 140 TargetProperty::Type target_property, |
102 int group) { | 141 int group) { |
103 DCHECK_EQ(target_property, TargetProperty::SCROLL_OFFSET); | 142 DCHECK_EQ(target_property, TargetProperty::SCROLL_OFFSET); |
104 DCHECK(animation_host_->mutator_host_client()); | 143 DCHECK(animation_host_->mutator_host_client()); |
105 animation_host_->mutator_host_client()->ScrollOffsetAnimationFinished(); | 144 animation_host_->mutator_host_client()->ScrollOffsetAnimationFinished(); |
106 } | 145 } |
107 | 146 |
108 void ScrollOffsetAnimationsImpl::ReattachScrollOffsetPlayerIfNeeded( | 147 void ScrollOffsetAnimationsImpl::ReattachScrollOffsetPlayerIfNeeded( |
109 ElementId element_id) { | 148 ElementId element_id) { |
110 if (scroll_offset_animation_player_->element_id() != element_id) { | 149 if (scroll_offset_animation_player_->element_id() != element_id) { |
111 if (scroll_offset_animation_player_->element_id()) | 150 if (scroll_offset_animation_player_->element_id()) |
112 scroll_offset_animation_player_->DetachElement(); | 151 scroll_offset_animation_player_->DetachElement(); |
113 if (element_id) | 152 if (element_id) |
114 scroll_offset_animation_player_->AttachElement(element_id); | 153 scroll_offset_animation_player_->AttachElement(element_id); |
115 } | 154 } |
116 } | 155 } |
117 | 156 |
118 } // namespace cc | 157 } // namespace cc |
OLD | NEW |