Thu, 15 Jan 2015 21:03:48 +0100
Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | /* |
michael@0 | 7 | * A struct that represents the value (type and actual data) of an |
michael@0 | 8 | * attribute. |
michael@0 | 9 | */ |
michael@0 | 10 | |
michael@0 | 11 | #ifndef nsAttrValue_h___ |
michael@0 | 12 | #define nsAttrValue_h___ |
michael@0 | 13 | |
michael@0 | 14 | #include "nscore.h" |
michael@0 | 15 | #include "nsStringGlue.h" |
michael@0 | 16 | #include "nsStringBuffer.h" |
michael@0 | 17 | #include "nsColor.h" |
michael@0 | 18 | #include "nsCaseTreatment.h" |
michael@0 | 19 | #include "nsMargin.h" |
michael@0 | 20 | #include "nsCOMPtr.h" |
michael@0 | 21 | #include "SVGAttrValueWrapper.h" |
michael@0 | 22 | #include "nsTArrayForwardDeclare.h" |
michael@0 | 23 | #include "nsIAtom.h" |
michael@0 | 24 | #include "mozilla/MemoryReporting.h" |
michael@0 | 25 | #include "mozilla/dom/BindingDeclarations.h" |
michael@0 | 26 | |
michael@0 | 27 | class nsAString; |
michael@0 | 28 | class nsIDocument; |
michael@0 | 29 | class nsStyledElementNotElementCSSInlineStyle; |
michael@0 | 30 | struct MiscContainer; |
michael@0 | 31 | |
michael@0 | 32 | namespace mozilla { |
michael@0 | 33 | namespace css { |
michael@0 | 34 | class StyleRule; |
michael@0 | 35 | struct URLValue; |
michael@0 | 36 | struct ImageValue; |
michael@0 | 37 | } |
michael@0 | 38 | } |
michael@0 | 39 | |
michael@0 | 40 | #define NS_ATTRVALUE_MAX_STRINGLENGTH_ATOM 12 |
michael@0 | 41 | |
michael@0 | 42 | #define NS_ATTRVALUE_BASETYPE_MASK (uintptr_t(3)) |
michael@0 | 43 | #define NS_ATTRVALUE_POINTERVALUE_MASK (~NS_ATTRVALUE_BASETYPE_MASK) |
michael@0 | 44 | |
michael@0 | 45 | #define NS_ATTRVALUE_INTEGERTYPE_BITS 4 |
michael@0 | 46 | #define NS_ATTRVALUE_INTEGERTYPE_MASK (uintptr_t((1 << NS_ATTRVALUE_INTEGERTYPE_BITS) - 1)) |
michael@0 | 47 | #define NS_ATTRVALUE_INTEGERTYPE_MULTIPLIER (1 << NS_ATTRVALUE_INTEGERTYPE_BITS) |
michael@0 | 48 | #define NS_ATTRVALUE_INTEGERTYPE_MAXVALUE ((1 << (31 - NS_ATTRVALUE_INTEGERTYPE_BITS)) - 1) |
michael@0 | 49 | #define NS_ATTRVALUE_INTEGERTYPE_MINVALUE (-NS_ATTRVALUE_INTEGERTYPE_MAXVALUE - 1) |
michael@0 | 50 | |
michael@0 | 51 | #define NS_ATTRVALUE_ENUMTABLEINDEX_BITS (32 - 16 - NS_ATTRVALUE_INTEGERTYPE_BITS) |
michael@0 | 52 | #define NS_ATTRVALUE_ENUMTABLE_VALUE_NEEDS_TO_UPPER (1 << (NS_ATTRVALUE_ENUMTABLEINDEX_BITS - 1)) |
michael@0 | 53 | #define NS_ATTRVALUE_ENUMTABLEINDEX_MAXVALUE (NS_ATTRVALUE_ENUMTABLE_VALUE_NEEDS_TO_UPPER - 1) |
michael@0 | 54 | #define NS_ATTRVALUE_ENUMTABLEINDEX_MASK \ |
michael@0 | 55 | (uintptr_t((((1 << NS_ATTRVALUE_ENUMTABLEINDEX_BITS) - 1) &~ NS_ATTRVALUE_ENUMTABLE_VALUE_NEEDS_TO_UPPER))) |
michael@0 | 56 | |
michael@0 | 57 | /** |
michael@0 | 58 | * A class used to construct a nsString from a nsStringBuffer (we might |
michael@0 | 59 | * want to move this to nsString at some point). |
michael@0 | 60 | * |
michael@0 | 61 | * WARNING: Note that nsCheapString doesn't take an explicit length -- it |
michael@0 | 62 | * assumes the string is maximally large, given the nsStringBuffer's storage |
michael@0 | 63 | * size. This means the given string buffer *must* be sized exactly correctly |
michael@0 | 64 | * for the string it contains (including one byte for a null terminator). If |
michael@0 | 65 | * it has any unused storage space, then that will result in bogus characters |
michael@0 | 66 | * at the end of our nsCheapString. |
michael@0 | 67 | */ |
michael@0 | 68 | class nsCheapString : public nsString { |
michael@0 | 69 | public: |
michael@0 | 70 | nsCheapString(nsStringBuffer* aBuf) |
michael@0 | 71 | { |
michael@0 | 72 | if (aBuf) |
michael@0 | 73 | aBuf->ToString(aBuf->StorageSize()/sizeof(char16_t) - 1, *this); |
michael@0 | 74 | } |
michael@0 | 75 | }; |
michael@0 | 76 | |
michael@0 | 77 | class nsAttrValue { |
michael@0 | 78 | friend struct MiscContainer; |
michael@0 | 79 | public: |
michael@0 | 80 | typedef nsTArray< nsCOMPtr<nsIAtom> > AtomArray; |
michael@0 | 81 | |
michael@0 | 82 | // This has to be the same as in ValueBaseType |
michael@0 | 83 | enum ValueType { |
michael@0 | 84 | eString = 0x00, // 00 |
michael@0 | 85 | // 01 this value indicates an 'misc' struct |
michael@0 | 86 | eAtom = 0x02, // 10 |
michael@0 | 87 | eInteger = 0x03, // 0011 |
michael@0 | 88 | eColor = 0x07, // 0111 |
michael@0 | 89 | eEnum = 0x0B, // 1011 This should eventually die |
michael@0 | 90 | ePercent = 0x0F, // 1111 |
michael@0 | 91 | // Values below here won't matter, they'll be always stored in the 'misc' |
michael@0 | 92 | // struct. |
michael@0 | 93 | eCSSStyleRule = 0x10 |
michael@0 | 94 | ,eURL = 0x11 |
michael@0 | 95 | ,eImage = 0x12 |
michael@0 | 96 | ,eAtomArray = 0x13 |
michael@0 | 97 | ,eDoubleValue = 0x14 |
michael@0 | 98 | ,eIntMarginValue = 0x15 |
michael@0 | 99 | ,eSVGAngle = 0x16 |
michael@0 | 100 | ,eSVGTypesBegin = eSVGAngle |
michael@0 | 101 | ,eSVGIntegerPair = 0x17 |
michael@0 | 102 | ,eSVGLength = 0x18 |
michael@0 | 103 | ,eSVGLengthList = 0x19 |
michael@0 | 104 | ,eSVGNumberList = 0x1A |
michael@0 | 105 | ,eSVGNumberPair = 0x1B |
michael@0 | 106 | ,eSVGPathData = 0x1C |
michael@0 | 107 | ,eSVGPointList = 0x1D |
michael@0 | 108 | ,eSVGPreserveAspectRatio = 0x1E |
michael@0 | 109 | ,eSVGStringList = 0x1F |
michael@0 | 110 | ,eSVGTransformList = 0x20 |
michael@0 | 111 | ,eSVGViewBox = 0x21 |
michael@0 | 112 | ,eSVGTypesEnd = eSVGViewBox |
michael@0 | 113 | }; |
michael@0 | 114 | |
michael@0 | 115 | nsAttrValue(); |
michael@0 | 116 | nsAttrValue(const nsAttrValue& aOther); |
michael@0 | 117 | explicit nsAttrValue(const nsAString& aValue); |
michael@0 | 118 | explicit nsAttrValue(nsIAtom* aValue); |
michael@0 | 119 | nsAttrValue(mozilla::css::StyleRule* aValue, const nsAString* aSerialized); |
michael@0 | 120 | explicit nsAttrValue(const nsIntMargin& aValue); |
michael@0 | 121 | ~nsAttrValue(); |
michael@0 | 122 | |
michael@0 | 123 | inline const nsAttrValue& operator=(const nsAttrValue& aOther); |
michael@0 | 124 | |
michael@0 | 125 | static nsresult Init(); |
michael@0 | 126 | static void Shutdown(); |
michael@0 | 127 | |
michael@0 | 128 | ValueType Type() const; |
michael@0 | 129 | |
michael@0 | 130 | void Reset(); |
michael@0 | 131 | |
michael@0 | 132 | void SetTo(const nsAttrValue& aOther); |
michael@0 | 133 | void SetTo(const nsAString& aValue); |
michael@0 | 134 | void SetTo(nsIAtom* aValue); |
michael@0 | 135 | void SetTo(int16_t aInt); |
michael@0 | 136 | void SetTo(int32_t aInt, const nsAString* aSerialized); |
michael@0 | 137 | void SetTo(double aValue, const nsAString* aSerialized); |
michael@0 | 138 | void SetTo(mozilla::css::StyleRule* aValue, const nsAString* aSerialized); |
michael@0 | 139 | void SetTo(mozilla::css::URLValue* aValue, const nsAString* aSerialized); |
michael@0 | 140 | void SetTo(const nsIntMargin& aValue); |
michael@0 | 141 | void SetTo(const nsSVGAngle& aValue, const nsAString* aSerialized); |
michael@0 | 142 | void SetTo(const nsSVGIntegerPair& aValue, const nsAString* aSerialized); |
michael@0 | 143 | void SetTo(const nsSVGLength2& aValue, const nsAString* aSerialized); |
michael@0 | 144 | void SetTo(const mozilla::SVGLengthList& aValue, |
michael@0 | 145 | const nsAString* aSerialized); |
michael@0 | 146 | void SetTo(const mozilla::SVGNumberList& aValue, |
michael@0 | 147 | const nsAString* aSerialized); |
michael@0 | 148 | void SetTo(const nsSVGNumberPair& aValue, const nsAString* aSerialized); |
michael@0 | 149 | void SetTo(const mozilla::SVGPathData& aValue, const nsAString* aSerialized); |
michael@0 | 150 | void SetTo(const mozilla::SVGPointList& aValue, const nsAString* aSerialized); |
michael@0 | 151 | void SetTo(const mozilla::SVGAnimatedPreserveAspectRatio& aValue, |
michael@0 | 152 | const nsAString* aSerialized); |
michael@0 | 153 | void SetTo(const mozilla::SVGStringList& aValue, |
michael@0 | 154 | const nsAString* aSerialized); |
michael@0 | 155 | void SetTo(const mozilla::SVGTransformList& aValue, |
michael@0 | 156 | const nsAString* aSerialized); |
michael@0 | 157 | void SetTo(const nsSVGViewBox& aValue, const nsAString* aSerialized); |
michael@0 | 158 | |
michael@0 | 159 | /** |
michael@0 | 160 | * Sets this object with the string or atom representation of aValue. |
michael@0 | 161 | * |
michael@0 | 162 | * After calling this method, this object will have type eString unless the |
michael@0 | 163 | * type of aValue is eAtom, in which case this object will also have type |
michael@0 | 164 | * eAtom. |
michael@0 | 165 | */ |
michael@0 | 166 | void SetToSerialized(const nsAttrValue& aValue); |
michael@0 | 167 | |
michael@0 | 168 | void SwapValueWith(nsAttrValue& aOther); |
michael@0 | 169 | |
michael@0 | 170 | void ToString(nsAString& aResult) const; |
michael@0 | 171 | inline void ToString(mozilla::dom::DOMString& aResult) const; |
michael@0 | 172 | |
michael@0 | 173 | /** |
michael@0 | 174 | * Returns the value of this object as an atom. If necessary, the value will |
michael@0 | 175 | * first be serialised using ToString before converting to an atom. |
michael@0 | 176 | */ |
michael@0 | 177 | already_AddRefed<nsIAtom> GetAsAtom() const; |
michael@0 | 178 | |
michael@0 | 179 | // Methods to get value. These methods do not convert so only use them |
michael@0 | 180 | // to retrieve the datatype that this nsAttrValue has. |
michael@0 | 181 | inline bool IsEmptyString() const; |
michael@0 | 182 | const nsCheapString GetStringValue() const; |
michael@0 | 183 | inline nsIAtom* GetAtomValue() const; |
michael@0 | 184 | inline int32_t GetIntegerValue() const; |
michael@0 | 185 | bool GetColorValue(nscolor& aColor) const; |
michael@0 | 186 | inline int16_t GetEnumValue() const; |
michael@0 | 187 | inline float GetPercentValue() const; |
michael@0 | 188 | inline AtomArray* GetAtomArrayValue() const; |
michael@0 | 189 | inline mozilla::css::StyleRule* GetCSSStyleRuleValue() const; |
michael@0 | 190 | inline mozilla::css::URLValue* GetURLValue() const; |
michael@0 | 191 | inline mozilla::css::ImageValue* GetImageValue() const; |
michael@0 | 192 | inline double GetDoubleValue() const; |
michael@0 | 193 | bool GetIntMarginValue(nsIntMargin& aMargin) const; |
michael@0 | 194 | |
michael@0 | 195 | /** |
michael@0 | 196 | * Returns the string corresponding to the stored enum value. |
michael@0 | 197 | * |
michael@0 | 198 | * @param aResult the string representing the enum tag |
michael@0 | 199 | * @param aRealTag wheter we want to have the real tag or the saved one |
michael@0 | 200 | */ |
michael@0 | 201 | void GetEnumString(nsAString& aResult, bool aRealTag) const; |
michael@0 | 202 | |
michael@0 | 203 | // Methods to get access to atoms we may have |
michael@0 | 204 | // Returns the number of atoms we have; 0 if we have none. It's OK |
michael@0 | 205 | // to call this without checking the type first; it handles that. |
michael@0 | 206 | uint32_t GetAtomCount() const; |
michael@0 | 207 | // Returns the atom at aIndex (0-based). Do not call this with |
michael@0 | 208 | // aIndex >= GetAtomCount(). |
michael@0 | 209 | nsIAtom* AtomAt(int32_t aIndex) const; |
michael@0 | 210 | |
michael@0 | 211 | uint32_t HashValue() const; |
michael@0 | 212 | bool Equals(const nsAttrValue& aOther) const; |
michael@0 | 213 | // aCaseSensitive == eIgnoreCase means ASCII case-insenstive matching |
michael@0 | 214 | bool Equals(const nsAString& aValue, nsCaseTreatment aCaseSensitive) const; |
michael@0 | 215 | bool Equals(nsIAtom* aValue, nsCaseTreatment aCaseSensitive) const; |
michael@0 | 216 | |
michael@0 | 217 | /** |
michael@0 | 218 | * Compares this object with aOther according to their string representation. |
michael@0 | 219 | * |
michael@0 | 220 | * For example, when called on an object with type eInteger and value 4, and |
michael@0 | 221 | * given aOther of type eString and value "4", EqualsAsStrings will return |
michael@0 | 222 | * true (while Equals will return false). |
michael@0 | 223 | */ |
michael@0 | 224 | bool EqualsAsStrings(const nsAttrValue& aOther) const; |
michael@0 | 225 | |
michael@0 | 226 | /** |
michael@0 | 227 | * Returns true if this AttrValue is equal to the given atom, or is an |
michael@0 | 228 | * array which contains the given atom. |
michael@0 | 229 | */ |
michael@0 | 230 | bool Contains(nsIAtom* aValue, nsCaseTreatment aCaseSensitive) const; |
michael@0 | 231 | /** |
michael@0 | 232 | * Returns true if this AttrValue is an atom equal to the given |
michael@0 | 233 | * string, or is an array of atoms which contains the given string. |
michael@0 | 234 | * This always does a case-sensitive comparison. |
michael@0 | 235 | */ |
michael@0 | 236 | bool Contains(const nsAString& aValue) const; |
michael@0 | 237 | |
michael@0 | 238 | void ParseAtom(const nsAString& aValue); |
michael@0 | 239 | void ParseAtomArray(const nsAString& aValue); |
michael@0 | 240 | void ParseStringOrAtom(const nsAString& aValue); |
michael@0 | 241 | |
michael@0 | 242 | /** |
michael@0 | 243 | * Structure for a mapping from int (enum) values to strings. When you use |
michael@0 | 244 | * it you generally create an array of them. |
michael@0 | 245 | * Instantiate like this: |
michael@0 | 246 | * EnumTable myTable[] = { |
michael@0 | 247 | * { "string1", 1 }, |
michael@0 | 248 | * { "string2", 2 }, |
michael@0 | 249 | * { 0 } |
michael@0 | 250 | * } |
michael@0 | 251 | */ |
michael@0 | 252 | struct EnumTable { |
michael@0 | 253 | /** The string the value maps to */ |
michael@0 | 254 | const char* tag; |
michael@0 | 255 | /** The enum value that maps to this string */ |
michael@0 | 256 | int16_t value; |
michael@0 | 257 | }; |
michael@0 | 258 | |
michael@0 | 259 | /** |
michael@0 | 260 | * Parse into an enum value. |
michael@0 | 261 | * |
michael@0 | 262 | * @param aValue the string to find the value for |
michael@0 | 263 | * @param aTable the enumeration to map with |
michael@0 | 264 | * @param aCaseSensitive specify if the parsing has to be case sensitive |
michael@0 | 265 | * @param aDefaultValue if non-null, this function will always return true. |
michael@0 | 266 | * Failure to parse aValue as one of the values in aTable will just |
michael@0 | 267 | * cause aDefaultValue->value to be stored as the enumeration value. |
michael@0 | 268 | * @return whether the enum value was found or not |
michael@0 | 269 | */ |
michael@0 | 270 | bool ParseEnumValue(const nsAString& aValue, |
michael@0 | 271 | const EnumTable* aTable, |
michael@0 | 272 | bool aCaseSensitive, |
michael@0 | 273 | const EnumTable* aDefaultValue = nullptr); |
michael@0 | 274 | |
michael@0 | 275 | /** |
michael@0 | 276 | * Parse a string into an integer. Can optionally parse percent (n%). |
michael@0 | 277 | * This method explicitly sets a lower bound of zero on the element, |
michael@0 | 278 | * whether it be percent or raw integer. |
michael@0 | 279 | * |
michael@0 | 280 | * @param aString the string to parse |
michael@0 | 281 | * @return whether the value could be parsed |
michael@0 | 282 | * |
michael@0 | 283 | * @see http://www.whatwg.org/html/#rules-for-parsing-dimension-values |
michael@0 | 284 | */ |
michael@0 | 285 | bool ParseSpecialIntValue(const nsAString& aString); |
michael@0 | 286 | |
michael@0 | 287 | |
michael@0 | 288 | /** |
michael@0 | 289 | * Parse a string value into an integer. |
michael@0 | 290 | * |
michael@0 | 291 | * @param aString the string to parse |
michael@0 | 292 | * @return whether the value could be parsed |
michael@0 | 293 | */ |
michael@0 | 294 | bool ParseIntValue(const nsAString& aString) { |
michael@0 | 295 | return ParseIntWithBounds(aString, INT32_MIN, INT32_MAX); |
michael@0 | 296 | } |
michael@0 | 297 | |
michael@0 | 298 | /** |
michael@0 | 299 | * Parse a string value into an integer with minimum value and maximum value. |
michael@0 | 300 | * |
michael@0 | 301 | * @param aString the string to parse |
michael@0 | 302 | * @param aMin the minimum value (if value is less it will be bumped up) |
michael@0 | 303 | * @param aMax the maximum value (if value is greater it will be chopped down) |
michael@0 | 304 | * @return whether the value could be parsed |
michael@0 | 305 | */ |
michael@0 | 306 | bool ParseIntWithBounds(const nsAString& aString, int32_t aMin, |
michael@0 | 307 | int32_t aMax = INT32_MAX); |
michael@0 | 308 | |
michael@0 | 309 | /** |
michael@0 | 310 | * Parse a string value into a non-negative integer. |
michael@0 | 311 | * This method follows the rules for parsing non-negative integer from: |
michael@0 | 312 | * http://dev.w3.org/html5/spec/infrastructure.html#rules-for-parsing-non-negative-integers |
michael@0 | 313 | * |
michael@0 | 314 | * @param aString the string to parse |
michael@0 | 315 | * @return whether the value is valid |
michael@0 | 316 | */ |
michael@0 | 317 | bool ParseNonNegativeIntValue(const nsAString& aString); |
michael@0 | 318 | |
michael@0 | 319 | /** |
michael@0 | 320 | * Parse a string value into a positive integer. |
michael@0 | 321 | * This method follows the rules for parsing non-negative integer from: |
michael@0 | 322 | * http://dev.w3.org/html5/spec/infrastructure.html#rules-for-parsing-non-negative-integers |
michael@0 | 323 | * In addition of these rules, the value has to be greater than zero. |
michael@0 | 324 | * |
michael@0 | 325 | * This is generally used for parsing content attributes which reflecting IDL |
michael@0 | 326 | * attributes are limited to only non-negative numbers greater than zero, see: |
michael@0 | 327 | * http://dev.w3.org/html5/spec/common-dom-interfaces.html#limited-to-only-non-negative-numbers-greater-than-zero |
michael@0 | 328 | * |
michael@0 | 329 | * @param aString the string to parse |
michael@0 | 330 | * @return whether the value was valid |
michael@0 | 331 | */ |
michael@0 | 332 | bool ParsePositiveIntValue(const nsAString& aString); |
michael@0 | 333 | |
michael@0 | 334 | /** |
michael@0 | 335 | * Parse a string into a color. This implements what HTML5 calls the |
michael@0 | 336 | * "rules for parsing a legacy color value". |
michael@0 | 337 | * |
michael@0 | 338 | * @param aString the string to parse |
michael@0 | 339 | * @return whether the value could be parsed |
michael@0 | 340 | */ |
michael@0 | 341 | bool ParseColor(const nsAString& aString); |
michael@0 | 342 | |
michael@0 | 343 | /** |
michael@0 | 344 | * Parse a string value into a double-precision floating point value. |
michael@0 | 345 | * |
michael@0 | 346 | * @param aString the string to parse |
michael@0 | 347 | * @return whether the value could be parsed |
michael@0 | 348 | */ |
michael@0 | 349 | bool ParseDoubleValue(const nsAString& aString); |
michael@0 | 350 | |
michael@0 | 351 | /** |
michael@0 | 352 | * Parse a lazy URI. This just sets up the storage for the URI; it |
michael@0 | 353 | * doesn't actually allocate it. |
michael@0 | 354 | */ |
michael@0 | 355 | bool ParseLazyURIValue(const nsAString& aString); |
michael@0 | 356 | |
michael@0 | 357 | /** |
michael@0 | 358 | * Parse a margin string of format 'top, right, bottom, left' into |
michael@0 | 359 | * an nsIntMargin. |
michael@0 | 360 | * |
michael@0 | 361 | * @param aString the string to parse |
michael@0 | 362 | * @return whether the value could be parsed |
michael@0 | 363 | */ |
michael@0 | 364 | bool ParseIntMarginValue(const nsAString& aString); |
michael@0 | 365 | |
michael@0 | 366 | /** |
michael@0 | 367 | * Convert a URL nsAttrValue to an Image nsAttrValue. |
michael@0 | 368 | * |
michael@0 | 369 | * @param aDocument the document this nsAttrValue belongs to. |
michael@0 | 370 | */ |
michael@0 | 371 | void LoadImage(nsIDocument* aDocument); |
michael@0 | 372 | |
michael@0 | 373 | /** |
michael@0 | 374 | * Parse a string into a CSS style rule. |
michael@0 | 375 | * |
michael@0 | 376 | * @param aString the style attribute value to be parsed. |
michael@0 | 377 | * @param aElement the element the attribute is set on. |
michael@0 | 378 | */ |
michael@0 | 379 | bool ParseStyleAttribute(const nsAString& aString, |
michael@0 | 380 | nsStyledElementNotElementCSSInlineStyle* aElement); |
michael@0 | 381 | |
michael@0 | 382 | size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const; |
michael@0 | 383 | |
michael@0 | 384 | private: |
michael@0 | 385 | // These have to be the same as in ValueType |
michael@0 | 386 | enum ValueBaseType { |
michael@0 | 387 | eStringBase = eString, // 00 |
michael@0 | 388 | eOtherBase = 0x01, // 01 |
michael@0 | 389 | eAtomBase = eAtom, // 10 |
michael@0 | 390 | eIntegerBase = 0x03 // 11 |
michael@0 | 391 | }; |
michael@0 | 392 | |
michael@0 | 393 | inline ValueBaseType BaseType() const; |
michael@0 | 394 | inline bool IsSVGType(ValueType aType) const; |
michael@0 | 395 | |
michael@0 | 396 | /** |
michael@0 | 397 | * Get the index of an EnumTable in the sEnumTableArray. |
michael@0 | 398 | * If the EnumTable is not in the sEnumTableArray, it is added. |
michael@0 | 399 | * |
michael@0 | 400 | * @param aTable the EnumTable to get the index of. |
michael@0 | 401 | * @return the index of the EnumTable. |
michael@0 | 402 | */ |
michael@0 | 403 | int16_t GetEnumTableIndex(const EnumTable* aTable); |
michael@0 | 404 | |
michael@0 | 405 | inline void SetPtrValueAndType(void* aValue, ValueBaseType aType); |
michael@0 | 406 | void SetIntValueAndType(int32_t aValue, ValueType aType, |
michael@0 | 407 | const nsAString* aStringValue); |
michael@0 | 408 | void SetColorValue(nscolor aColor, const nsAString& aString); |
michael@0 | 409 | void SetMiscAtomOrString(const nsAString* aValue); |
michael@0 | 410 | void ResetMiscAtomOrString(); |
michael@0 | 411 | void SetSVGType(ValueType aType, const void* aValue, |
michael@0 | 412 | const nsAString* aSerialized); |
michael@0 | 413 | inline void ResetIfSet(); |
michael@0 | 414 | |
michael@0 | 415 | inline void* GetPtr() const; |
michael@0 | 416 | inline MiscContainer* GetMiscContainer() const; |
michael@0 | 417 | inline int32_t GetIntInternal() const; |
michael@0 | 418 | |
michael@0 | 419 | // Clears the current MiscContainer. This will return null if there is no |
michael@0 | 420 | // existing container. |
michael@0 | 421 | MiscContainer* ClearMiscContainer(); |
michael@0 | 422 | // Like ClearMiscContainer, except allocates a new container if one does not |
michael@0 | 423 | // exist already. |
michael@0 | 424 | MiscContainer* EnsureEmptyMiscContainer(); |
michael@0 | 425 | bool EnsureEmptyAtomArray(); |
michael@0 | 426 | already_AddRefed<nsStringBuffer> |
michael@0 | 427 | GetStringBuffer(const nsAString& aValue) const; |
michael@0 | 428 | // aStrict is set true if stringifying the return value equals with |
michael@0 | 429 | // aValue. |
michael@0 | 430 | int32_t StringToInteger(const nsAString& aValue, |
michael@0 | 431 | bool* aStrict, |
michael@0 | 432 | nsresult* aErrorCode, |
michael@0 | 433 | bool aCanBePercent = false, |
michael@0 | 434 | bool* aIsPercent = nullptr) const; |
michael@0 | 435 | // Given an enum table and a particular entry in that table, return |
michael@0 | 436 | // the actual integer value we should store. |
michael@0 | 437 | int32_t EnumTableEntryToValue(const EnumTable* aEnumTable, |
michael@0 | 438 | const EnumTable* aTableEntry); |
michael@0 | 439 | |
michael@0 | 440 | static nsTArray<const EnumTable*>* sEnumTableArray; |
michael@0 | 441 | |
michael@0 | 442 | uintptr_t mBits; |
michael@0 | 443 | }; |
michael@0 | 444 | |
michael@0 | 445 | inline const nsAttrValue& |
michael@0 | 446 | nsAttrValue::operator=(const nsAttrValue& aOther) |
michael@0 | 447 | { |
michael@0 | 448 | SetTo(aOther); |
michael@0 | 449 | return *this; |
michael@0 | 450 | } |
michael@0 | 451 | |
michael@0 | 452 | inline nsIAtom* |
michael@0 | 453 | nsAttrValue::GetAtomValue() const |
michael@0 | 454 | { |
michael@0 | 455 | NS_PRECONDITION(Type() == eAtom, "wrong type"); |
michael@0 | 456 | return reinterpret_cast<nsIAtom*>(GetPtr()); |
michael@0 | 457 | } |
michael@0 | 458 | |
michael@0 | 459 | inline nsAttrValue::ValueBaseType |
michael@0 | 460 | nsAttrValue::BaseType() const |
michael@0 | 461 | { |
michael@0 | 462 | return static_cast<ValueBaseType>(mBits & NS_ATTRVALUE_BASETYPE_MASK); |
michael@0 | 463 | } |
michael@0 | 464 | |
michael@0 | 465 | inline void* |
michael@0 | 466 | nsAttrValue::GetPtr() const |
michael@0 | 467 | { |
michael@0 | 468 | NS_ASSERTION(BaseType() != eIntegerBase, |
michael@0 | 469 | "getting pointer from non-pointer"); |
michael@0 | 470 | return reinterpret_cast<void*>(mBits & NS_ATTRVALUE_POINTERVALUE_MASK); |
michael@0 | 471 | } |
michael@0 | 472 | |
michael@0 | 473 | inline bool |
michael@0 | 474 | nsAttrValue::IsEmptyString() const |
michael@0 | 475 | { |
michael@0 | 476 | return !mBits; |
michael@0 | 477 | } |
michael@0 | 478 | |
michael@0 | 479 | inline void |
michael@0 | 480 | nsAttrValue::ToString(mozilla::dom::DOMString& aResult) const |
michael@0 | 481 | { |
michael@0 | 482 | switch (Type()) { |
michael@0 | 483 | case eString: |
michael@0 | 484 | { |
michael@0 | 485 | nsStringBuffer* str = static_cast<nsStringBuffer*>(GetPtr()); |
michael@0 | 486 | if (str) { |
michael@0 | 487 | aResult.SetStringBuffer(str, str->StorageSize()/sizeof(char16_t) - 1); |
michael@0 | 488 | } |
michael@0 | 489 | // else aResult is already empty |
michael@0 | 490 | return; |
michael@0 | 491 | } |
michael@0 | 492 | case eAtom: |
michael@0 | 493 | { |
michael@0 | 494 | nsIAtom *atom = static_cast<nsIAtom*>(GetPtr()); |
michael@0 | 495 | aResult.SetStringBuffer(atom->GetStringBuffer(), atom->GetLength()); |
michael@0 | 496 | break; |
michael@0 | 497 | } |
michael@0 | 498 | default: |
michael@0 | 499 | { |
michael@0 | 500 | ToString(aResult.AsAString()); |
michael@0 | 501 | } |
michael@0 | 502 | } |
michael@0 | 503 | } |
michael@0 | 504 | |
michael@0 | 505 | #endif |