diff --git a/mozilla/content/base/public/nsContentUtils.h b/mozilla/content/base/public/nsContentUtils.h index 84c1339c7b1..804fc734795 100644 --- a/mozilla/content/base/public/nsContentUtils.h +++ b/mozilla/content/base/public/nsContentUtils.h @@ -78,6 +78,8 @@ class nsIConsoleService; class nsIStringBundleService; class nsIStringBundle; class nsIContentPolicy; +class nsILineBreaker; +class nsIWordBreaker; #ifdef MOZ_XTF class nsIXTFService; #endif @@ -336,6 +338,16 @@ public: return sPrefBranch; } + static nsILineBreaker* GetLineBreaker() + { + return sLineBreaker; + } + + static nsIWordBreaker* GetWordBreaker() + { + return sWordBreaker; + } + static nsresult GetDocumentAndPrincipal(nsIDOMNode* aNode, nsIDocument** aDocument, nsIPrincipal** aPrincipal); @@ -605,6 +617,9 @@ private: static nsIContentPolicy* sContentPolicyService; + static nsILineBreaker* sLineBreaker; + static nsIWordBreaker* sWordBreaker; + // Holds pointers to nsISupports* that should be released at shutdown static nsVoidArray* sPtrsToPtrsToRelease; diff --git a/mozilla/content/base/public/nsIDocument.h b/mozilla/content/base/public/nsIDocument.h index 9472dd06d68..caa25c7fc5f 100644 --- a/mozilla/content/base/public/nsIDocument.h +++ b/mozilla/content/base/public/nsIDocument.h @@ -273,14 +273,6 @@ public: mBidiEnabled = aBidiEnabled; } - /** - * Return the Line Breaker for the document - */ - virtual nsILineBreaker* GetLineBreaker() = 0; - virtual void SetLineBreaker(nsILineBreaker* aLineBreaker) = 0; - virtual nsIWordBreaker* GetWordBreaker() = 0; - virtual void SetWordBreaker(nsIWordBreaker* aWordBreaker) = 0; - /** * Access HTTP header data (this may also get set from other * sources, like HTML META tags). diff --git a/mozilla/content/base/src/nsContentUtils.cpp b/mozilla/content/base/src/nsContentUtils.cpp index 548ec3b2016..7a4fe692973 100644 --- a/mozilla/content/base/src/nsContentUtils.cpp +++ b/mozilla/content/base/src/nsContentUtils.cpp @@ -109,6 +109,9 @@ static NS_DEFINE_CID(kXTFServiceCID, NS_XTFSERVICE_CID); #endif #include "nsIMIMEService.h" +#include "nsLWBrkCIID.h" +#include "nsILineBreaker.h" +#include "nsIWordBreaker.h" // for ReportToConsole #include "nsIStringBundle.h" @@ -135,6 +138,8 @@ nsIConsoleService *nsContentUtils::sConsoleService; nsIStringBundleService *nsContentUtils::sStringBundleService; nsIStringBundle *nsContentUtils::sStringBundles[PropertiesFile_COUNT]; nsIContentPolicy *nsContentUtils::sContentPolicyService; +nsILineBreaker *nsContentUtils::sLineBreaker = nsnull; +nsIWordBreaker *nsContentUtils::sWordBreaker = nsnull; nsVoidArray *nsContentUtils::sPtrsToPtrsToRelease; @@ -187,6 +192,12 @@ nsContentUtils::Init() sIOService = nsnull; } + rv = CallGetService(NS_LBRK_CONTRACTID, &sLineBreaker); + NS_ENSURE_SUCCESS(rv, rv); + + rv = CallGetService(NS_WBRK_CONTRACTID, &sWordBreaker); + NS_ENSURE_SUCCESS(rv, rv); + // Ignore failure and just don't load images rv = CallGetService("@mozilla.org/image/loader;1", &sImgLoader); if (NS_FAILED(rv)) { @@ -427,6 +438,8 @@ nsContentUtils::Shutdown() NS_IF_RELEASE(sNameSpaceManager); NS_IF_RELEASE(sParserService); NS_IF_RELEASE(sIOService); + NS_IF_RELEASE(sLineBreaker); + NS_IF_RELEASE(sWordBreaker); #ifdef MOZ_XTF NS_IF_RELEASE(sXTFService); #endif diff --git a/mozilla/content/base/src/nsDocument.cpp b/mozilla/content/base/src/nsDocument.cpp index 84899160ab8..cc634560f8b 100644 --- a/mozilla/content/base/src/nsDocument.cpp +++ b/mozilla/content/base/src/nsDocument.cpp @@ -115,10 +115,6 @@ static NS_DEFINE_CID(kDOMEventGroupCID, NS_DOMEVENTGROUP_CID); -#include "nsILineBreakerFactory.h" -#include "nsIWordBreakerFactory.h" -#include "nsLWBrkCIID.h" - #include "nsHTMLAtoms.h" #include "nsScriptEventManager.h" @@ -1336,52 +1332,6 @@ nsDocument::RemoveCharSetObserver(nsIObserver* aObserver) mCharSetObservers.RemoveElement(aObserver); } -nsILineBreaker* -nsDocument::GetLineBreaker() -{ - if (!mLineBreaker) { - // no line breaker, find a default one - nsresult rv; - nsCOMPtr lbf = - do_GetService(NS_LWBRK_CONTRACTID, &rv); - NS_ENSURE_SUCCESS(rv, nsnull); - - lbf->GetBreaker(EmptyString(), getter_AddRefs(mLineBreaker)); - NS_ENSURE_TRUE(mLineBreaker, nsnull); - } - - return mLineBreaker; -} - -void -nsDocument::SetLineBreaker(nsILineBreaker* aLineBreaker) -{ - mLineBreaker = aLineBreaker; -} - -nsIWordBreaker* -nsDocument::GetWordBreaker() -{ - if (!mWordBreaker) { - // no word breaker, find a default one - nsresult rv; - nsCOMPtr wbf = - do_GetService(NS_LWBRK_CONTRACTID, &rv); - NS_ENSURE_SUCCESS(rv, nsnull); - - wbf->GetBreaker(EmptyString(), getter_AddRefs(mWordBreaker)); - NS_ENSURE_TRUE(wbf, nsnull); - } - - return mWordBreaker; -} - -void -nsDocument::SetWordBreaker(nsIWordBreaker* aWordBreaker) -{ - mWordBreaker = aWordBreaker; -} - void nsDocument::GetHeaderData(nsIAtom* aHeaderField, nsAString& aData) const { diff --git a/mozilla/content/base/src/nsDocument.h b/mozilla/content/base/src/nsDocument.h index 7b8d2805305..4442fb12b64 100644 --- a/mozilla/content/base/src/nsDocument.h +++ b/mozilla/content/base/src/nsDocument.h @@ -72,8 +72,6 @@ #include "nsIDOM3DocumentEvent.h" #include "nsCOMArray.h" #include "nsHashtable.h" -#include "nsIWordBreakerFactory.h" -#include "nsILineBreakerFactory.h" #include "nsIScriptObjectPrincipal.h" #include "nsIURI.h" #include "nsScriptLoader.h" @@ -354,14 +352,6 @@ public: */ virtual void RemoveCharSetObserver(nsIObserver* aObserver); - /** - * Return the Line Breaker for the document - */ - virtual nsILineBreaker* GetLineBreaker(); - virtual void SetLineBreaker(nsILineBreaker* aLineBreaker); - virtual nsIWordBreaker* GetWordBreaker(); - virtual void SetWordBreaker(nsIWordBreaker* aWordBreaker); - /** * Access HTTP header data (this may also get set from other sources, like * HTML META tags). @@ -721,8 +711,6 @@ protected: nsCOMPtr mDOMStyleSheets; nsCOMPtr mScriptLoader; nsDocHeaderData* mHeaderData; - nsCOMPtr mLineBreaker; - nsCOMPtr mWordBreaker; nsRefPtr mChildNodes; diff --git a/mozilla/content/base/src/nsHTMLContentSerializer.cpp b/mozilla/content/base/src/nsHTMLContentSerializer.cpp index 8bb1e0f6d3f..d3d3cf0b09f 100644 --- a/mozilla/content/base/src/nsHTMLContentSerializer.cpp +++ b/mozilla/content/base/src/nsHTMLContentSerializer.cpp @@ -57,7 +57,6 @@ #include "nsCRT.h" #include "nsIParserService.h" #include "nsContentUtils.h" -#include "nsILineBreakerFactory.h" #include "nsLWBrkCIID.h" #define kIndentStr NS_LITERAL_STRING(" ") @@ -66,7 +65,6 @@ #define kEndTag NS_LITERAL_STRING(" domDoc; aText->GetOwnerDocument(getter_AddRefs(domDoc)); nsCOMPtr document = do_QueryInterface(domDoc); - if (document) { - mLineBreaker = document->GetLineBreaker(); - } - - if (!mLineBreaker) { - nsresult rv; - nsCOMPtr lf(do_GetService(kLWBrkCID, &rv)); - if (NS_SUCCEEDED(rv)) { - rv = lf->GetBreaker(EmptyString(), getter_AddRefs(mLineBreaker)); - // Ignore result value. - // If we are unable to obtain a line breaker, - // we will use our simple fallback logic. - } - } } nsAutoString data; @@ -349,27 +333,22 @@ void nsHTMLContentSerializer::AppendWrapped_NonWhitespaceSequence( // we must wrap PRBool foundWrapPosition = PR_FALSE; + nsCOMPtr aLineBreaker = nsContentUtils::GetLineBreaker(); - if (mLineBreaker) { // we have a line breaker helper object - PRUint32 wrapPosition; - PRBool needMoreText; - nsresult rv; + if (aLineBreaker) { // we have a line breaker helper object + PRInt32 wrapPosition; - rv = mLineBreaker->Prev(aSequenceStart, - (aEnd - aSequenceStart), - (aPos - aSequenceStart) + 1, - &wrapPosition, - &needMoreText); - if (NS_SUCCEEDED(rv) && !needMoreText && wrapPosition > 0) { + wrapPosition = aLineBreaker->Prev(aSequenceStart, + (aEnd - aSequenceStart), + (aPos - aSequenceStart) + 1); + if (wrapPosition != NS_LINEBREAKER_NEED_MORE_TEXT) { foundWrapPosition = PR_TRUE; } else { - rv = mLineBreaker->Next(aSequenceStart, - (aEnd - aSequenceStart), - (aPos - aSequenceStart), - &wrapPosition, - &needMoreText); - if (NS_SUCCEEDED(rv) && !needMoreText && wrapPosition > 0) { + wrapPosition = aLineBreaker->Next(aSequenceStart, + (aEnd - aSequenceStart), + (aPos - aSequenceStart)); + if (wrapPosition != NS_LINEBREAKER_NEED_MORE_TEXT) { foundWrapPosition = PR_TRUE; } } @@ -389,7 +368,7 @@ void nsHTMLContentSerializer::AppendWrapped_NonWhitespaceSequence( } } - if (!mLineBreaker || !foundWrapPosition) { + if (!aLineBreaker || !foundWrapPosition) { // try some simple fallback logic // go forward up to the next whitespace position, // in the worst case this will be all the rest of the data diff --git a/mozilla/content/base/src/nsPlainTextSerializer.cpp b/mozilla/content/base/src/nsPlainTextSerializer.cpp index 6c0f5c2690e..3d8f0e9cbbb 100644 --- a/mozilla/content/base/src/nsPlainTextSerializer.cpp +++ b/mozilla/content/base/src/nsPlainTextSerializer.cpp @@ -38,7 +38,6 @@ * ***** END LICENSE BLOCK ***** */ #include "nsPlainTextSerializer.h" -#include "nsILineBreakerFactory.h" #include "nsLWBrkCIID.h" #include "nsIServiceManager.h" #include "nsHTMLAtoms.h" @@ -54,8 +53,6 @@ #include "nsCRT.h" #include "nsIParserService.h" -static NS_DEFINE_CID(kLWBrkCID, NS_LWBRK_CID); - #define PREF_STRUCTS "converter.html2txt.structs" #define PREF_HEADER_STRATEGY "converter.html2txt.header_strategy" @@ -166,19 +163,13 @@ nsPlainTextSerializer::Init(PRUint32 aFlags, PRUint32 aWrapColumn, NS_ENSURE_TRUE(nsContentUtils::GetParserServiceWeakRef(), NS_ERROR_UNEXPECTED); - nsresult rv; - mFlags = aFlags; mWrapColumn = aWrapColumn; // Only create a linebreaker if we will handle wrapping. if (MayWrap()) { - nsCOMPtr lf(do_GetService(kLWBrkCID, &rv)); - if (NS_SUCCEEDED(rv)) { - nsAutoString lbarg; - rv = lf->GetBreaker(lbarg, getter_AddRefs(mLineBreaker)); - if (NS_FAILED(rv)) return NS_ERROR_FAILURE; - } + mLineBreaker = nsContentUtils::GetLineBreaker(); + if (!mLineBreaker) return NS_ERROR_FAILURE; } // Set the line break character: @@ -1406,10 +1397,7 @@ nsPlainTextSerializer::AddToLine(const PRUnichar * aLineFragment, PRUint32 bonuswidth = (mWrapColumn > 20) ? 4 : 0; // XXX: Should calculate prefixwidth with GetUnicharStringWidth - while(mCurrentLineWidth+prefixwidth > mWrapColumn+bonuswidth) { - // Must wrap. Let's find a good place to do that. - nsresult result = NS_OK; - + while(mCurrentLineWidth+prefixwidth > mWrapColumn+bonuswidth) { // We go from the end removing one letter at a time until // we have a reasonable width PRInt32 goodSpace = mCurrentLine.Length(); @@ -1421,20 +1409,16 @@ nsPlainTextSerializer::AddToLine(const PRUnichar * aLineFragment, goodSpace++; - PRBool oNeedMoreText; - if (nsnull != mLineBreaker) { - result = mLineBreaker->Prev(mCurrentLine.get(), - mCurrentLine.Length(), goodSpace, - (PRUint32 *) &goodSpace, &oNeedMoreText); - if (oNeedMoreText) { - goodSpace = -1; - } - else if (nsCRT::IsAsciiSpace(mCurrentLine.CharAt(goodSpace-1))) { + if (mLineBreaker) { + goodSpace = mLineBreaker->Prev(mCurrentLine.get(), + mCurrentLine.Length(), goodSpace); + if (goodSpace != NS_LINEBREAKER_NEED_MORE_TEXT && + nsCRT::IsAsciiSpace(mCurrentLine.CharAt(goodSpace-1))) { --goodSpace; // adjust the position since line breaker returns a position next to space } } // fallback if the line breaker is unavailable or failed - if (nsnull == mLineBreaker || NS_FAILED(result)) { + if (!mLineBreaker) { goodSpace = mWrapColumn-prefixwidth; while (goodSpace >= 0 && !nsCRT::IsAsciiSpace(mCurrentLine.CharAt(goodSpace))) { @@ -1443,18 +1427,18 @@ nsPlainTextSerializer::AddToLine(const PRUnichar * aLineFragment, } nsAutoString restOfLine; - if (goodSpace < 0) { + if (goodSpace == NS_LINEBREAKER_NEED_MORE_TEXT) { // If we don't found a good place to break, accept long line and // try to find another place to break goodSpace=(prefixwidth>mWrapColumn+1)?1:mWrapColumn-prefixwidth+1; - result = NS_OK; - if (nsnull != mLineBreaker) { - result = mLineBreaker->Next(mCurrentLine.get(), - mCurrentLine.Length(), goodSpace, - (PRUint32 *) &goodSpace, &oNeedMoreText); + if (mLineBreaker) { + goodSpace = mLineBreaker->Next(mCurrentLine.get(), + mCurrentLine.Length(), goodSpace); + if (goodSpace == NS_LINEBREAKER_NEED_MORE_TEXT) + goodSpace = mCurrentLine.Length(); } // fallback if the line breaker is unavailable or failed - if (nsnull == mLineBreaker || NS_FAILED(result)) { + if (!mLineBreaker) { goodSpace=(prefixwidth>mWrapColumn)?1:mWrapColumn-prefixwidth; while (goodSpace < linelength && !nsCRT::IsAsciiSpace(mCurrentLine.CharAt(goodSpace))) { diff --git a/mozilla/editor/libeditor/text/nsInternetCiter.cpp b/mozilla/editor/libeditor/text/nsInternetCiter.cpp index 31b37855a17..7d36465cdd0 100644 --- a/mozilla/editor/libeditor/text/nsInternetCiter.cpp +++ b/mozilla/editor/libeditor/text/nsInternetCiter.cpp @@ -46,8 +46,8 @@ // Line breaker stuff #include "nsIServiceManager.h" -#include "nsILineBreakerFactory.h" #include "nsLWBrkCIID.h" +#include "nsILineBreaker.h" const PRUnichar gt ('>'); const PRUnichar space (' '); @@ -203,16 +203,9 @@ nsInternetCiter::Rewrap(const nsAString& aInString, aOutString.Truncate(); - nsCOMPtr lineBreaker; - nsILineBreakerFactory *lf; nsresult rv; - rv = CallGetService(NS_LWBRK_CONTRACTID, &lf); - if (NS_SUCCEEDED(rv)) - { - nsAutoString lbarg; - lf->GetBreaker(lbarg, getter_AddRefs(lineBreaker)); - NS_RELEASE(lf); - } + nsCOMPtr lineBreaker = do_GetService(NS_LBRK_CONTRACTID, &rv); + NS_ENSURE_SUCCESS(rv, rv); // Loop over lines in the input string, rewrapping each one. PRUint32 length; @@ -361,15 +354,13 @@ nsInternetCiter::Rewrap(const nsAString& aInString, continue; // continue inner loop, with outStringCol now at bol } - PRUint32 breakPt; + PRInt32 breakPt; rv = NS_ERROR_BASE; if (lineBreaker) { - PRBool needMore; - rv = lineBreaker->Prev(tString.get() + posInString, - length - posInString, - eol + 1 - posInString, &breakPt, &needMore); - if (NS_FAILED(rv) || needMore) + breakPt = lineBreaker->Prev(tString.get() + posInString, + length - posInString, eol + 1 - posInString); + if (breakPt == NS_LINEBREAKER_NEED_MORE_TEXT) { // if we couldn't find a breakpoint looking backwards, // and we're not starting a new line, then end this line @@ -381,11 +372,12 @@ nsInternetCiter::Rewrap(const nsAString& aInString, } // Else try looking forwards: - rv = lineBreaker->Next(tString.get() + posInString, - length - posInString, - eol - posInString, &breakPt, &needMore); - if (needMore) rv = NS_ERROR_BASE; + breakPt = lineBreaker->Next(tString.get() + posInString, + length - posInString, eol - posInString); + if (breakPt == NS_LINEBREAKER_NEED_MORE_TEXT) rv = NS_ERROR_BASE; + else rv = NS_OK; } + else rv = NS_OK; } // If rv is okay, then breakPt is the place to break. // If we get out here and rv is set, something went wrong with line @@ -445,3 +437,4 @@ nsInternetCiter::Rewrap(const nsAString& aInString, return NS_OK; } + diff --git a/mozilla/editor/libeditor/text/nsTextEditRules.cpp b/mozilla/editor/libeditor/text/nsTextEditRules.cpp index 059428bdb96..8ac1a67054c 100644 --- a/mozilla/editor/libeditor/text/nsTextEditRules.cpp +++ b/mozilla/editor/libeditor/text/nsTextEditRules.cpp @@ -60,8 +60,6 @@ #include "nsIPrefBranch.h" #include "nsIPrefService.h" #include "nsUnicharUtils.h" -#include "nsIWordBreakerFactory.h" -#include "nsLWBrkCIID.h" // for IBMBIDI #include "nsIPresShell.h" diff --git a/mozilla/editor/libeditor/text/nsWrapUtils.cpp b/mozilla/editor/libeditor/text/nsWrapUtils.cpp index 88a709f947c..9fd18fd696a 100644 --- a/mozilla/editor/libeditor/text/nsWrapUtils.cpp +++ b/mozilla/editor/libeditor/text/nsWrapUtils.cpp @@ -41,7 +41,7 @@ // Line breaker stuff #include "nsIServiceManager.h" -#include "nsILineBreakerFactory.h" +#include "nsILineBreaker.h" #include "nsLWBrkCIID.h" /* @@ -56,16 +56,8 @@ nsWrapUtils::Rewrap(const nsAString& aInString, { PRInt32 i; - nsCOMPtr lineBreaker; - - nsILineBreakerFactory *lf; - nsresult rv = CallGetService(NS_LWBRK_CONTRACTID, &lf); - if (NS_SUCCEEDED(rv)) - { - nsAutoString lbarg; - lf->GetBreaker(lbarg, getter_AddRefs(lineBreaker)); - NS_RELEASE(lf); - } + nsresult rv; + nsCOMPtr lineBreaker = do_GetService(NS_LBRK_CONTRACTID, &rv); aOutString.Truncate(); @@ -92,19 +84,18 @@ nsWrapUtils::Rewrap(const nsAString& aInString, if (i > 0) aFirstLineOffset = 0; // eol is the prospective end of line ... // look backwards from there for a place to break. - PRUint32 breakPt; - PRBool needMore; + PRInt32 breakPt; rv = NS_ERROR_BASE; if (lineBreaker) { - rv = lineBreaker->Prev(unicodeStr + i, length - i, eol - i, - &breakPt, &needMore); - if (NS_FAILED(rv) || needMore) + breakPt = lineBreaker->Prev(unicodeStr + i, length - i, eol - i); + if (breakPt == NS_LINEBREAKER_NEED_MORE_TEXT) { - rv = lineBreaker->Next(unicodeStr + i, length - i, eol - i, - &breakPt, &needMore); - if (needMore) rv = NS_ERROR_BASE; + breakPt = lineBreaker->Next(unicodeStr + i, length - i, eol - i); + if (breakPt == NS_LINEBREAKER_NEED_MORE_TEXT) rv = NS_ERROR_BASE; + else rv = NS_OK; } + else rv = NS_OK; } // If we get out here and rv is set, something went wrong with line breaker. // Just break the line, hard. diff --git a/mozilla/editor/txtsvc/src/nsTextServicesDocument.cpp b/mozilla/editor/txtsvc/src/nsTextServicesDocument.cpp index 92e7a83a41d..2290a6c6f9f 100644 --- a/mozilla/editor/txtsvc/src/nsTextServicesDocument.cpp +++ b/mozilla/editor/txtsvc/src/nsTextServicesDocument.cpp @@ -57,8 +57,8 @@ #include "nsIDOMHTMLElement.h" #include "nsIDOMHTMLDocument.h" -#include "nsIWordBreakerFactory.h" #include "nsLWBrkCIID.h" +#include "nsIWordBreaker.h" #include "nsIServiceManager.h" #define LOCK_DOC(doc) @@ -467,13 +467,6 @@ nsTextServicesDocument::ExpandRangeToWordBoundaries(nsIDOMRange *aRange) result = CreateDocumentContentIterator(getter_AddRefs(docIter)); NS_ENSURE_SUCCESS(result, result); - // Get a word breaker to use. - - nsCOMPtr wordBreaker; - result = GetWordBreaker(getter_AddRefs(wordBreaker)); - NS_ENSURE_SUCCESS(result, result); - NS_ENSURE_TRUE(wordBreaker, NS_ERROR_FAILURE); - // Grab all the text in the block containing our // first text node. @@ -496,7 +489,7 @@ nsTextServicesDocument::ExpandRangeToWordBoundaries(nsIDOMRange *aRange) nsCOMPtr wordStartNode, wordEndNode; PRInt32 wordStartOffset, wordEndOffset; - result = FindWordBounds(&offsetTable, &blockStr, wordBreaker, + result = FindWordBounds(&offsetTable, &blockStr, rngStartNode, rngStartOffset, getter_AddRefs(wordStartNode), &wordStartOffset, getter_AddRefs(wordEndNode), &wordEndOffset); @@ -524,7 +517,7 @@ nsTextServicesDocument::ExpandRangeToWordBoundaries(nsIDOMRange *aRange) return result; } - result = FindWordBounds(&offsetTable, &blockStr, wordBreaker, + result = FindWordBounds(&offsetTable, &blockStr, rngEndNode, rngEndOffset, getter_AddRefs(wordStartNode), &wordStartOffset, getter_AddRefs(wordEndNode), &wordEndOffset); @@ -4613,24 +4606,6 @@ nsTextServicesDocument::NodeHasOffsetEntry(nsVoidArray *aOffsetTable, nsIDOMNode return NS_OK; } -nsresult -nsTextServicesDocument::GetWordBreaker(nsIWordBreaker** aResult) -{ - NS_ENSURE_ARG_POINTER(aResult); - - *aResult = nsnull; - - nsresult result; - nsCOMPtr wbf(do_GetService(NS_LWBRK_CONTRACTID, &result)); - if (NS_SUCCEEDED(result) && wbf) - { - nsString wbarg; - result = wbf->GetBreaker(wbarg, aResult); - } - - return result; -} - // Spellchecker code has this. See bug 211343 #ifdef XP_MAC #define IS_NBSP_CHAR(c) (((unsigned char)0xca)==(c)) @@ -4641,7 +4616,6 @@ nsTextServicesDocument::GetWordBreaker(nsIWordBreaker** aResult) nsresult nsTextServicesDocument::FindWordBounds(nsVoidArray *aOffsetTable, nsString *aBlockStr, - nsIWordBreaker *aWordBreaker, nsIDOMNode *aNode, PRInt32 aNodeOffset, nsIDOMNode **aWordStartNode, @@ -4681,22 +4655,32 @@ nsTextServicesDocument::FindWordBounds(nsVoidArray *aOffsetTable, const PRUnichar *str = aBlockStr->get(); PRUint32 strLen = aBlockStr->Length(); - PRUint32 beginWord=0, endWord=0; - result = aWordBreaker->FindWord(str, strLen, strOffset, - &beginWord, &endWord); + nsIWordBreaker *aWordBreaker; + + result = CallGetService(NS_WBRK_CONTRACTID, &aWordBreaker); NS_ENSURE_SUCCESS(result, result); - // Strip out the NBSPs at the ends - while ((beginWord <= endWord) && (IS_NBSP_CHAR(str[beginWord]))) - beginWord++; - if (str[endWord] == (unsigned char)0x20) + nsWordRange res = aWordBreaker->FindWord(str, strLen, strOffset); + NS_IF_RELEASE(aWordBreaker); + if(res.mBegin > strLen) { - PRUint32 realEndWord = endWord - 1; - while ((realEndWord > beginWord) && (IS_NBSP_CHAR(str[realEndWord]))) + if(!str) + return NS_ERROR_NULL_POINTER; + else + return NS_ERROR_ILLEGAL_VALUE; + } + + // Strip out the NBSPs at the ends + while ((res.mBegin <= res.mEnd) && (IS_NBSP_CHAR(str[res.mBegin]))) + res.mBegin++; + if (str[res.mEnd] == (unsigned char)0x20) + { + PRUint32 realEndWord = res.mEnd - 1; + while ((realEndWord > res.mBegin) && (IS_NBSP_CHAR(str[realEndWord]))) realEndWord--; - if (realEndWord < endWord - 1) - endWord = realEndWord + 1; + if (realEndWord < res.mEnd - 1) + res.mEnd = realEndWord + 1; } // Now that we have the string offsets for the beginning @@ -4711,13 +4695,13 @@ nsTextServicesDocument::FindWordBounds(nsVoidArray *aOffsetTable, PRInt32 strEndOffset = entry->mStrOffset + entry->mLength; - // Check to see if beginWord is within the range covered - // by this entry. Note that if beginWord is after the last + // Check to see if res.mBegin is within the range covered + // by this entry. Note that if res.mBegin is after the last // character covered by this entry, we will use the next // entry if there is one. - if (entry->mStrOffset <= beginWord && - (beginWord < strEndOffset || (beginWord == strEndOffset && i == lastIndex))) + if (entry->mStrOffset <= res.mBegin && + (res.mBegin < strEndOffset || (res.mBegin == strEndOffset && i == lastIndex))) { if (aWordStartNode) { @@ -4726,7 +4710,7 @@ nsTextServicesDocument::FindWordBounds(nsVoidArray *aOffsetTable, } if (aWordStartOffset) - *aWordStartOffset = entry->mNodeOffset + beginWord - entry->mStrOffset; + *aWordStartOffset = entry->mNodeOffset + res.mBegin - entry->mStrOffset; if (!aWordEndNode && !aWordEndOffset) { @@ -4737,12 +4721,12 @@ nsTextServicesDocument::FindWordBounds(nsVoidArray *aOffsetTable, } } - // Check to see if endWord is within the range covered + // Check to see if res.mEnd is within the range covered // by this entry. - if (entry->mStrOffset <= endWord && endWord <= strEndOffset) + if (entry->mStrOffset <= res.mEnd && res.mEnd <= strEndOffset) { - if (beginWord == endWord && endWord == strEndOffset && i != lastIndex) + if (res.mBegin == res.mEnd && res.mEnd == strEndOffset && i != lastIndex) { // Wait for the next round so that we use the same entry // we did for aWordStartNode. @@ -4757,7 +4741,7 @@ nsTextServicesDocument::FindWordBounds(nsVoidArray *aOffsetTable, } if (aWordEndOffset) - *aWordEndOffset = entry->mNodeOffset + endWord - entry->mStrOffset; + *aWordEndOffset = entry->mNodeOffset + res.mEnd - entry->mStrOffset; break; } diff --git a/mozilla/editor/txtsvc/src/nsTextServicesDocument.h b/mozilla/editor/txtsvc/src/nsTextServicesDocument.h index e232ee9ffca..b6a2edb1122 100644 --- a/mozilla/editor/txtsvc/src/nsTextServicesDocument.h +++ b/mozilla/editor/txtsvc/src/nsTextServicesDocument.h @@ -53,7 +53,6 @@ #include "nsITextServicesFilter.h" #include "nsWeakReference.h" -class nsIWordBreaker; class nsIRangeUtils; /** implementation of a text services object. @@ -234,9 +233,7 @@ private: nsresult RemoveInvalidOffsetEntries(); nsresult SplitOffsetEntry(PRInt32 aTableIndex, PRInt32 aOffsetIntoEntry); - static nsresult GetWordBreaker(nsIWordBreaker **aWordBreaker); static nsresult FindWordBounds(nsVoidArray *offsetTable, nsString *blockStr, - nsIWordBreaker *aWordBreaker, nsIDOMNode *aNode, PRInt32 aNodeOffset, nsIDOMNode **aWordStartNode, PRInt32 *aWordStartOffset, diff --git a/mozilla/embedding/components/find/src/nsFind.cpp b/mozilla/embedding/components/find/src/nsFind.cpp index 4511a6cc799..f066b921288 100644 --- a/mozilla/embedding/components/find/src/nsFind.cpp +++ b/mozilla/embedding/components/find/src/nsFind.cpp @@ -1,4 +1,5 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; +c-basic-offset: 2 -*- */ /* ***** BEGIN LICENSE BLOCK ***** * Version: MPL 1.1/GPL 2.0/LGPL 2.1 * @@ -63,6 +64,7 @@ #include "nsServiceManagerUtils.h" #include "nsUnicharUtils.h" #include "nsIDOMElement.h" +#include "nsIWordBreaker.h" #include "nsCRT.h" // Yikes! Casting a char to unichar can fill with ones! diff --git a/mozilla/extensions/spellcheck/src/nsSpellCheckController.cpp b/mozilla/extensions/spellcheck/src/nsSpellCheckController.cpp index ea116899590..ad206a9115f 100644 --- a/mozilla/extensions/spellcheck/src/nsSpellCheckController.cpp +++ b/mozilla/extensions/spellcheck/src/nsSpellCheckController.cpp @@ -38,6 +38,8 @@ #include "nsSpellCheckController.h" #include "nsIServiceManager.h" +#include "nsIWordBreaker.h" +#include "nsLWBrkCIID.h" #include "nsIDOMRange.h" #include "nsISelection.h" #include "nsIDOMRange.h" @@ -106,9 +108,10 @@ nsSpellCheckController::Init(nsITextServicesDocument* aDoc, nsIDOMRange* aInitia mSpellChecker = do_GetService(NS_SPELLCHECKER_CONTRACTID, &rv); NS_ENSURE_SUCCESS(rv, rv); - // Create WordBreaker - rv = nsSpellCheckUtils::GetWordBreaker(getter_AddRefs(mWordBreaker)); - NS_ENSURE_SUCCESS(rv, rv); + mWordBreaker = do_GetService(NS_WBRK_CONTRACTID, &rv); + + if(NS_FAILED(rv) || !mWordBreaker) + return NS_ERROR_FAILURE; // zero out offset before starting mOffset = 0; @@ -177,37 +180,35 @@ nsSpellCheckController::FindBeginningOfWord(PRUint32& aPos) const PRUnichar* text = mText.get(); PRUint32 textLen = mText.Length(); PRUint32 wlen = 0; - PRUint32 beginWord = 0; - PRUint32 endWord = 0; PRUint32 prvWordEnd; PRUint32 offset = 0; while (offset < textLen) { prvWordEnd = endWord; - nsresult rv = mWordBreaker->FindWord(text, textLen, offset, &beginWord, &endWord); - if (NS_FAILED(rv)) break; + nsWordRange res = mWordBreaker->FindWord(text, textLen, offset); + if (res.mBegin > textLen) break; // The wordBreaker hands back the spaces inbetween the words // so we need to skip any words that are all spaces const PRUnichar* start = (text+offset); - const PRUnichar* endPtr = (text+endWord); + const PRUnichar* endPtr = (text+res.mEnd); while (*start == NBSP_SPACE_CODE && start < endPtr) start++; if (start == endPtr) { - offset = endWord; + offset = res.mEnd; continue; } - offset = endWord+1; + offset = res.mEnd+1; - wlen = endWord - beginWord; - if (endWord < aPos) { + wlen = res.mEnd - res.mBegin; + if (res.mEnd < aPos) { continue; } - if (aPos >= beginWord) { - aPos = beginWord; + if (aPos >= res.mBegin) { + aPos = res.mBegin; break; } } @@ -228,7 +229,8 @@ NS_IMETHODIMP nsSpellCheckController::NextMisspelledWord(PRUnichar **aWord) { NS_ENSURE_ARG_POINTER(aWord); - NS_ENSURE_TRUE(mDocument && mSpellChecker && mWordBreaker, NS_ERROR_NULL_POINTER); + NS_ENSURE_TRUE(mDocument && mSpellChecker && mWordBreaker, + NS_ERROR_NULL_POINTER); // Init the return values. *aWord = nsnull; @@ -476,7 +478,8 @@ nsSpellCheckController::ReplaceAllOccurrences(const CharBuffer *aOldWord, const { NS_ENSURE_ARG_POINTER(aOldWord); NS_ENSURE_ARG_POINTER(aNewWord); - NS_ENSURE_TRUE(mSpellChecker && mWordBreaker, NS_ERROR_NULL_POINTER); + NS_ENSURE_TRUE(mSpellChecker && mWordBreaker, + NS_ERROR_NULL_POINTER); // Now get the next misspelled word in the document. const PRUnichar* text = mText.get(); @@ -537,7 +540,8 @@ nsSpellCheckController::SpellCheckDOMRange(nsIDOMRange *aRangeToCheck, nsISelect NS_ENSURE_ARG_POINTER(aRangeToCheck); NS_ENSURE_ARG_POINTER(aSelectionOfWords); - NS_ENSURE_TRUE(mSpellChecker && mWordBreaker, NS_ERROR_NULL_POINTER); + NS_ENSURE_TRUE(mSpellChecker && mWordBreaker, + NS_ERROR_NULL_POINTER); NS_ENSURE_TRUE(mDocument, NS_ERROR_NULL_POINTER); mDocument->InitWithRange(aRangeToCheck); @@ -590,12 +594,19 @@ nsSpellCheckController::FindNextMisspelledWord(const PRUnichar* aText, aIsMisspelled = PR_FALSE; #ifdef DEBUG_rods - DUMPWORDS(mWordBreaker, aText, aTextLen); + DUMPWORDS(aText, aTextLen); #endif while (aOffset < aTextLen) { - nsresult result = mWordBreaker->FindWord(aText, aTextLen, aOffset, &aBeginWord, &aEndWord); - NS_ENSURE_SUCCESS(result, result); + nsWordRange res = nsContentUtils::mWordBreaker->FindWord(aText, aTextLen, + aOffset); + if (res.mBegin > atextLen) + if (!aText) return NS_ERROR_NULL_POINTER; + else return NS_ERROR_ILLEGAL_VALUE; + + aBeginWord = res.mBegin; + aEndWord = res.mEnd; + aWLen = aEndWord - aBeginWord; // The wordBreaker hands back the spaces inbetween the words diff --git a/mozilla/extensions/spellcheck/src/nsSpellCheckController.h b/mozilla/extensions/spellcheck/src/nsSpellCheckController.h index db0f35a733f..be0d42ca2dd 100644 --- a/mozilla/extensions/spellcheck/src/nsSpellCheckController.h +++ b/mozilla/extensions/spellcheck/src/nsSpellCheckController.h @@ -41,7 +41,6 @@ #include "nsITextServicesDocument.h" #include "nsISpellCheckController.h" -#include "nsIWordBreakerFactory.h" // nsIWordBreaker #include "nsIDOMNode.h" #include "nsISpellChecker.h" @@ -89,8 +88,8 @@ private: CharBuffer mBlockBuffer; CharBuffer mWordBuffer; - nsCOMPtr mWordBreaker; nsCOMPtr mSpellChecker; + nsCOMPtr mWordBreaker; nsString mText; PRUint32 mOffset; // starting offset to start spelling PRUint32 mEndPoint; // end point of range to be spell checked diff --git a/mozilla/extensions/spellcheck/src/nsSpellCheckUtils.cpp b/mozilla/extensions/spellcheck/src/nsSpellCheckUtils.cpp index 1cafcf77ab6..1932561e22d 100644 --- a/mozilla/extensions/spellcheck/src/nsSpellCheckUtils.cpp +++ b/mozilla/extensions/spellcheck/src/nsSpellCheckUtils.cpp @@ -48,8 +48,8 @@ #include "nsITextServicesDocument.h" #include "nsIServiceManager.h" -#include "nsIWordBreakerFactory.h" // nsIWordBreaker #include "nsLWBrkCIID.h" +#include "nsIWordBreaker.h" /* XXX The platform-specific #defines of IS_NSBSP_CHAR are unnecessary and @@ -198,27 +198,9 @@ nsSpellCheckUtils::LoadTextBlockIntoBuffer(nsITextServicesDocument* aTxtSvcDoc, return NS_OK; } -nsresult -nsSpellCheckUtils::GetWordBreaker(nsIWordBreaker** aResult) -{ - NS_ENSURE_ARG_POINTER(aResult); - - // no line breaker, find a default one - nsresult result; - nsCOMPtr wbf(do_GetService(NS_LWBRK_CONTRACTID, &result)); - if (NS_SUCCEEDED(result)) - { - nsAutoString wbarg; - result = wbf->GetBreaker(wbarg, aResult); - NS_IF_ADDREF(*aResult); - } - return result; -} - #ifdef NS_DEBUG nsresult -nsSpellCheckUtils::DumpWords(nsIWordBreaker* aWordBreaker, - const PRUnichar* aText, +nsSpellCheckUtils::DumpWords(const PRUnichar* aText, const PRUint32& aTextLen) { PRUint32 offset = 0; @@ -237,20 +219,23 @@ nsSpellCheckUtils::DumpWords(nsIWordBreaker* aWordBreaker, //printf("%s\n", NS_LossyConvertUCS2toASCII(aText).get()); free(line); + nsresult rv; + nsCOMPtr aWordBreaker = do_GetService(NS_WBRK_CONTRACTID, &rv); + NS_ENSURE_SUCCESS(rv, rv); + while (offset < aTextLen) { - PRUint32 begin = 0; - PRUint32 end = 0; - nsresult result = aWordBreaker->FindWord(aText, aTextLen, offset, &begin, &end); - NS_ENSURE_SUCCESS(result, result); - wlen = end - begin; - printf("%d %d l:%d ", begin, end, wlen); + nsWordRange res = aWordBreaker->FindWord(aText, aTextLen, offset); + if (res.mBegin > aTextLen) return NS_ERROR_ILLEGAL_VALUE; + + wlen = res.mEnd - res.mBegin; + printf("%d %d l:%d ", res.mBegin, res.mEnd, wlen); const PRUnichar* start = (const PRUnichar*)(aText+offset); PRUnichar* word = nsCRT::strndup(start, wlen); nsString str(word); printf("[%s]\n", NS_LossyConvertUCS2toASCII(str).get()); nsMemory::Free(word); - offset = end; + offset = res.mEnd; } for (i=0;i<7;i++) printf("**********"); printf("\n"); diff --git a/mozilla/extensions/spellcheck/src/nsSpellCheckUtils.h b/mozilla/extensions/spellcheck/src/nsSpellCheckUtils.h index 0a86cb69ac1..1b36acfa932 100644 --- a/mozilla/extensions/spellcheck/src/nsSpellCheckUtils.h +++ b/mozilla/extensions/spellcheck/src/nsSpellCheckUtils.h @@ -45,7 +45,6 @@ class nsISpellChecker; class nsITextServicesDocument; -class nsIWordBreaker; class CharBuffer { @@ -111,12 +110,8 @@ public: nsString& aText, PRUint32& aOffset); - // helper - static nsresult GetWordBreaker(nsIWordBreaker** aResult); - #ifdef NS_DEBUG - static nsresult DumpWords(nsIWordBreaker* aWordBreaker, - const PRUnichar* aText, + static nsresult DumpWords(const PRUnichar* aText, const PRUint32& aTextLen); #define DUMPWORDS(_wb, _txt, _txtLen) nsSpellCheckUtils::DumpWords(_wb, _txt, _txtLen); #else diff --git a/mozilla/intl/build/nsI18nModule.cpp b/mozilla/intl/build/nsI18nModule.cpp index 28783592180..d62c9878e05 100644 --- a/mozilla/intl/build/nsI18nModule.cpp +++ b/mozilla/intl/build/nsI18nModule.cpp @@ -291,8 +291,10 @@ static nsModuleComponentInfo components[] = NULL, NULL}, #endif /* INCLUDE_DBGDETECTOR */ // lwbrk - { "Line and Word Breaker", NS_LWBRK_CID, - NS_LWBRK_CONTRACTID, nsLWBreakerFImpConstructor}, + { "Line Breaker", NS_LBRK_CID, + NS_LBRK_CONTRACTID, nsJISx4051LineBreakerConstructor}, + { "Word Breaker", NS_WBRK_CID, + NS_WBRK_CONTRACTID, nsSampleWordBreakerConstructor}, { "Semantic Unit Scanner", NS_SEMANTICUNITSCANNER_CID, NS_SEMANTICUNITSCANNER_CONTRACTID, nsSemanticUnitScannerConstructor}, diff --git a/mozilla/intl/lwbrk/public/Makefile.in b/mozilla/intl/lwbrk/public/Makefile.in index 7a04a60888c..e96a63698a0 100644 --- a/mozilla/intl/lwbrk/public/Makefile.in +++ b/mozilla/intl/lwbrk/public/Makefile.in @@ -45,13 +45,8 @@ include $(DEPTH)/config/autoconf.mk MODULE = lwbrk EXPORTS = \ - nsIBreakState.h \ - nsIBinarySearchIterator.h \ nsILineBreaker.h \ - nsILineBreakerFactory.h \ - nsILinearIterator.h \ nsIWordBreaker.h \ - nsIWordBreakerFactory.h \ nsLWBrkCIID.h \ $(NULL) diff --git a/mozilla/intl/lwbrk/public/nsIBinarySearchIterator.h b/mozilla/intl/lwbrk/public/nsIBinarySearchIterator.h index 407d935f94c..e69de29bb2d 100644 --- a/mozilla/intl/lwbrk/public/nsIBinarySearchIterator.h +++ b/mozilla/intl/lwbrk/public/nsIBinarySearchIterator.h @@ -1,62 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ -#ifndef nsIBinarySearchIterator_h__ -#define nsIBinarySearchIterator_h__ - - -#include "nsISupports.h" -#include "nscore.h" - -// {E86B3373-BF89-11d2-B3AF-00805F8A6670} -#define NS_IBINARYSEARCHITERATOR_IID \ -{ 0xe86b3373, 0xbf89, 0x11d2, \ - { 0xb3, 0xaf, 0x0, 0x80, 0x5f, 0x8a, 0x66, 0x70 } }; - - -class nsIBinarySearchIterator : public nsISupports { - -public: - NS_DEFINE_STATIC_IID_ACCESSOR(NS_IBINARYSEARCHITERATOR_IID) - - NS_IMETHOD First() = 0; - NS_IMETHOD Next(PRBool aForward) = 0; - NS_IMETHOD Current(PRUint32 *oPosition) = 0; - NS_IMETHOD IsDone(PRBool *oResult) = 0; - -}; - -#endif /* nsIBinarySearchIterator_h__ */ diff --git a/mozilla/intl/lwbrk/public/nsIBreakState.h b/mozilla/intl/lwbrk/public/nsIBreakState.h index 4c703c2c643..e69de29bb2d 100644 --- a/mozilla/intl/lwbrk/public/nsIBreakState.h +++ b/mozilla/intl/lwbrk/public/nsIBreakState.h @@ -1,113 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ -#ifndef nsIBreakState_h__ -#define nsIBreakState_h__ - - -#include "nsISupports.h" - -#include "nscore.h" - -// {EE874261-C0BF-11d2-B3AF-00805F8A6670} -#define NS_IBREAKSTATE_IID \ -{ 0xee874261, 0xc0bf, 0x11d2, \ - { 0xb3, 0xaf, 0x0, 0x80, 0x5f, 0x8a, 0x66, 0x70 } }; - - - -class nsIBreakState : public nsISupports -{ -public: - - NS_DEFINE_STATIC_IID_ACCESSOR(NS_IBREAKSTATE_IID) - - NS_IMETHOD Set (PRUint32 aPos, PRBool aDone) = 0; - NS_IMETHOD GetText (const PRUnichar** oText) = 0; - NS_IMETHOD Length (PRUint32* oLen) = 0; - NS_IMETHOD IsDone (PRBool *oDone) = 0; - NS_IMETHOD Current (PRUint32* oPos) = 0; - NS_IMETHOD SetPrivate (PRUint32 aPriv) = 0; - NS_IMETHOD GetPrivate (PRUint32* oPriv) = 0; - -}; - - -#define IMPL_NS_IBREAKSTATE(name) \ -class name : public nsIBreakState { \ - NS_DECL_ISUPPORTS \ - name (const PRUnichar *aText, PRUint32 aLen) { \ - mText = aText; mLen = aLen; \ - mPos = 0; mPriv = 0; mDone = PR_FALSE; \ - } ; \ - virtual ~name () { } ; \ - \ -public: \ - NS_IMETHOD Set (PRUint32 aPos, PRBool aDone) \ - { mPos = aPos; mDone = aDone; return NS_OK; }; \ - \ - NS_IMETHOD GetText (const PRUnichar** oText) \ - { *oText = mText; return NS_OK; }; \ - \ - NS_IMETHOD Length (PRUint32* oLen) \ - { *oLen = mLen; return NS_OK; }; \ - \ - NS_IMETHOD IsDone (PRBool *oDone) \ - { *oDone = mDone; return NS_OK; }; \ - \ - NS_IMETHOD Current (PRUint32* oPos) \ - { *oPos = mPos; return NS_OK; }; \ - \ - NS_IMETHOD SetPrivate (PRUint32 aPriv) \ - { mPriv = aPriv; return NS_OK; }; \ - \ - NS_IMETHOD GetPrivate (PRUint32* oPriv) \ - { *oPriv = mPriv ; return NS_OK; }; \ - \ - PRUint32 Current() { return mPos;}; \ - \ - PRUint32 IsDone() { return mDone;}; \ - \ -protected: \ - PRUint32 mPos; \ - PRBool mDone; \ - PRUint32 mPriv; \ - const PRUnichar*mText; \ - PRUint32 mLen; \ -}; \ -NS_IMPL_ISUPPORTS1( name , nsIBreakState) - -#endif /* nsIBreakState_h__ */ diff --git a/mozilla/intl/lwbrk/public/nsILineBreaker.h b/mozilla/intl/lwbrk/public/nsILineBreaker.h index d0a0fac5971..80af60133aa 100644 --- a/mozilla/intl/lwbrk/public/nsILineBreaker.h +++ b/mozilla/intl/lwbrk/public/nsILineBreaker.h @@ -37,12 +37,12 @@ #ifndef nsILineBreaker_h__ #define nsILineBreaker_h__ - #include "nsISupports.h" -#include "nsIBreakState.h" #include "nscore.h" +#define NS_LINEBREAKER_NEED_MORE_TEXT -1 + // {E86B3375-BF89-11d2-B3AF-00805F8A6670} #define NS_ILINEBREAKER_IID \ { 0xe86b3375, 0xbf89, 0x11d2, \ @@ -53,15 +53,15 @@ class nsILineBreaker : public nsISupports { public: NS_DEFINE_STATIC_IID_ACCESSOR(NS_ILINEBREAKER_IID) - NS_IMETHOD BreakInBetween(const PRUnichar* aText1 , PRUint32 aTextLen1, - const PRUnichar* aText2 , PRUint32 aTextLen2, - PRBool *oCanBreak) = 0; + virtual PRBool BreakInBetween( const PRUnichar* aText1 , PRUint32 aTextLen1, + const PRUnichar* aText2 , + PRUint32 aTextLen2) = 0; - NS_IMETHOD Next( const PRUnichar* aText, PRUint32 aLen, PRUint32 aPos, - PRUint32* oNext, PRBool *oNeedMoreText) = 0; + virtual PRInt32 Next( const PRUnichar* aText, PRUint32 aLen, + PRUint32 aPos) = 0; - NS_IMETHOD Prev( const PRUnichar* aText, PRUint32 aLen, PRUint32 aPos, - PRUint32* oPrev, PRBool *oNeedMoreText) = 0; + virtual PRInt32 Prev( const PRUnichar* aText, PRUint32 aLen, + PRUint32 aPos) = 0; }; diff --git a/mozilla/intl/lwbrk/public/nsILineBreakerFactory.h b/mozilla/intl/lwbrk/public/nsILineBreakerFactory.h index feb43ca163b..e69de29bb2d 100644 --- a/mozilla/intl/lwbrk/public/nsILineBreakerFactory.h +++ b/mozilla/intl/lwbrk/public/nsILineBreakerFactory.h @@ -1,62 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ -#ifndef nsILineBreakerFactory_h__ -#define nsILineBreakerFactory_h__ - - -#include "nsISupports.h" -#include "nsILineBreaker.h" -#include "nsString.h" - -#include "nscore.h" - - -// {E86B3377-BF89-11d2-B3AF-00805F8A6670} -#define NS_ILINEBREAKERFACTORY_IID \ -{ 0xe86b3377, 0xbf89, 0x11d2, \ - { 0xb3, 0xaf, 0x0, 0x80, 0x5f, 0x8a, 0x66, 0x70 } } - -class nsILineBreakerFactory : public nsISupports -{ -public: - - NS_DEFINE_STATIC_IID_ACCESSOR(NS_ILINEBREAKERFACTORY_IID) - NS_IMETHOD GetBreaker(const nsAString& aParam, nsILineBreaker** breaker) = 0; -}; - - -#endif /* nsILineBreakerFactory_h__ */ diff --git a/mozilla/intl/lwbrk/public/nsILinearIterator.h b/mozilla/intl/lwbrk/public/nsILinearIterator.h index 50250023219..e69de29bb2d 100644 --- a/mozilla/intl/lwbrk/public/nsILinearIterator.h +++ b/mozilla/intl/lwbrk/public/nsILinearIterator.h @@ -1,63 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ -#ifndef nsILinearIterator_h__ -#define nsILinearIterator_h__ - - -#include "nsISupports.h" -#include "nscore.h" - -// {E86B3378-BF89-11d2-B3AF-00805F8A6670} -#define NS_ILINEARITERATOR_IID \ -{ 0xe86b3378, 0xbf89, 0x11d2, \ - { 0xb3, 0xaf, 0x0, 0x80, 0x5f, 0x8a, 0x66, 0x70 } }; - - -class nsILinearIterator : public nsISupports { - -public: - - NS_DEFINE_STATIC_IID_ACCESSOR(NS_ILINEARITERATOR_IID) - - NS_IMETHOD First() = 0; - NS_IMETHOD Next() = 0; - NS_IMETHOD Current(PRUint32 *oPosition) = 0; - NS_IMETHOD IsDone(PRBool *oResult) = 0; - -}; - -#endif /* nsILinearIterator_h__ */ diff --git a/mozilla/intl/lwbrk/public/nsIWordBreaker.h b/mozilla/intl/lwbrk/public/nsIWordBreaker.h index d9ed37976fb..0ab9ee99f16 100644 --- a/mozilla/intl/lwbrk/public/nsIWordBreaker.h +++ b/mozilla/intl/lwbrk/public/nsIWordBreaker.h @@ -37,35 +37,37 @@ #ifndef nsIWordBreaker_h__ #define nsIWordBreaker_h__ - #include "nsISupports.h" -#include "nsIBreakState.h" #include "nscore.h" +#define NS_WORDBREAKER_NEED_MORE_TEXT -1 + // {E86B3379-BF89-11d2-B3AF-00805F8A6670} #define NS_IWORDBREAKER_IID \ { 0xe86b3379, 0xbf89, 0x11d2, \ { 0xb3, 0xaf, 0x0, 0x80, 0x5f, 0x8a, 0x66, 0x70 } } +typedef struct { + PRUint32 mBegin; + PRUint32 mEnd; +} nsWordRange; class nsIWordBreaker : public nsISupports { public: NS_DEFINE_STATIC_IID_ACCESSOR(NS_IWORDBREAKER_IID) - NS_IMETHOD BreakInBetween(const PRUnichar* aText1 , PRUint32 aTextLen1, - const PRUnichar* aText2 , PRUint32 aTextLen2, - PRBool *oCanBreak) = 0; - NS_IMETHOD FindWord(const PRUnichar* aText1 , PRUint32 aTextLen1, - PRUint32 aOffset, - PRUint32 *oWordBegin, - PRUint32 *oWordEnd) = 0; - NS_IMETHOD NextWord(const PRUnichar* aText, PRUint32 aLen, PRUint32 aPos, - PRUint32* oNext, PRBool *oNeedMoreText) = 0; - - NS_IMETHOD PrevWord(const PRUnichar* aText, PRUint32 aLen, PRUint32 aPos, - PRUint32* oPrev, PRBool *oNeedMoreText) = 0; + virtual PRBool BreakInBetween(const PRUnichar* aText1 , PRUint32 aTextLen1, + const PRUnichar* aText2 , + PRUint32 aTextLen2) = 0; + virtual nsWordRange FindWord(const PRUnichar* aText1 , PRUint32 aTextLen1, + PRUint32 aOffset) = 0; + virtual PRInt32 NextWord(const PRUnichar* aText, PRUint32 aLen, + PRUint32 aPos) = 0; + + virtual PRInt32 PrevWord(const PRUnichar* aText, PRUint32 aLen, + PRUint32 aPos) = 0; }; diff --git a/mozilla/intl/lwbrk/public/nsIWordBreakerFactory.h b/mozilla/intl/lwbrk/public/nsIWordBreakerFactory.h index a22a1efd143..e69de29bb2d 100644 --- a/mozilla/intl/lwbrk/public/nsIWordBreakerFactory.h +++ b/mozilla/intl/lwbrk/public/nsIWordBreakerFactory.h @@ -1,62 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ -#ifndef nsIWordBreakerFactory_h__ -#define nsIWordBreakerFactory_h__ - - -#include "nsISupports.h" -#include "nsIWordBreaker.h" -#include "nsString.h" - -#include "nscore.h" - -// {E86B337A-BF89-11d2-B3AF-00805F8A6670} -#define NS_IWORDBREAKERFACTORY_IID \ -{ 0xe86b337a, 0xbf89, 0x11d2, \ - { 0xb3, 0xaf, 0x0, 0x80, 0x5f, 0x8a, 0x66, 0x70 } } - - -class nsIWordBreakerFactory : public nsISupports -{ -public: - - NS_DEFINE_STATIC_IID_ACCESSOR(NS_IWORDBREAKERFACTORY_IID) - NS_IMETHOD GetBreaker(const nsAString& aParam, nsIWordBreaker** breaker) = 0; -}; - - -#endif /* nsIWordBreakerFactory_h__ */ diff --git a/mozilla/intl/lwbrk/public/nsLWBrkCIID.h b/mozilla/intl/lwbrk/public/nsLWBrkCIID.h index 85cbdbff588..d19caf23ade 100644 --- a/mozilla/intl/lwbrk/public/nsLWBrkCIID.h +++ b/mozilla/intl/lwbrk/public/nsLWBrkCIID.h @@ -37,11 +37,18 @@ #ifndef nsLWBrkCIID_h__ #define nsLWBrkCIID_h__ -// {E86B337B-BF89-11d2-B3AF-00805F8A6670} -#define NS_LWBRK_CID \ -{ 0xe86b337b, 0xbf89, 0x11d2, \ - { 0xb3, 0xaf, 0x0, 0x80, 0x5f, 0x8a, 0x66, 0x70 } } +// {2BF64764-997F-450D-AF96-3028D1A902B0} +#define NS_LBRK_CID \ +{ 0x2bf64764, 0x997f, 0x450d, \ + { 0xaf, 0x96, 0x30, 0x28, 0xd1, 0xa9, 0x2, 0xb0 } } -#define NS_LWBRK_CONTRACTID "@mozilla.org/intl/lwbrk;1" +#define NS_LBRK_CONTRACTID "@mozilla.org/intl/lbrk;1" + +// {2BF64765-997F-450D-AF96-3028D1A902B0} +#define NS_WBRK_CID \ +{ 0x2bf64765, 0x997f, 0x450d, \ + { 0xaf, 0x96, 0x30, 0x28, 0xd1, 0xa9, 0x2, 0xb0 } } + +#define NS_WBRK_CONTRACTID "@mozilla.org/intl/wbrk;1" #endif diff --git a/mozilla/intl/lwbrk/src/Makefile.in b/mozilla/intl/lwbrk/src/Makefile.in index 2354d5883dc..1e2106e11d6 100644 --- a/mozilla/intl/lwbrk/src/Makefile.in +++ b/mozilla/intl/lwbrk/src/Makefile.in @@ -56,7 +56,6 @@ CSRCS = rulebrk.c CPPSRCS = \ nsJISx4501LineBreaker.cpp \ - nsLWBreakerFImp.cpp \ nsSampleWordBreaker.cpp \ nsSemanticUnitScanner.cpp \ $(NULL) diff --git a/mozilla/intl/lwbrk/src/nsJISx4501LineBreaker.cpp b/mozilla/intl/lwbrk/src/nsJISx4501LineBreaker.cpp index fb9ec704e08..15cf6505d10 100644 --- a/mozilla/intl/lwbrk/src/nsJISx4501LineBreaker.cpp +++ b/mozilla/intl/lwbrk/src/nsJISx4501LineBreaker.cpp @@ -39,8 +39,6 @@ #include "nsJISx4501LineBreaker.h" - - #include "pratom.h" #include "nsLWBRKDll.h" #include "jisx4501class.h" @@ -342,11 +340,7 @@ PRBool nsJISx4051LineBreaker::GetPair(PRInt8 c1, PRInt8 c2) return (0 == ((gPair[c1] >> c2 ) & 0x0001)); } - -nsJISx4051LineBreaker::nsJISx4051LineBreaker( - const PRUnichar* aNoBegin, PRInt32 aNoBeginLen, - const PRUnichar* aNoEnd, PRInt32 aNoEndLen -) +nsJISx4051LineBreaker::nsJISx4051LineBreaker() { } @@ -403,20 +397,15 @@ PRInt8 nsJISx4051LineBreaker::ContextualAnalysis( } -NS_IMETHODIMP nsJISx4051LineBreaker::BreakInBetween( +PRBool nsJISx4051LineBreaker::BreakInBetween( const PRUnichar* aText1 , PRUint32 aTextLen1, - const PRUnichar* aText2 , PRUint32 aTextLen2, - PRBool *oCanBreak) + const PRUnichar* aText2 , PRUint32 aTextLen2) { - NS_ENSURE_TRUE(aText1, NS_ERROR_NULL_POINTER); - NS_ENSURE_TRUE(aText2, NS_ERROR_NULL_POINTER); - - if((0 == aTextLen1) || (0==aTextLen2) || + if(!aText1 || !aText2 || (0 == aTextLen1) || (0==aTextLen2) || IS_HIGH_SURROGATE(aText1[aTextLen1-1]) && IS_LOW_SURROGATE(aText2[0]) ) //Do not separate a surrogate pair { - *oCanBreak = PR_FALSE; - return NS_OK; + return PR_FALSE; } //search for CJK characters until a space is found. @@ -440,8 +429,7 @@ NS_IMETHODIMP nsJISx4051LineBreaker::BreakInBetween( } //now apply western rule. - *oCanBreak = IS_SPACE(aText1[aTextLen1-1]) || IS_SPACE(aText2[0]); - return NS_OK; + return IS_SPACE(aText1[aTextLen1-1]) || IS_SPACE(aText2[0]); ROUTE_CJK_BETWEEN: @@ -463,24 +451,20 @@ ROUTE_CJK_BETWEEN: /* Handle cases for THAI */ if((CLASS_THAI == c1) && (CLASS_THAI == c2)) { - *oCanBreak = (0 == TrbWordBreakPos(aText1, aTextLen1, aText2, aTextLen2)); + return (0 == TrbWordBreakPos(aText1, aTextLen1, aText2, aTextLen2)); } else { - *oCanBreak = GetPair(c1,c2); + return GetPair(c1,c2); } - return NS_OK; } -NS_IMETHODIMP nsJISx4051LineBreaker::Next( - const PRUnichar* aText, PRUint32 aLen, PRUint32 aPos, - PRUint32* oNext, PRBool *oNeedMoreText) +PRInt32 nsJISx4051LineBreaker::Next( + const PRUnichar* aText, PRUint32 aLen, PRUint32 aPos) { - NS_ENSURE_TRUE(aText, NS_ERROR_NULL_POINTER); - NS_ENSURE_TRUE(oNext, NS_ERROR_NULL_POINTER); - NS_ENSURE_TRUE(oNeedMoreText, NS_ERROR_NULL_POINTER); - NS_ENSURE_TRUE(aPos <= aLen, NS_ERROR_ILLEGAL_VALUE); + NS_ASSERTION(aText, "aText shouldn't be null"); + NS_ASSERTION(aLen > aPos, "Illegal value (length > position)"); //forward check for CJK characters until a space is found. //if CJK char is found before space, use 4051, otherwise western @@ -488,17 +472,11 @@ NS_IMETHODIMP nsJISx4051LineBreaker::Next( for (cur = aPos; cur < aLen; ++cur) { if (IS_SPACE(aText[cur])) - { - *oNext = cur; - *oNeedMoreText = PR_FALSE; - return NS_OK; - } + return cur; if (IS_CJK_CHAR(aText[cur])) goto ROUTE_CJK_NEXT; } - *oNext = aLen; - *oNeedMoreText = PR_TRUE; - return NS_OK; + return NS_LINEBREAKER_NEED_MORE_TEXT; // Need more text ROUTE_CJK_NEXT: PRInt8 c1, c2; @@ -513,11 +491,7 @@ ROUTE_CJK_NEXT: } if(CLASS_THAI == c1) - { - *oNext = PRUint32(TrbFollowing(aText, aLen, aPos)); - *oNeedMoreText = PR_FALSE; - return NS_OK; - } + return PRUint32(TrbFollowing(aText, aLen, aPos)); for(cur++; cur GetClass(aText1[aTextLen1-1]) != this->GetClass(aText2[0])); - - return NS_OK; + return (this->GetClass(aText1[aTextLen1-1]) != this->GetClass(aText2[0])); } @@ -119,45 +110,41 @@ PRUint8 nsSampleWordBreaker::GetClass(PRUnichar c) return 0; } -nsresult nsSampleWordBreaker::FindWord( +nsWordRange nsSampleWordBreaker::FindWord( const PRUnichar* aText , PRUint32 aTextLen, - PRUint32 aOffset, - PRUint32 *oWordBegin, - PRUint32 *oWordEnd) + PRUint32 aOffset) { + nsWordRange range; NS_PRECONDITION( nsnull != aText, "null ptr"); NS_PRECONDITION( 0 != aTextLen, "len = 0"); - NS_PRECONDITION( nsnull != oWordBegin, "null ptr"); - NS_PRECONDITION( nsnull != oWordEnd, "null ptr"); NS_PRECONDITION( aOffset <= aTextLen, "aOffset > aTextLen"); - if((nsnull == aText ) || (nsnull == oWordBegin) || (nsnull == oWordEnd)) - return NS_ERROR_NULL_POINTER; - - if( aOffset > aTextLen ) - return NS_ERROR_ILLEGAL_VALUE; + range.mBegin = aTextLen + 1; + range.mEnd = aTextLen + 1; + if(!aText || aOffset > aTextLen) + return range; PRUint8 c = this->GetClass(aText[aOffset]); PRUint32 i; // Scan forward - *oWordEnd = aTextLen; + range.mEnd--; for(i = aOffset +1;i <= aTextLen; i++) { if( c != this->GetClass(aText[i])) { - *oWordEnd = i; + range.mEnd = i; break; } } // Scan backward - *oWordBegin = 0; + range.mBegin = 0; for(i = aOffset ;i > 0; i--) { if( c != this->GetClass(aText[i-1])) { - *oWordBegin = i; + range.mBegin = i; break; } } @@ -166,12 +153,11 @@ nsresult nsSampleWordBreaker::FindWord( // need to call Thai word breaker from here // we should pass the whole Thai segment to the thai word breaker to find a shorter answer } - return NS_OK; + return range; } -nsresult nsSampleWordBreaker::NextWord( - const PRUnichar* aText, PRUint32 aLen, PRUint32 aPos, - PRUint32* oNext, PRBool *oNeedMoreText) +PRInt32 nsSampleWordBreaker::NextWord( + const PRUnichar* aText, PRUint32 aLen, PRUint32 aPos) { PRInt8 c1, c2; PRUint32 cur = aPos; @@ -188,13 +174,13 @@ nsresult nsSampleWordBreaker::NextWord( // need to call Thai word breaker from here // we should pass the whole Thai segment to the thai word breaker to find a shorter answer } - *oNext = cur; - *oNeedMoreText = (cur == aLen) ? PR_TRUE : PR_FALSE; - return NS_OK; + if (cur == aLen) + return NS_WORDBREAKER_NEED_MORE_TEXT; + return cur; } -nsresult nsSampleWordBreaker::PrevWord(const PRUnichar* aText, PRUint32 aLen, PRUint32 aPos, - PRUint32* oPrev, PRBool *oNeedMoreText) +PRInt32 nsSampleWordBreaker::PrevWord( + const PRUnichar* aText, PRUint32 aLen, PRUint32 aPos) { PRInt8 c1, c2; PRUint32 cur = aPos; @@ -211,7 +197,7 @@ nsresult nsSampleWordBreaker::PrevWord(const PRUnichar* aText, PRUint32 aLen, PR // need to call Thai word breaker from here // we should pass the whole Thai segment to the thai word breaker to find a shorter answer } - *oPrev = cur; - *oNeedMoreText = (cur == 0) ? PR_TRUE : PR_FALSE; - return NS_OK; + if (!cur) + return NS_WORDBREAKER_NEED_MORE_TEXT; + return cur; } diff --git a/mozilla/intl/lwbrk/src/nsSampleWordBreaker.h b/mozilla/intl/lwbrk/src/nsSampleWordBreaker.h index 6083a3b4981..99674b0e039 100644 --- a/mozilla/intl/lwbrk/src/nsSampleWordBreaker.h +++ b/mozilla/intl/lwbrk/src/nsSampleWordBreaker.h @@ -59,19 +59,14 @@ public: nsSampleWordBreaker() ; virtual ~nsSampleWordBreaker() ; - NS_IMETHOD BreakInBetween(const PRUnichar* aText1 , PRUint32 aTextLen1, - const PRUnichar* aText2 , PRUint32 aTextLen2, - PRBool *oCanBreak); - NS_IMETHOD FindWord(const PRUnichar* aText1 , PRUint32 aTextLen1, - PRUint32 aOffset, - PRUint32 *oWordBegin, - PRUint32 *oWordEnd); + PRBool BreakInBetween(const PRUnichar* aText1 , PRUint32 aTextLen1, + const PRUnichar* aText2 , PRUint32 aTextLen2); + nsWordRange FindWord(const PRUnichar* aText1 , PRUint32 aTextLen1, + PRUint32 aOffset); - NS_IMETHOD NextWord(const PRUnichar* aText, PRUint32 aLen, PRUint32 aPos, - PRUint32* oNext, PRBool *oNeedMoreText); + PRInt32 NextWord(const PRUnichar* aText, PRUint32 aLen, PRUint32 aPos); - NS_IMETHOD PrevWord(const PRUnichar* aText, PRUint32 aLen, PRUint32 aPos, - PRUint32* oPrev, PRBool *oNeedMoreText); + PRInt32 PrevWord(const PRUnichar* aText, PRUint32 aLen, PRUint32 aPos); protected: PRUint8 GetClass(PRUnichar aChar); diff --git a/mozilla/intl/lwbrk/src/nsSemanticUnitScanner.cpp b/mozilla/intl/lwbrk/src/nsSemanticUnitScanner.cpp index cb47edfe671..4ef15ae816b 100644 --- a/mozilla/intl/lwbrk/src/nsSemanticUnitScanner.cpp +++ b/mozilla/intl/lwbrk/src/nsSemanticUnitScanner.cpp @@ -83,18 +83,12 @@ NS_IMETHODIMP nsSemanticUnitScanner::Next(const PRUnichar *text, PRInt32 length, return NS_OK; } - PRUint32 next; - PRBool needMoreText; + PRInt32 next; // find the next "word" - nsresult res = NextWord(text, (PRUint32) length, (PRUint32) pos, - &next, &needMoreText); - - NS_ASSERTION(NS_SUCCEEDED(res), "nsSampleWordBreaker::Next failed"); - if (NS_FAILED(res)) - return res; + next = NextWord(text, (PRUint32) length, (PRUint32) pos); // if we don't have enough text to make decision, return - if (needMoreText) { + if (next == NS_WORDBREAKER_NEED_MORE_TEXT) { *begin = pos; *end = isLastBuffer ? length : pos; *_retval = isLastBuffer; diff --git a/mozilla/intl/lwbrk/tests/TestLineBreak.cpp b/mozilla/intl/lwbrk/tests/TestLineBreak.cpp index dcd4c97395f..174781c02cf 100644 --- a/mozilla/intl/lwbrk/tests/TestLineBreak.cpp +++ b/mozilla/intl/lwbrk/tests/TestLineBreak.cpp @@ -39,19 +39,16 @@ #include "nsIComponentManager.h" #include "nsISupports.h" #include "nsServiceManagerUtils.h" -#include "nsILineBreakerFactory.h" #include "nsILineBreaker.h" -#include "nsIWordBreakerFactory.h" #include "nsIWordBreaker.h" -#include "nsIBreakState.h" #include "nsLWBrkCIID.h" #include "nsReadableUtils.h" +#include "nsString.h" #define WORK_AROUND_SERVICE_MANAGER_ASSERT -IMPL_NS_IBREAKSTATE( nsBreakState ) - -NS_DEFINE_CID(kLWBrkCID, NS_LWBRK_CID); +NS_DEFINE_CID(kLBrkCID, NS_LBRK_CID); +NS_DEFINE_CID(kWBrkCID, NS_WBRK_CID); static char teng1[] = @@ -106,20 +103,18 @@ PRBool TestASCIILB(nsILineBreaker *lb, PRUint32 i,j; PRUint32 res[256]; PRBool ok = PR_TRUE; - PRUint32 curr; - PRBool finishThisFrag = PR_FALSE; - for(i = 0, curr = 0; ((! finishThisFrag) && (i < 256)); i++) + PRInt32 curr; + for(i = 0, curr = 0; (curr != NS_LINEBREAKER_NEED_MORE_TEXT) && + (i < 256); i++) { - lb->Next(eng1.get(), eng1.Length(), curr, - &curr, - &finishThisFrag); - res [i] = curr; + curr = lb->Next(eng1.get(), eng1.Length(), curr); + res [i] = curr != NS_LINEBREAKER_NEED_MORE_TEXT ? curr : eng1.Length(); } if (i != outlen) { ok = PR_FALSE; - printf("WARNING!!! return size wrong, expect %d bet got %d \n", + printf("WARNING!!! return size wrong, expect %d but got %d \n", outlen, i); } printf("string = \n%s\n", in); @@ -158,24 +153,22 @@ PRBool TestASCIIWB(nsIWordBreaker *lb, const PRUint32* out, PRUint32 outlen) { nsAutoString eng1; eng1.AssignWithConversion(in); - // nsBreakState bk(eng1.get(), eng1.Length()); PRUint32 i,j; PRUint32 res[256]; PRBool ok = PR_TRUE; - PRBool done; - PRUint32 curr =0; + PRInt32 curr = 0; - for(i = 0, lb->NextWord(eng1.get(), eng1.Length(), curr, &curr, &done); - (! done ) && (i < 256); - lb->NextWord(eng1.get(), eng1.Length(), curr, &curr, &done), i++) + for(i = 0, curr = lb->NextWord(eng1.get(), eng1.Length(), curr); + (curr != NS_WORDBREAKER_NEED_MORE_TEXT) && (i < 256); + curr = lb->NextWord(eng1.get(), eng1.Length(), curr), i++) { - res [i] = curr; + res [i] = curr != NS_WORDBREAKER_NEED_MORE_TEXT ? curr : eng1.Length(); } if (i != outlen) { ok = PR_FALSE; - printf("WARNING!!! return size wrong, expect %d bet got %d\n", + printf("WARNING!!! return size wrong, expect %d but got %d\n", outlen, i); } printf("string = \n%s\n", in); @@ -212,95 +205,79 @@ PRBool TestASCIIWB(nsIWordBreaker *lb, PRBool TestLineBreaker() { - printf("==================================\n"); - printf("Finish nsILineBreakerFactory Test \n"); - printf("==================================\n"); - nsILineBreakerFactory *t = NULL; + printf("===========================\n"); + printf("Finish nsILineBreaker Test \n"); + printf("===========================\n"); + nsILineBreaker *t = NULL; nsresult res; PRBool ok = PR_TRUE; - res = CallGetService(kLWBrkCID, &t); + res = CallGetService(kLBrkCID, &t); printf("Test 1 - GetService():\n"); if(NS_FAILED(res) || ( t == NULL ) ) { printf("\t1st GetService failed\n"); ok = PR_FALSE; - } else { -#ifdef WORD_AROUND_SERVICE_MANAGER_ASSERT - NS_RELEASE(t); -#endif } - res = CallGetService(kLWBrkCID, &t); - + NS_IF_RELEASE(t); + + res = CallGetService(kLBrkCID, &t); + if(NS_FAILED(res) || ( t == NULL ) ) { printf("\t2nd GetService failed\n"); ok = PR_FALSE; } else { - - printf("Test 3 - GetLineBreaker():\n"); - nsILineBreaker *lb; - - nsAutoString lb_arg; - res = t->GetBreaker(lb_arg, &lb); - if(NS_FAILED(res) || (lb == NULL)) { - printf("GetBreaker(nsILineBreaker*) failed\n"); - ok = PR_FALSE; + printf("Test 4 - {First,Next}ForwardBreak():\n"); + if( TestASCIILB(t, teng1, sizeof(teng1)/sizeof(char), + exp1, sizeof(exp1)/sizeof(PRUint32)) ) + { + printf("Test 4 Passed\n\n"); } else { - - printf("Test 4 - {First,Next}ForwardBreak():\n"); - if( TestASCIILB(lb, teng1, sizeof(teng1)/sizeof(char), - exp1, sizeof(exp1)/sizeof(PRUint32)) ) - { - printf("Test 4 Passed\n\n"); - } else { - ok = PR_FALSE; - printf("Test 4 Failed\n\n"); - } - - printf("Test 5 - {First,Next}ForwardBreak():\n"); - if(TestASCIILB(lb, teng2, sizeof(teng2)/sizeof(char), - lexp2, sizeof(lexp2)/sizeof(PRUint32)) ) - { - printf("Test 5 Passed\n\n"); - } else { - ok = PR_FALSE; - printf("Test 5 Failed\n\n"); - } - - printf("Test 6 - {First,Next}ForwardBreak():\n"); - if(TestASCIILB(lb, teng3, sizeof(teng3)/sizeof(char), - exp3, sizeof(exp3)/sizeof(PRUint32)) ) - { - printf("Test 6 Passed\n\n"); - } else { - ok = PR_FALSE; - printf("Test 6 Failed\n\n"); - } - - - NS_IF_RELEASE(lb); + ok = PR_FALSE; + printf("Test 4 Failed\n\n"); } -#ifdef WORD_AROUND_SERVICE_MANAGER_ASSERT - NS_RELEASE(t); -#endif - } - printf("==================================\n"); - printf("Finish nsILineBreakerFactory Test \n"); - printf("==================================\n"); + printf("Test 5 - {First,Next}ForwardBreak():\n"); + if(TestASCIILB(t, teng2, sizeof(teng2)/sizeof(char), + lexp2, sizeof(lexp2)/sizeof(PRUint32)) ) + { + printf("Test 5 Passed\n\n"); + } else { + ok = PR_FALSE; + printf("Test 5 Failed\n\n"); + } - return ok; + printf("Test 6 - {First,Next}ForwardBreak():\n"); + if(TestASCIILB(t, teng3, sizeof(teng3)/sizeof(char), + exp3, sizeof(exp3)/sizeof(PRUint32)) ) + { + printf("Test 6 Passed\n\n"); + } else { + ok = PR_FALSE; + printf("Test 6 Failed\n\n"); + } + + + NS_RELEASE(t); + + } + + printf("===========================\n"); + printf("Finish nsILineBreaker Test \n"); + printf("===========================\n"); + + return ok; } PRBool TestWordBreaker() { - printf("==================================\n"); - printf("Finish nsIWordBreakerFactory Test \n"); - printf("==================================\n"); - nsIWordBreakerFactory *t = NULL; + printf("===========================\n"); + printf("Finish nsIWordBreaker Test \n"); + printf("===========================\n"); + nsIWordBreaker *t = NULL; nsresult res; PRBool ok = PR_TRUE; - res = CallGetService(kLWBrkCID, &t); + res = CallGetService(kWBrkCID, &t); printf("Test 1 - GetService():\n"); if(NS_FAILED(res) || ( t == NULL ) ) { @@ -310,62 +287,50 @@ PRBool TestWordBreaker() NS_RELEASE(t); } - res = CallGetService(kLWBrkCID, &t); + res = CallGetService(kWBrkCID, &t); if(NS_FAILED(res) || ( t == NULL ) ) { printf("\t2nd GetService failed\n"); ok = PR_FALSE; } else { - printf("Test 3 - GetWordBreaker():\n"); - nsIWordBreaker *lb; - - nsAutoString lb_arg; - res = t->GetBreaker(lb_arg, &lb); - if(NS_FAILED(res) || (lb == NULL)) { - printf("GetBreaker(nsIWordBreaker*) failed\n"); - ok = PR_FALSE; + printf("Test 4 - {First,Next}ForwardBreak():\n"); + if( TestASCIIWB(t, teng1, sizeof(teng1)/sizeof(char), + wexp1, sizeof(wexp1)/sizeof(PRUint32)) ) + { + printf("Test 4 Passed\n\n"); } else { - - printf("Test 4 - {First,Next}ForwardBreak():\n"); - if( TestASCIIWB(lb, teng1, sizeof(teng1)/sizeof(char), - wexp1, sizeof(wexp1)/sizeof(PRUint32)) ) - { - printf("Test 4 Passed\n\n"); - } else { - ok = PR_FALSE; - printf("Test 4 Failed\n\n"); - } - - printf("Test 5 - {First,Next}ForwardBreak():\n"); - if(TestASCIIWB(lb, teng2, sizeof(teng2)/sizeof(char), - wexp2, sizeof(wexp2)/sizeof(PRUint32)) ) - { - printf("Test 5 Passed\n\n"); - } else { - ok = PR_FALSE; - printf("Test 5 Failed\n\n"); - } - - printf("Test 6 - {First,Next}ForwardBreak():\n"); - if(TestASCIIWB(lb, teng3, sizeof(teng3)/sizeof(char), - wexp3, sizeof(wexp3)/sizeof(PRUint32)) ) - { - printf("Test 6 Passed\n\n"); - } else { - ok = PR_FALSE; - printf("Test 6 Failed\n\n"); - } - - - NS_IF_RELEASE(lb); + ok = PR_FALSE; + printf("Test 4 Failed\n\n"); } + printf("Test 5 - {First,Next}ForwardBreak():\n"); + if(TestASCIIWB(t, teng2, sizeof(teng2)/sizeof(char), + wexp2, sizeof(wexp2)/sizeof(PRUint32)) ) + { + printf("Test 5 Passed\n\n"); + } else { + ok = PR_FALSE; + printf("Test 5 Failed\n\n"); + } + + printf("Test 6 - {First,Next}ForwardBreak():\n"); + if(TestASCIIWB(t, teng3, sizeof(teng3)/sizeof(char), + wexp3, sizeof(wexp3)/sizeof(PRUint32)) ) + { + printf("Test 6 Passed\n\n"); + } else { + ok = PR_FALSE; + printf("Test 6 Failed\n\n"); + } + + NS_RELEASE(t); } - printf("==================================\n"); - printf("Finish nsIWordBreakerFactory Test \n"); - printf("==================================\n"); + + printf("===========================\n"); + printf("Finish nsIWordBreaker Test \n"); + printf("===========================\n"); return ok; } @@ -401,13 +366,9 @@ void SampleWordBreakUsage() void SamplePrintWordWithBreak() { PRUint32 numOfFragment = sizeof(wb) / sizeof(char*); - nsIWordBreakerFactory *t = NULL; + nsIWordBreaker *wbk = NULL; - nsresult res = CallGetService(kLWBrkCID, &t); - nsIWordBreaker *wbk; - - nsAutoString wb_arg; - res = t->GetBreaker(wb_arg, &wbk); + CallGetService(kWBrkCID, &wbk); nsAutoString result; nsAutoString tmp; @@ -415,20 +376,18 @@ void SamplePrintWordWithBreak() for(PRUint32 i = 0; i < numOfFragment; i++) { nsAutoString fragText; fragText.AssignWithConversion(wb[i]); - // nsBreakState bk(fragText.get(), fragText.Length()); - PRUint32 cur = 0; - PRBool done; - res = wbk->NextWord(fragText.get(), fragText.Length(), cur, &cur, &done); + PRInt32 cur = 0; + cur = wbk->NextWord(fragText.get(), fragText.Length(), cur); PRUint32 start = 0; - for(PRUint32 j = 0; ! done ; j++) + for(PRUint32 j = 0; cur != NS_WORDBREAKER_NEED_MORE_TEXT ; j++) { tmp.Truncate(); fragText.Mid(tmp, start, cur - start); result.Append(tmp); result.AppendLiteral("^"); - start = cur; - wbk->NextWord(fragText.get(), fragText.Length(), cur, &cur, &done); + start = (cur >= 0 ? cur : cur - start); + cur = wbk->NextWord(fragText.get(), fragText.Length(), cur); } tmp.Truncate(); @@ -441,12 +400,10 @@ void SamplePrintWordWithBreak() nsAutoString nextFragText; nextFragText.AssignWithConversion(wb[i+1]); PRBool canBreak = PR_TRUE; - res = wbk->BreakInBetween( fragText.get(), - fragText.Length(), - nextFragText.get(), - nextFragText.Length(), - &canBreak - ); + canBreak = wbk->BreakInBetween( fragText.get(), + fragText.Length(), + nextFragText.get(), + nextFragText.Length()); if(canBreak) result.AppendLiteral("^"); @@ -455,84 +412,73 @@ void SamplePrintWordWithBreak() } printf("Output From SamplePrintWordWithBreak() \n\n"); printf("[%s]\n", NS_LossyConvertUCS2toASCII(result).get()); + + NS_IF_RELEASE(wbk); } void SampleFindWordBreakFromPosition(PRUint32 fragN, PRUint32 offset) { PRUint32 numOfFragment = sizeof(wb) / sizeof(char*); - nsIWordBreakerFactory *t = NULL; - - nsresult res = CallGetService(kLWBrkCID, &t); - nsIWordBreaker *wbk; - - nsAutoString wb_arg; - res = t->GetBreaker(wb_arg, &wbk); + nsIWordBreaker *wbk = NULL; + CallGetService(kWBrkCID, &wbk); nsAutoString fragText; fragText.AssignWithConversion(wb[fragN]); - PRUint32 begin, end; - - nsAutoString result; - res = wbk->FindWord(fragText.get(), fragText.Length(), - offset, &begin, &end); + nsWordRange res = wbk->FindWord(fragText.get(), fragText.Length(), offset); - PRBool canbreak; - fragText.Mid(result, begin, end-begin); + PRBool canBreak; + fragText.Mid(result, res.mBegin, res.mEnd-res.mBegin); - if((PRUint32)fragText.Length() == end) // if we hit the end of the fragment + if((PRUint32)fragText.Length() == res.mEnd) // if we hit the end of the fragment { nsAutoString curFragText = fragText; for(PRUint32 p = fragN +1; p < numOfFragment ;p++) { - nsAutoString nextFragText; nextFragText.AssignWithConversion(wb[p]); - res = wbk->BreakInBetween(curFragText.get(), - curFragText.Length(), - nextFragText.get(), - nextFragText.Length(), - &canbreak); - if(canbreak) + nsAutoString nextFragText; nextFragText.AssignWithConversion(wb[p]); + canBreak = wbk->BreakInBetween(curFragText.get(), + curFragText.Length(), + nextFragText.get(), + nextFragText.Length()); + if(canBreak) break; - PRUint32 b, e; - res = wbk->FindWord(nextFragText.get(), nextFragText.Length(), - 0, &b, &e); + nsWordRange r = wbk->FindWord(nextFragText.get(), nextFragText.Length(), + 0); nsAutoString tmp; - nextFragText.Mid(tmp,b,e-b); + nextFragText.Mid(tmp,r.mBegin,r.mEnd-r.mBegin); result.Append(tmp); - if((PRUint32)nextFragText.Length() != e) + if((PRUint32)nextFragText.Length() != r.mEnd) break; nextFragText = curFragText; } } - if(0 == begin) // if we hit the beginning of the fragment + if(0 == res.mBegin) // if we hit the beginning of the fragment { nsAutoString curFragText = fragText; for(PRUint32 p = fragN ; p > 0 ;p--) { nsAutoString prevFragText; prevFragText.AssignWithConversion(wb[p-1]); - res = wbk->BreakInBetween(prevFragText.get(), - prevFragText.Length(), - curFragText.get(), - curFragText.Length(), - &canbreak); - if(canbreak) + canBreak = wbk->BreakInBetween(prevFragText.get(), + prevFragText.Length(), + curFragText.get(), + curFragText.Length()); + if(canBreak) break; - PRUint32 b, e; - res = wbk->FindWord(prevFragText.get(), prevFragText.Length(), - prevFragText.Length(), &b, &e); + nsWordRange r = wbk->FindWord(prevFragText.get(), prevFragText.Length(), + prevFragText.Length()); nsAutoString tmp; - prevFragText.Mid(tmp,b,e-b); + prevFragText.Mid(tmp,r.mBegin,r.mEnd-r.mBegin); result.Insert(tmp,0); - if(0 != b) + if(0 != r.mBegin) break; prevFragText = curFragText; @@ -541,6 +487,8 @@ void SampleFindWordBreakFromPosition(PRUint32 fragN, PRUint32 offset) printf("Output From SamplePrintWordWithBreak() \n\n"); printf("[%s]\n", NS_LossyConvertUCS2toASCII(result).get()); + + NS_IF_RELEASE(wbk); } // Main diff --git a/mozilla/layout/generic/nsTextFrame.cpp b/mozilla/layout/generic/nsTextFrame.cpp index 93b36994a76..13e27412991 100644 --- a/mozilla/layout/generic/nsTextFrame.cpp +++ b/mozilla/layout/generic/nsTextFrame.cpp @@ -70,7 +70,6 @@ #include "nsICaret.h" #include "nsCSSPseudoElements.h" #include "nsILineBreaker.h" -#include "nsIWordBreaker.h" #include "nsCompatibility.h" #include "nsCSSColorUtils.h" @@ -764,7 +763,6 @@ public: nsReflowStatus MeasureText(nsPresContext* aPresContext, const nsHTMLReflowState& aReflowState, nsTextTransformer& aTx, - nsILineBreaker* aLb, TextStyle& aTs, TextReflowData& aTextData); @@ -792,8 +790,7 @@ public: PRBool& aIsPaginated, PRBool& aIsSelected, PRBool& aHideStandardSelection, - PRInt16& aSelectionValue, - nsILineBreaker** aLineBreaker); + PRInt16& aSelectionValue); void PaintUnicodeText(nsPresContext* aPresContext, nsIRenderingContext& aRenderingContext, @@ -808,7 +805,6 @@ public: nscoord dx, nscoord dy); nsTextDimensions ComputeTotalWordDimensions(nsPresContext* aPresContext, - nsILineBreaker* aLineBreaker, nsLineLayout& aLineLayout, const nsHTMLReflowState& aReflowState, nsIFrame* aNextFrame, @@ -819,7 +815,6 @@ public: PRBool aCanBreakBefore); nsTextDimensions ComputeWordFragmentDimensions(nsPresContext* aPresContext, - nsILineBreaker* aLineBreaker, nsLineLayout& aLineLayout, const nsHTMLReflowState& aReflowState, nsIFrame* aNextFrame, @@ -2262,13 +2257,11 @@ nsresult nsTextFrame::GetTextInfoForPainting(nsPresContext* aPresContex PRBool& aIsPaginated, PRBool& aIsSelected, PRBool& aHideStandardSelection, - PRInt16& aSelectionValue, - nsILineBreaker** aLineBreaker) + PRInt16& aSelectionValue) { NS_ENSURE_ARG_POINTER(aPresContext); NS_ENSURE_ARG_POINTER(aPresShell); NS_ENSURE_ARG_POINTER(aSelectionController); - NS_ENSURE_ARG_POINTER(aLineBreaker); //get the presshell NS_IF_ADDREF(*aPresShell = aPresContext->GetPresShell()); @@ -2319,8 +2312,6 @@ nsresult nsTextFrame::GetTextInfoForPainting(nsPresContext* aPresContex if (!doc) return NS_ERROR_FAILURE; - NS_IF_ADDREF(*aLineBreaker = doc->GetLineBreaker()); - aIsSelected = (GetStateBits() & NS_FRAME_SELECTED_CONTENT) == NS_FRAME_SELECTED_CONTENT; return NS_OK; @@ -2337,7 +2328,6 @@ nsTextFrame::IsTextInSelection(nsPresContext* aPresContext, PRBool isSelected; PRBool hideStandardSelection; PRInt16 selectionValue; - nsCOMPtr lb; if (NS_FAILED(GetTextInfoForPainting(aPresContext, aRenderingContext, getter_AddRefs(shell), @@ -2346,8 +2336,7 @@ nsTextFrame::IsTextInSelection(nsPresContext* aPresContext, isPaginated, isSelected, hideStandardSelection, - selectionValue, - getter_AddRefs(lb)))) { + selectionValue))) { return PR_FALSE; } @@ -2365,7 +2354,7 @@ nsTextFrame::IsTextInSelection(nsPresContext* aPresContext, // this and we should just render the text fragment directly. See // PaintAsciiText()... - nsTextTransformer tx(lb, nsnull, aPresContext); + nsTextTransformer tx(aPresContext); PRInt32 textLength; // no need to worry about justification, that's always on the slow path PrepareUnicodeText(tx, &indexBuffer, &paintBuffer, &textLength); @@ -2473,7 +2462,6 @@ nsTextFrame::PaintUnicodeText(nsPresContext* aPresContext, PRBool isSelected; PRBool hideStandardSelection; PRInt16 selectionValue; - nsCOMPtr lb; #ifdef IBMBIDI PRBool isOddLevel = PR_FALSE; #endif @@ -2486,8 +2474,7 @@ nsTextFrame::PaintUnicodeText(nsPresContext* aPresContext, isPaginated, isSelected, hideStandardSelection, - selectionValue, - getter_AddRefs(lb)))) { + selectionValue))) { return; } @@ -2511,7 +2498,7 @@ nsTextFrame::PaintUnicodeText(nsPresContext* aPresContext, // this and we should just render the text fragment directly. See // PaintAsciiText()... - nsTextTransformer tx(lb, nsnull, aPresContext); + nsTextTransformer tx(aPresContext); PRInt32 textLength; // no need to worry about justification, that's always on the slow path PrepareUnicodeText(tx, (displaySelection ? &indexBuffer : nsnull), @@ -2813,7 +2800,7 @@ nsTextFrame::GetPositionSlowly(nsPresContext* aPresContext, } // Transform text from content into renderable form - nsTextTransformer tx(doc->GetLineBreaker(), nsnull, aPresContext); + nsTextTransformer tx(aPresContext); PRInt32 textLength; PRIntn numJustifiableCharacter; @@ -3245,7 +3232,6 @@ nsTextFrame::PaintTextSlowly(nsPresContext* aPresContext, PRBool isSelected; PRBool hideStandardSelection; PRInt16 selectionValue; - nsCOMPtr lb; if (NS_FAILED(GetTextInfoForPainting(aPresContext, aRenderingContext, getter_AddRefs(shell), @@ -3254,8 +3240,7 @@ nsTextFrame::PaintTextSlowly(nsPresContext* aPresContext, isPaginated, isSelected, hideStandardSelection, - selectionValue, - getter_AddRefs(lb)))) { + selectionValue))) { return; } @@ -3273,7 +3258,7 @@ nsTextFrame::PaintTextSlowly(nsPresContext* aPresContext, nscoord width = mRect.width; PRInt32 textLength; - nsTextTransformer tx(lb, nsnull, aPresContext); + nsTextTransformer tx(aPresContext); PRIntn numJustifiableCharacter; PrepareUnicodeText(tx, (displaySelection ? &indexBuffer : nsnull), @@ -3471,7 +3456,6 @@ nsTextFrame::PaintAsciiText(nsPresContext* aPresContext, PRBool isSelected; PRBool hideStandardSelection; PRInt16 selectionValue; - nsCOMPtr lb; if (NS_FAILED(GetTextInfoForPainting(aPresContext, aRenderingContext, getter_AddRefs(shell), @@ -3480,8 +3464,7 @@ nsTextFrame::PaintAsciiText(nsPresContext* aPresContext, isPaginated, isSelected, hideStandardSelection, - selectionValue, - getter_AddRefs(lb)))) { + selectionValue))) { return; } @@ -3509,7 +3492,7 @@ nsTextFrame::PaintAsciiText(nsPresContext* aPresContext, } } - nsTextTransformer tx(lb, nsnull, aPresContext); + nsTextTransformer tx(aPresContext); // See if we need to transform the text. If the text fragment is ascii and // wasn't transformed, then we can skip this step. If we're displaying the @@ -3824,7 +3807,7 @@ nsTextFrame::GetPosition(nsPresContext* aPresContext, // Get the renderable form of the text nsIDocument *doc = GetDocument(aPresContext); - nsTextTransformer tx(doc->GetLineBreaker(), nsnull, aPresContext); + nsTextTransformer tx(aPresContext); PRInt32 textLength; // no need to worry about justification, that's always on the slow path PrepareUnicodeText(tx, &indexBuffer, &paintBuffer, &textLength); @@ -4164,7 +4147,7 @@ nsTextFrame::GetPointFromOffset(nsPresContext* aPresContext, // Transform text from content into renderable form nsIDocument *doc = GetDocument(aPresContext); - nsTextTransformer tx(doc->GetLineBreaker(), nsnull, aPresContext); + nsTextTransformer tx(aPresContext); PRInt32 textLength; PRIntn numJustifiableCharacter; @@ -4448,7 +4431,7 @@ nsTextFrame::PeekOffset(nsPresContext* aPresContext, nsPeekOffsetStruct *aPos) if (!doc) { return NS_OK; } - nsTextTransformer tx(doc->GetLineBreaker(), nsnull, aPresContext); + nsTextTransformer tx(aPresContext); PrepareUnicodeText(tx, &indexBuffer, &paintBuffer, &textLength); if (textLength)//if no renderable length, you cant park here. @@ -4475,7 +4458,7 @@ nsTextFrame::PeekOffset(nsPresContext* aPresContext, nsPeekOffsetStruct *aPos) if (!doc) { return NS_OK; } - nsTextTransformer tx(doc->GetLineBreaker(), nsnull, aPresContext); + nsTextTransformer tx(aPresContext); PrepareUnicodeText(tx, &indexBuffer, &paintBuffer, &textLength); nsIFrame *frameUsed = nsnull; @@ -4637,8 +4620,7 @@ nsTextFrame::PeekOffset(nsPresContext* aPresContext, nsPeekOffsetStruct *aPos) return result; } - nsTextTransformer tx(doc->GetLineBreaker(), - doc->GetWordBreaker(), aPresContext); + nsTextTransformer tx(aPresContext); PrepareUnicodeText(tx, &indexBuffer, &paintBuffer, &textLength); nsIFrame *frameUsed = nsnull; @@ -4891,7 +4873,7 @@ nsTextFrame::CheckVisibility(nsPresContext* aContext, PRInt32 aStartIndex, PRInt if (!doc) return NS_ERROR_FAILURE; //create texttransformer - nsTextTransformer tx(doc->GetLineBreaker(), nsnull, aContext); + nsTextTransformer tx(aContext); //create the buffers nsAutoTextBuffer paintBuffer; nsAutoIndexBuffer indexBuffer; @@ -5055,7 +5037,6 @@ nsReflowStatus nsTextFrame::MeasureText(nsPresContext* aPresContext, const nsHTMLReflowState& aReflowState, nsTextTransformer& aTx, - nsILineBreaker* aLb, TextStyle& aTs, TextReflowData& aTextData) { @@ -5612,7 +5593,7 @@ nsTextFrame::MeasureText(nsPresContext* aPresContext, } } } - nsTextDimensions wordDimensions = ComputeTotalWordDimensions(aPresContext, aLb, + nsTextDimensions wordDimensions = ComputeTotalWordDimensions(aPresContext, lineLayout, aReflowState, next, lastWordDimensions, @@ -5814,8 +5795,7 @@ nsTextFrame::Reflow(nsPresContext* aPresContext, (0 != ts.mWordSpacing) || (0 != ts.mLetterSpacing) || ts.mJustifying); - nsILineBreaker *lb = doc->GetLineBreaker(); - nsTextTransformer tx(lb, nsnull, aPresContext); + nsTextTransformer tx(aPresContext); // Keep the text in ascii if possible. Note that if we're measuring small // caps text then transform to Unicode because the helper function only // accepts Unicode text @@ -5893,7 +5873,7 @@ nsTextFrame::Reflow(nsPresContext* aPresContext, // Measure the text // MeasureText may set TEXT_TRIMMED_WS flag, so don't clear after the call if (ts.mFont->mSize) - aStatus = MeasureText(aPresContext, aReflowState, tx, lb, ts, textData); + aStatus = MeasureText(aPresContext, aReflowState, tx, ts, textData); else { textData.mX = 0; textData.mAscent = 0; @@ -6132,7 +6112,6 @@ RevertSpacesToNBSP(PRUnichar* aBuffer, PRInt32 aWordLen) nsTextDimensions nsTextFrame::ComputeTotalWordDimensions(nsPresContext* aPresContext, - nsILineBreaker* aLineBreaker, nsLineLayout& aLineLayout, const nsHTMLReflowState& aReflowState, nsIFrame* aNextFrame, @@ -6163,7 +6142,6 @@ nsTextFrame::ComputeTotalWordDimensions(nsPresContext* aPresContext, PRBool stop = PR_FALSE; nsTextDimensions moreDimensions; moreDimensions = ComputeWordFragmentDimensions(aPresContext, - aLineBreaker, aLineLayout, aReflowState, aNextFrame, content, tc, @@ -6189,7 +6167,7 @@ nsTextFrame::ComputeTotalWordDimensions(nsPresContext* aPresContext, if(newWordBuf) { moreDimensions = - ComputeWordFragmentDimensions(aPresContext, aLineBreaker, + ComputeWordFragmentDimensions(aPresContext, aLineLayout, aReflowState, aNextFrame, content, tc, &stop, newWordBuf, aWordLen, newWordBufSize, @@ -6235,7 +6213,6 @@ nsTextFrame::ComputeTotalWordDimensions(nsPresContext* aPresContext, nsTextDimensions nsTextFrame::ComputeWordFragmentDimensions(nsPresContext* aPresContext, - nsILineBreaker* aLineBreaker, nsLineLayout& aLineLayout, const nsHTMLReflowState& aReflowState, nsIFrame* aNextFrame, @@ -6247,7 +6224,7 @@ nsTextFrame::ComputeWordFragmentDimensions(nsPresContext* aPresContext, PRUint32 aWordBufSize, PRBool aCanBreakBefore) { - nsTextTransformer tx(aLineBreaker, nsnull, aPresContext); + nsTextTransformer tx(aPresContext); tx.Init(aNextFrame, aContent, 0); PRBool isWhitespace, wasTransformed; PRInt32 wordLen, contentLen; @@ -6293,21 +6270,19 @@ nsTextFrame::ComputeWordFragmentDimensions(nsPresContext* aPresContext, { memcpy((void*)&(aWordBuf[aRunningWordLen]), bp, sizeof(PRUnichar)*wordLen); - PRUint32 breakP=0; + PRInt32 breakP=0; PRBool needMore=PR_TRUE; - nsresult lres = aLineBreaker->Next(aWordBuf, aRunningWordLen+wordLen, - 0, &breakP, &needMore); - if(NS_SUCCEEDED(lres)) + breakP = nsContentUtils::GetLineBreaker()->Next(aWordBuf, + aRunningWordLen+wordLen, 0); + // when we look at two pieces text together, we might decide to break + // eariler than if we only look at the 2nd pieces of text + if (breakP != NS_LINEBREAKER_NEED_MORE_TEXT && + (breakP < (aRunningWordLen + wordLen))) { - // when we look at two pieces text together, we might decide to break - // eariler than if we only look at the 2nd pieces of text - if(!needMore && (breakP < (aRunningWordLen + wordLen))) - { - wordLen = breakP - aRunningWordLen; - if(wordLen < 0) - wordLen = 0; - *aStop = PR_TRUE; - } + wordLen = breakP - aRunningWordLen; + if(wordLen < 0) + wordLen = 0; + *aStop = PR_TRUE; } // if we don't stop, we need to extend the buf so the next one can @@ -6321,8 +6296,9 @@ nsTextFrame::ComputeWordFragmentDimensions(nsPresContext* aPresContext, // Even if the previous text fragment is not breakable, the connected pieces // can be breakable in between. This especially true for CJK. PRBool canBreak; - nsresult lres = aLineBreaker->BreakInBetween(aWordBuf, aRunningWordLen, bp, wordLen, &canBreak); - if (NS_SUCCEEDED(lres) && canBreak) { + canBreak = nsContentUtils::GetLineBreaker()->BreakInBetween(aWordBuf, + aRunningWordLen, bp, wordLen); + if (canBreak) { wordLen = 0; *aStop = PR_TRUE; } diff --git a/mozilla/layout/generic/nsTextTransformer.cpp b/mozilla/layout/generic/nsTextTransformer.cpp index 3b2c1883852..16a7f4ee5de 100644 --- a/mozilla/layout/generic/nsTextTransformer.cpp +++ b/mozilla/layout/generic/nsTextTransformer.cpp @@ -165,14 +165,10 @@ nsTextTransformer::Shutdown() MOZ_DECL_CTOR_COUNTER(nsTextTransformer) -nsTextTransformer::nsTextTransformer(nsILineBreaker* aLineBreaker, - nsIWordBreaker* aWordBreaker, - nsPresContext* aPresContext) +nsTextTransformer::nsTextTransformer(nsPresContext* aPresContext) : mFrag(nsnull), mOffset(0), mMode(eNormal), - mLineBreaker(aLineBreaker), - mWordBreaker(aWordBreaker), mBufferPos(0), mTextTransform(NS_STYLE_TEXT_TRANSFORM_NONE), mFlags(0) @@ -185,14 +181,15 @@ nsTextTransformer::nsTextTransformer(nsILineBreaker* aLineBreaker, #ifdef IBMBIDI mPresContext = aPresContext; #endif - if (aLineBreaker == nsnull && aWordBreaker == nsnull ) + if (nsContentUtils::GetLineBreaker() == nsnull && + nsContentUtils::GetWordBreaker() == nsnull ) NS_ASSERTION(0, "invalid creation of nsTextTransformer"); #ifdef DEBUG static PRBool firstTime = PR_TRUE; if (firstTime) { firstTime = PR_FALSE; - SelfTest(aLineBreaker, aWordBreaker, aPresContext); + SelfTest(aPresContext); } #endif } @@ -543,10 +540,12 @@ nsTextTransformer::ScanNormalUnicodeText_F(PRBool aForLineBreak, const PRUnichar* cp = cp0 + offset; PRBool breakBetween = PR_FALSE; if (aForLineBreak) { - mLineBreaker->BreakInBetween(&firstChar, 1, cp, (fragLen-offset), &breakBetween); + breakBetween = nsContentUtils::GetLineBreaker()->BreakInBetween( + &firstChar, 1, cp, (fragLen-offset)); } else { - mWordBreaker->BreakInBetween(&firstChar, 1, cp, (fragLen-offset), &breakBetween); + breakBetween = nsContentUtils::GetWordBreaker()->BreakInBetween( + &firstChar, 1, cp, (fragLen-offset)); } // don't transform the first character until after BreakInBetween is called @@ -566,14 +565,16 @@ nsTextTransformer::ScanNormalUnicodeText_F(PRBool aForLineBreak, if (!breakBetween) { // Find next position - PRBool tryNextFrag; - PRUint32 next; + PRInt32 next; if (aForLineBreak) { - mLineBreaker->Next(cp0, fragLen, offset, &next, &tryNextFrag); + next = nsContentUtils::GetLineBreaker()->Next(cp0, fragLen, offset); } else { - mWordBreaker->NextWord(cp0, fragLen, offset, &next, &tryNextFrag); + next = nsContentUtils::GetWordBreaker()->NextWord(cp0, fragLen, offset); } + if (aForLineBreak && next == NS_LINEBREAKER_NEED_MORE_TEXT || + next == NS_WORDBREAKER_NEED_MORE_TEXT) + next = fragLen; numChars = (PRInt32) (next - (PRUint32) offset) + 1; // Since we know the number of characters we're adding grow the buffer @@ -1211,26 +1212,27 @@ nsTextTransformer::ScanNormalUnicodeText_B(PRBool aForLineBreak, const PRUnichar* cp = cp0 + offset; PRBool breakBetween = PR_FALSE; if (aForLineBreak) { - mLineBreaker->BreakInBetween(cp0, offset + 1, - mTransformBuf.GetBufferEnd()-1, 1, - &breakBetween); + breakBetween = nsContentUtils::GetLineBreaker()->BreakInBetween(cp0, + offset + 1, mTransformBuf.GetBufferEnd()-1, 1); } else { - mWordBreaker->BreakInBetween(cp0, offset + 1, - mTransformBuf.GetBufferEnd()-1, 1, - &breakBetween); + breakBetween = nsContentUtils::GetWordBreaker()->BreakInBetween(cp0, + offset + 1, mTransformBuf.GetBufferEnd()-1, 1); } if (!breakBetween) { // Find next position - PRBool tryPrevFrag; - PRUint32 prev; + PRInt32 prev; if (aForLineBreak) { - mLineBreaker->Prev(cp0, offset, offset, &prev, &tryPrevFrag); + prev = nsContentUtils::GetLineBreaker()->Prev(cp0, offset, offset); } else { - mWordBreaker->PrevWord(cp0, offset, offset, &prev, &tryPrevFrag); + prev = nsContentUtils::GetWordBreaker()->PrevWord(cp0, offset, offset); } + if (aForLineBreak && prev == NS_LINEBREAKER_NEED_MORE_TEXT || + prev == NS_WORDBREAKER_NEED_MORE_TEXT) + prev = 0; + numChars = (PRInt32) ((PRUint32) offset - prev) + 1; // Grow buffer before copying @@ -1685,9 +1687,7 @@ static SelfTestData tests[] = { #define NUM_TESTS (sizeof(tests) / sizeof(tests[0])) void -nsTextTransformer::SelfTest(nsILineBreaker* aLineBreaker, - nsIWordBreaker* aWordBreaker, - nsPresContext* aPresContext) +nsTextTransformer::SelfTest(nsPresContext* aPresContext) { PRBool gNoisy = PR_FALSE; if (PR_GetEnv("GECKO_TEXT_TRANSFORMER_NOISY_SELF_TEST")) { diff --git a/mozilla/layout/generic/nsTextTransformer.h b/mozilla/layout/generic/nsTextTransformer.h index 6cebc405411..7a28bb524c4 100644 --- a/mozilla/layout/generic/nsTextTransformer.h +++ b/mozilla/layout/generic/nsTextTransformer.h @@ -154,9 +154,7 @@ class nsTextTransformer { public: // Note: The text transformer does not hold a reference to the line // breaker and work breaker objects - nsTextTransformer(nsILineBreaker* aLineBreaker, - nsIWordBreaker* aWordBreaker, - nsPresContext* aPresContext); + nsTextTransformer(nsPresContext* aPresContext); ~nsTextTransformer(); @@ -346,10 +344,6 @@ protected: ePreWrap } mMode; - nsILineBreaker* mLineBreaker; // [WEAK] - - nsIWordBreaker* mWordBreaker; // [WEAK] - nsLanguageSpecificTransformType mLanguageSpecificTransformType; #ifdef IBMBIDI @@ -378,9 +372,7 @@ protected: static PRBool sWordSelectStopAtPunctuation; // should we stop at punctuation? #ifdef DEBUG - static void SelfTest(nsILineBreaker* aLineBreaker, - nsIWordBreaker* aWordBreaker, - nsPresContext* aPresContext); + static void SelfTest(nsPresContext* aPresContext); nsresult Init2(const nsTextFragment* aFrag, PRInt32 aStartingOffset,