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

Unified Diff: third_party/WebKit/Source/core/paint/PaintLayerScrollableArea.cpp

Issue 2383113003: Refactor ScrollableArea::setScrollPosition. (Closed)
Patch Set: Fix clamping, comment tweaks 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/paint/PaintLayerScrollableArea.cpp
diff --git a/third_party/WebKit/Source/core/paint/PaintLayerScrollableArea.cpp b/third_party/WebKit/Source/core/paint/PaintLayerScrollableArea.cpp
index 32054fb3d7af13061465e7b559e9ec93b3931750..3f89d3f1e5672e1be5a266bccba3a61b653a58b0 100644
--- a/third_party/WebKit/Source/core/paint/PaintLayerScrollableArea.cpp
+++ b/third_party/WebKit/Source/core/paint/PaintLayerScrollableArea.cpp
@@ -114,9 +114,10 @@ PaintLayerScrollableArea::PaintLayerScrollableArea(PaintLayer& layer)
// We save and restore only the scrollOffset as the other scroll values are recalculated.
Element* element = toElement(node);
m_scrollOffset = element->savedLayerScrollOffset();
- if (!m_scrollOffset.isZero())
+ if (!m_scrollOffset.isZero()) {
scrollAnimator().setCurrentPosition(
FloatPoint(m_scrollOffset.width(), m_scrollOffset.height()));
+ }
element->setSavedLayerScrollOffset(IntSize());
}
updateResizerAreaSet();
@@ -148,9 +149,10 @@ void PaintLayerScrollableArea::dispose() {
if (!box().documentBeingDestroyed()) {
Node* node = box().node();
// FIXME: Make setSavedLayerScrollOffset take DoubleSize. crbug.com/414283.
- if (node && node->isElementNode())
+ if (node && node->isElementNode()) {
toElement(node)->setSavedLayerScrollOffset(
flooredIntSize(m_scrollOffset));
+ }
}
if (LocalFrame* frame = box().frame()) {
@@ -498,8 +500,9 @@ IntRect PaintLayerScrollableArea::visibleContentRect(
: 0;
}
+ // TODO(szager): Handle fractional scroll offsets correctly.
return IntRect(
- IntPoint(scrollXOffset(), scrollYOffset()),
+ IntPoint(flooredIntSize(adjustedScrollOffset())),
IntSize(max(0, layer()->size().width() - verticalScrollbarWidth),
max(0, layer()->size().height() - horizontalScrollbarHeight)));
}
@@ -635,17 +638,11 @@ void PaintLayerScrollableArea::updateScrollDimensions() {
updateScrollOrigin();
}
-void PaintLayerScrollableArea::scrollToPosition(
- const DoublePoint& scrollPosition,
- ScrollOffsetClamping clamp,
- ScrollBehavior scrollBehavior,
+void PaintLayerScrollableArea::setScrollPositionUnconditionally(
+ const DoublePoint& position,
ScrollType scrollType) {
- DoublePoint newScrollPosition = clamp == ScrollOffsetClamped
- ? clampScrollPosition(scrollPosition)
- : scrollPosition;
- if (newScrollPosition != scrollPositionDouble())
- ScrollableArea::setScrollPosition(newScrollPosition, scrollType,
- scrollBehavior);
+ cancelScrollAnimation();
skobes 2016/10/04 22:25:26 Is this what happened before? (cancelling the anim
szager1 2016/10/04 22:54:13 Yes, it's the same thing that ProgrammaticScrollAn
+ scrollPositionChanged(position, scrollType);
}
void PaintLayerScrollableArea::updateAfterLayout() {
@@ -806,9 +803,13 @@ void PaintLayerScrollableArea::clampScrollPositionsAfterLayout() {
if (shouldPerformScrollAnchoring())
m_scrollAnchor.restore();
- DoublePoint clamped = clampScrollPosition(scrollPositionDouble());
- if (clamped != scrollPositionDouble() || scrollOriginChanged())
- ScrollableArea::setScrollPosition(clamped, ProgrammaticScroll);
+ if (scrollOriginChanged()) {
+ setScrollPositionUnconditionally(
+ clampScrollPosition(scrollPositionDouble()));
+ } else {
+ ScrollableArea::setScrollPosition(scrollPositionDouble(),
bokan 2016/10/04 22:17:25 Why not just ScrollableArea::setScrollPosition
szager1 2016/10/04 22:54:14 I don't understand the question; maybe you're aski
bokan 2016/10/04 22:56:51 What I meant was, since ScrollableArea::setScrollP
szager1 2016/10/04 23:37:37 No, this is necessary for the case where the scrol
bokan 2016/10/04 23:38:38 Got it, thanks.
+ ProgrammaticScroll);
+ }
setNeedsScrollPositionClamp(false);
resetScrollOriginChanged();
@@ -1563,17 +1564,17 @@ LayoutRect PaintLayerScrollableArea::scrollIntoView(
DoublePoint clampedScrollPosition = clampScrollPosition(
scrollPositionDouble() + roundedIntSize(r.location()));
- if (clampedScrollPosition == scrollPositionDouble())
+ if (clampedScrollPosition == scrollPositionDouble()) {
return LayoutRect(
box()
.localToAbsoluteQuad(FloatQuad(FloatRect(intersection(
layerBounds, localExposeRect))),
UseTransforms)
.boundingBox());
+ }
DoubleSize oldScrollOffset = adjustedScrollOffset();
- scrollToPosition(clampedScrollPosition, ScrollOffsetUnclamped,
- ScrollBehaviorInstant, scrollType);
+ setScrollPosition(clampedScrollPosition, scrollType, ScrollBehaviorInstant);
DoubleSize scrollOffsetDifference = adjustedScrollOffset() - oldScrollOffset;
localExposeRect.move(-LayoutSize(scrollOffsetDifference));
return LayoutRect(

Powered by Google App Engine
This is Rietveld 408576698