Back to index

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

Class used to manage processing of the space-manager band data. More...

#include <nsBlockBandData.h>

Inheritance diagram for nsBlockBandData:
Inheritance graph
[legend]
Collaboration diagram for nsBlockBandData:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nsBlockBandData ()
 ~nsBlockBandData ()
nsresult Init (nsSpaceManager *aSpaceManager, const nsSize &aSpace)
nsresult GetAvailableSpace (nscoord aY, PRBool aRelaxHeightConstraint, nsRect &aResult)
PRInt32 GetTrapezoidCount () const
const nsBandTrapezoidGetTrapezoid (PRInt32 aIndex) const
PRInt32 GetFloatCount () const
PRInt32 GetLeftFloatCount () const
PRInt32 GetRightFloatCount () const

Public Attributes

PRInt32 mCount
PRInt32 mSize
nsBandTrapezoidmTrapezoids

Protected Member Functions

nsresult GetBandData (nscoord aY, PRBool aRelaxHeightConstraint)
 utility method to calculate the band data at aY.
void ComputeAvailSpaceRect ()
 Computes the bounding rect of the available space, i.e.

Protected Attributes

nsSpaceManagermSpaceManager
nscoord mSpaceManagerX
nscoord mSpaceManagerY
nsSize mSpace
nsBandTrapezoid mData [NS_BLOCK_BAND_DATA_TRAPS]
nsRect mAvailSpace
PRInt32 mLeftFloats
PRInt32 mRightFloats

Detailed Description

Class used to manage processing of the space-manager band data.

Provides HTML/CSS specific behavior to the raw data.

Definition at line 51 of file nsBlockBandData.h.


Constructor & Destructor Documentation

Definition at line 56 of file nsBlockBandData.cpp.

{
  if (mTrapezoids != mData) {
    delete [] mTrapezoids;
  }
}

Member Function Documentation

Computes the bounding rect of the available space, i.e.

space between any left and right floats. Uses the current trapezoid data, see nsISpaceManager::GetBandData(). Also updates member data "availSpace".

Definition at line 154 of file nsBlockBandData.cpp.

