diff --git a/mozilla/layout/generic/nsTextFrame.cpp b/mozilla/layout/generic/nsTextFrame.cpp index ee19e38335c..74cee7f5063 100644 --- a/mozilla/layout/generic/nsTextFrame.cpp +++ b/mozilla/layout/generic/nsTextFrame.cpp @@ -416,6 +416,7 @@ public: nscoord dx, nscoord dy); nscoord ComputeTotalWordWidth(nsIPresContext* aPresContext, + nsILineBreaker* aLineBreaker, nsLineLayout& aLineLayout, const nsHTMLReflowState& aReflowState, nsIFrame* aNextFrame, @@ -425,6 +426,7 @@ public: PRUint32 aWordBufSize); nscoord ComputeWordFragmentWidth(nsIPresContext* aPresContext, + nsILineBreaker* aLineBreaker, nsLineLayout& aLineLayout, const nsHTMLReflowState& aReflowState, nsIFrame* aNextFrame, @@ -622,7 +624,7 @@ nsTextFrame::PrepareUnicodeText(nsTextTransformer& aTX, // Setup transform to operate starting in the content at our content // offset - aTX.Init(this, mContentOffset); + aTX.Init(this, mContent, mContentOffset); PRInt32 strInx = mContentOffset; @@ -2107,7 +2109,7 @@ nsTextFrame::PeekOffset(nsPeekOffsetStruct *aPos) PRInt32 wordLen, contentLen; if (aPos->mDirection == eDirPrevious){ keepSearching = PR_TRUE; - tx.Init(this, aPos->mStartOffset); + tx.Init(this, mContent, aPos->mStartOffset); if (tx.GetPrevWord(PR_FALSE, wordLen, contentLen, isWhitespace, PR_FALSE)){ if ((aPos->mEatingWS && !isWhitespace) || !aPos->mEatingWS){ aPos->mContentOffset = aPos->mStartOffset - contentLen; @@ -2136,7 +2138,7 @@ nsTextFrame::PeekOffset(nsPeekOffsetStruct *aPos) start = -1; //start at end } else if (aPos->mDirection == eDirNext){ - tx.Init(this, aPos->mStartOffset ); + tx.Init(this, mContent, aPos->mStartOffset ); #ifdef DEBUGWORDJUMP printf("Next- Start=%d aPos->mEatingWS=%s\n", aPos->mStartOffset, aPos->mEatingWS ? "TRUE" : "FALSE"); @@ -2372,18 +2374,14 @@ nsTextFrame::Reflow(nsIPresContext& aPresContext, PRBool endsInWhitespace = PR_FALSE; PRBool endsInNewline = PR_FALSE; - nsCOMPtr shell; - aPresContext.GetShell(getter_AddRefs(shell)); nsCOMPtr doc; - shell->GetDocument(getter_AddRefs(doc)); + mContent->GetDocument(*getter_AddRefs(doc)); // Setup text transformer to transform this frames text content PRUnichar wordBuf[WORD_BUF_SIZE]; nsCOMPtr lb; doc->GetLineBreaker(getter_AddRefs(lb)); - //nsCOMPtr wb; - //doc->GetWordBreaker(getter_AddRefs(wb)); nsTextTransformer tx(wordBuf, WORD_BUF_SIZE,lb,nsnull); - nsresult rv = tx.Init(/**textRun, XXX*/ this, startingOffset); + nsresult rv = tx.Init(this, mContent, startingOffset); if (NS_OK != rv) { return rv; } @@ -2559,7 +2557,7 @@ nsTextFrame::Reflow(nsIPresContext& aPresContext, // Look ahead in the text-run and compute the final word // width, taking into account any style changes and stopping // at the first breakable point. - nscoord wordWidth = ComputeTotalWordWidth(&aPresContext, lineLayout, + nscoord wordWidth = ComputeTotalWordWidth(&aPresContext, lb, lineLayout, aReflowState, next, lastWordWidth, pWordBuf, @@ -2803,6 +2801,7 @@ nsTextFrame::TrimTrailingWhiteSpace(nsIPresContext* aPresContext, nscoord nsTextFrame::ComputeTotalWordWidth(nsIPresContext* aPresContext, + nsILineBreaker* aLineBreaker, nsLineLayout& aLineLayout, const nsHTMLReflowState& aReflowState, nsIFrame* aNextFrame, @@ -2824,6 +2823,7 @@ nsTextFrame::ComputeTotalWordWidth(nsIPresContext* aPresContext, if (NS_OK == content->QueryInterface(kITextContentIID, (void**)&tc)) { PRBool stop; nscoord moreWidth = ComputeWordFragmentWidth(aPresContext, + aLineBreaker, aLineLayout, aReflowState, aNextFrame, tc, @@ -2874,6 +2874,7 @@ nsTextFrame::GetCorrectStyleContext(nsIPresContext* aPresContext, nscoord nsTextFrame::ComputeWordFragmentWidth(nsIPresContext* aPresContext, + nsILineBreaker* aLineBreaker, nsLineLayout& aLineLayout, const nsHTMLReflowState& aReflowState, nsIFrame* aTextFrame, @@ -2884,29 +2885,11 @@ nsTextFrame::ComputeWordFragmentWidth(nsIPresContext* aPresContext, PRUint32 aWordBufSize) { PRUnichar buf[TEXT_BUF_SIZE]; - nsIDocument* doc; - mContent->GetDocument(doc); - if (!doc) { - // Not all content objects have a document pointer. Anonymous content - // objects, e.g. generated content, do not live in the document model - nsIPresShell* shell; - - aPresContext->GetShell(&shell); - shell->GetDocument(&doc); - NS_RELEASE(shell); - } - - nsCOMPtr lb; - doc->GetLineBreaker(getter_AddRefs(lb)); - //nsCOMPtr wb; - //doc->GetWordBreaker(getter_AddRefs(wb)); - NS_IF_RELEASE(doc); - - nsTextTransformer tx(buf, TEXT_BUF_SIZE,lb,nsnull); + nsTextTransformer tx(buf, TEXT_BUF_SIZE,aLineBreaker,nsnull); // XXX we need the content-offset of the text frame!!! 0 won't // always be right when continuations are in action - tx.Init(/**textRun, XXX*/ aTextFrame, 0); + tx.Init(aTextFrame, mContent, 0); PRBool isWhitespace; PRInt32 wordLen, contentLen; @@ -2929,7 +2912,7 @@ nsTextFrame::ComputeWordFragmentWidth(nsIPresContext* aPresContext, PRUint32 breakP=0; PRBool needMore=PR_TRUE; - nsresult lres = lb->Next(aWordBuf, aWordBufLen+wordLen, 0, &breakP, &needMore); + nsresult lres = aLineBreaker->Next(aWordBuf, aWordBufLen+wordLen, 0, &breakP, &needMore); if(NS_SUCCEEDED(lres)) { // when we look at two pieces text together, we might decide to break diff --git a/mozilla/layout/generic/nsTextTransformer.cpp b/mozilla/layout/generic/nsTextTransformer.cpp index 93d12353c4f..3da5f840f8a 100644 --- a/mozilla/layout/generic/nsTextTransformer.cpp +++ b/mozilla/layout/generic/nsTextTransformer.cpp @@ -49,8 +49,6 @@ nsTextTransformer::nsTextTransformer(PRUnichar* aBuffer, PRInt32 aBufLen, mLineBreaker(aLineBreaker), mWordBreaker(aWordBreaker) { - NS_IF_ADDREF(mLineBreaker); - NS_IF_ADDREF(mWordBreaker); } nsTextTransformer::~nsTextTransformer() @@ -58,13 +56,11 @@ nsTextTransformer::~nsTextTransformer() if (mBuffer != mAutoBuffer) { delete [] mBuffer; } - NS_IF_RELEASE(mLineBreaker); - NS_IF_RELEASE(mWordBreaker); } nsresult -nsTextTransformer::Init(/*nsTextRun& aTextRun, XXX*/ - nsIFrame* aFrame, +nsTextTransformer::Init(nsIFrame* aFrame, + nsIContent* aContent, PRInt32 aStartingOffset) { // Make sure we have *some* space in case arguments to the ctor were @@ -76,16 +72,12 @@ nsTextTransformer::Init(/*nsTextRun& aTextRun, XXX*/ } // Get the frames text content - nsIContent* content; - aFrame->GetContent(&content); nsITextContent* tc; - if (NS_OK != content->QueryInterface(kITextContentIID, (void**) &tc)) { - NS_RELEASE(content); + if (NS_OK != aContent->QueryInterface(kITextContentIID, (void**) &tc)) { return NS_OK; } tc->GetText(mFrags, mNumFrags); NS_RELEASE(tc); - NS_RELEASE(content); mStartingOffset = aStartingOffset; mOffset = mStartingOffset; diff --git a/mozilla/layout/generic/nsTextTransformer.h b/mozilla/layout/generic/nsTextTransformer.h index cdef51b5589..fc8ee87ede0 100644 --- a/mozilla/layout/generic/nsTextTransformer.h +++ b/mozilla/layout/generic/nsTextTransformer.h @@ -22,6 +22,7 @@ #include "nsTextFragment.h" #include "nsISupports.h" +class nsIContent; class nsIFrame; class nsTextRun; class nsILineBreaker; @@ -46,6 +47,8 @@ class nsIWordBreaker; class nsTextTransformer { public: + // The text transformer does not hold a reference to the line breaker + // and work breaker objects nsTextTransformer(PRUnichar* aBuffer, PRInt32 aBufLen, nsILineBreaker* aLineBreaker, nsIWordBreaker *aWordBreaker); @@ -56,8 +59,8 @@ public: * occurs. Subsequent calls to GetTransformedTextFor will just * return the result of the single transformation. */ - nsresult Init(/*nsTextRun& aTextRun, XXX*/ - nsIFrame* aFrame, + nsresult Init(nsIFrame* aFrame, + nsIContent* aContent, PRInt32 aStartingOffset); PRInt32 GetContentLength() const { @@ -101,8 +104,8 @@ protected: PRUint8 mTextTransform; PRUint8 mPreformatted; - nsILineBreaker* mLineBreaker; - nsIWordBreaker* mWordBreaker; + nsILineBreaker* mLineBreaker; // does NOT hold reference + nsIWordBreaker* mWordBreaker; // does NOT hold reference }; #endif /* nsTextTransformer_h___ */ diff --git a/mozilla/layout/html/base/src/nsTextFrame.cpp b/mozilla/layout/html/base/src/nsTextFrame.cpp index ee19e38335c..74cee7f5063 100644 --- a/mozilla/layout/html/base/src/nsTextFrame.cpp +++ b/mozilla/layout/html/base/src/nsTextFrame.cpp @@ -416,6 +416,7 @@ public: nscoord dx, nscoord dy); nscoord ComputeTotalWordWidth(nsIPresContext* aPresContext, + nsILineBreaker* aLineBreaker, nsLineLayout& aLineLayout, const nsHTMLReflowState& aReflowState, nsIFrame* aNextFrame, @@ -425,6 +426,7 @@ public: PRUint32 aWordBufSize); nscoord ComputeWordFragmentWidth(nsIPresContext* aPresContext, + nsILineBreaker* aLineBreaker, nsLineLayout& aLineLayout, const nsHTMLReflowState& aReflowState, nsIFrame* aNextFrame, @@ -622,7 +624,7 @@ nsTextFrame::PrepareUnicodeText(nsTextTransformer& aTX, // Setup transform to operate starting in the content at our content // offset - aTX.Init(this, mContentOffset); + aTX.Init(this, mContent, mContentOffset); PRInt32 strInx = mContentOffset; @@ -2107,7 +2109,7 @@ nsTextFrame::PeekOffset(nsPeekOffsetStruct *aPos) PRInt32 wordLen, contentLen; if (aPos->mDirection == eDirPrevious){ keepSearching = PR_TRUE; - tx.Init(this, aPos->mStartOffset); + tx.Init(this, mContent, aPos->mStartOffset); if (tx.GetPrevWord(PR_FALSE, wordLen, contentLen, isWhitespace, PR_FALSE)){ if ((aPos->mEatingWS && !isWhitespace) || !aPos->mEatingWS){ aPos->mContentOffset = aPos->mStartOffset - contentLen; @@ -2136,7 +2138,7 @@ nsTextFrame::PeekOffset(nsPeekOffsetStruct *aPos) start = -1; //start at end } else if (aPos->mDirection == eDirNext){ - tx.Init(this, aPos->mStartOffset ); + tx.Init(this, mContent, aPos->mStartOffset ); #ifdef DEBUGWORDJUMP printf("Next- Start=%d aPos->mEatingWS=%s\n", aPos->mStartOffset, aPos->mEatingWS ? "TRUE" : "FALSE"); @@ -2372,18 +2374,14 @@ nsTextFrame::Reflow(nsIPresContext& aPresContext, PRBool endsInWhitespace = PR_FALSE; PRBool endsInNewline = PR_FALSE; - nsCOMPtr shell; - aPresContext.GetShell(getter_AddRefs(shell)); nsCOMPtr doc; - shell->GetDocument(getter_AddRefs(doc)); + mContent->GetDocument(*getter_AddRefs(doc)); // Setup text transformer to transform this frames text content PRUnichar wordBuf[WORD_BUF_SIZE]; nsCOMPtr lb; doc->GetLineBreaker(getter_AddRefs(lb)); - //nsCOMPtr wb; - //doc->GetWordBreaker(getter_AddRefs(wb)); nsTextTransformer tx(wordBuf, WORD_BUF_SIZE,lb,nsnull); - nsresult rv = tx.Init(/**textRun, XXX*/ this, startingOffset); + nsresult rv = tx.Init(this, mContent, startingOffset); if (NS_OK != rv) { return rv; } @@ -2559,7 +2557,7 @@ nsTextFrame::Reflow(nsIPresContext& aPresContext, // Look ahead in the text-run and compute the final word // width, taking into account any style changes and stopping // at the first breakable point. - nscoord wordWidth = ComputeTotalWordWidth(&aPresContext, lineLayout, + nscoord wordWidth = ComputeTotalWordWidth(&aPresContext, lb, lineLayout, aReflowState, next, lastWordWidth, pWordBuf, @@ -2803,6 +2801,7 @@ nsTextFrame::TrimTrailingWhiteSpace(nsIPresContext* aPresContext, nscoord nsTextFrame::ComputeTotalWordWidth(nsIPresContext* aPresContext, + nsILineBreaker* aLineBreaker, nsLineLayout& aLineLayout, const nsHTMLReflowState& aReflowState, nsIFrame* aNextFrame, @@ -2824,6 +2823,7 @@ nsTextFrame::ComputeTotalWordWidth(nsIPresContext* aPresContext, if (NS_OK == content->QueryInterface(kITextContentIID, (void**)&tc)) { PRBool stop; nscoord moreWidth = ComputeWordFragmentWidth(aPresContext, + aLineBreaker, aLineLayout, aReflowState, aNextFrame, tc, @@ -2874,6 +2874,7 @@ nsTextFrame::GetCorrectStyleContext(nsIPresContext* aPresContext, nscoord nsTextFrame::ComputeWordFragmentWidth(nsIPresContext* aPresContext, + nsILineBreaker* aLineBreaker, nsLineLayout& aLineLayout, const nsHTMLReflowState& aReflowState, nsIFrame* aTextFrame, @@ -2884,29 +2885,11 @@ nsTextFrame::ComputeWordFragmentWidth(nsIPresContext* aPresContext, PRUint32 aWordBufSize) { PRUnichar buf[TEXT_BUF_SIZE]; - nsIDocument* doc; - mContent->GetDocument(doc); - if (!doc) { - // Not all content objects have a document pointer. Anonymous content - // objects, e.g. generated content, do not live in the document model - nsIPresShell* shell; - - aPresContext->GetShell(&shell); - shell->GetDocument(&doc); - NS_RELEASE(shell); - } - - nsCOMPtr lb; - doc->GetLineBreaker(getter_AddRefs(lb)); - //nsCOMPtr wb; - //doc->GetWordBreaker(getter_AddRefs(wb)); - NS_IF_RELEASE(doc); - - nsTextTransformer tx(buf, TEXT_BUF_SIZE,lb,nsnull); + nsTextTransformer tx(buf, TEXT_BUF_SIZE,aLineBreaker,nsnull); // XXX we need the content-offset of the text frame!!! 0 won't // always be right when continuations are in action - tx.Init(/**textRun, XXX*/ aTextFrame, 0); + tx.Init(aTextFrame, mContent, 0); PRBool isWhitespace; PRInt32 wordLen, contentLen; @@ -2929,7 +2912,7 @@ nsTextFrame::ComputeWordFragmentWidth(nsIPresContext* aPresContext, PRUint32 breakP=0; PRBool needMore=PR_TRUE; - nsresult lres = lb->Next(aWordBuf, aWordBufLen+wordLen, 0, &breakP, &needMore); + nsresult lres = aLineBreaker->Next(aWordBuf, aWordBufLen+wordLen, 0, &breakP, &needMore); if(NS_SUCCEEDED(lres)) { // when we look at two pieces text together, we might decide to break diff --git a/mozilla/layout/html/base/src/nsTextTransformer.cpp b/mozilla/layout/html/base/src/nsTextTransformer.cpp index 93d12353c4f..3da5f840f8a 100644 --- a/mozilla/layout/html/base/src/nsTextTransformer.cpp +++ b/mozilla/layout/html/base/src/nsTextTransformer.cpp @@ -49,8 +49,6 @@ nsTextTransformer::nsTextTransformer(PRUnichar* aBuffer, PRInt32 aBufLen, mLineBreaker(aLineBreaker), mWordBreaker(aWordBreaker) { - NS_IF_ADDREF(mLineBreaker); - NS_IF_ADDREF(mWordBreaker); } nsTextTransformer::~nsTextTransformer() @@ -58,13 +56,11 @@ nsTextTransformer::~nsTextTransformer() if (mBuffer != mAutoBuffer) { delete [] mBuffer; } - NS_IF_RELEASE(mLineBreaker); - NS_IF_RELEASE(mWordBreaker); } nsresult -nsTextTransformer::Init(/*nsTextRun& aTextRun, XXX*/ - nsIFrame* aFrame, +nsTextTransformer::Init(nsIFrame* aFrame, + nsIContent* aContent, PRInt32 aStartingOffset) { // Make sure we have *some* space in case arguments to the ctor were @@ -76,16 +72,12 @@ nsTextTransformer::Init(/*nsTextRun& aTextRun, XXX*/ } // Get the frames text content - nsIContent* content; - aFrame->GetContent(&content); nsITextContent* tc; - if (NS_OK != content->QueryInterface(kITextContentIID, (void**) &tc)) { - NS_RELEASE(content); + if (NS_OK != aContent->QueryInterface(kITextContentIID, (void**) &tc)) { return NS_OK; } tc->GetText(mFrags, mNumFrags); NS_RELEASE(tc); - NS_RELEASE(content); mStartingOffset = aStartingOffset; mOffset = mStartingOffset; diff --git a/mozilla/layout/html/base/src/nsTextTransformer.h b/mozilla/layout/html/base/src/nsTextTransformer.h index cdef51b5589..fc8ee87ede0 100644 --- a/mozilla/layout/html/base/src/nsTextTransformer.h +++ b/mozilla/layout/html/base/src/nsTextTransformer.h @@ -22,6 +22,7 @@ #include "nsTextFragment.h" #include "nsISupports.h" +class nsIContent; class nsIFrame; class nsTextRun; class nsILineBreaker; @@ -46,6 +47,8 @@ class nsIWordBreaker; class nsTextTransformer { public: + // The text transformer does not hold a reference to the line breaker + // and work breaker objects nsTextTransformer(PRUnichar* aBuffer, PRInt32 aBufLen, nsILineBreaker* aLineBreaker, nsIWordBreaker *aWordBreaker); @@ -56,8 +59,8 @@ public: * occurs. Subsequent calls to GetTransformedTextFor will just * return the result of the single transformation. */ - nsresult Init(/*nsTextRun& aTextRun, XXX*/ - nsIFrame* aFrame, + nsresult Init(nsIFrame* aFrame, + nsIContent* aContent, PRInt32 aStartingOffset); PRInt32 GetContentLength() const { @@ -101,8 +104,8 @@ protected: PRUint8 mTextTransform; PRUint8 mPreformatted; - nsILineBreaker* mLineBreaker; - nsIWordBreaker* mWordBreaker; + nsILineBreaker* mLineBreaker; // does NOT hold reference + nsIWordBreaker* mWordBreaker; // does NOT hold reference }; #endif /* nsTextTransformer_h___ */