Index: Source/core/frame/LocalDOMWindow.cpp |
diff --git a/Source/core/frame/LocalDOMWindow.cpp b/Source/core/frame/LocalDOMWindow.cpp |
index 0c636c0bd315c613ab58748e3a472d3563458a3d..2b4002e5bd41cb79b7d8d80a3b90a3b75f179829 100644 |
--- a/Source/core/frame/LocalDOMWindow.cpp |
+++ b/Source/core/frame/LocalDOMWindow.cpp |
@@ -1210,11 +1210,14 @@ void LocalDOMWindow::scrollTo(double x, double y) const |
if (!isCurrentlyDisplayedInFrame()) |
return; |
- document()->updateLayoutIgnorePendingStylesheets(); |
- |
if (std::isnan(x) || std::isnan(y)) |
return; |
+ // It is only necessary to have an up-to-date layout if the position may be clamped, |
+ // which is never the case for (0, 0). |
+ if (x || y) |
+ document()->updateLayoutIgnorePendingStylesheets(); |
+ |
DoublePoint layoutPos(x * frame()->pageZoomFactor(), y * frame()->pageZoomFactor()); |
scrollViewportTo(frame(), layoutPos, ScrollBehaviorAuto); |
} |
@@ -1224,8 +1227,6 @@ void LocalDOMWindow::scrollTo(const ScrollToOptions& scrollToOptions) const |
if (!isCurrentlyDisplayedInFrame()) |
return; |
- document()->updateLayoutIgnorePendingStylesheets(); |
- |
FrameView* view = frame()->view(); |
if (!view) |
return; |
@@ -1234,6 +1235,15 @@ void LocalDOMWindow::scrollTo(const ScrollToOptions& scrollToOptions) const |
if (!host) |
return; |
+ // It is only necessary to have an up-to-date layout if the position may be clamped, |
+ // which is never the case for (0, 0). |
+ if (!scrollToOptions.hasLeft() |
+ || !scrollToOptions.hasTop() |
+ || scrollToOptions.left() |
+ || scrollToOptions.top()) { |
+ document()->updateLayoutIgnorePendingStylesheets(); |
+ } |
+ |
double scaledX = 0.0; |
double scaledY = 0.0; |