Back to index

lightning-sunbird  0.9+nobinonly
Classes | Public Types | Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes | Static Private Attributes
nsAttrValue Class Reference

#include <nsAttrValue.h>

List of all members.

Classes

struct  EnumTable
 Structure for a mapping from int (enum) values to strings. More...
struct  MiscContainer
union  MiscContainer.__unnamed__

Public Types

enum  ValueType {
  eString = 0x00, eAtom = 0x02, eInteger = 0x03, eColor = 0x07,
  eProportional = 0x0B, eEnum = 0x0F, ePercent = 0x13, eCSSStyleRule = 0x14,
  eAtomArray = 0x15
}

Public Member Functions

 nsAttrValue ()
 nsAttrValue (const nsAttrValue &aOther)
 nsAttrValue (const nsAString &aValue)
 nsAttrValue (nsICSSStyleRule *aValue)
 ~nsAttrValue ()
ValueType Type () const
void Reset ()
void SetTo (const nsAttrValue &aOther)
void SetTo (const nsAString &aValue)
void SetTo (PRInt16 aInt)
void SetTo (nsICSSStyleRule *aValue)
void SwapValueWith (nsAttrValue &aOther)
void ToString (nsAString &aResult) const
PRBool IsEmptyString () const
const nsCheapString GetStringValue () const
nsIAtomGetAtomValue () const
 Implementation of inline methods.
PRInt32 GetIntegerValue () const
PRBool GetColorValue (nscolor &aColor) const
PRInt32 GetProportionalValue () const
PRInt16 GetEnumValue () const
float GetPercentValue () const
nsCOMArray< nsIAtom > * GetAtomArrayValue () const
nsICSSStyleRuleGetCSSStyleRuleValue () const
PRInt32 GetAtomCount () const
nsIAtomAtomAt (PRInt32 aIndex) const
PRUint32 HashValue () const
PRBool Equals (const nsAttrValue &aOther) const
void ParseAtom (const nsAString &aValue)
void ParseAtomArray (const nsAString &aValue)
void ParseStringOrAtom (const nsAString &aValue)
PRBool ParseEnumValue (const nsAString &aValue, const EnumTable *aTable, PRBool aCaseSensitive=PR_FALSE)
 Parse into an enum value.
PRBool ParseSpecialIntValue (const nsAString &aString, PRBool aCanBePercent, PRBool aCanBeProportional)
 Parse a string into an integer.
PRBool ParseIntValue (const nsAString &aString)
 Parse a string value into an integer.
PRBool ParseIntWithBounds (const nsAString &aString, PRInt32 aMin, PRInt32 aMax=NS_ATTRVALUE_INTEGERTYPE_MAXVALUE)
 Parse a string value into an integer with minimum value and maximum value.
PRBool ParseColor (const nsAString &aString, nsIDocument *aDocument)
 Parse a string into a color.

Static Public Member Functions

static nsresult Init ()
static void Shutdown ()

Private Types

enum  ValueBaseType { eStringBase = eString, eOtherBase = 0x01, eAtomBase = eAtom, eIntegerBase = 0x03 }

Private Member Functions

ValueBaseType BaseType () const
void SetPtrValueAndType (void *aValue, ValueBaseType aType)
void SetIntValueAndType (PRInt32 aValue, ValueType aType)
void ResetIfSet ()
voidGetPtr () const
MiscContainerGetMiscContainer () const
PRInt32 GetIntInternal () const
PRBool EnsureEmptyMiscContainer ()
PRBool EnsureEmptyAtomArray ()

Private Attributes

PtrBits mBits

Static Private Attributes

static nsVoidArraysEnumTableArray = nsnull

Detailed Description

Definition at line 83 of file nsAttrValue.h.


Class Documentation

struct nsAttrValue::EnumTable

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 } }

Definition at line 173 of file nsAttrValue.h.

Class Members
const char * tag The string the value maps to.
PRInt16 value The enum value that maps to this string.
struct nsAttrValue::MiscContainer

Definition at line 247 of file nsAttrValue.h.

Class Members
union MiscContainer __unnamed__
ValueType mType
union nsAttrValue::MiscContainer.__unnamed__

Definition at line 250 of file nsAttrValue.h.

