Back to index

lightning-sunbird  0.9+nobinonly
Functions
nsStyleStruct.cpp File Reference
#include "nsStyleStruct.h"
#include "nsStyleConsts.h"
#include "nsString.h"
#include "nsUnitConversion.h"
#include "nsPresContext.h"
#include "nsIDeviceContext.h"
#include "nsIStyleRule.h"
#include "nsCRT.h"
#include "nsCOMPtr.h"
#include "nsIPresShell.h"
#include "nsIFrame.h"
#include "nsLayoutAtoms.h"
#include "nsHTMLReflowState.h"
#include "prenv.h"
#include "nsBidiUtils.h"
#include "imgIRequest.h"

Go to the source code of this file.

Functions

PRBool IsFixedUnit (nsStyleUnit aUnit, PRBool aEnumOK)
nscoord CalcSideFor (const nsIFrame *aFrame, const nsStyleCoord &aCoord, PRUint8 aSpacing, PRUint8 aSide)
void CalcSidesFor (const nsIFrame *aFrame, const nsStyleSides &aSides, PRUint8 aSpacing, nsMargin &aResult)
static PRBool EqualURIs (nsIURI *aURI1, nsIURI *aURI2)
static PRBool EqualImages (imgIRequest *aImage1, imgIRequest *aImage2)
static PRBool IsFixedData (const nsStyleSides &aSides, PRBool aEnumOK)
static nscoord CalcCoord (const nsStyleCoord &aCoord, const nscoord *aEnumTable, PRInt32 aNumEnums)

Function Documentation

static nscoord CalcCoord ( const nsStyleCoord aCoord,
const nscoord aEnumTable,
PRInt32  aNumEnums 
) [static]

Definition at line 266 of file nsStyleStruct.cpp.

{
  switch (aCoord.GetUnit()) {
    case eStyleUnit_Null:
      return 0;
    case eStyleUnit_Coord:
      return aCoord.GetCoordValue();
    case eStyleUnit_Enumerated:
      if (nsnull != aEnumTable) {
        PRInt32 value = aCoord.GetIntValue();
        if ((0 <= value) && (value < aNumEnums)) {
          return aEnumTable[aCoord.GetIntValue()];
        }
      }
      break;
    case eStyleUnit_Chars:
      // XXX we need a frame and a rendering context to calculate this, bug 281972, bug 282126.
      NS_NOTYETIMPLEMENTED("CalcCoord: eStyleUnit_Chars");
      return 0;
    default:
      NS_ERROR("bad unit type");
      break;
  }
  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nscoord CalcSideFor ( const nsIFrame aFrame,
const nsStyleCoord aCoord,
PRUint8  aSpacing,
PRUint8  aSide 
) [inline]

Definition at line 69 of file nsStyleStruct.cpp.

{
  nscoord result = 0;

  switch (aCoord.GetUnit()) {
    case eStyleUnit_Auto:
      // Auto margins are handled by layout
      break;

    case eStyleUnit_Percent:
      {
        nscoord baseWidth = 0;
        nsIFrame* frame = aFrame ?
            nsHTMLReflowState::GetContainingBlockFor(aFrame) : nsnull;
        if (frame) {
          baseWidth = frame->GetSize().width;
          // subtract border of containing block
          nsMargin border;
          frame->GetStyleBorder()->CalcBorderFor(frame, border);
          baseWidth -= (border.left + border.right);
          // if aFrame is not absolutely positioned, subtract
          // padding of containing block
          const nsStyleDisplay* displayData = aFrame->GetStyleDisplay();
          if (displayData->mPosition != NS_STYLE_POSITION_ABSOLUTE &&
              displayData->mPosition != NS_STYLE_POSITION_FIXED) {
            nsMargin padding;
            frame->GetStylePadding()->CalcPaddingFor(frame, padding);
            baseWidth -= (padding.left + padding.right);
          }
        }
        result = (nscoord)((float)baseWidth * aCoord.GetPercentValue());
      }
      break;

    case eStyleUnit_Coord:
      result = aCoord.GetCoordValue();
      break;

    case eStyleUnit_Enumerated:
    case eStyleUnit_Null:
    case eStyleUnit_Normal:
    case eStyleUnit_Integer:
    case eStyleUnit_Proportional:
    default:
      result = 0;
      break;
  }
  if ((NS_SPACING_PADDING == aSpacing) || (NS_SPACING_BORDER == aSpacing)) {
    if (result < 0) {
      result = 0;
    }
  }
  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void CalcSidesFor ( const nsIFrame aFrame,
const nsStyleSides aSides,
PRUint8  aSpacing,
nsMargin aResult 
) [inline]

Definition at line 126 of file nsStyleStruct.cpp.

{
  nsStyleCoord  coord;

  aResult.left = CalcSideFor(aFrame, aSides.GetLeft(coord), aSpacing,
                             NS_SIDE_LEFT);
  aResult.top = CalcSideFor(aFrame, aSides.GetTop(coord), aSpacing,
                            NS_SIDE_TOP);
  aResult.right = CalcSideFor(aFrame, aSides.GetRight(coord), aSpacing,
                              NS_SIDE_RIGHT);
  aResult.bottom = CalcSideFor(aFrame, aSides.GetBottom(coord), aSpacing,
                               NS_SIDE_BOTTOM);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PRBool EqualImages ( imgIRequest aImage1,
imgIRequest aImage2 
) [static]

Definition at line 150 of file nsStyleStruct.cpp.

{
  if (aImage1 == aImage2) {
    return PR_TRUE;
  }

  if (!aImage1 || !aImage2) {
    return PR_FALSE;
  }

  nsCOMPtr<nsIURI> uri1, uri2;
  aImage1->GetURI(getter_AddRefs(uri1));
  aImage2->GetURI(getter_AddRefs(uri2));
  return EqualURIs(uri1, uri2);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PRBool EqualURIs ( nsIURI aURI1,
nsIURI aURI2 
) [static]

Definition at line 141 of file nsStyleStruct.cpp.

{
  PRBool eq;
  return aURI1 == aURI2 ||    // handle null==null, and optimize
         (aURI1 && aURI2 &&
          NS_SUCCEEDED(aURI1->Equals(aURI2, &eq)) && // not equal on fail
          eq);
}

Here is the caller graph for this function:

static PRBool IsFixedData ( const nsStyleSides aSides,
PRBool  aEnumOK 
) [static]

Definition at line 257 of file nsStyleStruct.cpp.

{
  NS_FOR_CSS_SIDES(side) {
    if (!IsFixedUnit(aSides.GetUnit(side), aEnumOK))
      return PR_FALSE;
  }
  return PR_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool IsFixedUnit ( nsStyleUnit  aUnit,
PRBool  aEnumOK 
) [inline]

Definition at line 60 of file nsStyleStruct.cpp.

{
  return PRBool((aUnit == eStyleUnit_Null) || 
                (aUnit == eStyleUnit_Coord) || 
                (aEnumOK && (aUnit == eStyleUnit_Enumerated)));
}

Here is the caller graph for this function: