Relanding bug 461410 - nsILineIterator is never used outside of layout - set nsresults to replicate the existing code more correctly, which fixes the mochitest failures, r+sr=roc with nits noted by Mats Palmgren

This commit is contained in:
Benjamin Smedberg 2008-10-30 12:17:59 -07:00
parent e33aefb9b8
commit ae14b3d6aa
13 changed files with 219 additions and 235 deletions

View File

@ -1685,7 +1685,7 @@ PRInt32 nsHyperTextAccessible::GetCaretLineNumber()
NS_ENSURE_TRUE(caretFrame, -1);
PRInt32 lineNumber = 1;
nsCOMPtr<nsILineIterator> lineIterForCaret;
nsAutoLineIterator lineIterForCaret;
nsCOMPtr<nsIContent> hyperTextContent = do_QueryInterface(mDOMNode);
while (caretFrame) {
if (hyperTextContent == caretFrame->GetContent()) {
@ -1698,11 +1698,10 @@ PRInt32 nsHyperTextAccessible::GetCaretLineNumber()
// Add lines for the sibling frames before the caret
nsIFrame *sibling = parentFrame->GetFirstChild(nsnull);
while (sibling && sibling != caretFrame) {
nsCOMPtr<nsILineIterator> lineIterForSibling = do_QueryInterface(sibling);
nsAutoLineIterator lineIterForSibling = sibling->GetLineIterator();
if (lineIterForSibling) {
PRInt32 addLines;
// For the frames before that grab all the lines
lineIterForSibling->GetNumLines(&addLines);
PRInt32 addLines = lineIterForSibling->GetNumLines();
lineNumber += addLines;
}
sibling = sibling->GetNextSibling();
@ -1710,11 +1709,10 @@ PRInt32 nsHyperTextAccessible::GetCaretLineNumber()
// Get the line number relative to the container with lines
if (!lineIterForCaret) { // Add the caret line just once
lineIterForCaret = do_QueryInterface(parentFrame);
lineIterForCaret = parentFrame->GetLineIterator();
if (lineIterForCaret) {
// Ancestor of caret
PRInt32 addLines;
lineIterForCaret->FindLineContaining(caretFrame, &addLines);
PRInt32 addLines = lineIterForCaret->FindLineContaining(caretFrame);
lineNumber += addLines;
}
}

View File

@ -3801,11 +3801,9 @@ UnionRectForClosestScrolledView(nsIFrame* aFrame,
f &&
frameType == nsGkAtoms::blockFrame) {
// find the line containing aFrame and increase the top of |offset|.
nsCOMPtr<nsILineIterator> lines(do_QueryInterface(f));
nsAutoLineIterator lines = f->GetLineIterator();
if (lines) {
PRInt32 index = -1;
lines->FindLineContaining(prevFrame, &index);
PRInt32 index = lines->FindLineContaining(prevFrame);
if (index >= 0) {
nsIFrame *trash1;
PRInt32 trash2;

View File

@ -315,6 +315,22 @@ nsBlockFrame::Destroy()
nsBlockFrameSuper::Destroy();
}
/* virtual */ nsILineIterator*
nsBlockFrame::GetLineIterator()
{
nsLineIterator* it = new nsLineIterator;
if (!it)
return nsnull;
const nsStyleVisibility* visibility = GetStyleVisibility();
nsresult rv = it->Init(mLines, visibility->mDirection == NS_STYLE_DIRECTION_RTL);
if (NS_FAILED(rv)) {
delete it;
return nsnull;
}
return it;
}
NS_IMETHODIMP
nsBlockFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr)
{
@ -324,26 +340,6 @@ nsBlockFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr)
*aInstancePtr = static_cast<void*>(static_cast<nsBlockFrame*>(this));
return NS_OK;
}
if (aIID.Equals(NS_GET_IID(nsILineIterator)) ||
aIID.Equals(NS_GET_IID(nsILineIteratorNavigator))) {
nsLineIterator* it = new nsLineIterator;
if (!it) {
*aInstancePtr = nsnull;
return NS_ERROR_OUT_OF_MEMORY;
}
NS_ADDREF(it); // reference passed to caller
const nsStyleVisibility* visibility = GetStyleVisibility();
nsresult rv = it->Init(mLines,
visibility->mDirection == NS_STYLE_DIRECTION_RTL);
if (NS_FAILED(rv)) {
*aInstancePtr = nsnull;
NS_RELEASE(it);
return rv;
}
*aInstancePtr = static_cast<nsILineIteratorNavigator*>(it);
return NS_OK;
}
return nsBlockFrameSuper::QueryInterface(aIID, aInstancePtr);
}

View File

@ -74,7 +74,6 @@ class nsBlockInFlowLineIterator;
class nsBulletFrame;
class nsLineBox;
class nsFirstLineFrame;
class nsILineIterator;
class nsIntervalSet;
/**
* Child list name indices
@ -598,6 +597,8 @@ protected:
//----------------------------------------
virtual nsILineIterator* GetLineIterator();
public:
nsLineList* GetOverflowLines() const;
protected:

View File

@ -4544,14 +4544,11 @@ nsFrame::GetNextPrevLineFromeBlockFrame(nsPresContext* aPresContext,
aPos->mResultContent = nsnull;
aPos->mAttachForward = (aPos->mDirection == eDirNext);
nsresult result;
nsCOMPtr<nsILineIteratorNavigator> it;
result = aBlockFrame->QueryInterface(NS_GET_IID(nsILineIteratorNavigator),getter_AddRefs(it));
if (NS_FAILED(result) || !it)
return result;
nsAutoLineIterator it = aBlockFrame->GetLineIterator();
if (!it)
return NS_ERROR_FAILURE;
PRInt32 searchingLine = aLineStart;
PRInt32 countLines;
result = it->GetNumLines(&countLines);
PRInt32 countLines = it->GetNumLines();
if (aOutSideLimit > 0) //start at end
searchingLine = countLines;
else if (aOutSideLimit <0)//start at beginning
@ -4571,6 +4568,8 @@ nsFrame::GetNextPrevLineFromeBlockFrame(nsPresContext* aPresContext,
nsRect rect;
PRBool isBeforeFirstFrame, isAfterLastFrame;
PRBool found = PR_FALSE;
nsresult result = NS_OK;
while (!found)
{
if (aPos->mDirection == eDirPrevious)
@ -4619,15 +4618,15 @@ nsFrame::GetNextPrevLineFromeBlockFrame(nsPresContext* aPresContext,
if (NS_SUCCEEDED(result) && resultFrame)
{
nsCOMPtr<nsILineIteratorNavigator> newIt;
//check to see if this is ANOTHER blockframe inside the other one if so then call into its lines
result = resultFrame->QueryInterface(NS_GET_IID(nsILineIteratorNavigator),getter_AddRefs(newIt));
if (NS_SUCCEEDED(result) && newIt)
nsAutoLineIterator newIt = resultFrame->GetLineIterator();
if (newIt)
{
aPos->mResultFrame = resultFrame;
return NS_OK;
}
//resultFrame is not a block frame
result = NS_ERROR_FAILURE;
nsCOMPtr<nsIFrameEnumerator> frameTraversal;
result = NS_NewFrameTraversal(getter_AddRefs(frameTraversal),
@ -5065,15 +5064,16 @@ nsIFrame::PeekOffset(nsPeekOffsetStruct* aPos)
}
case eSelectLine :
{
nsCOMPtr<nsILineIteratorNavigator> iter;
nsAutoLineIterator iter;
nsIFrame *blockFrame = this;
while (NS_FAILED(result)){
PRInt32 thisLine = nsFrame::GetLineNumber(blockFrame, aPos->mScrollViewStop, &blockFrame);
if (thisLine < 0)
return NS_ERROR_FAILURE;
result = blockFrame->QueryInterface(NS_GET_IID(nsILineIteratorNavigator),getter_AddRefs(iter));
NS_ASSERTION(NS_SUCCEEDED(result) && iter, "GetLineNumber() succeeded but no block frame?");
iter = blockFrame->GetLineIterator();
NS_ASSERTION(iter, "GetLineNumber() succeeded but no block frame?");
result = NS_OK;
int edgeCase = 0;//no edge case. this should look at thisLine
@ -5117,20 +5117,23 @@ nsIFrame::PeekOffset(nsPeekOffsetStruct* aPos)
//got the table frame now
while(frame) //ok time to drill down to find iterator
{
result = frame->QueryInterface(NS_GET_IID(nsILineIteratorNavigator),
getter_AddRefs(iter));
if (NS_SUCCEEDED(result))
iter = frame->GetLineIterator();
if (iter)
{
aPos->mResultFrame = frame;
searchTableBool = PR_TRUE;
result = NS_OK;
break; //while(frame)
}
result = NS_ERROR_FAILURE;
frame = frame->GetFirstChild(nsnull);
}
}
if (!searchTableBool)
result = aPos->mResultFrame->QueryInterface(NS_GET_IID(nsILineIteratorNavigator),
getter_AddRefs(iter));
if (!searchTableBool) {
iter = aPos->mResultFrame->GetLineIterator();
result = iter ? NS_OK : NS_ERROR_FAILURE;
}
if (NS_SUCCEEDED(result) && iter)//we've struck another block element!
{
doneLooping = PR_FALSE;
@ -5160,14 +5163,13 @@ nsIFrame::PeekOffset(nsPeekOffsetStruct* aPos)
case eSelectBeginLine:
case eSelectEndLine:
{
nsCOMPtr<nsILineIteratorNavigator> it;
// Adjusted so that the caret can't get confused when content changes
nsIFrame* blockFrame = AdjustFrameForSelectionStyles(this);
PRInt32 thisLine = nsFrame::GetLineNumber(blockFrame, aPos->mScrollViewStop, &blockFrame);
if (thisLine < 0)
return NS_ERROR_FAILURE;
result = blockFrame->QueryInterface(NS_GET_IID(nsILineIteratorNavigator),getter_AddRefs(it));
NS_ASSERTION(NS_SUCCEEDED(result) && it, "GetLineNumber() succeeded but no block frame?");
nsAutoLineIterator it = blockFrame->GetLineIterator();
NS_ASSERTION(it, "GetLineNumber() succeeded but no block frame?");
PRInt32 lineFrameCount;
nsIFrame *firstFrame;
@ -5178,8 +5180,7 @@ nsIFrame::PeekOffset(nsPeekOffsetStruct* aPos)
#ifdef IBMBIDI
if (aPos->mVisual && PresContext()->BidiEnabled()) {
PRBool lineIsRTL;
it->GetDirection(&lineIsRTL);
PRBool lineIsRTL = it->GetDirection();
PRBool isReordered;
nsIFrame *lastFrame;
result = it->CheckLineOrder(thisLine, &isReordered, &firstFrame, &lastFrame);
@ -5335,7 +5336,7 @@ nsFrame::GetLineNumber(nsIFrame *aFrame, PRBool aLockScroll, nsIFrame** aContain
nsIFrame *blockFrame = aFrame;
nsIFrame *thisBlock;
PRInt32 thisLine;
nsCOMPtr<nsILineIteratorNavigator> it;
nsAutoLineIterator it;
nsresult result = NS_ERROR_FAILURE;
while (NS_FAILED(result) && blockFrame)
{
@ -5356,7 +5357,9 @@ nsFrame::GetLineNumber(nsIFrame *aFrame, PRBool aLockScroll, nsIFrame** aContain
if (blockFrame) {
if (aLockScroll && blockFrame->GetType() == nsGkAtoms::scrollFrame)
return -1;
result = blockFrame->QueryInterface(NS_GET_IID(nsILineIteratorNavigator),getter_AddRefs(it));
it = blockFrame->GetLineIterator();
if (!it)
result = NS_ERROR_FAILURE;
}
}
if (!blockFrame || !it)
@ -5364,17 +5367,16 @@ nsFrame::GetLineNumber(nsIFrame *aFrame, PRBool aLockScroll, nsIFrame** aContain
if (aContainingBlock)
*aContainingBlock = blockFrame;
result = it->FindLineContaining(thisBlock, &thisLine);
if (NS_FAILED(result))
return -1;
return thisLine;
return it->FindLineContaining(thisBlock);
}
nsresult
nsIFrame::GetFrameFromDirection(nsDirection aDirection, PRBool aVisual,
PRBool aJumpLines, PRBool aScrollViewStop,
nsIFrame** aOutFrame, PRInt32* aOutOffset, PRBool* aOutJumpedLine)
{
{
nsresult result;
if (!aOutFrame || !aOutOffset || !aOutJumpedLine)
return NS_ERROR_NULL_POINTER;
@ -5388,21 +5390,20 @@ nsIFrame::GetFrameFromDirection(nsDirection aDirection, PRBool aVisual,
nsIFrame *traversedFrame = this;
while (!selectable) {
nsIFrame *blockFrame;
nsCOMPtr<nsILineIteratorNavigator> it;
PRInt32 thisLine = nsFrame::GetLineNumber(traversedFrame, aScrollViewStop, &blockFrame);
if (thisLine < 0)
return NS_ERROR_FAILURE;
nsresult result = blockFrame->QueryInterface(NS_GET_IID(nsILineIteratorNavigator),getter_AddRefs(it));
NS_ASSERTION(NS_SUCCEEDED(result) && it, "GetLineNumber() succeeded but no block frame?");
nsAutoLineIterator it = blockFrame->GetLineIterator();
NS_ASSERTION(it, "GetLineNumber() succeeded but no block frame?");
PRBool atLineEdge;
nsIFrame *firstFrame;
nsIFrame *lastFrame;
#ifdef IBMBIDI
if (aVisual && presContext->BidiEnabled()) {
PRBool lineIsRTL;
it->GetDirection(&lineIsRTL);
PRBool lineIsRTL = it->GetDirection();
PRBool isReordered;
result = it->CheckLineOrder(thisLine, &isReordered, &firstFrame, &lastFrame);
nsIFrame** framePtr = aDirection == eDirPrevious ? &firstFrame : &lastFrame;
@ -6190,7 +6191,7 @@ nsFrame::RefreshSizeCache(nsBoxLayoutState& aState)
metrics->mBlockMinSize.height = 0;
// ok we need the max ascent of the items on the line. So to do this
// ask the block for its line iterator. Get the max ascent.
nsCOMPtr<nsILineIterator> lines = do_QueryInterface(static_cast<nsIFrame*>(this));
nsAutoLineIterator lines = GetLineIterator();
if (lines)
{
metrics->mBlockMinSize.height = 0;
@ -6233,6 +6234,12 @@ nsFrame::RefreshSizeCache(nsBoxLayoutState& aState)
return rv;
}
/* virtual */ nsILineIterator*
nsFrame::GetLineIterator()
{
return nsnull;
}
nsSize
nsFrame::GetPrefSize(nsBoxLayoutState& aState)
{

View File

@ -621,6 +621,8 @@ private:
NS_IMETHODIMP RefreshSizeCache(nsBoxLayoutState& aState);
virtual nsILineIterator* GetLineIterator();
protected:
NS_IMETHOD_(nsrefcnt) AddRef(void);
NS_IMETHOD_(nsrefcnt) Release(void);

View File

@ -427,8 +427,6 @@ nsFrameList::List(FILE* out) const
nsIFrame*
nsFrameList::GetPrevVisualFor(nsIFrame* aFrame) const
{
nsCOMPtr<nsILineIterator> iter;
if (!mFirstChild)
return nsnull;
@ -439,8 +437,8 @@ nsFrameList::GetPrevVisualFor(nsIFrame* aFrame) const
nsBidiLevel baseLevel = nsBidiPresUtils::GetFrameBaseLevel(mFirstChild);
nsBidiPresUtils* bidiUtils = mFirstChild->PresContext()->GetBidiUtils();
nsresult result = parent->QueryInterface(NS_GET_IID(nsILineIterator), getter_AddRefs(iter));
if (NS_FAILED(result) || !iter) {
nsAutoLineIterator iter = parent->GetLineIterator();
if (!iter) {
// Parent is not a block Frame
if (parent->GetType() == nsGkAtoms::lineFrame) {
// Line frames are not bidi-splittable, so need to consider bidi reordering
@ -465,11 +463,11 @@ nsFrameList::GetPrevVisualFor(nsIFrame* aFrame) const
PRInt32 thisLine;
if (aFrame) {
result = iter->FindLineContaining(aFrame, &thisLine);
if (NS_FAILED(result) || thisLine < 0)
thisLine = iter->FindLineContaining(aFrame);
if (thisLine < 0)
return nsnull;
} else {
iter->GetNumLines(&thisLine);
thisLine = iter->GetNumLines();
}
nsIFrame* frame = nsnull;
@ -504,8 +502,6 @@ nsFrameList::GetPrevVisualFor(nsIFrame* aFrame) const
nsIFrame*
nsFrameList::GetNextVisualFor(nsIFrame* aFrame) const
{
nsCOMPtr<nsILineIterator> iter;
if (!mFirstChild)
return nsnull;
@ -516,8 +512,8 @@ nsFrameList::GetNextVisualFor(nsIFrame* aFrame) const
nsBidiLevel baseLevel = nsBidiPresUtils::GetFrameBaseLevel(mFirstChild);
nsBidiPresUtils* bidiUtils = mFirstChild->PresContext()->GetBidiUtils();
nsresult result = parent->QueryInterface(NS_GET_IID(nsILineIterator), getter_AddRefs(iter));
if (NS_FAILED(result) || !iter) {
nsAutoLineIterator iter = parent->GetLineIterator();
if (!iter) {
// Parent is not a block Frame
if (parent->GetType() == nsGkAtoms::lineFrame) {
// Line frames are not bidi-splittable, so need to consider bidi reordering
@ -542,8 +538,8 @@ nsFrameList::GetNextVisualFor(nsIFrame* aFrame) const
PRInt32 thisLine;
if (aFrame) {
result = iter->FindLineContaining(aFrame, &thisLine);
if (NS_FAILED(result) || thisLine < 0)
thisLine = iter->FindLineContaining(aFrame);
if (thisLine < 0)
return nsnull;
} else {
thisLine = -1;
@ -565,8 +561,7 @@ nsFrameList::GetNextVisualFor(nsIFrame* aFrame) const
}
}
PRInt32 numLines;
iter->GetNumLines(&numLines);
PRInt32 numLines = iter->GetNumLines();
if (!frame && thisLine < numLines - 1) {
// Get the first frame of the next line
iter->GetLine(thisLine + 1, &firstFrameOnLine, &numFramesOnLine, lineBounds, &lineFlags);

View File

@ -85,6 +85,7 @@ class nsIDOMRange;
class nsISelectionController;
class nsBoxLayoutState;
class nsIBoxLayout;
class nsILineIterator;
#ifdef ACCESSIBILITY
class nsIAccessible;
#endif
@ -2224,6 +2225,14 @@ NS_PTR_TO_INT32(frame->GetProperty(nsGkAtoms::embeddingLevel))
const nsRect& aOldOverflowRect,
const nsSize& aNewDesiredSize);
/**
* Get a line iterator for this frame, if supported.
*
* @return nsnull if no line iterator is supported.
* @note dispose the line iterator using nsILineIterator::DisposeLineIterator
*/
virtual nsILineIterator* GetLineIterator() = 0;
protected:
// Members
nsRect mRect;

View File

@ -37,26 +37,11 @@
#ifndef nsILineIterator_h___
#define nsILineIterator_h___
#include "nsISupports.h"
#include "nscore.h"
#include "nsCoord.h"
/* a6cf90ff-15b3-11d2-932e-00805f8add32 */
#define NS_ILINE_ITERATOR_IID \
{ 0xa6cf90ff, 0x15b3, 0x11d2,{0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32}}
/* {80AA3D7A-E0BF-4e18-8A82-2110397D7BC4}*/
#define NS_ILINE_ITERATOR_NAV_IID \
{ 0x80aa3d7a, 0xe0bf, 0x4e18,{0x8a, 0x82, 0x21, 0x10, 0x39, 0x7d, 0x7b, 0xc4}}
// Line iterator API.
//
// Lines are numbered from 0 to N, where 0 is the top line and N is
// the bottom line.
//
// NOTE: while you can get this interface by doing a slezy hacky
// QueryInterface on block frames, it isn't like a normal com
// interface: it's not reflexive (you can't query back to the block
// frame) and unlike other frames, it *IS* reference counted so don't
// forget to NS_RELEASE it when you are done with it!
class nsIFrame;
struct nsRect;
// Line Flags (see GetLine below)
@ -67,17 +52,36 @@
// This bit is set when the line ends in some sort of break.
#define NS_LINE_FLAG_ENDS_IN_BREAK 0x4
class nsILineIterator : public nsISupports {
/**
* Line iterator API.
*
* Lines are numbered from 0 to N, where 0 is the top line and N is
* the bottom line.
*
* Obtain this interface from frames via nsIFrame::GetLineIterator.
* When you are finished using the iterator, call DisposeLineIterator()
* to destroy the iterator if appropriate.
*/
class nsILineIterator
{
protected:
~nsILineIterator() { }
public:
NS_DECLARE_STATIC_IID_ACCESSOR(NS_ILINE_ITERATOR_IID)
virtual void DisposeLineIterator() = 0;
// Return the number of lines in the block.
NS_IMETHOD GetNumLines(PRInt32* aResult) = 0;
/**
* The number of lines in the block
*/
virtual PRInt32 GetNumLines() = 0;
// Return the prevailing direction for the line. aIsRightToLeft will
// be set to PR_TRUE if the CSS direction property for the block is
// "rtl", otherwise aIsRightToLeft will be set to PR_FALSE.
NS_IMETHOD GetDirection(PRBool* aIsRightToLeft) = 0;
/**
* The prevailing direction of lines.
*
* @return PR_TRUE if the CSS direction property for the block is
* "rtl", otherwise PR_FALSE
*/
virtual PRBool GetDirection() = 0;
// Return structural information about a line. aFirstFrameOnLine is
// the first frame on the line and aNumFramesOnLine is the number of
@ -98,19 +102,20 @@ public:
nsRect& aLineBounds,
PRUint32* aLineFlags) = 0;
// Given a frame that's a child of the block, find which line its on
// and return that line index into aIndexResult. aIndexResult will
// be set to -1 if the frame cannot be found.
NS_IMETHOD FindLineContaining(nsIFrame* aFrame,
PRInt32* aLineNumberResult) = 0;
/**
* Given a frame that's a child of the block, find which line its on
* and return that line index. Returns -1 if the frame cannot be found.
*/
virtual PRInt32 FindLineContaining(nsIFrame* aFrame) = 0;
// Given a Y coordinate relative to the block that provided this
// line iterator, find the line that contains the Y
// coordinate. Returns -1 in aLineNumberResult if the Y coordinate
// is above the first line. Returns N (where N is the number of
// lines) if the Y coordinate is below the last line.
NS_IMETHOD FindLineAt(nscoord aY,
PRInt32* aLineNumberResult) = 0;
/**
* Given a Y coordinate relative to the block that provided this
* line iterator, return the line that contains the Y
* coordinate. Returns -1 in aLineNumberResult if the Y coordinate
* is above the first line. Returns N (where N is the number of
* lines) if the Y coordinate is below the last line.
*/
virtual PRInt32 FindLineAt(nscoord aY) = 0;
// Given a line number and an X coordinate, find the frame on the
// line that is nearest to the X coordinate. The
@ -136,15 +141,33 @@ public:
#endif
};
NS_DEFINE_STATIC_IID_ACCESSOR(nsILineIterator, NS_ILINE_ITERATOR_IID)
//special line iterator for keyboard navigation
class nsILineIteratorNavigator : public nsILineIterator {
class nsAutoLineIterator
{
public:
NS_DECLARE_STATIC_IID_ACCESSOR(NS_ILINE_ITERATOR_NAV_IID)
nsAutoLineIterator() : mRawPtr(nsnull) { }
nsAutoLineIterator(nsILineIterator *i) : mRawPtr(i) { }
~nsAutoLineIterator() {
if (mRawPtr)
mRawPtr->DisposeLineIterator();
}
operator nsILineIterator*() { return mRawPtr; }
nsILineIterator* operator->() { return mRawPtr; }
nsILineIterator* operator=(nsILineIterator* i) {
if (i == mRawPtr)
return i;
if (mRawPtr)
mRawPtr->DisposeLineIterator();
mRawPtr = i;
return i;
}
private:
nsILineIterator* mRawPtr;
};
NS_DEFINE_STATIC_IID_ACCESSOR(nsILineIteratorNavigator,
NS_ILINE_ITERATOR_NAV_IID)
#endif /* nsILineIterator_h___ */

View File

@ -543,7 +543,11 @@ nsLineIterator::~nsLineIterator()
}
}
NS_IMPL_ISUPPORTS2(nsLineIterator, nsILineIterator, nsILineIteratorNavigator)
/* virtual */ void
nsLineIterator::DisposeLineIterator()
{
delete this;
}
nsresult
nsLineIterator::Init(nsLineList& aLines, PRBool aRightToLeft)
@ -578,26 +582,16 @@ nsLineIterator::Init(nsLineList& aLines, PRBool aRightToLeft)
return NS_OK;
}
NS_IMETHODIMP
nsLineIterator::GetNumLines(PRInt32* aResult)
PRInt32
nsLineIterator::GetNumLines()
{
NS_PRECONDITION(aResult, "null OUT ptr");
if (!aResult) {
return NS_ERROR_NULL_POINTER;
}
*aResult = mNumLines;
return NS_OK;
return mNumLines;
}
NS_IMETHODIMP
nsLineIterator::GetDirection(PRBool* aIsRightToLeft)
PRBool
nsLineIterator::GetDirection()
{
NS_PRECONDITION(aIsRightToLeft, "null OUT ptr");
if (!aIsRightToLeft) {
return NS_ERROR_NULL_POINTER;
}
*aIsRightToLeft = mRightToLeft;
return NS_OK;
return mRightToLeft;
}
NS_IMETHODIMP
@ -635,42 +629,35 @@ nsLineIterator::GetLine(PRInt32 aLineNumber,
return NS_OK;
}
NS_IMETHODIMP
nsLineIterator::FindLineContaining(nsIFrame* aFrame,
PRInt32* aLineNumberResult)
PRInt32
nsLineIterator::FindLineContaining(nsIFrame* aFrame)
{
nsLineBox* line = mLines[0];
PRInt32 lineNumber = 0;
while (lineNumber != mNumLines) {
if (line->Contains(aFrame)) {
*aLineNumberResult = lineNumber;
return NS_OK;
return lineNumber;
}
line = mLines[++lineNumber];
}
*aLineNumberResult = -1;
return NS_OK;
return -1;
}
NS_IMETHODIMP
nsLineIterator::FindLineAt(nscoord aY,
PRInt32* aLineNumberResult)
/* virtual */ PRInt32
nsLineIterator::FindLineAt(nscoord aY)
{
nsLineBox* line = mLines[0];
if (!line || (aY < line->mBounds.y)) {
*aLineNumberResult = -1;
return NS_OK;
return -1;
}
PRInt32 lineNumber = 0;
while (lineNumber != mNumLines) {
if ((aY >= line->mBounds.y) && (aY < line->mBounds.YMost())) {
*aLineNumberResult = lineNumber;
return NS_OK;
return lineNumber;
}
line = mLines[++lineNumber];
}
*aLineNumberResult = mNumLines;
return NS_OK;
return mNumLines;
}
#ifdef IBMBIDI

View File

@ -1508,24 +1508,23 @@ nsLineList_const_reverse_iterator::operator=(const nsLineList_const_reverse_iter
//----------------------------------------------------------------------
class nsLineIterator : public nsILineIteratorNavigator {
class NS_FINAL_CLASS nsLineIterator : public nsILineIterator
{
public:
nsLineIterator();
virtual ~nsLineIterator();
~nsLineIterator();
NS_DECL_ISUPPORTS
virtual void DisposeLineIterator();
NS_IMETHOD GetNumLines(PRInt32* aResult);
NS_IMETHOD GetDirection(PRBool* aIsRightToLeft);
virtual PRInt32 GetNumLines();
virtual PRBool GetDirection();
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);
virtual PRInt32 FindLineContaining(nsIFrame* aFrame);
virtual PRInt32 FindLineAt(nscoord aY);
NS_IMETHOD FindFrameAt(PRInt32 aLineNumber,
nscoord aX,
nsIFrame** aFrameFound,
@ -1541,15 +1540,7 @@ public:
#endif
nsresult Init(nsLineList& aLines, PRBool aRightToLeft);
protected:
PRInt32 NumLines() const {
return mNumLines;
}
nsLineBox* CurrentLine() {
return mLines[mIndex];
}
private:
nsLineBox* PrevLine() {
if (0 == mIndex) {
return nsnull;

View File

@ -64,17 +64,6 @@ nsTableRowGroupFrame::~nsTableRowGroupFrame()
{
}
/* ----------- nsTableRowGroupFrame ---------- */
nsrefcnt nsTableRowGroupFrame::AddRef(void)
{
return 1;//implementation of nsLineIterator
}
nsrefcnt nsTableRowGroupFrame::Release(void)
{
return 1;//implementation of nsLineIterator
}
NS_IMETHODIMP
nsTableRowGroupFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr)
{
@ -85,14 +74,6 @@ nsTableRowGroupFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr)
*aInstancePtr = (void*)this;
return NS_OK;
}
if (aIID.Equals(NS_GET_IID(nsILineIteratorNavigator))) {
*aInstancePtr = static_cast<nsILineIteratorNavigator*>(this);
return NS_OK;
}
if (aIID.Equals(NS_GET_IID(nsILineIterator))) {
*aInstancePtr = static_cast<nsILineIterator*>(this);
return NS_OK;
}
return nsHTMLContainerFrame::QueryInterface(aIID, aInstancePtr);
}
@ -1653,23 +1634,18 @@ void nsTableRowGroupFrame::SetContinuousBCBorderWidth(PRUint8 aForSide,
}
//nsILineIterator methods
NS_IMETHODIMP
nsTableRowGroupFrame::GetNumLines(PRInt32* aResult)
PRInt32
nsTableRowGroupFrame::GetNumLines()
{
NS_ENSURE_ARG_POINTER(aResult);
*aResult = GetRowCount();
return NS_OK;
return GetRowCount();
}
NS_IMETHODIMP
nsTableRowGroupFrame::GetDirection(PRBool* aIsRightToLeft)
PRBool
nsTableRowGroupFrame::GetDirection()
{
NS_ENSURE_ARG_POINTER(aIsRightToLeft);
// rtl is table wide @see nsTableIterator
nsTableFrame* table = nsTableFrame::GetTableFrame(this);
*aIsRightToLeft = (NS_STYLE_DIRECTION_RTL ==
table->GetStyleVisibility()->mDirection);
return NS_OK;
return (NS_STYLE_DIRECTION_RTL ==
table->GetStyleVisibility()->mDirection);
}
NS_IMETHODIMP
@ -1714,28 +1690,25 @@ nsTableRowGroupFrame::GetLine(PRInt32 aLineNumber,
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsTableRowGroupFrame::FindLineContaining(nsIFrame* aFrame,
PRInt32* aLineNumberResult)
PRInt32
nsTableRowGroupFrame::FindLineContaining(nsIFrame* aFrame)
{
NS_ENSURE_ARG_POINTER(aFrame);
NS_ENSURE_ARG_POINTER(aLineNumberResult);
NS_ASSERTION((aFrame->GetType() == nsGkAtoms::tableRowFrame),
"RowGroup contains a frame that is not a row");
nsTableRowFrame* rowFrame = (nsTableRowFrame*)aFrame;
*aLineNumberResult = rowFrame->GetRowIndex() - GetStartRowIndex();
return NS_OK;
return rowFrame->GetRowIndex() - GetStartRowIndex();
}
NS_IMETHODIMP
nsTableRowGroupFrame::FindLineAt(nscoord aY,
PRInt32* aLineNumberResult)
PRInt32
nsTableRowGroupFrame::FindLineAt(nscoord aY)
{
NS_NOTREACHED("Not implemented");
return NS_ERROR_NOT_IMPLEMENTED;
}
#ifdef IBMBIDI
NS_IMETHODIMP
nsTableRowGroupFrame::CheckLineOrder(PRInt32 aLine,

View File

@ -96,11 +96,12 @@ struct nsRowGroupReflowState {
* @see nsTableFrame
* @see nsTableRowFrame
*/
class nsTableRowGroupFrame : public nsHTMLContainerFrame, public nsILineIteratorNavigator
class nsTableRowGroupFrame
: public nsHTMLContainerFrame
, public nsILineIterator
{
public:
// nsISupports
NS_DECL_ISUPPORTS_INHERITED
NS_IMETHOD QueryInterface(const nsIID &aIID, void **aInstancePtr);
/** instantiate a new instance of nsTableRowFrame.
* @param aPresShell the pres shell for this frame
@ -227,6 +228,8 @@ public:
// nsILineIterator methods
public:
virtual void DisposeLineIterator() { }
// The table row is the equivalent to a line in block layout.
// The nsILineIterator assumes that a line resides in a block, this role is
// fullfilled by the row group. Rows in table are counted relative to the
@ -235,14 +238,14 @@ public:
// row index of the first row in the row group.
/** Get the number of rows in a row group
* @param aResult - pointer that holds the number of lines in a row group
* @return the number of lines in a row group
*/
NS_IMETHOD GetNumLines(PRInt32* aResult);
virtual PRInt32 GetNumLines();
/** @see nsILineIterator.h GetDirection
* @param aIsRightToLeft - true if the table is rtl
* @return true if the table is rtl
*/
NS_IMETHOD GetDirection(PRBool* aIsRightToLeft);
virtual PRBool GetDirection();
/** Return structural information about a line.
* @param aLineNumber - the index of the row relative to the row group
@ -264,16 +267,15 @@ public:
/** Given a frame that's a child of the rowgroup, find which line its on.
* @param aFrame - frame, should be a row
* @param aIndexResult - row index relative to the row group if this a row
* frame. aIndexResult will be set to -1 if the frame
* cannot be found.
* @return row index relative to the row group if this a row
* frame. -1 if the frame cannot be found.
*/
NS_IMETHOD FindLineContaining(nsIFrame* aFrame, PRInt32* aLineNumberResult);
virtual PRInt32 FindLineContaining(nsIFrame* aFrame);
/** not implemented
* the function is also not called in our tree
*/
NS_IMETHOD FindLineAt(nscoord aY, PRInt32* aLineNumberResult);
virtual PRInt32 FindLineAt(nscoord aY);
/** Find the orginating cell frame on a row that is the nearest to the
* coordinate X.
@ -373,6 +375,8 @@ public:
GetStyleDisplay()->mOverflowY == NS_STYLE_OVERFLOW_CLIP;
}
virtual nsILineIterator* GetLineIterator() { return this; }
protected:
nsTableRowGroupFrame(nsStyleContext* aContext);