Class Members
nsCOMArray< nsIAtom > * mAtomArray
nscolor mColor
nsICSSStyleRule * mCSSStyleRule

Member Enumeration Documentation

Enumerator:
eStringBase 
eOtherBase 
eAtomBase 
eIntegerBase 

Definition at line 240 of file nsAttrValue.h.

                     {
    eStringBase =    eString,    // 00
    eOtherBase =     0x01,       // 01
    eAtomBase =      eAtom,      // 10
    eIntegerBase =   0x03        // 11
  };
Enumerator:
eString 
eAtom 
eInteger 
eColor 
eProportional 
eEnum 
ePercent 
eCSSStyleRule 
eAtomArray 

Definition at line 98 of file nsAttrValue.h.

                 {
    eString =       0x00, //    00
                          //    01  this value indicates an 'misc' struct
    eAtom =         0x02, //    10
    eInteger =      0x03, // 00011
    eColor =        0x07, // 00111
    eProportional = 0x0B, // 01011
    eEnum =         0x0F, // 01111  This should eventually die
    ePercent =      0x13, // 10011
    // Values below here won't matter, they'll be stored in the 'misc' struct
    // anyway
    eCSSStyleRule = 0x14,
    eAtomArray =    0x15 
#ifdef MOZ_SVG
    ,eSVGValue =    0x16
#endif
  };

Constructor & Destructor Documentation

Definition at line 53 of file nsAttrValue.cpp.

    : mBits(0)
{
}

Definition at line 58 of file nsAttrValue.cpp.

    : mBits(0)
{
  SetTo(aOther);
}

Here is the call graph for this function:

nsAttrValue::nsAttrValue ( const nsAString &  aValue) [explicit]

Definition at line 64 of file nsAttrValue.cpp.

    : mBits(0)
{
  SetTo(aValue);
}

Here is the call graph for this function:

nsAttrValue::nsAttrValue ( nsICSSStyleRule aValue) [explicit]

Definition at line 70 of file nsAttrValue.cpp.

    : mBits(0)
{
  SetTo(aValue);
}

Here is the call graph for this function:

Definition at line 84 of file nsAttrValue.cpp.

{
  ResetIfSet();
}

Here is the call graph for this function:


Member Function Documentation

nsIAtom * nsAttrValue::AtomAt ( PRInt32  aIndex) const

Definition at line 465 of file nsAttrValue.cpp.

