Backed out 4 changesets (bug 1825722) for causing reftest failures CLOSED TREE
[gecko.git] / layout / style / nsCSSValue.h
blobbc8914bbc1bc051c38666c320b4b3c7c29cb34fe
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 /* representation of simple property values within CSS declarations */
9 #ifndef nsCSSValue_h___
10 #define nsCSSValue_h___
12 #include "mozilla/Attributes.h"
13 #include "mozilla/CORSMode.h"
14 #include "mozilla/EnumTypeTraits.h"
15 #include "mozilla/MemoryReporting.h"
16 #include "mozilla/ServoBindingTypes.h"
17 #include "mozilla/URLExtraData.h"
18 #include "mozilla/UniquePtr.h"
20 #include "nsCoord.h"
21 #include "nsTArray.h"
23 #include <type_traits>
25 // XXX Avoid including this here by moving function bodies to the cpp file
26 #include "mozilla/FloatingPoint.h"
28 class imgRequestProxy;
29 class nsAtom;
30 class nsIContent;
32 class nsIPrincipal;
33 class nsIURI;
34 class nsPresContext;
35 template <class T>
36 class nsPtrHashKey;
37 struct RawServoCssUrlData;
39 namespace mozilla {
40 class CSSStyleSheet;
41 } // namespace mozilla
43 // Forward declaration copied here since ServoBindings.h #includes nsCSSValue.h.
44 extern "C" {
45 mozilla::URLExtraData* Servo_CssUrlData_GetExtraData(const RawServoCssUrlData*);
46 bool Servo_CssUrlData_IsLocalRef(const RawServoCssUrlData* url);
49 enum nsCSSUnit : uint32_t {
50 eCSSUnit_Null = 0, // (n/a) null unit, value is not specified
52 eCSSUnit_Percent = 100, // (1.0 == 100%) value is percentage of
53 // something
54 eCSSUnit_Number = 101, // value is numeric (usually multiplier,
55 // different behavior than percent)
57 // Font relative measure
58 eCSSUnit_EM = 800, // == current font size
59 eCSSUnit_XHeight = 801, // distance from top of lower case x to
60 // baseline
61 eCSSUnit_Char = 802, // number of characters, used for width with
62 // monospace font
63 eCSSUnit_RootEM = 803, // == root element font size
64 eCSSUnit_Ideographic = 804, // == CJK water ideograph width
65 eCSSUnit_CapHeight = 805, // == Capital letter height
67 // Screen relative measure
68 eCSSUnit_Point = 900, // 4/3 of a CSS pixel
69 eCSSUnit_Inch = 901, // 96 CSS pixels
70 eCSSUnit_Millimeter = 902, // 96/25.4 CSS pixels
71 eCSSUnit_Centimeter = 903, // 96/2.54 CSS pixels
72 eCSSUnit_Pica = 904, // 12 points == 16 CSS pixls
73 eCSSUnit_Quarter = 905, // 96/101.6 CSS pixels
74 eCSSUnit_Pixel = 906, // CSS pixel unit
76 // Viewport percentage lengths
77 eCSSUnit_VW = 950,
78 eCSSUnit_VH = 951,
79 eCSSUnit_VMin = 952,
80 eCSSUnit_VMax = 953,
83 struct nsCSSValuePair;
84 struct nsCSSValuePair_heap;
85 struct nsCSSValueList;
86 struct nsCSSValueList_heap;
87 struct nsCSSValueSharedList;
88 struct nsCSSValuePairList;
89 struct nsCSSValuePairList_heap;
91 class nsCSSValue {
92 public:
93 explicit nsCSSValue() : mUnit(eCSSUnit_Null) {}
95 nsCSSValue(float aValue, nsCSSUnit aUnit);
96 nsCSSValue(const nsCSSValue& aCopy);
97 nsCSSValue(nsCSSValue&& aOther) : mUnit(aOther.mUnit), mValue(aOther.mValue) {
98 aOther.mUnit = eCSSUnit_Null;
101 nsCSSValue& operator=(const nsCSSValue& aCopy);
102 nsCSSValue& operator=(nsCSSValue&& aCopy);
103 bool operator==(const nsCSSValue& aOther) const;
105 bool operator!=(const nsCSSValue& aOther) const { return !(*this == aOther); }
107 nsCSSUnit GetUnit() const { return mUnit; }
108 bool IsLengthUnit() const {
109 return eCSSUnit_EM <= mUnit && mUnit <= eCSSUnit_Pixel;
112 * A "pixel" length unit is a some multiple of CSS pixels.
114 static bool IsPixelLengthUnit(nsCSSUnit aUnit) {
115 return eCSSUnit_Point <= aUnit && aUnit <= eCSSUnit_Pixel;
117 bool IsPixelLengthUnit() const { return IsPixelLengthUnit(mUnit); }
118 static bool IsPercentLengthUnit(nsCSSUnit aUnit) {
119 return aUnit == eCSSUnit_Percent;
121 static bool IsFloatUnit(nsCSSUnit aUnit) { return eCSSUnit_Number <= aUnit; }
123 float GetPercentValue() const {
124 MOZ_ASSERT(mUnit == eCSSUnit_Percent, "not a percent value");
125 return mValue;
128 float GetFloatValue() const {
129 MOZ_ASSERT(eCSSUnit_Number <= mUnit, "not a float value");
130 MOZ_ASSERT(!std::isnan(mValue));
131 return mValue;
134 nscoord GetPixelLength() const;
136 void Reset() { mUnit = eCSSUnit_Null; }
137 ~nsCSSValue() { Reset(); }
139 public:
140 void SetPercentValue(float aValue);
141 void SetFloatValue(float aValue, nsCSSUnit aUnit);
143 protected:
144 nsCSSUnit mUnit;
145 float mValue;
148 #endif /* nsCSSValue_h___ */