OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef ScrollAndScaleEmulator_h |
| 6 #define ScrollAndScaleEmulator_h |
| 7 |
| 8 #include "core/CoreExport.h" |
| 9 #include "core/frame/PageScaleConstraints.h" |
| 10 #include "platform/geometry/DoublePoint.h" |
| 11 #include "platform/geometry/IntPoint.h" |
| 12 #include "platform/heap/Handle.h" |
| 13 #include "wtf/Noncopyable.h" |
| 14 #include "wtf/PassRefPtr.h" |
| 15 #include "wtf/RefCounted.h" |
| 16 |
| 17 namespace blink { |
| 18 |
| 19 class FrameHost; |
| 20 class IntSize; |
| 21 |
| 22 // Overrides the scroll positions of frame and visual viewport and the page |
| 23 // scale with fixed values. |
| 24 // |
| 25 // Scroll position overrides are enforced within VisualViewport and FrameView |
| 26 // by manipulating their minimum/maximum scroll positions. The override is then |
| 27 // applied when the scroll position is clamped to these min/max values. |
| 28 // |
| 29 // Similarly, the scale override is enforced through setting custom user-agent |
| 30 // PageScaleConstraints in WebViewImpl. |
| 31 class CORE_EXPORT ScrollAndScaleEmulator final : public GarbageCollected<ScrollA
ndScaleEmulator> { |
| 32 WTF_MAKE_NONCOPYABLE(ScrollAndScaleEmulator); |
| 33 public: |
| 34 // Create a new emulator instance. Also disables threaded scrolling for the |
| 35 // frame's page while the override is in effect. |
| 36 static ScrollAndScaleEmulator* create(FrameHost*); |
| 37 |
| 38 DECLARE_TRACE(); |
| 39 |
| 40 // Enforce new override values, notify viewports about changes. |
| 41 void update(const IntPoint& framePosition, const DoublePoint& visualViewport
Position, float pageScale); |
| 42 |
| 43 // Clear overrides, notify viewports about changes. Also restores threaded |
| 44 // scrolling settings and original user-agent PageScaleConstraints. |
| 45 void clear(); |
| 46 |
| 47 // Return main frame scroll position with active overrides for individual |
| 48 // coordinates applied. |
| 49 IntPoint applyFramePositionOverride(const IntPoint&); |
| 50 |
| 51 // Return visual viewport scroll position with active overrides for |
| 52 // individual coordinates applied. |
| 53 DoublePoint applyVisualViewportPositionOverride(const DoublePoint&); |
| 54 |
| 55 // Calculate and return main frame size for original PageScaleConstraints. |
| 56 IntSize mainFrameSize(const IntSize& webViewSize); |
| 57 |
| 58 private: |
| 59 ScrollAndScaleEmulator(FrameHost*); |
| 60 |
| 61 // Return PageScaleConstraints that enforce any active page scale override. |
| 62 // Defaults to original constraints if no override is active. |
| 63 PageScaleConstraints pageScaleConstraints(); |
| 64 |
| 65 void setThreadedScrollingEnabled(bool); |
| 66 |
| 67 template <typename Point> |
| 68 Point applyPositionOverride(const Point& position, const Point& override); |
| 69 |
| 70 // Scroll position of frame. |x < 0| or |y < 0| disables the override for th
e respective coordinate. |
| 71 IntPoint m_framePosition; |
| 72 |
| 73 // Scroll position of visual viewport. |x < 0| or |y < 0| disables the overr
ide for the respective coordinate. |
| 74 DoublePoint m_visualViewportPosition; |
| 75 |
| 76 // Simulates visual viewport pinch zoom. |pageScale == 0| disables the overr
ide. |
| 77 double m_pageScale; |
| 78 |
| 79 Member<FrameHost> m_frameHost; |
| 80 |
| 81 bool m_originalThreadedScrollingEnabled; |
| 82 PageScaleConstraints m_originalPageScaleConstraints; |
| 83 }; |
| 84 |
| 85 } // namespace blink |
| 86 |
| 87 #endif // ScrollAndScaleEmulator_h |
OLD | NEW |