2004-01-15 17:07:27 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2004-01-15 17:07:27 +00:00
|
|
|
|
2006-03-30 08:03:04 +00:00
|
|
|
/*
|
|
|
|
* A struct that represents the value (type and actual data) of an
|
|
|
|
* attribute.
|
|
|
|
*/
|
|
|
|
|
2004-01-15 17:07:27 +00:00
|
|
|
#ifndef nsAttrValue_h___
|
|
|
|
#define nsAttrValue_h___
|
|
|
|
|
|
|
|
#include "nscore.h"
|
2014-04-10 17:39:20 +00:00
|
|
|
#include "nsStringGlue.h"
|
2005-02-02 22:58:01 +00:00
|
|
|
#include "nsStringBuffer.h"
|
2004-03-04 02:06:28 +00:00
|
|
|
#include "nsColor.h"
|
2005-09-11 19:20:08 +00:00
|
|
|
#include "nsCaseTreatment.h"
|
2010-06-25 02:01:07 +00:00
|
|
|
#include "nsMargin.h"
|
2010-08-11 21:05:28 +00:00
|
|
|
#include "nsCOMPtr.h"
|
2012-02-15 23:40:46 +00:00
|
|
|
#include "SVGAttrValueWrapper.h"
|
2012-12-19 01:16:06 +00:00
|
|
|
#include "nsTArrayForwardDeclare.h"
|
2013-01-29 14:42:14 +00:00
|
|
|
#include "nsIAtom.h"
|
2013-06-23 12:03:39 +00:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2013-01-29 14:42:14 +00:00
|
|
|
#include "mozilla/dom/BindingDeclarations.h"
|
2004-01-15 17:07:27 +00:00
|
|
|
|
|
|
|
class nsAString;
|
2012-08-24 17:50:49 +00:00
|
|
|
class nsIDocument;
|
2012-09-30 16:40:24 +00:00
|
|
|
class nsStyledElementNotElementCSSInlineStyle;
|
|
|
|
struct MiscContainer;
|
2004-01-15 17:07:27 +00:00
|
|
|
|
2011-03-11 02:48:57 +00:00
|
|
|
namespace mozilla {
|
|
|
|
namespace css {
|
|
|
|
class StyleRule;
|
2012-08-24 17:50:49 +00:00
|
|
|
struct URLValue;
|
|
|
|
struct ImageValue;
|
2011-03-11 02:48:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-02-10 09:08:06 +00:00
|
|
|
#define NS_ATTRVALUE_MAX_STRINGLENGTH_ATOM 12
|
2004-03-04 02:06:28 +00:00
|
|
|
|
2012-10-02 08:24:11 +00:00
|
|
|
#define NS_ATTRVALUE_BASETYPE_MASK (uintptr_t(3))
|
2004-03-04 02:06:28 +00:00
|
|
|
#define NS_ATTRVALUE_POINTERVALUE_MASK (~NS_ATTRVALUE_BASETYPE_MASK)
|
|
|
|
|
2008-02-17 02:50:44 +00:00
|
|
|
#define NS_ATTRVALUE_INTEGERTYPE_BITS 4
|
2012-10-02 08:24:11 +00:00
|
|
|
#define NS_ATTRVALUE_INTEGERTYPE_MASK (uintptr_t((1 << NS_ATTRVALUE_INTEGERTYPE_BITS) - 1))
|
2004-03-04 02:06:28 +00:00
|
|
|
#define NS_ATTRVALUE_INTEGERTYPE_MULTIPLIER (1 << NS_ATTRVALUE_INTEGERTYPE_BITS)
|
2005-01-24 10:43:14 +00:00
|
|
|
#define NS_ATTRVALUE_INTEGERTYPE_MAXVALUE ((1 << (31 - NS_ATTRVALUE_INTEGERTYPE_BITS)) - 1)
|
2004-03-04 02:06:28 +00:00
|
|
|
#define NS_ATTRVALUE_INTEGERTYPE_MINVALUE (-NS_ATTRVALUE_INTEGERTYPE_MAXVALUE - 1)
|
2004-01-15 17:07:27 +00:00
|
|
|
|
2005-01-25 00:02:58 +00:00
|
|
|
#define NS_ATTRVALUE_ENUMTABLEINDEX_BITS (32 - 16 - NS_ATTRVALUE_INTEGERTYPE_BITS)
|
2008-09-26 10:39:18 +00:00
|
|
|
#define NS_ATTRVALUE_ENUMTABLE_VALUE_NEEDS_TO_UPPER (1 << (NS_ATTRVALUE_ENUMTABLEINDEX_BITS - 1))
|
|
|
|
#define NS_ATTRVALUE_ENUMTABLEINDEX_MAXVALUE (NS_ATTRVALUE_ENUMTABLE_VALUE_NEEDS_TO_UPPER - 1)
|
|
|
|
#define NS_ATTRVALUE_ENUMTABLEINDEX_MASK \
|
2012-10-02 08:24:11 +00:00
|
|
|
(uintptr_t((((1 << NS_ATTRVALUE_ENUMTABLEINDEX_BITS) - 1) &~ NS_ATTRVALUE_ENUMTABLE_VALUE_NEEDS_TO_UPPER)))
|
2005-01-25 00:02:58 +00:00
|
|
|
|
2005-02-02 22:58:01 +00:00
|
|
|
/**
|
|
|
|
* A class used to construct a nsString from a nsStringBuffer (we might
|
|
|
|
* want to move this to nsString at some point).
|
2013-08-29 15:39:56 +00:00
|
|
|
*
|
|
|
|
* WARNING: Note that nsCheapString doesn't take an explicit length -- it
|
|
|
|
* assumes the string is maximally large, given the nsStringBuffer's storage
|
|
|
|
* size. This means the given string buffer *must* be sized exactly correctly
|
|
|
|
* for the string it contains (including one byte for a null terminator). If
|
|
|
|
* it has any unused storage space, then that will result in bogus characters
|
|
|
|
* at the end of our nsCheapString.
|
2005-02-02 22:58:01 +00:00
|
|
|
*/
|
|
|
|
class nsCheapString : public nsString {
|
|
|
|
public:
|
2014-08-05 13:19:51 +00:00
|
|
|
explicit nsCheapString(nsStringBuffer* aBuf)
|
2005-02-02 22:58:01 +00:00
|
|
|
{
|
|
|
|
if (aBuf)
|
2014-01-04 15:02:17 +00:00
|
|
|
aBuf->ToString(aBuf->StorageSize()/sizeof(char16_t) - 1, *this);
|
2005-02-02 22:58:01 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2004-01-15 17:07:27 +00:00
|
|
|
class nsAttrValue {
|
2012-09-30 16:40:24 +00:00
|
|
|
friend struct MiscContainer;
|
2004-01-15 17:07:27 +00:00
|
|
|
public:
|
2010-08-11 21:05:28 +00:00
|
|
|
typedef nsTArray< nsCOMPtr<nsIAtom> > AtomArray;
|
|
|
|
|
2004-03-04 02:06:28 +00:00
|
|
|
// This has to be the same as in ValueBaseType
|
|
|
|
enum ValueType {
|
2008-02-17 02:50:44 +00:00
|
|
|
eString = 0x00, // 00
|
|
|
|
// 01 this value indicates an 'misc' struct
|
|
|
|
eAtom = 0x02, // 10
|
|
|
|
eInteger = 0x03, // 0011
|
|
|
|
eColor = 0x07, // 0111
|
|
|
|
eEnum = 0x0B, // 1011 This should eventually die
|
|
|
|
ePercent = 0x0F, // 1111
|
2008-09-26 10:39:18 +00:00
|
|
|
// Values below here won't matter, they'll be always stored in the 'misc'
|
|
|
|
// struct.
|
2013-05-24 13:27:51 +00:00
|
|
|
eCSSStyleRule = 0x10
|
|
|
|
,eURL = 0x11
|
|
|
|
,eImage = 0x12
|
|
|
|
,eAtomArray = 0x13
|
|
|
|
,eDoubleValue = 0x14
|
|
|
|
,eIntMarginValue = 0x15
|
|
|
|
,eSVGAngle = 0x16
|
|
|
|
,eSVGTypesBegin = eSVGAngle
|
|
|
|
,eSVGIntegerPair = 0x17
|
|
|
|
,eSVGLength = 0x18
|
|
|
|
,eSVGLengthList = 0x19
|
|
|
|
,eSVGNumberList = 0x1A
|
|
|
|
,eSVGNumberPair = 0x1B
|
|
|
|
,eSVGPathData = 0x1C
|
|
|
|
,eSVGPointList = 0x1D
|
|
|
|
,eSVGPreserveAspectRatio = 0x1E
|
|
|
|
,eSVGStringList = 0x1F
|
|
|
|
,eSVGTransformList = 0x20
|
|
|
|
,eSVGViewBox = 0x21
|
|
|
|
,eSVGTypesEnd = eSVGViewBox
|
2004-03-04 02:06:28 +00:00
|
|
|
};
|
|
|
|
|
2012-09-30 16:40:24 +00:00
|
|
|
nsAttrValue();
|
|
|
|
nsAttrValue(const nsAttrValue& aOther);
|
|
|
|
explicit nsAttrValue(const nsAString& aValue);
|
|
|
|
explicit nsAttrValue(nsIAtom* aValue);
|
|
|
|
nsAttrValue(mozilla::css::StyleRule* aValue, const nsAString* aSerialized);
|
|
|
|
explicit nsAttrValue(const nsIntMargin& aValue);
|
|
|
|
~nsAttrValue();
|
|
|
|
|
|
|
|
inline const nsAttrValue& operator=(const nsAttrValue& aOther);
|
|
|
|
|
|
|
|
static nsresult Init();
|
|
|
|
static void Shutdown();
|
|
|
|
|
2004-03-04 02:06:28 +00:00
|
|
|
ValueType Type() const;
|
|
|
|
|
2004-01-15 17:07:27 +00:00
|
|
|
void Reset();
|
2004-03-04 02:06:28 +00:00
|
|
|
|
2004-01-26 19:22:05 +00:00
|
|
|
void SetTo(const nsAttrValue& aOther);
|
2004-01-15 17:07:27 +00:00
|
|
|
void SetTo(const nsAString& aValue);
|
2012-02-15 23:40:44 +00:00
|
|
|
void SetTo(nsIAtom* aValue);
|
2012-08-22 15:56:38 +00:00
|
|
|
void SetTo(int16_t aInt);
|
|
|
|
void SetTo(int32_t aInt, const nsAString* aSerialized);
|
2012-02-15 23:40:45 +00:00
|
|
|
void SetTo(double aValue, const nsAString* aSerialized);
|
2011-03-11 02:48:57 +00:00
|
|
|
void SetTo(mozilla::css::StyleRule* aValue, const nsAString* aSerialized);
|
2012-08-24 17:50:49 +00:00
|
|
|
void SetTo(mozilla::css::URLValue* aValue, const nsAString* aSerialized);
|
2010-06-25 02:01:07 +00:00
|
|
|
void SetTo(const nsIntMargin& aValue);
|
2012-02-15 23:40:45 +00:00
|
|
|
void SetTo(const nsSVGAngle& aValue, const nsAString* aSerialized);
|
2012-02-15 23:40:45 +00:00
|
|
|
void SetTo(const nsSVGIntegerPair& aValue, const nsAString* aSerialized);
|
2012-02-15 23:40:45 +00:00
|
|
|
void SetTo(const nsSVGLength2& aValue, const nsAString* aSerialized);
|
2012-02-15 23:40:45 +00:00
|
|
|
void SetTo(const mozilla::SVGLengthList& aValue,
|
|
|
|
const nsAString* aSerialized);
|
2012-02-15 23:40:46 +00:00
|
|
|
void SetTo(const mozilla::SVGNumberList& aValue,
|
|
|
|
const nsAString* aSerialized);
|
2012-02-15 23:40:45 +00:00
|
|
|
void SetTo(const nsSVGNumberPair& aValue, const nsAString* aSerialized);
|
2012-02-15 23:40:46 +00:00
|
|
|
void SetTo(const mozilla::SVGPathData& aValue, const nsAString* aSerialized);
|
2012-02-15 23:40:46 +00:00
|
|
|
void SetTo(const mozilla::SVGPointList& aValue, const nsAString* aSerialized);
|
2012-02-15 23:40:46 +00:00
|
|
|
void SetTo(const mozilla::SVGAnimatedPreserveAspectRatio& aValue,
|
|
|
|
const nsAString* aSerialized);
|
2012-02-15 23:40:46 +00:00
|
|
|
void SetTo(const mozilla::SVGStringList& aValue,
|
|
|
|
const nsAString* aSerialized);
|
2012-02-15 23:40:46 +00:00
|
|
|
void SetTo(const mozilla::SVGTransformList& aValue,
|
|
|
|
const nsAString* aSerialized);
|
2012-02-15 23:40:46 +00:00
|
|
|
void SetTo(const nsSVGViewBox& aValue, const nsAString* aSerialized);
|
2004-01-26 19:22:05 +00:00
|
|
|
|
2012-02-14 02:00:56 +00:00
|
|
|
/**
|
|
|
|
* Sets this object with the string or atom representation of aValue.
|
|
|
|
*
|
|
|
|
* After calling this method, this object will have type eString unless the
|
|
|
|
* type of aValue is eAtom, in which case this object will also have type
|
|
|
|
* eAtom.
|
|
|
|
*/
|
|
|
|
void SetToSerialized(const nsAttrValue& aValue);
|
|
|
|
|
2004-01-26 19:22:05 +00:00
|
|
|
void SwapValueWith(nsAttrValue& aOther);
|
2004-01-15 17:07:27 +00:00
|
|
|
|
|
|
|
void ToString(nsAString& aResult) const;
|
2013-01-29 14:42:14 +00:00
|
|
|
inline void ToString(mozilla::dom::DOMString& aResult) const;
|
|
|
|
|
2012-02-14 02:00:56 +00:00
|
|
|
/**
|
|
|
|
* Returns the value of this object as an atom. If necessary, the value will
|
|
|
|
* first be serialised using ToString before converting to an atom.
|
|
|
|
*/
|
|
|
|
already_AddRefed<nsIAtom> GetAsAtom() const;
|
2004-01-15 17:07:27 +00:00
|
|
|
|
2004-01-26 19:22:05 +00:00
|
|
|
// Methods to get value. These methods do not convert so only use them
|
|
|
|
// to retrieve the datatype that this nsAttrValue has.
|
2011-09-29 06:19:26 +00:00
|
|
|
inline bool IsEmptyString() const;
|
2005-02-02 22:58:01 +00:00
|
|
|
const nsCheapString GetStringValue() const;
|
2004-03-04 02:06:28 +00:00
|
|
|
inline nsIAtom* GetAtomValue() const;
|
2012-08-22 15:56:38 +00:00
|
|
|
inline int32_t GetIntegerValue() const;
|
2011-09-29 06:19:26 +00:00
|
|
|
bool GetColorValue(nscolor& aColor) const;
|
2012-08-22 15:56:38 +00:00
|
|
|
inline int16_t GetEnumValue() const;
|
2004-03-04 02:06:28 +00:00
|
|
|
inline float GetPercentValue() const;
|
2010-08-11 21:05:28 +00:00
|
|
|
inline AtomArray* GetAtomArrayValue() const;
|
2011-03-11 02:48:57 +00:00
|
|
|
inline mozilla::css::StyleRule* GetCSSStyleRuleValue() const;
|
2012-08-24 17:50:49 +00:00
|
|
|
inline mozilla::css::URLValue* GetURLValue() const;
|
|
|
|
inline mozilla::css::ImageValue* GetImageValue() const;
|
2011-03-25 14:43:53 +00:00
|
|
|
inline double GetDoubleValue() const;
|
2011-09-29 06:19:26 +00:00
|
|
|
bool GetIntMarginValue(nsIntMargin& aMargin) const;
|
2004-01-26 19:22:05 +00:00
|
|
|
|
2010-04-15 11:03:00 +00:00
|
|
|
/**
|
|
|
|
* Returns the string corresponding to the stored enum value.
|
|
|
|
*
|
|
|
|
* @param aResult the string representing the enum tag
|
|
|
|
* @param aRealTag wheter we want to have the real tag or the saved one
|
|
|
|
*/
|
2011-09-29 06:19:26 +00:00
|
|
|
void GetEnumString(nsAString& aResult, bool aRealTag) const;
|
2010-04-15 11:03:00 +00:00
|
|
|
|
2004-03-09 23:22:02 +00:00
|
|
|
// Methods to get access to atoms we may have
|
|
|
|
// Returns the number of atoms we have; 0 if we have none. It's OK
|
|
|
|
// to call this without checking the type first; it handles that.
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t GetAtomCount() const;
|
2004-03-09 23:22:02 +00:00
|
|
|
// Returns the atom at aIndex (0-based). Do not call this with
|
|
|
|
// aIndex >= GetAtomCount().
|
2012-08-22 15:56:38 +00:00
|
|
|
nsIAtom* AtomAt(int32_t aIndex) const;
|
2004-03-09 23:22:02 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t HashValue() const;
|
2011-09-29 06:19:26 +00:00
|
|
|
bool Equals(const nsAttrValue& aOther) const;
|
2012-12-13 22:08:44 +00:00
|
|
|
// aCaseSensitive == eIgnoreCase means ASCII case-insenstive matching
|
2011-09-29 06:19:26 +00:00
|
|
|
bool Equals(const nsAString& aValue, nsCaseTreatment aCaseSensitive) const;
|
|
|
|
bool Equals(nsIAtom* aValue, nsCaseTreatment aCaseSensitive) const;
|
2004-01-26 19:22:05 +00:00
|
|
|
|
2012-02-14 02:00:56 +00:00
|
|
|
/**
|
|
|
|
* Compares this object with aOther according to their string representation.
|
|
|
|
*
|
|
|
|
* For example, when called on an object with type eInteger and value 4, and
|
|
|
|
* given aOther of type eString and value "4", EqualsAsStrings will return
|
|
|
|
* true (while Equals will return false).
|
|
|
|
*/
|
|
|
|
bool EqualsAsStrings(const nsAttrValue& aOther) const;
|
|
|
|
|
2005-10-08 23:06:27 +00:00
|
|
|
/**
|
|
|
|
* Returns true if this AttrValue is equal to the given atom, or is an
|
|
|
|
* array which contains the given atom.
|
|
|
|
*/
|
2011-09-29 06:19:26 +00:00
|
|
|
bool Contains(nsIAtom* aValue, nsCaseTreatment aCaseSensitive) const;
|
2011-10-28 17:06:39 +00:00
|
|
|
/**
|
|
|
|
* Returns true if this AttrValue is an atom equal to the given
|
|
|
|
* string, or is an array of atoms which contains the given string.
|
|
|
|
* This always does a case-sensitive comparison.
|
|
|
|
*/
|
|
|
|
bool Contains(const nsAString& aValue) const;
|
2005-10-08 23:06:27 +00:00
|
|
|
|
2004-03-04 02:06:28 +00:00
|
|
|
void ParseAtom(const nsAString& aValue);
|
|
|
|
void ParseAtomArray(const nsAString& aValue);
|
|
|
|
void ParseStringOrAtom(const nsAString& aValue);
|
2004-01-15 17:07:27 +00:00
|
|
|
|
2005-01-25 00:02:58 +00:00
|
|
|
/**
|
|
|
|
* Structure for a mapping from int (enum) values to strings. When you use
|
|
|
|
* it you generally create an array of them.
|
|
|
|
* Instantiate like this:
|
|
|
|
* EnumTable myTable[] = {
|
|
|
|
* { "string1", 1 },
|
|
|
|
* { "string2", 2 },
|
|
|
|
* { 0 }
|
|
|
|
* }
|
|
|
|
*/
|
|
|
|
struct EnumTable {
|
|
|
|
/** The string the value maps to */
|
|
|
|
const char* tag;
|
|
|
|
/** The enum value that maps to this string */
|
2012-08-22 15:56:38 +00:00
|
|
|
int16_t value;
|
2005-01-25 00:02:58 +00:00
|
|
|
};
|
|
|
|
|
2004-03-04 02:06:28 +00:00
|
|
|
/**
|
|
|
|
* Parse into an enum value.
|
|
|
|
*
|
|
|
|
* @param aValue the string to find the value for
|
|
|
|
* @param aTable the enumeration to map with
|
2010-04-15 11:03:00 +00:00
|
|
|
* @param aCaseSensitive specify if the parsing has to be case sensitive
|
2011-08-10 22:25:22 +00:00
|
|
|
* @param aDefaultValue if non-null, this function will always return true.
|
|
|
|
* Failure to parse aValue as one of the values in aTable will just
|
|
|
|
* cause aDefaultValue->value to be stored as the enumeration value.
|
2004-03-04 02:06:28 +00:00
|
|
|
* @return whether the enum value was found or not
|
|
|
|
*/
|
2011-09-29 06:19:26 +00:00
|
|
|
bool ParseEnumValue(const nsAString& aValue,
|
2005-01-25 00:02:58 +00:00
|
|
|
const EnumTable* aTable,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool aCaseSensitive,
|
2012-07-30 14:20:58 +00:00
|
|
|
const EnumTable* aDefaultValue = nullptr);
|
2004-03-04 02:06:28 +00:00
|
|
|
|
|
|
|
/**
|
2008-02-17 02:50:44 +00:00
|
|
|
* Parse a string into an integer. Can optionally parse percent (n%).
|
|
|
|
* This method explicitly sets a lower bound of zero on the element,
|
|
|
|
* whether it be percent or raw integer.
|
2004-03-04 02:06:28 +00:00
|
|
|
*
|
|
|
|
* @param aString the string to parse
|
|
|
|
* @return whether the value could be parsed
|
2010-11-12 08:46:13 +00:00
|
|
|
*
|
|
|
|
* @see http://www.whatwg.org/html/#rules-for-parsing-dimension-values
|
2004-03-04 02:06:28 +00:00
|
|
|
*/
|
2011-09-29 06:19:26 +00:00
|
|
|
bool ParseSpecialIntValue(const nsAString& aString);
|
2004-03-04 02:06:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parse a string value into an integer.
|
|
|
|
*
|
|
|
|
* @param aString the string to parse
|
|
|
|
* @return whether the value could be parsed
|
|
|
|
*/
|
2011-09-29 06:19:26 +00:00
|
|
|
bool ParseIntValue(const nsAString& aString) {
|
2012-09-28 06:57:33 +00:00
|
|
|
return ParseIntWithBounds(aString, INT32_MIN, INT32_MAX);
|
2004-01-15 17:07:27 +00:00
|
|
|
}
|
|
|
|
|
2004-03-04 02:06:28 +00:00
|
|
|
/**
|
|
|
|
* Parse a string value into an integer with minimum value and maximum value.
|
|
|
|
*
|
|
|
|
* @param aString the string to parse
|
|
|
|
* @param aMin the minimum value (if value is less it will be bumped up)
|
|
|
|
* @param aMax the maximum value (if value is greater it will be chopped down)
|
|
|
|
* @return whether the value could be parsed
|
|
|
|
*/
|
2012-08-22 15:56:38 +00:00
|
|
|
bool ParseIntWithBounds(const nsAString& aString, int32_t aMin,
|
2012-09-28 06:57:33 +00:00
|
|
|
int32_t aMax = INT32_MAX);
|
2004-03-04 02:06:28 +00:00
|
|
|
|
2010-03-05 19:38:26 +00:00
|
|
|
/**
|
|
|
|
* Parse a string value into a non-negative integer.
|
|
|
|
* This method follows the rules for parsing non-negative integer from:
|
|
|
|
* http://dev.w3.org/html5/spec/infrastructure.html#rules-for-parsing-non-negative-integers
|
|
|
|
*
|
2010-04-11 14:12:51 +00:00
|
|
|
* @param aString the string to parse
|
|
|
|
* @return whether the value is valid
|
2010-03-05 19:38:26 +00:00
|
|
|
*/
|
2011-09-29 06:19:26 +00:00
|
|
|
bool ParseNonNegativeIntValue(const nsAString& aString);
|
2010-03-05 19:38:26 +00:00
|
|
|
|
2010-05-23 21:36:49 +00:00
|
|
|
/**
|
|
|
|
* Parse a string value into a positive integer.
|
|
|
|
* This method follows the rules for parsing non-negative integer from:
|
|
|
|
* http://dev.w3.org/html5/spec/infrastructure.html#rules-for-parsing-non-negative-integers
|
|
|
|
* In addition of these rules, the value has to be greater than zero.
|
|
|
|
*
|
|
|
|
* This is generally used for parsing content attributes which reflecting IDL
|
|
|
|
* attributes are limited to only non-negative numbers greater than zero, see:
|
|
|
|
* http://dev.w3.org/html5/spec/common-dom-interfaces.html#limited-to-only-non-negative-numbers-greater-than-zero
|
|
|
|
*
|
|
|
|
* @param aString the string to parse
|
|
|
|
* @return whether the value was valid
|
|
|
|
*/
|
2011-09-29 06:19:26 +00:00
|
|
|
bool ParsePositiveIntValue(const nsAString& aString);
|
2010-05-23 21:36:49 +00:00
|
|
|
|
2004-03-04 02:06:28 +00:00
|
|
|
/**
|
2010-06-03 20:11:34 +00:00
|
|
|
* Parse a string into a color. This implements what HTML5 calls the
|
|
|
|
* "rules for parsing a legacy color value".
|
2004-03-04 02:06:28 +00:00
|
|
|
*
|
|
|
|
* @param aString the string to parse
|
|
|
|
* @return whether the value could be parsed
|
|
|
|
*/
|
2011-09-29 06:19:26 +00:00
|
|
|
bool ParseColor(const nsAString& aString);
|
2004-03-04 02:06:28 +00:00
|
|
|
|
2008-07-09 08:22:20 +00:00
|
|
|
/**
|
2011-03-25 14:43:40 +00:00
|
|
|
* Parse a string value into a double-precision floating point value.
|
2008-07-09 08:22:20 +00:00
|
|
|
*
|
|
|
|
* @param aString the string to parse
|
|
|
|
* @return whether the value could be parsed
|
|
|
|
*/
|
2011-09-29 06:19:26 +00:00
|
|
|
bool ParseDoubleValue(const nsAString& aString);
|
2008-07-09 08:22:20 +00:00
|
|
|
|
2009-03-10 13:51:34 +00:00
|
|
|
/**
|
|
|
|
* Parse a lazy URI. This just sets up the storage for the URI; it
|
|
|
|
* doesn't actually allocate it.
|
|
|
|
*/
|
2011-09-29 06:19:26 +00:00
|
|
|
bool ParseLazyURIValue(const nsAString& aString);
|
2009-03-10 13:51:34 +00:00
|
|
|
|
2010-06-25 02:01:07 +00:00
|
|
|
/**
|
|
|
|
* Parse a margin string of format 'top, right, bottom, left' into
|
|
|
|
* an nsIntMargin.
|
|
|
|
*
|
|
|
|
* @param aString the string to parse
|
|
|
|
* @return whether the value could be parsed
|
|
|
|
*/
|
2011-09-29 06:19:26 +00:00
|
|
|
bool ParseIntMarginValue(const nsAString& aString);
|
2010-06-25 02:01:07 +00:00
|
|
|
|
2012-08-24 17:50:49 +00:00
|
|
|
/**
|
|
|
|
* Convert a URL nsAttrValue to an Image nsAttrValue.
|
|
|
|
*
|
|
|
|
* @param aDocument the document this nsAttrValue belongs to.
|
|
|
|
*/
|
2012-09-04 15:53:11 +00:00
|
|
|
void LoadImage(nsIDocument* aDocument);
|
2012-08-24 17:50:49 +00:00
|
|
|
|
2012-09-30 16:40:24 +00:00
|
|
|
/**
|
|
|
|
* Parse a string into a CSS style rule.
|
|
|
|
*
|
|
|
|
* @param aString the style attribute value to be parsed.
|
|
|
|
* @param aElement the element the attribute is set on.
|
|
|
|
*/
|
|
|
|
bool ParseStyleAttribute(const nsAString& aString,
|
|
|
|
nsStyledElementNotElementCSSInlineStyle* aElement);
|
|
|
|
|
2013-06-23 12:03:39 +00:00
|
|
|
size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
|
2011-08-10 22:54:19 +00:00
|
|
|
|
2004-01-15 17:07:27 +00:00
|
|
|
private:
|
2004-03-04 02:06:28 +00:00
|
|
|
// These have to be the same as in ValueType
|
|
|
|
enum ValueBaseType {
|
|
|
|
eStringBase = eString, // 00
|
|
|
|
eOtherBase = 0x01, // 01
|
|
|
|
eAtomBase = eAtom, // 10
|
2004-03-04 02:34:46 +00:00
|
|
|
eIntegerBase = 0x03 // 11
|
2004-03-04 02:06:28 +00:00
|
|
|
};
|
2004-01-15 17:07:27 +00:00
|
|
|
|
2004-03-04 02:06:28 +00:00
|
|
|
inline ValueBaseType BaseType() const;
|
2012-02-15 23:40:46 +00:00
|
|
|
inline bool IsSVGType(ValueType aType) const;
|
2004-03-04 02:06:28 +00:00
|
|
|
|
2010-04-15 11:03:00 +00:00
|
|
|
/**
|
|
|
|
* Get the index of an EnumTable in the sEnumTableArray.
|
|
|
|
* If the EnumTable is not in the sEnumTableArray, it is added.
|
|
|
|
*
|
|
|
|
* @param aTable the EnumTable to get the index of.
|
2011-08-10 22:25:22 +00:00
|
|
|
* @return the index of the EnumTable.
|
2010-04-15 11:03:00 +00:00
|
|
|
*/
|
2012-08-22 15:56:38 +00:00
|
|
|
int16_t GetEnumTableIndex(const EnumTable* aTable);
|
2010-04-15 11:03:00 +00:00
|
|
|
|
2004-03-04 02:06:28 +00:00
|
|
|
inline void SetPtrValueAndType(void* aValue, ValueBaseType aType);
|
2012-08-22 15:56:38 +00:00
|
|
|
void SetIntValueAndType(int32_t aValue, ValueType aType,
|
2008-09-26 10:39:18 +00:00
|
|
|
const nsAString* aStringValue);
|
2009-08-19 15:05:14 +00:00
|
|
|
void SetColorValue(nscolor aColor, const nsAString& aString);
|
2008-09-26 10:39:18 +00:00
|
|
|
void SetMiscAtomOrString(const nsAString* aValue);
|
|
|
|
void ResetMiscAtomOrString();
|
2012-02-15 23:40:46 +00:00
|
|
|
void SetSVGType(ValueType aType, const void* aValue,
|
|
|
|
const nsAString* aSerialized);
|
2004-03-04 02:06:28 +00:00
|
|
|
inline void ResetIfSet();
|
|
|
|
|
|
|
|
inline void* GetPtr() const;
|
|
|
|
inline MiscContainer* GetMiscContainer() const;
|
2012-08-22 15:56:38 +00:00
|
|
|
inline int32_t GetIntInternal() const;
|
2004-03-04 02:06:28 +00:00
|
|
|
|
2012-09-30 16:40:24 +00:00
|
|
|
// Clears the current MiscContainer. This will return null if there is no
|
|
|
|
// existing container.
|
|
|
|
MiscContainer* ClearMiscContainer();
|
|
|
|
// Like ClearMiscContainer, except allocates a new container if one does not
|
|
|
|
// exist already.
|
|
|
|
MiscContainer* EnsureEmptyMiscContainer();
|
2011-09-29 06:19:26 +00:00
|
|
|
bool EnsureEmptyAtomArray();
|
2013-04-22 11:13:22 +00:00
|
|
|
already_AddRefed<nsStringBuffer>
|
|
|
|
GetStringBuffer(const nsAString& aValue) const;
|
2011-08-10 22:25:22 +00:00
|
|
|
// Given an enum table and a particular entry in that table, return
|
|
|
|
// the actual integer value we should store.
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t EnumTableEntryToValue(const EnumTable* aEnumTable,
|
2011-08-10 22:25:22 +00:00
|
|
|
const EnumTable* aTableEntry);
|
2004-01-15 17:07:27 +00:00
|
|
|
|
2012-12-19 01:16:06 +00:00
|
|
|
static nsTArray<const EnumTable*>* sEnumTableArray;
|
2005-01-25 00:02:58 +00:00
|
|
|
|
2012-10-02 08:24:11 +00:00
|
|
|
uintptr_t mBits;
|
2004-01-15 17:07:27 +00:00
|
|
|
};
|
|
|
|
|
2012-02-14 02:00:57 +00:00
|
|
|
inline const nsAttrValue&
|
|
|
|
nsAttrValue::operator=(const nsAttrValue& aOther)
|
|
|
|
{
|
|
|
|
SetTo(aOther);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2004-03-04 02:06:28 +00:00
|
|
|
inline nsIAtom*
|
|
|
|
nsAttrValue::GetAtomValue() const
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(Type() == eAtom, "wrong type");
|
2007-07-08 07:08:04 +00:00
|
|
|
return reinterpret_cast<nsIAtom*>(GetPtr());
|
2004-03-04 02:06:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline nsAttrValue::ValueBaseType
|
|
|
|
nsAttrValue::BaseType() const
|
|
|
|
{
|
2007-07-08 07:08:04 +00:00
|
|
|
return static_cast<ValueBaseType>(mBits & NS_ATTRVALUE_BASETYPE_MASK);
|
2004-03-04 02:06:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void*
|
|
|
|
nsAttrValue::GetPtr() const
|
|
|
|
{
|
|
|
|
NS_ASSERTION(BaseType() != eIntegerBase,
|
|
|
|
"getting pointer from non-pointer");
|
2007-07-08 07:08:04 +00:00
|
|
|
return reinterpret_cast<void*>(mBits & NS_ATTRVALUE_POINTERVALUE_MASK);
|
2004-03-04 02:06:28 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
inline bool
|
2004-04-13 16:45:59 +00:00
|
|
|
nsAttrValue::IsEmptyString() const
|
|
|
|
{
|
|
|
|
return !mBits;
|
|
|
|
}
|
|
|
|
|
2013-01-29 14:42:14 +00:00
|
|
|
inline void
|
|
|
|
nsAttrValue::ToString(mozilla::dom::DOMString& aResult) const
|
|
|
|
{
|
|
|
|
switch (Type()) {
|
|
|
|
case eString:
|
|
|
|
{
|
|
|
|
nsStringBuffer* str = static_cast<nsStringBuffer*>(GetPtr());
|
|
|
|
if (str) {
|
2014-01-04 15:02:17 +00:00
|
|
|
aResult.SetStringBuffer(str, str->StorageSize()/sizeof(char16_t) - 1);
|
2013-01-29 14:42:14 +00:00
|
|
|
}
|
|
|
|
// else aResult is already empty
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
case eAtom:
|
|
|
|
{
|
|
|
|
nsIAtom *atom = static_cast<nsIAtom*>(GetPtr());
|
|
|
|
aResult.SetStringBuffer(atom->GetStringBuffer(), atom->GetLength());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
ToString(aResult.AsAString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-15 17:07:27 +00:00
|
|
|
#endif
|