{
  NS_PRECONDITION(aIndex >= 0, "Index must not be negative");
  NS_PRECONDITION(GetAtomCount() > aIndex, "aIndex out of range");
  
  if (BaseType() == eAtomBase) {
    return GetAtomValue();
  }

  NS_ASSERTION(Type() == eAtomArray, "GetAtomCount must be confused");
  
  return GetAtomArrayValue()->ObjectAt(aIndex);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 345 of file nsAttrValue.h.

Here is the caller graph for this function:

Definition at line 927 of file nsAttrValue.cpp.

{
  if (Type() == eAtomArray) {
    GetAtomArrayValue()->Clear();
    return PR_TRUE;
  }

  if (!EnsureEmptyMiscContainer()) {
    // should already be reset
    return PR_FALSE;
  }

  nsCOMArray<nsIAtom>* array = new nsCOMArray<nsIAtom>;
  if (!array) {
    Reset();
    return PR_FALSE;
  }

  MiscContainer* cont = GetMiscContainer();
  cont->mAtomArray = array;
  cont->mType = eAtomArray;

  return PR_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 882 of file nsAttrValue.cpp.

{
  MiscContainer* cont;
  if (BaseType() == eOtherBase) {
    cont = GetMiscContainer();
    switch (cont->mType) {
      case eCSSStyleRule:
      {
        NS_RELEASE(cont->mCSSStyleRule);
        break;
      }
      case eAtomArray:
      {
        delete cont->mAtomArray;
        break;
      }
#ifdef MOZ_SVG
      case eSVGValue:
      {
        NS_RELEASE(cont->mSVGValue);
        break;
      }
#endif
      default:
      {
        break;
      }
    }
  }
  else {
    ResetIfSet();

    cont = new MiscContainer;
    NS_ENSURE_TRUE(cont, PR_FALSE);

    SetPtrValueAndType(cont, eOtherBase);
  }

  cont->mType = eColor;
  cont->mColor = 0;

  return PR_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 541 of file nsAttrValue.cpp.

{
  if (BaseType() != aOther.BaseType()) {
    return PR_FALSE;
  }

  switch(BaseType()) {
    case eStringBase:
    {
      return GetStringValue().Equals(aOther.GetStringValue());
    }
    case eOtherBase:
    {
      break;
    }
    case eAtomBase:
    case eIntegerBase:
    {
      return mBits == aOther.mBits;
    }
  }

  MiscContainer* thisCont = GetMiscContainer();
  MiscContainer* otherCont = aOther.GetMiscContainer();
  if (thisCont->mType != otherCont->mType) {
    return PR_FALSE;
  }

  switch (thisCont->mType) {
    case eColor:
    {
      return thisCont->mColor == otherCont->mColor;
    }
    case eCSSStyleRule:
    {
      return thisCont->mCSSStyleRule == otherCont->mCSSStyleRule;
    }
    case eAtomArray:
    {
      // For classlists we could be insensitive to order, however
      // classlists are never mapped attributes so they are never compared.

      PRInt32 count = thisCont->mAtomArray->Count();
      if (count != otherCont->mAtomArray->Count()) {
        return PR_FALSE;
      }

      PRInt32 i;
      for (i = 0; i < count; ++i) {
        if (thisCont->mAtomArray->ObjectAt(i) !=
            otherCont->mAtomArray->ObjectAt(i)) {
          return PR_FALSE;
        }
      }
      return PR_TRUE;
    }
#ifdef MOZ_SVG
    case eSVGValue:
    {
      return thisCont->mSVGValue == otherCont->mSVGValue;
    }
#endif
    default:
    {
      NS_NOTREACHED("unknown type stored in MiscContainer");
      return PR_FALSE;
    }
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 322 of file nsAttrValue.h.

{
  NS_PRECONDITION(Type() == eAtomArray, "wrong type");
  return GetMiscContainer()->mAtomArray;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 449 of file nsAttrValue.cpp.

{
  ValueType type = Type();

  if (type == eAtom) {
    return 1;
  }

  if (type == eAtomArray) {
    return GetAtomArrayValue()->Count();
  }

  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsIAtom * nsAttrValue::GetAtomValue ( ) const [inline]

Implementation of inline methods.

Definition at line 283 of file nsAttrValue.h.

{
  NS_PRECONDITION(Type() == eAtom, "wrong type");
  return NS_REINTERPRET_CAST(nsIAtom*, GetPtr());
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 417 of file nsAttrValue.cpp.

{
  NS_PRECONDITION(Type() == eColor || Type() == eString, "wrong type");
  switch (BaseType()) {
    case eString:
    {
      return GetPtr() && NS_ColorNameToRGB(GetStringValue(), &aColor);
    }
    case eOtherBase:
    {
      aColor = GetMiscContainer()->mColor;
      
      break;
    }
    case eIntegerBase:
    {
      aColor = NS_STATIC_CAST(nscolor, GetIntInternal());
      
      break;
    }
    default:
    {
      NS_NOTREACHED("unexpected basetype");
      
      break;
    }
  }

  return PR_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 329 of file nsAttrValue.h.

{
  NS_PRECONDITION(Type() == eCSSStyleRule, "wrong type");
  return GetMiscContainer()->mCSSStyleRule;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRInt16 nsAttrValue::GetEnumValue ( ) const [inline]

Definition at line 304 of file nsAttrValue.h.

{
  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.
  return NS_STATIC_CAST(PRInt16,
            GetIntInternal() >> NS_ATTRVALUE_ENUMTABLEINDEX_BITS);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 290 of file nsAttrValue.h.

{
  NS_PRECONDITION(Type() == eInteger, "wrong type");
  return GetIntInternal();
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRInt32 nsAttrValue::GetIntInternal ( ) const [inline, private]

Definition at line 395 of file nsAttrValue.h.

{
  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.
  return NS_STATIC_CAST(PRInt32, mBits & ~NS_ATTRVALUE_INTEGERTYPE_MASK) /
         NS_ATTRVALUE_INTEGERTYPE_MULTIPLIER;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 388 of file nsAttrValue.h.

{
  NS_ASSERTION(BaseType() == eOtherBase, "wrong type");
  return NS_STATIC_CAST(MiscContainer*, GetPtr());
}

Here is the call graph for this function:

Here is the caller graph for this function:

float nsAttrValue::GetPercentValue ( ) const [inline]

Definition at line 314 of file nsAttrValue.h.

{
  NS_PRECONDITION(Type() == ePercent, "wrong type");
  return NS_STATIC_CAST(float, GetIntInternal()) /
         100.0f;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 297 of file nsAttrValue.h.

{
  NS_PRECONDITION(Type() == eProportional, "wrong type");
  return GetIntInternal();
}

Here is the call graph for this function:

Here is the caller graph for this function:

void * nsAttrValue::GetPtr ( ) const [inline, private]

Definition at line 380 of file nsAttrValue.h.

{
  NS_ASSERTION(BaseType() != eIntegerBase,
               "getting pointer from non-pointer");
  return NS_REINTERPRET_CAST(void*, mBits & NS_ATTRVALUE_POINTERVALUE_MASK);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 409 of file nsAttrValue.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 480 of file nsAttrValue.cpp.

{
  switch(BaseType()) {
    case eStringBase:
    {
      nsStringBuffer* str = NS_STATIC_CAST(nsStringBuffer*, GetPtr());
      if (str) {
        PRUint32 len = str->StorageSize()/sizeof(PRUnichar) - 1;
        return nsCRT::BufferHashCode(NS_STATIC_CAST(PRUnichar*, str->Data()), len);
      }

      return 0;
    }
    case eOtherBase:
    {
      break;
    }
    case eAtomBase:
    case eIntegerBase:
    {
      // mBits and PRUint32 might have different size. This should silence
      // any warnings or compile-errors. This is what the implementation of
      // NS_PTR_TO_INT32 does to take care of the same problem.
      return mBits - 0;
    }
  }

  MiscContainer* cont = GetMiscContainer();
  switch (cont->mType) {
    case eColor:
    {
      return cont->mColor;
    }
    case eCSSStyleRule:
    {
      return NS_PTR_TO_INT32(cont->mCSSStyleRule);
    }
    case eAtomArray:
    {
      PRUint32 retval = 0;
      PRInt32 i, count = cont->mAtomArray->Count();
      for (i = 0; i < count; ++i) {
        retval ^= NS_PTR_TO_INT32(cont->mAtomArray->ObjectAt(i));
      }
      return retval;
    }
#ifdef MOZ_SVG
    case eSVGValue:
    {
      return NS_PTR_TO_INT32(cont->mSVGValue);
    }
#endif
    default:
    {
      NS_NOTREACHED("unknown type stored in MiscContainer");
      return 0;
    }
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 91 of file nsAttrValue.cpp.

Here is the call graph for this function:

PRBool nsAttrValue::IsEmptyString ( ) const [inline]

Definition at line 407 of file nsAttrValue.h.

{
  return !mBits;
}

Here is the caller graph for this function:

void nsAttrValue::ParseAtom ( const nsAString &  aValue)

Definition at line 612 of file nsAttrValue.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void nsAttrValue::ParseAtomArray ( const nsAString &  aValue)

Definition at line 623 of file nsAttrValue.cpp.

{
  nsAString::const_iterator iter, end;
  aValue.BeginReading(iter);
  aValue.EndReading(end);

  // skip initial whitespace
  while (iter != end && nsCRT::IsAsciiSpace(*iter)) {
    ++iter;
  }

  if (iter == end) {
    ResetIfSet();
    return;
  }

  nsAString::const_iterator start(iter);

  // get first - and often only - atom
  do {
    ++iter;
  } while (iter != end && !nsCRT::IsAsciiSpace(*iter));

  nsCOMPtr<nsIAtom> classAtom = do_GetAtom(Substring(start, iter));
  if (!classAtom) {
    Reset();
    return;
  }

  // skip whitespace
  while (iter != end && nsCRT::IsAsciiSpace(*iter)) {
    ++iter;
  }

  if (iter == end) {
    // we only found one classname so don't bother storing a list
    ResetIfSet();
    nsIAtom* atom = nsnull;
    classAtom.swap(atom);
    SetPtrValueAndType(atom, eAtomBase);
    return;
  }

  if (!EnsureEmptyAtomArray()) {
    return;
  }

  nsCOMArray<nsIAtom>* array = GetAtomArrayValue();
  
  if (!array->AppendObject(classAtom)) {
    Reset();
    return;
  }

  // parse the rest of the classnames
  do {
    start = iter;

    do {
      ++iter;
    } while (iter != end && !nsCRT::IsAsciiSpace(*iter));

    classAtom = do_GetAtom(Substring(start, iter));

    if (!array->AppendObject(classAtom)) {
      Reset();
      return;
    }

    // skip whitespace
    while (iter != end && nsCRT::IsAsciiSpace(*iter)) {
      ++iter;
    }
  } while (iter != end);

  return;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsAttrValue::ParseColor ( const nsAString &  aString,
nsIDocument aDocument 
)

Parse a string into a color.

Parameters:
aStringthe string to parse
aDocumentthe document (to find out whether we're in quirks mode)
Returns:
whether the value could be parsed

Definition at line 831 of file nsAttrValue.cpp.

{
  nsAutoString colorStr(aString);
  colorStr.CompressWhitespace(PR_TRUE, PR_TRUE);
  if (colorStr.IsEmpty()) {
    Reset();
    return PR_FALSE;
  }

  nscolor color;
  // No color names begin with a '#', but numerical colors do so
  // it is a very common first char
  if ((colorStr.CharAt(0) != '#') && NS_ColorNameToRGB(colorStr, &color)) {
    SetTo(colorStr);
    return PR_TRUE;
  }

  // Check if we are in compatibility mode
  // XXX evil NS_HexToRGB and NS_LooseHexToRGB take nsString as argument!
  nsCOMPtr<nsIHTMLDocument> doc(do_QueryInterface(aDocument));
  if (doc && doc->GetCompatibilityMode() == eCompatibility_NavQuirks) {
    NS_LooseHexToRGB(colorStr, &color);
  }
  else {
    if (colorStr.First() != '#') {
      Reset();
      return PR_FALSE;
    }
    colorStr.Cut(0, 1);
    if (!NS_HexToRGB(colorStr, &color)) {
      Reset();
      return PR_FALSE;
    }
  }

  PRInt32 colAsInt = NS_STATIC_CAST(PRInt32, color);
  PRInt32 tmp = colAsInt * NS_ATTRVALUE_INTEGERTYPE_MULTIPLIER;
  if (tmp / NS_ATTRVALUE_INTEGERTYPE_MULTIPLIER == colAsInt) {
    ResetIfSet();
    SetIntValueAndType(colAsInt, eColor);
  }
  else if (EnsureEmptyMiscContainer()) {
    MiscContainer* cont = GetMiscContainer();
    cont->mColor = color;
    cont->mType = eColor;
  }

  return PR_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsAttrValue::ParseEnumValue ( const nsAString &  aValue,
const EnumTable aTable,
PRBool  aCaseSensitive = PR_FALSE 
)

Parse into an enum value.

Parameters:
aValuethe string to find the value for
aTablethe enumeration to map with
aResultthe enum mapping [OUT]
Returns:
whether the enum value was found or not

Definition at line 716 of file nsAttrValue.cpp.

{
  ResetIfSet();

  // Have to const cast here since nsVoidArray can't deal with constpointers
  EnumTable* tableStart = NS_CONST_CAST(EnumTable*, aTable);

  nsAutoString val(aValue);
  while (aTable->tag) {
    if (aCaseSensitive ? val.EqualsASCII(aTable->tag) :
                         val.EqualsIgnoreCase(aTable->tag)) {

      // Find index of EnumTable
      PRInt16 index = sEnumTableArray->IndexOf(tableStart);
      if (index < 0) {
        index = sEnumTableArray->Count();
        NS_ASSERTION(index <= NS_ATTRVALUE_ENUMTABLEINDEX_MAXVALUE,
                     "too many enum tables");
        if (!sEnumTableArray->AppendElement(tableStart)) {
          return PR_FALSE;
        }
      }

      PRInt32 value = (aTable->value << NS_ATTRVALUE_ENUMTABLEINDEX_BITS) +
                      index;

      SetIntValueAndType(value, eEnum);
      NS_ASSERTION(GetEnumValue() == aTable->value,
                   "failed to store enum properly");

      return PR_TRUE;
    }
    aTable++;
  }

  return PR_FALSE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsAttrValue::ParseIntValue ( const nsAString &  aString) [inline]

Parse a string value into an integer.

Parameters:
aStringthe string to parse
Returns:
whether the value could be parsed

Definition at line 213 of file nsAttrValue.h.

Here is the call graph for this function:

Here is the caller graph for this function:

Parse a string value into an integer with minimum value and maximum value.

Parameters:
aStringthe string to parse
aMinthe minimum value (if value is less it will be bumped up)
aMaxthe maximum value (if value is greater it will be chopped down)
Returns:
whether the value could be parsed

Definition at line 808 of file nsAttrValue.cpp.

{
  NS_PRECONDITION(aMin < aMax &&
                  aMin >= NS_ATTRVALUE_INTEGERTYPE_MINVALUE &&
                  aMax <= NS_ATTRVALUE_INTEGERTYPE_MAXVALUE, "bad boundaries");

  ResetIfSet();

  PRInt32 ec;
  PRInt32 val = PromiseFlatString(aString).ToInteger(&ec);
  if (NS_FAILED(ec)) {
    return PR_FALSE;
  }

  val = PR_MAX(val, aMin);
  val = PR_MIN(val, aMax);
  SetIntValueAndType(val, eInteger);

  return PR_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsAttrValue::ParseSpecialIntValue ( const nsAString &  aString,
PRBool  aCanBePercent,
PRBool  aCanBeProportional 
)

Parse a string into an integer.

Can optionally parse percent (n%) and proportional (n*). This method explicitly sets a lower bound of zero on the element, whether it be proportional or percent or raw integer.

Parameters:
aStringthe string to parse
aCanBePercentPR_TRUE if it can be a percent value (%)
aCanBeProportionalPR_TRUE if it can be a proportional value (*)
Returns:
whether the value could be parsed

Definition at line 757 of file nsAttrValue.cpp.

{
  ResetIfSet();

  PRInt32 ec;
  nsAutoString tmp(aString);
  PRInt32 val = tmp.ToInteger(&ec);

  if (NS_FAILED(ec)) {
    if (aCanBeProportional) {
      // Even if the integer could not be parsed, it might just be "*"
      tmp.CompressWhitespace(PR_TRUE, PR_TRUE);
      if (tmp.Length() == 1 && tmp.Last() == '*') {
        // special case: HTML spec says a value '*' == '1*'
        // see http://www.w3.org/TR/html4/types.html#type-multi-length
        // bug 29061
        SetIntValueAndType(1, eProportional);
        return PR_TRUE;
      }
    }
    return PR_FALSE;
  }

  val = PR_MAX(val, 0);
  val = PR_MIN(val, NS_ATTRVALUE_INTEGERTYPE_MAXVALUE);

  // % (percent)
  // XXX RFindChar means that 5%x will be parsed!
  if (aCanBePercent && tmp.RFindChar('%') >= 0) {
    if (val > 100) {
      val = 100;
    }
    SetIntValueAndType(val, ePercent);
    return PR_TRUE;
  }

  // * (proportional) 
  // XXX RFindChar means that 5*x will be parsed!
  if (aCanBeProportional && tmp.RFindChar('*') >= 0) {
    SetIntValueAndType(val, eProportional);
    return PR_TRUE;
  }

  // Straight number is interpreted as integer
  SetIntValueAndType(val, eInteger);
  return PR_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsAttrValue::ParseStringOrAtom ( const nsAString &  aValue)

Definition at line 702 of file nsAttrValue.cpp.

{
  PRUint32 len = aValue.Length();
  // Don't bother with atoms if it's an empty string since
  // we can store those efficently anyway.
  if (len && len <= NS_ATTRVALUE_MAX_STRINGLENGTH_ATOM) {
    ParseAtom(aValue);
  }
  else {
    SetTo(aValue);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 129 of file nsAttrValue.cpp.

{
  switch(BaseType()) {
    case eStringBase:
    {
      nsStringBuffer* str = NS_STATIC_CAST(nsStringBuffer*, GetPtr());
      if (str) {
        str->Release();
      }

      break;
    }
    case eOtherBase:
    {
      EnsureEmptyMiscContainer();
      delete GetMiscContainer();

      break;
    }
    case eAtomBase:
    {
      nsIAtom* atom = GetAtomValue();
      NS_RELEASE(atom);

      break;
    }
    case eIntegerBase:
    {
      break;
    }
  }

  mBits = 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsAttrValue::ResetIfSet ( ) [inline, private]

Definition at line 372 of file nsAttrValue.h.

{
  if (mBits) {
    Reset();
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsAttrValue::SetIntValueAndType ( PRInt32  aValue,
ValueType  aType 
) [inline, private]

Definition at line 359 of file nsAttrValue.h.

{
#ifdef DEBUG
  {
    PRInt32 tmp = aValue * NS_ATTRVALUE_INTEGERTYPE_MULTIPLIER;
    NS_ASSERTION(tmp / NS_ATTRVALUE_INTEGERTYPE_MULTIPLIER == aValue,
                 "Integer too big to fit");
  }
#endif
  mBits = (aValue * NS_ATTRVALUE_INTEGERTYPE_MULTIPLIER) | aType;
}

Here is the caller graph for this function:

void nsAttrValue::SetPtrValueAndType ( void aValue,
ValueBaseType  aType 
) [inline, private]

Definition at line 351 of file nsAttrValue.h.

{
  NS_ASSERTION(!(NS_PTR_TO_INT32(aValue) & ~NS_ATTRVALUE_POINTERVALUE_MASK),
               "pointer not properly aligned, this will crash");
  mBits = NS_REINTERPRET_CAST(PtrBits, aValue) | aType;
}

Here is the caller graph for this function:

Definition at line 165 of file nsAttrValue.cpp.

{
  switch (aOther.BaseType()) {
    case eStringBase:
    {
      ResetIfSet();
      nsStringBuffer* str = NS_STATIC_CAST(nsStringBuffer*, aOther.GetPtr());
      if (str) {
        str->AddRef();
        SetPtrValueAndType(str, eStringBase);
      }
      return;
    }
    case eOtherBase:
    {
      break;
    }
    case eAtomBase:
    {
      ResetIfSet();
      nsIAtom* atom = aOther.GetAtomValue();
      NS_ADDREF(atom);
      SetPtrValueAndType(atom, eAtomBase);
      return;
    }
    case eIntegerBase:
    {
      ResetIfSet();
      mBits = aOther.mBits;
      return;      
    }
  }

  MiscContainer* otherCont = aOther.GetMiscContainer();
  switch (otherCont->mType) {
    case eColor:
    {
      if (EnsureEmptyMiscContainer()) {
        MiscContainer* cont = GetMiscContainer();
        cont->mColor = otherCont->mColor;
        cont->mType = eColor;
      }
      break;
    }
    case eCSSStyleRule:
    {
      SetTo(otherCont->mCSSStyleRule);
      break;
    }
    case eAtomArray:
    {
      if (!EnsureEmptyAtomArray() ||
          !GetAtomArrayValue()->AppendObjects(*otherCont->mAtomArray)) {
        Reset();
      }
      break;
    }
#ifdef MOZ_SVG
    case eSVGValue:
    {
      SetTo(otherCont->mSVGValue);
    }
#endif
    default:
    {
      NS_NOTREACHED("unknown type stored in MiscContainer");
      break;
    }
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsAttrValue::SetTo ( const nsAString &  aValue)

Definition at line 237 of file nsAttrValue.cpp.

{
  ResetIfSet();
  if (!aValue.IsEmpty()) {
    PRUint32 len = aValue.Length();

    nsStringBuffer* buf = nsStringBuffer::FromString(aValue);
    if (buf && (buf->StorageSize()/sizeof(PRUnichar) - 1) == len) {
      buf->AddRef();
      SetPtrValueAndType(buf, eStringBase);
      return;
    }

    buf = nsStringBuffer::Alloc((len + 1) * sizeof(PRUnichar));
    if (!buf) {
      return;
    }
    PRUnichar *data = NS_STATIC_CAST(PRUnichar*, buf->Data());
    CopyUnicodeTo(aValue, 0, data, len);
    data[len] = PRUnichar(0);

    SetPtrValueAndType(buf, eStringBase);
  }
}

Here is the call graph for this function:

Definition at line 263 of file nsAttrValue.cpp.

Here is the call graph for this function:

Definition at line 270 of file nsAttrValue.cpp.

{
  if (EnsureEmptyMiscContainer()) {
    MiscContainer* cont = GetMiscContainer();
    NS_ADDREF(cont->mCSSStyleRule = aValue);
    cont->mType = eCSSStyleRule;
  }
}

Here is the call graph for this function:

Definition at line 103 of file nsAttrValue.cpp.

Definition at line 292 of file nsAttrValue.cpp.

{
  PtrBits tmp = aOther.mBits;
  aOther.mBits = mBits;
  mBits = tmp;
}

Here is the caller graph for this function:

void nsAttrValue::ToString ( nsAString &  aResult) const

Definition at line 300 of file nsAttrValue.cpp.

{
  switch(Type()) {
    case eString:
    {
      nsStringBuffer* str = NS_STATIC_CAST(nsStringBuffer*, GetPtr());
      if (str) {
        str->ToString(str->StorageSize()/sizeof(PRUnichar) - 1, aResult);
      }
      else {
        aResult.Truncate();
      }
      break;
    }
    case eAtom:
    {
      NS_STATIC_CAST(nsIAtom*, GetPtr())->ToString(aResult);

      break;
    }
    case eInteger:
    {
      nsAutoString intStr;
      intStr.AppendInt(GetIntInternal());
      aResult = intStr;

      break;
    }
    case eColor:
    {
      nscolor v;
      GetColorValue(v);
      NS_RGBToHex(v, aResult);

      break;
    }
    case eProportional:
    {
      nsAutoString intStr;
      intStr.AppendInt(GetIntInternal());
      aResult = intStr + NS_LITERAL_STRING("*");

      break;
    }
    case eEnum:
    {
      PRInt16 val = GetEnumValue();
      EnumTable* table = NS_STATIC_CAST(EnumTable*, sEnumTableArray->
          FastElementAt(GetIntInternal() & NS_ATTRVALUE_ENUMTABLEINDEX_MASK));
      while (table->tag) {
        if (table->value == val) {
          aResult.AssignASCII(table->tag);

          return;
        }
        table++;
      }

      NS_NOTREACHED("couldn't find value in EnumTable");

      break;
    }
    case ePercent:
    {
      nsAutoString intStr;
      intStr.AppendInt(GetIntInternal());
      aResult = intStr + NS_LITERAL_STRING("%");

      break;
    }
    case eCSSStyleRule:
    {
      aResult.Truncate();
      nsCSSDeclaration* decl = 
        GetMiscContainer()->mCSSStyleRule->GetDeclaration();
      if (decl) {
        decl->ToString(aResult);
      }

      break;
    }
    case eAtomArray:
    {
      MiscContainer* cont = GetMiscContainer();
      PRInt32 count = cont->mAtomArray->Count();
      if (count) {
        cont->mAtomArray->ObjectAt(0)->ToString(aResult);
        nsAutoString tmp;
        PRInt32 i;
        for (i = 1; i < count; ++i) {
          cont->mAtomArray->ObjectAt(i)->ToString(tmp);
          aResult.Append(NS_LITERAL_STRING(" ") + tmp);
        }
      }
      else {
        aResult.Truncate();
      }
      break;
    }
#ifdef MOZ_SVG
    case eSVGValue:
    {
      GetMiscContainer()->mSVGValue->GetValueString(aResult);
    }
#endif
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 110 of file nsAttrValue.cpp.

Here is the call graph for this function:


Member Data Documentation

Definition at line 275 of file nsAttrValue.h.

Definition at line 273 of file nsAttrValue.h.


The documentation for this class was generated from the following files: