Back to index

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

#include <nsLineBox.h>

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

List of all members.

Public Member Functions

 nsLineIterator ()
virtual ~nsLineIterator ()
NS_DECL_ISUPPORTS NS_IMETHOD GetNumLines (PRInt32 *aResult)
NS_IMETHOD GetDirection (PRBool *aIsRightToLeft)
NS_IMETHOD GetLine (PRInt32 aLineNumber, nsIFrame **aFirstFrameOnLine, PRInt32 *aNumFramesOnLine, nsRect &aLineBounds, PRUint32 *aLineFlags)
NS_IMETHOD FindLineContaining (nsIFrame *aFrame, PRInt32 *aLineNumberResult)
NS_IMETHOD FindLineAt (nscoord aY, PRInt32 *aLineNumberResult)
NS_IMETHOD FindFrameAt (PRInt32 aLineNumber, nscoord aX, nsIFrame **aFrameFound, PRBool *aXIsBeforeFirstFrame, PRBool *aXIsAfterLastFrame)
NS_IMETHOD GetNextSiblingOnLine (nsIFrame *&aFrame, PRInt32 aLineNumber)
nsresult Init (nsLineList &aLines, PRBool aRightToLeft)

Protected Member Functions

PRInt32 NumLines () const
nsLineBoxCurrentLine ()
nsLineBoxPrevLine ()
nsLineBoxNextLine ()
nsLineBoxLineAt (PRInt32 aIndex)

Protected Attributes

nsLineBox ** mLines
PRInt32 mIndex
PRInt32 mNumLines
PRPackedBool mRightToLeft

Detailed Description

Definition at line 1473 of file nsLineBox.h.


Constructor & Destructor Documentation

Definition at line 515 of file nsLineBox.cpp.

Definition at line 523 of file nsLineBox.cpp.

{
  if (mLines != gDummyLines) {
    delete [] mLines;
  }
}

Member Function Documentation

nsLineBox* nsLineIterator::CurrentLine ( ) [inline, protected]

Definition at line 1511 of file nsLineBox.h.

                           {
    return mLines[mIndex];
  }
NS_IMETHODIMP nsLineIterator::FindFrameAt ( PRInt32  aLineNumber,
nscoord  aX,
nsIFrame **  aFrameFound,
PRBool aXIsBeforeFirstFrame,
PRBool aXIsAfterLastFrame 
) [virtual]

Implements nsILineIterator.

Definition at line 763 of file nsLineBox.cpp.

{
  NS_PRECONDITION(aFrameFound && aXIsBeforeFirstFrame && aXIsAfterLastFrame,
                  "null OUT ptr");
  if (!aFrameFound || !aXIsBeforeFirstFrame || !aXIsAfterLastFrame) {
    return NS_ERROR_NULL_POINTER;
  }
  if ((aLineNumber < 0) || (aLineNumber >= mNumLines)) {
    return NS_ERROR_INVALID_ARG;
  }

  nsLineBox* line = mLines[aLineNumber];
  if (!line) {
    *aFrameFound = nsnull;
    *aXIsBeforeFirstFrame = PR_TRUE;
    *aXIsAfterLastFrame = PR_FALSE;
    return NS_OK;
  }

  if (line->mBounds.width == 0 && line->mBounds.height == 0)
    return NS_ERROR_FAILURE;

  nsIFrame* frame = line->mFirstChild;
  nsIFrame* closestFromLeft = nsnull;
  nsIFrame* closestFromRight = nsnull;
  PRInt32 n = line->GetChildCount();
  while (n--) {
    nsRect rect = frame->GetRect();
    if (rect.width > 0) {
      // If aX is inside this frame - this is it
      if (rect.x <= aX && rect.XMost() > aX) {
        closestFromLeft = closestFromRight = frame;
        break;
      }
      if (rect.x < aX) {
        if (!closestFromLeft || 
            rect.XMost() > closestFromLeft->GetRect().XMost())
          closestFromLeft = frame;
      }
      else {
        if (!closestFromRight ||
            rect.x < closestFromRight->GetRect().x)
          closestFromRight = frame;
      }
    }
    frame = frame->GetNextSibling();
  }
  if (!closestFromLeft && !closestFromRight) {
    // All frames were zero-width. Just take the first one.
    closestFromLeft = closestFromRight = line->mFirstChild;
  }
  *aXIsBeforeFirstFrame = mRightToLeft ? !closestFromRight : !closestFromLeft;
  *aXIsAfterLastFrame = mRightToLeft ? !closestFromLeft : !closestFromRight;
  if (closestFromLeft == closestFromRight) {
    *aFrameFound = closestFromLeft;
  }
  else if (!closestFromLeft) {
    *aFrameFound = closestFromRight;
  }
  else if (!closestFromRight) {
    *aFrameFound = closestFromLeft;
  }
  else { // we're between two frames
    nscoord delta = closestFromRight->GetRect().x - closestFromLeft->GetRect().XMost();
    if (aX < closestFromLeft->GetRect().XMost() + delta/2)
      *aFrameFound = closestFromLeft;
    else
      *aFrameFound = closestFromRight;
  }
  return NS_OK;
}

Here is the call graph for this function:

NS_IMETHODIMP nsLineIterator::FindLineAt ( nscoord  aY,
PRInt32 aLineNumberResult 
) [virtual]

Implements nsILineIterator.

Definition at line 640 of file nsLineBox.cpp.

