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

Side by Side Diff: third_party/WebKit/Source/core/layout/ScrollAnchor.cpp

Issue 2015113003: Correctly update scroll offset animations in response to scroll anchoring (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "core/layout/ScrollAnchor.h" 5 #include "core/layout/ScrollAnchor.h"
6 6
7 #include "core/frame/FrameView.h" 7 #include "core/frame/FrameView.h"
8 #include "core/frame/UseCounter.h" 8 #include "core/frame/UseCounter.h"
9 #include "core/layout/line/InlineTextBox.h" 9 #include "core/layout/line/InlineTextBox.h"
10 #include "core/paint/PaintLayerScrollableArea.h" 10 #include "core/paint/PaintLayerScrollableArea.h"
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 m_lastAdjustment = IntSize(); 235 m_lastAdjustment = IntSize();
236 m_lastAdjusted.clear(); 236 m_lastAdjusted.clear();
237 return; 237 return;
238 } 238 }
239 adjust(adjustment); 239 adjust(adjustment);
240 } 240 }
241 241
242 void ScrollAnchor::adjust(IntSize adjustment) 242 void ScrollAnchor::adjust(IntSize adjustment)
243 { 243 {
244 DoublePoint desiredPos = m_scroller->scrollPositionDouble() + adjustment; 244 DoublePoint desiredPos = m_scroller->scrollPositionDouble() + adjustment;
245 ScrollAnimatorBase* animator = m_scroller->existingScrollAnimator(); 245 ScrollAnimatorBase* animator = m_scroller->existingScrollAnimator();
skobes 2016/05/27 17:58:30 Could these five lines be reduced to m_scroller
ymalik 2016/05/27 20:03:11 Done.
246 if (!animator || !animator->hasRunningAnimation()) { 246
247 if (!animator)
247 m_scroller->setScrollPosition(desiredPos, AnchoringScroll); 248 m_scroller->setScrollPosition(desiredPos, AnchoringScroll);
248 animator->adjustImplOnlyScrollOffsetAnimation(FloatSize(adjustment)); 249 else
249 } else { 250 animator->adjustAnimationAndSetScrollPosition(adjustment, AnchoringScrol l);
250 // If in the middle of a scroll animation, stop the animation, make
251 // the adjustment, and continue the animation on the pending delta.
252 // TODO(skobes): This is not quite right, we are starting a new curve wi thout
253 // saving our progress on the existing curve.
254 FloatSize pendingDelta = animator->desiredTargetPosition() -
255 FloatPoint(m_scroller->scrollPositionDouble());
256 animator->cancelAnimation();
257 m_scroller->setScrollPosition(desiredPos, AnchoringScroll);
258 animator->userScroll(ScrollByPixel, pendingDelta);
259 }
260 251
261 if (m_current && m_lastAdjusted.m_anchorObject != m_current.m_anchorObject) { 252 if (m_current && m_lastAdjusted.m_anchorObject != m_current.m_anchorObject) {
262 m_lastAdjusted.clear(); 253 m_lastAdjusted.clear();
263 m_lastAdjusted = m_current; 254 m_lastAdjusted = m_current;
264 } 255 }
265 m_hasBounced = (m_lastAdjustment == -adjustment); 256 m_hasBounced = (m_lastAdjustment == -adjustment);
266 m_lastAdjustment = adjustment; 257 m_lastAdjustment = adjustment;
267 258
268 // Update UMA metric. 259 // Update UMA metric.
269 DEFINE_STATIC_LOCAL(EnumerationHistogram, adjustedOffsetHistogram, 260 DEFINE_STATIC_LOCAL(EnumerationHistogram, adjustedOffsetHistogram,
(...skipping 24 matching lines...) Expand all
294 285
295 void ScrollAnchor::notifyRemoved(LayoutObject* layoutObject) 286 void ScrollAnchor::notifyRemoved(LayoutObject* layoutObject)
296 { 287 {
297 if (m_current.m_anchorObject == layoutObject) 288 if (m_current.m_anchorObject == layoutObject)
298 m_current.clear(); 289 m_current.clear();
299 if (m_lastAdjusted.m_anchorObject == layoutObject) 290 if (m_lastAdjusted.m_anchorObject == layoutObject)
300 m_lastAdjusted.clear(); 291 m_lastAdjusted.clear();
301 } 292 }
302 293
303 } // namespace blink 294 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698