Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Public Attributes
nsStyleCoord Class Reference

Class that hold a single size specification used by the style system. More...

#include <nsStyleCoord.h>

Collaboration diagram for nsStyleCoord:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nsStyleCoord (nsStyleUnit aUnit=eStyleUnit_Null)
 nsStyleCoord (nscoord aValue)
 nsStyleCoord (PRInt32 aValue, nsStyleUnit aUnit)
 nsStyleCoord (float aValue, nsStyleUnit aUnit)
 nsStyleCoord (const nsStyleCoord &aCopy)
nsStyleCoordoperator= (const nsStyleCoord &aCopy)
PRBool operator== (const nsStyleCoord &aOther) const
PRBool operator!= (const nsStyleCoord &aOther) const
nsStyleUnit GetUnit (void) const
nscoord GetCoordValue (void) const
PRInt32 GetIntValue (void) const
float GetPercentValue (void) const
float GetFactorValue (void) const
void GetUnionValue (nsStyleUnion &aValue) const
void Reset (void)
void SetCoordValue (nscoord aValue)
void SetIntValue (PRInt32 aValue, nsStyleUnit aUnit)
void SetPercentValue (float aValue)
void SetFactorValue (float aValue)
void SetNormalValue (void)
void SetAutoValue (void)
void SetUnionValue (const nsStyleUnion &aValue, nsStyleUnit aUnit)
void AppendToString (nsString &aBuffer) const
void ToString (nsString &aBuffer) const

Public Attributes

nsStyleUnit mUnit
nsStyleUnion mValue

Detailed Description

Class that hold a single size specification used by the style system.

The size specification consists of two parts -- a number and a unit. The number is an integer, a floating point value, an nscoord, or undefined, and the unit is an nsStyleUnit. Checking the unit is a must before asking for the value in any particular form.

Definition at line 72 of file nsStyleCoord.h.


Constructor & Destructor Documentation

Definition at line 42 of file nsStyleCoord.cpp.

  : mUnit(aUnit)
{
  NS_ASSERTION(aUnit < eStyleUnit_Percent, "not a valueless unit");
  if (aUnit >= eStyleUnit_Percent) {
    mUnit = eStyleUnit_Null;
  }
  mValue.mInt = 0;
}

Definition at line 52 of file nsStyleCoord.cpp.

Definition at line 58 of file nsStyleCoord.cpp.

  : mUnit(aUnit)
{
  //if you want to pass in eStyleUnit_Coord, don't. instead, use the
  //constructor just above this one... MMP
  NS_ASSERTION((aUnit == eStyleUnit_Proportional) ||
               (aUnit == eStyleUnit_Enumerated) ||
               (aUnit == eStyleUnit_Integer), "not an int value");
  if ((aUnit == eStyleUnit_Proportional) ||
      (aUnit == eStyleUnit_Enumerated) ||
      (aUnit == eStyleUnit_Integer)) {
    mValue.mInt = aValue;
  }
  else {
    mUnit = eStyleUnit_Null;
    mValue.mInt = 0;
  }
}
nsStyleCoord::nsStyleCoord ( float  aValue,
nsStyleUnit  aUnit 
)

Definition at line 77 of file nsStyleCoord.cpp.

  : mUnit(aUnit)
{
  NS_ASSERTION((aUnit == eStyleUnit_Percent) ||
               (aUnit == eStyleUnit_Factor), "not a float value");
  if ((aUnit == eStyleUnit_Percent) ||
      (aUnit == eStyleUnit_Factor)) {
    mValue.mFloat = aValue;
  }
  else {
    mUnit = eStyleUnit_Null;
    mValue.mInt = 0;
  }
}

Definition at line 92 of file nsStyleCoord.cpp.

  : mUnit(aCopy.mUnit)
{
  if ((eStyleUnit_Percent <= mUnit) && (mUnit < eStyleUnit_Coord)) {
    mValue.mFloat = aCopy.mValue.mFloat;
  }
  else {
    mValue.mInt = aCopy.mValue.mInt;
  }
}

Member Function Documentation

Definition at line 192 of file nsStyleCoord.cpp.

{
  if ((eStyleUnit_Percent <= mUnit) && (mUnit < eStyleUnit_Coord)) {
    aBuffer.AppendFloat(mValue.mFloat);
  }
  else if ((eStyleUnit_Coord == mUnit) || 
           (eStyleUnit_Proportional == mUnit) ||
           (eStyleUnit_Enumerated == mUnit) ||
           (eStyleUnit_Integer == mUnit)) {
    aBuffer.AppendInt(mValue.mInt, 10);
    aBuffer.AppendLiteral("[0x");
    aBuffer.AppendInt(mValue.mInt, 16);
    aBuffer.Append(PRUnichar(']'));
  }

  switch (mUnit) {
    case eStyleUnit_Null:         aBuffer.AppendLiteral("Null");     break;
    case eStyleUnit_Coord:        aBuffer.AppendLiteral("tw");       break;
    case eStyleUnit_Percent:      aBuffer.AppendLiteral("%");        break;
    case eStyleUnit_Factor:       aBuffer.AppendLiteral("f");        break;
    case eStyleUnit_Normal:       aBuffer.AppendLiteral("Normal");   break;
    case eStyleUnit_Auto:         aBuffer.AppendLiteral("Auto");     break;
    case eStyleUnit_Proportional: aBuffer.AppendLiteral("*");        break;
    case eStyleUnit_Enumerated:   aBuffer.AppendLiteral("enum");     break;
    case eStyleUnit_Integer:      aBuffer.AppendLiteral("int");      break;
    case eStyleUnit_Chars:        aBuffer.AppendLiteral("chars");    break;
  }
  aBuffer.Append(PRUnichar(' '));
}

