зеркало из https://github.com/mozilla/gecko-dev.git
Tweaked FindLineContaining to return the index in the line where the frame is found
This commit is contained in:
Родитель
2970e96968
Коммит
187be6b63f
|
@ -130,96 +130,20 @@ nsLineBox::IsLastChild(nsIFrame* aFrame) const
|
|||
return aFrame == lastFrame;
|
||||
}
|
||||
|
||||
PRBool
|
||||
nsLineBox::Contains(nsIFrame* aFrame) const
|
||||
PRInt32
|
||||
nsLineBox::IndexOf(nsIFrame* aFrame) const
|
||||
{
|
||||
PRInt32 n = ChildCount();
|
||||
PRInt32 i, n = ChildCount();
|
||||
nsIFrame* frame = mFirstChild;
|
||||
while (--n >= 0) {
|
||||
for (i = 0; i < n; i++) {
|
||||
if (frame == aFrame) {
|
||||
return PR_TRUE;
|
||||
return i;
|
||||
}
|
||||
frame->GetNextSibling(&frame);
|
||||
}
|
||||
return PR_FALSE;
|
||||
return -1;
|
||||
}
|
||||
|
||||
#if 0
|
||||
static PRInt32
|
||||
LengthOf(nsIFrame* aFrame)
|
||||
{
|
||||
PRInt32 result = 0;
|
||||
while (nsnull != aFrame) {
|
||||
result++;
|
||||
aFrame->GetNextSibling(aFrame);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void
|
||||
nsLineBox::Verify()
|
||||
{
|
||||
nsIFrame* lastFrame = LastChild();
|
||||
if (nsnull != lastFrame) {
|
||||
nsIFrame* nextInFlow;
|
||||
lastFrame->GetNextInFlow(nextInFlow);
|
||||
if (nsnull != mNext) {
|
||||
nsIFrame* nextSibling;
|
||||
lastFrame->GetNextSibling(nextSibling);
|
||||
NS_ASSERTION(mNext->mFirstChild == nextSibling, "bad line list");
|
||||
}
|
||||
}
|
||||
PRInt32 len = LengthOf(mFirstChild);
|
||||
NS_ASSERTION(len >= ChildCount(), "bad mChildCount");
|
||||
}
|
||||
|
||||
static void
|
||||
VerifyLines(nsLineBox* aLine)
|
||||
{
|
||||
while (nsnull != aLine) {
|
||||
aLine->Verify();
|
||||
aLine = aLine->mNext;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
VerifyChildCount(nsLineBox* aLines, PRBool aEmptyOK = PR_FALSE)
|
||||
{
|
||||
if (nsnull != aLines) {
|
||||
PRInt32 childCount = LengthOf(aLines->mFirstChild);
|
||||
PRInt32 sum = 0;
|
||||
nsLineBox* line = aLines;
|
||||
while (nsnull != line) {
|
||||
if (!aEmptyOK) {
|
||||
NS_ASSERTION(0 != line->ChildCount(), "empty line left in line list");
|
||||
}
|
||||
sum += line->ChildCount();
|
||||
line = line->mNext;
|
||||
}
|
||||
if (sum != childCount) {
|
||||
printf("Bad sibling list/line mChildCount's\n");
|
||||
nsLineBox* line = aLines;
|
||||
while (nsnull != line) {
|
||||
line->List(stdout, 1);
|
||||
if (nsnull != line->mNext) {
|
||||
nsIFrame* lastFrame = line->LastChild();
|
||||
if (nsnull != lastFrame) {
|
||||
nsIFrame* nextSibling;
|
||||
lastFrame->GetNextSibling(nextSibling);
|
||||
if (line->mNext->mFirstChild != nextSibling) {
|
||||
printf(" [list broken: nextSibling=%p mNext->mFirstChild=%p]\n",
|
||||
nextSibling, line->mNext->mFirstChild);
|
||||
}
|
||||
}
|
||||
}
|
||||
line = line->mNext;
|
||||
}
|
||||
NS_ASSERTION(sum == childCount, "bad sibling list/line mChildCount's");
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void
|
||||
nsLineBox::DeleteLineList(nsIPresContext& aPresContext, nsLineBox* aLine)
|
||||
{
|
||||
|
@ -254,14 +178,19 @@ nsLineBox::LastLine(nsLineBox* aLine)
|
|||
}
|
||||
|
||||
nsLineBox*
|
||||
nsLineBox::FindLineContaining(nsLineBox* aLine, nsIFrame* aFrame)
|
||||
nsLineBox::FindLineContaining(nsLineBox* aLine, nsIFrame* aFrame,
|
||||
PRInt32* aFrameIndexInLine)
|
||||
{
|
||||
NS_PRECONDITION(aFrameIndexInLine && aLine && aFrame, "null ptr");
|
||||
while (nsnull != aLine) {
|
||||
if (aLine->Contains(aFrame)) {
|
||||
PRInt32 ix = aLine->IndexOf(aFrame);
|
||||
if (ix >= 0) {
|
||||
*aFrameIndexInLine = ix;
|
||||
return aLine;
|
||||
}
|
||||
aLine = aLine->mNext;
|
||||
}
|
||||
*aFrameIndexInLine = -1;
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
|
|
|
@ -49,10 +49,6 @@ public:
|
|||
|
||||
nscoord GetHeight() const { return mBounds.height; }
|
||||
|
||||
#ifdef NS_DEBUG
|
||||
PRBool CheckIsBlock() const;
|
||||
#endif
|
||||
|
||||
PRBool IsEmptyLine() const {
|
||||
return 0 != (mState & LINE_ISA_EMPTY_LINE);
|
||||
}
|
||||
|
@ -74,7 +70,8 @@ public:
|
|||
|
||||
static nsLineBox* LastLine(nsLineBox* aLine);
|
||||
|
||||
static nsLineBox* FindLineContaining(nsLineBox* aLine, nsIFrame* aFrame);
|
||||
static nsLineBox* FindLineContaining(nsLineBox* aLine, nsIFrame* aFrame,
|
||||
PRInt32* aFrameIndexInLine);
|
||||
|
||||
void List(FILE* out, PRInt32 aIndent) const;
|
||||
|
||||
|
@ -162,13 +159,16 @@ public:
|
|||
|
||||
char* StateToString(char* aBuf, PRInt32 aBufSize) const;
|
||||
|
||||
PRBool Contains(nsIFrame* aFrame) const;
|
||||
PRInt32 IndexOf(nsIFrame* aFrame) const;
|
||||
|
||||
PRBool Contains(nsIFrame* aFrame) const {
|
||||
return IndexOf(aFrame) >= 0;
|
||||
}
|
||||
|
||||
#ifdef NS_DEBUG
|
||||
void Verify();
|
||||
PRBool CheckIsBlock() const;
|
||||
#endif
|
||||
|
||||
//XXX protected:
|
||||
nsIFrame* mFirstChild;
|
||||
PRUint16 mChildCount;
|
||||
PRUint16 mState;
|
||||
|
@ -178,8 +178,6 @@ public:
|
|||
nscoord mCarriedOutBottomMargin;/* XXX switch to 16 bits */
|
||||
nsVoidArray* mFloaters;
|
||||
nsLineBox* mNext;
|
||||
|
||||
protected:
|
||||
};
|
||||
|
||||
#endif /* nsLineBox_h___ */
|
||||
|
|
|
@ -130,96 +130,20 @@ nsLineBox::IsLastChild(nsIFrame* aFrame) const
|
|||
return aFrame == lastFrame;
|
||||
}
|
||||
|
||||
PRBool
|
||||
nsLineBox::Contains(nsIFrame* aFrame) const
|
||||
PRInt32
|
||||
nsLineBox::IndexOf(nsIFrame* aFrame) const
|
||||
{
|
||||
PRInt32 n = ChildCount();
|
||||
PRInt32 i, n = ChildCount();
|
||||
nsIFrame* frame = mFirstChild;
|
||||
while (--n >= 0) {
|
||||
for (i = 0; i < n; i++) {
|
||||
if (frame == aFrame) {
|
||||
return PR_TRUE;
|
||||
return i;
|
||||
}
|
||||
frame->GetNextSibling(&frame);
|
||||
}
|
||||
return PR_FALSE;
|
||||
return -1;
|
||||
}
|
||||
|
||||
#if 0
|
||||
static PRInt32
|
||||
LengthOf(nsIFrame* aFrame)
|
||||
{
|
||||
PRInt32 result = 0;
|
||||
while (nsnull != aFrame) {
|
||||
result++;
|
||||
aFrame->GetNextSibling(aFrame);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void
|
||||
nsLineBox::Verify()
|
||||
{
|
||||
nsIFrame* lastFrame = LastChild();
|
||||
if (nsnull != lastFrame) {
|
||||
nsIFrame* nextInFlow;
|
||||
lastFrame->GetNextInFlow(nextInFlow);
|
||||
if (nsnull != mNext) {
|
||||
nsIFrame* nextSibling;
|
||||
lastFrame->GetNextSibling(nextSibling);
|
||||
NS_ASSERTION(mNext->mFirstChild == nextSibling, "bad line list");
|
||||
}
|
||||
}
|
||||
PRInt32 len = LengthOf(mFirstChild);
|
||||
NS_ASSERTION(len >= ChildCount(), "bad mChildCount");
|
||||
}
|
||||
|
||||
static void
|
||||
VerifyLines(nsLineBox* aLine)
|
||||
{
|
||||
while (nsnull != aLine) {
|
||||
aLine->Verify();
|
||||
aLine = aLine->mNext;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
VerifyChildCount(nsLineBox* aLines, PRBool aEmptyOK = PR_FALSE)
|
||||
{
|
||||
if (nsnull != aLines) {
|
||||
PRInt32 childCount = LengthOf(aLines->mFirstChild);
|
||||
PRInt32 sum = 0;
|
||||
nsLineBox* line = aLines;
|
||||
while (nsnull != line) {
|
||||
if (!aEmptyOK) {
|
||||
NS_ASSERTION(0 != line->ChildCount(), "empty line left in line list");
|
||||
}
|
||||
sum += line->ChildCount();
|
||||
line = line->mNext;
|
||||
}
|
||||
if (sum != childCount) {
|
||||
printf("Bad sibling list/line mChildCount's\n");
|
||||
nsLineBox* line = aLines;
|
||||
while (nsnull != line) {
|
||||
line->List(stdout, 1);
|
||||
if (nsnull != line->mNext) {
|
||||
nsIFrame* lastFrame = line->LastChild();
|
||||
if (nsnull != lastFrame) {
|
||||
nsIFrame* nextSibling;
|
||||
lastFrame->GetNextSibling(nextSibling);
|
||||
if (line->mNext->mFirstChild != nextSibling) {
|
||||
printf(" [list broken: nextSibling=%p mNext->mFirstChild=%p]\n",
|
||||
nextSibling, line->mNext->mFirstChild);
|
||||
}
|
||||
}
|
||||
}
|
||||
line = line->mNext;
|
||||
}
|
||||
NS_ASSERTION(sum == childCount, "bad sibling list/line mChildCount's");
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void
|
||||
nsLineBox::DeleteLineList(nsIPresContext& aPresContext, nsLineBox* aLine)
|
||||
{
|
||||
|
@ -254,14 +178,19 @@ nsLineBox::LastLine(nsLineBox* aLine)
|
|||
}
|
||||
|
||||
nsLineBox*
|
||||
nsLineBox::FindLineContaining(nsLineBox* aLine, nsIFrame* aFrame)
|
||||
nsLineBox::FindLineContaining(nsLineBox* aLine, nsIFrame* aFrame,
|
||||
PRInt32* aFrameIndexInLine)
|
||||
{
|
||||
NS_PRECONDITION(aFrameIndexInLine && aLine && aFrame, "null ptr");
|
||||
while (nsnull != aLine) {
|
||||
if (aLine->Contains(aFrame)) {
|
||||
PRInt32 ix = aLine->IndexOf(aFrame);
|
||||
if (ix >= 0) {
|
||||
*aFrameIndexInLine = ix;
|
||||
return aLine;
|
||||
}
|
||||
aLine = aLine->mNext;
|
||||
}
|
||||
*aFrameIndexInLine = -1;
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
|
|
|
@ -49,10 +49,6 @@ public:
|
|||
|
||||
nscoord GetHeight() const { return mBounds.height; }
|
||||
|
||||
#ifdef NS_DEBUG
|
||||
PRBool CheckIsBlock() const;
|
||||
#endif
|
||||
|
||||
PRBool IsEmptyLine() const {
|
||||
return 0 != (mState & LINE_ISA_EMPTY_LINE);
|
||||
}
|
||||
|
@ -74,7 +70,8 @@ public:
|
|||
|
||||
static nsLineBox* LastLine(nsLineBox* aLine);
|
||||
|
||||
static nsLineBox* FindLineContaining(nsLineBox* aLine, nsIFrame* aFrame);
|
||||
static nsLineBox* FindLineContaining(nsLineBox* aLine, nsIFrame* aFrame,
|
||||
PRInt32* aFrameIndexInLine);
|
||||
|
||||
void List(FILE* out, PRInt32 aIndent) const;
|
||||
|
||||
|
@ -162,13 +159,16 @@ public:
|
|||
|
||||
char* StateToString(char* aBuf, PRInt32 aBufSize) const;
|
||||
|
||||
PRBool Contains(nsIFrame* aFrame) const;
|
||||
PRInt32 IndexOf(nsIFrame* aFrame) const;
|
||||
|
||||
PRBool Contains(nsIFrame* aFrame) const {
|
||||
return IndexOf(aFrame) >= 0;
|
||||
}
|
||||
|
||||
#ifdef NS_DEBUG
|
||||
void Verify();
|
||||
PRBool CheckIsBlock() const;
|
||||
#endif
|
||||
|
||||
//XXX protected:
|
||||
nsIFrame* mFirstChild;
|
||||
PRUint16 mChildCount;
|
||||
PRUint16 mState;
|
||||
|
@ -178,8 +178,6 @@ public:
|
|||
nscoord mCarriedOutBottomMargin;/* XXX switch to 16 bits */
|
||||
nsVoidArray* mFloaters;
|
||||
nsLineBox* mNext;
|
||||
|
||||
protected:
|
||||
};
|
||||
|
||||
#endif /* nsLineBox_h___ */
|
||||
|
|
Загрузка…
Ссылка в новой задаче