{
  nsLineBox* line = mLines[0];
  if (!line || (aY < line->mBounds.y)) {
    *aLineNumberResult = -1;
    return NS_OK;
  }
  PRInt32 lineNumber = 0;
  while (lineNumber != mNumLines) {
    if ((aY >= line->mBounds.y) && (aY < line->mBounds.YMost())) {
      *aLineNumberResult = lineNumber;
      return NS_OK;
    }
    line = mLines[++lineNumber];
  }
  *aLineNumberResult = mNumLines;
  return NS_OK;
}
NS_IMETHODIMP nsLineIterator::FindLineContaining ( nsIFrame aFrame,
PRInt32 aLineNumberResult 
) [virtual]

Implements nsILineIterator.

Definition at line 623 of file nsLineBox.cpp.

{
  nsLineBox* line = mLines[0];
  PRInt32 lineNumber = 0;
  while (lineNumber != mNumLines) {
    if (line->Contains(aFrame)) {
      *aLineNumberResult = lineNumber;
      return NS_OK;
    }
    line = mLines[++lineNumber];
  }
  *aLineNumberResult = -1;
  return NS_OK;
}

Here is the call graph for this function:

NS_IMETHODIMP nsLineIterator::GetDirection ( PRBool aIsRightToLeft) [virtual]

Implements nsILineIterator.

Definition at line 577 of file nsLineBox.cpp.

{
  NS_PRECONDITION(aIsRightToLeft, "null OUT ptr");
  if (!aIsRightToLeft) {
    return NS_ERROR_NULL_POINTER;
  }
  *aIsRightToLeft = mRightToLeft;
  return NS_OK;
}
NS_IMETHODIMP nsLineIterator::GetLine ( PRInt32  aLineNumber,
nsIFrame **  aFirstFrameOnLine,
PRInt32 aNumFramesOnLine,
nsRect aLineBounds,
PRUint32 aLineFlags 
) [virtual]

Implements nsILineIterator.

Definition at line 588 of file nsLineBox.cpp.

{
  NS_ENSURE_ARG_POINTER(aFirstFrameOnLine);
  NS_ENSURE_ARG_POINTER(aNumFramesOnLine);
  NS_ENSURE_ARG_POINTER(aLineFlags);

  if ((aLineNumber < 0) || (aLineNumber >= mNumLines)) {
    *aFirstFrameOnLine = nsnull;
    *aNumFramesOnLine = 0;
    aLineBounds.SetRect(0, 0, 0, 0);
    return NS_OK;
  }
  nsLineBox* line = mLines[aLineNumber];
  *aFirstFrameOnLine = line->mFirstChild;
  *aNumFramesOnLine = line->GetChildCount();
  aLineBounds = line->mBounds;

  PRUint32 flags = 0;
  if (line->IsBlock()) {
    flags |= NS_LINE_FLAG_IS_BLOCK;
  }
  else {
    if (line->HasBreakAfter())
      flags |= NS_LINE_FLAG_ENDS_IN_BREAK;
  }
  *aLineFlags = flags;

  return NS_OK;
}

Here is the call graph for this function:

NS_IMETHODIMP nsLineIterator::GetNextSiblingOnLine ( nsIFrame *&  aFrame,
PRInt32  aLineNumber 
) [virtual]

Implements nsILineIterator.

Definition at line 840 of file nsLineBox.cpp.

{
  aFrame = aFrame->GetNextSibling();
  return NS_OK;
}

Here is the call graph for this function:

Implements nsILineIterator.

Definition at line 566 of file nsLineBox.cpp.

{
  NS_PRECONDITION(aResult, "null OUT ptr");
  if (!aResult) {
    return NS_ERROR_NULL_POINTER;
  }
  *aResult = mNumLines;
  return NS_OK;
}
nsresult nsLineIterator::Init ( nsLineList aLines,
PRBool  aRightToLeft 
)

Definition at line 533 of file nsLineBox.cpp.

{
  mRightToLeft = aRightToLeft;

  // Count the lines
  PRInt32 numLines = aLines.size();
  if (0 == numLines) {
    // Use gDummyLines so that we don't need null pointer checks in
    // the accessor methods
    mLines = gDummyLines;
    return NS_OK;
  }

  // Make a linear array of the lines
  mLines = new nsLineBox*[numLines];
  if (!mLines) {
    // Use gDummyLines so that we don't need null pointer checks in
    // the accessor methods
    mLines = gDummyLines;
    return NS_ERROR_OUT_OF_MEMORY;
  }
  nsLineBox** lp = mLines;
  for (nsLineList::iterator line = aLines.begin(), line_end = aLines.end() ;
       line != line_end;
       ++line)
  {
    *lp++ = line;
  }
  mNumLines = numLines;
  return NS_OK;
}

Here is the caller graph for this function:

nsLineBox* nsLineIterator::LineAt ( PRInt32  aIndex) [inline, protected]

Definition at line 1529 of file nsLineBox.h.

                                    {
    if ((aIndex < 0) || (aIndex >= mNumLines)) {
      return nsnull;
    }
    return mLines[aIndex];
  }
nsLineBox* nsLineIterator::NextLine ( ) [inline, protected]

Definition at line 1522 of file nsLineBox.h.

                        {
    if (mIndex >= mNumLines - 1) {
      return nsnull;
    }
    return mLines[++mIndex];
  }
PRInt32 nsLineIterator::NumLines ( ) const [inline, protected]

Definition at line 1507 of file nsLineBox.h.

                           {
    return mNumLines;
  }
nsLineBox* nsLineIterator::PrevLine ( ) [inline, protected]

Definition at line 1515 of file nsLineBox.h.

                        {
    if (0 == mIndex) {
      return nsnull;
    }
    return mLines[--mIndex];
  }

Member Data Documentation

Definition at line 1537 of file nsLineBox.h.

Definition at line 1536 of file nsLineBox.h.

Definition at line 1538 of file nsLineBox.h.

Definition at line 1539 of file nsLineBox.h.


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