2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* IBM Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2003
|
|
|
|
* IBM Corporation. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* IBM Corporation
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* A struct that represents the value (type and actual data) of an
|
|
|
|
* attribute.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef nsAttrValue_h___
|
|
|
|
#define nsAttrValue_h___
|
|
|
|
|
|
|
|
#include "nscore.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsStringBuffer.h"
|
|
|
|
#include "nsColor.h"
|
|
|
|
#include "nsCaseTreatment.h"
|
2010-06-24 19:01:07 -07:00
|
|
|
#include "nsMargin.h"
|
2010-08-11 14:05:28 -07:00
|
|
|
#include "nsCOMPtr.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-04-13 04:57:53 -07:00
|
|
|
typedef PRUptrdiff PtrBits;
|
2007-03-22 10:30:00 -07:00
|
|
|
class nsAString;
|
|
|
|
class nsIAtom;
|
|
|
|
class nsISVGValue;
|
|
|
|
class nsIDocument;
|
2010-11-08 18:48:59 -08:00
|
|
|
template<class E, class A> class nsTArray;
|
|
|
|
template<class E, class A> class nsTPtrArray;
|
|
|
|
struct nsTArrayDefaultAllocator;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-03-10 18:48:57 -08:00
|
|
|
namespace mozilla {
|
|
|
|
namespace css {
|
|
|
|
class StyleRule;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#define NS_ATTRVALUE_MAX_STRINGLENGTH_ATOM 12
|
|
|
|
|
|
|
|
#define NS_ATTRVALUE_BASETYPE_MASK (PtrBits(3))
|
|
|
|
#define NS_ATTRVALUE_POINTERVALUE_MASK (~NS_ATTRVALUE_BASETYPE_MASK)
|
|
|
|
|
2008-02-16 18:50:44 -08:00
|
|
|
#define NS_ATTRVALUE_INTEGERTYPE_BITS 4
|
2007-03-22 10:30:00 -07:00
|
|
|
#define NS_ATTRVALUE_INTEGERTYPE_MASK (PtrBits((1 << NS_ATTRVALUE_INTEGERTYPE_BITS) - 1))
|
|
|
|
#define NS_ATTRVALUE_INTEGERTYPE_MULTIPLIER (1 << NS_ATTRVALUE_INTEGERTYPE_BITS)
|
|
|
|
#define NS_ATTRVALUE_INTEGERTYPE_MAXVALUE ((1 << (31 - NS_ATTRVALUE_INTEGERTYPE_BITS)) - 1)
|
|
|
|
#define NS_ATTRVALUE_INTEGERTYPE_MINVALUE (-NS_ATTRVALUE_INTEGERTYPE_MAXVALUE - 1)
|
|
|
|
|
|
|
|
#define NS_ATTRVALUE_ENUMTABLEINDEX_BITS (32 - 16 - NS_ATTRVALUE_INTEGERTYPE_BITS)
|
2008-09-26 03:39:18 -07: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 \
|
|
|
|
(PtrBits((((1 << NS_ATTRVALUE_ENUMTABLEINDEX_BITS) - 1) &~ NS_ATTRVALUE_ENUMTABLE_VALUE_NEEDS_TO_UPPER)))
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A class used to construct a nsString from a nsStringBuffer (we might
|
|
|
|
* want to move this to nsString at some point).
|
|
|
|
*/
|
|
|
|
class nsCheapString : public nsString {
|
|
|
|
public:
|
|
|
|
nsCheapString(nsStringBuffer* aBuf)
|
|
|
|
{
|
|
|
|
if (aBuf)
|
|
|
|
aBuf->ToString(aBuf->StorageSize()/2 - 1, *this);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class nsAttrValue {
|
|
|
|
public:
|
2010-08-11 14:05:28 -07:00
|
|
|
typedef nsTArray< nsCOMPtr<nsIAtom> > AtomArray;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsAttrValue();
|
|
|
|
nsAttrValue(const nsAttrValue& aOther);
|
|
|
|
explicit nsAttrValue(const nsAString& aValue);
|
2011-03-10 18:48:57 -08:00
|
|
|
nsAttrValue(mozilla::css::StyleRule* aValue, const nsAString* aSerialized);
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef MOZ_SVG
|
|
|
|
explicit nsAttrValue(nsISVGValue* aValue);
|
|
|
|
#endif
|
2010-06-24 19:01:07 -07:00
|
|
|
explicit nsAttrValue(const nsIntMargin& aValue);
|
2007-03-22 10:30:00 -07:00
|
|
|
~nsAttrValue();
|
|
|
|
|
|
|
|
static nsresult Init();
|
|
|
|
static void Shutdown();
|
|
|
|
|
|
|
|
// This has to be the same as in ValueBaseType
|
|
|
|
enum ValueType {
|
2008-02-16 18:50:44 -08: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 03:39:18 -07:00
|
|
|
// Values below here won't matter, they'll be always stored in the 'misc'
|
|
|
|
// struct.
|
2008-02-16 18:50:44 -08:00
|
|
|
eCSSStyleRule = 0x10,
|
|
|
|
eAtomArray = 0x11
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef MOZ_SVG
|
2008-02-16 18:50:44 -08:00
|
|
|
,eSVGValue = 0x12
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
2008-07-09 01:22:20 -07:00
|
|
|
,eFloatValue = 0x13
|
2010-06-24 19:01:07 -07:00
|
|
|
,eIntMarginValue = 0x14
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
ValueType Type() const;
|
|
|
|
|
|
|
|
void Reset();
|
|
|
|
|
|
|
|
void SetTo(const nsAttrValue& aOther);
|
|
|
|
void SetTo(const nsAString& aValue);
|
|
|
|
void SetTo(PRInt16 aInt);
|
2011-03-10 18:48:57 -08:00
|
|
|
void SetTo(mozilla::css::StyleRule* aValue, const nsAString* aSerialized);
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef MOZ_SVG
|
|
|
|
void SetTo(nsISVGValue* aValue);
|
|
|
|
#endif
|
2010-06-24 19:01:07 -07:00
|
|
|
void SetTo(const nsIntMargin& aValue);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
void SwapValueWith(nsAttrValue& aOther);
|
|
|
|
|
|
|
|
void ToString(nsAString& aResult) const;
|
|
|
|
|
|
|
|
// Methods to get value. These methods do not convert so only use them
|
|
|
|
// to retrieve the datatype that this nsAttrValue has.
|
|
|
|
inline PRBool IsEmptyString() const;
|
|
|
|
const nsCheapString GetStringValue() const;
|
|
|
|
inline nsIAtom* GetAtomValue() const;
|
|
|
|
inline PRInt32 GetIntegerValue() const;
|
|
|
|
PRBool GetColorValue(nscolor& aColor) const;
|
|
|
|
inline PRInt16 GetEnumValue() const;
|
|
|
|
inline float GetPercentValue() const;
|
2010-08-11 14:05:28 -07:00
|
|
|
inline AtomArray* GetAtomArrayValue() const;
|
2011-03-10 18:48:57 -08:00
|
|
|
inline mozilla::css::StyleRule* GetCSSStyleRuleValue() const;
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef MOZ_SVG
|
|
|
|
inline nsISVGValue* GetSVGValue() const;
|
|
|
|
#endif
|
2011-03-25 07:43:40 -07:00
|
|
|
inline double GetFloatValue() const;
|
2010-06-24 19:01:07 -07:00
|
|
|
PRBool GetIntMarginValue(nsIntMargin& aMargin) const;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-04-15 04:03:00 -07: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
|
|
|
|
*/
|
|
|
|
void GetEnumString(nsAString& aResult, PRBool aRealTag) const;
|
|
|
|
|
2007-03-22 10:30:00 -07: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.
|
2010-08-11 14:05:28 -07:00
|
|
|
PRUint32 GetAtomCount() const;
|
2007-03-22 10:30:00 -07:00
|
|
|
// Returns the atom at aIndex (0-based). Do not call this with
|
|
|
|
// aIndex >= GetAtomCount().
|
|
|
|
nsIAtom* AtomAt(PRInt32 aIndex) const;
|
|
|
|
|
|
|
|
PRUint32 HashValue() const;
|
|
|
|
PRBool Equals(const nsAttrValue& aOther) const;
|
|
|
|
PRBool Equals(const nsAString& aValue, nsCaseTreatment aCaseSensitive) const;
|
|
|
|
PRBool Equals(nsIAtom* aValue, nsCaseTreatment aCaseSensitive) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if this AttrValue is equal to the given atom, or is an
|
|
|
|
* array which contains the given atom.
|
|
|
|
*/
|
|
|
|
PRBool Contains(nsIAtom* aValue, nsCaseTreatment aCaseSensitive) const;
|
|
|
|
|
|
|
|
void ParseAtom(const nsAString& aValue);
|
|
|
|
void ParseAtomArray(const nsAString& aValue);
|
|
|
|
void ParseStringOrAtom(const nsAString& aValue);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 */
|
|
|
|
PRInt16 value;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parse into an enum value.
|
|
|
|
*
|
|
|
|
* @param aValue the string to find the value for
|
|
|
|
* @param aTable the enumeration to map with
|
2010-04-15 04:03:00 -07:00
|
|
|
* @param aCaseSensitive specify if the parsing has to be case sensitive
|
2007-03-22 10:30:00 -07:00
|
|
|
* @return whether the enum value was found or not
|
|
|
|
*/
|
|
|
|
PRBool ParseEnumValue(const nsAString& aValue,
|
|
|
|
const EnumTable* aTable,
|
2010-04-15 04:03:00 -07:00
|
|
|
PRBool aCaseSensitive);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/**
|
2008-02-16 18:50:44 -08: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.
|
2007-03-22 10:30:00 -07:00
|
|
|
*
|
|
|
|
* @param aString the string to parse
|
|
|
|
* @return whether the value could be parsed
|
2010-11-12 00:46:13 -08:00
|
|
|
*
|
|
|
|
* @see http://www.whatwg.org/html/#rules-for-parsing-dimension-values
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2011-02-04 11:46:16 -08:00
|
|
|
PRBool ParseSpecialIntValue(const nsAString& aString);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parse a string value into an integer.
|
|
|
|
*
|
|
|
|
* @param aString the string to parse
|
|
|
|
* @return whether the value could be parsed
|
|
|
|
*/
|
|
|
|
PRBool ParseIntValue(const nsAString& aString) {
|
2008-09-26 03:39:18 -07:00
|
|
|
return ParseIntWithBounds(aString, PR_INT32_MIN, PR_INT32_MAX);
|
2007-03-22 10:30:00 -07: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
|
|
|
|
*/
|
|
|
|
PRBool ParseIntWithBounds(const nsAString& aString, PRInt32 aMin,
|
2008-09-26 03:39:18 -07:00
|
|
|
PRInt32 aMax = PR_INT32_MAX);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-05 11:38:26 -08: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 07:12:51 -07:00
|
|
|
* @param aString the string to parse
|
|
|
|
* @return whether the value is valid
|
2010-03-05 11:38:26 -08:00
|
|
|
*/
|
|
|
|
PRBool ParseNonNegativeIntValue(const nsAString& aString);
|
|
|
|
|
2010-05-23 14:36:49 -07: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
|
|
|
|
*/
|
|
|
|
PRBool ParsePositiveIntValue(const nsAString& aString);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
2010-06-03 13:11:34 -07:00
|
|
|
* Parse a string into a color. This implements what HTML5 calls the
|
|
|
|
* "rules for parsing a legacy color value".
|
2007-03-22 10:30:00 -07:00
|
|
|
*
|
|
|
|
* @param aString the string to parse
|
|
|
|
* @return whether the value could be parsed
|
|
|
|
*/
|
2010-07-17 01:09:14 -07:00
|
|
|
PRBool ParseColor(const nsAString& aString);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-07-09 01:22:20 -07:00
|
|
|
/**
|
2011-03-25 07:43:40 -07:00
|
|
|
* Parse a string value into a double-precision floating point value.
|
2008-07-09 01:22:20 -07:00
|
|
|
*
|
|
|
|
* @param aString the string to parse
|
|
|
|
* @return whether the value could be parsed
|
|
|
|
*/
|
|
|
|
PRBool ParseFloatValue(const nsAString& aString);
|
|
|
|
|
2009-03-10 06:51:34 -07:00
|
|
|
/**
|
|
|
|
* Parse a lazy URI. This just sets up the storage for the URI; it
|
|
|
|
* doesn't actually allocate it.
|
|
|
|
*/
|
|
|
|
PRBool ParseLazyURIValue(const nsAString& aString);
|
|
|
|
|
2010-06-24 19:01:07 -07: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
|
|
|
|
*/
|
|
|
|
PRBool ParseIntMarginValue(const nsAString& aString);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
private:
|
|
|
|
// These have to be the same as in ValueType
|
|
|
|
enum ValueBaseType {
|
|
|
|
eStringBase = eString, // 00
|
|
|
|
eOtherBase = 0x01, // 01
|
|
|
|
eAtomBase = eAtom, // 10
|
|
|
|
eIntegerBase = 0x03 // 11
|
|
|
|
};
|
|
|
|
|
|
|
|
struct MiscContainer
|
|
|
|
{
|
|
|
|
ValueType mType;
|
2008-09-26 03:39:18 -07:00
|
|
|
// mStringBits points to either nsIAtom* or nsStringBuffer* and is used when
|
|
|
|
// mType isn't mCSSStyleRule or eSVGValue.
|
|
|
|
// Note eStringBase and eAtomBase is used also to handle the type of
|
|
|
|
// mStringBits.
|
|
|
|
PtrBits mStringBits;
|
2007-03-22 10:30:00 -07:00
|
|
|
union {
|
2008-09-26 03:39:18 -07:00
|
|
|
PRInt32 mInteger;
|
2007-03-22 10:30:00 -07:00
|
|
|
nscolor mColor;
|
2008-09-26 03:39:18 -07:00
|
|
|
PRUint32 mEnumValue;
|
|
|
|
PRInt32 mPercent;
|
2011-03-10 18:48:57 -08:00
|
|
|
mozilla::css::StyleRule* mCSSStyleRule;
|
2010-08-11 14:05:28 -07:00
|
|
|
AtomArray* mAtomArray;
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef MOZ_SVG
|
|
|
|
nsISVGValue* mSVGValue;
|
|
|
|
#endif
|
2011-03-25 07:43:40 -07:00
|
|
|
double mFloatValue;
|
2010-06-24 19:01:07 -07:00
|
|
|
nsIntMargin* mIntMargin;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
inline ValueBaseType BaseType() const;
|
|
|
|
|
2010-04-15 04:03:00 -07:00
|
|
|
/**
|
|
|
|
* Get the index of an EnumTable in the sEnumTableArray.
|
|
|
|
* If the EnumTable is not in the sEnumTableArray, it is added.
|
|
|
|
* If there is no more space in sEnumTableArray, it returns PR_FALSE.
|
|
|
|
*
|
|
|
|
* @param aTable the EnumTable to get the index of.
|
|
|
|
* @param aResult the index of the EnumTable.
|
|
|
|
* @return whether the index has been found or inserted.
|
|
|
|
*/
|
|
|
|
PRBool GetEnumTableIndex(const EnumTable* aTable, PRInt16& aResult);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
inline void SetPtrValueAndType(void* aValue, ValueBaseType aType);
|
2008-09-26 03:39:18 -07:00
|
|
|
void SetIntValueAndType(PRInt32 aValue, ValueType aType,
|
|
|
|
const nsAString* aStringValue);
|
2009-08-19 08:05:14 -07:00
|
|
|
void SetColorValue(nscolor aColor, const nsAString& aString);
|
2008-09-26 03:39:18 -07:00
|
|
|
void SetMiscAtomOrString(const nsAString* aValue);
|
|
|
|
void ResetMiscAtomOrString();
|
2007-03-22 10:30:00 -07:00
|
|
|
inline void ResetIfSet();
|
|
|
|
|
|
|
|
inline void* GetPtr() const;
|
|
|
|
inline MiscContainer* GetMiscContainer() const;
|
|
|
|
inline PRInt32 GetIntInternal() const;
|
|
|
|
|
|
|
|
PRBool EnsureEmptyMiscContainer();
|
|
|
|
PRBool EnsureEmptyAtomArray();
|
2008-09-26 03:39:18 -07:00
|
|
|
nsStringBuffer* GetStringBuffer(const nsAString& aValue) const;
|
|
|
|
// aStrict is set PR_TRUE if stringifying the return value equals with
|
|
|
|
// aValue.
|
|
|
|
PRInt32 StringToInteger(const nsAString& aValue,
|
|
|
|
PRBool* aStrict,
|
|
|
|
PRInt32* aErrorCode,
|
|
|
|
PRBool aCanBePercent = PR_FALSE,
|
|
|
|
PRBool* aIsPercent = nsnull) const;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-11-08 18:48:59 -08:00
|
|
|
static nsTPtrArray<const EnumTable, nsTArrayDefaultAllocator>* sEnumTableArray;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
PtrBits mBits;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implementation of inline methods
|
|
|
|
*/
|
|
|
|
|
|
|
|
inline nsIAtom*
|
|
|
|
nsAttrValue::GetAtomValue() const
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(Type() == eAtom, "wrong type");
|
2007-07-08 00:08:04 -07:00
|
|
|
return reinterpret_cast<nsIAtom*>(GetPtr());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline PRInt32
|
|
|
|
nsAttrValue::GetIntegerValue() const
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(Type() == eInteger, "wrong type");
|
2008-09-26 03:39:18 -07:00
|
|
|
return (BaseType() == eIntegerBase)
|
|
|
|
? GetIntInternal()
|
|
|
|
: GetMiscContainer()->mInteger;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline PRInt16
|
|
|
|
nsAttrValue::GetEnumValue() const
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(Type() == eEnum, "wrong type");
|
|
|
|
// We don't need to worry about sign extension here since we're
|
|
|
|
// returning an PRInt16 which will cut away the top bits.
|
2008-09-26 03:39:18 -07:00
|
|
|
return static_cast<PRInt16>((
|
|
|
|
(BaseType() == eIntegerBase)
|
|
|
|
? static_cast<PRUint32>(GetIntInternal())
|
|
|
|
: GetMiscContainer()->mEnumValue)
|
|
|
|
>> NS_ATTRVALUE_ENUMTABLEINDEX_BITS);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline float
|
|
|
|
nsAttrValue::GetPercentValue() const
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(Type() == ePercent, "wrong type");
|
2008-09-26 03:39:18 -07:00
|
|
|
return ((BaseType() == eIntegerBase)
|
|
|
|
? GetIntInternal()
|
|
|
|
: GetMiscContainer()->mPercent)
|
|
|
|
/ 100.0f;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-08-11 14:05:28 -07:00
|
|
|
inline nsAttrValue::AtomArray*
|
2007-03-22 10:30:00 -07:00
|
|
|
nsAttrValue::GetAtomArrayValue() const
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(Type() == eAtomArray, "wrong type");
|
|
|
|
return GetMiscContainer()->mAtomArray;
|
|
|
|
}
|
|
|
|
|
2011-03-10 18:48:57 -08:00
|
|
|
inline mozilla::css::StyleRule*
|
2007-03-22 10:30:00 -07:00
|
|
|
nsAttrValue::GetCSSStyleRuleValue() const
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(Type() == eCSSStyleRule, "wrong type");
|
|
|
|
return GetMiscContainer()->mCSSStyleRule;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef MOZ_SVG
|
|
|
|
inline nsISVGValue*
|
|
|
|
nsAttrValue::GetSVGValue() const
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(Type() == eSVGValue, "wrong type");
|
|
|
|
return GetMiscContainer()->mSVGValue;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-03-25 07:43:40 -07:00
|
|
|
inline double
|
2008-07-09 01:22:20 -07:00
|
|
|
nsAttrValue::GetFloatValue() const
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(Type() == eFloatValue, "wrong type");
|
|
|
|
return GetMiscContainer()->mFloatValue;
|
|
|
|
}
|
|
|
|
|
2010-06-24 19:01:07 -07:00
|
|
|
inline PRBool
|
|
|
|
nsAttrValue::GetIntMarginValue(nsIntMargin& aMargin) const
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(Type() == eIntMarginValue, "wrong type");
|
|
|
|
nsIntMargin* m = GetMiscContainer()->mIntMargin;
|
|
|
|
if (!m)
|
|
|
|
return PR_FALSE;
|
|
|
|
aMargin = *m;
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
inline nsAttrValue::ValueBaseType
|
|
|
|
nsAttrValue::BaseType() const
|
|
|
|
{
|
2007-07-08 00:08:04 -07:00
|
|
|
return static_cast<ValueBaseType>(mBits & NS_ATTRVALUE_BASETYPE_MASK);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
|
|
|
nsAttrValue::SetPtrValueAndType(void* aValue, ValueBaseType aType)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!(NS_PTR_TO_INT32(aValue) & ~NS_ATTRVALUE_POINTERVALUE_MASK),
|
|
|
|
"pointer not properly aligned, this will crash");
|
2007-07-08 00:08:04 -07:00
|
|
|
mBits = reinterpret_cast<PtrBits>(aValue) | aType;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
|
|
|
nsAttrValue::ResetIfSet()
|
|
|
|
{
|
|
|
|
if (mBits) {
|
|
|
|
Reset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void*
|
|
|
|
nsAttrValue::GetPtr() const
|
|
|
|
{
|
|
|
|
NS_ASSERTION(BaseType() != eIntegerBase,
|
|
|
|
"getting pointer from non-pointer");
|
2007-07-08 00:08:04 -07:00
|
|
|
return reinterpret_cast<void*>(mBits & NS_ATTRVALUE_POINTERVALUE_MASK);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline nsAttrValue::MiscContainer*
|
|
|
|
nsAttrValue::GetMiscContainer() const
|
|
|
|
{
|
|
|
|
NS_ASSERTION(BaseType() == eOtherBase, "wrong type");
|
2007-07-08 00:08:04 -07:00
|
|
|
return static_cast<MiscContainer*>(GetPtr());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline PRInt32
|
|
|
|
nsAttrValue::GetIntInternal() const
|
|
|
|
{
|
|
|
|
NS_ASSERTION(BaseType() == eIntegerBase,
|
|
|
|
"getting integer from non-integer");
|
|
|
|
// Make sure we get a signed value.
|
|
|
|
// Lets hope the optimizer optimizes this into a shift. Unfortunatly signed
|
|
|
|
// bitshift right is implementaion dependant.
|
2007-07-08 00:08:04 -07:00
|
|
|
return static_cast<PRInt32>(mBits & ~NS_ATTRVALUE_INTEGERTYPE_MASK) /
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ATTRVALUE_INTEGERTYPE_MULTIPLIER;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline PRBool
|
|
|
|
nsAttrValue::IsEmptyString() const
|
|
|
|
{
|
|
|
|
return !mBits;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|