Bumping manifests a=b2g-bump
[gecko.git] / layout / style / nsCSSValue.h
bloba9d7ddd912a2ef0574a1ef351a116b56f8f025e9
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/. */
6 /* representation of simple property values within CSS declarations */
8 #ifndef nsCSSValue_h___
9 #define nsCSSValue_h___
11 #include "mozilla/Attributes.h"
12 #include "mozilla/MemoryReporting.h"
14 #include "nsIPrincipal.h"
15 #include "nsIURI.h"
16 #include "nsCOMPtr.h"
17 #include "nsCSSKeywords.h"
18 #include "nsCSSProperty.h"
19 #include "nsColor.h"
20 #include "nsCoord.h"
21 #include "nsRefPtrHashtable.h"
22 #include "nsString.h"
23 #include "nsStringBuffer.h"
24 #include "nsTArray.h"
25 #include "nsStyleConsts.h"
26 #include "gfxFontFamilyList.h"
28 class imgRequestProxy;
29 class nsIDocument;
30 class nsIPrincipal;
31 class nsIURI;
32 class nsPresContext;
33 template <class T>
34 class nsPtrHashKey;
36 namespace mozilla {
37 class CSSStyleSheet;
38 } // namespace mozilla
40 // Deletes a linked list iteratively to avoid blowing up the stack (bug 456196).
41 #define NS_CSS_DELETE_LIST_MEMBER(type_, ptr_, member_) \
42 { \
43 type_ *cur = (ptr_)->member_; \
44 (ptr_)->member_ = nullptr; \
45 while (cur) { \
46 type_ *dlm_next = cur->member_; \
47 cur->member_ = nullptr; \
48 delete cur; \
49 cur = dlm_next; \
50 } \
53 // Clones a linked list iteratively to avoid blowing up the stack.
54 // If it fails to clone the entire list then 'to_' is deleted and
55 // we return null.
56 #define NS_CSS_CLONE_LIST_MEMBER(type_, from_, member_, to_, args_) \
57 { \
58 type_ *dest = (to_); \
59 (to_)->member_ = nullptr; \
60 for (const type_ *src = (from_)->member_; src; src = src->member_) { \
61 type_ *clm_clone = src->Clone args_; \
62 if (!clm_clone) { \
63 delete (to_); \
64 return nullptr; \
65 } \
66 dest->member_ = clm_clone; \
67 dest = clm_clone; \
68 } \
71 namespace mozilla {
72 namespace css {
74 struct URLValue {
75 // Methods are not inline because using an nsIPrincipal means requiring
76 // caps, which leads to REQUIRES hell, since this header is included all
77 // over.
79 // For both constructors aString must not be null.
80 // For both constructors aOriginPrincipal must not be null.
81 // Construct with a base URI; this will create the actual URI lazily from
82 // aString and aBaseURI.
83 URLValue(nsStringBuffer* aString, nsIURI* aBaseURI, nsIURI* aReferrer,
84 nsIPrincipal* aOriginPrincipal);
85 // Construct with the actual URI.
86 URLValue(nsIURI* aURI, nsStringBuffer* aString, nsIURI* aReferrer,
87 nsIPrincipal* aOriginPrincipal);
89 protected:
90 ~URLValue();
92 public:
93 bool operator==(const URLValue& aOther) const;
95 // URIEquals only compares URIs and principals (unlike operator==, which
96 // also compares the original strings). URIEquals also assumes that the
97 // mURI member of both URL objects is non-null. Do NOT call this method
98 // unless you're sure this is the case.
99 bool URIEquals(const URLValue& aOther) const;
101 nsIURI* GetURI() const;
103 size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
105 private:
106 // If mURIResolved is false, mURI stores the base URI.
107 // If mURIResolved is true, mURI stores the URI we resolve to; this may be
108 // null if the URI is invalid.
109 mutable nsCOMPtr<nsIURI> mURI;
110 public:
111 nsStringBuffer* mString; // Could use nsRefPtr, but it'd add useless
112 // null-checks; this is never null.
113 nsCOMPtr<nsIURI> mReferrer;
114 nsCOMPtr<nsIPrincipal> mOriginPrincipal;
116 NS_INLINE_DECL_REFCOUNTING(URLValue)
118 private:
119 mutable bool mURIResolved;
121 URLValue(const URLValue& aOther) MOZ_DELETE;
122 URLValue& operator=(const URLValue& aOther) MOZ_DELETE;
125 struct ImageValue : public URLValue {
126 // Not making the constructor and destructor inline because that would
127 // force us to include imgIRequest.h, which leads to REQUIRES hell, since
128 // this header is included all over.
129 // aString must not be null.
130 ImageValue(nsIURI* aURI, nsStringBuffer* aString, nsIURI* aReferrer,
131 nsIPrincipal* aOriginPrincipal, nsIDocument* aDocument);
132 private:
133 ~ImageValue();
135 public:
136 // Inherit operator== from URLValue
138 nsRefPtrHashtable<nsPtrHashKey<nsISupports>, imgRequestProxy> mRequests;
140 // Override AddRef and Release to not only log ourselves correctly, but
141 // also so that we delete correctly without a virtual destructor
142 NS_INLINE_DECL_REFCOUNTING(ImageValue)
145 struct GridNamedArea {
146 nsString mName;
147 uint32_t mColumnStart;
148 uint32_t mColumnEnd;
149 uint32_t mRowStart;
150 uint32_t mRowEnd;
153 struct GridTemplateAreasValue MOZ_FINAL {
154 // Parsed value
155 nsTArray<GridNamedArea> mNamedAreas;
157 // Original <string> values. Length gives the number of rows,
158 // content makes serialization easier.
159 nsTArray<nsString> mTemplates;
161 // How many columns grid-template-areas contributes to the explicit grid.
162 // http://dev.w3.org/csswg/css-grid/#explicit-grid
163 uint32_t mNColumns;
165 // How many rows grid-template-areas contributes to the explicit grid.
166 // http://dev.w3.org/csswg/css-grid/#explicit-grid
167 uint32_t NRows() const {
168 return mTemplates.Length();
171 GridTemplateAreasValue()
172 : mNColumns(0)
173 // Default constructors for mNamedAreas and mTemplates: empty arrays.
177 bool operator==(const GridTemplateAreasValue& aOther) const
179 return mTemplates == aOther.mTemplates;
182 bool operator!=(const GridTemplateAreasValue& aOther) const
184 return !(*this == aOther);
187 NS_INLINE_DECL_REFCOUNTING(GridTemplateAreasValue)
189 size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
191 private:
192 // Private destructor to make sure this isn't used as a stack variable
193 // or member variable.
194 ~GridTemplateAreasValue()
198 GridTemplateAreasValue(const GridTemplateAreasValue& aOther) MOZ_DELETE;
199 GridTemplateAreasValue&
200 operator=(const GridTemplateAreasValue& aOther) MOZ_DELETE;
203 class FontFamilyListRefCnt MOZ_FINAL : public FontFamilyList {
204 public:
205 FontFamilyListRefCnt()
206 : FontFamilyList()
208 MOZ_COUNT_CTOR(FontFamilyListRefCnt);
211 explicit FontFamilyListRefCnt(FontFamilyType aGenericType)
212 : FontFamilyList(aGenericType)
214 MOZ_COUNT_CTOR(FontFamilyListRefCnt);
217 FontFamilyListRefCnt(const nsAString& aFamilyName,
218 QuotedName aQuoted)
219 : FontFamilyList(aFamilyName, aQuoted)
221 MOZ_COUNT_CTOR(FontFamilyListRefCnt);
224 FontFamilyListRefCnt(const FontFamilyListRefCnt& aOther)
225 : FontFamilyList(aOther)
227 MOZ_COUNT_CTOR(FontFamilyListRefCnt);
230 NS_INLINE_DECL_REFCOUNTING(FontFamilyListRefCnt);
232 private:
233 ~FontFamilyListRefCnt() {
234 MOZ_COUNT_DTOR(FontFamilyListRefCnt);
241 enum nsCSSUnit {
242 eCSSUnit_Null = 0, // (n/a) null unit, value is not specified
243 eCSSUnit_Auto = 1, // (n/a) value is algorithmic
244 eCSSUnit_Inherit = 2, // (n/a) value is inherited
245 eCSSUnit_Initial = 3, // (n/a) value is default UA value
246 eCSSUnit_Unset = 4, // (n/a) value equivalent to 'initial' if on a reset property, 'inherit' otherwise
247 eCSSUnit_None = 5, // (n/a) value is none
248 eCSSUnit_Normal = 6, // (n/a) value is normal (algorithmic, different than auto)
249 eCSSUnit_System_Font = 7, // (n/a) value is -moz-use-system-font
250 eCSSUnit_All = 8, // (n/a) value is all
251 eCSSUnit_Dummy = 9, // (n/a) a fake but specified value, used
252 // only in temporary values
253 eCSSUnit_DummyInherit = 10, // (n/a) a fake but specified value, used
254 // only in temporary values
256 eCSSUnit_String = 11, // (char16_t*) a string value
257 eCSSUnit_Ident = 12, // (char16_t*) a string value
258 eCSSUnit_Attr = 14, // (char16_t*) a attr(string) value
259 eCSSUnit_Local_Font = 15, // (char16_t*) a local font name
260 eCSSUnit_Font_Format = 16, // (char16_t*) a font format name
261 eCSSUnit_Element = 17, // (char16_t*) an element id
263 eCSSUnit_Array = 20, // (nsCSSValue::Array*) a list of values
264 eCSSUnit_Counter = 21, // (nsCSSValue::Array*) a counter(string,[string]) value
265 eCSSUnit_Counters = 22, // (nsCSSValue::Array*) a counters(string,string[,string]) value
266 eCSSUnit_Cubic_Bezier = 23, // (nsCSSValue::Array*) a list of float values
267 eCSSUnit_Steps = 24, // (nsCSSValue::Array*) a list of (integer, enumerated)
268 eCSSUnit_Function = 25, // (nsCSSValue::Array*) a function with
269 // parameters. First elem of array is name,
270 // an nsCSSKeyword as eCSSUnit_Enumerated,
271 // the rest of the values are arguments.
273 // The top level of a calc() expression is eCSSUnit_Calc. All
274 // remaining eCSSUnit_Calc_* units only occur inside these toplevel
275 // calc values.
277 // eCSSUnit_Calc has an array with exactly 1 element. eCSSUnit_Calc
278 // exists so we can distinguish calc(2em) from 2em as specified values
279 // (but we drop this distinction for nsStyleCoord when we store
280 // computed values).
281 eCSSUnit_Calc = 30, // (nsCSSValue::Array*) calc() value
282 // Plus, Minus, Times_* and Divided have arrays with exactly 2
283 // elements. a + b + c + d is grouped as ((a + b) + c) + d
284 eCSSUnit_Calc_Plus = 31, // (nsCSSValue::Array*) + node within calc()
285 eCSSUnit_Calc_Minus = 32, // (nsCSSValue::Array*) - within calc
286 eCSSUnit_Calc_Times_L = 33, // (nsCSSValue::Array*) num * val within calc
287 eCSSUnit_Calc_Times_R = 34, // (nsCSSValue::Array*) val * num within calc
288 eCSSUnit_Calc_Divided = 35, // (nsCSSValue::Array*) / within calc
290 eCSSUnit_URL = 40, // (nsCSSValue::URL*) value
291 eCSSUnit_Image = 41, // (nsCSSValue::Image*) value
292 eCSSUnit_Gradient = 42, // (nsCSSValueGradient*) value
293 eCSSUnit_TokenStream = 43, // (nsCSSValueTokenStream*) value
294 eCSSUnit_GridTemplateAreas = 44, // (GridTemplateAreasValue*)
295 // for grid-template-areas
297 eCSSUnit_Pair = 50, // (nsCSSValuePair*) pair of values
298 eCSSUnit_Triplet = 51, // (nsCSSValueTriplet*) triplet of values
299 eCSSUnit_Rect = 52, // (nsCSSRect*) rectangle (four values)
300 eCSSUnit_List = 53, // (nsCSSValueList*) list of values
301 eCSSUnit_ListDep = 54, // (nsCSSValueList*) same as List
302 // but does not own the list
303 eCSSUnit_SharedList = 55, // (nsCSSValueSharedList*) same as list
304 // but reference counted and shared
305 eCSSUnit_PairList = 56, // (nsCSSValuePairList*) list of value pairs
306 eCSSUnit_PairListDep = 57, // (nsCSSValuePairList*) same as PairList
307 // but does not own the list
309 eCSSUnit_FontFamilyList = 58, // (FontFamilyList*) value
311 eCSSUnit_Integer = 70, // (int) simple value
312 eCSSUnit_Enumerated = 71, // (int) value has enumerated meaning
314 eCSSUnit_EnumColor = 80, // (int) enumerated color (kColorKTable)
315 eCSSUnit_RGBColor = 81, // (nscolor) an opaque RGBA value specified as rgb()
316 eCSSUnit_RGBAColor = 82, // (nscolor) an RGBA value specified as rgba()
317 eCSSUnit_HexColor = 83, // (nscolor) an opaque RGBA value specified as #rrggbb
318 eCSSUnit_ShortHexColor = 84, // (nscolor) an opaque RGBA value specified as #rgb
319 eCSSUnit_PercentageRGBColor = 85, // (nsCSSValueFloatColor*)
320 eCSSUnit_PercentageRGBAColor = 86, // (nsCSSValueFloatColor*)
321 eCSSUnit_HSLColor = 87, // (nsCSSValueFloatColor*)
322 eCSSUnit_HSLAColor = 88, // (nsCSSValueFloatColor*)
324 eCSSUnit_Percent = 90, // (float) 1.0 == 100%) value is percentage of something
325 eCSSUnit_Number = 91, // (float) value is numeric (usually multiplier, different behavior that percent)
327 // Physical length units
328 eCSSUnit_PhysicalMillimeter = 200, // (float) 1/25.4 inch
330 // Length units - relative
331 // Viewport relative measure
332 eCSSUnit_ViewportWidth = 700, // (float) 1% of the width of the initial containing block
333 eCSSUnit_ViewportHeight = 701, // (float) 1% of the height of the initial containing block
334 eCSSUnit_ViewportMin = 702, // (float) smaller of ViewportWidth and ViewportHeight
335 eCSSUnit_ViewportMax = 703, // (float) larger of ViewportWidth and ViewportHeight
337 // Font relative measure
338 eCSSUnit_EM = 800, // (float) == current font size
339 eCSSUnit_XHeight = 801, // (float) distance from top of lower case x to baseline
340 eCSSUnit_Char = 802, // (float) number of characters, used for width with monospace font
341 eCSSUnit_RootEM = 803, // (float) == root element font size
343 // Screen relative measure
344 eCSSUnit_Point = 900, // (float) 4/3 of a CSS pixel
345 eCSSUnit_Inch = 901, // (float) 96 CSS pixels
346 eCSSUnit_Millimeter = 902, // (float) 96/25.4 CSS pixels
347 eCSSUnit_Centimeter = 903, // (float) 96/2.54 CSS pixels
348 eCSSUnit_Pica = 904, // (float) 12 points == 16 CSS pixls
349 eCSSUnit_Pixel = 905, // (float) CSS pixel unit
351 // Angular units
352 eCSSUnit_Degree = 1000, // (float) 360 per circle
353 eCSSUnit_Grad = 1001, // (float) 400 per circle
354 eCSSUnit_Radian = 1002, // (float) 2*pi per circle
355 eCSSUnit_Turn = 1003, // (float) 1 per circle
357 // Frequency units
358 eCSSUnit_Hertz = 2000, // (float) 1/seconds
359 eCSSUnit_Kilohertz = 2001, // (float) 1000 Hertz
361 // Time units
362 eCSSUnit_Seconds = 3000, // (float) Standard time
363 eCSSUnit_Milliseconds = 3001, // (float) 1/1000 second
365 // Flexible fraction (CSS Grid)
366 eCSSUnit_FlexFraction = 4000 // (float) Fraction of free space
369 struct nsCSSValueGradient;
370 struct nsCSSValuePair;
371 struct nsCSSValuePair_heap;
372 struct nsCSSValueTokenStream;
373 struct nsCSSRect;
374 struct nsCSSRect_heap;
375 struct nsCSSValueList;
376 struct nsCSSValueList_heap;
377 struct nsCSSValueSharedList;
378 struct nsCSSValuePairList;
379 struct nsCSSValuePairList_heap;
380 struct nsCSSValueTriplet;
381 struct nsCSSValueTriplet_heap;
382 class nsCSSValueFloatColor;
384 class nsCSSValue {
385 public:
386 struct Array;
387 friend struct Array;
389 friend struct mozilla::css::URLValue;
391 friend struct mozilla::css::ImageValue;
393 // for valueless units only (null, auto, inherit, none, all, normal)
394 explicit nsCSSValue(nsCSSUnit aUnit = eCSSUnit_Null)
395 : mUnit(aUnit)
397 NS_ABORT_IF_FALSE(aUnit <= eCSSUnit_DummyInherit, "not a valueless unit");
400 nsCSSValue(int32_t aValue, nsCSSUnit aUnit);
401 nsCSSValue(float aValue, nsCSSUnit aUnit);
402 nsCSSValue(const nsString& aValue, nsCSSUnit aUnit);
403 nsCSSValue(Array* aArray, nsCSSUnit aUnit);
404 explicit nsCSSValue(mozilla::css::URLValue* aValue);
405 explicit nsCSSValue(mozilla::css::ImageValue* aValue);
406 explicit nsCSSValue(nsCSSValueGradient* aValue);
407 explicit nsCSSValue(nsCSSValueTokenStream* aValue);
408 explicit nsCSSValue(mozilla::css::GridTemplateAreasValue* aValue);
409 explicit nsCSSValue(mozilla::css::FontFamilyListRefCnt* aValue);
410 nsCSSValue(const nsCSSValue& aCopy);
411 ~nsCSSValue() { Reset(); }
413 nsCSSValue& operator=(const nsCSSValue& aCopy);
414 bool operator==(const nsCSSValue& aOther) const;
416 bool operator!=(const nsCSSValue& aOther) const
418 return !(*this == aOther);
421 // Enum for AppendToString's aValueSerialization argument.
422 enum Serialization { eNormalized, eAuthorSpecified };
425 * Serialize |this| as a specified value for |aProperty| and append
426 * it to |aResult|.
428 void AppendToString(nsCSSProperty aProperty, nsAString& aResult,
429 Serialization aValueSerialization) const;
431 nsCSSUnit GetUnit() const { return mUnit; }
432 bool IsLengthUnit() const
433 { return eCSSUnit_PhysicalMillimeter <= mUnit && mUnit <= eCSSUnit_Pixel; }
435 * A "fixed" length unit is one that means a specific physical length
436 * which we try to match based on the physical characteristics of an
437 * output device.
439 bool IsFixedLengthUnit() const
440 { return mUnit == eCSSUnit_PhysicalMillimeter; }
442 * What the spec calls relative length units is, for us, split
443 * between relative length units and pixel length units.
445 * A "relative" length unit is a multiple of some derived metric,
446 * such as a font em-size, which itself was controlled by an input CSS
447 * length. Relative length units should not be scaled by zooming, since
448 * the underlying CSS length would already have been scaled.
450 bool IsRelativeLengthUnit() const
451 { return eCSSUnit_EM <= mUnit && mUnit <= eCSSUnit_RootEM; }
453 * A "pixel" length unit is a some multiple of CSS pixels.
455 bool IsPixelLengthUnit() const
456 { return eCSSUnit_Point <= mUnit && mUnit <= eCSSUnit_Pixel; }
457 bool IsAngularUnit() const
458 { return eCSSUnit_Degree <= mUnit && mUnit <= eCSSUnit_Turn; }
459 bool IsFrequencyUnit() const
460 { return eCSSUnit_Hertz <= mUnit && mUnit <= eCSSUnit_Kilohertz; }
461 bool IsTimeUnit() const
462 { return eCSSUnit_Seconds <= mUnit && mUnit <= eCSSUnit_Milliseconds; }
463 bool IsCalcUnit() const
464 { return eCSSUnit_Calc <= mUnit && mUnit <= eCSSUnit_Calc_Divided; }
466 bool UnitHasStringValue() const
467 { return eCSSUnit_String <= mUnit && mUnit <= eCSSUnit_Element; }
468 bool UnitHasArrayValue() const
469 { return eCSSUnit_Array <= mUnit && mUnit <= eCSSUnit_Calc_Divided; }
471 // Checks for the nsCSSValue being of a particular type of color unit:
473 // - IsIntegerColorUnit returns true for:
474 // eCSSUnit_RGBColor -- rgb(int,int,int)
475 // eCSSUnit_RGBAColor -- rgba(int,int,int,float)
476 // eCSSUnit_HexColor -- #rrggbb
477 // eCSSUnit_ShortHexColor -- #rgb
479 // - IsFLoatColorUnit returns true for:
480 // eCSSUnit_PercentageRGBColor -- rgb(%,%,%)
481 // eCSSUnit_PercentageRGBAColor -- rgba(%,%,%,float)
482 // eCSSUnit_HSLColor -- hsl(float,%,%)
483 // eCSSUnit_HSLAColor -- hsla(float,%,%,float)
485 // - IsNumericColorUnit returns true for any of the above units.
487 // Note that color keywords and system colors are represented by
488 // eCSSUnit_EnumColor and eCSSUnit_Ident.
489 bool IsIntegerColorUnit() const { return IsIntegerColorUnit(mUnit); }
490 bool IsFloatColorUnit() const { return IsFloatColorUnit(mUnit); }
491 bool IsNumericColorUnit() const { return IsNumericColorUnit(mUnit); }
492 static bool IsIntegerColorUnit(nsCSSUnit aUnit)
493 { return eCSSUnit_RGBColor <= aUnit && aUnit <= eCSSUnit_ShortHexColor; }
494 static bool IsFloatColorUnit(nsCSSUnit aUnit)
495 { return eCSSUnit_PercentageRGBColor <= aUnit &&
496 aUnit <= eCSSUnit_HSLAColor; }
497 static bool IsNumericColorUnit(nsCSSUnit aUnit)
498 { return IsIntegerColorUnit(aUnit) || IsFloatColorUnit(aUnit); }
500 int32_t GetIntValue() const
502 NS_ABORT_IF_FALSE(mUnit == eCSSUnit_Integer ||
503 mUnit == eCSSUnit_Enumerated ||
504 mUnit == eCSSUnit_EnumColor,
505 "not an int value");
506 return mValue.mInt;
509 nsCSSKeyword GetKeywordValue() const
511 NS_ABORT_IF_FALSE(mUnit == eCSSUnit_Enumerated, "not a keyword value");
512 return static_cast<nsCSSKeyword>(mValue.mInt);
515 float GetPercentValue() const
517 NS_ABORT_IF_FALSE(mUnit == eCSSUnit_Percent, "not a percent value");
518 return mValue.mFloat;
521 float GetFloatValue() const
523 NS_ABORT_IF_FALSE(eCSSUnit_Number <= mUnit, "not a float value");
524 MOZ_ASSERT(!mozilla::IsNaN(mValue.mFloat));
525 return mValue.mFloat;
528 float GetAngleValue() const
530 NS_ABORT_IF_FALSE(eCSSUnit_Degree <= mUnit &&
531 mUnit <= eCSSUnit_Turn, "not an angle value");
532 return mValue.mFloat;
535 // Converts any angle to radians.
536 double GetAngleValueInRadians() const;
538 nsAString& GetStringValue(nsAString& aBuffer) const
540 NS_ABORT_IF_FALSE(UnitHasStringValue(), "not a string value");
541 aBuffer.Truncate();
542 uint32_t len = NS_strlen(GetBufferValue(mValue.mString));
543 mValue.mString->ToString(len, aBuffer);
544 return aBuffer;
547 const char16_t* GetStringBufferValue() const
549 NS_ABORT_IF_FALSE(UnitHasStringValue(), "not a string value");
550 return GetBufferValue(mValue.mString);
553 nscolor GetColorValue() const;
554 bool IsNonTransparentColor() const;
556 Array* GetArrayValue() const
558 NS_ABORT_IF_FALSE(UnitHasArrayValue(), "not an array value");
559 return mValue.mArray;
562 nsIURI* GetURLValue() const
564 NS_ABORT_IF_FALSE(mUnit == eCSSUnit_URL || mUnit == eCSSUnit_Image,
565 "not a URL value");
566 return mUnit == eCSSUnit_URL ?
567 mValue.mURL->GetURI() : mValue.mImage->GetURI();
570 nsCSSValueGradient* GetGradientValue() const
572 NS_ABORT_IF_FALSE(mUnit == eCSSUnit_Gradient, "not a gradient value");
573 return mValue.mGradient;
576 nsCSSValueTokenStream* GetTokenStreamValue() const
578 NS_ABORT_IF_FALSE(mUnit == eCSSUnit_TokenStream, "not a token stream value");
579 return mValue.mTokenStream;
582 nsCSSValueSharedList* GetSharedListValue() const
584 NS_ABORT_IF_FALSE(mUnit == eCSSUnit_SharedList, "not a shared list value");
585 return mValue.mSharedList;
588 mozilla::FontFamilyList* GetFontFamilyListValue() const
590 NS_ABORT_IF_FALSE(mUnit == eCSSUnit_FontFamilyList,
591 "not a font family list value");
592 NS_ASSERTION(mValue.mFontFamilyList != nullptr,
593 "font family list value should never be null");
594 return mValue.mFontFamilyList;
597 // bodies of these are below
598 inline nsCSSValuePair& GetPairValue();
599 inline const nsCSSValuePair& GetPairValue() const;
601 inline nsCSSRect& GetRectValue();
602 inline const nsCSSRect& GetRectValue() const;
604 inline nsCSSValueList* GetListValue();
605 inline const nsCSSValueList* GetListValue() const;
607 inline nsCSSValuePairList* GetPairListValue();
608 inline const nsCSSValuePairList* GetPairListValue() const;
610 inline nsCSSValueTriplet& GetTripletValue();
611 inline const nsCSSValueTriplet& GetTripletValue() const;
614 mozilla::css::URLValue* GetURLStructValue() const
616 // Not allowing this for Image values, because if the caller takes
617 // a ref to them they won't be able to delete them properly.
618 NS_ABORT_IF_FALSE(mUnit == eCSSUnit_URL, "not a URL value");
619 return mValue.mURL;
622 mozilla::css::ImageValue* GetImageStructValue() const
624 NS_ABORT_IF_FALSE(mUnit == eCSSUnit_Image, "not an Image value");
625 return mValue.mImage;
628 mozilla::css::GridTemplateAreasValue* GetGridTemplateAreas() const
630 NS_ABORT_IF_FALSE(mUnit == eCSSUnit_GridTemplateAreas,
631 "not a grid-template-areas value");
632 return mValue.mGridTemplateAreas;
635 const char16_t* GetOriginalURLValue() const
637 NS_ABORT_IF_FALSE(mUnit == eCSSUnit_URL || mUnit == eCSSUnit_Image,
638 "not a URL value");
639 return GetBufferValue(mUnit == eCSSUnit_URL ?
640 mValue.mURL->mString :
641 mValue.mImage->mString);
644 // Not making this inline because that would force us to include
645 // imgIRequest.h, which leads to REQUIRES hell, since this header is included
646 // all over.
647 imgRequestProxy* GetImageValue(nsIDocument* aDocument) const;
649 nscoord GetFixedLength(nsPresContext* aPresContext) const;
650 nscoord GetPixelLength() const;
652 void Reset() // sets to null
654 if (mUnit != eCSSUnit_Null)
655 DoReset();
657 private:
658 void DoReset();
660 public:
661 void SetIntValue(int32_t aValue, nsCSSUnit aUnit);
662 void SetPercentValue(float aValue);
663 void SetFloatValue(float aValue, nsCSSUnit aUnit);
664 void SetStringValue(const nsString& aValue, nsCSSUnit aUnit);
665 void SetColorValue(nscolor aValue);
666 void SetIntegerColorValue(nscolor aValue, nsCSSUnit aUnit);
667 void SetFloatColorValue(float aComponent1,
668 float aComponent2,
669 float aComponent3,
670 float aAlpha, nsCSSUnit aUnit);
671 void SetArrayValue(nsCSSValue::Array* aArray, nsCSSUnit aUnit);
672 void SetURLValue(mozilla::css::URLValue* aURI);
673 void SetImageValue(mozilla::css::ImageValue* aImage);
674 void SetGradientValue(nsCSSValueGradient* aGradient);
675 void SetTokenStreamValue(nsCSSValueTokenStream* aTokenStream);
676 void SetGridTemplateAreas(mozilla::css::GridTemplateAreasValue* aValue);
677 void SetFontFamilyListValue(mozilla::css::FontFamilyListRefCnt* aFontListValue);
678 void SetPairValue(const nsCSSValuePair* aPair);
679 void SetPairValue(const nsCSSValue& xValue, const nsCSSValue& yValue);
680 void SetSharedListValue(nsCSSValueSharedList* aList);
681 void SetDependentListValue(nsCSSValueList* aList);
682 void SetDependentPairListValue(nsCSSValuePairList* aList);
683 void SetTripletValue(const nsCSSValueTriplet* aTriplet);
684 void SetTripletValue(const nsCSSValue& xValue, const nsCSSValue& yValue, const nsCSSValue& zValue);
685 void SetAutoValue();
686 void SetInheritValue();
687 void SetInitialValue();
688 void SetUnsetValue();
689 void SetNoneValue();
690 void SetAllValue();
691 void SetNormalValue();
692 void SetSystemFontValue();
693 void SetDummyValue();
694 void SetDummyInheritValue();
696 // These are a little different - they allocate storage for you and
697 // return a handle.
698 nsCSSRect& SetRectValue();
699 nsCSSValueList* SetListValue();
700 nsCSSValuePairList* SetPairListValue();
702 void StartImageLoad(nsIDocument* aDocument) const; // Only pretend const
704 // Initializes as a function value with the specified function id.
705 Array* InitFunction(nsCSSKeyword aFunctionId, uint32_t aNumArgs);
706 // Checks if this is a function value with the specified function id.
707 bool EqualsFunction(nsCSSKeyword aFunctionId) const;
709 // Returns an already addrefed buffer. Guaranteed to return non-null.
710 // (Will abort on allocation failure.)
711 static already_AddRefed<nsStringBuffer>
712 BufferFromString(const nsString& aValue);
714 size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
716 private:
717 static const char16_t* GetBufferValue(nsStringBuffer* aBuffer) {
718 return static_cast<char16_t*>(aBuffer->Data());
721 protected:
722 nsCSSUnit mUnit;
723 union {
724 int32_t mInt;
725 float mFloat;
726 // Note: the capacity of the buffer may exceed the length of the string.
727 // If we're of a string type, mString is not null.
728 nsStringBuffer* mString;
729 nscolor mColor;
730 Array* mArray;
731 mozilla::css::URLValue* mURL;
732 mozilla::css::ImageValue* mImage;
733 mozilla::css::GridTemplateAreasValue* mGridTemplateAreas;
734 nsCSSValueGradient* mGradient;
735 nsCSSValueTokenStream* mTokenStream;
736 nsCSSValuePair_heap* mPair;
737 nsCSSRect_heap* mRect;
738 nsCSSValueTriplet_heap* mTriplet;
739 nsCSSValueList_heap* mList;
740 nsCSSValueList* mListDependent;
741 nsCSSValueSharedList* mSharedList;
742 nsCSSValuePairList_heap* mPairList;
743 nsCSSValuePairList* mPairListDependent;
744 nsCSSValueFloatColor* mFloatColor;
745 mozilla::css::FontFamilyListRefCnt* mFontFamilyList;
746 } mValue;
749 struct nsCSSValue::Array MOZ_FINAL {
751 // return |Array| with reference count of zero
752 static Array* Create(size_t aItemCount) {
753 return new (aItemCount) Array(aItemCount);
756 nsCSSValue& operator[](size_t aIndex) {
757 NS_ABORT_IF_FALSE(aIndex < mCount, "out of range");
758 return mArray[aIndex];
761 const nsCSSValue& operator[](size_t aIndex) const {
762 NS_ABORT_IF_FALSE(aIndex < mCount, "out of range");
763 return mArray[aIndex];
766 nsCSSValue& Item(size_t aIndex) { return (*this)[aIndex]; }
767 const nsCSSValue& Item(size_t aIndex) const { return (*this)[aIndex]; }
769 size_t Count() const { return mCount; }
771 bool operator==(const Array& aOther) const
773 if (mCount != aOther.mCount)
774 return false;
775 for (size_t i = 0; i < mCount; ++i)
776 if ((*this)[i] != aOther[i])
777 return false;
778 return true;
781 // XXXdholbert This uses a size_t ref count. Should we use a variant
782 // of NS_INLINE_DECL_REFCOUNTING that takes a type as an argument?
783 void AddRef() {
784 if (mRefCnt == size_t(-1)) { // really want SIZE_MAX
785 NS_WARNING("refcount overflow, leaking nsCSSValue::Array");
786 return;
788 ++mRefCnt;
789 NS_LOG_ADDREF(this, mRefCnt, "nsCSSValue::Array", sizeof(*this));
791 void Release() {
792 if (mRefCnt == size_t(-1)) { // really want SIZE_MAX
793 NS_WARNING("refcount overflow, leaking nsCSSValue::Array");
794 return;
796 --mRefCnt;
797 NS_LOG_RELEASE(this, mRefCnt, "nsCSSValue::Array");
798 if (mRefCnt == 0)
799 delete this;
802 private:
804 size_t mRefCnt;
805 const size_t mCount;
806 // This must be the last sub-object, since we extend this array to
807 // be of size mCount; it needs to be a sub-object so it gets proper
808 // alignment.
809 nsCSSValue mArray[1];
811 void* operator new(size_t aSelfSize, size_t aItemCount) CPP_THROW_NEW {
812 NS_ABORT_IF_FALSE(aItemCount > 0, "cannot have a 0 item count");
813 return ::operator new(aSelfSize + sizeof(nsCSSValue) * (aItemCount - 1));
816 void operator delete(void* aPtr) { ::operator delete(aPtr); }
818 nsCSSValue* First() { return mArray; }
820 const nsCSSValue* First() const { return mArray; }
822 #define CSSVALUE_LIST_FOR_EXTRA_VALUES(var) \
823 for (nsCSSValue *var = First() + 1, *var##_end = First() + mCount; \
824 var != var##_end; ++var)
826 explicit Array(size_t aItemCount)
827 : mRefCnt(0)
828 , mCount(aItemCount)
830 MOZ_COUNT_CTOR(nsCSSValue::Array);
831 CSSVALUE_LIST_FOR_EXTRA_VALUES(val) {
832 new (val) nsCSSValue();
836 ~Array()
838 MOZ_COUNT_DTOR(nsCSSValue::Array);
839 CSSVALUE_LIST_FOR_EXTRA_VALUES(val) {
840 val->~nsCSSValue();
844 size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
846 #undef CSSVALUE_LIST_FOR_EXTRA_VALUES
848 private:
849 Array(const Array& aOther) MOZ_DELETE;
850 Array& operator=(const Array& aOther) MOZ_DELETE;
853 // Prefer nsCSSValue::Array for lists of fixed size.
854 struct nsCSSValueList {
855 nsCSSValueList() : mNext(nullptr) { MOZ_COUNT_CTOR(nsCSSValueList); }
856 ~nsCSSValueList();
858 nsCSSValueList* Clone() const; // makes a deep copy
859 void CloneInto(nsCSSValueList* aList) const; // makes a deep copy into aList
860 void AppendToString(nsCSSProperty aProperty, nsAString& aResult,
861 nsCSSValue::Serialization aValueSerialization) const;
863 bool operator==(nsCSSValueList const& aOther) const;
864 bool operator!=(const nsCSSValueList& aOther) const
865 { return !(*this == aOther); }
867 size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
869 nsCSSValue mValue;
870 nsCSSValueList* mNext;
872 private:
873 nsCSSValueList(const nsCSSValueList& aCopy) // makes a shallow copy
874 : mValue(aCopy.mValue), mNext(nullptr)
876 MOZ_COUNT_CTOR(nsCSSValueList);
880 // nsCSSValueList_heap differs from nsCSSValueList only in being
881 // refcounted. It should not be necessary to use this class directly;
882 // it's an implementation detail of nsCSSValue.
883 struct nsCSSValueList_heap MOZ_FINAL : public nsCSSValueList {
884 NS_INLINE_DECL_REFCOUNTING(nsCSSValueList_heap)
886 size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
888 private:
889 // Private destructor, to discourage deletion outside of Release():
890 ~nsCSSValueList_heap()
895 // This is a reference counted list value. Note that the object is
896 // a wrapper for the reference count and a pointer to the head of the
897 // list, whereas the other list types (such as nsCSSValueList) do
898 // not have such a wrapper.
899 struct nsCSSValueSharedList MOZ_FINAL {
900 nsCSSValueSharedList()
901 : mHead(nullptr)
903 MOZ_COUNT_CTOR(nsCSSValueSharedList);
906 // Takes ownership of aList.
907 explicit nsCSSValueSharedList(nsCSSValueList* aList)
908 : mHead(aList)
910 MOZ_COUNT_CTOR(nsCSSValueSharedList);
913 private:
914 // Private destructor, to discourage deletion outside of Release():
915 ~nsCSSValueSharedList();
917 public:
918 NS_INLINE_DECL_REFCOUNTING(nsCSSValueSharedList)
920 void AppendToString(nsCSSProperty aProperty, nsAString& aResult,
921 nsCSSValue::Serialization aValueSerialization) const;
923 bool operator==(nsCSSValueSharedList const& aOther) const;
924 bool operator!=(const nsCSSValueSharedList& aOther) const
925 { return !(*this == aOther); }
927 size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
929 nsCSSValueList* mHead;
932 // This has to be here so that the relationship between nsCSSValueList
933 // and nsCSSValueList_heap is visible.
934 inline nsCSSValueList*
935 nsCSSValue::GetListValue()
937 if (mUnit == eCSSUnit_List)
938 return mValue.mList;
939 else {
940 NS_ABORT_IF_FALSE(mUnit == eCSSUnit_ListDep, "not a pairlist value");
941 return mValue.mListDependent;
945 inline const nsCSSValueList*
946 nsCSSValue::GetListValue() const
948 if (mUnit == eCSSUnit_List)
949 return mValue.mList;
950 else {
951 NS_ABORT_IF_FALSE(mUnit == eCSSUnit_ListDep, "not a pairlist value");
952 return mValue.mListDependent;
956 struct nsCSSRect {
957 nsCSSRect(void);
958 nsCSSRect(const nsCSSRect& aCopy);
959 ~nsCSSRect();
961 void AppendToString(nsCSSProperty aProperty, nsAString& aResult,
962 nsCSSValue::Serialization aValueSerialization) const;
964 bool operator==(const nsCSSRect& aOther) const {
965 return mTop == aOther.mTop &&
966 mRight == aOther.mRight &&
967 mBottom == aOther.mBottom &&
968 mLeft == aOther.mLeft;
971 bool operator!=(const nsCSSRect& aOther) const {
972 return mTop != aOther.mTop ||
973 mRight != aOther.mRight ||
974 mBottom != aOther.mBottom ||
975 mLeft != aOther.mLeft;
978 void SetAllSidesTo(const nsCSSValue& aValue);
980 bool AllSidesEqualTo(const nsCSSValue& aValue) const {
981 return mTop == aValue &&
982 mRight == aValue &&
983 mBottom == aValue &&
984 mLeft == aValue;
987 void Reset() {
988 mTop.Reset();
989 mRight.Reset();
990 mBottom.Reset();
991 mLeft.Reset();
994 bool HasValue() const {
995 return
996 mTop.GetUnit() != eCSSUnit_Null ||
997 mRight.GetUnit() != eCSSUnit_Null ||
998 mBottom.GetUnit() != eCSSUnit_Null ||
999 mLeft.GetUnit() != eCSSUnit_Null;
1002 nsCSSValue mTop;
1003 nsCSSValue mRight;
1004 nsCSSValue mBottom;
1005 nsCSSValue mLeft;
1007 typedef nsCSSValue nsCSSRect::*side_type;
1008 static const side_type sides[4];
1011 // nsCSSRect_heap differs from nsCSSRect only in being
1012 // refcounted. It should not be necessary to use this class directly;
1013 // it's an implementation detail of nsCSSValue.
1014 struct nsCSSRect_heap MOZ_FINAL : public nsCSSRect {
1015 NS_INLINE_DECL_REFCOUNTING(nsCSSRect_heap)
1017 size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
1019 private:
1020 // Private destructor, to discourage deletion outside of Release():
1021 ~nsCSSRect_heap()
1026 // This has to be here so that the relationship between nsCSSRect
1027 // and nsCSSRect_heap is visible.
1028 inline nsCSSRect&
1029 nsCSSValue::GetRectValue()
1031 NS_ABORT_IF_FALSE(mUnit == eCSSUnit_Rect, "not a rect value");
1032 return *mValue.mRect;
1035 inline const nsCSSRect&
1036 nsCSSValue::GetRectValue() const
1038 NS_ABORT_IF_FALSE(mUnit == eCSSUnit_Rect, "not a rect value");
1039 return *mValue.mRect;
1042 struct nsCSSValuePair {
1043 nsCSSValuePair()
1045 MOZ_COUNT_CTOR(nsCSSValuePair);
1047 explicit nsCSSValuePair(nsCSSUnit aUnit)
1048 : mXValue(aUnit), mYValue(aUnit)
1050 MOZ_COUNT_CTOR(nsCSSValuePair);
1052 nsCSSValuePair(const nsCSSValue& aXValue, const nsCSSValue& aYValue)
1053 : mXValue(aXValue), mYValue(aYValue)
1055 MOZ_COUNT_CTOR(nsCSSValuePair);
1057 nsCSSValuePair(const nsCSSValuePair& aCopy)
1058 : mXValue(aCopy.mXValue), mYValue(aCopy.mYValue)
1060 MOZ_COUNT_CTOR(nsCSSValuePair);
1062 ~nsCSSValuePair()
1064 MOZ_COUNT_DTOR(nsCSSValuePair);
1067 bool operator==(const nsCSSValuePair& aOther) const {
1068 return mXValue == aOther.mXValue &&
1069 mYValue == aOther.mYValue;
1072 bool operator!=(const nsCSSValuePair& aOther) const {
1073 return mXValue != aOther.mXValue ||
1074 mYValue != aOther.mYValue;
1077 bool BothValuesEqualTo(const nsCSSValue& aValue) const {
1078 return mXValue == aValue &&
1079 mYValue == aValue;
1082 void SetBothValuesTo(const nsCSSValue& aValue) {
1083 mXValue = aValue;
1084 mYValue = aValue;
1087 void Reset() {
1088 mXValue.Reset();
1089 mYValue.Reset();
1092 bool HasValue() const {
1093 return mXValue.GetUnit() != eCSSUnit_Null ||
1094 mYValue.GetUnit() != eCSSUnit_Null;
1097 void AppendToString(nsCSSProperty aProperty, nsAString& aResult,
1098 nsCSSValue::Serialization aValueSerialization) const;
1100 size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
1102 nsCSSValue mXValue;
1103 nsCSSValue mYValue;
1106 // nsCSSValuePair_heap differs from nsCSSValuePair only in being
1107 // refcounted. It should not be necessary to use this class directly;
1108 // it's an implementation detail of nsCSSValue.
1109 struct nsCSSValuePair_heap MOZ_FINAL : public nsCSSValuePair {
1110 // forward constructor
1111 nsCSSValuePair_heap(const nsCSSValue& aXValue, const nsCSSValue& aYValue)
1112 : nsCSSValuePair(aXValue, aYValue)
1115 NS_INLINE_DECL_REFCOUNTING(nsCSSValuePair_heap)
1117 size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
1119 private:
1120 // Private destructor, to discourage deletion outside of Release():
1121 ~nsCSSValuePair_heap()
1126 struct nsCSSValueTriplet {
1127 nsCSSValueTriplet()
1129 MOZ_COUNT_CTOR(nsCSSValueTriplet);
1131 explicit nsCSSValueTriplet(nsCSSUnit aUnit)
1132 : mXValue(aUnit), mYValue(aUnit), mZValue(aUnit)
1134 MOZ_COUNT_CTOR(nsCSSValueTriplet);
1136 nsCSSValueTriplet(const nsCSSValue& aXValue,
1137 const nsCSSValue& aYValue,
1138 const nsCSSValue& aZValue)
1139 : mXValue(aXValue), mYValue(aYValue), mZValue(aZValue)
1141 MOZ_COUNT_CTOR(nsCSSValueTriplet);
1143 nsCSSValueTriplet(const nsCSSValueTriplet& aCopy)
1144 : mXValue(aCopy.mXValue), mYValue(aCopy.mYValue), mZValue(aCopy.mZValue)
1146 MOZ_COUNT_CTOR(nsCSSValueTriplet);
1148 ~nsCSSValueTriplet()
1150 MOZ_COUNT_DTOR(nsCSSValueTriplet);
1153 bool operator==(const nsCSSValueTriplet& aOther) const {
1154 return mXValue == aOther.mXValue &&
1155 mYValue == aOther.mYValue &&
1156 mZValue == aOther.mZValue;
1159 bool operator!=(const nsCSSValueTriplet& aOther) const {
1160 return mXValue != aOther.mXValue ||
1161 mYValue != aOther.mYValue ||
1162 mZValue != aOther.mZValue;
1165 bool AllValuesEqualTo(const nsCSSValue& aValue) const {
1166 return mXValue == aValue &&
1167 mYValue == aValue &&
1168 mZValue == aValue;
1171 void SetAllValuesTo(const nsCSSValue& aValue) {
1172 mXValue = aValue;
1173 mYValue = aValue;
1174 mZValue = aValue;
1177 void Reset() {
1178 mXValue.Reset();
1179 mYValue.Reset();
1180 mZValue.Reset();
1183 bool HasValue() const {
1184 return mXValue.GetUnit() != eCSSUnit_Null ||
1185 mYValue.GetUnit() != eCSSUnit_Null ||
1186 mZValue.GetUnit() != eCSSUnit_Null;
1189 void AppendToString(nsCSSProperty aProperty, nsAString& aResult,
1190 nsCSSValue::Serialization aValueSerialization) const;
1192 nsCSSValue mXValue;
1193 nsCSSValue mYValue;
1194 nsCSSValue mZValue;
1197 // nsCSSValueTriplet_heap differs from nsCSSValueTriplet only in being
1198 // refcounted. It should not be necessary to use this class directly;
1199 // it's an implementation detail of nsCSSValue.
1200 struct nsCSSValueTriplet_heap MOZ_FINAL : public nsCSSValueTriplet {
1201 // forward constructor
1202 nsCSSValueTriplet_heap(const nsCSSValue& aXValue, const nsCSSValue& aYValue, const nsCSSValue& aZValue)
1203 : nsCSSValueTriplet(aXValue, aYValue, aZValue)
1206 NS_INLINE_DECL_REFCOUNTING(nsCSSValueTriplet_heap)
1208 size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
1210 private:
1211 // Private destructor, to discourage deletion outside of Release():
1212 ~nsCSSValueTriplet_heap()
1217 // This has to be here so that the relationship between nsCSSValuePair
1218 // and nsCSSValuePair_heap is visible.
1219 inline nsCSSValuePair&
1220 nsCSSValue::GetPairValue()
1222 NS_ABORT_IF_FALSE(mUnit == eCSSUnit_Pair, "not a pair value");
1223 return *mValue.mPair;
1226 inline const nsCSSValuePair&
1227 nsCSSValue::GetPairValue() const
1229 NS_ABORT_IF_FALSE(mUnit == eCSSUnit_Pair, "not a pair value");
1230 return *mValue.mPair;
1233 inline nsCSSValueTriplet&
1234 nsCSSValue::GetTripletValue()
1236 NS_ABORT_IF_FALSE(mUnit == eCSSUnit_Triplet, "not a triplet value");
1237 return *mValue.mTriplet;
1240 inline const nsCSSValueTriplet&
1241 nsCSSValue::GetTripletValue() const
1243 NS_ABORT_IF_FALSE(mUnit == eCSSUnit_Triplet, "not a triplet value");
1244 return *mValue.mTriplet;
1247 // Maybe should be replaced with nsCSSValueList and nsCSSValue::Array?
1248 struct nsCSSValuePairList {
1249 nsCSSValuePairList() : mNext(nullptr) { MOZ_COUNT_CTOR(nsCSSValuePairList); }
1250 ~nsCSSValuePairList();
1252 nsCSSValuePairList* Clone() const; // makes a deep copy
1253 void AppendToString(nsCSSProperty aProperty, nsAString& aResult,
1254 nsCSSValue::Serialization aValueSerialization) const;
1256 bool operator==(const nsCSSValuePairList& aOther) const;
1257 bool operator!=(const nsCSSValuePairList& aOther) const
1258 { return !(*this == aOther); }
1260 size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
1262 nsCSSValue mXValue;
1263 nsCSSValue mYValue;
1264 nsCSSValuePairList* mNext;
1266 private:
1267 nsCSSValuePairList(const nsCSSValuePairList& aCopy) // makes a shallow copy
1268 : mXValue(aCopy.mXValue), mYValue(aCopy.mYValue), mNext(nullptr)
1270 MOZ_COUNT_CTOR(nsCSSValuePairList);
1274 // nsCSSValuePairList_heap differs from nsCSSValuePairList only in being
1275 // refcounted. It should not be necessary to use this class directly;
1276 // it's an implementation detail of nsCSSValue.
1277 struct nsCSSValuePairList_heap MOZ_FINAL : public nsCSSValuePairList {
1278 NS_INLINE_DECL_REFCOUNTING(nsCSSValuePairList_heap)
1280 size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
1282 private:
1283 // Private destructor, to discourage deletion outside of Release():
1284 ~nsCSSValuePairList_heap()
1289 // This has to be here so that the relationship between nsCSSValuePairList
1290 // and nsCSSValuePairList_heap is visible.
1291 inline nsCSSValuePairList*
1292 nsCSSValue::GetPairListValue()
1294 if (mUnit == eCSSUnit_PairList)
1295 return mValue.mPairList;
1296 else {
1297 NS_ABORT_IF_FALSE (mUnit == eCSSUnit_PairListDep, "not a pairlist value");
1298 return mValue.mPairListDependent;
1302 inline const nsCSSValuePairList*
1303 nsCSSValue::GetPairListValue() const
1305 if (mUnit == eCSSUnit_PairList)
1306 return mValue.mPairList;
1307 else {
1308 NS_ABORT_IF_FALSE (mUnit == eCSSUnit_PairListDep, "not a pairlist value");
1309 return mValue.mPairListDependent;
1313 struct nsCSSValueGradientStop {
1314 public:
1315 nsCSSValueGradientStop();
1316 // needed to keep bloat logs happy when we use the TArray
1317 // in nsCSSValueGradient
1318 nsCSSValueGradientStop(const nsCSSValueGradientStop& aOther);
1319 ~nsCSSValueGradientStop();
1321 nsCSSValue mLocation;
1322 nsCSSValue mColor;
1324 bool operator==(const nsCSSValueGradientStop& aOther) const
1326 return (mLocation == aOther.mLocation &&
1327 mColor == aOther.mColor);
1330 bool operator!=(const nsCSSValueGradientStop& aOther) const
1332 return !(*this == aOther);
1335 size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
1338 struct nsCSSValueGradient MOZ_FINAL {
1339 nsCSSValueGradient(bool aIsRadial, bool aIsRepeating);
1341 // true if gradient is radial, false if it is linear
1342 bool mIsRadial;
1343 bool mIsRepeating;
1344 bool mIsLegacySyntax;
1345 bool mIsExplicitSize;
1346 // line position and angle
1347 nsCSSValuePair mBgPos;
1348 nsCSSValue mAngle;
1350 // Only meaningful if mIsRadial is true
1351 private:
1352 nsCSSValue mRadialValues[2];
1353 public:
1354 nsCSSValue& GetRadialShape()
1356 MOZ_ASSERT(!mIsExplicitSize);
1357 return mRadialValues[0];
1359 const nsCSSValue& GetRadialShape() const
1361 MOZ_ASSERT(!mIsExplicitSize);
1362 return mRadialValues[0];
1364 nsCSSValue& GetRadialSize()
1366 MOZ_ASSERT(!mIsExplicitSize);
1367 return mRadialValues[1];
1369 const nsCSSValue& GetRadialSize() const
1371 MOZ_ASSERT(!mIsExplicitSize);
1372 return mRadialValues[1];
1374 nsCSSValue& GetRadiusX()
1376 MOZ_ASSERT(mIsExplicitSize);
1377 return mRadialValues[0];
1379 const nsCSSValue& GetRadiusX() const
1381 MOZ_ASSERT(mIsExplicitSize);
1382 return mRadialValues[0];
1384 nsCSSValue& GetRadiusY()
1386 MOZ_ASSERT(mIsExplicitSize);
1387 return mRadialValues[1];
1389 const nsCSSValue& GetRadiusY() const
1391 MOZ_ASSERT(mIsExplicitSize);
1392 return mRadialValues[1];
1395 InfallibleTArray<nsCSSValueGradientStop> mStops;
1397 bool operator==(const nsCSSValueGradient& aOther) const
1399 if (mIsRadial != aOther.mIsRadial ||
1400 mIsRepeating != aOther.mIsRepeating ||
1401 mIsLegacySyntax != aOther.mIsLegacySyntax ||
1402 mIsExplicitSize != aOther.mIsExplicitSize ||
1403 mBgPos != aOther.mBgPos ||
1404 mAngle != aOther.mAngle ||
1405 mRadialValues[0] != aOther.mRadialValues[0] ||
1406 mRadialValues[1] != aOther.mRadialValues[1])
1407 return false;
1409 if (mStops.Length() != aOther.mStops.Length())
1410 return false;
1412 for (uint32_t i = 0; i < mStops.Length(); i++) {
1413 if (mStops[i] != aOther.mStops[i])
1414 return false;
1417 return true;
1420 bool operator!=(const nsCSSValueGradient& aOther) const
1422 return !(*this == aOther);
1425 NS_INLINE_DECL_REFCOUNTING(nsCSSValueGradient)
1427 size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
1429 private:
1430 // Private destructor, to discourage deletion outside of Release():
1431 ~nsCSSValueGradient()
1435 nsCSSValueGradient(const nsCSSValueGradient& aOther) MOZ_DELETE;
1436 nsCSSValueGradient& operator=(const nsCSSValueGradient& aOther) MOZ_DELETE;
1439 struct nsCSSValueTokenStream MOZ_FINAL {
1440 nsCSSValueTokenStream();
1442 private:
1443 // Private destructor, to discourage deletion outside of Release():
1444 ~nsCSSValueTokenStream();
1446 public:
1447 bool operator==(const nsCSSValueTokenStream& aOther) const
1449 bool eq;
1450 return mPropertyID == aOther.mPropertyID &&
1451 mShorthandPropertyID == aOther.mShorthandPropertyID &&
1452 mTokenStream.Equals(aOther.mTokenStream) &&
1453 (mBaseURI == aOther.mBaseURI ||
1454 (mBaseURI && aOther.mBaseURI &&
1455 NS_SUCCEEDED(mBaseURI->Equals(aOther.mBaseURI, &eq)) &&
1456 eq)) &&
1457 (mSheetURI == aOther.mSheetURI ||
1458 (mSheetURI && aOther.mSheetURI &&
1459 NS_SUCCEEDED(mSheetURI->Equals(aOther.mSheetURI, &eq)) &&
1460 eq)) &&
1461 (mSheetPrincipal == aOther.mSheetPrincipal ||
1462 (mSheetPrincipal && aOther.mSheetPrincipal &&
1463 NS_SUCCEEDED(mSheetPrincipal->Equals(aOther.mSheetPrincipal,
1464 &eq)) &&
1465 eq));
1468 bool operator!=(const nsCSSValueTokenStream& aOther) const
1470 return !(*this == aOther);
1473 NS_INLINE_DECL_REFCOUNTING(nsCSSValueTokenStream)
1475 size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
1477 // The property that has mTokenStream as its unparsed specified value.
1478 // When a variable reference is used in a shorthand property, a
1479 // TokenStream value is stored as the specified value for each of its
1480 // component longhand properties.
1481 nsCSSProperty mPropertyID;
1483 // The shorthand property that had a value with a variable reference,
1484 // which caused the longhand property identified by mPropertyID to have
1485 // a TokenStream value.
1486 nsCSSProperty mShorthandPropertyID;
1488 // The unparsed CSS corresponding to the specified value of the property.
1489 // When the value of a shorthand property has a variable reference, the
1490 // same mTokenStream value is used on each of the nsCSSValueTokenStream
1491 // objects that will be set by parsing the shorthand.
1492 nsString mTokenStream;
1494 nsCOMPtr<nsIURI> mBaseURI;
1495 nsCOMPtr<nsIURI> mSheetURI;
1496 nsCOMPtr<nsIPrincipal> mSheetPrincipal;
1497 mozilla::CSSStyleSheet* mSheet;
1498 uint32_t mLineNumber;
1499 uint32_t mLineOffset;
1501 // This table is used to hold a reference on to any ImageValue that results
1502 // from re-parsing this token stream at computed value time. When properties
1503 // like background-image contain a normal url(), the Declaration's data block
1504 // will hold a reference to the ImageValue. When a token stream is used,
1505 // the Declaration only holds on to this nsCSSValueTokenStream object, and
1506 // the ImageValue would only exist for the duration of
1507 // nsRuleNode::WalkRuleTree, in the AutoCSSValueArray. So instead when
1508 // we re-parse a token stream and get an ImageValue, we record it in this
1509 // table so that the Declaration can be the object that keeps holding
1510 // a reference to it.
1511 nsTHashtable<nsRefPtrHashKey<mozilla::css::ImageValue> > mImageValues;
1513 private:
1514 nsCSSValueTokenStream(const nsCSSValueTokenStream& aOther) MOZ_DELETE;
1515 nsCSSValueTokenStream& operator=(const nsCSSValueTokenStream& aOther) MOZ_DELETE;
1518 class nsCSSValueFloatColor MOZ_FINAL {
1519 public:
1520 nsCSSValueFloatColor(float aComponent1, float aComponent2, float aComponent3,
1521 float aAlpha)
1522 : mComponent1(aComponent1)
1523 , mComponent2(aComponent2)
1524 , mComponent3(aComponent3)
1525 , mAlpha(aAlpha)
1527 MOZ_COUNT_CTOR(nsCSSValueFloatColor);
1530 private:
1531 // Private destructor, to discourage deletion outside of Release():
1532 ~nsCSSValueFloatColor()
1534 MOZ_COUNT_DTOR(nsCSSValueFloatColor);
1537 public:
1538 bool operator==(nsCSSValueFloatColor& aOther) const;
1540 nscolor GetColorValue(nsCSSUnit aUnit) const;
1541 bool IsNonTransparentColor() const;
1543 void AppendToString(nsCSSUnit aUnit, nsAString& aResult) const;
1545 size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
1547 NS_INLINE_DECL_REFCOUNTING(nsCSSValueFloatColor)
1549 private:
1550 // FIXME: We should not be clamping specified RGB color components.
1551 float mComponent1; // 0..1 for RGB, 0..360 for HSL
1552 float mComponent2; // 0..1
1553 float mComponent3; // 0..1
1554 float mAlpha; // 0..1
1556 nsCSSValueFloatColor(const nsCSSValueFloatColor& aOther) MOZ_DELETE;
1557 nsCSSValueFloatColor& operator=(const nsCSSValueFloatColor& aOther)
1558 MOZ_DELETE;
1561 struct nsCSSCornerSizes {
1562 nsCSSCornerSizes(void);
1563 nsCSSCornerSizes(const nsCSSCornerSizes& aCopy);
1564 ~nsCSSCornerSizes();
1566 // argument is a "full corner" constant from nsStyleConsts.h
1567 nsCSSValue const & GetCorner(uint32_t aCorner) const {
1568 return this->*corners[aCorner];
1570 nsCSSValue & GetCorner(uint32_t aCorner) {
1571 return this->*corners[aCorner];
1574 bool operator==(const nsCSSCornerSizes& aOther) const {
1575 NS_FOR_CSS_FULL_CORNERS(corner) {
1576 if (this->GetCorner(corner) != aOther.GetCorner(corner))
1577 return false;
1579 return true;
1582 bool operator!=(const nsCSSCornerSizes& aOther) const {
1583 NS_FOR_CSS_FULL_CORNERS(corner) {
1584 if (this->GetCorner(corner) != aOther.GetCorner(corner))
1585 return true;
1587 return false;
1590 bool HasValue() const {
1591 NS_FOR_CSS_FULL_CORNERS(corner) {
1592 if (this->GetCorner(corner).GetUnit() != eCSSUnit_Null)
1593 return true;
1595 return false;
1598 void Reset();
1600 nsCSSValue mTopLeft;
1601 nsCSSValue mTopRight;
1602 nsCSSValue mBottomRight;
1603 nsCSSValue mBottomLeft;
1605 protected:
1606 typedef nsCSSValue nsCSSCornerSizes::*corner_type;
1607 static const corner_type corners[4];
1610 #endif /* nsCSSValue_h___ */