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

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

Issue 2118683002: Limit ScrollAnchor to 20 adjustments between user scrolls. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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
« no previous file with comments | « third_party/WebKit/Source/core/layout/ScrollAnchor.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
11 #include "platform/Histogram.h" 11 #include "platform/Histogram.h"
12 12
13 namespace blink { 13 namespace blink {
14 14
15 using Corner = ScrollAnchor::Corner; 15 using Corner = ScrollAnchor::Corner;
16 16
17 static const int kMaxAdjustments = 20;
ymalik 2016/07/01 01:07:11 How did you come up with this number? We do have s
skobes 2016/07/01 17:28:26 I tried to pick something high enough to preserve
18
17 ScrollAnchor::ScrollAnchor(ScrollableArea* scroller) 19 ScrollAnchor::ScrollAnchor(ScrollableArea* scroller)
18 : m_scroller(scroller) 20 : m_scroller(scroller)
19 , m_hasBounced(false) 21 , m_hasBounced(false)
22 , m_adjustmentCount(0)
20 { 23 {
21 ASSERT(m_scroller); 24 ASSERT(m_scroller);
22 ASSERT(m_scroller->isFrameView() || m_scroller->isPaintLayerScrollableArea() ); 25 ASSERT(m_scroller->isFrameView() || m_scroller->isPaintLayerScrollableArea() );
23 } 26 }
24 27
25 ScrollAnchor::~ScrollAnchor() 28 ScrollAnchor::~ScrollAnchor()
26 { 29 {
27 } 30 }
28 31
29 // TODO(pilgrim) replace all instances of scrollerLayoutBox with scrollerLayoutB oxItem 32 // TODO(pilgrim) replace all instances of scrollerLayoutBox with scrollerLayoutB oxItem
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 if (adjustment.isZero()) 247 if (adjustment.isZero())
245 return; 248 return;
246 if (adjustment == -m_lastAdjustment && m_hasBounced) { 249 if (adjustment == -m_lastAdjustment && m_hasBounced) {
247 // Don't bounce more than once. 250 // Don't bounce more than once.
248 clear(); 251 clear();
249 m_hasBounced = false; 252 m_hasBounced = false;
250 m_lastAdjustment = IntSize(); 253 m_lastAdjustment = IntSize();
251 m_lastAdjusted.clear(); 254 m_lastAdjusted.clear();
252 return; 255 return;
253 } 256 }
254 adjust(adjustment); 257 if (++m_adjustmentCount <= kMaxAdjustments)
ymalik 2016/07/01 01:07:11 Brief comment explaining the rationale behind this
skobes 2016/07/01 17:28:26 Done.
258 adjust(adjustment);
255 } 259 }
256 260
257 void ScrollAnchor::adjust(IntSize adjustment) 261 void ScrollAnchor::adjust(IntSize adjustment)
258 { 262 {
259 m_scroller->scrollAnimator().adjustAnimationAndSetScrollPosition(adjustment, AnchoringScroll); 263 m_scroller->scrollAnimator().adjustAnimationAndSetScrollPosition(adjustment, AnchoringScroll);
260 264
261 if (m_current && m_lastAdjusted.m_anchorObject != m_current.m_anchorObject) { 265 if (m_current && m_lastAdjusted.m_anchorObject != m_current.m_anchorObject) {
262 m_lastAdjusted.clear(); 266 m_lastAdjusted.clear();
263 m_lastAdjusted = m_current; 267 m_lastAdjusted = m_current;
264 } 268 }
265 m_hasBounced = (m_lastAdjustment == -adjustment); 269 m_hasBounced = (m_lastAdjustment == -adjustment);
266 m_lastAdjustment = adjustment; 270 m_lastAdjustment = adjustment;
267 271
268 // Update UMA metric. 272 // Update UMA metric.
269 DEFINE_STATIC_LOCAL(EnumerationHistogram, adjustedOffsetHistogram, 273 DEFINE_STATIC_LOCAL(EnumerationHistogram, adjustedOffsetHistogram,
270 ("Layout.ScrollAnchor.AdjustedScrollOffset", 2)); 274 ("Layout.ScrollAnchor.AdjustedScrollOffset", 2));
271 adjustedOffsetHistogram.count(1); 275 adjustedOffsetHistogram.count(1);
272 UseCounter::count(scrollerLayoutBox(m_scroller)->document(), UseCounter::Scr ollAnchored); 276 UseCounter::count(scrollerLayoutBox(m_scroller)->document(), UseCounter::Scr ollAnchored);
273 } 277 }
274 278
275 void ScrollAnchor::clear() 279 void ScrollAnchor::clear()
276 { 280 {
281 m_adjustmentCount = 0;
277 m_current.clear(); 282 m_current.clear();
278 } 283 }
279 284
280 void ScrollAnchor::AnchorPoint::clear() 285 void ScrollAnchor::AnchorPoint::clear()
281 { 286 {
282 LayoutObject* anchorObject = m_anchorObject; 287 LayoutObject* anchorObject = m_anchorObject;
283 m_anchorObject = nullptr; 288 m_anchorObject = nullptr;
284 289
285 if (anchorObject) 290 if (anchorObject)
286 anchorObject->maybeClearIsScrollAnchorObject(); 291 anchorObject->maybeClearIsScrollAnchorObject();
287 } 292 }
288 293
289 bool ScrollAnchor::refersTo(const LayoutObject* layoutObject) const 294 bool ScrollAnchor::refersTo(const LayoutObject* layoutObject) const
290 { 295 {
291 return m_current.m_anchorObject == layoutObject 296 return m_current.m_anchorObject == layoutObject
292 || m_lastAdjusted.m_anchorObject == layoutObject; 297 || m_lastAdjusted.m_anchorObject == layoutObject;
293 } 298 }
294 299
295 void ScrollAnchor::notifyRemoved(LayoutObject* layoutObject) 300 void ScrollAnchor::notifyRemoved(LayoutObject* layoutObject)
296 { 301 {
297 if (m_current.m_anchorObject == layoutObject) 302 if (m_current.m_anchorObject == layoutObject)
298 m_current.clear(); 303 m_current.clear();
299 if (m_lastAdjusted.m_anchorObject == layoutObject) 304 if (m_lastAdjusted.m_anchorObject == layoutObject)
300 m_lastAdjusted.clear(); 305 m_lastAdjusted.clear();
301 } 306 }
302 307
303 } // namespace blink 308 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/layout/ScrollAnchor.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698