Index: third_party/WebKit/Source/core/layout/LayoutBox.cpp |
diff --git a/third_party/WebKit/Source/core/layout/LayoutBox.cpp b/third_party/WebKit/Source/core/layout/LayoutBox.cpp |
index b59cf4626abb3a6e4380f5724f7e55c2d0214412..bf2bbdc558be98055fb006d193dae454530e77fe 100644 |
--- a/third_party/WebKit/Source/core/layout/LayoutBox.cpp |
+++ b/third_party/WebKit/Source/core/layout/LayoutBox.cpp |
@@ -256,18 +256,20 @@ void LayoutBox::styleDidChange(StyleDifference diff, |
} |
// If our zoom factor changes and we have a defined scrollLeft/Top, we need to adjust that value into the |
- // new zoomed coordinate space. |
+ // new zoomed coordinate space. Note that the new scroll position may be outside the normal min/max |
+ // range of the scrollable area, which is weird but OK, because the scrollable area will update its |
+ // min/max in updateAfterLayout(). |
if (hasOverflowClip() && oldStyle && |
oldStyle->effectiveZoom() != newStyle.effectiveZoom()) { |
PaintLayerScrollableArea* scrollableArea = this->getScrollableArea(); |
ASSERT(scrollableArea); |
- if (int left = scrollableArea->scrollXOffset()) { |
- left = (left / oldStyle->effectiveZoom()) * newStyle.effectiveZoom(); |
- scrollableArea->scrollToXOffset(left); |
- } |
- if (int top = scrollableArea->scrollYOffset()) { |
- top = (top / oldStyle->effectiveZoom()) * newStyle.effectiveZoom(); |
- scrollableArea->scrollToYOffset(top); |
+ // We use scrollPosition() rather than offsetFromOrigin(), because scrollPosition is the distance |
+ // from the beginning of flow for the box, which is the dimension we want to preserve. |
+ DoublePoint oldPosition = scrollableArea->scrollPositionDouble(); |
+ if (oldPosition.x() || oldPosition.y()) { |
+ DoublePoint newPosition = oldPosition.scaledBy(newStyle.effectiveZoom() / |
+ oldStyle->effectiveZoom()); |
+ scrollableArea->setScrollPositionUnconditionally(newPosition); |
} |
} |
@@ -512,13 +514,15 @@ LayoutUnit LayoutBox::scrollHeight() const { |
} |
LayoutUnit LayoutBox::scrollLeft() const { |
- return hasOverflowClip() ? LayoutUnit(getScrollableArea()->scrollXOffset()) |
- : LayoutUnit(); |
+ return hasOverflowClip() |
+ ? LayoutUnit(getScrollableArea()->offsetFromOrigin().width()) |
+ : LayoutUnit(); |
} |
LayoutUnit LayoutBox::scrollTop() const { |
- return hasOverflowClip() ? LayoutUnit(getScrollableArea()->scrollYOffset()) |
- : LayoutUnit(); |
+ return hasOverflowClip() |
+ ? LayoutUnit(getScrollableArea()->offsetFromOrigin().height()) |
+ : LayoutUnit(); |
} |
int LayoutBox::pixelSnappedScrollWidth() const { |
@@ -539,18 +543,24 @@ void LayoutBox::setScrollLeft(LayoutUnit newLeft) { |
// does, presumably this code does as well. |
DisableCompositingQueryAsserts disabler; |
- if (hasOverflowClip()) |
- getScrollableArea()->scrollToXOffset(newLeft, ScrollOffsetClamped, |
- ScrollBehaviorAuto); |
+ if (!hasOverflowClip()) |
+ return; |
+ |
+ PaintLayerScrollableArea* scrollableArea = getScrollableArea(); |
+ DoubleSize newOffset(newLeft, scrollableArea->offsetFromOrigin().height()); |
+ scrollableArea->scrollToOffsetFromOrigin(newOffset, ScrollBehaviorAuto); |
} |
void LayoutBox::setScrollTop(LayoutUnit newTop) { |
// Hits in compositing/overflow/do-not-assert-on-invisible-composited-layers.html |
DisableCompositingQueryAsserts disabler; |
- if (hasOverflowClip()) |
- getScrollableArea()->scrollToYOffset(newTop, ScrollOffsetClamped, |
- ScrollBehaviorAuto); |
+ if (!hasOverflowClip()) |
+ return; |
+ |
+ PaintLayerScrollableArea* scrollableArea = getScrollableArea(); |
+ DoubleSize newOffset(scrollableArea->offsetFromOrigin().width(), newTop); |
+ scrollableArea->scrollToOffsetFromOrigin(newOffset, ScrollBehaviorAuto); |
} |
void LayoutBox::scrollToOffset(const DoubleSize& offset, |
@@ -559,9 +569,10 @@ void LayoutBox::scrollToOffset(const DoubleSize& offset, |
// does, presumably this code does as well. |
DisableCompositingQueryAsserts disabler; |
- if (hasOverflowClip()) |
- getScrollableArea()->scrollToOffset(offset, ScrollOffsetClamped, |
- scrollBehavior); |
+ if (!hasOverflowClip()) |
+ return; |
+ |
+ getScrollableArea()->scrollToOffsetFromOrigin(offset, scrollBehavior); |
} |
// Returns true iff we are attempting an autoscroll inside an iframe with scrolling="no". |
@@ -1076,8 +1087,7 @@ void LayoutBox::middleClickAutoscroll(const IntPoint& sourcePoint) { |
scroll(ScrollByPixel, FloatSize(adjustedScrollDelta(delta))); |
} |
-void LayoutBox::scrollByRecursively(const DoubleSize& delta, |
- ScrollOffsetClamping clamp) { |
+void LayoutBox::scrollByRecursively(const DoubleSize& delta) { |
if (delta.isZero()) |
return; |
@@ -1089,15 +1099,15 @@ void LayoutBox::scrollByRecursively(const DoubleSize& delta, |
PaintLayerScrollableArea* scrollableArea = this->getScrollableArea(); |
ASSERT(scrollableArea); |
- DoubleSize newScrollOffset = scrollableArea->adjustedScrollOffset() + delta; |
- scrollableArea->scrollToOffset(newScrollOffset, clamp); |
+ DoubleSize newScrollOffset = scrollableArea->offsetFromOrigin() + delta; |
+ scrollableArea->scrollToOffsetFromOrigin(newScrollOffset); |
// If this layer can't do the scroll we ask the next layer up that can scroll to try |
DoubleSize remainingScrollOffset = |
- newScrollOffset - scrollableArea->adjustedScrollOffset(); |
+ newScrollOffset - scrollableArea->offsetFromOrigin(); |
if (!remainingScrollOffset.isZero() && parent()) { |
if (LayoutBox* scrollableBox = enclosingScrollableBox()) |
- scrollableBox->scrollByRecursively(remainingScrollOffset, clamp); |
+ scrollableBox->scrollByRecursively(remainingScrollOffset); |
LocalFrame* frame = this->frame(); |
if (frame && frame->page()) |
@@ -1135,7 +1145,7 @@ IntSize LayoutBox::scrolledContentOffset() const { |
ASSERT(hasLayer()); |
// FIXME: Return DoubleSize here. crbug.com/414283. |
PaintLayerScrollableArea* scrollableArea = getScrollableArea(); |
- IntSize result = flooredIntSize(scrollableArea->scrollOffset()) + |
+ IntSize result = flooredIntSize(scrollableArea->scrollPosition()) + |
originAdjustmentForScrollbars(); |
if (isHorizontalWritingMode() && |
shouldPlaceBlockDirectionScrollbarOnLogicalLeft()) |