OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2011, Google Inc. All rights reserved. | 2 * Copyright (c) 2011, Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 if (hasRunningAnimation()) | 112 if (hasRunningAnimation()) |
113 cancelAnimation(); | 113 cancelAnimation(); |
114 return ScrollAnimatorBase::userScroll(granularity, delta); | 114 return ScrollAnimatorBase::userScroll(granularity, delta); |
115 } | 115 } |
116 | 116 |
117 bool needsPostAnimationCleanup = m_runState == RunState::PostAnimationCleanu
p; | 117 bool needsPostAnimationCleanup = m_runState == RunState::PostAnimationCleanu
p; |
118 if (m_runState == RunState::PostAnimationCleanup) | 118 if (m_runState == RunState::PostAnimationCleanup) |
119 resetAnimationState(); | 119 resetAnimationState(); |
120 | 120 |
121 FloatSize consumedDelta = computeDeltaToConsume(delta); | 121 FloatSize consumedDelta = computeDeltaToConsume(delta); |
122 | |
123 FloatPoint targetPos = desiredTargetPosition(); | 122 FloatPoint targetPos = desiredTargetPosition(); |
124 targetPos.move(consumedDelta); | 123 targetPos.move(consumedDelta); |
125 | 124 |
126 if (willAnimateToOffset(targetPos)) { | 125 if (willAnimateToOffset(targetPos)) { |
127 m_lastGranularity = granularity; | 126 m_lastGranularity = granularity; |
128 // Report unused delta only if there is no animation running. See | 127 // Report unused delta only if there is no animation running. See |
129 // comment below regarding scroll latching. | 128 // comment below regarding scroll latching. |
130 // TODO(bokan): Need to standardize how ScrollAnimators report | 129 // TODO(bokan): Need to standardize how ScrollAnimators report |
131 // unusedDelta. This differs from ScrollAnimatorMac currently. | 130 // unusedDelta. This differs from ScrollAnimatorMac currently. |
132 return ScrollResult(true, true, 0, 0); | 131 return ScrollResult(true, true, 0, 0); |
133 } | 132 } |
134 | 133 |
135 // If the run state when this method was called was PostAnimationCleanup and | 134 // If the run state when this method was called was PostAnimationCleanup and |
136 // we're not starting an animation, stay in PostAnimationCleanup state so | 135 // we're not starting an animation, stay in PostAnimationCleanup state so |
137 // that the main thread scrolling reason can be removed. | 136 // that the main thread scrolling reason can be removed. |
138 if (needsPostAnimationCleanup) | 137 if (needsPostAnimationCleanup) |
139 m_runState = RunState::PostAnimationCleanup; | 138 m_runState = RunState::PostAnimationCleanup; |
140 | 139 |
141 // Report unused delta only if there is no animation and we are not | 140 // Report unused delta only if there is no animation and we are not |
142 // starting one. This ensures we latch for the duration of the | 141 // starting one. This ensures we latch for the duration of the |
143 // animation rather than animating multiple scrollers at the same time. | 142 // animation rather than animating multiple scrollers at the same time. |
144 return ScrollResult(false, false, delta.width(), delta.height()); | 143 return ScrollResult(false, false, delta.width(), delta.height()); |
145 } | 144 } |
146 | 145 |
147 bool ScrollAnimator::willAnimateToOffset(const FloatPoint& targetPos) | 146 bool ScrollAnimator::willAnimateToOffset(const FloatPoint& targetPos) |
148 { | 147 { |
149 if (m_runState == RunState::PostAnimationCleanup) | 148 if (m_runState == RunState::PostAnimationCleanup) |
150 resetAnimationState(); | 149 resetAnimationState(); |
151 | 150 |
152 if (m_runState == RunState::WaitingToCancelOnCompositor) { | 151 if (m_runState == RunState::WaitingToCancelOnCompositor |
| 152 || m_runState == RunState::WaitingToCancelOnCompositorButNewScroll) { |
153 ASSERT(m_animationCurve); | 153 ASSERT(m_animationCurve); |
154 m_targetOffset = targetPos; | 154 m_targetOffset = targetPos; |
155 if (registerAndScheduleAnimation()) | 155 if (registerAndScheduleAnimation()) |
156 m_runState = RunState::WaitingToCancelOnCompositorButNewScroll; | 156 m_runState = RunState::WaitingToCancelOnCompositorButNewScroll; |
157 return true; | 157 return true; |
158 } | 158 } |
159 | 159 |
160 if (m_animationCurve) { | 160 if (m_animationCurve) { |
161 if ((targetPos - m_targetOffset).isZero()) | 161 if ((targetPos - m_targetOffset).isZero()) |
162 return true; | 162 return true; |
(...skipping 22 matching lines...) Expand all Loading... |
185 | 185 |
186 m_targetOffset = targetPos; | 186 m_targetOffset = targetPos; |
187 m_startTime = m_timeFunction(); | 187 m_startTime = m_timeFunction(); |
188 | 188 |
189 if (registerAndScheduleAnimation()) | 189 if (registerAndScheduleAnimation()) |
190 m_runState = RunState::WaitingToSendToCompositor; | 190 m_runState = RunState::WaitingToSendToCompositor; |
191 | 191 |
192 return true; | 192 return true; |
193 } | 193 } |
194 | 194 |
| 195 void ScrollAnimator::adjustAnimationAndSetScrollPosition( |
| 196 IntSize adjustment, ScrollType scrollType) |
| 197 { |
| 198 DoublePoint adjustedPos = m_scrollableArea->clampScrollPosition( |
| 199 m_scrollableArea->scrollPositionDouble() + adjustment); |
| 200 IntSize actualAdjustment = roundedIntPoint(adjustedPos) - |
| 201 roundedIntPoint(m_scrollableArea->scrollPositionDouble()); |
| 202 |
| 203 m_scrollableArea->setScrollPosition(adjustedPos, scrollType); |
| 204 |
| 205 if (m_runState == RunState::Idle) { |
| 206 adjustImplOnlyScrollOffsetAnimation(actualAdjustment); |
| 207 } else if (hasRunningAnimation()) { |
| 208 m_targetOffset += toFloatSize(actualAdjustment); |
| 209 if (m_animationCurve) { |
| 210 m_animationCurve->applyAdjustment(actualAdjustment); |
| 211 if (m_runState != RunState::RunningOnMainThread && registerAndSchedu
leAnimation()) |
| 212 m_runState = RunState::RunningOnCompositorButNeedsAdjustment; |
| 213 } |
| 214 } |
| 215 } |
| 216 |
195 void ScrollAnimator::scrollToOffsetWithoutAnimation(const FloatPoint& offset) | 217 void ScrollAnimator::scrollToOffsetWithoutAnimation(const FloatPoint& offset) |
196 { | 218 { |
197 m_currentPos = offset; | 219 m_currentPos = offset; |
198 | 220 |
199 resetAnimationState(); | 221 resetAnimationState(); |
200 notifyPositionChanged(); | 222 notifyPositionChanged(); |
201 } | 223 } |
202 | 224 |
203 void ScrollAnimator::tickAnimation(double monotonicTime) | 225 void ScrollAnimator::tickAnimation(double monotonicTime) |
204 { | 226 { |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 } | 288 } |
267 | 289 |
268 void ScrollAnimator::updateCompositorAnimations() | 290 void ScrollAnimator::updateCompositorAnimations() |
269 { | 291 { |
270 ScrollAnimatorCompositorCoordinator::updateCompositorAnimations(); | 292 ScrollAnimatorCompositorCoordinator::updateCompositorAnimations(); |
271 if (m_runState == RunState::PostAnimationCleanup) { | 293 if (m_runState == RunState::PostAnimationCleanup) { |
272 postAnimationCleanupAndReset(); | 294 postAnimationCleanupAndReset(); |
273 return; | 295 return; |
274 } | 296 } |
275 | 297 |
276 if (m_compositorAnimationId && m_runState != RunState::RunningOnCompositor | 298 if (m_runState == RunState::WaitingToCancelOnCompositor) { |
277 && m_runState != RunState::RunningOnCompositorButNeedsUpdate | 299 DCHECK(m_compositorAnimationId); |
278 && m_runState != RunState::WaitingToCancelOnCompositorButNewScroll) { | 300 abortAnimation(); |
279 // If the current run state is WaitingToSendToCompositor but we have a | 301 postAnimationCleanupAndReset(); |
280 // non-zero compositor animation id, there's a currently running | 302 return; |
281 // compositor animation that needs to be removed here before the new | 303 } |
282 // animation is added below. | |
283 ASSERT(m_runState == RunState::WaitingToCancelOnCompositor | |
284 || m_runState == RunState::WaitingToSendToCompositor | |
285 || m_runState == RunState::RunningOnCompositorButNeedsTakeover); | |
286 | 304 |
287 if (m_runState == RunState::RunningOnCompositorButNeedsTakeover) { | 305 if (m_runState == RunState::RunningOnCompositorButNeedsTakeover) { |
288 // The animation is already aborted when the call to | 306 // The call to ::takeOverCompositorAnimation aborted the animation and |
289 // ::takeOverCompositorAnimation is made. | 307 // put us in this state. The assumption is that takeOver is called |
290 m_runState = RunState::WaitingToSendToCompositor; | 308 // because a main thread scrolling reason is added, and simply trying |
291 } else { | 309 // to ::sendAnimationToCompositor will fail and we will run on the main |
292 abortAnimation(); | 310 // thread. |
293 } | 311 resetAnimationIds(); |
294 | 312 m_runState = RunState::WaitingToSendToCompositor; |
295 m_compositorAnimationId = 0; | |
296 m_compositorAnimationGroupId = 0; | |
297 if (m_runState == RunState::WaitingToCancelOnCompositor) { | |
298 postAnimationCleanupAndReset(); | |
299 return; | |
300 } | |
301 } | 313 } |
302 | 314 |
303 if (m_runState == RunState::RunningOnCompositorButNeedsUpdate | 315 if (m_runState == RunState::RunningOnCompositorButNeedsUpdate |
304 || m_runState == RunState::WaitingToCancelOnCompositorButNewScroll) { | 316 || m_runState == RunState::WaitingToCancelOnCompositorButNewScroll |
| 317 || m_runState == RunState::RunningOnCompositorButNeedsAdjustment) { |
305 // Abort the running animation before a new one with an updated | 318 // Abort the running animation before a new one with an updated |
306 // target is added. | 319 // target is added. |
307 abortAnimation(); | 320 abortAnimation(); |
| 321 resetAnimationIds(); |
308 | 322 |
309 m_compositorAnimationId = 0; | 323 if (m_runState != RunState::RunningOnCompositorButNeedsAdjustment) { |
310 m_compositorAnimationGroupId = 0; | 324 // When in RunningOnCompositorButNeedsAdjustment, the call to |
| 325 // ::adjustScrollOffsetAnimation should have made the necessary |
| 326 // adjustment to the curve. |
| 327 m_animationCurve->updateTarget(m_timeFunction() - m_startTime, |
| 328 compositorOffsetFromBlinkOffset(m_targetOffset)); |
| 329 } |
311 | 330 |
312 m_animationCurve->updateTarget(m_timeFunction() - m_startTime, | |
313 compositorOffsetFromBlinkOffset(m_targetOffset)); | |
314 if (m_runState == RunState::WaitingToCancelOnCompositorButNewScroll) | 331 if (m_runState == RunState::WaitingToCancelOnCompositorButNewScroll) |
315 m_animationCurve->setInitialValue(compositorOffsetFromBlinkOffset(cu
rrentPosition())); | 332 m_animationCurve->setInitialValue(compositorOffsetFromBlinkOffset(cu
rrentPosition())); |
| 333 |
316 m_runState = RunState::WaitingToSendToCompositor; | 334 m_runState = RunState::WaitingToSendToCompositor; |
317 } | 335 } |
318 | 336 |
319 if (m_runState == RunState::WaitingToSendToCompositor) { | 337 if (m_runState == RunState::WaitingToSendToCompositor) { |
320 if (!m_compositorAnimationAttachedToLayerId) | 338 if (!m_compositorAnimationAttachedToLayerId) |
321 reattachCompositorPlayerIfNeeded(getScrollableArea()->compositorAnim
ationTimeline()); | 339 reattachCompositorPlayerIfNeeded(getScrollableArea()->compositorAnim
ationTimeline()); |
322 | 340 |
323 if (!m_animationCurve) { | 341 if (!m_animationCurve) { |
324 m_animationCurve = adoptPtr(CompositorFactory::current().createScrol
lOffsetAnimationCurve( | 342 m_animationCurve = adoptPtr(CompositorFactory::current().createScrol
lOffsetAnimationCurve( |
325 compositorOffsetFromBlinkOffset(m_targetOffset), | 343 compositorOffsetFromBlinkOffset(m_targetOffset), |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
426 } | 444 } |
427 return true; | 445 return true; |
428 } | 446 } |
429 | 447 |
430 DEFINE_TRACE(ScrollAnimator) | 448 DEFINE_TRACE(ScrollAnimator) |
431 { | 449 { |
432 ScrollAnimatorBase::trace(visitor); | 450 ScrollAnimatorBase::trace(visitor); |
433 } | 451 } |
434 | 452 |
435 } // namespace blink | 453 } // namespace blink |
OLD | NEW |