Bug 1010761 - Use Text in nsWSRunObject; r=ehsan

This commit is contained in:
Aryeh Gregor 2014-08-13 14:53:32 +03:00
parent 0b4a8e008c
commit 0f9d6c5715
4 changed files with 52 additions and 59 deletions

View File

@ -405,7 +405,7 @@ nsWSRunObject::DeleteWSBackward()
// Caller's job to ensure that previous char is really ws. If it is normal // Caller's job to ensure that previous char is really ws. If it is normal
// ws, we need to delete the whole run. // ws, we need to delete the whole run.
if (nsCRT::IsAsciiSpace(point.mChar)) { if (nsCRT::IsAsciiSpace(point.mChar)) {
nsCOMPtr<nsIContent> startNodeText, endNodeText; nsRefPtr<Text> startNodeText, endNodeText;
int32_t startOffset, endOffset; int32_t startOffset, endOffset;
GetAsciiWSBounds(eBoth, point.mTextNode, point.mOffset + 1, GetAsciiWSBounds(eBoth, point.mTextNode, point.mOffset + 1,
getter_AddRefs(startNodeText), &startOffset, getter_AddRefs(startNodeText), &startOffset,
@ -456,7 +456,7 @@ nsWSRunObject::DeleteWSForward()
// Caller's job to ensure that next char is really ws. If it is normal ws, // Caller's job to ensure that next char is really ws. If it is normal ws,
// we need to delete the whole run. // we need to delete the whole run.
if (nsCRT::IsAsciiSpace(point.mChar)) { if (nsCRT::IsAsciiSpace(point.mChar)) {
nsCOMPtr<nsIContent> startNodeText, endNodeText; nsRefPtr<Text> startNodeText, endNodeText;
int32_t startOffset, endOffset; int32_t startOffset, endOffset;
GetAsciiWSBounds(eBoth, point.mTextNode, point.mOffset + 1, GetAsciiWSBounds(eBoth, point.mTextNode, point.mOffset + 1,
getter_AddRefs(startNodeText), &startOffset, getter_AddRefs(startNodeText), &startOffset,
@ -628,11 +628,11 @@ nsWSRunObject::GetWSNodes()
nsCOMPtr<nsINode> wsBoundingParent = GetWSBoundingParent(); nsCOMPtr<nsINode> wsBoundingParent = GetWSBoundingParent();
// first look backwards to find preceding ws nodes // first look backwards to find preceding ws nodes
if (mNode->NodeType() == nsIDOMNode::TEXT_NODE) { if (mNode->IsNodeOfType(nsINode::eTEXT)) {
nsCOMPtr<nsIContent> textNode(do_QueryInterface(mNode)); nsRefPtr<Text> textNode(static_cast<Text*>(mNode.get()));
const nsTextFragment* textFrag = textNode->GetText(); const nsTextFragment* textFrag = textNode->GetText();
mNodeArray.InsertElementAt(0, static_cast<Text*>(mNode.get())); mNodeArray.InsertElementAt(0, textNode);
if (mOffset) { if (mOffset) {
for (int32_t pos = mOffset - 1; pos >= 0; pos--) { for (int32_t pos = mOffset - 1; pos >= 0; pos--) {
// sanity bounds check the char position. bug 136165 // sanity bounds check the char position. bug 136165
@ -643,22 +643,22 @@ nsWSRunObject::GetWSNodes()
char16_t theChar = textFrag->CharAt(pos); char16_t theChar = textFrag->CharAt(pos);
if (!nsCRT::IsAsciiSpace(theChar)) { if (!nsCRT::IsAsciiSpace(theChar)) {
if (theChar != nbsp) { if (theChar != nbsp) {
mStartNode = mNode; mStartNode = textNode;
mStartOffset = pos + 1; mStartOffset = pos + 1;
mStartReason = WSType::text; mStartReason = WSType::text;
mStartReasonNode = mNode; mStartReasonNode = textNode;
break; break;
} }
// as we look backwards update our earliest found nbsp // as we look backwards update our earliest found nbsp
mFirstNBSPNode = mNode; mFirstNBSPNode = textNode;
mFirstNBSPOffset = pos; mFirstNBSPOffset = pos;
// also keep track of latest nbsp so far // also keep track of latest nbsp so far
if (!mLastNBSPNode) { if (!mLastNBSPNode) {
mLastNBSPNode = mNode; mLastNBSPNode = textNode;
mLastNBSPOffset = pos; mLastNBSPOffset = pos;
} }
} }
start.node = mNode; start.node = textNode;
start.offset = pos; start.offset = pos;
} }
} }
@ -675,11 +675,9 @@ nsWSRunObject::GetWSNodes()
mStartOffset = start.offset; mStartOffset = start.offset;
mStartReason = WSType::otherBlock; mStartReason = WSType::otherBlock;
mStartReasonNode = priorNode; mStartReasonNode = priorNode;
} } else if (priorNode->IsNodeOfType(nsINode::eTEXT)) {
else if (priorNode->NodeType() == nsIDOMNode::TEXT_NODE) { nsRefPtr<Text> textNode(static_cast<Text*>(priorNode.get()));
mNodeArray.InsertElementAt(0, static_cast<Text*>(priorNode.get())); mNodeArray.InsertElementAt(0, textNode);
NS_ENSURE_SUCCESS(res, res);
nsCOMPtr<nsIContent> textNode(do_QueryInterface(priorNode));
const nsTextFragment *textFrag; const nsTextFragment *textFrag;
if (!textNode || !(textFrag = textNode->GetText())) { if (!textNode || !(textFrag = textNode->GetText())) {
return NS_ERROR_NULL_POINTER; return NS_ERROR_NULL_POINTER;
@ -700,22 +698,22 @@ nsWSRunObject::GetWSNodes()
char16_t theChar = textFrag->CharAt(pos); char16_t theChar = textFrag->CharAt(pos);
if (!nsCRT::IsAsciiSpace(theChar)) { if (!nsCRT::IsAsciiSpace(theChar)) {
if (theChar != nbsp) { if (theChar != nbsp) {
mStartNode = priorNode; mStartNode = textNode;
mStartOffset = pos + 1; mStartOffset = pos + 1;
mStartReason = WSType::text; mStartReason = WSType::text;
mStartReasonNode = priorNode; mStartReasonNode = textNode;
break; break;
} }
// as we look backwards update our earliest found nbsp // as we look backwards update our earliest found nbsp
mFirstNBSPNode = priorNode; mFirstNBSPNode = textNode;
mFirstNBSPOffset = pos; mFirstNBSPOffset = pos;
// also keep track of latest nbsp so far // also keep track of latest nbsp so far
if (!mLastNBSPNode) { if (!mLastNBSPNode) {
mLastNBSPNode = priorNode; mLastNBSPNode = textNode;
mLastNBSPOffset = pos; mLastNBSPOffset = pos;
} }
} }
start.SetPoint(priorNode, pos); start.SetPoint(textNode, pos);
} }
} }
} else { } else {
@ -740,9 +738,9 @@ nsWSRunObject::GetWSNodes()
} }
// then look ahead to find following ws nodes // then look ahead to find following ws nodes
if (mNode->NodeType() == nsIDOMNode::TEXT_NODE) { if (mNode->IsNodeOfType(nsINode::eTEXT)) {
// don't need to put it on list. it already is from code above // don't need to put it on list. it already is from code above
nsCOMPtr<nsIContent> textNode(do_QueryInterface(mNode)); nsRefPtr<Text> textNode(static_cast<Text*>(mNode.get()));
const nsTextFragment *textFrag = textNode->GetText(); const nsTextFragment *textFrag = textNode->GetText();
uint32_t len = textNode->TextLength(); uint32_t len = textNode->TextLength();
@ -756,22 +754,22 @@ nsWSRunObject::GetWSNodes()
char16_t theChar = textFrag->CharAt(pos); char16_t theChar = textFrag->CharAt(pos);
if (!nsCRT::IsAsciiSpace(theChar)) { if (!nsCRT::IsAsciiSpace(theChar)) {
if (theChar != nbsp) { if (theChar != nbsp) {
mEndNode = mNode; mEndNode = textNode;
mEndOffset = pos; mEndOffset = pos;
mEndReason = WSType::text; mEndReason = WSType::text;
mEndReasonNode = mNode; mEndReasonNode = textNode;
break; break;
} }
// as we look forwards update our latest found nbsp // as we look forwards update our latest found nbsp
mLastNBSPNode = mNode; mLastNBSPNode = textNode;
mLastNBSPOffset = pos; mLastNBSPOffset = pos;
// also keep track of earliest nbsp so far // also keep track of earliest nbsp so far
if (!mFirstNBSPNode) { if (!mFirstNBSPNode) {
mFirstNBSPNode = mNode; mFirstNBSPNode = textNode;
mFirstNBSPOffset = pos; mFirstNBSPOffset = pos;
} }
} }
end.SetPoint(mNode, pos + 1); end.SetPoint(textNode, pos + 1);
} }
} }
} }
@ -788,9 +786,9 @@ nsWSRunObject::GetWSNodes()
mEndOffset = end.offset; mEndOffset = end.offset;
mEndReason = WSType::otherBlock; mEndReason = WSType::otherBlock;
mEndReasonNode = nextNode; mEndReasonNode = nextNode;
} else if (mHTMLEditor->IsTextNode(nextNode)) { } else if (nextNode->IsNodeOfType(nsINode::eTEXT)) {
mNodeArray.AppendElement(static_cast<Text*>(nextNode.get())); nsRefPtr<Text> textNode(static_cast<Text*>(nextNode.get()));
nsCOMPtr<nsIContent> textNode(do_QueryInterface(nextNode)); mNodeArray.AppendElement(textNode);
const nsTextFragment *textFrag; const nsTextFragment *textFrag;
if (!textNode || !(textFrag = textNode->GetText())) { if (!textNode || !(textFrag = textNode->GetText())) {
return NS_ERROR_NULL_POINTER; return NS_ERROR_NULL_POINTER;
@ -800,7 +798,7 @@ nsWSRunObject::GetWSNodes()
if (len < 1) { if (len < 1) {
// Zero length text node. Set end point to it // Zero length text node. Set end point to it
// so we can get past it! // so we can get past it!
end.SetPoint(nextNode,0); end.SetPoint(textNode, 0);
} else { } else {
for (uint32_t pos = 0; pos < len; pos++) { for (uint32_t pos = 0; pos < len; pos++) {
// sanity bounds check the char position. bug 136165 // sanity bounds check the char position. bug 136165
@ -811,22 +809,22 @@ nsWSRunObject::GetWSNodes()
char16_t theChar = textFrag->CharAt(pos); char16_t theChar = textFrag->CharAt(pos);
if (!nsCRT::IsAsciiSpace(theChar)) { if (!nsCRT::IsAsciiSpace(theChar)) {
if (theChar != nbsp) { if (theChar != nbsp) {
mEndNode = nextNode; mEndNode = textNode;
mEndOffset = pos; mEndOffset = pos;
mEndReason = WSType::text; mEndReason = WSType::text;
mEndReasonNode = nextNode; mEndReasonNode = textNode;
break; break;
} }
// as we look forwards update our latest found nbsp // as we look forwards update our latest found nbsp
mLastNBSPNode = nextNode; mLastNBSPNode = textNode;
mLastNBSPOffset = pos; mLastNBSPOffset = pos;
// also keep track of earliest nbsp so far // also keep track of earliest nbsp so far
if (!mFirstNBSPNode) { if (!mFirstNBSPNode) {
mFirstNBSPNode = nextNode; mFirstNBSPNode = textNode;
mFirstNBSPOffset = pos; mFirstNBSPOffset = pos;
} }
} }
end.SetPoint(nextNode, pos + 1); end.SetPoint(textNode, pos + 1);
} }
} }
} else { } else {
@ -1249,7 +1247,7 @@ nsWSRunObject::PrepareToDeleteRangePriv(nsWSRunObject* aEndObject)
WSPoint point = GetCharBefore(mNode, mOffset); WSPoint point = GetCharBefore(mNode, mOffset);
if (point.mTextNode && nsCRT::IsAsciiSpace(point.mChar)) if (point.mTextNode && nsCRT::IsAsciiSpace(point.mChar))
{ {
nsCOMPtr<nsIContent> wsStartNode, wsEndNode; nsRefPtr<Text> wsStartNode, wsEndNode;
int32_t wsStartOffset, wsEndOffset; int32_t wsStartOffset, wsEndOffset;
GetAsciiWSBounds(eBoth, mNode, mOffset, GetAsciiWSBounds(eBoth, mNode, mOffset,
getter_AddRefs(wsStartNode), &wsStartOffset, getter_AddRefs(wsStartNode), &wsStartOffset,
@ -1294,7 +1292,7 @@ nsWSRunObject::PrepareToSplitAcrossBlocksPriv()
WSPoint point = GetCharBefore(mNode, mOffset); WSPoint point = GetCharBefore(mNode, mOffset);
if (point.mTextNode && nsCRT::IsAsciiSpace(point.mChar)) if (point.mTextNode && nsCRT::IsAsciiSpace(point.mChar))
{ {
nsCOMPtr<nsIContent> wsStartNode, wsEndNode; nsRefPtr<Text> wsStartNode, wsEndNode;
int32_t wsStartOffset, wsEndOffset; int32_t wsStartOffset, wsEndOffset;
GetAsciiWSBounds(eBoth, mNode, mOffset, GetAsciiWSBounds(eBoth, mNode, mOffset,
getter_AddRefs(wsStartNode), &wsStartOffset, getter_AddRefs(wsStartNode), &wsStartOffset,
@ -1406,7 +1404,7 @@ nsWSRunObject::GetCharAfter(nsINode* aNode, int32_t aOffset)
return GetWSPointAfter(aNode, aOffset); return GetWSPointAfter(aNode, aOffset);
} else { } else {
// Use WSPoint version of GetCharAfter() // Use WSPoint version of GetCharAfter()
return GetCharAfter(WSPoint(static_cast<Text*>(aNode), aOffset, 0)); return GetCharAfter(WSPoint(mNodeArray[idx], aOffset, 0));
} }
} }
@ -1421,7 +1419,7 @@ nsWSRunObject::GetCharBefore(nsINode* aNode, int32_t aOffset)
return GetWSPointBefore(aNode, aOffset); return GetWSPointBefore(aNode, aOffset);
} else { } else {
// Use WSPoint version of GetCharBefore() // Use WSPoint version of GetCharBefore()
return GetCharBefore(WSPoint(static_cast<Text*>(aNode), aOffset, 0)); return GetCharBefore(WSPoint(mNodeArray[idx], aOffset, 0));
} }
} }
@ -1511,7 +1509,7 @@ nsWSRunObject::ConvertToNBSP(WSPoint aPoint, AreaRestriction aAR)
NS_ENSURE_SUCCESS(res, res); NS_ENSURE_SUCCESS(res, res);
// Next, find range of ws it will replace // Next, find range of ws it will replace
nsCOMPtr<nsIContent> startNode, endNode; nsRefPtr<Text> startNode, endNode;
int32_t startOffset = 0, endOffset = 0; int32_t startOffset = 0, endOffset = 0;
GetAsciiWSBounds(eAfter, aPoint.mTextNode, aPoint.mOffset + 1, GetAsciiWSBounds(eAfter, aPoint.mTextNode, aPoint.mOffset + 1,
@ -1529,13 +1527,13 @@ nsWSRunObject::ConvertToNBSP(WSPoint aPoint, AreaRestriction aAR)
void void
nsWSRunObject::GetAsciiWSBounds(int16_t aDir, nsINode* aNode, int32_t aOffset, nsWSRunObject::GetAsciiWSBounds(int16_t aDir, nsINode* aNode, int32_t aOffset,
nsIContent** outStartNode, int32_t* outStartOffset, Text** outStartNode, int32_t* outStartOffset,
nsIContent** outEndNode, int32_t* outEndOffset) Text** outEndNode, int32_t* outEndOffset)
{ {
MOZ_ASSERT(aNode && outStartNode && outStartOffset && outEndNode && MOZ_ASSERT(aNode && outStartNode && outStartOffset && outEndNode &&
outEndOffset); outEndOffset);
nsCOMPtr<nsIContent> startNode, endNode; nsRefPtr<Text> startNode, endNode;
int32_t startOffset = 0, endOffset = 0; int32_t startOffset = 0, endOffset = 0;
if (aDir & eAfter) { if (aDir & eAfter) {
@ -1632,7 +1630,7 @@ nsWSRunObject::FindRun(nsINode* aNode, int32_t aOffset, WSFragment** outRun,
} }
char16_t char16_t
nsWSRunObject::GetCharAt(nsIContent *aTextNode, int32_t aOffset) nsWSRunObject::GetCharAt(Text* aTextNode, int32_t aOffset)
{ {
// return 0 if we can't get a char, for whatever reason // return 0 if we can't get a char, for whatever reason
NS_ENSURE_TRUE(aTextNode, 0); NS_ENSURE_TRUE(aTextNode, 0);
@ -1838,7 +1836,7 @@ nsWSRunObject::CheckTrailingNBSPOfRun(WSFragment *aRun)
// editor softwraps at this point, the spaces won't be split across lines, // editor softwraps at this point, the spaces won't be split across lines,
// which looks ugly and is bad for the moose. // which looks ugly and is bad for the moose.
nsCOMPtr<nsIContent> startNode, endNode; nsRefPtr<Text> startNode, endNode;
int32_t startOffset, endOffset; int32_t startOffset, endOffset;
GetAsciiWSBounds(eBoth, prevPoint.mTextNode, prevPoint.mOffset + 1, GetAsciiWSBounds(eBoth, prevPoint.mTextNode, prevPoint.mOffset + 1,
getter_AddRefs(startNode), &startOffset, getter_AddRefs(startNode), &startOffset,

View File

@ -282,16 +282,11 @@ class MOZ_STACK_CLASS nsWSRunObject
// stored in the struct. // stored in the struct.
struct MOZ_STACK_CLASS WSPoint struct MOZ_STACK_CLASS WSPoint
{ {
nsCOMPtr<nsIContent> mTextNode; nsRefPtr<mozilla::dom::Text> mTextNode;
uint32_t mOffset; uint32_t mOffset;
char16_t mChar; char16_t mChar;
WSPoint() : mTextNode(0),mOffset(0),mChar(0) {} WSPoint() : mTextNode(0),mOffset(0),mChar(0) {}
WSPoint(nsIContent* aNode, int32_t aOffset, char16_t aChar) :
mTextNode(aNode),mOffset(aOffset),mChar(aChar)
{
MOZ_ASSERT(mTextNode->IsNodeOfType(nsINode::eTEXT));
}
WSPoint(mozilla::dom::Text* aTextNode, int32_t aOffset, char16_t aChar) : WSPoint(mozilla::dom::Text* aTextNode, int32_t aOffset, char16_t aChar) :
mTextNode(aTextNode),mOffset(aOffset),mChar(aChar) {} mTextNode(aTextNode),mOffset(aOffset),mChar(aChar) {}
}; };
@ -333,13 +328,13 @@ class MOZ_STACK_CLASS nsWSRunObject
nsresult ConvertToNBSP(WSPoint aPoint, nsresult ConvertToNBSP(WSPoint aPoint,
AreaRestriction aAR = eAnywhere); AreaRestriction aAR = eAnywhere);
void GetAsciiWSBounds(int16_t aDir, nsINode* aNode, int32_t aOffset, void GetAsciiWSBounds(int16_t aDir, nsINode* aNode, int32_t aOffset,
nsIContent** outStartNode, mozilla::dom::Text** outStartNode,
int32_t* outStartOffset, int32_t* outStartOffset,
nsIContent** outEndNode, mozilla::dom::Text** outEndNode,
int32_t* outEndOffset); int32_t* outEndOffset);
void FindRun(nsINode* aNode, int32_t aOffset, WSFragment** outRun, void FindRun(nsINode* aNode, int32_t aOffset, WSFragment** outRun,
bool after); bool after);
char16_t GetCharAt(nsIContent *aTextNode, int32_t aOffset); char16_t GetCharAt(mozilla::dom::Text* aTextNode, int32_t aOffset);
WSPoint GetWSPointAfter(nsINode* aNode, int32_t aOffset); WSPoint GetWSPointAfter(nsINode* aNode, int32_t aOffset);
WSPoint GetWSPointBefore(nsINode* aNode, int32_t aOffset); WSPoint GetWSPointBefore(nsINode* aNode, int32_t aOffset);
nsresult CheckTrailingNBSPOfRun(WSFragment *aRun); nsresult CheckTrailingNBSPOfRun(WSFragment *aRun);
@ -371,10 +366,10 @@ class MOZ_STACK_CLASS nsWSRunObject
WSType mEndReason; // reason why ws ends (eText, eOtherBlock, etc) WSType mEndReason; // reason why ws ends (eText, eOtherBlock, etc)
nsCOMPtr<nsINode> mEndReasonNode; // the node that implicated by end reason nsCOMPtr<nsINode> mEndReasonNode; // the node that implicated by end reason
nsCOMPtr<nsINode> mFirstNBSPNode; // location of first nbsp in ws run, if any nsRefPtr<mozilla::dom::Text> mFirstNBSPNode; // location of first nbsp in ws run, if any
int32_t mFirstNBSPOffset; // ... int32_t mFirstNBSPOffset; // ...
nsCOMPtr<nsINode> mLastNBSPNode; // location of last nbsp in ws run, if any nsRefPtr<mozilla::dom::Text> mLastNBSPNode; // location of last nbsp in ws run, if any
int32_t mLastNBSPOffset; // ... int32_t mLastNBSPOffset; // ...
// the list of nodes containing ws in this run // the list of nodes containing ws in this run

View File

@ -2446,7 +2446,7 @@ nsEditor::InsertTextImpl(const nsAString& aStringToInsert,
nsresult nsEditor::InsertTextIntoTextNodeImpl(const nsAString& aStringToInsert, nsresult nsEditor::InsertTextIntoTextNodeImpl(const nsAString& aStringToInsert,
nsINode* aTextNode, Text* aTextNode,
int32_t aOffset, int32_t aOffset,
bool aSuppressIME) bool aSuppressIME)
{ {

View File

@ -208,7 +208,7 @@ public:
int32_t *aInOutOffset, int32_t *aInOutOffset,
nsIDOMDocument *aDoc); nsIDOMDocument *aDoc);
nsresult InsertTextIntoTextNodeImpl(const nsAString& aStringToInsert, nsresult InsertTextIntoTextNodeImpl(const nsAString& aStringToInsert,
nsINode* aTextNode, mozilla::dom::Text* aTextNode,
int32_t aOffset, int32_t aOffset,
bool aSuppressIME = false); bool aSuppressIME = false);
nsresult InsertTextIntoTextNodeImpl(const nsAString& aStringToInsert, nsresult InsertTextIntoTextNodeImpl(const nsAString& aStringToInsert,