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 <wtf/MonotonicTime.h>
31#include <wtf/text/WTFString.h>
32
33namespace IPC {
34class Decoder;
35class Encoder;
36}
37
38namespace WTF {
39class TextStream;
40}
41
42namespace WebKit {
43
44class VisibleContentRectUpdateInfo {
45public:
46 VisibleContentRectUpdateInfo() = default;
47
48 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, MonotonicTime timestamp, double horizontalVelocity, double verticalVelocity, double scaleChangeRate, uint64_t lastLayerTreeTransactionId)
49 : m_exposedContentRect(exposedContentRect)
50 , m_unobscuredContentRect(unobscuredContentRect)
51 , m_contentInsets(contentInsets)
52 , m_unobscuredContentRectRespectingInputViewBounds(unobscuredContentRectRespectingInputViewBounds)
53 , m_unobscuredRectInScrollViewCoordinates(unobscuredRectInScrollViewCoordinates)
54 , m_customFixedPositionRect(customFixedPositionRect)
55 , m_obscuredInsets(obscuredInsets)
56 , m_unobscuredSafeAreaInsets(unobscuredSafeAreaInsets)
57 , m_lastLayerTreeTransactionID(lastLayerTreeTransactionId)
58 , m_scale(scale)
59 , m_timestamp(timestamp)
60 , m_horizontalVelocity(horizontalVelocity)
61 , m_verticalVelocity(verticalVelocity)
62 , m_scaleChangeRate(scaleChangeRate)
63 , m_inStableState(inStableState)
64 , m_isFirstUpdateForNewViewSize(isFirstUpdateForNewViewSize)
65 , m_isChangingObscuredInsetsInteractively(isChangingObscuredInsetsInteractively)
66 , m_allowShrinkToFit(allowShrinkToFit)
67 , m_enclosedInScrollableAncestorView(enclosedInScrollableAncestorView)
68 {
69 }
70
71 const WebCore::FloatRect& exposedContentRect() const { return m_exposedContentRect; }
72 const WebCore::FloatRect& unobscuredContentRect() const { return m_unobscuredContentRect; }
73 const WebCore::FloatBoxExtent& contentInsets() const { return m_contentInsets; }
74 const WebCore::FloatRect& unobscuredRectInScrollViewCoordinates() const { return m_unobscuredRectInScrollViewCoordinates; }
75 const WebCore::FloatRect& unobscuredContentRectRespectingInputViewBounds() const { return m_unobscuredContentRectRespectingInputViewBounds; }
76 const WebCore::FloatRect& customFixedPositionRect() const { return m_customFixedPositionRect; }
77 const WebCore::FloatBoxExtent& obscuredInsets() const { return m_obscuredInsets; }
78 const WebCore::FloatBoxExtent& unobscuredSafeAreaInsets() const { return m_unobscuredSafeAreaInsets; }
79
80 double scale() const { return m_scale; }
81 bool inStableState() const { return m_inStableState; }
82 bool isFirstUpdateForNewViewSize() const { return m_isFirstUpdateForNewViewSize; }
83 bool isChangingObscuredInsetsInteractively() const { return m_isChangingObscuredInsetsInteractively; }
84 bool allowShrinkToFit() const { return m_allowShrinkToFit; }
85 bool enclosedInScrollableAncestorView() const { return m_enclosedInScrollableAncestorView; }
86
87 MonotonicTime timestamp() const { return m_timestamp; }
88 double horizontalVelocity() const { return m_horizontalVelocity; }
89 double verticalVelocity() const { return m_verticalVelocity; }
90 double scaleChangeRate() const { return m_scaleChangeRate; }
91
92 uint64_t lastLayerTreeTransactionID() const { return m_lastLayerTreeTransactionID; }
93
94 void encode(IPC::Encoder&) const;
95 static bool decode(IPC::Decoder&, VisibleContentRectUpdateInfo&);
96
97 String dump() const;
98
99private:
100 WebCore::FloatRect m_exposedContentRect;
101 WebCore::FloatRect m_unobscuredContentRect;
102 WebCore::FloatBoxExtent m_contentInsets;
103 WebCore::FloatRect m_unobscuredContentRectRespectingInputViewBounds;
104 WebCore::FloatRect m_unobscuredRectInScrollViewCoordinates;
105 WebCore::FloatRect m_customFixedPositionRect; // When visual viewports are enabled, this is the layout viewport.
106 WebCore::FloatBoxExtent m_obscuredInsets;
107 WebCore::FloatBoxExtent m_unobscuredSafeAreaInsets;
108 uint64_t m_lastLayerTreeTransactionID { 0 };
109 double m_scale { -1 };
110 MonotonicTime m_timestamp;
111 double m_horizontalVelocity { 0 };
112 double m_verticalVelocity { 0 };
113 double m_scaleChangeRate { 0 };
114 bool m_inStableState { false };
115 bool m_isFirstUpdateForNewViewSize { false };
116 bool m_isChangingObscuredInsetsInteractively { false };
117 bool m_allowShrinkToFit { false };
118 bool m_enclosedInScrollableAncestorView { false };
119};
120
121inline bool operator==(const VisibleContentRectUpdateInfo& a, const VisibleContentRectUpdateInfo& b)
122{
123 // Note: the comparison doesn't include timestamp and velocity since we care about equality based on the other data.
124 return a.scale() == b.scale()
125 && a.exposedContentRect() == b.exposedContentRect()
126 && a.unobscuredContentRect() == b.unobscuredContentRect()
127 && a.contentInsets() == b.contentInsets()
128 && a.unobscuredContentRectRespectingInputViewBounds() == b.unobscuredContentRectRespectingInputViewBounds()
129 && a.customFixedPositionRect() == b.customFixedPositionRect()
130 && a.obscuredInsets() == b.obscuredInsets()
131 && a.unobscuredSafeAreaInsets() == b.unobscuredSafeAreaInsets()
132 && a.horizontalVelocity() == b.horizontalVelocity()
133 && a.verticalVelocity() == b.verticalVelocity()
134 && a.scaleChangeRate() == b.scaleChangeRate()
135 && a.inStableState() == b.inStableState()
136 && a.isFirstUpdateForNewViewSize() == b.isFirstUpdateForNewViewSize()
137 && a.allowShrinkToFit() == b.allowShrinkToFit()
138 && a.enclosedInScrollableAncestorView() == b.enclosedInScrollableAncestorView();
139}
140
141WTF::TextStream& operator<<(WTF::TextStream&, const VisibleContentRectUpdateInfo&);
142
143} // namespace WebKit
144