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

Unified Diff: third_party/WebKit/Source/web/WebViewImpl.cpp

Issue 2096633002: Adds scroll position/scale emulation to DevTools. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Sync changes from patches 2111203004 + 2118773002. Created 4 years, 6 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/web/WebViewImpl.cpp
diff --git a/third_party/WebKit/Source/web/WebViewImpl.cpp b/third_party/WebKit/Source/web/WebViewImpl.cpp
index 3e92e32a2f867341300bb60c550f5729a13a1c55..223cd590395ca5442e8b0b2b76a7b764a080d6f0 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"
@@ -3208,6 +3209,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());
bokan 2016/07/01 21:05:12 Give the ScrollAndScaleEmulator a ref to the frame
Eric Seckler 2016/07/04 14:33:08 Done. At the moment, I don't keep a reference to t
bokan 2016/07/04 22:44:08 I would actually move the ScrollAndScaleEmulator o
+ }
+}
+
+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());
bokan 2016/07/01 21:05:12 This will clear existing UA constraints. You shoul
Eric Seckler 2016/07/04 14:33:08 Done.
+
+ // TODO(eseckler): For some reason, we seem to need this enforce the cleared
+ // constraints. Adding it in setScrollAndScaleOverride() makes the override
+ // ineffective, though.
bokan 2016/07/01 21:05:13 I think you it doesn't work in the setter because
Eric Seckler 2016/07/04 14:33:08 What I'm seeing is that the scale factor is not re
bokan 2016/07/04 22:44:08 Thanks for tracking it down. See my reply in DevTo
+ page()->frameHost().pageScaleConstraintsSet().computeFinalConstraints();
+
+ m_scrollAndScaleEmulator.clear();
+ resetScrollAndScaleState();
+}
+
void WebViewImpl::scrollAndRescaleViewports(float scaleFactor,
const IntPoint& mainFrameOrigin,
const FloatPoint& visualViewportOrigin)
@@ -3342,10 +3395,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());
bokan 2016/07/01 21:05:13 I'd add a method to the scrollAndScaleEmulator tha
Eric Seckler 2016/07/04 14:33:08 Done.
+ pageScaleConstraintsSet().computeFinalConstraints();
+ }
frameSize.scale(1 / minimumPageScaleFactor());
+ if (m_scrollAndScaleEmulator) {
+ pageScaleConstraintsSet().setUserAgentConstraints(m_scrollAndScaleEmulator->pageScaleConstraints());
+ pageScaleConstraintsSet().computeFinalConstraints();
+ }
+
return expandedIntSize(frameSize);
}
@@ -3834,10 +3899,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();
}

Powered by Google App Engine
This is Rietveld 408576698