ScrollbarData.h (4672B)
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_ScrollbarData_h 8 #define mozilla_gfx_layers_ScrollbarData_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 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) {} 55 56 /** 57 * This constructor is for Container layer type. 58 */ 59 ScrollbarData(const Maybe<ScrollDirection>& aDirection, 60 uint64_t aTargetViewId) 61 : mDirection(aDirection), 62 mScrollbarLayerType(ScrollbarLayerType::Container), 63 mTargetViewId(aTargetViewId) {} 64 65 public: 66 ScrollbarData() = default; 67 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); 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 OuterCSSCoord mThumbStart; 103 OuterCSSCoord mThumbLength; 104 OuterCSSCoord mThumbMinLength; 105 106 /** 107 * Whether the scrollbar thumb can be dragged asynchronously. 108 */ 109 bool mThumbIsAsyncDraggable = false; 110 111 OuterCSSCoord mScrollTrackStart; 112 OuterCSSCoord mScrollTrackLength; 113 uint64_t mTargetViewId = ScrollableLayerGuid::NULL_SCROLL_ID; 114 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; 126 } 127 bool operator!=(const ScrollbarData& aOther) const { 128 return !(*this == aOther); 129 } 130 131 bool IsThumb() const { 132 return mScrollbarLayerType == ScrollbarLayerType::Thumb; 133 } 134 }; 135 136 } // namespace layers 137 } // namespace mozilla 138 139 #endif // mozilla_gfx_layers_ScrollbarData_h