1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_gfx_layers_ScrollbarData_h
#define mozilla_gfx_layers_ScrollbarData_h
#include "FrameMetrics.h"
#include "mozilla/Maybe.h"
#include "mozilla/gfx/Types.h"
#include "mozilla/layers/LayersTypes.h"
#include "mozilla/layers/ScrollableLayerGuid.h"
namespace IPC {
template <typename T>
struct ParamTraits;
} // namespace IPC
namespace mozilla {
namespace layers {
// clang-format off
MOZ_DEFINE_ENUM_CLASS_WITH_BASE(ScrollbarLayerType, uint8_t, (
None,
Thumb,
Container
));
// clang-format on
/**
* It stores data for scroll thumb layer or container layers.
*/
struct ScrollbarData {
private:
/**
* This constructor is for Thumb layer type.
*/
ScrollbarData(ScrollDirection aDirection, float aThumbRatio,
CSSCoord aThumbStart, CSSCoord aThumbLength,
bool aThumbIsAsyncDraggable, CSSCoord aScrollTrackStart,
CSSCoord aScrollTrackLength, uint64_t aTargetViewId)
: mDirection(Some(aDirection)),
mScrollbarLayerType(ScrollbarLayerType::Thumb),
mThumbRatio(aThumbRatio),
mThumbStart(aThumbStart),
mThumbLength(aThumbLength),
mThumbIsAsyncDraggable(aThumbIsAsyncDraggable),
mScrollTrackStart(aScrollTrackStart),
mScrollTrackLength(aScrollTrackLength),
mTargetViewId(aTargetViewId) {}
/**
* This constructor is for Container layer type.
*/
ScrollbarData(const Maybe<ScrollDirection>& aDirection,
uint64_t aTargetViewId)
: mDirection(aDirection),
mScrollbarLayerType(ScrollbarLayerType::Container),
mTargetViewId(aTargetViewId) {}
public:
ScrollbarData() = default;
static ScrollbarData CreateForThumb(ScrollDirection aDirection,
float aThumbRatio, CSSCoord aThumbStart,
CSSCoord aThumbLength,
bool aThumbIsAsyncDraggable,
CSSCoord aScrollTrackStart,
CSSCoord aScrollTrackLength,
uint64_t aTargetViewId) {
return ScrollbarData(aDirection, aThumbRatio, aThumbStart, aThumbLength,
aThumbIsAsyncDraggable, aScrollTrackStart,
aScrollTrackLength, aTargetViewId);
}
static ScrollbarData CreateForScrollbarContainer(
const Maybe<ScrollDirection>& aDirection, uint64_t aTargetViewId) {
return ScrollbarData(aDirection, aTargetViewId);
}
/**
* The mDirection contains a direction if mScrollbarLayerType is Thumb
* or Container, otherwise it's empty.
*/
Maybe<ScrollDirection> mDirection;
/**
* Indicate what kind of layer this data is for. All possibilities are defined
* in enum ScrollbarLayerType
*/
ScrollbarLayerType mScrollbarLayerType = ScrollbarLayerType::None;
/**
* The scrollbar thumb ratio is the ratio of the thumb position (in the CSS
* pixels of the scrollframe's parent's space) to the scroll position (in the
* CSS pixels of the scrollframe's space).
*/
float mThumbRatio = 0.0f;
CSSCoord mThumbStart;
CSSCoord mThumbLength;
/**
* Whether the scrollbar thumb can be dragged asynchronously.
*/
bool mThumbIsAsyncDraggable = false;
CSSCoord mScrollTrackStart;
CSSCoord mScrollTrackLength;
uint64_t mTargetViewId = ScrollableLayerGuid::NULL_SCROLL_ID;
bool operator==(const ScrollbarData& aOther) const {
return mDirection == aOther.mDirection &&
mScrollbarLayerType == aOther.mScrollbarLayerType &&
mThumbRatio == aOther.mThumbRatio &&
mThumbStart == aOther.mThumbStart &&
mThumbLength == aOther.mThumbLength &&
mThumbIsAsyncDraggable == aOther.mThumbIsAsyncDraggable &&
mScrollTrackStart == aOther.mScrollTrackStart &&
mScrollTrackLength == aOther.mScrollTrackLength &&
mTargetViewId == aOther.mTargetViewId;
}
bool operator!=(const ScrollbarData& aOther) const {
return !(*this == aOther);
}
bool IsThumb() const {
return mScrollbarLayerType == ScrollbarLayerType::Thumb;
}
};
} // namespace layers
} // namespace mozilla
#endif // mozilla_gfx_layers_ScrollbarData_h
|