From 6029691b3fcfe49335d2e3f0713c4ce4e1bea9f0 Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Fri, 6 Aug 2010 11:39:19 -0400 Subject: [PATCH] Backed out changeset b64704446120 because of build bustage failure in TestWinTSF.cpp --- content/base/src/nsTextFragment.cpp | 22 +++++++++++++ content/base/src/nsTextFragment.h | 19 ++--------- .../spellcheck/src/mozInlineSpellWordUtil.cpp | 32 ++++++++++--------- 3 files changed, 42 insertions(+), 31 deletions(-) diff --git a/content/base/src/nsTextFragment.cpp b/content/base/src/nsTextFragment.cpp index 99a5dfe66e77..ce6fe5bd5b32 100644 --- a/content/base/src/nsTextFragment.cpp +++ b/content/base/src/nsTextFragment.cpp @@ -42,6 +42,7 @@ */ #include "nsTextFragment.h" +#include "nsString.h" #include "nsCRT.h" #include "nsReadableUtils.h" #include "nsMemory.h" @@ -240,6 +241,27 @@ nsTextFragment::SetTo(const PRUnichar* aBuffer, PRInt32 aLength) mState.mLength = aLength; } +void +nsTextFragment::AppendTo(nsAString& aString) const +{ + if (mState.mIs2b) { + aString.Append(m2b, mState.mLength); + } else { + AppendASCIItoUTF16(Substring(m1b, m1b + mState.mLength), + aString); + } +} + +void +nsTextFragment::AppendTo(nsAString& aString, PRInt32 aOffset, PRInt32 aLength) const +{ + if (mState.mIs2b) { + aString.Append(m2b + aOffset, aLength); + } else { + AppendASCIItoUTF16(Substring(m1b + aOffset, m1b + aOffset + aLength), aString); + } +} + void nsTextFragment::CopyTo(PRUnichar *aDest, PRInt32 aOffset, PRInt32 aCount) { diff --git a/content/base/src/nsTextFragment.h b/content/base/src/nsTextFragment.h index bbdd602c3961..b26050a2abbc 100644 --- a/content/base/src/nsTextFragment.h +++ b/content/base/src/nsTextFragment.h @@ -44,7 +44,7 @@ #ifndef nsTextFragment_h___ #define nsTextFragment_h___ -#include "nsString.h" +#include "nsAString.h" #include "nsTraceRefcnt.h" class nsString; class nsCString; @@ -165,27 +165,14 @@ public: /** * Append the contents of this string fragment to aString */ - void AppendTo(nsAString& aString) const { - if (mState.mIs2b) { - aString.Append(m2b, mState.mLength); - } else { - AppendASCIItoUTF16(Substring(m1b, m1b + mState.mLength), - aString); - } - } + void AppendTo(nsAString& aString) const; /** * Append a substring of the contents of this string fragment to aString. * @param aOffset where to start the substring in this text fragment * @param aLength the length of the substring */ - void AppendTo(nsAString& aString, PRInt32 aOffset, PRInt32 aLength) const { - if (mState.mIs2b) { - aString.Append(m2b + aOffset, aLength); - } else { - AppendASCIItoUTF16(Substring(m1b + aOffset, m1b + aOffset + aLength), aString); - } - } + void AppendTo(nsAString& aString, PRInt32 aOffset, PRInt32 aLength) const; /** * Make a copy of the fragments contents starting at offset for diff --git a/extensions/spellcheck/src/mozInlineSpellWordUtil.cpp b/extensions/spellcheck/src/mozInlineSpellWordUtil.cpp index 9bbd14f7edba..cf8a51e37c8c 100644 --- a/extensions/spellcheck/src/mozInlineSpellWordUtil.cpp +++ b/extensions/spellcheck/src/mozInlineSpellWordUtil.cpp @@ -51,7 +51,6 @@ #include "nsUnicharUtilCIID.h" #include "nsServiceManagerUtils.h" #include "nsIContent.h" -#include "nsTextFragment.h" // IsIgnorableCharacter // @@ -430,6 +429,13 @@ IsBRElement(nsIDOMNode* aNode) return NS_SUCCEEDED(rv); } +static void +GetNodeText(nsIDOMNode* aNode, nsAutoString& aText) +{ + nsresult rv = aNode->GetNodeValue(aText); + NS_ASSERTION(NS_SUCCEEDED(rv), "Unable to get node text"); +} + // Find the previous node in the DOM tree in preorder. This isn't fast because // one call to GetPrevSibling can be O(N) in the number of siblings... static nsIDOMNode* @@ -474,12 +480,10 @@ ContainsDOMWordSeparator(nsIDOMNode* aNode, PRInt32 aBeforeOffset, if (!IsTextNode(aNode)) return PR_FALSE; - nsCOMPtr content = do_QueryInterface(aNode); - NS_ASSERTION(content, "Where is our content?"); - const nsTextFragment* textFragment = content->GetText(); - NS_ASSERTION(textFragment, "Where is our text?"); - for (PRInt32 i = NS_MIN(aBeforeOffset, PRInt32(textFragment->GetLength())) - 1; i >= 0; --i) { - if (IsDOMWordSeparator(textFragment->CharAt(i))) { + nsAutoString str; + GetNodeText(aNode, str); + for (PRInt32 i = NS_MIN(aBeforeOffset, PRInt32(str.Length())) - 1; i >= 0; --i) { + if (IsDOMWordSeparator(str.CharAt(i))) { *aSeparatorOffset = i; return PR_TRUE; } @@ -580,6 +584,7 @@ mozInlineSpellWordUtil::BuildSoftText() PRBool seenSoftEnd = PR_FALSE; // Leave this outside the loop so large heap string allocations can be reused // across iterations + nsAutoString str; while (node) { if (node == mSoftEnd.mNode) { seenSoftEnd = PR_TRUE; @@ -587,17 +592,14 @@ mozInlineSpellWordUtil::BuildSoftText() PRBool exit = PR_FALSE; if (IsTextNode(node)) { - nsCOMPtr content = do_QueryInterface(node); - NS_ASSERTION(content, "Where is our content?"); - const nsTextFragment* textFragment = content->GetText(); - NS_ASSERTION(textFragment, "Where is our text?"); - PRInt32 lastOffsetInNode = textFragment->GetLength(); + GetNodeText(node, str); + PRInt32 lastOffsetInNode = str.Length(); if (seenSoftEnd) { // check whether we can stop after this for (PRInt32 i = node == mSoftEnd.mNode ? mSoftEnd.mOffset : 0; - i < PRInt32(textFragment->GetLength()); ++i) { - if (IsDOMWordSeparator(textFragment->CharAt(i))) { + i < PRInt32(str.Length()); ++i) { + if (IsDOMWordSeparator(str.CharAt(i))) { exit = PR_TRUE; // stop at the first separator after the soft end point lastOffsetInNode = i; @@ -610,7 +612,7 @@ mozInlineSpellWordUtil::BuildSoftText() PRInt32 len = lastOffsetInNode - firstOffsetInNode; mSoftTextDOMMapping.AppendElement( DOMTextMapping(NodeOffset(node, firstOffsetInNode), mSoftText.Length(), len)); - textFragment->AppendTo(mSoftText, firstOffsetInNode, len); + mSoftText.Append(Substring(str, firstOffsetInNode, len)); } firstOffsetInNode = 0;