From af040c285ae43b31ad3a0ccc98ac230e5874c397 Mon Sep 17 00:00:00 2001 From: "kipp%netscape.com" Date: Sat, 10 Oct 1998 04:35:01 +0000 Subject: [PATCH] Added methods to support word breaking git-svn-id: svn://10.0.0.236/trunk@12508 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/layout/generic/nsLineLayout.cpp | 58 +++++++++++++++++++ mozilla/layout/generic/nsLineLayout.h | 36 ++++++++++-- mozilla/layout/html/base/src/nsLineLayout.cpp | 58 +++++++++++++++++++ mozilla/layout/html/base/src/nsLineLayout.h | 36 ++++++++++-- 4 files changed, 178 insertions(+), 10 deletions(-) diff --git a/mozilla/layout/generic/nsLineLayout.cpp b/mozilla/layout/generic/nsLineLayout.cpp index 92d48c15ed7..e4200d285ce 100644 --- a/mozilla/layout/generic/nsLineLayout.cpp +++ b/mozilla/layout/generic/nsLineLayout.cpp @@ -100,6 +100,64 @@ nsLineLayout::AddText(nsIFrame* aTextFrame) return NS_OK;/* XXX */ } +nsIFrame* +nsLineLayout::FindNextText(nsIFrame* aFrame) +{ + // Only the first-in-flows are present in the text run list so + // backup from the argument frame to its first-in-flow. + for (;;) { + nsIFrame* prevInFlow; + aFrame->GetPrevInFlow(prevInFlow); + if (nsnull == prevInFlow) { + break; + } + aFrame = prevInFlow; + } + + // Now look for the frame that follows aFrame's first-in-flow + nsTextRun* run = mReflowTextRuns; + while (nsnull != run) { + PRInt32 ix = run->mArray.IndexOf(aFrame); + if (ix >= 0) { + if (ix < run->mArray.Count() - 1) { + return (nsIFrame*) run->mArray[ix + 1]; + } + } + run = run->mNext; + } + return nsnull; +} + +PRBool +nsLineLayout::IsNextWordFrame(nsIFrame* aFrame) +{ + if (0 != mWordFrames.Count()) { + nsIFrame* next = (nsIFrame*) mWordFrames[0]; + return next == aFrame; + } + return PR_FALSE; +} + +PRBool +nsLineLayout::IsLastWordFrame(nsIFrame* aFrame) +{ + PRInt32 n = mWordFrames.Count(); + if (0 != n) { + nsIFrame* next = (nsIFrame*) mWordFrames[0]; + return (next == aFrame) && (1 == n); + } + return PR_FALSE; +} + +void +nsLineLayout::ForgetWordFrame(nsIFrame* aFrame) +{ + NS_ASSERTION((void*)aFrame == mWordFrames[0], "forget-word-frame"); + if (0 != mWordFrames.Count()) { + mWordFrames.RemoveElementAt(0); + } +} + // XXX move this somewhere else!!! PRBool nsLineLayout::TreatFrameAsBlock(const nsStyleDisplay* aDisplay, diff --git a/mozilla/layout/generic/nsLineLayout.h b/mozilla/layout/generic/nsLineLayout.h index 124379b5b45..856c720d136 100644 --- a/mozilla/layout/generic/nsLineLayout.h +++ b/mozilla/layout/generic/nsLineLayout.h @@ -75,6 +75,7 @@ public: #ifdef NS_DEBUG mPlacedFrames.Clear(); #endif + ForgetWordFrames(); } // Add to the placed-frame count @@ -116,8 +117,6 @@ public: void UpdateInlines(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight, PRBool aPlacedLeftFloater); - // -------------------------------------------------- - // Reset the text-run information in preparation for a FindTextRuns void ResetTextRuns(); @@ -133,6 +132,30 @@ public: // FindTextRuns. The internal text-run state is reset. nsTextRun* TakeTextRuns(); + void SetReflowTextRuns(nsTextRun* aTextRuns) { + mReflowTextRuns = aTextRuns; + } + + nsIFrame* FindNextText(nsIFrame* aFrame); + + void RecordWordFrame(nsIFrame* aWordFrame) { + mWordFrames.AppendElement(aWordFrame); + } + + void ForgetWordFrames() { + mWordFrames.Clear(); + } + + PRBool IsNextWordFrame(nsIFrame* aFrame); + + PRBool InNonBreakingUnit() { + return 0 != mWordFrames.Count(); + } + + PRBool IsLastWordFrame(nsIFrame* aFrame); + + void ForgetWordFrame(nsIFrame* aFrame); + PRInt32 GetColumn() { return mColumn; } @@ -145,18 +168,19 @@ public: mLineNumber++; } - void AddFloater(nsPlaceholderFrame* aFrame); - static PRBool TreatFrameAsBlock(const nsStyleDisplay* aDisplay, const nsStylePosition* aPosition); + // -------------------------------------------------- + + void AddFloater(nsPlaceholderFrame* aFrame); + nsIPresContext& mPresContext; nsISpaceManager* mSpaceManager; nsBlockReflowState* mBlockReflowState; PRBool mListPositionOutside; PRInt32 mLineNumber; -// nscoord mLeftEdge; PRInt32 mColumn; //XXX temporary? @@ -176,6 +200,8 @@ protected: nsVoidArray mPlacedFrames; #endif + nsVoidArray mWordFrames; + nsVoidArray mInlineStack; // These slots are used during FindTextRuns diff --git a/mozilla/layout/html/base/src/nsLineLayout.cpp b/mozilla/layout/html/base/src/nsLineLayout.cpp index 92d48c15ed7..e4200d285ce 100644 --- a/mozilla/layout/html/base/src/nsLineLayout.cpp +++ b/mozilla/layout/html/base/src/nsLineLayout.cpp @@ -100,6 +100,64 @@ nsLineLayout::AddText(nsIFrame* aTextFrame) return NS_OK;/* XXX */ } +nsIFrame* +nsLineLayout::FindNextText(nsIFrame* aFrame) +{ + // Only the first-in-flows are present in the text run list so + // backup from the argument frame to its first-in-flow. + for (;;) { + nsIFrame* prevInFlow; + aFrame->GetPrevInFlow(prevInFlow); + if (nsnull == prevInFlow) { + break; + } + aFrame = prevInFlow; + } + + // Now look for the frame that follows aFrame's first-in-flow + nsTextRun* run = mReflowTextRuns; + while (nsnull != run) { + PRInt32 ix = run->mArray.IndexOf(aFrame); + if (ix >= 0) { + if (ix < run->mArray.Count() - 1) { + return (nsIFrame*) run->mArray[ix + 1]; + } + } + run = run->mNext; + } + return nsnull; +} + +PRBool +nsLineLayout::IsNextWordFrame(nsIFrame* aFrame) +{ + if (0 != mWordFrames.Count()) { + nsIFrame* next = (nsIFrame*) mWordFrames[0]; + return next == aFrame; + } + return PR_FALSE; +} + +PRBool +nsLineLayout::IsLastWordFrame(nsIFrame* aFrame) +{ + PRInt32 n = mWordFrames.Count(); + if (0 != n) { + nsIFrame* next = (nsIFrame*) mWordFrames[0]; + return (next == aFrame) && (1 == n); + } + return PR_FALSE; +} + +void +nsLineLayout::ForgetWordFrame(nsIFrame* aFrame) +{ + NS_ASSERTION((void*)aFrame == mWordFrames[0], "forget-word-frame"); + if (0 != mWordFrames.Count()) { + mWordFrames.RemoveElementAt(0); + } +} + // XXX move this somewhere else!!! PRBool nsLineLayout::TreatFrameAsBlock(const nsStyleDisplay* aDisplay, diff --git a/mozilla/layout/html/base/src/nsLineLayout.h b/mozilla/layout/html/base/src/nsLineLayout.h index 124379b5b45..856c720d136 100644 --- a/mozilla/layout/html/base/src/nsLineLayout.h +++ b/mozilla/layout/html/base/src/nsLineLayout.h @@ -75,6 +75,7 @@ public: #ifdef NS_DEBUG mPlacedFrames.Clear(); #endif + ForgetWordFrames(); } // Add to the placed-frame count @@ -116,8 +117,6 @@ public: void UpdateInlines(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight, PRBool aPlacedLeftFloater); - // -------------------------------------------------- - // Reset the text-run information in preparation for a FindTextRuns void ResetTextRuns(); @@ -133,6 +132,30 @@ public: // FindTextRuns. The internal text-run state is reset. nsTextRun* TakeTextRuns(); + void SetReflowTextRuns(nsTextRun* aTextRuns) { + mReflowTextRuns = aTextRuns; + } + + nsIFrame* FindNextText(nsIFrame* aFrame); + + void RecordWordFrame(nsIFrame* aWordFrame) { + mWordFrames.AppendElement(aWordFrame); + } + + void ForgetWordFrames() { + mWordFrames.Clear(); + } + + PRBool IsNextWordFrame(nsIFrame* aFrame); + + PRBool InNonBreakingUnit() { + return 0 != mWordFrames.Count(); + } + + PRBool IsLastWordFrame(nsIFrame* aFrame); + + void ForgetWordFrame(nsIFrame* aFrame); + PRInt32 GetColumn() { return mColumn; } @@ -145,18 +168,19 @@ public: mLineNumber++; } - void AddFloater(nsPlaceholderFrame* aFrame); - static PRBool TreatFrameAsBlock(const nsStyleDisplay* aDisplay, const nsStylePosition* aPosition); + // -------------------------------------------------- + + void AddFloater(nsPlaceholderFrame* aFrame); + nsIPresContext& mPresContext; nsISpaceManager* mSpaceManager; nsBlockReflowState* mBlockReflowState; PRBool mListPositionOutside; PRInt32 mLineNumber; -// nscoord mLeftEdge; PRInt32 mColumn; //XXX temporary? @@ -176,6 +200,8 @@ protected: nsVoidArray mPlacedFrames; #endif + nsVoidArray mWordFrames; + nsVoidArray mInlineStack; // These slots are used during FindTextRuns