diff --git a/editor/libeditor/html/nsWSRunObject.cpp b/editor/libeditor/html/nsWSRunObject.cpp index 698399174c10..97e432bfe1b1 100644 --- a/editor/libeditor/html/nsWSRunObject.cpp +++ b/editor/libeditor/html/nsWSRunObject.cpp @@ -1251,12 +1251,11 @@ nsWSRunObject::PrepareToDeleteRangePriv(nsWSRunObject* aEndObject) WSPoint point = GetCharBefore(mNode, mOffset); if (point.mTextNode && nsCRT::IsAsciiSpace(point.mChar)) { - nsCOMPtr wsStartNode, wsEndNode; + nsCOMPtr wsStartNode, wsEndNode; int32_t wsStartOffset, wsEndOffset; - GetAsciiWSBounds(eBoth, mNode, mOffset, - getter_AddRefs(wsStartNode), &wsStartOffset, - getter_AddRefs(wsEndNode), &wsEndOffset); - point.mTextNode = wsStartNode; + GetAsciiWSBounds(eBoth, GetAsDOMNode(mNode), mOffset, address_of(wsStartNode), + &wsStartOffset, address_of(wsEndNode), &wsEndOffset); + point.mTextNode = do_QueryInterface(wsStartNode); point.mOffset = wsStartOffset; res = ConvertToNBSP(point, eOutsideUserSelectAll); NS_ENSURE_SUCCESS(res, res); @@ -1296,12 +1295,11 @@ nsWSRunObject::PrepareToSplitAcrossBlocksPriv() WSPoint point = GetCharBefore(mNode, mOffset); if (point.mTextNode && nsCRT::IsAsciiSpace(point.mChar)) { - nsCOMPtr wsStartNode, wsEndNode; + nsCOMPtr wsStartNode, wsEndNode; int32_t wsStartOffset, wsEndOffset; - GetAsciiWSBounds(eBoth, mNode, mOffset, - getter_AddRefs(wsStartNode), &wsStartOffset, - getter_AddRefs(wsEndNode), &wsEndOffset); - point.mTextNode = wsStartNode; + GetAsciiWSBounds(eBoth, GetAsDOMNode(mNode), mOffset, address_of(wsStartNode), + &wsStartOffset, address_of(wsEndNode), &wsEndOffset); + point.mTextNode = do_QueryInterface(wsStartNode); point.mOffset = wsStartOffset; res = ConvertToNBSP(point); NS_ENSURE_SUCCESS(res, res); @@ -1534,53 +1532,80 @@ nsWSRunObject::GetAsciiWSBounds(int16_t aDir, nsINode* aNode, int32_t aOffset, nsIContent** outStartNode, int32_t* outStartOffset, nsIContent** outEndNode, int32_t* outEndOffset) { - MOZ_ASSERT(aNode && outStartNode && outStartOffset && outEndNode && - outEndOffset); + nsCOMPtr outStartDOMNode, outEndDOMNode; + GetAsciiWSBounds(aDir, GetAsDOMNode(aNode), aOffset, + address_of(outStartDOMNode), outStartOffset, + address_of(outEndDOMNode), outEndOffset); + nsCOMPtr start(do_QueryInterface(outStartDOMNode)); + nsCOMPtr end(do_QueryInterface(outEndDOMNode)); + start.forget(outStartNode); + end.forget(outEndNode); +} - nsCOMPtr startNode, endNode; - int32_t startOffset = 0, endOffset = 0; +void +nsWSRunObject::GetAsciiWSBounds(int16_t aDir, nsIDOMNode *aNode, int32_t aOffset, + nsCOMPtr *outStartNode, int32_t *outStartOffset, + nsCOMPtr *outEndNode, int32_t *outEndOffset) +{ + MOZ_ASSERT(aNode && outStartNode && outEndNode); - if (aDir & eAfter) { - WSPoint point = GetCharAfter(aNode, aOffset); + nsCOMPtr startNode, endNode; + int32_t startOffset=0, endOffset=0; + + nsCOMPtr node(do_QueryInterface(aNode)); + if (aDir & eAfter) + { + WSPoint point = GetCharAfter(node, aOffset); if (point.mTextNode) { - // We found a text node, at least - startNode = endNode = point.mTextNode; - startOffset = endOffset = point.mOffset; - - // 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++; + // we found a text node, at least + endNode = do_QueryInterface(point.mTextNode); + endOffset = point.mOffset; + startNode = endNode; + startOffset = endOffset; + + // scan ahead to end of ascii ws + while (nsCRT::IsAsciiSpace(point.mChar)) + { + endNode = do_QueryInterface(point.mTextNode); + point.mOffset++; // endOffset is _after_ ws endOffset = point.mOffset; + point = GetCharAfter(point); + if (!point.mTextNode) { + break; + } } } } - - if (aDir & eBefore) { - WSPoint point = GetCharBefore(aNode, aOffset); + + if (aDir & eBefore) + { + WSPoint point = GetCharBefore(node, aOffset); if (point.mTextNode) { - // We found a text node, at least - startNode = point.mTextNode; - startOffset = point.mOffset + 1; - if (!endNode) { + // we found a text node, at least + startNode = do_QueryInterface(point.mTextNode); + startOffset = point.mOffset+1; + if (!endNode) + { endNode = startNode; endOffset = startOffset; } - - // Scan back to start of ASCII ws - for (; nsCRT::IsAsciiSpace(point.mChar) && point.mTextNode; - point = GetCharBefore(point)) { - startNode = point.mTextNode; + + // scan back to start of ascii ws + while (nsCRT::IsAsciiSpace(point.mChar)) + { + startNode = do_QueryInterface(point.mTextNode); startOffset = point.mOffset; + point = GetCharBefore(point); + if (!point.mTextNode) { + break; + } } } - } - - startNode.forget(outStartNode); + } + + *outStartNode = startNode; *outStartOffset = startOffset; - endNode.forget(outEndNode); + *outEndNode = endNode; *outEndOffset = endOffset; } diff --git a/editor/libeditor/html/nsWSRunObject.h b/editor/libeditor/html/nsWSRunObject.h index b0fcb1739bda..bcf0f65ffd8a 100644 --- a/editor/libeditor/html/nsWSRunObject.h +++ b/editor/libeditor/html/nsWSRunObject.h @@ -339,6 +339,9 @@ class MOZ_STACK_CLASS nsWSRunObject int32_t* outStartOffset, nsIContent** outEndNode, int32_t* outEndOffset); + void GetAsciiWSBounds(int16_t aDir, nsIDOMNode *aNode, int32_t aOffset, + nsCOMPtr *outStartNode, int32_t *outStartOffset, + nsCOMPtr *outEndNode, int32_t *outEndOffset); void FindRun(nsINode* aNode, int32_t aOffset, WSFragment** outRun, bool after); char16_t GetCharAt(nsIContent *aTextNode, int32_t aOffset);