1 | /* |
2 | * Copyright (C) 2014 Apple Inc. All rights reserved. |
3 | * |
4 | * Redistribution and use in source and binary forms, with or without |
5 | * modification, are permitted provided that the following conditions |
6 | * are met: |
7 | * 1. Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. |
9 | * 2. Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. |
12 | * |
13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' |
14 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
15 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
17 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
18 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
19 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
20 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
21 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
22 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
23 | * THE POSSIBILITY OF SUCH DAMAGE. |
24 | */ |
25 | |
26 | #pragma once |
27 | |
28 | #include <WebCore/FloatRect.h> |
29 | #include <WebCore/LengthBox.h> |
30 | #include <WebCore/VelocityData.h> |
31 | #include <wtf/MonotonicTime.h> |
32 | #include <wtf/text/WTFString.h> |
33 | |
34 | namespace IPC { |
35 | class Decoder; |
36 | class Encoder; |
37 | } |
38 | |
39 | namespace WTF { |
40 | class TextStream; |
41 | } |
42 | |
43 | namespace WebKit { |
44 | |
45 | class VisibleContentRectUpdateInfo { |
46 | public: |
47 | VisibleContentRectUpdateInfo() = default; |
48 | |
49 | VisibleContentRectUpdateInfo(const WebCore::FloatRect& exposedContentRect, const WebCore::FloatRect& unobscuredContentRect, const WebCore::FloatBoxExtent& contentInsets, const WebCore::FloatRect& unobscuredRectInScrollViewCoordinates, const WebCore::FloatRect& unobscuredContentRectRespectingInputViewBounds, const WebCore::FloatRect& customFixedPositionRect, const WebCore::FloatBoxExtent& obscuredInsets, const WebCore::FloatBoxExtent& unobscuredSafeAreaInsets, double scale, bool inStableState, bool isFirstUpdateForNewViewSize, bool isChangingObscuredInsetsInteractively, bool allowShrinkToFit, bool enclosedInScrollableAncestorView, const WebCore::VelocityData& scrollVelocity, uint64_t lastLayerTreeTransactionId) |
50 | : m_exposedContentRect(exposedContentRect) |
51 | , m_unobscuredContentRect(unobscuredContentRect) |
52 | , m_contentInsets(contentInsets) |
53 | , m_unobscuredContentRectRespectingInputViewBounds(unobscuredContentRectRespectingInputViewBounds) |
54 | , m_unobscuredRectInScrollViewCoordinates(unobscuredRectInScrollViewCoordinates) |
55 | , m_customFixedPositionRect(customFixedPositionRect) |
56 | , m_obscuredInsets(obscuredInsets) |
57 | , m_unobscuredSafeAreaInsets(unobscuredSafeAreaInsets) |
58 | , m_scrollVelocity(scrollVelocity) |
59 | , m_lastLayerTreeTransactionID(lastLayerTreeTransactionId) |
60 | , m_scale(scale) |
61 | , m_inStableState(inStableState) |
62 | , m_isFirstUpdateForNewViewSize(isFirstUpdateForNewViewSize) |
63 | , m_isChangingObscuredInsetsInteractively(isChangingObscuredInsetsInteractively) |
64 | , m_allowShrinkToFit(allowShrinkToFit) |
65 | , m_enclosedInScrollableAncestorView(enclosedInScrollableAncestorView) |
66 | { |
67 | } |
68 | |
69 | const WebCore::FloatRect& exposedContentRect() const { return m_exposedContentRect; } |
70 | const WebCore::FloatRect& unobscuredContentRect() const { return m_unobscuredContentRect; } |
71 | const WebCore::FloatBoxExtent& contentInsets() const { return m_contentInsets; } |
72 | const WebCore::FloatRect& unobscuredRectInScrollViewCoordinates() const { return m_unobscuredRectInScrollViewCoordinates; } |
73 | const WebCore::FloatRect& unobscuredContentRectRespectingInputViewBounds() const { return m_unobscuredContentRectRespectingInputViewBounds; } |
74 | const WebCore::FloatRect& customFixedPositionRect() const { return m_customFixedPositionRect; } |
75 | const WebCore::VelocityData& scrollVelocity() const { return m_scrollVelocity; } |
76 | const WebCore::FloatBoxExtent& obscuredInsets() const { return m_obscuredInsets; } |
77 | const WebCore::FloatBoxExtent& unobscuredSafeAreaInsets() const { return m_unobscuredSafeAreaInsets; } |
78 | |
79 | double scale() const { return m_scale; } |
80 | bool inStableState() const { return m_inStableState; } |
81 | bool isFirstUpdateForNewViewSize() const { return m_isFirstUpdateForNewViewSize; } |
82 | bool isChangingObscuredInsetsInteractively() const { return m_isChangingObscuredInsetsInteractively; } |
83 | bool allowShrinkToFit() const { return m_allowShrinkToFit; } |
84 | bool enclosedInScrollableAncestorView() const { return m_enclosedInScrollableAncestorView; } |
85 | uint64_t lastLayerTreeTransactionID() const { return m_lastLayerTreeTransactionID; } |
86 | |
87 | MonotonicTime timestamp() const { return m_scrollVelocity.lastUpdateTime; } |
88 | |
89 | void encode(IPC::Encoder&) const; |
90 | static bool decode(IPC::Decoder&, VisibleContentRectUpdateInfo&); |
91 | |
92 | String dump() const; |
93 | |
94 | private: |
95 | WebCore::FloatRect m_exposedContentRect; |
96 | WebCore::FloatRect m_unobscuredContentRect; |
97 | WebCore::FloatBoxExtent m_contentInsets; |
98 | WebCore::FloatRect m_unobscuredContentRectRespectingInputViewBounds; |
99 | WebCore::FloatRect m_unobscuredRectInScrollViewCoordinates; |
100 | WebCore::FloatRect m_customFixedPositionRect; // When visual viewports are enabled, this is the layout viewport. |
101 | WebCore::FloatBoxExtent m_obscuredInsets; |
102 | WebCore::FloatBoxExtent m_unobscuredSafeAreaInsets; |
103 | WebCore::VelocityData m_scrollVelocity; |
104 | uint64_t m_lastLayerTreeTransactionID { 0 }; |
105 | double m_scale { -1 }; |
106 | bool m_inStableState { false }; |
107 | bool m_isFirstUpdateForNewViewSize { false }; |
108 | bool m_isChangingObscuredInsetsInteractively { false }; |
109 | bool m_allowShrinkToFit { false }; |
110 | bool m_enclosedInScrollableAncestorView { false }; |
111 | }; |
112 | |
113 | inline bool operator==(const VisibleContentRectUpdateInfo& a, const VisibleContentRectUpdateInfo& b) |
114 | { |
115 | // Note: the comparison doesn't include timestamp and velocity since we care about equality based on the other data. |
116 | return a.scale() == b.scale() |
117 | && a.exposedContentRect() == b.exposedContentRect() |
118 | && a.unobscuredContentRect() == b.unobscuredContentRect() |
119 | && a.contentInsets() == b.contentInsets() |
120 | && a.unobscuredContentRectRespectingInputViewBounds() == b.unobscuredContentRectRespectingInputViewBounds() |
121 | && a.customFixedPositionRect() == b.customFixedPositionRect() |
122 | && a.obscuredInsets() == b.obscuredInsets() |
123 | && a.unobscuredSafeAreaInsets() == b.unobscuredSafeAreaInsets() |
124 | && a.scrollVelocity().equalIgnoringTimestamp(b.scrollVelocity()) |
125 | && a.inStableState() == b.inStableState() |
126 | && a.isFirstUpdateForNewViewSize() == b.isFirstUpdateForNewViewSize() |
127 | && a.allowShrinkToFit() == b.allowShrinkToFit() |
128 | && a.enclosedInScrollableAncestorView() == b.enclosedInScrollableAncestorView(); |
129 | } |
130 | |
131 | WTF::TextStream& operator<<(WTF::TextStream&, const VisibleContentRectUpdateInfo&); |
132 | |
133 | } // namespace WebKit |
134 | |