Chromium Code Reviews| 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 = compositorSizeFromBlinkSize( | |
|
skobes
2016/05/27 17:58:30
This doesn't make sense to me. An adjustment is a
ymalik
2016/05/27 20:03:11
You're right. I was confusing it with the target_o
| |
| 201 roundedIntPoint(adjustedPos) - | |
| 202 roundedIntPoint(m_scrollableArea->scrollPositionDouble())); | |
| 203 | |
| 204 m_scrollableArea->setScrollPosition(adjustedPos, scrollType); | |
| 205 | |
| 206 if (m_runState == RunState::Idle) { | |
| 207 adjustImplOnlyScrollOffsetAnimation(actualAdjustment); | |
| 208 } else if (hasRunningAnimation()) { | |
| 209 m_targetOffset += toFloatSize(actualAdjustment); | |
| 210 if (m_animationCurve) { | |
| 211 m_animationCurve->applyAdjustment(actualAdjustment); | |
| 212 if (m_runState != RunState::RunningOnMainThread && registerAndSchedu leAnimation()) | |
| 213 m_runState = RunState::RunningOnCompositorButNeedsAdjustment; | |
| 214 } | |
| 215 } | |
| 216 } | |
| 217 | |
| 195 void ScrollAnimator::scrollToOffsetWithoutAnimation(const FloatPoint& offset) | 218 void ScrollAnimator::scrollToOffsetWithoutAnimation(const FloatPoint& offset) |
| 196 { | 219 { |
| 197 m_currentPos = offset; | 220 m_currentPos = offset; |
| 198 | 221 |
| 199 resetAnimationState(); | 222 resetAnimationState(); |
| 200 notifyPositionChanged(); | 223 notifyPositionChanged(); |
| 201 } | 224 } |
| 202 | 225 |
| 203 void ScrollAnimator::tickAnimation(double monotonicTime) | 226 void ScrollAnimator::tickAnimation(double monotonicTime) |
| 204 { | 227 { |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 266 } | 289 } |
| 267 | 290 |
| 268 void ScrollAnimator::updateCompositorAnimations() | 291 void ScrollAnimator::updateCompositorAnimations() |
| 269 { | 292 { |
| 270 ScrollAnimatorCompositorCoordinator::updateCompositorAnimations(); | 293 ScrollAnimatorCompositorCoordinator::updateCompositorAnimations(); |
| 271 if (m_runState == RunState::PostAnimationCleanup) { | 294 if (m_runState == RunState::PostAnimationCleanup) { |
| 272 postAnimationCleanupAndReset(); | 295 postAnimationCleanupAndReset(); |
| 273 return; | 296 return; |
| 274 } | 297 } |
| 275 | 298 |
| 276 if (m_compositorAnimationId && m_runState != RunState::RunningOnCompositor | 299 if (m_runState == RunState::WaitingToCancelOnCompositor) { |
| 277 && m_runState != RunState::RunningOnCompositorButNeedsUpdate | 300 DCHECK(m_compositorAnimationId); |
| 278 && m_runState != RunState::WaitingToCancelOnCompositorButNewScroll) { | 301 abortAnimation(); |
| 279 // If the current run state is WaitingToSendToCompositor but we have a | 302 postAnimationCleanupAndReset(); |
| 280 // non-zero compositor animation id, there's a currently running | 303 return; |
| 281 // compositor animation that needs to be removed here before the new | 304 } |
| 282 // animation is added below. | |
| 283 ASSERT(m_runState == RunState::WaitingToCancelOnCompositor | |
| 284 || m_runState == RunState::WaitingToSendToCompositor | |
| 285 || m_runState == RunState::RunningOnCompositorButNeedsTakeover); | |
| 286 | 305 |
| 287 if (m_runState == RunState::RunningOnCompositorButNeedsTakeover) { | 306 if (m_runState == RunState::RunningOnCompositorButNeedsTakeover) { |
| 288 // The animation is already aborted when the call to | 307 // The call to ::takeOverCompositorAnimation aborted the animation and |
| 289 // ::takeOverCompositorAnimation is made. | 308 // put us in this state. The assumption is that takeOver is called |
| 290 m_runState = RunState::WaitingToSendToCompositor; | 309 // because a main thread scrolling reason is added, and simply trying |
| 291 } else { | 310 // to ::sendAnimationToCompositor will fail and we will run on the main |
| 292 abortAnimation(); | 311 // thread. |
| 293 } | 312 resetAnimationIds(); |
| 294 | 313 m_runState = RunState::WaitingToSendToCompositor; |
| 295 m_compositorAnimationId = 0; | |
| 296 m_compositorAnimationGroupId = 0; | |
| 297 if (m_runState == RunState::WaitingToCancelOnCompositor) { | |
| 298 postAnimationCleanupAndReset(); | |
| 299 return; | |
| 300 } | |
| 301 } | 314 } |
| 302 | 315 |
| 303 if (m_runState == RunState::RunningOnCompositorButNeedsUpdate | 316 if (m_runState == RunState::RunningOnCompositorButNeedsUpdate |
| 304 || m_runState == RunState::WaitingToCancelOnCompositorButNewScroll) { | 317 || m_runState == RunState::WaitingToCancelOnCompositorButNewScroll |
| 318 || m_runState == RunState::RunningOnCompositorButNeedsAdjustment) { | |
| 305 // Abort the running animation before a new one with an updated | 319 // Abort the running animation before a new one with an updated |
| 306 // target is added. | 320 // target is added. |
| 307 abortAnimation(); | 321 abortAnimation(); |
| 322 resetAnimationIds(); | |
| 308 | 323 |
| 309 m_compositorAnimationId = 0; | 324 if (m_runState != RunState::RunningOnCompositorButNeedsAdjustment) { |
| 310 m_compositorAnimationGroupId = 0; | 325 // When in RunningOnCompositorButNeedsAdjustment, the call to |
| 326 // ::adjustScrollOffsetAnimation should have made the necessary | |
| 327 // adjustment ot the curve. | |
|
ajuma
2016/05/27 14:21:34
s/ot/to
ymalik
2016/05/27 20:03:11
Done.
| |
| 328 m_animationCurve->updateTarget(m_timeFunction() - m_startTime, | |
| 329 compositorOffsetFromBlinkOffset(m_targetOffset)); | |
| 330 } | |
| 311 | 331 |
| 312 m_animationCurve->updateTarget(m_timeFunction() - m_startTime, | |
| 313 compositorOffsetFromBlinkOffset(m_targetOffset)); | |
| 314 if (m_runState == RunState::WaitingToCancelOnCompositorButNewScroll) | 332 if (m_runState == RunState::WaitingToCancelOnCompositorButNewScroll) |
| 315 m_animationCurve->setInitialValue(compositorOffsetFromBlinkOffset(cu rrentPosition())); | 333 m_animationCurve->setInitialValue(compositorOffsetFromBlinkOffset(cu rrentPosition())); |
| 334 | |
| 316 m_runState = RunState::WaitingToSendToCompositor; | 335 m_runState = RunState::WaitingToSendToCompositor; |
| 317 } | 336 } |
| 318 | 337 |
| 319 if (m_runState == RunState::WaitingToSendToCompositor) { | 338 if (m_runState == RunState::WaitingToSendToCompositor) { |
| 320 if (!m_compositorAnimationAttachedToLayerId) | 339 if (!m_compositorAnimationAttachedToLayerId) |
| 321 reattachCompositorPlayerIfNeeded(getScrollableArea()->compositorAnim ationTimeline()); | 340 reattachCompositorPlayerIfNeeded(getScrollableArea()->compositorAnim ationTimeline()); |
| 322 | 341 |
| 323 if (!m_animationCurve) { | 342 if (!m_animationCurve) { |
| 324 m_animationCurve = adoptPtr(CompositorFactory::current().createScrol lOffsetAnimationCurve( | 343 m_animationCurve = adoptPtr(CompositorFactory::current().createScrol lOffsetAnimationCurve( |
| 325 compositorOffsetFromBlinkOffset(m_targetOffset), | 344 compositorOffsetFromBlinkOffset(m_targetOffset), |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 426 } | 445 } |
| 427 return true; | 446 return true; |
| 428 } | 447 } |
| 429 | 448 |
| 430 DEFINE_TRACE(ScrollAnimator) | 449 DEFINE_TRACE(ScrollAnimator) |
| 431 { | 450 { |
| 432 ScrollAnimatorBase::trace(visitor); | 451 ScrollAnimatorBase::trace(visitor); |
| 433 } | 452 } |
| 434 | 453 |
| 435 } // namespace blink | 454 } // namespace blink |
| OLD | NEW |