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

Unified Diff: third_party/WebKit/Source/core/frame/ScrollAndScaleEmulator.h

Issue 2096633002: Adds scroll position/scale emulation to DevTools. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Sync, patch in 2169483002 (+ regression test), add DevTools tests. Created 4 years, 5 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/ScrollAndScaleEmulator.h
diff --git a/third_party/WebKit/Source/core/frame/ScrollAndScaleEmulator.h b/third_party/WebKit/Source/core/frame/ScrollAndScaleEmulator.h
new file mode 100644
index 0000000000000000000000000000000000000000..4c5d304800523aa79800b69c4ae7378d72495b33
--- /dev/null
+++ b/third_party/WebKit/Source/core/frame/ScrollAndScaleEmulator.h
@@ -0,0 +1,87 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef ScrollAndScaleEmulator_h
+#define ScrollAndScaleEmulator_h
+
+#include "core/CoreExport.h"
+#include "core/frame/PageScaleConstraints.h"
+#include "platform/geometry/DoublePoint.h"
+#include "platform/geometry/IntPoint.h"
+#include "platform/heap/Handle.h"
+#include "wtf/Noncopyable.h"
+#include "wtf/PassRefPtr.h"
+#include "wtf/RefCounted.h"
+
+namespace blink {
+
+class FrameHost;
+class IntSize;
+
+// Overrides the scroll positions of frame and visual viewport and the page
+// scale with fixed values.
+//
+// Scroll position overrides are enforced within VisualViewport and FrameView
+// by manipulating their minimum/maximum scroll positions. The override is then
+// applied when the scroll position is clamped to these min/max values.
+//
+// Similarly, the scale override is enforced through setting custom user-agent
+// PageScaleConstraints in WebViewImpl.
+class CORE_EXPORT ScrollAndScaleEmulator final : public GarbageCollected<ScrollAndScaleEmulator> {
+ WTF_MAKE_NONCOPYABLE(ScrollAndScaleEmulator);
+public:
+ // Create a new emulator instance. Also disables threaded scrolling for the
+ // frame's page while the override is in effect.
+ static ScrollAndScaleEmulator* create(FrameHost*);
+
+ DECLARE_TRACE();
+
+ // Enforce new override values, notify viewports about changes.
+ void update(const IntPoint& framePosition, const DoublePoint& visualViewportPosition, float pageScale);
+
+ // Clear overrides, notify viewports about changes. Also restores threaded
+ // scrolling settings and original user-agent PageScaleConstraints.
+ void clear();
+
+ // Return main frame scroll position with active overrides for individual
+ // coordinates applied.
+ IntPoint applyFramePositionOverride(const IntPoint&);
+
+ // Return visual viewport scroll position with active overrides for
+ // individual coordinates applied.
+ DoublePoint applyVisualViewportPositionOverride(const DoublePoint&);
+
+ // Calculate and return main frame size for original PageScaleConstraints.
+ IntSize mainFrameSize(const IntSize& webViewSize);
+
+private:
+ ScrollAndScaleEmulator(FrameHost*);
+
+ // Return PageScaleConstraints that enforce any active page scale override.
+ // Defaults to original constraints if no override is active.
+ PageScaleConstraints pageScaleConstraints();
+
+ void setThreadedScrollingEnabled(bool);
+
+ template <typename Point>
+ Point applyPositionOverride(const Point& position, const Point& override);
+
+ // Scroll position of frame. |x < 0| or |y < 0| disables the override for the respective coordinate.
+ IntPoint m_framePosition;
+
+ // Scroll position of visual viewport. |x < 0| or |y < 0| disables the override for the respective coordinate.
+ DoublePoint m_visualViewportPosition;
+
+ // Simulates visual viewport pinch zoom. |pageScale == 0| disables the override.
+ double m_pageScale;
+
+ Member<FrameHost> m_frameHost;
+
+ bool m_originalThreadedScrollingEnabled;
+ PageScaleConstraints m_originalPageScaleConstraints;
+};
+
+} // namespace blink
+
+#endif // ScrollAndScaleEmulator_h

Powered by Google App Engine
This is Rietveld 408576698