Source code

Revision control

Other Tools

1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
3
/* This Source Code Form is subject to the terms of the Mozilla Public
4
* License, v. 2.0. If a copy of the MPL was not distributed with this
5
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#ifndef mozilla_gfx_layers_LayerAttributes_h
8
#define mozilla_gfx_layers_LayerAttributes_h
9
10
#include "FrameMetrics.h"
11
#include "mozilla/Maybe.h"
12
#include "mozilla/gfx/Types.h"
13
#include "mozilla/layers/LayersTypes.h"
14
#include "mozilla/layers/ScrollableLayerGuid.h"
15
16
namespace IPC {
17
template <typename T>
18
struct ParamTraits;
19
} // namespace IPC
20
21
namespace mozilla {
22
namespace layers {
23
24
// clang-format off
25
MOZ_DEFINE_ENUM_CLASS_WITH_BASE(ScrollbarLayerType, uint8_t, (
26
None,
27
Thumb,
28
Container
29
));
30
// clang-format on
31
32
/**
33
* It stores data for scroll thumb layer or container layers.
34
*/
35
struct ScrollbarData {
36
private:
37
/**
38
* This constructor is for Thumb layer type.
39
*/
40
ScrollbarData(ScrollDirection aDirection, float aThumbRatio,
41
CSSCoord aThumbStart, CSSCoord aThumbLength,
42
bool aThumbIsAsyncDraggable, CSSCoord aScrollTrackStart,
43
CSSCoord aScrollTrackLength, uint64_t aTargetViewId)
44
: mDirection(Some(aDirection)),
45
mScrollbarLayerType(ScrollbarLayerType::Thumb),
46
mThumbRatio(aThumbRatio),
47
mThumbStart(aThumbStart),
48
mThumbLength(aThumbLength),
49
mThumbIsAsyncDraggable(aThumbIsAsyncDraggable),
50
mScrollTrackStart(aScrollTrackStart),
51
mScrollTrackLength(aScrollTrackLength),
52
mTargetViewId(aTargetViewId) {}
53
54
/**
55
* This constructor is for Container layer type.
56
*/
57
ScrollbarData(const Maybe<ScrollDirection>& aDirection,
58
uint64_t aTargetViewId)
59
: mDirection(aDirection),
60
mScrollbarLayerType(ScrollbarLayerType::Container),
61
mTargetViewId(aTargetViewId) {}
62
63
public:
64
ScrollbarData() = default;
65
66
static ScrollbarData CreateForThumb(ScrollDirection aDirection,
67
float aThumbRatio, CSSCoord aThumbStart,
68
CSSCoord aThumbLength,
69
bool aThumbIsAsyncDraggable,
70
CSSCoord aScrollTrackStart,
71
CSSCoord aScrollTrackLength,
72
uint64_t aTargetViewId) {
73
return ScrollbarData(aDirection, aThumbRatio, aThumbStart, aThumbLength,
74
aThumbIsAsyncDraggable, aScrollTrackStart,
75
aScrollTrackLength, aTargetViewId);
76
}
77
78
static ScrollbarData CreateForScrollbarContainer(
79
const Maybe<ScrollDirection>& aDirection, uint64_t aTargetViewId) {
80
return ScrollbarData(aDirection, aTargetViewId);
81
}
82
83
/**
84
* The mDirection contains a direction if mScrollbarLayerType is Thumb
85
* or Container, otherwise it's empty.
86
*/
87
Maybe<ScrollDirection> mDirection;
88
89
/**
90
* Indicate what kind of layer this data is for. All possibilities are defined
91
* in enum ScrollbarLayerType
92
*/
93
ScrollbarLayerType mScrollbarLayerType = ScrollbarLayerType::None;
94
95
/**
96
* The scrollbar thumb ratio is the ratio of the thumb position (in the CSS
97
* pixels of the scrollframe's parent's space) to the scroll position (in the
98
* CSS pixels of the scrollframe's space).
99
*/
100
float mThumbRatio = 0.0f;
101
102
CSSCoord mThumbStart;
103
CSSCoord mThumbLength;
104
105
/**
106
* Whether the scrollbar thumb can be dragged asynchronously.
107
*/
108
bool mThumbIsAsyncDraggable = false;
109
110
CSSCoord mScrollTrackStart;
111
CSSCoord mScrollTrackLength;
112
uint64_t mTargetViewId = ScrollableLayerGuid::NULL_SCROLL_ID;
113
114
bool operator==(const ScrollbarData& aOther) const {
115
return mDirection == aOther.mDirection &&
116
mScrollbarLayerType == aOther.mScrollbarLayerType &&
117
mThumbRatio == aOther.mThumbRatio &&
118
mThumbStart == aOther.mThumbStart &&
119
mThumbLength == aOther.mThumbLength &&
120
mThumbIsAsyncDraggable == aOther.mThumbIsAsyncDraggable &&
121
mScrollTrackStart == aOther.mScrollTrackStart &&
122
mScrollTrackLength == aOther.mScrollTrackLength &&
123
mTargetViewId == aOther.mTargetViewId;
124
}
125
bool operator!=(const ScrollbarData& aOther) const {
126
return !(*this == aOther);
127
}
128
129
bool IsThumb() const {
130
return mScrollbarLayerType == ScrollbarLayerType::Thumb;
131
}
132
};
133
134
/**
135
* Infrequently changing layer attributes.
136
*/
137
class SimpleLayerAttributes final {
138
friend struct IPC::ParamTraits<mozilla::layers::SimpleLayerAttributes>;
139
140
public:
141
SimpleLayerAttributes()
142
: mTransformIsPerspective(false),
143
mPostXScale(1.0f),
144
mPostYScale(1.0f),
145
mContentFlags(0),
146
mOpacity(1.0f),
147
mIsFixedPosition(false),
148
mMixBlendMode(gfx::CompositionOp::OP_OVER),
149
mForceIsolatedGroup(false) {}
150
151
/**
152
* Setters.
153
* All set methods return true if values changed, false otherwise.
154
*/
155
156
bool SetPostScale(float aXScale, float aYScale) {
157
if (mPostXScale == aXScale && mPostYScale == aYScale) {
158
return false;
159
}
160
mPostXScale = aXScale;
161
mPostYScale = aYScale;
162
return true;
163
}
164
165
bool SetContentFlags(uint32_t aFlags) {
166
if (aFlags == mContentFlags) {
167
return false;
168
}
169
mContentFlags = aFlags;
170
return true;
171
}
172
173
bool SetOpacity(float aOpacity) {
174
if (aOpacity == mOpacity) {
175
return false;
176
}
177
mOpacity = aOpacity;
178
return true;
179
}
180
181
bool SetIsFixedPosition(bool aFixedPosition) {
182
if (mIsFixedPosition == aFixedPosition) {
183
return false;
184
}
185
mIsFixedPosition = aFixedPosition;
186
return true;
187
}
188
189
bool SetIsAsyncZoomContainer(const Maybe<FrameMetrics::ViewID>& aViewId) {
190
if (mIsAsyncZoomContainerForViewId == aViewId) {
191
return false;
192
}
193
mIsAsyncZoomContainerForViewId = aViewId;
194
return true;
195
}
196
197
bool SetScrollbarData(const ScrollbarData& aScrollbarData) {
198
if (mScrollbarData == aScrollbarData) {
199
return false;
200
}
201
mScrollbarData = aScrollbarData;
202
return true;
203
}
204
205
bool SetMixBlendMode(gfx::CompositionOp aMixBlendMode) {
206
if (mMixBlendMode == aMixBlendMode) {
207
return false;
208
}
209
mMixBlendMode = aMixBlendMode;
210
return true;
211
}
212
213
bool SetForceIsolatedGroup(bool aForceIsolatedGroup) {
214
if (mForceIsolatedGroup == aForceIsolatedGroup) {
215
return false;
216
}
217
mForceIsolatedGroup = aForceIsolatedGroup;
218
return true;
219
}
220
221
bool SetTransform(const gfx::Matrix4x4& aMatrix) {
222
if (mTransform == aMatrix) {
223
return false;
224
}
225
mTransform = aMatrix;
226
return true;
227
}
228
229
bool SetTransformIsPerspective(bool aIsPerspective) {
230
if (mTransformIsPerspective == aIsPerspective) {
231
return false;
232
}
233
mTransformIsPerspective = aIsPerspective;
234
return true;
235
}
236
237
bool SetScrolledClip(const Maybe<LayerClip>& aScrolledClip) {
238
if (mScrolledClip == aScrolledClip) {
239
return false;
240
}
241
mScrolledClip = aScrolledClip;
242
return true;
243
}
244
245
bool SetFixedPositionData(ScrollableLayerGuid::ViewID aTargetViewId,
246
const LayerPoint& aAnchor, SideBits aSides) {
247
if (mFixedPositionData && mFixedPositionData->mScrollId == aTargetViewId &&
248
mFixedPositionData->mAnchor == aAnchor &&
249
mFixedPositionData->mSides == aSides) {
250
return false;
251
}
252
if (!mFixedPositionData) {
253
mFixedPositionData.emplace();
254
}
255
mFixedPositionData->mScrollId = aTargetViewId;
256
mFixedPositionData->mAnchor = aAnchor;
257
mFixedPositionData->mSides = aSides;
258
return true;
259
}
260
261
bool SetStickyPositionData(ScrollableLayerGuid::ViewID aScrollId,
262
LayerRectAbsolute aOuter,
263
LayerRectAbsolute aInner) {
264
if (mStickyPositionData &&
265
mStickyPositionData->mOuter.IsEqualEdges(aOuter) &&
266
mStickyPositionData->mInner.IsEqualEdges(aInner)) {
267
return false;
268
}
269
if (!mStickyPositionData) {
270
mStickyPositionData.emplace();
271
}
272
mStickyPositionData->mScrollId = aScrollId;
273
mStickyPositionData->mOuter = aOuter;
274
mStickyPositionData->mInner = aInner;
275
return true;
276
}
277
278
/**
279
* This returns true if scrolling info is equivalent for the purposes of
280
* APZ hit testing.
281
*/
282
bool HitTestingInfoIsEqual(const SimpleLayerAttributes& aOther) const {
283
if (mScrollbarData != aOther.mScrollbarData) {
284
return false;
285
}
286
if (GetFixedPositionScrollContainerId() !=
287
aOther.GetFixedPositionScrollContainerId()) {
288
return false;
289
}
290
if (mTransform != aOther.mTransform) {
291
return false;
292
}
293
return true;
294
}
295
296
/**
297
* Getters.
298
*/
299
300
float GetPostXScale() const { return mPostXScale; }
301
302
float GetPostYScale() const { return mPostYScale; }
303
304
uint32_t GetContentFlags() const { return mContentFlags; }
305
306
float GetOpacity() const { return mOpacity; }
307
308
bool IsFixedPosition() const { return mIsFixedPosition; }
309
310
Maybe<FrameMetrics::ViewID> IsAsyncZoomContainer() const {
311
return mIsAsyncZoomContainerForViewId;
312
}
313
314
const ScrollbarData& GetScrollbarData() const { return mScrollbarData; }
315
316
gfx::CompositionOp GetMixBlendMode() const { return mMixBlendMode; }
317
318
bool GetForceIsolatedGroup() const { return mForceIsolatedGroup; }
319
320
const gfx::Matrix4x4& GetTransform() const { return mTransform; }
321
322
bool GetTransformIsPerspective() const { return mTransformIsPerspective; }
323
324
const Maybe<LayerClip>& GetScrolledClip() const { return mScrolledClip; }
325
326
ScrollableLayerGuid::ViewID GetFixedPositionScrollContainerId() const {
327
return (mIsFixedPosition && mFixedPositionData)
328
? mFixedPositionData->mScrollId
329
: ScrollableLayerGuid::NULL_SCROLL_ID;
330
}
331
332
LayerPoint GetFixedPositionAnchor() const {
333
return mFixedPositionData ? mFixedPositionData->mAnchor : LayerPoint();
334
}
335
336
SideBits GetFixedPositionSides() const {
337
return mFixedPositionData ? mFixedPositionData->mSides : SideBits::eNone;
338
}
339
340
bool IsStickyPosition() const { return !!mStickyPositionData; }
341
342
ScrollableLayerGuid::ViewID GetStickyScrollContainerId() const {
343
return mStickyPositionData->mScrollId;
344
}
345
346
const LayerRectAbsolute& GetStickyScrollRangeOuter() const {
347
return mStickyPositionData->mOuter;
348
}
349
350
const LayerRectAbsolute& GetStickyScrollRangeInner() const {
351
return mStickyPositionData->mInner;
352
}
353
354
bool operator==(const SimpleLayerAttributes& aOther) const {
355
return mTransform == aOther.mTransform &&
356
mTransformIsPerspective == aOther.mTransformIsPerspective &&
357
mScrolledClip == aOther.mScrolledClip &&
358
mPostXScale == aOther.mPostXScale &&
359
mPostYScale == aOther.mPostYScale &&
360
mContentFlags == aOther.mContentFlags &&
361
mOpacity == aOther.mOpacity &&
362
mIsFixedPosition == aOther.mIsFixedPosition &&
363
mIsAsyncZoomContainerForViewId ==
364
aOther.mIsAsyncZoomContainerForViewId &&
365
mScrollbarData == aOther.mScrollbarData &&
366
mMixBlendMode == aOther.mMixBlendMode &&
367
mForceIsolatedGroup == aOther.mForceIsolatedGroup;
368
}
369
370
private:
371
gfx::Matrix4x4 mTransform;
372
bool mTransformIsPerspective;
373
Maybe<LayerClip> mScrolledClip;
374
float mPostXScale;
375
float mPostYScale;
376
uint32_t mContentFlags;
377
float mOpacity;
378
bool mIsFixedPosition;
379
Maybe<FrameMetrics::ViewID> mIsAsyncZoomContainerForViewId;
380
ScrollbarData mScrollbarData;
381
gfx::CompositionOp mMixBlendMode;
382
bool mForceIsolatedGroup;
383
384
struct FixedPositionData {
385
ScrollableLayerGuid::ViewID mScrollId;
386
LayerPoint mAnchor;
387
SideBits mSides;
388
};
389
Maybe<FixedPositionData> mFixedPositionData;
390
friend struct IPC::ParamTraits<
391
mozilla::layers::SimpleLayerAttributes::FixedPositionData>;
392
393
struct StickyPositionData {
394
ScrollableLayerGuid::ViewID mScrollId;
395
LayerRectAbsolute mOuter;
396
LayerRectAbsolute mInner;
397
};
398
Maybe<StickyPositionData> mStickyPositionData;
399
friend struct IPC::ParamTraits<
400
mozilla::layers::SimpleLayerAttributes::StickyPositionData>;
401
402
// Make sure to add new members to operator== and the ParamTraits template
403
// instantiation.
404
};
405
406
} // namespace layers
407
} // namespace mozilla
408
409
#endif // mozilla_gfx_layers_LayerAttributes_h