Bug 1004522 part 13 - Clean up nsWSRunObject::GetAsciiWSBounds; r=ehsan

This commit is contained in:
Aryeh Gregor 2014-05-02 15:15:27 +03:00
Родитель bce8f0f030
Коммит e186271f6e
2 изменённых файлов: 42 добавлений и 70 удалений

Просмотреть файл

@ -1251,11 +1251,12 @@ nsWSRunObject::PrepareToDeleteRangePriv(nsWSRunObject* aEndObject)
WSPoint point = GetCharBefore(mNode, mOffset);
if (point.mTextNode && nsCRT::IsAsciiSpace(point.mChar))
{
nsCOMPtr<nsIDOMNode> wsStartNode, wsEndNode;
nsCOMPtr<Text> wsStartNode, wsEndNode;
int32_t wsStartOffset, wsEndOffset;
GetAsciiWSBounds(eBoth, GetAsDOMNode(mNode), mOffset, address_of(wsStartNode),
&wsStartOffset, address_of(wsEndNode), &wsEndOffset);
point.mTextNode = do_QueryInterface(wsStartNode);
GetAsciiWSBounds(eBoth, mNode, mOffset,
getter_AddRefs(wsStartNode), &wsStartOffset,
getter_AddRefs(wsEndNode), &wsEndOffset);
point.mTextNode = wsStartNode;
point.mOffset = wsStartOffset;
res = ConvertToNBSP(point, eOutsideUserSelectAll);
NS_ENSURE_SUCCESS(res, res);
@ -1295,11 +1296,12 @@ nsWSRunObject::PrepareToSplitAcrossBlocksPriv()
WSPoint point = GetCharBefore(mNode, mOffset);
if (point.mTextNode && nsCRT::IsAsciiSpace(point.mChar))
{
nsCOMPtr<nsIDOMNode> wsStartNode, wsEndNode;
nsCOMPtr<Text> wsStartNode, wsEndNode;
int32_t wsStartOffset, wsEndOffset;
GetAsciiWSBounds(eBoth, GetAsDOMNode(mNode), mOffset, address_of(wsStartNode),
&wsStartOffset, address_of(wsEndNode), &wsEndOffset);
point.mTextNode = do_QueryInterface(wsStartNode);
GetAsciiWSBounds(eBoth, mNode, mOffset,
getter_AddRefs(wsStartNode), &wsStartOffset,
getter_AddRefs(wsEndNode), &wsEndOffset);
point.mTextNode = wsStartNode;
point.mOffset = wsStartOffset;
res = ConvertToNBSP(point);
NS_ENSURE_SUCCESS(res, res);
@ -1532,80 +1534,53 @@ nsWSRunObject::GetAsciiWSBounds(int16_t aDir, nsINode* aNode, int32_t aOffset,
nsIContent** outStartNode, int32_t* outStartOffset,
nsIContent** outEndNode, int32_t* outEndOffset)
{
nsCOMPtr<nsIDOMNode> outStartDOMNode, outEndDOMNode;
GetAsciiWSBounds(aDir, GetAsDOMNode(aNode), aOffset,
address_of(outStartDOMNode), outStartOffset,
address_of(outEndDOMNode), outEndOffset);
nsCOMPtr<nsIContent> start(do_QueryInterface(outStartDOMNode));
nsCOMPtr<nsIContent> end(do_QueryInterface(outEndDOMNode));
start.forget(outStartNode);
end.forget(outEndNode);
}
MOZ_ASSERT(aNode && outStartNode && outStartOffset && outEndNode &&
outEndOffset);
void
nsWSRunObject::GetAsciiWSBounds(int16_t aDir, nsIDOMNode *aNode, int32_t aOffset,
nsCOMPtr<nsIDOMNode> *outStartNode, int32_t *outStartOffset,
nsCOMPtr<nsIDOMNode> *outEndNode, int32_t *outEndOffset)
{
MOZ_ASSERT(aNode && outStartNode && outEndNode);
nsCOMPtr<Text> startNode, endNode;
int32_t startOffset = 0, endOffset = 0;
nsCOMPtr<nsIDOMNode> startNode, endNode;
int32_t startOffset=0, endOffset=0;
nsCOMPtr<nsINode> node(do_QueryInterface(aNode));
if (aDir & eAfter)
{
WSPoint point = GetCharAfter(node, aOffset);
if (aDir & eAfter) {
WSPoint point = GetCharAfter(aNode, aOffset);
if (point.mTextNode) {
// we found a text node, at least
endNode = do_QueryInterface(point.mTextNode);
endOffset = point.mOffset;
startNode = endNode;
startOffset = endOffset;
// We found a text node, at least
startNode = endNode = point.mTextNode;
startOffset = endOffset = point.mOffset;
// scan ahead to end of ascii ws
while (nsCRT::IsAsciiSpace(point.mChar))
{
endNode = do_QueryInterface(point.mTextNode);
point.mOffset++; // endOffset is _after_ ws
// Scan ahead to end of ASCII ws
for (; nsCRT::IsAsciiSpace(point.mChar) && point.mTextNode;
point = GetCharAfter(point)) {
endNode = point.mTextNode;
// endOffset is _after_ ws
point.mOffset++;
endOffset = point.mOffset;
point = GetCharAfter(point);
if (!point.mTextNode) {
break;
}
}
}
}
if (aDir & eBefore)
{
WSPoint point = GetCharBefore(node, aOffset);
if (aDir & eBefore) {
WSPoint point = GetCharBefore(aNode, aOffset);
if (point.mTextNode) {
// we found a text node, at least
startNode = do_QueryInterface(point.mTextNode);
startOffset = point.mOffset+1;
if (!endNode)
{
// We found a text node, at least
startNode = point.mTextNode;
startOffset = point.mOffset + 1;
if (!endNode) {
endNode = startNode;
endOffset = startOffset;
}
// scan back to start of ascii ws
while (nsCRT::IsAsciiSpace(point.mChar))
{
startNode = do_QueryInterface(point.mTextNode);
// Scan back to start of ASCII ws
for (; nsCRT::IsAsciiSpace(point.mChar) && point.mTextNode;
point = GetCharBefore(point)) {
startNode = point.mTextNode;
startOffset = point.mOffset;
point = GetCharBefore(point);
if (!point.mTextNode) {
break;
}
}
}
}
*outStartNode = startNode;
startNode.forget(outStartNode);
*outStartOffset = startOffset;
*outEndNode = endNode;
endNode.forget(outEndNode);
*outEndOffset = endOffset;
}

Просмотреть файл

@ -339,9 +339,6 @@ class MOZ_STACK_CLASS nsWSRunObject
int32_t* outStartOffset,
nsIContent** outEndNode,
int32_t* outEndOffset);
void GetAsciiWSBounds(int16_t aDir, nsIDOMNode *aNode, int32_t aOffset,
nsCOMPtr<nsIDOMNode> *outStartNode, int32_t *outStartOffset,
nsCOMPtr<nsIDOMNode> *outEndNode, int32_t *outEndOffset);
void FindRun(nsINode* aNode, int32_t aOffset, WSFragment** outRun,
bool after);
char16_t GetCharAt(nsIContent *aTextNode, int32_t aOffset);