Here is the caller graph for this function:

Definition at line 160 of file nsStyleCoord.h.

{
  NS_ASSERTION((mUnit == eStyleUnit_Coord), "not a coord value");
  if (mUnit == eStyleUnit_Coord) {
    return mValue.mInt;
  }
  return 0;
}
float nsStyleCoord::GetFactorValue ( void  ) const [inline]

Definition at line 193 of file nsStyleCoord.h.

{
  NS_ASSERTION(mUnit == eStyleUnit_Factor, "not a factor value");
  if (mUnit == eStyleUnit_Factor) {
    return mValue.mFloat;
  }
  return 0.0f;
}

Here is the caller graph for this function:

PRInt32 nsStyleCoord::GetIntValue ( void  ) const [inline]

Definition at line 169 of file nsStyleCoord.h.

Here is the caller graph for this function:

float nsStyleCoord::GetPercentValue ( void  ) const [inline]

Definition at line 184 of file nsStyleCoord.h.

{
  NS_ASSERTION(mUnit == eStyleUnit_Percent, "not a percent value");
  if (mUnit == eStyleUnit_Percent) {
    return mValue.mFloat;
  }
  return 0.0f;
}

Here is the caller graph for this function:

void nsStyleCoord::GetUnionValue ( nsStyleUnion aValue) const [inline]

Definition at line 202 of file nsStyleCoord.h.

{
  memcpy(&aValue, &mValue, sizeof(nsStyleUnion));
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsStyleUnit nsStyleCoord::GetUnit ( void  ) const [inline]

Definition at line 84 of file nsStyleCoord.h.

{ return mUnit; }
PRBool nsStyleCoord::operator!= ( const nsStyleCoord aOther) const [inline]

Definition at line 155 of file nsStyleCoord.h.

{
  return PRBool(! ((*this) == aOther));
}
nsStyleCoord & nsStyleCoord::operator= ( const nsStyleCoord aCopy)

Definition at line 103 of file nsStyleCoord.cpp.

{
  mUnit = aCopy.mUnit;
  if ((eStyleUnit_Percent <= mUnit) && (mUnit < eStyleUnit_Coord)) {
    mValue.mFloat = aCopy.mValue.mFloat;
  }
  else {
    mValue.mInt = aCopy.mValue.mInt;
  }
  return *this;
}
PRBool nsStyleCoord::operator== ( const nsStyleCoord aOther) const

Definition at line 115 of file nsStyleCoord.cpp.

{
  if (mUnit == aOther.mUnit) {
    if ((eStyleUnit_Percent <= mUnit) && (mUnit < eStyleUnit_Coord)) {
      return PRBool(mValue.mFloat == aOther.mValue.mFloat);
    }
    else {
      return PRBool(mValue.mInt == aOther.mValue.mInt);
    }
  }
  return PR_FALSE;
}

Definition at line 128 of file nsStyleCoord.cpp.

Here is the caller graph for this function:

Definition at line 176 of file nsStyleCoord.cpp.

Here is the caller graph for this function:

Definition at line 134 of file nsStyleCoord.cpp.

Here is the caller graph for this function:

Definition at line 164 of file nsStyleCoord.cpp.

Here is the caller graph for this function:

Definition at line 140 of file nsStyleCoord.cpp.

{
  NS_ASSERTION((aUnit == eStyleUnit_Proportional) ||
               (aUnit == eStyleUnit_Enumerated) ||
               (aUnit == eStyleUnit_Chars) ||
               (aUnit == eStyleUnit_Integer), "not an int value");
  if ((aUnit == eStyleUnit_Proportional) ||
      (aUnit == eStyleUnit_Enumerated) ||
      (aUnit == eStyleUnit_Chars) ||
      (aUnit == eStyleUnit_Integer)) {
    mUnit = aUnit;
    mValue.mInt = aValue;
  }
  else {
    Reset();
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 170 of file nsStyleCoord.cpp.

Here is the caller graph for this function:

Definition at line 158 of file nsStyleCoord.cpp.

Here is the caller graph for this function:

Definition at line 182 of file nsStyleCoord.cpp.

{
  mUnit = aUnit;
#if PR_BYTES_PER_INT == PR_BYTES_PER_FLOAT
  mValue.mInt = aValue.mInt;
#else
  memcpy(&mValue, &aValue, sizeof(nsStyleUnion));
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsStyleCoord::ToString ( nsString aBuffer) const

Definition at line 222 of file nsStyleCoord.cpp.

{
  aBuffer.Truncate();
  AppendToString(aBuffer);
}

Here is the call graph for this function:


Member Data Documentation

Definition at line 104 of file nsStyleCoord.h.

Definition at line 105 of file nsStyleCoord.h.


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