{
#ifdef REALLY_NOISY_COMPUTEAVAILSPACERECT
  printf("nsBlockBandData::ComputeAvailSpaceRect %p with count %d\n", this, mCount);
#endif
  if (0 == mCount) {
    mAvailSpace.x = 0;
    mAvailSpace.y = 0;
    mAvailSpace.width = 0;
    mAvailSpace.height = 0;
    mLeftFloats = 0;
    mRightFloats = 0;
    return;
  }

  nsBandTrapezoid* trapezoid = mTrapezoids;
  // The trapezoid to the left of the first right-floated trapezoid.
  nsBandTrapezoid* rightTrapezoid = nsnull;

  PRInt32 leftFloats = 0;
  PRInt32 rightFloats = 0;
  if (mCount > 1) {
    // If there's more than one trapezoid that means there are floats
    PRInt32 i;

    // Examine each trapezoid in the band, counting up the number of
    // left and right floats. Use the right-most float to
    // determine where the right edge of the available space is.
    NS_PRECONDITION(mCount<=mSize, "bad state, count > size");
    for (i = 0; i < mCount; i++) {
      trapezoid = &mTrapezoids[i];
      if (trapezoid->mState != nsBandTrapezoid::Available) {
#ifdef REALLY_NOISY_COMPUTEAVAILSPACERECT
        printf("band %p checking !Avail trap %p with frame %p\n", this, trapezoid, trapezoid->mFrame);
#endif
        if (nsBandTrapezoid::OccupiedMultiple == trapezoid->mState) {
          PRInt32 j, numFrames = trapezoid->mFrames->Count();
          NS_ASSERTION(numFrames > 0, "bad trapezoid frame list");
          for (j = 0; j < numFrames; j++) {
            nsIFrame* f = (nsIFrame*) trapezoid->mFrames->ElementAt(j);
            const nsStyleDisplay* display = f->GetStyleDisplay();
            if (NS_STYLE_FLOAT_LEFT == display->mFloats) {
              leftFloats++;
            }
            else if (NS_STYLE_FLOAT_RIGHT == display->mFloats) {
              rightFloats++;
              if ((nsnull == rightTrapezoid) && (i > 0)) {
                rightTrapezoid = &mTrapezoids[i - 1];
              }
            }
          }
        } else {
          const nsStyleDisplay* display = trapezoid->mFrame->GetStyleDisplay();
          if (NS_STYLE_FLOAT_LEFT == display->mFloats) {
            leftFloats++;
          }
          else if (NS_STYLE_FLOAT_RIGHT == display->mFloats) {
            rightFloats++;
            if ((nsnull == rightTrapezoid) && (i > 0)) {
              rightTrapezoid = &mTrapezoids[i - 1];
            }
          }
        }
      }
    }
  }
  else if (mTrapezoids[0].mState != nsBandTrapezoid::Available) {
    // We have a float using up all the available space
    leftFloats = 1;
  }
#ifdef REALLY_NOISY_COMPUTEAVAILSPACERECT
  printf("band %p has floats %d, %d\n", this, leftFloats, rightFloats);
#endif
  mLeftFloats = leftFloats;
  mRightFloats = rightFloats;

  // We look for available space in the last trapezoid before the
  // first right float, or in the last trapezoid if there is no right
  // float or no trapezoid before the first right float.
  if (nsnull != rightTrapezoid) {
    trapezoid = rightTrapezoid;
  }
  trapezoid->GetRect(mAvailSpace);

  // When there is no available space, we still need a proper X
  // coordinate to place objects that end up here anyway.
  if (nsBandTrapezoid::Available != trapezoid->mState) {
    if (nsBandTrapezoid::OccupiedMultiple == trapezoid->mState) {
      // It's not clear what coordinate to use when there is no
      // available space and the space is multiply occupied...So: If
      // any of the floats that are a part of the trapezoid are left
      // floats then we move over to the right edge of the
      // unavaliable space.
      PRInt32 j, numFrames = trapezoid->mFrames->Count();
      NS_ASSERTION(numFrames > 0, "bad trapezoid frame list");
      for (j = 0; j < numFrames; j++) {
        nsIFrame* f = (nsIFrame*) trapezoid->mFrames->ElementAt(j);
        const nsStyleDisplay* display = f->GetStyleDisplay();
        if (NS_STYLE_FLOAT_LEFT == display->mFloats) {
          mAvailSpace.x = mAvailSpace.XMost();
          break;
        }
      }
    }
    else {
      const nsStyleDisplay* display = trapezoid->mFrame->GetStyleDisplay();
      if (NS_STYLE_FLOAT_LEFT == display->mFloats) {
        mAvailSpace.x = mAvailSpace.XMost();
      }
    }
    mAvailSpace.width = 0;
  }

  // Fixup width
  if (NS_UNCONSTRAINEDSIZE == mSpace.width) {
    mAvailSpace.width = NS_UNCONSTRAINEDSIZE;
  }
#ifdef REALLY_NOISY_COMPUTEAVAILSPACERECT
  printf("  ComputeAvailSpaceRect settting state mAvailSpace (%d,%d,%d,%d)\n", 
         mAvailSpace.x, mAvailSpace.y, mAvailSpace.width, mAvailSpace.height);
#endif

}

Here is the caller graph for this function:

nsresult nsBlockBandData::GetAvailableSpace ( nscoord  aY,
PRBool  aRelaxHeightConstraint,
nsRect aResult 
)

Definition at line 82 of file nsBlockBandData.cpp.

