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/. */
7 #ifndef mozilla_gfx_layers_ScrollbarData_h
8 #define mozilla_gfx_layers_ScrollbarData_h
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"
25 MOZ_DEFINE_ENUM_CLASS_WITH_BASE(ScrollbarLayerType
, uint8_t, (
33 * It stores data for scroll thumb layer or container layers.
35 struct ScrollbarData
{
38 * This constructor is for Thumb layer type.
40 ScrollbarData(ScrollDirection aDirection
, float aThumbRatio
,
41 OuterCSSCoord aThumbStart
, OuterCSSCoord aThumbLength
,
42 OuterCSSCoord aThumbMinLength
, bool aThumbIsAsyncDraggable
,
43 OuterCSSCoord aScrollTrackStart
,
44 OuterCSSCoord aScrollTrackLength
, uint64_t aTargetViewId
)
45 : mDirection(Some(aDirection
)),
46 mScrollbarLayerType(ScrollbarLayerType::Thumb
),
47 mThumbRatio(aThumbRatio
),
48 mThumbStart(aThumbStart
),
49 mThumbLength(aThumbLength
),
50 mThumbMinLength(aThumbMinLength
),
51 mThumbIsAsyncDraggable(aThumbIsAsyncDraggable
),
52 mScrollTrackStart(aScrollTrackStart
),
53 mScrollTrackLength(aScrollTrackLength
),
54 mTargetViewId(aTargetViewId
) {}
57 * This constructor is for Container layer type.
59 ScrollbarData(const Maybe
<ScrollDirection
>& aDirection
,
60 uint64_t aTargetViewId
)
61 : mDirection(aDirection
),
62 mScrollbarLayerType(ScrollbarLayerType::Container
),
63 mTargetViewId(aTargetViewId
) {}
66 ScrollbarData() = default;
68 static ScrollbarData
CreateForThumb(
69 ScrollDirection aDirection
, float aThumbRatio
, OuterCSSCoord aThumbStart
,
70 OuterCSSCoord aThumbLength
, OuterCSSCoord aThumbMinLength
,
71 bool aThumbIsAsyncDraggable
, OuterCSSCoord aScrollTrackStart
,
72 OuterCSSCoord aScrollTrackLength
, uint64_t aTargetViewId
) {
73 return ScrollbarData(aDirection
, aThumbRatio
, aThumbStart
, aThumbLength
,
74 aThumbMinLength
, aThumbIsAsyncDraggable
,
75 aScrollTrackStart
, aScrollTrackLength
, aTargetViewId
);
78 static ScrollbarData
CreateForScrollbarContainer(
79 const Maybe
<ScrollDirection
>& aDirection
, uint64_t aTargetViewId
) {
80 return ScrollbarData(aDirection
, aTargetViewId
);
84 * The mDirection contains a direction if mScrollbarLayerType is Thumb
85 * or Container, otherwise it's empty.
87 Maybe
<ScrollDirection
> mDirection
;
90 * Indicate what kind of layer this data is for. All possibilities are defined
91 * in enum ScrollbarLayerType
93 ScrollbarLayerType mScrollbarLayerType
= ScrollbarLayerType::None
;
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).
100 float mThumbRatio
= 0.0f
;
102 OuterCSSCoord mThumbStart
;
103 OuterCSSCoord mThumbLength
;
104 OuterCSSCoord mThumbMinLength
;
107 * Whether the scrollbar thumb can be dragged asynchronously.
109 bool mThumbIsAsyncDraggable
= false;
111 OuterCSSCoord mScrollTrackStart
;
112 OuterCSSCoord mScrollTrackLength
;
113 uint64_t mTargetViewId
= ScrollableLayerGuid::NULL_SCROLL_ID
;
115 bool operator==(const ScrollbarData
& aOther
) const {
116 return mDirection
== aOther
.mDirection
&&
117 mScrollbarLayerType
== aOther
.mScrollbarLayerType
&&
118 mThumbRatio
== aOther
.mThumbRatio
&&
119 mThumbStart
== aOther
.mThumbStart
&&
120 mThumbLength
== aOther
.mThumbLength
&&
121 mThumbMinLength
== aOther
.mThumbMinLength
&&
122 mThumbIsAsyncDraggable
== aOther
.mThumbIsAsyncDraggable
&&
123 mScrollTrackStart
== aOther
.mScrollTrackStart
&&
124 mScrollTrackLength
== aOther
.mScrollTrackLength
&&
125 mTargetViewId
== aOther
.mTargetViewId
;
127 bool operator!=(const ScrollbarData
& aOther
) const {
128 return !(*this == aOther
);
131 bool IsThumb() const {
132 return mScrollbarLayerType
== ScrollbarLayerType::Thumb
;
136 } // namespace layers
137 } // namespace mozilla
139 #endif // mozilla_gfx_layers_ScrollbarData_h