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

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

Issue 2387883002: Use float for scroll offset. (Closed)
Patch Set: Fix README.md Created 4 years, 2 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/LayoutBlockFlow.h" 9 #include "core/layout/LayoutBlockFlow.h"
10 #include "core/layout/api/LayoutBoxItem.h" 10 #include "core/layout/api/LayoutBoxItem.h"
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 // When root layer scrolling is off, the LayoutView will have no scroll 105 // When root layer scrolling is off, the LayoutView will have no scroll
106 // offset (since scrolling is handled by the FrameView) so 106 // offset (since scrolling is handled by the FrameView) so
107 // localToAncestorQuad returns document coords, so we must subtract scroll 107 // localToAncestorQuad returns document coords, so we must subtract scroll
108 // offset to get viewport coords. We discard the fractional part of the 108 // offset to get viewport coords. We discard the fractional part of the
109 // scroll offset so that the rounding in restore() matches the snapping of 109 // scroll offset so that the rounding in restore() matches the snapping of
110 // the anchor node to the pixel grid of the layer it paints into. For 110 // the anchor node to the pixel grid of the layer it paints into. For
111 // non-FrameView scrollers, we rely on the flooring behavior of 111 // non-FrameView scrollers, we rely on the flooring behavior of
112 // LayoutBox::scrolledContentOffset. 112 // LayoutBox::scrolledContentOffset.
113 if (!RuntimeEnabledFeatures::rootLayerScrollingEnabled() && 113 if (!RuntimeEnabledFeatures::rootLayerScrollingEnabled() &&
114 scrollerBox->isLayoutView()) 114 scrollerBox->isLayoutView())
115 relativeBounds.moveBy(-flooredIntPoint(scroller->scrollPositionDouble())); 115 relativeBounds.moveBy(IntPoint(-scroller->scrollOffsetInt()));
116 return relativeBounds; 116 return relativeBounds;
117 } 117 }
118 118
119 static LayoutPoint computeRelativeOffset(const LayoutObject* layoutObject, 119 static LayoutPoint computeRelativeOffset(const LayoutObject* layoutObject,
120 const ScrollableArea* scroller, 120 const ScrollableArea* scroller,
121 Corner corner) { 121 Corner corner) {
122 return cornerPointOfRect(relativeBounds(layoutObject, scroller), corner); 122 return cornerPointOfRect(relativeBounds(layoutObject, scroller), corner);
123 } 123 }
124 124
125 static bool candidateMayMoveWithScroller(const LayoutObject* candidate, 125 static bool candidateMayMoveWithScroller(const LayoutObject* candidate,
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 return false; 209 return false;
210 current = current->parent(); 210 current = current->parent();
211 } 211 }
212 } 212 }
213 213
214 void ScrollAnchor::save() { 214 void ScrollAnchor::save() {
215 if (m_saved) 215 if (m_saved)
216 return; 216 return;
217 m_saved = true; 217 m_saved = true;
218 DCHECK(m_scroller); 218 DCHECK(m_scroller);
219 219 ScrollOffset scrollOffset = m_scroller->scrollOffset();
220 ScrollbarOrientation blockLayoutAxis = 220 float blockDirectionScrollOffset =
221 scrollerLayoutBox(m_scroller)->isHorizontalWritingMode() 221 scrollerLayoutBox(m_scroller)->isHorizontalWritingMode()
222 ? VerticalScrollbar 222 ? scrollOffset.height()
223 : HorizontalScrollbar; 223 : scrollOffset.width();
224 if (m_scroller->scrollPosition(blockLayoutAxis) == 0) { 224 if (blockDirectionScrollOffset == 0) {
225 clear(); 225 clear();
226 return; 226 return;
227 } 227 }
228 228
229 if (!m_anchorObject) { 229 if (!m_anchorObject) {
230 findAnchor(); 230 findAnchor();
231 if (!m_anchorObject) 231 if (!m_anchorObject)
232 return; 232 return;
233 233
234 m_anchorObject->setIsScrollAnchorObject(); 234 m_anchorObject->setIsScrollAnchorObject();
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 // TODO(skobes): add UMA metric for this. 280 // TODO(skobes): add UMA metric for this.
281 clear(); 281 clear();
282 282
283 DEFINE_STATIC_LOCAL(EnumerationHistogram, suppressedBySanaclapHistogram, 283 DEFINE_STATIC_LOCAL(EnumerationHistogram, suppressedBySanaclapHistogram,
284 ("Layout.ScrollAnchor.SuppressedBySanaclap", 2)); 284 ("Layout.ScrollAnchor.SuppressedBySanaclap", 2));
285 suppressedBySanaclapHistogram.count(1); 285 suppressedBySanaclapHistogram.count(1);
286 286
287 return; 287 return;
288 } 288 }
289 289
290 m_scroller->setScrollPosition(m_scroller->scrollPositionDouble() + adjustment, 290 m_scroller->setScrollOffset(
291 AnchoringScroll); 291 m_scroller->scrollOffset() + FloatSize(adjustment), AnchoringScroll);
292 292
293 // Update UMA metric. 293 // Update UMA metric.
294 DEFINE_STATIC_LOCAL(EnumerationHistogram, adjustedOffsetHistogram, 294 DEFINE_STATIC_LOCAL(EnumerationHistogram, adjustedOffsetHistogram,
295 ("Layout.ScrollAnchor.AdjustedScrollOffset", 2)); 295 ("Layout.ScrollAnchor.AdjustedScrollOffset", 2));
296 adjustedOffsetHistogram.count(1); 296 adjustedOffsetHistogram.count(1);
297 UseCounter::count(scrollerLayoutBox(m_scroller)->document(), 297 UseCounter::count(scrollerLayoutBox(m_scroller)->document(),
298 UseCounter::ScrollAnchored); 298 UseCounter::ScrollAnchored);
299 } 299 }
300 300
301 void ScrollAnchor::clear() { 301 void ScrollAnchor::clear() {
302 LayoutObject* anchorObject = m_anchorObject; 302 LayoutObject* anchorObject = m_anchorObject;
303 m_anchorObject = nullptr; 303 m_anchorObject = nullptr;
304 304
305 if (anchorObject) 305 if (anchorObject)
306 anchorObject->maybeClearIsScrollAnchorObject(); 306 anchorObject->maybeClearIsScrollAnchorObject();
307 } 307 }
308 308
309 bool ScrollAnchor::refersTo(const LayoutObject* layoutObject) const { 309 bool ScrollAnchor::refersTo(const LayoutObject* layoutObject) const {
310 return m_anchorObject == layoutObject; 310 return m_anchorObject == layoutObject;
311 } 311 }
312 312
313 void ScrollAnchor::notifyRemoved(LayoutObject* layoutObject) { 313 void ScrollAnchor::notifyRemoved(LayoutObject* layoutObject) {
314 if (m_anchorObject == layoutObject) 314 if (m_anchorObject == layoutObject)
315 clear(); 315 clear();
316 } 316 }
317 317
318 } // namespace blink 318 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/layout/README.md ('k') | third_party/WebKit/Source/core/layout/ScrollAnchorTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698