{
  // Get the raw band data for the given Y coordinate
  nsresult rv = GetBandData(aY, aRelaxHeightConstraint);
  if (NS_FAILED(rv)) { return rv; }

  // Compute the bounding rect of the available space, i.e. space
  // between any left and right floats.
  ComputeAvailSpaceRect();
  aResult = mAvailSpace;
#ifdef REALLY_NOISY_COMPUTEAVAILSPACERECT
  printf("nsBBD %p GetAvailableSpace(%d) returing (%d, %d, %d, %d)\n",
          this, aY, aResult.x, aResult.y, aResult.width, aResult.height);
#endif
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsBlockBandData::GetBandData ( nscoord  aY,
PRBool  aRelaxHeightConstraint 
) [protected]

utility method to calculate the band data at aY.

nsBlockBandData methods should never call mSpaceManager->GetBandData directly. They should always call this method instead so data members mTrapezoid, mCount, and mSize all get managed properly.

Definition at line 108 of file nsBlockBandData.cpp.

{
  NS_ASSERTION(mSpaceManager, "bad state, no space manager");
  PRInt32 iterations =0;
  nsSize space = mSpace;
  if (aRelaxHeightConstraint) {
    space.height = NS_UNCONSTRAINEDSIZE;
  }
  nsresult rv = mSpaceManager->GetBandData(aY, space, *this);
  while (NS_FAILED(rv)) {
    iterations++;
    if (iterations>ERROR_TOO_MANY_ITERATIONS)
    {
      NS_ASSERTION(PR_FALSE, "too many iterations in nsBlockBandData::GetBandData");
      return NS_ERROR_FAILURE;
    }
    // We need more space for our bands
    NS_ASSERTION(mTrapezoids, "bad state, no mTrapezoids");
    if (mTrapezoids && (mTrapezoids != mData)) {
      delete [] mTrapezoids;
    }
    PRInt32 newSize = mSize * 2;
    if (newSize<mCount) {
      newSize = mCount;
    }
    mTrapezoids = new nsBandTrapezoid[newSize];
    NS_POSTCONDITION(mTrapezoids, "failure allocating mTrapezoids");
    if (!mTrapezoids) {
      return NS_ERROR_OUT_OF_MEMORY;
    }
    mSize = newSize;
    rv = mSpaceManager->GetBandData(aY, space, *this);
  }
  NS_POSTCONDITION(mCount<=mSize, "bad state, count > size");
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 77 of file nsBlockBandData.h.

                                {
    return mLeftFloats + mRightFloats;
  }

Here is the caller graph for this function:

Definition at line 80 of file nsBlockBandData.h.

                                    {
    return mLeftFloats;
  }

Here is the caller graph for this function:

Definition at line 83 of file nsBlockBandData.h.

                                     {
    return mRightFloats;
  }

Here is the caller graph for this function:

Definition at line 69 of file nsBlockBandData.h.

                                                            {
    return &mTrapezoids[aIndex];
  }

Here is the caller graph for this function:

Definition at line 65 of file nsBlockBandData.h.

                                    {
    return mCount;
  }

Here is the caller graph for this function:

nsresult nsBlockBandData::Init ( nsSpaceManager aSpaceManager,
const nsSize aSpace 
)

Definition at line 64 of file nsBlockBandData.cpp.

{
  NS_PRECONDITION(aSpaceManager, "null pointer");

  mSpaceManager = aSpaceManager;
  aSpaceManager->GetTranslation(mSpaceManagerX, mSpaceManagerY);

  mSpace = aSpace;
  mLeftFloats = 0;
  mRightFloats = 0;
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 112 of file nsBlockBandData.h.

Definition at line 154 of file nsSpaceManager.h.

Definition at line 109 of file nsBlockBandData.h.

Definition at line 118 of file nsBlockBandData.h.

Definition at line 118 of file nsBlockBandData.h.

Definition at line 155 of file nsSpaceManager.h.

Definition at line 106 of file nsBlockBandData.h.

Definition at line 102 of file nsBlockBandData.h.

Definition at line 103 of file nsBlockBandData.h.

Definition at line 103 of file nsBlockBandData.h.

Definition at line 156 of file nsSpaceManager.h.


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