Bug 1004522 part 11 - Convert nsWSRunObject.mNodeArray to nsTArray<nsRefPtr<Text>>; r=ehsan

This commit is contained in:
Aryeh Gregor 2014-05-02 15:15:27 +03:00
parent 1f80f52434
commit 37717a0d9a
2 changed files with 20 additions and 43 deletions

View File

@ -635,8 +635,7 @@ nsWSRunObject::GetWSNodes()
nsCOMPtr<nsIContent> textNode(do_QueryInterface(mNode));
const nsTextFragment* textFrag = textNode->GetText();
res = PrependNodeToList(mNode);
NS_ENSURE_SUCCESS(res, res);
mNodeArray.InsertElementAt(0, static_cast<Text*>(mNode.get()));
if (mOffset) {
for (int32_t pos = mOffset - 1; pos >= 0; pos--) {
// sanity bounds check the char position. bug 136165
@ -681,7 +680,7 @@ nsWSRunObject::GetWSNodes()
mStartReasonNode = priorNode;
}
else if (priorNode->NodeType() == nsIDOMNode::TEXT_NODE) {
res = PrependNodeToList(priorNode);
mNodeArray.InsertElementAt(0, static_cast<Text*>(priorNode.get()));
NS_ENSURE_SUCCESS(res, res);
nsCOMPtr<nsIContent> textNode(do_QueryInterface(priorNode));
const nsTextFragment *textFrag;
@ -793,8 +792,7 @@ nsWSRunObject::GetWSNodes()
mEndReason = WSType::otherBlock;
mEndReasonNode = nextNode;
} else if (mHTMLEditor->IsTextNode(nextNode)) {
res = AppendNodeToList(nextNode);
NS_ENSURE_SUCCESS(res, res);
mNodeArray.AppendElement(static_cast<Text*>(nextNode.get()));
nsCOMPtr<nsIContent> textNode(do_QueryInterface(nextNode));
const nsTextFragment *textFrag;
if (!textNode || !(textFrag = textNode->GetText())) {
@ -1020,26 +1018,6 @@ nsWSRunObject::MakeSingleWSRun(WSType aType)
mEndRun = mStartRun;
}
nsresult
nsWSRunObject::PrependNodeToList(nsINode *aNode)
{
NS_ENSURE_TRUE(aNode, NS_ERROR_NULL_POINTER);
if (!mNodeArray.InsertObjectAt(aNode, 0)) {
return NS_ERROR_FAILURE;
}
return NS_OK;
}
nsresult
nsWSRunObject::AppendNodeToList(nsINode* aNode)
{
NS_ENSURE_TRUE(aNode, NS_ERROR_NULL_POINTER);
if (!mNodeArray.AppendObject(aNode)) {
return NS_ERROR_FAILURE;
}
return NS_OK;
}
nsresult
nsWSRunObject::GetPreviousWSNodeInner(nsINode* aStartNode,
nsINode* aBlockParent,
@ -1375,7 +1353,7 @@ nsWSRunObject::DeleteChars(nsIDOMNode *aStartNode, int32_t aStartOffset,
}
}
int32_t count = mNodeArray.Count();
int32_t count = mNodeArray.Length();
while (idx < count)
{
node = GetAsDOMNode(mNodeArray[idx]);
@ -1427,7 +1405,7 @@ nsWSRunObject::DeleteChars(nsIDOMNode *aStartNode, int32_t aStartOffset,
res = mHTMLEditor->DeleteNode(node);
NS_ENSURE_SUCCESS(res, res);
nsCOMPtr<nsINode> node_ = do_QueryInterface(node);
mNodeArray.RemoveObject(node_);
mNodeArray.RemoveElement(node_);
--count;
--idx;
}
@ -1482,14 +1460,14 @@ nsWSRunObject::GetCharAfter(const WSPoint &aPoint)
// Can't find point, but it's not an error
return outPoint;
}
int32_t numNodes = mNodeArray.Count();
int32_t numNodes = mNodeArray.Length();
if (uint16_t(aPoint.mOffset) < aPoint.mTextNode->TextLength()) {
outPoint = aPoint;
outPoint.mChar = GetCharAt(aPoint.mTextNode, aPoint.mOffset);
return outPoint;
} else if (idx + 1 < numNodes) {
outPoint.mTextNode = do_QueryInterface(mNodeArray[idx + 1]);
outPoint.mTextNode = mNodeArray[idx + 1];
MOZ_ASSERT(outPoint.mTextNode);
outPoint.mOffset = 0;
outPoint.mChar = GetCharAt(outPoint.mTextNode, 0);
@ -1519,7 +1497,7 @@ nsWSRunObject::GetCharBefore(const WSPoint &aPoint)
outPoint.mChar = GetCharAt(aPoint.mTextNode, aPoint.mOffset - 1);
return outPoint;
} else if (idx) {
outPoint.mTextNode = do_QueryInterface(mNodeArray[idx - 1]);
outPoint.mTextNode = mNodeArray[idx - 1];
uint32_t len = outPoint.mTextNode->TextLength();
if (len) {
@ -1719,8 +1697,8 @@ nsWSRunObject::GetWSPointAfter(nsIDOMNode *aNode, int32_t aOffset)
// Note: only to be called if aNode is not a ws node.
// binary search on wsnodes
int32_t numNodes, firstNum, curNum, lastNum;
numNodes = mNodeArray.Count();
uint32_t numNodes, firstNum, curNum, lastNum;
numNodes = mNodeArray.Length();
if (!numNodes) {
// do nothing if there are no nodes to search
@ -1752,15 +1730,15 @@ nsWSRunObject::GetWSPointAfter(nsIDOMNode *aNode, int32_t aOffset)
// When the binary search is complete, we always know that the current node
// is the same as the end node, which is always past our range. Therefore,
// we've found the node immediately after the point of interest.
if (curNum == mNodeArray.Count()) {
if (curNum == mNodeArray.Length()) {
// they asked for past our range (it's after the last node). GetCharAfter
// will do the work for us when we pass it the last index of the last node.
nsCOMPtr<nsIContent> textNode(do_QueryInterface(mNodeArray[curNum-1]));
nsRefPtr<Text> textNode(mNodeArray[curNum - 1]);
WSPoint point(textNode, textNode->TextLength(), 0);
return GetCharAfter(point);
} else {
// The char after the point of interest is the first character of our range.
nsCOMPtr<nsIContent> textNode(do_QueryInterface(mNodeArray[curNum]));
nsRefPtr<Text> textNode(mNodeArray[curNum]);
WSPoint point(textNode, 0, 0);
return GetCharAfter(point);
}
@ -1772,8 +1750,8 @@ nsWSRunObject::GetWSPointBefore(nsIDOMNode *aNode, int32_t aOffset)
// Note: only to be called if aNode is not a ws node.
// binary search on wsnodes
int32_t numNodes, firstNum, curNum, lastNum;
numNodes = mNodeArray.Count();
uint32_t numNodes, firstNum, curNum, lastNum;
numNodes = mNodeArray.Length();
if (!numNodes) {
// do nothing if there are no nodes to search
@ -1805,17 +1783,17 @@ nsWSRunObject::GetWSPointBefore(nsIDOMNode *aNode, int32_t aOffset)
// When the binary search is complete, we always know that the current node
// is the same as the end node, which is always past our range. Therefore,
// we've found the node immediately after the point of interest.
if (curNum == mNodeArray.Count()) {
if (curNum == mNodeArray.Length()) {
// get the point before the end of the last node, we can pass the length
// of the node into GetCharBefore, and it will return the last character.
nsCOMPtr<nsIContent> textNode(do_QueryInterface(mNodeArray[curNum - 1]));
nsRefPtr<Text> textNode(mNodeArray[curNum - 1]);
WSPoint point(textNode, textNode->TextLength(), 0);
return GetCharBefore(point);
} else {
// we can just ask the current node for the point immediately before it,
// it will handle moving to the previous node (if any) and returning the
// appropriate character
nsCOMPtr<nsIContent> textNode(do_QueryInterface(mNodeArray[curNum]));
nsRefPtr<Text> textNode(mNodeArray[curNum]);
WSPoint point(textNode, 0, 0);
return GetCharBefore(point);
}

View File

@ -317,8 +317,6 @@ class MOZ_STACK_CLASS nsWSRunObject
void GetRuns();
void ClearRuns();
void MakeSingleWSRun(WSType aType);
nsresult PrependNodeToList(nsINode* aNode);
nsresult AppendNodeToList(nsINode* aNode);
nsresult GetPreviousWSNode(::DOMPoint aPoint,
nsINode* aBlockParent,
nsCOMPtr<nsINode>* aPriorNode);
@ -384,7 +382,8 @@ class MOZ_STACK_CLASS nsWSRunObject
nsCOMPtr<nsINode> mLastNBSPNode; // location of last nbsp in ws run, if any
int32_t mLastNBSPOffset; // ...
nsCOMArray<nsINode> mNodeArray; //the list of nodes containing ws in this run
// the list of nodes containing ws in this run
nsTArray<nsRefPtr<mozilla::dom::Text>> mNodeArray;
WSFragment *mStartRun; // the first WSFragment in the run
WSFragment *mEndRun; // the last WSFragment in the run, may be same as first