зеркало из https://github.com/mozilla/gecko-dev.git
Backed out changeset b64704446120 because of build bustage failure in TestWinTSF.cpp
This commit is contained in:
Родитель
865dbccfd8
Коммит
6029691b3f
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<nsIContent> 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<nsIContent> 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;
|
||||
|
|
Загрузка…
Ссылка в новой задаче