Backed out 2 changesets (bug 1287054) for causing Android wpt failures in SVGLength...
[gecko.git] / layout / style / nsCSSValue.h
blobc364ec637df334d13b6062e54d47423f76cc74b6
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
65 // Screen relative measure
66 eCSSUnit_Point = 900, // 4/3 of a CSS pixel
67 eCSSUnit_Inch = 901, // 96 CSS pixels
68 eCSSUnit_Millimeter = 902, // 96/25.4 CSS pixels
69 eCSSUnit_Centimeter = 903, // 96/2.54 CSS pixels
70 eCSSUnit_Pica = 904, // 12 points == 16 CSS pixls
71 eCSSUnit_Quarter = 905, // 96/101.6 CSS pixels
72 eCSSUnit_Pixel = 906, // CSS pixel unit
75 struct nsCSSValuePair;
76 struct nsCSSValuePair_heap;
77 struct nsCSSValueList;
78 struct nsCSSValueList_heap;
79 struct nsCSSValueSharedList;
80 struct nsCSSValuePairList;
81 struct nsCSSValuePairList_heap;
83 class nsCSSValue {
84 public:
85 explicit nsCSSValue() : mUnit(eCSSUnit_Null) {}
87 nsCSSValue(float aValue, nsCSSUnit aUnit);
88 nsCSSValue(const nsCSSValue& aCopy);
89 nsCSSValue(nsCSSValue&& aOther) : mUnit(aOther.mUnit), mValue(aOther.mValue) {
90 aOther.mUnit = eCSSUnit_Null;
93 nsCSSValue& operator=(const nsCSSValue& aCopy);
94 nsCSSValue& operator=(nsCSSValue&& aCopy);
95 bool operator==(const nsCSSValue& aOther) const;
97 bool operator!=(const nsCSSValue& aOther) const { return !(*this == aOther); }
99 nsCSSUnit GetUnit() const { return mUnit; }
100 bool IsLengthUnit() const {
101 return eCSSUnit_EM <= mUnit && mUnit <= eCSSUnit_Pixel;
104 * A "pixel" length unit is a some multiple of CSS pixels.
106 static bool IsPixelLengthUnit(nsCSSUnit aUnit) {
107 return eCSSUnit_Point <= aUnit && aUnit <= eCSSUnit_Pixel;
109 bool IsPixelLengthUnit() const { return IsPixelLengthUnit(mUnit); }
110 static bool IsPercentLengthUnit(nsCSSUnit aUnit) {
111 return aUnit == eCSSUnit_Percent;
113 static bool IsFloatUnit(nsCSSUnit aUnit) { return eCSSUnit_Number <= aUnit; }
115 float GetPercentValue() const {
116 MOZ_ASSERT(mUnit == eCSSUnit_Percent, "not a percent value");
117 return mValue;
120 float GetFloatValue() const {
121 MOZ_ASSERT(eCSSUnit_Number <= mUnit, "not a float value");
122 MOZ_ASSERT(!std::isnan(mValue));
123 return mValue;
126 nscoord GetPixelLength() const;
128 void Reset() { mUnit = eCSSUnit_Null; }
129 ~nsCSSValue() { Reset(); }
131 public:
132 void SetPercentValue(float aValue);
133 void SetFloatValue(float aValue, nsCSSUnit aUnit);
135 protected:
136 nsCSSUnit mUnit;
137 float mValue;
140 #endif /* nsCSSValue_h___ */