2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04: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 20:07:27 +03:00
|
|
|
|
2006-03-30 12:03:04 +04:00
|
|
|
/*
|
|
|
|
* A struct that represents the value (type and actual data) of an
|
|
|
|
* attribute.
|
|
|
|
*/
|
|
|
|
|
2004-01-15 20:07:27 +03:00
|
|
|
#ifndef nsAttrValue_h___
|
|
|
|
#define nsAttrValue_h___
|
|
|
|
|
|
|
|
#include "nscore.h"
|
2014-04-10 21:39:20 +04:00
|
|
|
#include "nsStringGlue.h"
|
2005-02-03 01:58:01 +03:00
|
|
|
#include "nsStringBuffer.h"
|
2004-03-04 05:06:28 +03:00
|
|
|
#include "nsColor.h"
|
2005-09-11 23:20:08 +04:00
|
|
|
#include "nsCaseTreatment.h"
|
2010-06-25 06:01:07 +04:00
|
|
|
#include "nsMargin.h"
|
2010-08-12 01:05:28 +04:00
|
|
|
#include "nsCOMPtr.h"
|
2012-02-16 03:40:46 +04:00
|
|
|
#include "SVGAttrValueWrapper.h"
|
2012-12-19 05:16:06 +04:00
|
|
|
#include "nsTArrayForwardDeclare.h"
|
2013-01-29 18:42:14 +04:00
|
|
|
#include "nsIAtom.h"
|
2013-06-23 16:03:39 +04:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2013-01-29 18:42:14 +04:00
|
|
|
#include "mozilla/dom/BindingDeclarations.h"
|
2004-01-15 20:07:27 +03:00
|
|
|
|
2015-08-19 00:55:21 +03:00
|
|
|
// Undefine LoadImage to prevent naming conflict with Windows.
|
|
|
|
#undef LoadImage
|
|
|
|
|
2004-01-15 20:07:27 +03:00
|
|
|
class nsAString;
|
2012-08-24 21:50:49 +04:00
|
|
|
class nsIDocument;
|
2012-09-30 20:40:24 +04:00
|
|
|
class nsStyledElementNotElementCSSInlineStyle;
|
|
|
|
struct MiscContainer;
|
2004-01-15 20:07:27 +03:00
|
|
|
|
2011-03-11 05:48:57 +03:00
|
|
|
namespace mozilla {
|
|
|
|
namespace css {
|
2015-11-09 10:57:16 +03:00
|
|
|
class Declaration;
|
2012-08-24 21:50:49 +04:00
|
|
|
struct URLValue;
|
|
|
|
struct ImageValue;
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace css
|
|
|
|
} // namespace mozilla
|
2011-03-11 05:48:57 +03:00
|
|
|
|
2004-02-10 12:08:06 +03:00
|
|
|
#define NS_ATTRVALUE_MAX_STRINGLENGTH_ATOM 12
|
2004-03-04 05:06:28 +03:00
|
|
|
|
2012-10-02 12:24:11 +04:00
|
|
|
#define NS_ATTRVALUE_BASETYPE_MASK (uintptr_t(3))
|
2004-03-04 05:06:28 +03:00
|
|
|
#define NS_ATTRVALUE_POINTERVALUE_MASK (~NS_ATTRVALUE_BASETYPE_MASK)
|
|
|
|
|
2008-02-17 05:50:44 +03:00
|
|
|
#define NS_ATTRVALUE_INTEGERTYPE_BITS 4
|
2012-10-02 12:24:11 +04:00
|
|
|
#define NS_ATTRVALUE_INTEGERTYPE_MASK (uintptr_t((1 << NS_ATTRVALUE_INTEGERTYPE_BITS) - 1))
|
2004-03-04 05:06:28 +03:00
|
|
|
#define NS_ATTRVALUE_INTEGERTYPE_MULTIPLIER (1 << NS_ATTRVALUE_INTEGERTYPE_BITS)
|
2005-01-24 13:43:14 +03:00
|
|
|
#define NS_ATTRVALUE_INTEGERTYPE_MAXVALUE ((1 << (31 - NS_ATTRVALUE_INTEGERTYPE_BITS)) - 1)
|
2004-03-04 05:06:28 +03:00
|
|
|
#define NS_ATTRVALUE_INTEGERTYPE_MINVALUE (-NS_ATTRVALUE_INTEGERTYPE_MAXVALUE - 1)
|
2004-01-15 20:07:27 +03:00
|
|
|
|
2005-01-25 03:02:58 +03:00
|
|
|
#define NS_ATTRVALUE_ENUMTABLEINDEX_BITS (32 - 16 - NS_ATTRVALUE_INTEGERTYPE_BITS)
|
2008-09-26 14:39:18 +04: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 12:24:11 +04:00
|
|
|
(uintptr_t((((1 << NS_ATTRVALUE_ENUMTABLEINDEX_BITS) - 1) &~ NS_ATTRVALUE_ENUMTABLE_VALUE_NEEDS_TO_UPPER)))
|
2005-01-25 03:02:58 +03:00
|
|
|
|
2005-02-03 01:58:01 +03: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 19:39:56 +04: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-03 01:58:01 +03:00
|
|
|
*/
|
|
|
|
class nsCheapString : public nsString {
|
|
|
|
public:
|
2014-08-05 17:19:51 +04:00
|
|
|
explicit nsCheapString(nsStringBuffer* aBuf)
|
2005-02-03 01:58:01 +03:00
|
|
|
{
|
|
|
|
if (aBuf)
|
2014-01-04 19:02:17 +04:00
|
|
|
aBuf->ToString(aBuf->StorageSize()/sizeof(char16_t) - 1, *this);
|
2005-02-03 01:58:01 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2004-01-15 20:07:27 +03:00
|
|
|
class nsAttrValue {
|
2012-09-30 20:40:24 +04:00
|
|
|
friend struct MiscContainer;
|
2004-01-15 20:07:27 +03:00
|
|
|
public:
|
2010-08-12 01:05:28 +04:00
|
|
|
typedef nsTArray< nsCOMPtr<nsIAtom> > AtomArray;
|
|
|
|
|
2004-03-04 05:06:28 +03:00
|
|
|
// This has to be the same as in ValueBaseType
|
|
|
|
enum ValueType {
|
2008-02-17 05:50:44 +03: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 14:39:18 +04:00
|
|
|
// Values below here won't matter, they'll be always stored in the 'misc'
|
|
|
|
// struct.
|
2015-11-09 10:57:16 +03:00
|
|
|
eCSSDeclaration = 0x10
|
2013-05-24 17:27:51 +04:00
|
|
|
,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 05:06:28 +03:00
|
|
|
};
|
|
|
|
|
2012-09-30 20:40:24 +04:00
|
|
|
nsAttrValue();
|
|
|
|
nsAttrValue(const nsAttrValue& aOther);
|
|
|
|
explicit nsAttrValue(const nsAString& aValue);
|
|
|
|
explicit nsAttrValue(nsIAtom* aValue);
|
2015-11-09 10:57:16 +03:00
|
|
|
nsAttrValue(mozilla::css::Declaration* aValue, const nsAString* aSerialized);
|
2012-09-30 20:40:24 +04:00
|
|
|
explicit nsAttrValue(const nsIntMargin& aValue);
|
|
|
|
~nsAttrValue();
|
|
|
|
|
|
|
|
inline const nsAttrValue& operator=(const nsAttrValue& aOther);
|
|
|
|
|
|
|
|
static nsresult Init();
|
|
|
|
static void Shutdown();
|
|
|
|
|
2004-03-04 05:06:28 +03:00
|
|
|
ValueType Type() const;
|
2015-07-25 08:57:13 +03:00
|
|
|
// Returns true when this value is self-contained and does not depend on
|
|
|
|
// the state of its associated element.
|
|
|
|
// Returns false when this value depends on the state of its associated
|
|
|
|
// element and may be invalid if that state has been changed by changes to
|
|
|
|
// that element state outside of attribute setting.
|
|
|
|
inline bool StoresOwnData() const;
|
2004-03-04 05:06:28 +03:00
|
|
|
|
2004-01-15 20:07:27 +03:00
|
|
|
void Reset();
|
2004-03-04 05:06:28 +03:00
|
|
|
|
2004-01-26 22:22:05 +03:00
|
|
|
void SetTo(const nsAttrValue& aOther);
|
2004-01-15 20:07:27 +03:00
|
|
|
void SetTo(const nsAString& aValue);
|
2012-02-16 03:40:44 +04:00
|
|
|
void SetTo(nsIAtom* aValue);
|
2012-08-22 19:56:38 +04:00
|
|
|
void SetTo(int16_t aInt);
|
|
|
|
void SetTo(int32_t aInt, const nsAString* aSerialized);
|
2012-02-16 03:40:45 +04:00
|
|
|
void SetTo(double aValue, const nsAString* aSerialized);
|
2015-11-09 10:57:16 +03:00
|
|
|
void SetTo(mozilla::css::Declaration* aValue, const nsAString* aSerialized);
|
2012-08-24 21:50:49 +04:00
|
|
|
void SetTo(mozilla::css::URLValue* aValue, const nsAString* aSerialized);
|
2010-06-25 06:01:07 +04:00
|
|
|
void SetTo(const nsIntMargin& aValue);
|
2012-02-16 03:40:45 +04:00
|
|
|
void SetTo(const nsSVGAngle& aValue, const nsAString* aSerialized);
|
2012-02-16 03:40:45 +04:00
|
|
|
void SetTo(const nsSVGIntegerPair& aValue, const nsAString* aSerialized);
|
2012-02-16 03:40:45 +04:00
|
|
|
void SetTo(const nsSVGLength2& aValue, const nsAString* aSerialized);
|
2012-02-16 03:40:45 +04:00
|
|
|
void SetTo(const mozilla::SVGLengthList& aValue,
|
|
|
|
const nsAString* aSerialized);
|
2012-02-16 03:40:46 +04:00
|
|
|
void SetTo(const mozilla::SVGNumberList& aValue,
|
|
|
|
const nsAString* aSerialized);
|
2012-02-16 03:40:45 +04:00
|
|
|
void SetTo(const nsSVGNumberPair& aValue, const nsAString* aSerialized);
|
2012-02-16 03:40:46 +04:00
|
|
|
void SetTo(const mozilla::SVGPathData& aValue, const nsAString* aSerialized);
|
2012-02-16 03:40:46 +04:00
|
|
|
void SetTo(const mozilla::SVGPointList& aValue, const nsAString* aSerialized);
|
2012-02-16 03:40:46 +04:00
|
|
|
void SetTo(const mozilla::SVGAnimatedPreserveAspectRatio& aValue,
|
|
|
|
const nsAString* aSerialized);
|
2012-02-16 03:40:46 +04:00
|
|
|
void SetTo(const mozilla::SVGStringList& aValue,
|
|
|
|
const nsAString* aSerialized);
|
2012-02-16 03:40:46 +04:00
|
|
|
void SetTo(const mozilla::SVGTransformList& aValue,
|
|
|
|
const nsAString* aSerialized);
|
2012-02-16 03:40:46 +04:00
|
|
|
void SetTo(const nsSVGViewBox& aValue, const nsAString* aSerialized);
|
2004-01-26 22:22:05 +03:00
|
|
|
|
2012-02-14 06:00:56 +04: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 22:22:05 +03:00
|
|
|
void SwapValueWith(nsAttrValue& aOther);
|
2004-01-15 20:07:27 +03:00
|
|
|
|
|
|
|
void ToString(nsAString& aResult) const;
|
2013-01-29 18:42:14 +04:00
|
|
|
inline void ToString(mozilla::dom::DOMString& aResult) const;
|
|
|
|
|
2012-02-14 06:00:56 +04: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 20:07:27 +03:00
|
|
|
|
2004-01-26 22:22:05 +03: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 10:19:26 +04:00
|
|
|
inline bool IsEmptyString() const;
|
2005-02-03 01:58:01 +03:00
|
|
|
const nsCheapString GetStringValue() const;
|
2004-03-04 05:06:28 +03:00
|
|
|
inline nsIAtom* GetAtomValue() const;
|
2012-08-22 19:56:38 +04:00
|
|
|
inline int32_t GetIntegerValue() const;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool GetColorValue(nscolor& aColor) const;
|
2012-08-22 19:56:38 +04:00
|
|
|
inline int16_t GetEnumValue() const;
|
2004-03-04 05:06:28 +03:00
|
|
|
inline float GetPercentValue() const;
|
2010-08-12 01:05:28 +04:00
|
|
|
inline AtomArray* GetAtomArrayValue() const;
|
2015-11-09 10:57:16 +03:00
|
|
|
inline mozilla::css::Declaration* GetCSSDeclarationValue() const;
|
2012-08-24 21:50:49 +04:00
|
|
|
inline mozilla::css::URLValue* GetURLValue() const;
|
|
|
|
inline mozilla::css::ImageValue* GetImageValue() const;
|
2011-03-25 17:43:53 +03:00
|
|
|
inline double GetDoubleValue() const;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool GetIntMarginValue(nsIntMargin& aMargin) const;
|
2004-01-26 22:22:05 +03:00
|
|
|
|
2010-04-15 15:03:00 +04: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 10:19:26 +04:00
|
|
|
void GetEnumString(nsAString& aResult, bool aRealTag) const;
|
2010-04-15 15:03:00 +04:00
|
|
|
|
2004-03-10 02:22:02 +03: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 19:56:38 +04:00
|
|
|
uint32_t GetAtomCount() const;
|
2004-03-10 02:22:02 +03:00
|
|
|
// Returns the atom at aIndex (0-based). Do not call this with
|
|
|
|
// aIndex >= GetAtomCount().
|
2012-08-22 19:56:38 +04:00
|
|
|
nsIAtom* AtomAt(int32_t aIndex) const;
|
2004-03-10 02:22:02 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t HashValue() const;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool Equals(const nsAttrValue& aOther) const;
|
2012-12-14 02:08:44 +04:00
|
|
|
// aCaseSensitive == eIgnoreCase means ASCII case-insenstive matching
|
2011-09-29 10:19:26 +04:00
|
|
|
bool Equals(const nsAString& aValue, nsCaseTreatment aCaseSensitive) const;
|
|
|
|
bool Equals(nsIAtom* aValue, nsCaseTreatment aCaseSensitive) const;
|
2004-01-26 22:22:05 +03:00
|
|
|
|
2012-02-14 06:00:56 +04: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-09 03:06:27 +04:00
|
|
|
/**
|
|
|
|
* Returns true if this AttrValue is equal to the given atom, or is an
|
|
|
|
* array which contains the given atom.
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
bool Contains(nsIAtom* aValue, nsCaseTreatment aCaseSensitive) const;
|
2011-10-28 21:06:39 +04: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-09 03:06:27 +04:00
|
|
|
|
2004-03-04 05:06:28 +03:00
|
|
|
void ParseAtom(const nsAString& aValue);
|
|
|
|
void ParseAtomArray(const nsAString& aValue);
|
|
|
|
void ParseStringOrAtom(const nsAString& aValue);
|
2004-01-15 20:07:27 +03:00
|
|
|
|
2005-01-25 03:02:58 +03: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 19:56:38 +04:00
|
|
|
int16_t value;
|
2005-01-25 03:02:58 +03:00
|
|
|
};
|
|
|
|
|
2004-03-04 05:06:28 +03: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 15:03:00 +04:00
|
|
|
* @param aCaseSensitive specify if the parsing has to be case sensitive
|
2011-08-11 02:25:22 +04: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 05:06:28 +03:00
|
|
|
* @return whether the enum value was found or not
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
bool ParseEnumValue(const nsAString& aValue,
|
2005-01-25 03:02:58 +03:00
|
|
|
const EnumTable* aTable,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aCaseSensitive,
|
2012-07-30 18:20:58 +04:00
|
|
|
const EnumTable* aDefaultValue = nullptr);
|
2004-03-04 05:06:28 +03:00
|
|
|
|
|
|
|
/**
|
2008-02-17 05:50:44 +03: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 05:06:28 +03:00
|
|
|
*
|
|
|
|
* @param aString the string to parse
|
|
|
|
* @return whether the value could be parsed
|
2010-11-12 11:46:13 +03:00
|
|
|
*
|
|
|
|
* @see http://www.whatwg.org/html/#rules-for-parsing-dimension-values
|
2004-03-04 05:06:28 +03:00
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
bool ParseSpecialIntValue(const nsAString& aString);
|
2004-03-04 05:06:28 +03:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parse a string value into an integer.
|
|
|
|
*
|
|
|
|
* @param aString the string to parse
|
|
|
|
* @return whether the value could be parsed
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
bool ParseIntValue(const nsAString& aString) {
|
2012-09-28 10:57:33 +04:00
|
|
|
return ParseIntWithBounds(aString, INT32_MIN, INT32_MAX);
|
2004-01-15 20:07:27 +03:00
|
|
|
}
|
|
|
|
|
2004-03-04 05:06:28 +03: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 19:56:38 +04:00
|
|
|
bool ParseIntWithBounds(const nsAString& aString, int32_t aMin,
|
2012-09-28 10:57:33 +04:00
|
|
|
int32_t aMax = INT32_MAX);
|
2004-03-04 05:06:28 +03:00
|
|
|
|
2010-03-05 22:38:26 +03: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 18:12:51 +04:00
|
|
|
* @param aString the string to parse
|
|
|
|
* @return whether the value is valid
|
2010-03-05 22:38:26 +03:00
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
bool ParseNonNegativeIntValue(const nsAString& aString);
|
2010-03-05 22:38:26 +03:00
|
|
|
|
2010-05-24 01:36:49 +04: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 10:19:26 +04:00
|
|
|
bool ParsePositiveIntValue(const nsAString& aString);
|
2010-05-24 01:36:49 +04:00
|
|
|
|
2004-03-04 05:06:28 +03:00
|
|
|
/**
|
2010-06-04 00:11:34 +04:00
|
|
|
* Parse a string into a color. This implements what HTML5 calls the
|
|
|
|
* "rules for parsing a legacy color value".
|
2004-03-04 05:06:28 +03:00
|
|
|
*
|
|
|
|
* @param aString the string to parse
|
|
|
|
* @return whether the value could be parsed
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
bool ParseColor(const nsAString& aString);
|
2004-03-04 05:06:28 +03:00
|
|
|
|
2008-07-09 12:22:20 +04:00
|
|
|
/**
|
2011-03-25 17:43:40 +03:00
|
|
|
* Parse a string value into a double-precision floating point value.
|
2008-07-09 12:22:20 +04:00
|
|
|
*
|
|
|
|
* @param aString the string to parse
|
|
|
|
* @return whether the value could be parsed
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
bool ParseDoubleValue(const nsAString& aString);
|
2008-07-09 12:22:20 +04:00
|
|
|
|
2009-03-10 16:51:34 +03:00
|
|
|
/**
|
|
|
|
* Parse a lazy URI. This just sets up the storage for the URI; it
|
|
|
|
* doesn't actually allocate it.
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
bool ParseLazyURIValue(const nsAString& aString);
|
2009-03-10 16:51:34 +03:00
|
|
|
|
2010-06-25 06:01:07 +04: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 10:19:26 +04:00
|
|
|
bool ParseIntMarginValue(const nsAString& aString);
|
2010-06-25 06:01:07 +04:00
|
|
|
|
2012-08-24 21:50:49 +04:00
|
|
|
/**
|
|
|
|
* Convert a URL nsAttrValue to an Image nsAttrValue.
|
|
|
|
*
|
|
|
|
* @param aDocument the document this nsAttrValue belongs to.
|
|
|
|
*/
|
2012-09-04 19:53:11 +04:00
|
|
|
void LoadImage(nsIDocument* aDocument);
|
2012-08-24 21:50:49 +04:00
|
|
|
|
2012-09-30 20:40:24 +04: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 16:03:39 +04:00
|
|
|
size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
|
2011-08-11 02:54:19 +04:00
|
|
|
|
2004-01-15 20:07:27 +03:00
|
|
|
private:
|
2004-03-04 05:06:28 +03:00
|
|
|
// These have to be the same as in ValueType
|
|
|
|
enum ValueBaseType {
|
|
|
|
eStringBase = eString, // 00
|
|
|
|
eOtherBase = 0x01, // 01
|
|
|
|
eAtomBase = eAtom, // 10
|
2004-03-04 05:34:46 +03:00
|
|
|
eIntegerBase = 0x03 // 11
|
2004-03-04 05:06:28 +03:00
|
|
|
};
|
2004-01-15 20:07:27 +03:00
|
|
|
|
2004-03-04 05:06:28 +03:00
|
|
|
inline ValueBaseType BaseType() const;
|
2012-02-16 03:40:46 +04:00
|
|
|
inline bool IsSVGType(ValueType aType) const;
|
2004-03-04 05:06:28 +03:00
|
|
|
|
2010-04-15 15:03:00 +04: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-11 02:25:22 +04:00
|
|
|
* @return the index of the EnumTable.
|
2010-04-15 15:03:00 +04:00
|
|
|
*/
|
2012-08-22 19:56:38 +04:00
|
|
|
int16_t GetEnumTableIndex(const EnumTable* aTable);
|
2010-04-15 15:03:00 +04:00
|
|
|
|
2004-03-04 05:06:28 +03:00
|
|
|
inline void SetPtrValueAndType(void* aValue, ValueBaseType aType);
|
2012-08-22 19:56:38 +04:00
|
|
|
void SetIntValueAndType(int32_t aValue, ValueType aType,
|
2008-09-26 14:39:18 +04:00
|
|
|
const nsAString* aStringValue);
|
2009-08-19 19:05:14 +04:00
|
|
|
void SetColorValue(nscolor aColor, const nsAString& aString);
|
2008-09-26 14:39:18 +04:00
|
|
|
void SetMiscAtomOrString(const nsAString* aValue);
|
|
|
|
void ResetMiscAtomOrString();
|
2012-02-16 03:40:46 +04:00
|
|
|
void SetSVGType(ValueType aType, const void* aValue,
|
|
|
|
const nsAString* aSerialized);
|
2004-03-04 05:06:28 +03:00
|
|
|
inline void ResetIfSet();
|
|
|
|
|
|
|
|
inline void* GetPtr() const;
|
|
|
|
inline MiscContainer* GetMiscContainer() const;
|
2012-08-22 19:56:38 +04:00
|
|
|
inline int32_t GetIntInternal() const;
|
2004-03-04 05:06:28 +03:00
|
|
|
|
2012-09-30 20:40:24 +04: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 10:19:26 +04:00
|
|
|
bool EnsureEmptyAtomArray();
|
2013-04-22 15:13:22 +04:00
|
|
|
already_AddRefed<nsStringBuffer>
|
|
|
|
GetStringBuffer(const nsAString& aValue) const;
|
2011-08-11 02:25:22 +04:00
|
|
|
// Given an enum table and a particular entry in that table, return
|
|
|
|
// the actual integer value we should store.
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t EnumTableEntryToValue(const EnumTable* aEnumTable,
|
2011-08-11 02:25:22 +04:00
|
|
|
const EnumTable* aTableEntry);
|
2004-01-15 20:07:27 +03:00
|
|
|
|
2012-12-19 05:16:06 +04:00
|
|
|
static nsTArray<const EnumTable*>* sEnumTableArray;
|
2005-01-25 03:02:58 +03:00
|
|
|
|
2012-10-02 12:24:11 +04:00
|
|
|
uintptr_t mBits;
|
2004-01-15 20:07:27 +03:00
|
|
|
};
|
|
|
|
|
2012-02-14 06:00:57 +04:00
|
|
|
inline const nsAttrValue&
|
|
|
|
nsAttrValue::operator=(const nsAttrValue& aOther)
|
|
|
|
{
|
|
|
|
SetTo(aOther);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2004-03-04 05:06:28 +03:00
|
|
|
inline nsIAtom*
|
|
|
|
nsAttrValue::GetAtomValue() const
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(Type() == eAtom, "wrong type");
|
2007-07-08 11:08:04 +04:00
|
|
|
return reinterpret_cast<nsIAtom*>(GetPtr());
|
2004-03-04 05:06:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
inline nsAttrValue::ValueBaseType
|
|
|
|
nsAttrValue::BaseType() const
|
|
|
|
{
|
2007-07-08 11:08:04 +04:00
|
|
|
return static_cast<ValueBaseType>(mBits & NS_ATTRVALUE_BASETYPE_MASK);
|
2004-03-04 05:06:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void*
|
|
|
|
nsAttrValue::GetPtr() const
|
|
|
|
{
|
|
|
|
NS_ASSERTION(BaseType() != eIntegerBase,
|
|
|
|
"getting pointer from non-pointer");
|
2007-07-08 11:08:04 +04:00
|
|
|
return reinterpret_cast<void*>(mBits & NS_ATTRVALUE_POINTERVALUE_MASK);
|
2004-03-04 05:06:28 +03:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
inline bool
|
2004-04-13 20:45:59 +04:00
|
|
|
nsAttrValue::IsEmptyString() const
|
|
|
|
{
|
|
|
|
return !mBits;
|
|
|
|
}
|
|
|
|
|
2013-01-29 18:42:14 +04: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 19:02:17 +04:00
|
|
|
aResult.SetStringBuffer(str, str->StorageSize()/sizeof(char16_t) - 1);
|
2013-01-29 18:42:14 +04: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 20:07:27 +03:00
|
|
|
#endif
|