Index: third_party/WebKit/Source/web/WebViewImpl.cpp |
diff --git a/third_party/WebKit/Source/web/WebViewImpl.cpp b/third_party/WebKit/Source/web/WebViewImpl.cpp |
index 7f9d5c550cfe56d0f26f919d9bc120bda193ac41..43d06bc10e4b950906f3094a6290087892b88360 100644 |
--- a/third_party/WebKit/Source/web/WebViewImpl.cpp |
+++ b/third_party/WebKit/Source/web/WebViewImpl.cpp |
@@ -56,6 +56,7 @@ |
#include "core/frame/LocalFrame.h" |
#include "core/frame/PageScaleConstraintsSet.h" |
#include "core/frame/RemoteFrame.h" |
+#include "core/frame/ScrollAndScaleEmulator.h" |
#include "core/frame/Settings.h" |
#include "core/frame/SmartClip.h" |
#include "core/frame/TopControls.h" |
@@ -3207,6 +3208,58 @@ WebFloatSize WebViewImpl::visualViewportSize() const |
return page()->frameHost().visualViewport().visibleRect().size(); |
} |
+void WebViewImpl::setScrollAndScaleOverride(const WebDeviceEmulationParams& params) |
+{ |
+ if (!page() || !mainFrameImpl()) |
+ return; |
+ |
+ FrameView * view = mainFrameImpl()->frameView(); |
+ if (!view) |
+ return; |
+ |
+ if (!m_scrollAndScaleEmulator) { |
+ m_scrollAndScaleEmulator = ScrollAndScaleEmulator::create(); |
+ |
+ // Force main thread scrolling, because we do not apply scroll position |
+ // overrides in the compositor thread. |
+ m_scrollAndScaleEmulator->disableThreadedScrolling(page()); |
+ } |
+ |
+ bool hasChanged = m_scrollAndScaleEmulator->update( |
+ static_cast<IntPoint>(params.scrollPosition), |
+ static_cast<FloatPoint>(params.visualViewportPosition), |
+ params.visualViewportScale); |
+ if (hasChanged) { |
+ view->setScrollAndScaleEmulator(m_scrollAndScaleEmulator); |
+ page()->frameHost().visualViewport().setScrollAndScaleEmulator(m_scrollAndScaleEmulator); |
+ page()->frameHost().setUserAgentPageScaleConstraints(m_scrollAndScaleEmulator->pageScaleConstraints()); |
+ } |
+} |
+ |
+void WebViewImpl::clearScrollAndScaleOverride() |
+{ |
+ if (!m_scrollAndScaleEmulator || !page() || !mainFrameImpl()) |
+ return; |
+ |
+ FrameView * view = mainFrameImpl()->frameView(); |
+ if (!view) |
+ return; |
+ |
+ m_scrollAndScaleEmulator->restoreThreadedScrolling(page()); |
+ |
+ view->setScrollAndScaleEmulator(nullptr); |
+ page()->frameHost().visualViewport().setScrollAndScaleEmulator(nullptr); |
+ page()->frameHost().setUserAgentPageScaleConstraints(PageScaleConstraints()); |
+ |
+ // TODO(eseckler): For some reason, we seem to need this enforce the cleared |
+ // constraints. Adding it in setScrollAndScaleOverride() makes the override |
+ // ineffective, though. |
+ page()->frameHost().pageScaleConstraintsSet().computeFinalConstraints(); |
Eric Seckler
2016/06/30 20:01:28
Not sure why this line is necessary here (otherwis
|
+ |
+ m_scrollAndScaleEmulator.clear(); |
+ resetScrollAndScaleState(); |
+} |
+ |
void WebViewImpl::scrollAndRescaleViewports(float scaleFactor, |
const IntPoint& mainFrameOrigin, |
const FloatPoint& visualViewportOrigin) |
@@ -3340,10 +3393,22 @@ void WebViewImpl::setIgnoreViewportTagScaleLimits(bool ignore) |
IntSize WebViewImpl::mainFrameSize() |
{ |
- // The frame size should match the viewport size at minimum scale, since the |
- // viewport must always be contained by the frame. |
FloatSize frameSize(m_size); |
+ |
+ // The frame size should match the viewport size at minimum scale, since the |
+ // viewport must always be contained by the frame. ScrollAndScaleEmulator |
+ // overrides the minimum scale in the userAgentConstraints. These overrides |
+ // should be ignored for this calculation. |
+ if (m_scrollAndScaleEmulator) { |
+ pageScaleConstraintsSet().setUserAgentConstraints(PageScaleConstraints()); |
+ pageScaleConstraintsSet().computeFinalConstraints(); |
+ } |
frameSize.scale(1 / minimumPageScaleFactor()); |
+ if (m_scrollAndScaleEmulator) { |
+ pageScaleConstraintsSet().setUserAgentConstraints(m_scrollAndScaleEmulator->pageScaleConstraints()); |
+ pageScaleConstraintsSet().computeFinalConstraints(); |
+ } |
+ |
return expandedIntSize(frameSize); |
} |
@@ -3832,10 +3897,12 @@ void WebViewImpl::setRootLayerTransform(const WebSize& rootLayerOffset, float ro |
void WebViewImpl::enableDeviceEmulation(const WebDeviceEmulationParams& params) |
{ |
m_devToolsEmulator->enableDeviceEmulation(params); |
+ setScrollAndScaleOverride(params); |
} |
void WebViewImpl::disableDeviceEmulation() |
{ |
+ clearScrollAndScaleOverride(); |
m_devToolsEmulator->disableDeviceEmulation(); |
} |