Bug 344560 and 345112 r=bryner a=schrep Make the spellchecker asynchronos to avoid DOM notification flush when called from frame code
git-svn-id: svn://10.0.0.236/branches/MOZILLA_1_8_BRANCH@206604 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -39,6 +39,8 @@
|
||||
#ifndef __mozinlinespellchecker_h__
|
||||
#define __mozinlinespellchecker_h__
|
||||
|
||||
#include "nsAutoPtr.h"
|
||||
#include "nsIDOMRange.h"
|
||||
#include "nsIEditorSpellCheck.h"
|
||||
#include "nsIEditActionListener.h"
|
||||
#include "nsIInlineSpellChecker.h"
|
||||
@@ -51,13 +53,97 @@
|
||||
#include "nsWeakReference.h"
|
||||
#include "mozISpellI18NUtil.h"
|
||||
|
||||
class nsIDOMDocumentRange;
|
||||
class nsIDOMMouseEventListener;
|
||||
class nsIEventQueueService;
|
||||
class mozInlineSpellWordUtil;
|
||||
class mozInlineSpellChecker;
|
||||
class mozInlineSpellResume;
|
||||
|
||||
class mozInlineSpellStatus
|
||||
{
|
||||
public:
|
||||
mozInlineSpellStatus(mozInlineSpellChecker* aSpellChecker);
|
||||
|
||||
nsresult InitForEditorChange(PRInt32 aAction,
|
||||
nsIDOMNode* aAnchorNode, PRInt32 aAnchorOffset,
|
||||
nsIDOMNode* aPreviousNode, PRInt32 aPreviousOffset,
|
||||
nsIDOMNode* aStartNode, PRInt32 aStartOffset,
|
||||
nsIDOMNode* aEndNode, PRInt32 aEndOffset);
|
||||
nsresult InitForNavigation(PRBool aForceCheck, PRInt32 aNewPositionOffset,
|
||||
nsIDOMNode* aOldAnchorNode, PRInt32 aOldAnchorOffset,
|
||||
nsIDOMNode* aNewAnchorNode, PRInt32 aNewAnchorOffset,
|
||||
PRBool* aContinue);
|
||||
nsresult InitForSelection();
|
||||
nsresult InitForRange(nsIDOMRange* aRange);
|
||||
|
||||
nsresult FinishInitOnEvent(mozInlineSpellWordUtil& aWordUtil);
|
||||
|
||||
nsRefPtr<mozInlineSpellChecker> mSpellChecker;
|
||||
|
||||
// The total number of words checked in this sequence, using this tally tells
|
||||
// us when to stop. This count is preserved as we continue checking in new
|
||||
// messages.
|
||||
PRInt32 mWordCount;
|
||||
|
||||
// what happened?
|
||||
enum Operation { eOpChange, // for SpellCheckAfterChange except kOpDeleteSelection
|
||||
eOpChangeDelete, // for SpellCheckAfterChange kOpDeleteSelection
|
||||
eOpNavigation, // for HandleNavigationEvent
|
||||
eOpSelection, // re-check all misspelled words
|
||||
eOpResume }; // for resuming a previously started check
|
||||
Operation mOp;
|
||||
|
||||
// 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;
|
||||
|
||||
// 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;
|
||||
|
||||
// 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
|
||||
// (such as for the intial check of everything).
|
||||
//
|
||||
// For mOp == eOpNavigation, this is the NEW position of the cursor
|
||||
nsCOMPtr<nsIDOMRange> mAnchorRange;
|
||||
|
||||
// -----
|
||||
// The following members are only for navigation events and are only
|
||||
// stored for FinishNavigationEvent to initialize the other members.
|
||||
// -----
|
||||
|
||||
// this is the OLD position of the cursor
|
||||
nsCOMPtr<nsIDOMRange> mOldNavigationAnchorRange;
|
||||
|
||||
// Set when we should force checking the current word. See
|
||||
// mozInlineSpellChecker::HandleNavigationEvent for a description of why we
|
||||
// have this.
|
||||
PRBool mForceNavigationWordCheck;
|
||||
|
||||
// Contains the offset passed in to HandleNavigationEvent
|
||||
PRInt32 mNewNavigationPositionOffset;
|
||||
|
||||
protected:
|
||||
nsresult FinishNavigationEvent(mozInlineSpellWordUtil& aWordUtil);
|
||||
|
||||
nsresult FillNoCheckRangeFromAnchor(mozInlineSpellWordUtil& aWordUtil);
|
||||
|
||||
nsresult GetDocumentRange(nsIDOMDocumentRange** aDocRange);
|
||||
nsresult PositionToCollapsedRange(nsIDOMDocumentRange* aDocRange,
|
||||
nsIDOMNode* aNode, PRInt32 aOffset,
|
||||
nsIDOMRange** aRange);
|
||||
};
|
||||
|
||||
class mozInlineSpellChecker : public nsIInlineSpellChecker, nsIEditActionListener, nsIDOMMouseListener, nsIDOMKeyListener,
|
||||
nsSupportsWeakReference
|
||||
{
|
||||
private:
|
||||
friend class mozInlineSpellStatus;
|
||||
|
||||
// Access with CanEnableInlineSpellChecking
|
||||
enum SpellCheckingState { SpellCheck_Uninitialized = -1,
|
||||
@@ -74,11 +160,25 @@ private:
|
||||
PRInt32 mNumWordsInSpellSelection;
|
||||
PRInt32 mMaxNumWordsInSpellSelection;
|
||||
|
||||
// How many misspellings we can add at once. This is often less than the max
|
||||
// total number of misspellings. When you have a large textarea prepopulated
|
||||
// with text with many misspellings, we can hit this limit. By making it
|
||||
// lower than the total number of misspelled words, new text typed by the
|
||||
// user can also have spellchecking in it.
|
||||
PRInt32 mMaxMisspellingsPerCheck;
|
||||
|
||||
// we need to keep track of the current text position in the document
|
||||
// so we can spell check the old word when the user clicks around the document.
|
||||
nsCOMPtr<nsIDOMNode> mCurrentSelectionAnchorNode;
|
||||
PRInt32 mCurrentSelectionOffset;
|
||||
|
||||
// Set when we have spellchecked after the last edit operation. See the
|
||||
// commment at the top of the .cpp file for more info.
|
||||
PRBool mNeedsCheckAfterNavigation;
|
||||
|
||||
// lazily created, may be NULL
|
||||
nsCOMPtr<nsIEventQueueService> mEventQueueService;
|
||||
|
||||
// TODO: these should be defined somewhere so that they don't have to be copied
|
||||
// from editor!
|
||||
enum OperationID
|
||||
@@ -147,15 +247,14 @@ public:
|
||||
mozInlineSpellChecker();
|
||||
virtual ~mozInlineSpellChecker();
|
||||
|
||||
// spell check the selected text specified by aSelection
|
||||
nsresult SpellCheckSelection(nsISelection *aSelection);
|
||||
// re-spellcheck the currently marked ranges
|
||||
nsresult SpellCheckSelection();
|
||||
|
||||
// spell checks all of the words between two nodes
|
||||
nsresult SpellCheckBetweenNodes(nsIDOMNode *aStartNode,
|
||||
PRInt32 aStartOffset,
|
||||
nsIDOMNode *aEndNode,
|
||||
PRInt32 aEndOffset,
|
||||
nsISelection *aSpellCheckSelection);
|
||||
PRInt32 aEndOffset);
|
||||
|
||||
// examines the dom node in question and returns true if the inline spell
|
||||
// checker should skip the node (i.e. the text is inside of a block quote
|
||||
@@ -166,25 +265,34 @@ public:
|
||||
nsIDOMNode* aPreviousNode, PRInt32 aPreviousOffset,
|
||||
nsISelection* aSpellCheckSelection);
|
||||
|
||||
// spell check the text contained within aRange
|
||||
// spell check the text contained within aRange, potentially scheduling
|
||||
// another check in the future if the time threshold is reached
|
||||
nsresult ScheduleSpellCheck(const mozInlineSpellStatus& aStatus);
|
||||
|
||||
nsresult DoSpellCheckSelection(mozInlineSpellWordUtil& aWordUtil,
|
||||
nsISelection* aSpellCheckSelection,
|
||||
mozInlineSpellStatus* aStatus);
|
||||
nsresult DoSpellCheck(mozInlineSpellWordUtil& aWordUtil,
|
||||
nsIDOMRange *aRange, nsIDOMRange* aNoCheckRange,
|
||||
nsIDOMRange *aCreatedRange,
|
||||
nsISelection *aSpellCheckSelection);
|
||||
nsISelection *aSpellCheckSelection,
|
||||
mozInlineSpellStatus* aStatus,
|
||||
PRBool* aDoneChecking);
|
||||
|
||||
// helper routine to determine if a point is inside of a the passed in selection.
|
||||
nsresult IsPointInSelection(nsISelection *aSelection,
|
||||
nsIDOMNode *aNode,
|
||||
PRInt32 aOffset,
|
||||
nsIDOMRange **aRange);
|
||||
|
||||
|
||||
nsresult CleanupRangesInSelection(nsISelection *aSelection);
|
||||
|
||||
// helper routines used to control how many ranges we allow into the spell check selection
|
||||
nsresult RemoveRange(nsISelection *aSpellCheckSelection, nsIDOMRange * aRange);
|
||||
nsresult AddRange(nsISelection *aSpellCheckSelection, nsIDOMRange * aRange);
|
||||
PRBool SpellCheckSelectionIsFull() { return mNumWordsInSpellSelection >= mMaxNumWordsInSpellSelection; }
|
||||
|
||||
nsresult MakeSpellCheckRange(nsIDOMNode* aStartNode, PRInt32 aStartOffset,
|
||||
nsIDOMNode* aEndNode, PRInt32 aEndOffset,
|
||||
nsIDOMRange** aRange);
|
||||
|
||||
// DOM and editor event registration helper routines
|
||||
nsresult RegisterEventListeners();
|
||||
nsresult UnregisterEventListeners();
|
||||
@@ -192,6 +300,8 @@ public:
|
||||
|
||||
nsresult GetSpellCheckSelection(nsISelection ** aSpellCheckSelection);
|
||||
nsresult SaveCurrentSelectionPosition();
|
||||
|
||||
nsresult ResumeCheck(mozInlineSpellStatus* resume);
|
||||
};
|
||||
|
||||
#endif /* __mozinlinespellchecker_h__ */
|
||||
|
||||
@@ -241,17 +241,6 @@ mozInlineSpellWordUtil::SetEnd(nsIDOMNode* aEndNode, PRInt32 aEndOffset)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
// mozInlineSpellWordUtil::ExpandFor
|
||||
|
||||
nsresult
|
||||
mozInlineSpellWordUtil::ExpandFor(nsIDOMNode* aBeginNode, PRInt32 aBeginOffset,
|
||||
nsIDOMNode* aEndNode, PRInt32 aEndOffset)
|
||||
{
|
||||
// InvalidateWords();
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
nsresult
|
||||
mozInlineSpellWordUtil::SetPosition(nsIDOMNode* aNode, PRInt32 aOffset)
|
||||
{
|
||||
|
||||
@@ -88,10 +88,6 @@ public:
|
||||
|
||||
nsresult SetEnd(nsIDOMNode* aEndNode, PRInt32 aEndOffset);
|
||||
|
||||
// expands the current range to incorporate this new range
|
||||
nsresult ExpandFor(nsIDOMNode* aBeginNode, PRInt32 aBeginOffset,
|
||||
nsIDOMNode* 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);
|
||||
|
||||
Reference in New Issue
Block a user