Index: Source/core/loader/FrameLoader.cpp |
diff --git a/Source/core/loader/FrameLoader.cpp b/Source/core/loader/FrameLoader.cpp |
index d602d080c9d6b349b6d109012f9dc51bd37a2421..f179bf2c1d02e2f1c9cfe688d3683de444f30b23 100644 |
--- a/Source/core/loader/FrameLoader.cpp |
+++ b/Source/core/loader/FrameLoader.cpp |
@@ -50,8 +50,10 @@ |
#include "core/fetch/ResourceFetcher.h" |
#include "core/fetch/ResourceLoader.h" |
#include "core/frame/DOMWindow.h" |
+#include "core/frame/FrameHost.h" |
#include "core/frame/FrameView.h" |
#include "core/frame/LocalFrame.h" |
+#include "core/frame/PinchViewport.h" |
#include "core/frame/csp/ContentSecurityPolicy.h" |
#include "core/html/HTMLFormElement.h" |
#include "core/html/HTMLFrameOwnerElement.h" |
@@ -184,6 +186,12 @@ void FrameLoader::saveScrollState() |
return; |
m_currentItem->setScrollPoint(m_frame->view()->scrollPosition()); |
+ |
+ if (m_frame->settings()->pinchVirtualViewportEnabled()) |
+ m_currentItem->setPinchViewportScrollPoint(m_frame->host()->pinchViewport().visibleRect().location()); |
+ else |
+ m_currentItem->setPinchViewportScrollPoint(FloatPoint(-1, -1)); |
+ |
if (m_frame->isMainFrame() && !m_frame->page()->inspectorController().deviceEmulationEnabled()) |
m_currentItem->setPageScaleFactor(m_frame->page()->pageScaleFactor()); |
@@ -992,15 +1000,32 @@ void FrameLoader::restoreScrollPositionAndViewState() |
// page height increases, 3. ignore clamp detection after load completes |
// because that may be because the page will never reach its previous |
// height. |
- bool canRestoreWithoutClamping = view->clampOffsetAtScale(m_currentItem->scrollPoint(), m_currentItem->pageScaleFactor()) == m_currentItem->scrollPoint(); |
+ float mainFrameScale = m_frame->settings()->pinchVirtualViewportEnabled() ? 1 : m_currentItem->pageScaleFactor(); |
+ bool canRestoreWithoutClamping = view->clampOffsetAtScale(m_currentItem->scrollPoint(), mainFrameScale) == m_currentItem->scrollPoint(); |
bool canRestoreWithoutAnnoyingUser = !view->wasScrolledByUser() && (canRestoreWithoutClamping || m_state == FrameStateComplete); |
if (!canRestoreWithoutAnnoyingUser) |
return; |
- if (m_frame->isMainFrame() && m_currentItem->pageScaleFactor()) |
- m_frame->page()->setPageScaleFactor(m_currentItem->pageScaleFactor(), m_currentItem->scrollPoint()); |
- else |
+ if (m_frame->isMainFrame() && m_currentItem->pageScaleFactor()) { |
+ FloatPoint pinchViewportOffset(m_currentItem->pinchViewportScrollPoint()); |
+ IntPoint frameScrollOffset(m_currentItem->scrollPoint()); |
+ |
+ m_frame->page()->setPageScaleFactor(m_currentItem->pageScaleFactor(), frameScrollOffset); |
+ |
+ if (m_frame->document()->settings()->pinchVirtualViewportEnabled()) { |
+ // If the pinch viewport's offset is (-1, -1) it means the history item |
+ // is an old version of HistoryItem so distribute the scroll between |
+ // the main frame and the pinch viewport as best as we can. |
+ // FIXME(bokan): This legacy distribution can be removed once the virtual viewport |
+ // pinch path is enabled on all platforms for at least one release. |
+ if (pinchViewportOffset.x() == -1 && pinchViewportOffset.y() == -1) |
+ pinchViewportOffset = FloatPoint(frameScrollOffset - view->scrollPosition()); |
+ |
+ m_frame->host()->pinchViewport().setLocation(pinchViewportOffset); |
+ } |
+ } else { |
view->setScrollPositionNonProgrammatically(m_currentItem->scrollPoint()); |
+ } |
if (m_frame->isMainFrame()) { |
if (ScrollingCoordinator* scrollingCoordinator = m_frame->page()->scrollingCoordinator()) |