ServoStyleConstsForwards.h (6945B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ 4 5 /* 6 * This file contains forward declarations and typedefs for types that cbindgen 7 * cannot understand but renames / prefixes, and includes for some of the types 8 * it needs. 9 */ 10 11 #ifndef mozilla_ServoStyleConsts_h 12 # error "This file is only meant to be included from ServoStyleConsts.h" 13 #endif 14 15 #ifndef mozilla_ServoStyleConstsForwards_h 16 # define mozilla_ServoStyleConstsForwards_h 17 18 # include <atomic> 19 20 # include "NonCustomCSSPropertyId.h" 21 # include "Units.h" 22 # include "mozilla/AtomArray.h" 23 # include "mozilla/CORSMode.h" 24 # include "mozilla/MemoryReporting.h" 25 # include "mozilla/ServoBindingTypes.h" 26 # include "mozilla/ServoTypes.h" 27 # include "mozilla/gfx/Types.h" 28 # include "mozilla/image/Resolution.h" 29 # include "nsColor.h" 30 # include "nsCompatibility.h" 31 # include "nsCoord.h" 32 # include "nsIURI.h" 33 34 struct RawServoAnimationValueTable; 35 36 class nsAtom; 37 class nsIFrame; 38 class nsINode; 39 class nsIContent; 40 class nsCSSPropertyIDSet; 41 class nsPresContext; 42 class nsSimpleContentList; 43 class imgRequestProxy; 44 struct nsCSSValueSharedList; 45 struct AnchorPosResolutionParams; 46 struct AnchorPosOffsetResolutionParams; 47 class gfxFontFeatureValueSet; 48 struct GeckoFontMetrics; 49 namespace mozilla { 50 51 // Forward declaration for `StyleLengthPercentageUnion::AsCalc`, which 52 // references the type below in the generated code. 53 struct StyleCalcLengthPercentage; 54 55 namespace gfx { 56 struct FontVariation; 57 struct FontFeature; 58 } // namespace gfx 59 } // namespace mozilla 60 using gfxFontVariation = mozilla::gfx::FontVariation; 61 using gfxFontFeature = mozilla::gfx::FontFeature; 62 63 enum nsCSSUnit : uint32_t; 64 enum nsChangeHint : uint32_t; 65 66 namespace nsStyleTransformMatrix { 67 enum class MatrixTransformOperator : uint8_t; 68 } 69 70 template <typename T> 71 class nsMainThreadPtrHolder; 72 73 namespace mozilla { 74 75 class ComputedStyle; 76 77 using Matrix4x4Components = float[16]; 78 using StyleMatrix4x4Components = Matrix4x4Components; 79 80 // This is sound because std::num::NonZeroUsize is repr(transparent). 81 // 82 // It is just the case that cbindgen doesn't understand it natively. 83 using StyleNonZeroUsize = uintptr_t; 84 85 struct Keyframe; 86 struct PropertyStyleAnimationValuePair; 87 88 using ComputedKeyframeValues = nsTArray<PropertyStyleAnimationValuePair>; 89 90 class ComputedStyle; 91 enum class LogicalAxis : uint8_t; 92 enum class PhysicalAxis : uint8_t; 93 class SeenPtrs; 94 class SharedFontList; 95 class StyleSheet; 96 class WritingMode; 97 class ServoElementSnapshotTable; 98 class StyleParserState; 99 100 template <typename T> 101 struct StyleForgottenArcSlicePtr; 102 103 struct AnimationPropertySegment; 104 struct AspectRatio; 105 struct ComputedTiming; 106 struct CSSPropertyId; 107 struct URLExtraData; 108 109 enum HalfCorner : uint8_t; 110 enum class LogicalSide : uint8_t; 111 enum class PseudoStyleType : uint8_t; 112 enum class OriginFlags : uint8_t; 113 enum class UseBoxSizing : uint8_t; 114 115 template <typename L> 116 union StyleGenericCalcNode; 117 118 namespace css { 119 class Loader; 120 class LoaderReusableStyleSheets; 121 class SheetLoadData; 122 using SheetLoadDataHolder = nsMainThreadPtrHolder<SheetLoadData>; 123 enum SheetParsingMode : uint8_t; 124 } // namespace css 125 126 namespace dom { 127 enum class IterationCompositeOperation : uint8_t; 128 enum class CallerType : uint32_t; 129 130 class Element; 131 class Document; 132 133 } // namespace dom 134 135 // Replacement for a Rust Box<T> for a non-dynamically-sized-type. 136 // 137 // TODO(emilio): If this was some sort of nullable box then this could be made 138 // to work with moves, and also reduce memory layout size of stuff, potentially. 139 template <typename T> 140 struct StyleBox { 141 explicit StyleBox(UniquePtr<T> aPtr) : mRaw(aPtr.release()) { 142 MOZ_DIAGNOSTIC_ASSERT(mRaw); 143 } 144 145 ~StyleBox() { 146 MOZ_DIAGNOSTIC_ASSERT(mRaw); 147 delete mRaw; 148 } 149 150 StyleBox(const StyleBox& aOther) : StyleBox(MakeUnique<T>(*aOther)) {} 151 152 StyleBox& operator=(const StyleBox& aOther) const { 153 delete mRaw; 154 mRaw = MakeUnique<T>(*aOther).release(); 155 return *this; 156 } 157 158 const T* operator->() const { 159 MOZ_DIAGNOSTIC_ASSERT(mRaw); 160 return mRaw; 161 } 162 163 const T& operator*() const { 164 MOZ_DIAGNOSTIC_ASSERT(mRaw); 165 return *mRaw; 166 } 167 168 T* operator->() { 169 MOZ_DIAGNOSTIC_ASSERT(mRaw); 170 return mRaw; 171 } 172 173 T& operator*() { 174 MOZ_DIAGNOSTIC_ASSERT(mRaw); 175 return *mRaw; 176 } 177 178 bool operator==(const StyleBox& aOther) const { return *(*this) == *aOther; } 179 180 bool operator!=(const StyleBox& aOther) const { return *(*this) != *aOther; } 181 182 private: 183 T* mRaw; 184 }; 185 186 // Work-around weird cbindgen renaming / avoiding moving stuff outside its 187 // namespace. 188 189 using StyleLoader = css::Loader; 190 using StyleLoaderReusableStyleSheets = css::LoaderReusableStyleSheets; 191 using StyleCallerType = dom::CallerType; 192 using StyleSheetParsingMode = css::SheetParsingMode; 193 using StyleSheetLoadData = css::SheetLoadData; 194 using StyleSheetLoadDataHolder = css::SheetLoadDataHolder; 195 using StyleGeckoMallocSizeOf = MallocSizeOf; 196 using StyleDomStyleSheet = StyleSheet; 197 198 using StyleRawGeckoNode = nsINode; 199 using StyleRawGeckoElement = dom::Element; 200 using StyleDocument = dom::Document; 201 using StyleComputedValues = ComputedStyle; 202 using StyleIterationCompositeOperation = dom::IterationCompositeOperation; 203 204 using StyleMatrixTransformOperator = 205 nsStyleTransformMatrix::MatrixTransformOperator; 206 207 # define SERVO_LOCKED_ARC_TYPE(name_) struct StyleLocked##type_; 208 # include "mozilla/ServoLockedArcTypeList.h" 209 # undef SERVO_LOCKED_ARC_TYPE 210 211 # define SERVO_BOXED_TYPE(name_, type_) struct Style##type_; 212 # include "mozilla/ServoBoxedTypeList.h" 213 # undef SERVO_BOXED_TYPE 214 215 using StyleAtomicUsize = std::atomic<size_t>; 216 217 # define SERVO_FIXED_POINT_HELPERS(T, RawT, FractionBits) \ 218 static constexpr RawT kPointFive = 1 << (FractionBits - 1); \ 219 static constexpr uint16_t kScale = 1 << FractionBits; \ 220 static constexpr float kInverseScale = 1.0f / kScale; \ 221 static T FromRaw(RawT aRaw) { return {{aRaw}}; } \ 222 static T FromFloat(float aFloat) { \ 223 return FromRaw(RawT(aFloat * kScale)); \ 224 } \ 225 static T FromInt(RawT aInt) { return FromRaw(RawT(aInt * kScale)); } \ 226 RawT Raw() const { return _0.value; } \ 227 uint16_t UnsignedRaw() const { return uint16_t(Raw()); } \ 228 float ToFloat() const { return Raw() * kInverseScale; } \ 229 RawT ToIntRounded() const { return (Raw() + kPointFive) >> FractionBits; } \ 230 inline void ToString(nsACString&) const; 231 232 } // namespace mozilla 233 234 # ifndef HAVE_64BIT_BUILD 235 static_assert(sizeof(void*) == 4, ""); 236 # define SERVO_32_BITS 1 237 # endif 238 # define CBINDGEN_IS_GECKO 239 240 #endif