Line data Source code
1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* This Source Code Form is subject to the terms of the Mozilla Public
3 : * License, v. 2.0. If a copy of the MPL was not distributed with this
4 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 :
6 : #ifndef ScrollbarStyles_h
7 : #define ScrollbarStyles_h
8 :
9 : #include <stdint.h>
10 : #include "nsStyleConsts.h" // for NS_STYLE_SCROLL_SNAP_*
11 : #include "nsStyleCoord.h" // for nsStyleCoord
12 : #include "mozilla/dom/WindowBinding.h"
13 :
14 : // Forward declarations
15 : struct nsStyleDisplay;
16 :
17 : namespace mozilla {
18 :
19 1596 : struct ScrollbarStyles
20 : {
21 : // Always one of NS_STYLE_OVERFLOW_SCROLL, NS_STYLE_OVERFLOW_HIDDEN,
22 : // or NS_STYLE_OVERFLOW_AUTO.
23 : uint8_t mHorizontal;
24 : uint8_t mVertical;
25 : // Always one of NS_STYLE_SCROLL_BEHAVIOR_AUTO or
26 : // NS_STYLE_SCROLL_BEHAVIOR_SMOOTH
27 : uint8_t mScrollBehavior;
28 : // Always one of NS_STYLE_SCROLL_SNAP_NONE, NS_STYLE_SCROLL_SNAP_MANDATORY,
29 : // or NS_STYLE_SCROLL_SNAP_PROXIMITY.
30 : uint8_t mScrollSnapTypeX;
31 : uint8_t mScrollSnapTypeY;
32 : nsStyleCoord mScrollSnapPointsX;
33 : nsStyleCoord mScrollSnapPointsY;
34 : nsStyleCoord::CalcValue mScrollSnapDestinationX;
35 : nsStyleCoord::CalcValue mScrollSnapDestinationY;
36 :
37 54 : ScrollbarStyles(uint8_t aH, uint8_t aV)
38 54 : : mHorizontal(aH), mVertical(aV),
39 : mScrollBehavior(NS_STYLE_SCROLL_BEHAVIOR_AUTO),
40 : mScrollSnapTypeX(NS_STYLE_SCROLL_SNAP_TYPE_NONE),
41 : mScrollSnapTypeY(NS_STYLE_SCROLL_SNAP_TYPE_NONE),
42 : mScrollSnapPointsX(nsStyleCoord(eStyleUnit_None)),
43 54 : mScrollSnapPointsY(nsStyleCoord(eStyleUnit_None)) {
44 :
45 54 : mScrollSnapDestinationX.mPercent = 0;
46 54 : mScrollSnapDestinationX.mLength = nscoord(0.0f);
47 54 : mScrollSnapDestinationX.mHasPercent = false;
48 54 : mScrollSnapDestinationY.mPercent = 0;
49 54 : mScrollSnapDestinationY.mLength = nscoord(0.0f);
50 54 : mScrollSnapDestinationY.mHasPercent = false;
51 54 : }
52 :
53 : explicit ScrollbarStyles(const nsStyleDisplay* aDisplay);
54 : ScrollbarStyles(uint8_t aH, uint8_t aV, const nsStyleDisplay* aDisplay);
55 : bool operator==(const ScrollbarStyles& aStyles) const {
56 : return aStyles.mHorizontal == mHorizontal && aStyles.mVertical == mVertical &&
57 : aStyles.mScrollBehavior == mScrollBehavior &&
58 : aStyles.mScrollSnapTypeX == mScrollSnapTypeX &&
59 : aStyles.mScrollSnapTypeY == mScrollSnapTypeY &&
60 : aStyles.mScrollSnapPointsX == mScrollSnapPointsX &&
61 : aStyles.mScrollSnapPointsY == mScrollSnapPointsY &&
62 : aStyles.mScrollSnapDestinationX == mScrollSnapDestinationX &&
63 : aStyles.mScrollSnapDestinationY == mScrollSnapDestinationY;
64 : }
65 : bool operator!=(const ScrollbarStyles& aStyles) const {
66 : return !(*this == aStyles);
67 : }
68 0 : bool IsHiddenInBothDirections() const {
69 0 : return mHorizontal == NS_STYLE_OVERFLOW_HIDDEN &&
70 0 : mVertical == NS_STYLE_OVERFLOW_HIDDEN;
71 : }
72 0 : bool IsSmoothScroll(dom::ScrollBehavior aBehavior) const {
73 0 : return aBehavior == dom::ScrollBehavior::Smooth ||
74 0 : (aBehavior == dom::ScrollBehavior::Auto &&
75 0 : mScrollBehavior == NS_STYLE_SCROLL_BEHAVIOR_SMOOTH);
76 : }
77 : };
78 :
79 : } // namespace mozilla
80 :
81 : #endif
|