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

Unified Diff: third_party/WebKit/Source/core/frame/LocalDOMWindow.cpp

Issue 1366893002: Make window.scroll properties relative to the layout viewport. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: "worked on review comments" Created 5 years, 3 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/frame/LocalDOMWindow.cpp
diff --git a/third_party/WebKit/Source/core/frame/LocalDOMWindow.cpp b/third_party/WebKit/Source/core/frame/LocalDOMWindow.cpp
index 87e8c5891b1ba1eff4d79b06e1d3f244e3af3e97..ba41de3380c000eebc3b57293db19e576077ac4a 100644
--- a/third_party/WebKit/Source/core/frame/LocalDOMWindow.cpp
+++ b/third_party/WebKit/Source/core/frame/LocalDOMWindow.cpp
@@ -938,7 +938,7 @@ static FloatSize getViewportSize(LocalFrame* frame)
toLocalFrame(parent)->document()->updateLayoutIgnorePendingStylesheets();
}
- return frame->isMainFrame()
+ return frame->isMainFrame() && !host->settings().inertVisualViewport()
? host->visualViewport().visibleRect().size()
: view->visibleContentRect(IncludeScrollbars).size();
}
@@ -1004,7 +1004,8 @@ double LocalDOMWindow::scrollX() const
frame()->document()->updateLayoutIgnorePendingStylesheets();
- double viewportX = view->scrollableArea()->scrollPositionDouble().x();
+ ScrollableArea* viewport = host->settings().inertVisualViewport() ? view->layoutViewportScrollableArea() : view->scrollableArea();
+ double viewportX = viewport->scrollPositionDouble().x();
return adjustScrollForAbsoluteZoom(viewportX, frame()->pageZoomFactor());
}
@@ -1023,7 +1024,8 @@ double LocalDOMWindow::scrollY() const
frame()->document()->updateLayoutIgnorePendingStylesheets();
- double viewportY = view->scrollableArea()->scrollPositionDouble().y();
+ ScrollableArea* viewport = host->settings().inertVisualViewport() ? view->layoutViewportScrollableArea() : view->scrollableArea();
+ double viewportY = viewport->scrollPositionDouble().y();
return adjustScrollForAbsoluteZoom(viewportY, frame()->pageZoomFactor());
}
@@ -1131,13 +1133,18 @@ void LocalDOMWindow::scrollBy(double x, double y, ScrollBehavior scrollBehavior)
if (!view)
return;
+ FrameHost* host = frame()->host();
+ if (!host)
+ return;
+
x = ScrollableArea::normalizeNonFiniteScroll(x);
y = ScrollableArea::normalizeNonFiniteScroll(y);
DoublePoint currentOffset = view->scrollableArea()->scrollPositionDouble();
DoubleSize scaledDelta(x * frame()->pageZoomFactor(), y * frame()->pageZoomFactor());
- view->scrollableArea()->setScrollPosition(currentOffset + scaledDelta, ProgrammaticScroll, scrollBehavior);
+ ScrollableArea* viewport = host->settings().inertVisualViewport() ? view->layoutViewportScrollableArea() : view->scrollableArea();
+ viewport->setScrollPosition(currentOffset + scaledDelta, ProgrammaticScroll, scrollBehavior);
}
void LocalDOMWindow::scrollBy(const ScrollToOptions& scrollToOptions) const
@@ -1162,6 +1169,10 @@ void LocalDOMWindow::scrollTo(double x, double y) const
if (!view)
return;
+ FrameHost* host = frame()->host();
+ if (!host)
+ return;
+
x = ScrollableArea::normalizeNonFiniteScroll(x);
y = ScrollableArea::normalizeNonFiniteScroll(y);
@@ -1171,7 +1182,8 @@ void LocalDOMWindow::scrollTo(double x, double y) const
document()->updateLayoutIgnorePendingStylesheets();
DoublePoint layoutPos(x * frame()->pageZoomFactor(), y * frame()->pageZoomFactor());
- view->scrollableArea()->setScrollPosition(layoutPos, ProgrammaticScroll, ScrollBehaviorAuto);
+ ScrollableArea* viewport = host->settings().inertVisualViewport() ? view->layoutViewportScrollableArea() : view->scrollableArea();
+ viewport->setScrollPosition(layoutPos, ProgrammaticScroll, ScrollBehaviorAuto);
}
void LocalDOMWindow::scrollTo(const ScrollToOptions& scrollToOptions) const
@@ -1183,6 +1195,10 @@ void LocalDOMWindow::scrollTo(const ScrollToOptions& scrollToOptions) const
if (!view)
return;
+ FrameHost* host = frame()->host();
+ 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()
@@ -1207,7 +1223,8 @@ void LocalDOMWindow::scrollTo(const ScrollToOptions& scrollToOptions) const
ScrollBehavior scrollBehavior = ScrollBehaviorAuto;
ScrollableArea::scrollBehaviorFromString(scrollToOptions.behavior(), scrollBehavior);
- view->scrollableArea()->setScrollPosition(DoublePoint(scaledX, scaledY), ProgrammaticScroll, scrollBehavior);
+ ScrollableArea* viewport = host->settings().inertVisualViewport() ? view->layoutViewportScrollableArea() : view->scrollableArea();
+ viewport->setScrollPosition(DoublePoint(scaledX, scaledY), ProgrammaticScroll, scrollBehavior);
}
void LocalDOMWindow::moveBy(int x, int y) const

Powered by Google App Engine
This is Rietveld 408576698