Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(488)

Side by Side Diff: third_party/WebKit/Source/platform/scroll/ScrollAnimator.cpp

Issue 1926473003: Smooth scroll animation should not override scroll anchoring update (MT) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: disable test for mac Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 , m_lastGranularity(ScrollByPixel) 66 , m_lastGranularity(ScrollByPixel)
67 { 67 {
68 } 68 }
69 69
70 ScrollAnimator::~ScrollAnimator() 70 ScrollAnimator::~ScrollAnimator()
71 { 71 {
72 } 72 }
73 73
74 FloatPoint ScrollAnimator::desiredTargetPosition() const 74 FloatPoint ScrollAnimator::desiredTargetPosition() const
75 { 75 {
76 if (m_runState == RunState::WaitingToCancelOnCompositor)
77 return currentPosition();
76 return (m_animationCurve || m_runState == RunState::WaitingToSendToComposito r) 78 return (m_animationCurve || m_runState == RunState::WaitingToSendToComposito r)
77 ? m_targetOffset : currentPosition(); 79 ? m_targetOffset : currentPosition();
78 } 80 }
79 81
80 bool ScrollAnimator::hasRunningAnimation() const 82 bool ScrollAnimator::hasRunningAnimation() const
81 { 83 {
82 return (m_animationCurve || m_runState == RunState::WaitingToSendToComposito r); 84 return (m_animationCurve || m_runState == RunState::WaitingToSendToComposito r);
83 } 85 }
84 86
85 FloatSize ScrollAnimator::computeDeltaToConsume(const FloatSize& delta) const 87 FloatSize ScrollAnimator::computeDeltaToConsume(const FloatSize& delta) const
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 // animation rather than animating multiple scrollers at the same time. 143 // animation rather than animating multiple scrollers at the same time.
142 return ScrollResult(false, false, delta.width(), delta.height()); 144 return ScrollResult(false, false, delta.width(), delta.height());
143 } 145 }
144 146
145 bool ScrollAnimator::willAnimateToOffset(const FloatPoint& targetPos) 147 bool ScrollAnimator::willAnimateToOffset(const FloatPoint& targetPos)
146 { 148 {
147 if (m_runState == RunState::PostAnimationCleanup) 149 if (m_runState == RunState::PostAnimationCleanup)
148 resetAnimationState(); 150 resetAnimationState();
149 151
150 if (m_runState == RunState::WaitingToCancelOnCompositor) { 152 if (m_runState == RunState::WaitingToCancelOnCompositor) {
151 // Ignore user scroll if WaitingToCancelOnCompositor. Can be in this 153 ASSERT(m_animationCurve);
152 // state when holding down an arrow. 154 m_targetOffset = targetPos;
153 // TODO(ymalik): Handle this case by either updating the target on the 155 if (registerAndScheduleAnimation())
154 // current scroll or starting a new animation (see crbug.com/599876). 156 m_runState = RunState::WaitingToCancelOnCompositorButNewScroll;
155 return true; 157 return true;
156 } 158 }
157 159
158 if (m_animationCurve) { 160 if (m_animationCurve) {
159 if ((targetPos - m_targetOffset).isZero()) 161 if ((targetPos - m_targetOffset).isZero())
160 return true; 162 return true;
161 163
162 m_targetOffset = targetPos; 164 m_targetOffset = targetPos;
163 ASSERT(m_runState == RunState::RunningOnMainThread 165 ASSERT(m_runState == RunState::RunningOnMainThread
164 || m_runState == RunState::RunningOnCompositor 166 || m_runState == RunState::RunningOnCompositor
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 } 266 }
265 267
266 void ScrollAnimator::updateCompositorAnimations() 268 void ScrollAnimator::updateCompositorAnimations()
267 { 269 {
268 if (m_runState == RunState::PostAnimationCleanup) { 270 if (m_runState == RunState::PostAnimationCleanup) {
269 postAnimationCleanupAndReset(); 271 postAnimationCleanupAndReset();
270 return; 272 return;
271 } 273 }
272 274
273 if (m_compositorAnimationId && m_runState != RunState::RunningOnCompositor 275 if (m_compositorAnimationId && m_runState != RunState::RunningOnCompositor
274 && m_runState != RunState::RunningOnCompositorButNeedsUpdate) { 276 && m_runState != RunState::RunningOnCompositorButNeedsUpdate
277 && m_runState != RunState::WaitingToCancelOnCompositorButNewScroll) {
275 // If the current run state is WaitingToSendToCompositor but we have a 278 // If the current run state is WaitingToSendToCompositor but we have a
276 // non-zero compositor animation id, there's a currently running 279 // non-zero compositor animation id, there's a currently running
277 // compositor animation that needs to be removed here before the new 280 // compositor animation that needs to be removed here before the new
278 // animation is added below. 281 // animation is added below.
279 ASSERT(m_runState == RunState::WaitingToCancelOnCompositor 282 ASSERT(m_runState == RunState::WaitingToCancelOnCompositor
280 || m_runState == RunState::WaitingToSendToCompositor 283 || m_runState == RunState::WaitingToSendToCompositor
281 || m_runState == RunState::RunningOnCompositorButNeedsTakeover); 284 || m_runState == RunState::RunningOnCompositorButNeedsTakeover);
282 285
283 if (m_runState == RunState::RunningOnCompositorButNeedsTakeover) { 286 if (m_runState == RunState::RunningOnCompositorButNeedsTakeover) {
284 // The animation is already aborted when the call to 287 // The animation is already aborted when the call to
285 // ::takeoverCompositorAnimation is made. 288 // ::takeoverCompositorAnimation is made.
286 m_runState = RunState::WaitingToSendToCompositor; 289 m_runState = RunState::WaitingToSendToCompositor;
287 } else { 290 } else {
288 abortAnimation(); 291 abortAnimation();
289 } 292 }
290 293
291 m_compositorAnimationId = 0; 294 m_compositorAnimationId = 0;
292 m_compositorAnimationGroupId = 0; 295 m_compositorAnimationGroupId = 0;
293 if (m_runState == RunState::WaitingToCancelOnCompositor) { 296 if (m_runState == RunState::WaitingToCancelOnCompositor) {
294 postAnimationCleanupAndReset(); 297 postAnimationCleanupAndReset();
295 return; 298 return;
296 } 299 }
297 } 300 }
298 301
299 if (m_runState == RunState::WaitingToSendToCompositor 302 if (m_runState == RunState::RunningOnCompositorButNeedsUpdate
300 || m_runState == RunState::RunningOnCompositorButNeedsUpdate) { 303 || m_runState == RunState::WaitingToCancelOnCompositorButNewScroll) {
304 // Abort the running animation before a new one with an updated
305 // target is added.
306 abortAnimation();
307
308 m_compositorAnimationId = 0;
309 m_compositorAnimationGroupId = 0;
310
311 m_animationCurve->updateTarget(m_timeFunction() - m_startTime,
312 compositorOffsetFromBlinkOffset(m_targetOffset));
313 if (m_runState == RunState::WaitingToCancelOnCompositorButNewScroll)
314 m_animationCurve->setInitialValue(compositorOffsetFromBlinkOffset(cu rrentPosition()));
315 m_runState = RunState::WaitingToSendToCompositor;
316 }
317
318 if (m_runState == RunState::WaitingToSendToCompositor) {
301 if (!m_compositorAnimationAttachedToLayerId) 319 if (!m_compositorAnimationAttachedToLayerId)
302 reattachCompositorPlayerIfNeeded(getScrollableArea()->compositorAnim ationTimeline()); 320 reattachCompositorPlayerIfNeeded(getScrollableArea()->compositorAnim ationTimeline());
303 321
304 if (m_runState == RunState::RunningOnCompositorButNeedsUpdate) {
305 // Abort the running animation before a new one with an updated
306 // target is added.
307 abortAnimation();
308
309 m_compositorAnimationId = 0;
310 m_compositorAnimationGroupId = 0;
311
312 m_animationCurve->updateTarget(m_timeFunction() - m_startTime,
313 compositorOffsetFromBlinkOffset(m_targetOffset));
314 m_runState = RunState::WaitingToSendToCompositor;
315 }
316
317 if (!m_animationCurve) { 322 if (!m_animationCurve) {
318 m_animationCurve = adoptPtr(CompositorFactory::current().createScrol lOffsetAnimationCurve( 323 m_animationCurve = adoptPtr(CompositorFactory::current().createScrol lOffsetAnimationCurve(
319 compositorOffsetFromBlinkOffset(m_targetOffset), 324 compositorOffsetFromBlinkOffset(m_targetOffset),
320 CompositorAnimationCurve::TimingFunctionTypeEaseInOut, 325 CompositorAnimationCurve::TimingFunctionTypeEaseInOut,
321 m_lastGranularity == ScrollByPixel ? 326 m_lastGranularity == ScrollByPixel ?
322 CompositorScrollOffsetAnimationCurve::ScrollDurationInverseD elta : 327 CompositorScrollOffsetAnimationCurve::ScrollDurationInverseD elta :
323 CompositorScrollOffsetAnimationCurve::ScrollDurationConstant )); 328 CompositorScrollOffsetAnimationCurve::ScrollDurationConstant ));
324 m_animationCurve->setInitialValue(compositorOffsetFromBlinkOffset(cu rrentPosition())); 329 m_animationCurve->setInitialValue(compositorOffsetFromBlinkOffset(cu rrentPosition()));
325 } 330 }
326 331
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 } 426 }
422 return true; 427 return true;
423 } 428 }
424 429
425 DEFINE_TRACE(ScrollAnimator) 430 DEFINE_TRACE(ScrollAnimator)
426 { 431 {
427 ScrollAnimatorBase::trace(visitor); 432 ScrollAnimatorBase::trace(visitor);
428 } 433 }
429 434
430 } // namespace blink 435 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698