mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 684638 part 4. Switch from nsIDOMNode to nsINode in mozInlineSpellWordUtil. r=ehsan
This commit is contained in:
parent
dcfdba5859
commit
9a5b112e48
@ -50,6 +50,7 @@
|
||||
#include "nsDOMString.h"
|
||||
#include "jspubtd.h"
|
||||
#include "nsDOMMemoryReporter.h"
|
||||
#include "nsIVariant.h"
|
||||
|
||||
// Including 'windows.h' will #define GetClassInfo to something else.
|
||||
#ifdef XP_WIN
|
||||
@ -76,7 +77,6 @@ class nsChildContentList;
|
||||
class nsNodeWeakReference;
|
||||
class nsNodeSupportsWeakRefTearoff;
|
||||
class nsIEditor;
|
||||
class nsIVariant;
|
||||
class nsIDOMUserDataHandler;
|
||||
class nsAttrAndChildArray;
|
||||
class nsXPCClassInfo;
|
||||
|
@ -95,6 +95,8 @@
|
||||
#include "nsIContent.h"
|
||||
#include "nsEventListenerManager.h"
|
||||
#include "nsGUIEvent.h"
|
||||
#include "nsRange.h"
|
||||
#include "nsContentUtils.h"
|
||||
|
||||
// Set to spew messages to the console about what is happening.
|
||||
//#define DEBUG_INLINESPELL
|
||||
@ -164,8 +166,7 @@ mozInlineSpellStatus::InitForEditorChange(
|
||||
mOp = eOpChange;
|
||||
|
||||
// range to check
|
||||
rv = doc->CreateRange(getter_AddRefs(mRange));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
mRange = new nsRange();
|
||||
|
||||
// ...we need to put the start and end in the correct order
|
||||
nsCOMPtr<nsIDOMNSRange> nsrange = do_QueryInterface(mAnchorRange, &rv);
|
||||
@ -284,7 +285,7 @@ mozInlineSpellStatus::InitForSelection()
|
||||
// a change operation over the given range.
|
||||
|
||||
nsresult
|
||||
mozInlineSpellStatus::InitForRange(nsIDOMRange* aRange)
|
||||
mozInlineSpellStatus::InitForRange(nsIRange* aRange)
|
||||
{
|
||||
mOp = eOpChange;
|
||||
mRange = aRange;
|
||||
@ -374,7 +375,7 @@ mozInlineSpellStatus::FinishNavigationEvent(mozInlineSpellWordUtil& aWordUtil)
|
||||
|
||||
// find the word on the old caret position, this is the one that we MAY need
|
||||
// to check
|
||||
nsCOMPtr<nsIDOMRange> oldWord;
|
||||
nsCOMPtr<nsIRange> oldWord;
|
||||
rv = aWordUtil.GetRangeForWord(oldAnchorNode, oldAnchorOffset,
|
||||
getter_AddRefs(oldWord));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
@ -796,7 +797,8 @@ mozInlineSpellChecker::SpellCheckRange(nsIDOMRange* aRange)
|
||||
NS_ENSURE_TRUE(mSpellCheck, NS_ERROR_NOT_INITIALIZED);
|
||||
|
||||
mozInlineSpellStatus status(this);
|
||||
nsresult rv = status.InitForRange(aRange);
|
||||
nsCOMPtr<nsIRange> range = do_QueryInterface(aRange);
|
||||
nsresult rv = status.InitForRange(range);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
return ScheduleSpellCheck(status);
|
||||
}
|
||||
@ -1002,7 +1004,7 @@ nsresult
|
||||
mozInlineSpellChecker::MakeSpellCheckRange(
|
||||
nsIDOMNode* aStartNode, PRInt32 aStartOffset,
|
||||
nsIDOMNode* aEndNode, PRInt32 aEndOffset,
|
||||
nsIDOMRange** aRange)
|
||||
nsIRange** aRange)
|
||||
{
|
||||
nsresult rv;
|
||||
*aRange = nsnull;
|
||||
@ -1057,7 +1059,7 @@ mozInlineSpellChecker::MakeSpellCheckRange(
|
||||
rv = range->SetEndAfter(aEndNode);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
range.swap(*aRange);
|
||||
CallQueryInterface(range, aRange);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -1067,7 +1069,7 @@ mozInlineSpellChecker::SpellCheckBetweenNodes(nsIDOMNode *aStartNode,
|
||||
nsIDOMNode *aEndNode,
|
||||
PRInt32 aEndOffset)
|
||||
{
|
||||
nsCOMPtr<nsIDOMRange> range;
|
||||
nsCOMPtr<nsIRange> range;
|
||||
nsresult rv = MakeSpellCheckRange(aStartNode, aStartOffset,
|
||||
aEndNode, aEndOffset,
|
||||
getter_AddRefs(range));
|
||||
@ -1222,7 +1224,7 @@ mozInlineSpellChecker::DoSpellCheckSelection(mozInlineSpellWordUtil& aWordUtil,
|
||||
// check range over it that needs to be deleted. All the old ranges
|
||||
// were cleared above. We also need to clear the word count so that we
|
||||
// check all words instead of stopping early.
|
||||
status.mRange = checkRange;
|
||||
status.mRange = do_QueryInterface(checkRange);
|
||||
rv = DoSpellCheck(aWordUtil, aSpellCheckSelection, &status,
|
||||
&doneChecking);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
@ -1271,8 +1273,6 @@ nsresult mozInlineSpellChecker::DoSpellCheck(mozInlineSpellWordUtil& aWordUtil,
|
||||
mozInlineSpellStatus* aStatus,
|
||||
bool* aDoneChecking)
|
||||
{
|
||||
nsCOMPtr<nsIDOMNode> beginNode, endNode;
|
||||
PRInt32 beginOffset, endOffset;
|
||||
*aDoneChecking = true;
|
||||
|
||||
// get the editor for SkipSpellCheckForNode, this may fail in reasonable
|
||||
@ -1297,13 +1297,26 @@ nsresult mozInlineSpellChecker::DoSpellCheck(mozInlineSpellWordUtil& aWordUtil,
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// set the starting DOM position to be the beginning of our range
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
aStatus->mRange->GetStartContainer(getter_AddRefs(beginNode));
|
||||
aStatus->mRange->GetStartOffset(&beginOffset);
|
||||
aStatus->mRange->GetEndContainer(getter_AddRefs(endNode));
|
||||
aStatus->mRange->GetEndOffset(&endOffset);
|
||||
aWordUtil.SetEnd(endNode, endOffset);
|
||||
aWordUtil.SetPosition(beginNode, beginOffset);
|
||||
{
|
||||
// Scope for the node/offset pairs here so they don't get
|
||||
// accidentally used later
|
||||
nsINode* beginNode = aStatus->mRange->GetStartParent();
|
||||
PRInt32 beginOffset = aStatus->mRange->StartOffset();
|
||||
nsINode* endNode = aStatus->mRange->GetEndParent();
|
||||
PRInt32 endOffset = aStatus->mRange->EndOffset();
|
||||
|
||||
// Now check that we're still looking at a range that's under
|
||||
// aWordUtil.GetRootNode()
|
||||
nsINode* rootNode = aWordUtil.GetRootNode();
|
||||
if (!nsContentUtils::ContentIsDescendantOf(beginNode, rootNode) ||
|
||||
!nsContentUtils::ContentIsDescendantOf(endNode, rootNode)) {
|
||||
// Just bail out and don't try to spell-check this
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
aWordUtil.SetEnd(endNode, endOffset);
|
||||
aWordUtil.SetPosition(beginNode, beginOffset);
|
||||
}
|
||||
|
||||
// aWordUtil.SetPosition flushes pending notifications, check editor again.
|
||||
editor = do_QueryReferent(mEditor);
|
||||
@ -1321,7 +1334,7 @@ nsresult mozInlineSpellChecker::DoSpellCheck(mozInlineSpellWordUtil& aWordUtil,
|
||||
PRTime beginTime = PR_Now();
|
||||
|
||||
nsAutoString wordText;
|
||||
nsCOMPtr<nsIDOMRange> wordRange;
|
||||
nsCOMPtr<nsIRange> wordRange;
|
||||
bool dontCheckWord;
|
||||
while (NS_SUCCEEDED(aWordUtil.GetNextWord(wordText,
|
||||
getter_AddRefs(wordRange),
|
||||
@ -1329,7 +1342,11 @@ nsresult mozInlineSpellChecker::DoSpellCheck(mozInlineSpellWordUtil& aWordUtil,
|
||||
wordRange) {
|
||||
wordsSinceTimeCheck ++;
|
||||
|
||||
// get the range for the current word
|
||||
// get the range for the current word.
|
||||
// Not using nsINode here for now because we have to call into
|
||||
// selection APIs that use nsIDOMNode. :(
|
||||
nsCOMPtr<nsIDOMNode> beginNode, endNode;
|
||||
PRInt32 beginOffset, endOffset;
|
||||
wordRange->GetStartContainer(getter_AddRefs(beginNode));
|
||||
wordRange->GetEndContainer(getter_AddRefs(endNode));
|
||||
wordRange->GetStartOffset(&beginOffset);
|
||||
|
@ -40,7 +40,7 @@
|
||||
#define __mozinlinespellchecker_h__
|
||||
|
||||
#include "nsAutoPtr.h"
|
||||
#include "nsIDOMRange.h"
|
||||
#include "nsIRange.h"
|
||||
#include "nsIEditorSpellCheck.h"
|
||||
#include "nsIEditActionListener.h"
|
||||
#include "nsIInlineSpellChecker.h"
|
||||
@ -78,7 +78,7 @@ public:
|
||||
nsIDOMNode* aNewAnchorNode, PRInt32 aNewAnchorOffset,
|
||||
bool* aContinue);
|
||||
nsresult InitForSelection();
|
||||
nsresult InitForRange(nsIDOMRange* aRange);
|
||||
nsresult InitForRange(nsIRange* aRange);
|
||||
|
||||
nsresult FinishInitOnEvent(mozInlineSpellWordUtil& aWordUtil);
|
||||
|
||||
@ -99,14 +99,14 @@ public:
|
||||
|
||||
// Used for events where we have already computed the range to use. It can
|
||||
// also be NULL in these cases where we need to check the entire range.
|
||||
nsCOMPtr<nsIDOMRange> mRange;
|
||||
nsCOMPtr<nsIRange> mRange;
|
||||
|
||||
// If we happen to know something was inserted, this is that range.
|
||||
// Can be NULL (this only allows an optimization, so not setting doesn't hurt)
|
||||
nsCOMPtr<nsIDOMRange> mCreatedRange;
|
||||
|
||||
// Contains the range computed for the current word. Can be NULL.
|
||||
nsCOMPtr<nsIDOMRange> mNoCheckRange;
|
||||
nsCOMPtr<nsIRange> mNoCheckRange;
|
||||
|
||||
// Indicates the position of the cursor for the event (so we can compute
|
||||
// mNoCheckRange). It can be NULL if we don't care about the cursor position
|
||||
@ -283,7 +283,7 @@ public:
|
||||
|
||||
nsresult MakeSpellCheckRange(nsIDOMNode* aStartNode, PRInt32 aStartOffset,
|
||||
nsIDOMNode* aEndNode, PRInt32 aEndOffset,
|
||||
nsIDOMRange** aRange);
|
||||
nsIRange** aRange);
|
||||
|
||||
// DOM and editor event registration helper routines
|
||||
nsresult RegisterEventListeners();
|
||||
|
@ -110,34 +110,31 @@ mozInlineSpellWordUtil::Init(nsWeakPtr aWeakEditor)
|
||||
nsCOMPtr<nsIDOMElement> rootElt;
|
||||
rv = editor->GetRootElement(getter_AddRefs(rootElt));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
mRootNode = rootElt;
|
||||
|
||||
nsCOMPtr<nsINode> rootNode = do_QueryInterface(rootElt);
|
||||
mRootNode = rootNode;
|
||||
NS_ASSERTION(mRootNode, "GetRootElement returned null *and* claimed to suceed!");
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
static bool
|
||||
IsTextNode(nsIDOMNode* aNode)
|
||||
static inline bool
|
||||
IsTextNode(nsINode* aNode)
|
||||
{
|
||||
PRUint16 type = 0;
|
||||
aNode->GetNodeType(&type);
|
||||
return type == nsIDOMNode::TEXT_NODE;
|
||||
return aNode->IsNodeOfType(nsINode::eTEXT);
|
||||
}
|
||||
|
||||
typedef void (* OnLeaveNodeFunPtr)(nsIDOMNode* aNode, void* aClosure);
|
||||
typedef void (* OnLeaveNodeFunPtr)(nsINode* aNode, void* aClosure);
|
||||
|
||||
// Find the next node in the DOM tree in preorder. This isn't fast because
|
||||
// one call to GetNextSibling can be O(N) in the number of siblings...
|
||||
// Calls OnLeaveNodeFunPtr when the traversal leaves a node
|
||||
// XXXbz if this used nsINode, this would be trivial
|
||||
static nsIDOMNode*
|
||||
FindNextNode(nsIDOMNode* aNode, nsIDOMNode* aRoot,
|
||||
OnLeaveNodeFunPtr aOnLeaveNode = nsnull, void* aClosure = nsnull)
|
||||
// Find the next node in the DOM tree in preorder.
|
||||
// Calls OnLeaveNodeFunPtr when the traversal leaves a node, which is
|
||||
// why we can't just use GetNextNode here, sadly.
|
||||
static nsINode*
|
||||
FindNextNode(nsINode* aNode, nsINode* aRoot,
|
||||
OnLeaveNodeFunPtr aOnLeaveNode, void* aClosure)
|
||||
{
|
||||
NS_PRECONDITION(aNode, "Null starting node?");
|
||||
|
||||
nsCOMPtr<nsIDOMNode> next;
|
||||
aNode->GetFirstChild(getter_AddRefs(next));
|
||||
nsINode* next = aNode->GetFirstChild();
|
||||
if (next)
|
||||
return next;
|
||||
|
||||
@ -145,7 +142,7 @@ FindNextNode(nsIDOMNode* aNode, nsIDOMNode* aRoot,
|
||||
if (aNode == aRoot)
|
||||
return nsnull;
|
||||
|
||||
aNode->GetNextSibling(getter_AddRefs(next));
|
||||
next = aNode->GetNextSibling();
|
||||
if (next)
|
||||
return next;
|
||||
|
||||
@ -155,12 +152,12 @@ FindNextNode(nsIDOMNode* aNode, nsIDOMNode* aRoot,
|
||||
aOnLeaveNode(aNode, aClosure);
|
||||
}
|
||||
|
||||
aNode->GetParentNode(getter_AddRefs(next));
|
||||
next = aNode->GetParent();
|
||||
if (next == aRoot || ! next)
|
||||
return nsnull;
|
||||
aNode = next;
|
||||
|
||||
aNode->GetNextSibling(getter_AddRefs(next));
|
||||
next = aNode->GetNextSibling();
|
||||
if (next)
|
||||
return next;
|
||||
}
|
||||
@ -168,43 +165,29 @@ FindNextNode(nsIDOMNode* aNode, nsIDOMNode* aRoot,
|
||||
|
||||
// aNode is not a text node. Find the first text node starting at aNode/aOffset
|
||||
// in a preorder DOM traversal.
|
||||
static nsIDOMNode*
|
||||
FindNextTextNode(nsIDOMNode* aNode, PRInt32 aOffset, nsIDOMNode* aRoot)
|
||||
static nsINode*
|
||||
FindNextTextNode(nsINode* aNode, PRInt32 aOffset, nsINode* aRoot)
|
||||
{
|
||||
NS_PRECONDITION(aNode, "Null starting node?");
|
||||
NS_ASSERTION(!IsTextNode(aNode), "FindNextTextNode should start with a non-text node");
|
||||
|
||||
nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
|
||||
nsCOMPtr<nsIDOMNode> checkNode;
|
||||
nsINode* checkNode;
|
||||
// Need to start at the aOffset'th child
|
||||
nsIContent* child = node->GetChildAt(aOffset);
|
||||
nsIContent* child = aNode->GetChildAt(aOffset);
|
||||
|
||||
if (child) {
|
||||
checkNode = do_QueryInterface(child);
|
||||
checkNode = child;
|
||||
} else {
|
||||
// aOffset was beyond the end of the child list.
|
||||
// goto next node in a preorder DOM traversal.
|
||||
// XXXbz this is generally reimplementing GetNextNode.
|
||||
nsINode* next = node->GetNextSibling();
|
||||
if (!next) {
|
||||
nsCOMPtr<nsINode> root = do_QueryInterface(aRoot);
|
||||
while (!next) {
|
||||
// Go up
|
||||
next = node->GetNodeParent();
|
||||
if (next == root || !next) {
|
||||
return nsnull;
|
||||
}
|
||||
node = next;
|
||||
next = node->GetNextSibling();
|
||||
}
|
||||
}
|
||||
checkNode = do_QueryInterface(next);
|
||||
// goto next node after the last descendant of aNode in
|
||||
// a preorder DOM traversal.
|
||||
checkNode = aNode->GetNextNonChildNode(aRoot);
|
||||
}
|
||||
|
||||
while (checkNode && !IsTextNode(checkNode)) {
|
||||
checkNode = FindNextNode(checkNode, aRoot);
|
||||
checkNode = checkNode->GetNextNode(aRoot);
|
||||
}
|
||||
return checkNode.get();
|
||||
return checkNode;
|
||||
}
|
||||
|
||||
// mozInlineSpellWordUtil::SetEnd
|
||||
@ -225,7 +208,7 @@ FindNextTextNode(nsIDOMNode* aNode, PRInt32 aOffset, nsIDOMNode* aRoot)
|
||||
// position.
|
||||
|
||||
nsresult
|
||||
mozInlineSpellWordUtil::SetEnd(nsIDOMNode* aEndNode, PRInt32 aEndOffset)
|
||||
mozInlineSpellWordUtil::SetEnd(nsINode* aEndNode, PRInt32 aEndOffset)
|
||||
{
|
||||
NS_PRECONDITION(aEndNode, "Null end node?");
|
||||
|
||||
@ -243,7 +226,7 @@ mozInlineSpellWordUtil::SetEnd(nsIDOMNode* aEndNode, PRInt32 aEndOffset)
|
||||
}
|
||||
|
||||
nsresult
|
||||
mozInlineSpellWordUtil::SetPosition(nsIDOMNode* aNode, PRInt32 aOffset)
|
||||
mozInlineSpellWordUtil::SetPosition(nsINode* aNode, PRInt32 aOffset)
|
||||
{
|
||||
InvalidateWords();
|
||||
|
||||
@ -274,7 +257,7 @@ mozInlineSpellWordUtil::EnsureWords()
|
||||
}
|
||||
|
||||
nsresult
|
||||
mozInlineSpellWordUtil::MakeRangeForWord(const RealWord& aWord, nsIDOMRange** aRange)
|
||||
mozInlineSpellWordUtil::MakeRangeForWord(const RealWord& aWord, nsIRange** aRange)
|
||||
{
|
||||
NodeOffset begin = MapSoftTextOffsetToDOMPosition(aWord.mSoftTextOffset, HINT_BEGIN);
|
||||
NodeOffset end = MapSoftTextOffsetToDOMPosition(aWord.EndOffset(), HINT_END);
|
||||
@ -286,10 +269,11 @@ mozInlineSpellWordUtil::MakeRangeForWord(const RealWord& aWord, nsIDOMRange** aR
|
||||
nsresult
|
||||
mozInlineSpellWordUtil::GetRangeForWord(nsIDOMNode* aWordNode,
|
||||
PRInt32 aWordOffset,
|
||||
nsIDOMRange** aRange)
|
||||
nsIRange** aRange)
|
||||
{
|
||||
// Set our soft end and start
|
||||
NodeOffset pt = NodeOffset(aWordNode, aWordOffset);
|
||||
nsCOMPtr<nsINode> wordNode = do_QueryInterface(aWordNode);
|
||||
NodeOffset pt = NodeOffset(wordNode, aWordOffset);
|
||||
|
||||
InvalidateWords();
|
||||
mSoftBegin = mSoftEnd = pt;
|
||||
@ -332,7 +316,7 @@ NormalizeWord(const nsSubstring& aInput, PRInt32 aPos, PRInt32 aLen, nsAString&
|
||||
// range unless the word was misspelled. This may or may not be possible.
|
||||
|
||||
nsresult
|
||||
mozInlineSpellWordUtil::GetNextWord(nsAString& aText, nsIDOMRange** aRange,
|
||||
mozInlineSpellWordUtil::GetNextWord(nsAString& aText, nsIRange** aRange,
|
||||
bool* aSkipChecking)
|
||||
{
|
||||
#ifdef DEBUG_SPELLCHECK
|
||||
@ -368,15 +352,14 @@ mozInlineSpellWordUtil::GetNextWord(nsAString& aText, nsIDOMRange** aRange,
|
||||
|
||||
nsresult
|
||||
mozInlineSpellWordUtil::MakeRange(NodeOffset aBegin, NodeOffset aEnd,
|
||||
nsIDOMRange** aRange)
|
||||
nsIRange** aRange)
|
||||
{
|
||||
if (!mDOMDocument)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
nsRefPtr<nsRange> range = new nsRange();
|
||||
nsCOMPtr<nsINode> begin(do_QueryInterface(aBegin.mNode));
|
||||
nsCOMPtr<nsINode> end(do_QueryInterface(aEnd.mNode));
|
||||
nsresult rv = range->Set(begin, aBegin.mOffset, end, aEnd.mOffset);
|
||||
nsresult rv = range->Set(aBegin.mNode, aBegin.mOffset,
|
||||
aEnd.mNode, aEnd.mOffset);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
range.forget(aRange);
|
||||
|
||||
@ -415,38 +398,11 @@ IsDOMWordSeparator(PRUnichar ch)
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool
|
||||
IsBRElement(nsIDOMNode* aNode)
|
||||
static inline bool
|
||||
IsBRElement(nsINode* aNode)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIDOMHTMLBRElement> elt = do_QueryInterface(aNode, &rv);
|
||||
return NS_SUCCEEDED(rv);
|
||||
}
|
||||
|
||||
// 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*
|
||||
FindPrevNode(nsIDOMNode* aNode, nsIDOMNode* aRoot)
|
||||
{
|
||||
if (aNode == aRoot)
|
||||
return nsnull;
|
||||
|
||||
nsCOMPtr<nsIDOMNode> prev;
|
||||
aNode->GetPreviousSibling(getter_AddRefs(prev));
|
||||
if (prev) {
|
||||
for (;;) {
|
||||
nsCOMPtr<nsIDOMNode> lastChild;
|
||||
prev->GetLastChild(getter_AddRefs(lastChild));
|
||||
if (!lastChild)
|
||||
return prev;
|
||||
prev = lastChild;
|
||||
}
|
||||
}
|
||||
|
||||
// No prev sibling. So we are the first child of our parent, if any. Our
|
||||
// parent is our previous node.
|
||||
aNode->GetParentNode(getter_AddRefs(prev));
|
||||
return prev;
|
||||
return aNode->IsElement() &&
|
||||
aNode->AsElement()->IsHTML(nsGkAtoms::br);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -458,7 +414,7 @@ FindPrevNode(nsIDOMNode* aNode, nsIDOMNode* aRoot)
|
||||
* This function does not modify aSeparatorOffset when it returns false.
|
||||
*/
|
||||
static bool
|
||||
ContainsDOMWordSeparator(nsIDOMNode* aNode, PRInt32 aBeforeOffset,
|
||||
ContainsDOMWordSeparator(nsINode* aNode, PRInt32 aBeforeOffset,
|
||||
PRInt32* aSeparatorOffset)
|
||||
{
|
||||
if (IsBRElement(aNode)) {
|
||||
@ -469,8 +425,8 @@ ContainsDOMWordSeparator(nsIDOMNode* aNode, PRInt32 aBeforeOffset,
|
||||
if (!IsTextNode(aNode))
|
||||
return false;
|
||||
|
||||
nsCOMPtr<nsIContent> content = do_QueryInterface(aNode);
|
||||
NS_ASSERTION(content, "Where is our content?");
|
||||
// aNode is actually an nsIContent, since it's eTEXT
|
||||
nsIContent* content = static_cast<nsIContent*>(aNode);
|
||||
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) {
|
||||
@ -491,14 +447,13 @@ ContainsDOMWordSeparator(nsIDOMNode* aNode, PRInt32 aBeforeOffset,
|
||||
}
|
||||
|
||||
static bool
|
||||
IsBreakElement(nsIDOMNode* aNode)
|
||||
IsBreakElement(nsINode* aNode)
|
||||
{
|
||||
nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
|
||||
if (!node->IsElement()) {
|
||||
if (!aNode->IsElement()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
dom::Element *element = node->AsElement();
|
||||
dom::Element *element = aNode->AsElement();
|
||||
|
||||
if (element->IsHTML(nsGkAtoms::br))
|
||||
return true;
|
||||
@ -519,7 +474,7 @@ struct CheckLeavingBreakElementClosure {
|
||||
};
|
||||
|
||||
static void
|
||||
CheckLeavingBreakElement(nsIDOMNode* aNode, void* aClosure)
|
||||
CheckLeavingBreakElement(nsINode* aNode, void* aClosure)
|
||||
{
|
||||
CheckLeavingBreakElementClosure* cl =
|
||||
static_cast<CheckLeavingBreakElementClosure*>(aClosure);
|
||||
@ -543,7 +498,7 @@ mozInlineSpellWordUtil::BuildSoftText()
|
||||
// containing a DOM word separator, a non-inline-element
|
||||
// boundary, or the hard start node. That's where we'll start building the
|
||||
// soft string from.
|
||||
nsIDOMNode* node = mSoftBegin.mNode;
|
||||
nsINode* node = mSoftBegin.mNode;
|
||||
PRInt32 firstOffsetInNode = 0;
|
||||
PRInt32 checkBeforeOffset = mSoftBegin.mOffset;
|
||||
while (node) {
|
||||
@ -568,12 +523,12 @@ mozInlineSpellWordUtil::BuildSoftText()
|
||||
}
|
||||
checkBeforeOffset = PR_INT32_MAX;
|
||||
if (IsBreakElement(node)) {
|
||||
// Since FindPrevNode follows tree *preorder*, we're about to traverse
|
||||
// Since GetPreviousContent follows tree *preorder*, we're about to traverse
|
||||
// up out of 'node'. Since node induces breaks (e.g., it's a block),
|
||||
// don't bother trying to look outside it, just stop now.
|
||||
break;
|
||||
}
|
||||
node = FindPrevNode(node, mRootNode);
|
||||
node = node->GetPreviousContent(mRootNode);
|
||||
}
|
||||
|
||||
// Now build up the string moving forward through the DOM until we reach
|
||||
@ -591,7 +546,7 @@ mozInlineSpellWordUtil::BuildSoftText()
|
||||
|
||||
bool exit = false;
|
||||
if (IsTextNode(node)) {
|
||||
nsCOMPtr<nsIContent> content = do_QueryInterface(node);
|
||||
nsIContent* content = static_cast<nsIContent*>(node);
|
||||
NS_ASSERTION(content, "Where is our content?");
|
||||
const nsTextFragment* textFragment = content->GetText();
|
||||
NS_ASSERTION(textFragment, "Where is our text?");
|
||||
|
@ -44,8 +44,8 @@
|
||||
|
||||
//#define DEBUG_SPELLCHECK
|
||||
|
||||
class nsIDOMRange;
|
||||
class nsIDOMNode;
|
||||
class nsIRange;
|
||||
class nsINode;
|
||||
|
||||
/**
|
||||
* This class extracts text from the DOM and builds it into a single string.
|
||||
@ -71,10 +71,10 @@ class mozInlineSpellWordUtil
|
||||
{
|
||||
public:
|
||||
struct NodeOffset {
|
||||
nsIDOMNode* mNode;
|
||||
PRInt32 mOffset;
|
||||
nsINode* mNode;
|
||||
PRInt32 mOffset;
|
||||
|
||||
NodeOffset(nsIDOMNode* aNode, PRInt32 aOffset) :
|
||||
NodeOffset(nsINode* aNode, PRInt32 aOffset) :
|
||||
mNode(aNode), mOffset(aOffset) {}
|
||||
};
|
||||
|
||||
@ -85,11 +85,11 @@ public:
|
||||
|
||||
nsresult Init(nsWeakPtr aWeakEditor);
|
||||
|
||||
nsresult SetEnd(nsIDOMNode* aEndNode, PRInt32 aEndOffset);
|
||||
nsresult SetEnd(nsINode* aEndNode, PRInt32 aEndOffset);
|
||||
|
||||
// sets the current position, this should be inside the range. If we are in
|
||||
// the middle of a word, we'll move to its start.
|
||||
nsresult SetPosition(nsIDOMNode* aNode, PRInt32 aOffset);
|
||||
nsresult SetPosition(nsINode* aNode, PRInt32 aOffset);
|
||||
|
||||
// Given a point inside or immediately following a word, this returns the
|
||||
// DOM range that exactly encloses that word's characters. The current
|
||||
@ -101,13 +101,13 @@ public:
|
||||
// before you actually generate the range you are interested in and iterate
|
||||
// the words in it.
|
||||
nsresult GetRangeForWord(nsIDOMNode* aWordNode, PRInt32 aWordOffset,
|
||||
nsIDOMRange** aRange);
|
||||
nsIRange** aRange);
|
||||
|
||||
// Moves to the the next word in the range, and retrieves it's text and range.
|
||||
// An empty word and a NULL range are returned when we are done checking.
|
||||
// aSkipChecking will be set if the word is "special" and shouldn't be
|
||||
// checked (e.g., an email address).
|
||||
nsresult GetNextWord(nsAString& aText, nsIDOMRange** aRange,
|
||||
nsresult GetNextWord(nsAString& aText, nsIRange** aRange,
|
||||
bool* aSkipChecking);
|
||||
|
||||
// Call to normalize some punctuation. This function takes an autostring
|
||||
@ -116,7 +116,7 @@ public:
|
||||
|
||||
nsIDOMDocument* GetDOMDocument() const { return mDOMDocument; }
|
||||
nsIDocument* GetDocument() const { return mDocument; }
|
||||
nsIDOMNode* GetRootNode() { return mRootNode; }
|
||||
nsINode* GetRootNode() { return mRootNode; }
|
||||
nsIUGenCategory* GetCategories() { return mCategories; }
|
||||
|
||||
private:
|
||||
@ -126,8 +126,8 @@ private:
|
||||
nsCOMPtr<nsIDocument> mDocument;
|
||||
nsCOMPtr<nsIUGenCategory> mCategories;
|
||||
|
||||
// range to check, see SetRange
|
||||
nsIDOMNode* mRootNode;
|
||||
// range to check, see SetPosition and SetEnd
|
||||
nsINode* mRootNode;
|
||||
NodeOffset mSoftBegin;
|
||||
NodeOffset mSoftEnd;
|
||||
|
||||
@ -191,6 +191,6 @@ private:
|
||||
void SplitDOMWord(PRInt32 aStart, PRInt32 aEnd);
|
||||
|
||||
// Convenience functions, object must be initialized
|
||||
nsresult MakeRange(NodeOffset aBegin, NodeOffset aEnd, nsIDOMRange** aRange);
|
||||
nsresult MakeRangeForWord(const RealWord& aWord, nsIDOMRange** aRange);
|
||||
nsresult MakeRange(NodeOffset aBegin, NodeOffset aEnd, nsIRange** aRange);
|
||||
nsresult MakeRangeForWord(const RealWord& aWord, nsIRange** aRange);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user