Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Static Public Member Functions | Public Attributes | Private Types | Private Member Functions | Private Attributes | Static Private Attributes | Friends
mozInlineSpellChecker Class Reference

#include <mozInlineSpellChecker.h>

Inheritance diagram for mozInlineSpellChecker:
Inheritance graph
[legend]
Collaboration diagram for mozInlineSpellChecker:
Collaboration graph
[legend]

List of all members.

Public Member Functions

NS_IMETHOD HandleEvent (nsIDOMEvent *aEvent)
NS_IMETHOD MouseDown (nsIDOMEvent *aMouseEvent)
 Processes a mouse down event.
NS_IMETHOD MouseUp (nsIDOMEvent *aMouseEvent)
 Processes a mouse up event.
NS_IMETHOD MouseClick (nsIDOMEvent *aMouseEvent)
 Processes a mouse click event.
NS_IMETHOD MouseDblClick (nsIDOMEvent *aMouseEvent)
 Processes a mouse click event.
NS_IMETHOD MouseOver (nsIDOMEvent *aMouseEvent)
 Processes a mouse enter event.
NS_IMETHOD MouseOut (nsIDOMEvent *aMouseEvent)
 Processes a mouse leave event.
NS_IMETHOD KeyDown (nsIDOMEvent *aKeyEvent)
 Processes a key pressed event.
NS_IMETHOD KeyUp (nsIDOMEvent *aKeyEvent)
 Processes a key release event.
NS_IMETHOD KeyPress (nsIDOMEvent *aKeyEvent)
 Processes a key typed event.
 mozInlineSpellChecker ()
virtual ~mozInlineSpellChecker ()
nsresult SpellCheckSelection ()
nsresult SpellCheckBetweenNodes (nsIDOMNode *aStartNode, PRInt32 aStartOffset, nsIDOMNode *aEndNode, PRInt32 aEndOffset)
nsresult SkipSpellCheckForNode (nsIEditor *aEditor, nsIDOMNode *aNode, PRBool *aCheckSpelling)
nsresult SpellCheckAfterChange (nsIDOMNode *aCursorNode, PRInt32 aCursorOffset, nsIDOMNode *aPreviousNode, PRInt32 aPreviousOffset, nsISelection *aSpellCheckSelection)
nsresult ScheduleSpellCheck (const mozInlineSpellStatus &aStatus)
nsresult DoSpellCheckSelection (mozInlineSpellWordUtil &aWordUtil, nsISelection *aSpellCheckSelection, mozInlineSpellStatus *aStatus)
nsresult DoSpellCheck (mozInlineSpellWordUtil &aWordUtil, nsISelection *aSpellCheckSelection, mozInlineSpellStatus *aStatus, PRBool *aDoneChecking)
nsresult IsPointInSelection (nsISelection *aSelection, nsIDOMNode *aNode, PRInt32 aOffset, nsIDOMRange **aRange)
nsresult CleanupRangesInSelection (nsISelection *aSelection)
nsresult RemoveRange (nsISelection *aSpellCheckSelection, nsIDOMRange *aRange)
nsresult AddRange (nsISelection *aSpellCheckSelection, nsIDOMRange *aRange)
PRBool SpellCheckSelectionIsFull ()
nsresult MakeSpellCheckRange (nsIDOMNode *aStartNode, PRInt32 aStartOffset, nsIDOMNode *aEndNode, PRInt32 aEndOffset, nsIDOMRange **aRange)
nsresult RegisterEventListeners ()
nsresult UnregisterEventListeners ()
nsresult HandleNavigationEvent (nsIDOMEvent *aEvent, PRBool aForceWordSpellCheck, PRInt32 aNewPositionOffset=0)
nsresult GetSpellCheckSelection (nsISelection **aSpellCheckSelection)
nsresult SaveCurrentSelectionPosition ()
nsresult ResumeCheck (mozInlineSpellStatus *resume)
void init (in nsIEditor aEditor)
void cleanup ()
void spellCheckAfterEditorChange (in long aAction, in nsISelection aSelection, in nsIDOMNode aPreviousSelectedNode, in long aPreviousSelectedOffset, in nsIDOMNode aStartNode, in long aStartOffset, in nsIDOMNode aEndNode, in long aEndOffset)
void spellCheckRange (in nsIDOMRange aSelection)
nsIDOMRange getMispelledWord (in nsIDOMNode aNode, in long aOffset)
void replaceWord (in nsIDOMNode aNode, in long aOffset, in AString aNewword)
void addWordToDictionary (in AString aWord)
void ignoreWord (in AString aWord)
void ignoreWords ([array, size_is(aCount)] in wstring aWordsToIgnore, in unsigned long aCount)

Static Public Member Functions

NS_DECL_ISUPPORTS
NS_DECL_NSIEDITACTIONLISTENER
static
NS_DECL_NSIINLINESPELLCHECKER
PRBool 
CanEnableInlineSpellChecking ()

Public Attributes

readonly attribute
nsIEditorSpellCheck 
spellChecker
attribute boolean enableRealTimeSpell

Private Types

enum  SpellCheckingState { SpellCheck_Uninitialized = -1, SpellCheck_NotAvailable = 0, SpellCheck_Available = 1 }
enum  OperationID {
  kOpIgnore = -1, kOpNone = 0, kOpUndo, kOpRedo,
  kOpInsertNode, kOpCreateNode, kOpDeleteNode, kOpSplitNode,
  kOpJoinNode, kOpDeleteSelection, kOpInsertBreak = 1000, kOpInsertText = 1001,
  kOpInsertIMEText = 1002, kOpDeleteText = 1003, kOpMakeList = 3001, kOpIndent = 3002,
  kOpOutdent = 3003, kOpAlign = 3004, kOpMakeBasicBlock = 3005, kOpRemoveList = 3006,
  kOpMakeDefListItem = 3007, kOpInsertElement = 3008, kOpInsertQuotation = 3009, kOpSetTextProperty = 3010,
  kOpRemoveTextProperty = 3011, kOpHTMLPaste = 3012, kOpLoadHTML = 3013, kOpResetTextProperties = 3014,
  kOpSetAbsolutePosition = 3015, kOpRemoveAbsolutePosition = 3016, kOpDecreaseZIndex = 3017, kOpIncreaseZIndex = 3018
}

Private Member Functions

void WillCreateNode (in DOMString aTag, in nsIDOMNode aParent, in long aPosition)
 Called before the editor creates a node.
void DidCreateNode (in DOMString aTag, in nsIDOMNode aNode, in nsIDOMNode aParent, in long aPosition, in nsresult aResult)
 Called after the editor creates a node.
void WillInsertNode (in nsIDOMNode aNode, in nsIDOMNode aParent, in long aPosition)
 Called before the editor inserts a node.
void DidInsertNode (in nsIDOMNode aNode, in nsIDOMNode aParent, in long aPosition, in nsresult aResult)
 Called after the editor inserts a node.
void WillDeleteNode (in nsIDOMNode aChild)
 Called before the editor deletes a node.
void DidDeleteNode (in nsIDOMNode aChild, in nsresult aResult)
 Called after the editor deletes a node.
void WillSplitNode (in nsIDOMNode aExistingRightNode, in long aOffset)
 Called before the editor splits a node.
void DidSplitNode (in nsIDOMNode aExistingRightNode, in long aOffset, in nsIDOMNode aNewLeftNode, in nsresult aResult)
 Called after the editor splits a node.
void WillJoinNodes (in nsIDOMNode aLeftNode, in nsIDOMNode aRightNode, in nsIDOMNode aParent)
 Called before the editor joins 2 nodes.
void DidJoinNodes (in nsIDOMNode aLeftNode, in nsIDOMNode aRightNode, in nsIDOMNode aParent, in nsresult aResult)
 Called after the editor joins 2 nodes.
void WillInsertText (in nsIDOMCharacterData aTextNode, in long aOffset, in DOMString aString)
 Called before the editor inserts text.
void DidInsertText (in nsIDOMCharacterData aTextNode, in long aOffset, in DOMString aString, in nsresult aResult)
 Called after the editor inserts text.
void WillDeleteText (in nsIDOMCharacterData aTextNode, in long aOffset, in long aLength)
 Called before the editor deletes text.
void DidDeleteText (in nsIDOMCharacterData aTextNode, in long aOffset, in long aLength, in nsresult aResult)
 Called before the editor deletes text.
void WillDeleteSelection (in nsISelection aSelection)
 Called before the editor deletes the selection.
void DidDeleteSelection (in nsISelection aSelection)
 Called after the editor deletes the selection.
void handleEvent (in nsIDOMEvent event)
 This method is called whenever an event occurs of the type for which the EventListener interface was registered.

Private Attributes

nsWeakPtr mEditor
nsCOMPtr< nsIEditorSpellCheckmSpellCheck
nsCOMPtr< nsITextServicesDocumentmTextServicesDocument
nsCOMPtr< nsIDOMTreeWalkermTreeWalker
nsCOMPtr< mozISpellI18NUtilmConverter
PRInt32 mNumWordsInSpellSelection
PRInt32 mMaxNumWordsInSpellSelection
PRInt32 mMaxMisspellingsPerCheck
nsCOMPtr< nsIDOMNodemCurrentSelectionAnchorNode
PRInt32 mCurrentSelectionOffset
PRBool mNeedsCheckAfterNavigation
nsCOMPtr< nsIEventQueueServicemEventQueueService

Static Private Attributes

static SpellCheckingState gCanEnableSpellChecking

Friends

class mozInlineSpellStatus

Detailed Description

Definition at line 142 of file mozInlineSpellChecker.h.


Member Enumeration Documentation

Enumerator:
kOpIgnore 
kOpNone 
kOpUndo 
kOpRedo 
kOpInsertNode 
kOpCreateNode 
kOpDeleteNode 
kOpSplitNode 
kOpJoinNode 
kOpDeleteSelection 
kOpInsertBreak 
kOpInsertText 
kOpInsertIMEText 
kOpDeleteText 
kOpMakeList 
kOpIndent 
kOpOutdent 
kOpAlign 
kOpMakeBasicBlock 
kOpRemoveList 
kOpMakeDefListItem 
kOpInsertElement 
kOpInsertQuotation 
kOpSetTextProperty 
kOpRemoveTextProperty 
kOpHTMLPaste 
kOpLoadHTML 
kOpResetTextProperties 
kOpSetAbsolutePosition 
kOpRemoveAbsolutePosition 
kOpDecreaseZIndex 
kOpIncreaseZIndex 

Definition at line 184 of file mozInlineSpellChecker.h.

Enumerator:
SpellCheck_Uninitialized 
SpellCheck_NotAvailable 
SpellCheck_Available 

Definition at line 149 of file mozInlineSpellChecker.h.


Constructor & Destructor Documentation

Definition at line 577 of file mozInlineSpellChecker.cpp.

{
}

Member Function Documentation

nsresult mozInlineSpellChecker::AddRange ( nsISelection aSpellCheckSelection,
nsIDOMRange aRange 
)

Definition at line 1578 of file mozInlineSpellChecker.cpp.

{
  NS_ENSURE_ARG_POINTER(aSpellCheckSelection);
  NS_ENSURE_ARG_POINTER(aRange);

  nsresult rv = NS_OK;

  if (!SpellCheckSelectionIsFull())
  {
    rv = aSpellCheckSelection->AddRange(aRange);
    if (NS_SUCCEEDED(rv))
      mNumWordsInSpellSelection++;
  }

  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsIInlineSpellChecker::addWordToDictionary ( in AString  aWord) [inherited]

Definition at line 638 of file mozInlineSpellChecker.cpp.

{
  nsresult rv;
  if (gCanEnableSpellChecking == SpellCheck_Uninitialized) {
    gCanEnableSpellChecking = SpellCheck_NotAvailable;

    nsCOMPtr<nsIEditorSpellCheck> spellchecker =
      do_CreateInstance("@mozilla.org/editor/editorspellchecker;1", &rv);
    NS_ENSURE_SUCCESS(rv, PR_FALSE);

    PRBool canSpellCheck = PR_TRUE;
    nsCOMPtr<nsIEditorSpellCheck_MOZILLA_1_8_BRANCH> spellcheckerBranch =
      do_QueryInterface(spellchecker, &rv);
    if (NS_SUCCEEDED(rv)) {
      rv = spellcheckerBranch->CanSpellCheck(&canSpellCheck);
      NS_ENSURE_SUCCESS(rv, PR_FALSE);
    }

    if (canSpellCheck)
      gCanEnableSpellChecking = SpellCheck_Available;
  }
  return (gCanEnableSpellChecking == SpellCheck_Available);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1519 of file mozInlineSpellChecker.cpp.

{
  // integrity check - remove ranges that have collapsed to nothing. This
  // can happen if the node containing a highlighted word was removed.
  NS_ENSURE_ARG_POINTER(aSelection);

  PRInt32 count;
  aSelection->GetRangeCount(&count);

  for (PRInt32 index = 0; index < count; index++)
  {
    nsCOMPtr<nsIDOMRange> checkRange;
    aSelection->GetRangeAt(index, getter_AddRefs(checkRange));

    if (checkRange)
    {
      PRBool collapsed;
      checkRange->GetCollapsed(&collapsed);
      if (collapsed)
      {
        RemoveRange(aSelection, checkRange);
        index--;
        count--;
      }
    }
  }

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsIEditActionListener::DidCreateNode ( in DOMString  aTag,
in nsIDOMNode  aNode,
in nsIDOMNode  aParent,
in long  aPosition,
in nsresult  aResult 
) [inherited]

Called after the editor creates a node.

Parameters:
aTagThe tag name of the DOM Node to create.
aNodeThe DOM Node that was created.
aParentThe node to insert the new object into
aPositionThe place in aParent to insert the new node 0=first child, 1=second child, etc. any number > number of current children = last child
aResultThe result of the create node operation.
void nsIEditActionListener::DidDeleteNode ( in nsIDOMNode  aChild,
in nsresult  aResult 
) [inherited]

Called after the editor deletes a node.

Parameters:
aChildThe node to delete
aResultThe result of the delete node operation.

Called after the editor deletes the selection.

Parameters:
aSelectionThe selection, after deletion

Here is the caller graph for this function:

void nsIEditActionListener::DidDeleteText ( in nsIDOMCharacterData  aTextNode,
in long  aOffset,
in long  aLength,
in nsresult  aResult 
) [inherited]

Called before the editor deletes text.

Parameters:
aTextNodeThis node getting text deleted
aOffsetThe offset in aTextNode to delete at.
aLengthThe amount of text to delete.
aResultThe result of the delete text operation.

Here is the caller graph for this function:

void nsIEditActionListener::DidInsertNode ( in nsIDOMNode  aNode,
in nsIDOMNode  aParent,
in long  aPosition,
in nsresult  aResult 
) [inherited]

Called after the editor inserts a node.

Parameters:
aNodeThe DOM Node to insert.
aParentThe node to insert the new object into
aPositionThe place in aParent to insert the new node 0=first child, 1=second child, etc. any number > number of current children = last child
aResultThe result of the insert node operation.
void nsIEditActionListener::DidInsertText ( in nsIDOMCharacterData  aTextNode,
in long  aOffset,
in DOMString  aString,
in nsresult  aResult 
) [inherited]

Called after the editor inserts text.

Parameters:
aTextNodeThis node getting inserted text
aOffsetThe offset in aTextNode to insert at.
aStringThe string that gets inserted.
aResultThe result of the insert text operation.

Here is the caller graph for this function:

void nsIEditActionListener::DidJoinNodes ( in nsIDOMNode  aLeftNode,
in nsIDOMNode  aRightNode,
in nsIDOMNode  aParent,
in nsresult  aResult 
) [inherited]

Called after the editor joins 2 nodes.

Parameters:
aLeftNodeThis node will be merged into the right node
aRightNodeThe node that will be merged into. There is no requirement that the two nodes be of the same type.
aParentThe parent of aRightNode
aResultThe result of the join operation.
void nsIEditActionListener::DidSplitNode ( in nsIDOMNode  aExistingRightNode,
in long  aOffset,
in nsIDOMNode  aNewLeftNode,
in nsresult  aResult 
) [inherited]

Called after the editor splits a node.

Parameters:
aExistingRightNodethe node to split. It will become the new node's next sibling.
aOffsetthe offset of aExistingRightNode's content|children to do the split at
aNewLeftNode[OUT] the new node resulting from the split, becomes aExistingRightNode's previous sibling.
nsresult mozInlineSpellChecker::DoSpellCheck ( mozInlineSpellWordUtil aWordUtil,
nsISelection aSpellCheckSelection,
mozInlineSpellStatus aStatus,
PRBool aDoneChecking 
)

Definition at line 1289 of file mozInlineSpellChecker.cpp.

{
  nsCOMPtr<nsIDOMNode> beginNode, endNode;
  PRInt32 beginOffset, endOffset;
  *aDoneChecking = PR_TRUE;

  // get the editor for SkipSpellCheckForNode, this may fail in reasonable
  // circumstances since the editor could have gone away
  nsCOMPtr<nsIEditor> editor (do_QueryReferent(mEditor));
  if (! editor)
    return NS_ERROR_FAILURE;

  PRBool iscollapsed;
  nsresult rv = aStatus->mRange->GetCollapsed(&iscollapsed);
  NS_ENSURE_SUCCESS(rv, rv);
  if (iscollapsed)
    return NS_OK;

  nsCOMPtr<nsISelection2> sel2 = do_QueryInterface(aSpellCheckSelection, &rv);
  NS_ENSURE_SUCCESS(rv, rv);

  // see if the selection has any ranges, if not, then we can optimize checking
  // range inclusion later (we have no ranges when we are initially checking or
  // when there are no misspelled words yet).
  PRInt32 originalRangeCount;
  rv = aSpellCheckSelection->GetRangeCount(&originalRangeCount);
  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);

  // we need to use IsPointInRange which is on a more specific interface
  nsCOMPtr<nsIDOMNSRange> noCheckRange, createdRange;
  if (aStatus->mNoCheckRange)
    noCheckRange = do_QueryInterface(aStatus->mNoCheckRange);
  if (aStatus->mCreatedRange)
    createdRange = do_QueryInterface(aStatus->mCreatedRange);

  PRInt32 wordsSinceTimeCheck = 0;
  PRTime beginTime = PR_Now();

  nsAutoString wordText;
  nsCOMPtr<nsIDOMRange> wordRange;
  PRBool dontCheckWord;
  while (NS_SUCCEEDED(aWordUtil.GetNextWord(wordText,
                                            getter_AddRefs(wordRange),
                                            &dontCheckWord)) &&
         wordRange) {
    wordsSinceTimeCheck ++;

    // get the range for the current word
    wordRange->GetStartContainer(getter_AddRefs(beginNode));
    wordRange->GetEndContainer(getter_AddRefs(endNode));
    wordRange->GetStartOffset(&beginOffset);
    wordRange->GetEndOffset(&endOffset);

#ifdef DEBUG_INLINESPELL
    printf("->Got word \"%s\"", NS_ConvertUTF16toUTF8(wordText).get());
    if (dontCheckWord)
      printf(" (not checking)");
    printf("\n");
#endif

    // see if there is a spellcheck range that already intersects the word
    // and remove it. We only need to remove old ranges, so don't bother if
    // there were no ranges when we started out.
    if (originalRangeCount > 0) {
      // likewise, if this word is inside new text, we won't bother testing
      PRBool inCreatedRange = PR_FALSE;
      if (createdRange)
        createdRange->IsPointInRange(beginNode, beginOffset, &inCreatedRange);
      if (! inCreatedRange) {
        nsCOMArray<nsIDOMRange> ranges;
        rv = sel2->GetRangesForIntervalCOMArray(beginNode, beginOffset,
                                                endNode, endOffset,
                                                PR_TRUE, &ranges);
        NS_ENSURE_SUCCESS(rv, rv);
        for (PRInt32 i = 0; i < ranges.Count(); i ++)
          RemoveRange(aSpellCheckSelection, ranges[i]);
      }
    }

    // some words are special and don't need checking
    if (dontCheckWord)
      continue;

    // some nodes we don't spellcheck
    PRBool checkSpelling;
    rv = SkipSpellCheckForNode(editor, beginNode, &checkSpelling);
    NS_ENSURE_SUCCESS(rv, rv);
    if (!checkSpelling)
      continue;

    // Don't check spelling if we're inside the noCheckRange. This needs to
    // be done after we clear any old selection because the excluded word
    // might have been previously marked.
    //
    // We do a simple check to see if the beginning of our word is in the
    // exclusion range. Because the exclusion range is a multiple of a word,
    // this is sufficient.
    if (noCheckRange) {
      PRBool inExclusion = PR_FALSE;
      noCheckRange->IsPointInRange(beginNode, beginOffset, &inExclusion);
      if (inExclusion)
        continue;
    }

    NS_ENSURE_TRUE(mSpellCheck, NS_ERROR_NOT_INITIALIZED);

    // check spelling and add to selection if misspelled
    PRBool isMisspelled;
    aWordUtil.NormalizeWord(wordText);
    rv = mSpellCheck->CheckCurrentWordNoSuggest(wordText.get(), &isMisspelled);
    if (isMisspelled) {
      // misspelled words count extra toward the max
      wordsSinceTimeCheck += MISSPELLED_WORD_COUNT_PENALTY;
      AddRange(aSpellCheckSelection, wordRange);

      aStatus->mWordCount ++;
      if (aStatus->mWordCount >= mMaxMisspellingsPerCheck ||
          SpellCheckSelectionIsFull())
        break;
    }

    // see if we've run out of time, only check every N words for perf
    if (wordsSinceTimeCheck >= INLINESPELL_TIMEOUT_CHECK_FREQUENCY) {
      wordsSinceTimeCheck = 0;
      if (PR_Now() > beginTime + INLINESPELL_CHECK_TIMEOUT * PR_USEC_PER_MSEC) {
        // stop checking, our time limit has been exceeded

        // move the range to encompass the stuff that needs checking
        rv = aStatus->mRange->SetStart(endNode, endOffset);
        if (NS_FAILED(rv)) {
          // The range might be unhappy because the beginning is after the
          // end. This is possible when the requested end was in the middle
          // of a word, just ignore this situation and assume we're done.
          return NS_OK;
        }
        *aDoneChecking = PR_FALSE;
        return NS_OK;
      }
    }
  }

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1196 of file mozInlineSpellChecker.cpp.

{
  nsresult rv;

  // clear out mNumWordsInSpellSelection since we'll be rebuilding the ranges.
  mNumWordsInSpellSelection = 0;

  // Since we could be modifying the ranges for the spellCheckSelection while
  // looping on the spell check selection, keep a separate array of range
  // elements inside the selection
  nsCOMArray<nsIDOMRange> ranges;

  PRInt32 count;
  aSpellCheckSelection->GetRangeCount(&count);

  PRInt32 idx;
  nsCOMPtr<nsIDOMRange> checkRange;
  for (idx = 0; idx < count; idx ++) {
    aSpellCheckSelection->GetRangeAt(idx, getter_AddRefs(checkRange));
    if (checkRange) {
      if (! ranges.AppendObject(checkRange))
        return NS_ERROR_OUT_OF_MEMORY;
    }
  }

  // We have saved the ranges above. Clearing the spellcheck selection here
  // isn't necessary (rechecking each word will modify it as necessary) but
  // provides better performance. By ensuring that no ranges need to be
  // removed in DoSpellCheck, we can save checking range inclusion which is
  // slow.
  aSpellCheckSelection->RemoveAllRanges();

  // We use this state object for all calls, and just update its range. Note
  // that we don't need to call FinishInit since we will be filling in the
  // necessary information.
  mozInlineSpellStatus status(this);
  rv = status.InitForRange(nsnull);
  NS_ENSURE_SUCCESS(rv, rv);

  PRBool doneChecking;
  for (idx = 0; idx < count; idx ++) {
    checkRange = ranges[idx];
    if (checkRange) {
      // We can consider this word as "added" since we know it has no spell
      // 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;
      rv = DoSpellCheck(aWordUtil, aSpellCheckSelection, &status,
                        &doneChecking);
      NS_ENSURE_SUCCESS(rv, rv);
      NS_ASSERTION(doneChecking, "We gave the spellchecker one word, but it didn't finish checking?!?!");

      status.mWordCount = 0;
    }
  }

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1596 of file mozInlineSpellChecker.cpp.

{ 
  nsCOMPtr<nsIEditor> editor (do_QueryReferent(mEditor));
  NS_ENSURE_TRUE(editor, NS_ERROR_NULL_POINTER);

  nsCOMPtr<nsISelectionController> selcon;
  nsresult rv = editor->GetSelectionController(getter_AddRefs(selcon));
  NS_ENSURE_SUCCESS(rv, rv); 

  nsCOMPtr<nsISelection> spellCheckSelection;
  return selcon->GetSelection(nsISelectionController::SELECTION_SPELLCHECK, aSpellCheckSelection);
}

Here is the call graph for this function:

Here is the caller graph for this function:

This method is called whenever an event occurs of the type for which the EventListener interface was registered.

Parameters:
evtThe Event contains contextual information about the event. It also contains the stopPropagation and preventDefault methods which are used in determining the event's flow and default action.

Definition at line 1694 of file mozInlineSpellChecker.cpp.

{
  return NS_OK;
}
nsresult mozInlineSpellChecker::HandleNavigationEvent ( nsIDOMEvent aEvent,
PRBool  aForceWordSpellCheck,
PRInt32  aNewPositionOffset = 0 
)

Definition at line 1659 of file mozInlineSpellChecker.cpp.

{
  nsresult rv;

  // If we already handled the navigation event and there is no possibility
  // anything has changed since then, we don't have to do anything. This
  // optimization makes a noticable different when you hold down a navigation
  // key like Page Down.
  if (! mNeedsCheckAfterNavigation)
    return NS_OK;

  nsCOMPtr<nsIDOMNode> currentAnchorNode = mCurrentSelectionAnchorNode;
  PRInt32 currentAnchorOffset = mCurrentSelectionOffset;

  // now remember the new focus position resulting from the event
  rv = SaveCurrentSelectionPosition();
  NS_ENSURE_SUCCESS(rv, rv);

  PRBool shouldPost;
  mozInlineSpellStatus status(this);
  rv = status.InitForNavigation(aForceWordSpellCheck, aNewPositionOffset,
                                currentAnchorNode, currentAnchorOffset,
                                mCurrentSelectionAnchorNode, mCurrentSelectionOffset,
                                &shouldPost);
  NS_ENSURE_SUCCESS(rv, rv);
  if (shouldPost) {
    rv = ScheduleSpellCheck(status);
    NS_ENSURE_SUCCESS(rv, rv);
  }

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsIInlineSpellChecker::ignoreWord ( in AString  aWord) [inherited]
void nsIInlineSpellChecker::ignoreWords ( [array, size_is(aCount)] in wstring  aWordsToIgnore,
in unsigned long  aCount 
) [inherited]
void nsIInlineSpellChecker::init ( in nsIEditor  aEditor) [inherited]
nsresult mozInlineSpellChecker::IsPointInSelection ( nsISelection aSelection,
nsIDOMNode aNode,
PRInt32  aOffset,
nsIDOMRange **  aRange 
)

Definition at line 1493 of file mozInlineSpellChecker.cpp.

{
  *aRange = nsnull;

  nsresult rv;
  nsCOMPtr<nsISelection2> sel2 = do_QueryInterface(aSelection, &rv);
  NS_ENSURE_SUCCESS(rv, rv);

  nsCOMArray<nsIDOMRange> ranges;
  rv = sel2->GetRangesForIntervalCOMArray(aNode, aOffset, aNode, aOffset,
                                          PR_TRUE, &ranges);
  NS_ENSURE_SUCCESS(rv, rv);

  if (ranges.Count() == 0)
    return NS_OK; // no matches

  // there may be more than one range returned, and we don't know what do
  // do with that, so just get the first one
  NS_ADDREF(*aRange = ranges[0]);
  return NS_OK;
}

Here is the call graph for this function:

Processes a key pressed event.

Parameters:
aKeyEvent
See also:
nsIDOMEvent.h
Returns:
whether the event was consumed or ignored.
See also:
nsresult

Implements nsIDOMKeyListener.

Definition at line 1740 of file mozInlineSpellChecker.cpp.

{
  return NS_OK;
}

Processes a key typed event.

Parameters:
aKeyEvent
See also:
nsIDOMEvent.h
Returns:
whether the event was consumed or ignored.
See also:
nsresult

Implements nsIDOMKeyListener.

Definition at line 1752 of file mozInlineSpellChecker.cpp.

{
  nsCOMPtr<nsIDOMKeyEvent>keyEvent = do_QueryInterface(aKeyEvent);
  NS_ENSURE_TRUE(keyEvent, NS_OK);

  PRUint32 keyCode;
  keyEvent->GetKeyCode(&keyCode);

  // we only care about navigation keys that moved selection 
  switch (keyCode)
  {
    case nsIDOMKeyEvent::DOM_VK_RIGHT:
    case nsIDOMKeyEvent::DOM_VK_LEFT:
      HandleNavigationEvent(aKeyEvent, PR_FALSE, keyCode == nsIDOMKeyEvent::DOM_VK_RIGHT ? 1 : -1);
      break;
    case nsIDOMKeyEvent::DOM_VK_UP:
    case nsIDOMKeyEvent::DOM_VK_DOWN:
    case nsIDOMKeyEvent::DOM_VK_HOME:
    case nsIDOMKeyEvent::DOM_VK_END:
    case nsIDOMKeyEvent::DOM_VK_PAGE_UP:
    case nsIDOMKeyEvent::DOM_VK_PAGE_DOWN:
      HandleNavigationEvent(aKeyEvent, PR_TRUE /* force a spelling correction */);
      break;
  }

  return NS_OK;
}

Here is the call graph for this function:

Processes a key release event.

Parameters:
aKeyEvent
See also:
nsIDOMEvent.h
Returns:
whether the event was consumed or ignored.
See also:
nsresult

Implements nsIDOMKeyListener.

Definition at line 1746 of file mozInlineSpellChecker.cpp.

{
  return NS_OK;
}
nsresult mozInlineSpellChecker::MakeSpellCheckRange ( nsIDOMNode aStartNode,
PRInt32  aStartOffset,
nsIDOMNode aEndNode,
PRInt32  aEndOffset,
nsIDOMRange **  aRange 
)

Definition at line 1029 of file mozInlineSpellChecker.cpp.

{
  nsresult rv;
  *aRange = nsnull;

  nsCOMPtr<nsIEditor> editor (do_QueryReferent(mEditor));
  NS_ENSURE_TRUE(editor, NS_ERROR_NULL_POINTER);

  nsCOMPtr<nsIDOMDocument> doc;
  rv = editor->GetDocument(getter_AddRefs(doc));
  NS_ENSURE_SUCCESS(rv, rv);

  nsCOMPtr<nsIDOMDocumentRange> docrange = do_QueryInterface(doc);
  NS_ENSURE_TRUE(docrange, NS_ERROR_FAILURE);

  nsCOMPtr<nsIDOMRange> range;
  rv = docrange->CreateRange(getter_AddRefs(range));
  NS_ENSURE_SUCCESS(rv, rv);

  // possibly use full range of the editor
  nsCOMPtr<nsIDOMElement> rootElem;
  if (! aStartNode || ! aEndNode) {
    rv = editor->GetRootElement(getter_AddRefs(rootElem));
    NS_ENSURE_SUCCESS(rv, rv);

    aStartNode = rootElem;
    aStartOffset = 0;

    aEndNode = rootElem;
    aEndOffset = -1;
  }

  if (aEndOffset == -1) {
    nsCOMPtr<nsIDOMNodeList> childNodes;
    rv = aEndNode->GetChildNodes(getter_AddRefs(childNodes));
    NS_ENSURE_SUCCESS(rv, rv);

    PRUint32 childCount;
    rv = childNodes->GetLength(&childCount);
    NS_ENSURE_SUCCESS(rv, rv);

    aEndOffset = childCount;
  }

  // sometimes we are are requested to check an empty range (possibly an empty
  // document). This will result in assertions later.
  if (aStartNode == aEndNode && aStartOffset == aEndOffset)
    return NS_OK;

  rv = range->SetStart(aStartNode, aStartOffset);
  NS_ENSURE_SUCCESS(rv, rv);
  if (aEndOffset)
    rv = range->SetEnd(aEndNode, aEndOffset);
  else
    rv = range->SetEndAfter(aEndNode);
  NS_ENSURE_SUCCESS(rv, rv);

  range.swap(*aRange);
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Processes a mouse click event.

Parameters:
aMouseEvent
See also:
nsIDOMEvent.h
Returns:
whether the event was consumed or ignored.
See also:
nsresult

Implements nsIDOMMouseListener.

Definition at line 1699 of file mozInlineSpellChecker.cpp.

{
  nsCOMPtr<nsIDOMMouseEvent>mouseEvent = do_QueryInterface(aMouseEvent);
  NS_ENSURE_TRUE(mouseEvent, NS_OK);

  // ignore any errors from HandleNavigationEvent as we don't want to prevent 
  // anyone else from seeing this event.
  PRUint16 button;
  mouseEvent->GetButton(&button);
  if (button == 0)
    HandleNavigationEvent(mouseEvent, PR_FALSE);
  else
    HandleNavigationEvent(mouseEvent, PR_TRUE);
  return NS_OK;
}

Here is the call graph for this function:

Processes a mouse click event.

Parameters:
aMouseEvent
See also:
nsIDOMEvent.h
Returns:
whether the event was consumed or ignored.
See also:
nsresult

Implements nsIDOMMouseListener.

Definition at line 1725 of file mozInlineSpellChecker.cpp.

{
  return NS_OK;
}

Processes a mouse down event.

Parameters:
aMouseEvent
See also:
nsIDOMEvent.h
Returns:
whether the event was consumed or ignored.
See also:
nsresult

Implements nsIDOMMouseListener.

Definition at line 1715 of file mozInlineSpellChecker.cpp.

{
  return NS_OK;
}

Processes a mouse leave event.

Parameters:
aMouseEvent
See also:
nsIDOMEvent.h
Returns:
whether the event was consumed or ignored.
See also:
nsresult

Implements nsIDOMMouseListener.

Definition at line 1735 of file mozInlineSpellChecker.cpp.

{
  return NS_OK;
}

Processes a mouse enter event.

Parameters:
aMouseEvent
See also:
nsIDOMEvent.h
Returns:
whether the event was consumed or ignored.
See also:
nsresult

Implements nsIDOMMouseListener.

Definition at line 1730 of file mozInlineSpellChecker.cpp.

{
  return NS_OK;
}

Processes a mouse up event.

Parameters:
aMouseEvent
See also:
nsIDOMEvent.h
Returns:
whether the event was consumed or ignored.
See also:
nsresult

Implements nsIDOMMouseListener.

Definition at line 1720 of file mozInlineSpellChecker.cpp.

{
  return NS_OK;
}

Definition at line 668 of file mozInlineSpellChecker.cpp.

{
  nsCOMPtr<nsIEditor> editor (do_QueryReferent(mEditor));
  NS_ENSURE_TRUE(editor, NS_ERROR_NULL_POINTER);

  editor->AddEditActionListener(this);

  nsCOMPtr<nsIDOMDocument> doc;
  nsresult rv = editor->GetDocument(getter_AddRefs(doc));
  NS_ENSURE_SUCCESS(rv, rv); 

  nsCOMPtr<nsIDOMEventReceiver> eventReceiver = do_QueryInterface(doc, &rv);
  NS_ENSURE_SUCCESS(rv, rv); 

  eventReceiver->AddEventListenerByIID(NS_STATIC_CAST(nsIDOMMouseListener*, this), NS_GET_IID(nsIDOMMouseListener));
  eventReceiver->AddEventListenerByIID(NS_STATIC_CAST(nsIDOMKeyListener*, this), NS_GET_IID(nsIDOMKeyListener));

  return NS_OK;
}

Here is the call graph for this function:

nsresult mozInlineSpellChecker::RemoveRange ( nsISelection aSpellCheckSelection,
nsIDOMRange aRange 
)

Definition at line 1557 of file mozInlineSpellChecker.cpp.

{
  NS_ENSURE_ARG_POINTER(aSpellCheckSelection);
  NS_ENSURE_ARG_POINTER(aRange);

  nsresult rv = aSpellCheckSelection->RemoveRange(aRange);
  if (NS_SUCCEEDED(rv) && mNumWordsInSpellSelection)
    mNumWordsInSpellSelection--;

  return rv;
}

Here is the caller graph for this function:

void nsIInlineSpellChecker::replaceWord ( in nsIDOMNode  aNode,
in long  aOffset,
in AString  aNewword 
) [inherited]

Definition at line 1451 of file mozInlineSpellChecker.cpp.

{
  if (! mSpellCheck)
    return NS_OK; // spell checking has been turned off

  mozInlineSpellWordUtil wordUtil;
  nsresult rv = wordUtil.Init(mEditor);
  if (NS_FAILED(rv))
    return NS_OK; // editor doesn't like us, don't assert

  nsCOMPtr<nsISelection> spellCheckSelection;
  rv = GetSpellCheckSelection(getter_AddRefs(spellCheckSelection));
  NS_ENSURE_SUCCESS(rv, rv);
  CleanupRangesInSelection(spellCheckSelection);

  rv = aStatus->FinishInitOnEvent(wordUtil);
  NS_ENSURE_SUCCESS(rv, rv);
  if (! aStatus->mRange)
    return NS_OK; // empty range, nothing to do

  PRBool doneChecking = PR_TRUE;
  if (aStatus->mOp == mozInlineSpellStatus::eOpSelection)
    rv = DoSpellCheckSelection(wordUtil, spellCheckSelection, aStatus);
  else
    rv = DoSpellCheck(wordUtil, spellCheckSelection, aStatus, &doneChecking);
  NS_ENSURE_SUCCESS(rv, rv);

  if (! doneChecking)
    rv = ScheduleSpellCheck(*aStatus);
  return rv;
}

Here is the call graph for this function:

Definition at line 1609 of file mozInlineSpellChecker.cpp.

{
  nsCOMPtr<nsIEditor> editor (do_QueryReferent(mEditor));
  NS_ENSURE_TRUE(editor, NS_OK);

  // figure out the old caret position based on the current selection
  nsCOMPtr<nsISelection> selection;
  nsresult rv = editor->GetSelection(getter_AddRefs(selection));
  NS_ENSURE_SUCCESS(rv, rv);

  rv = selection->GetFocusNode(getter_AddRefs(mCurrentSelectionAnchorNode));
  NS_ENSURE_SUCCESS(rv, rv);
  
  selection->GetFocusOffset(&mCurrentSelectionOffset);

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1173 of file mozInlineSpellChecker.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult mozInlineSpellChecker::SkipSpellCheckForNode ( nsIEditor aEditor,
nsIDOMNode aNode,
PRBool aCheckSpelling 
)

Definition at line 1121 of file mozInlineSpellChecker.cpp.

{
  *checkSpelling = PR_TRUE;
  NS_ENSURE_ARG_POINTER(aNode);

  PRUint32 flags;
  aEditor->GetFlags(&flags);
  if (flags & nsIPlaintextEditor::eEditorMailMask)
  {
    nsCOMPtr<nsIDOMNode> parent;
    aNode->GetParentNode(getter_AddRefs(parent));

    while (parent)
    {
      nsCOMPtr<nsIDOMElement> parentElement = do_QueryInterface(parent);
      if (!parentElement)
        break;

      nsAutoString parentTagName;
      parentElement->GetTagName(parentTagName);

      if (parentTagName.Equals(NS_LITERAL_STRING("blockquote"), nsCaseInsensitiveStringComparator()))
      {
        *checkSpelling = PR_FALSE;
        break;
      }
      else if (parentTagName.Equals(NS_LITERAL_STRING("pre"), nsCaseInsensitiveStringComparator()))
      {
        nsAutoString classname;
        parentElement->GetAttribute(NS_LITERAL_STRING("class"),classname);
        if (classname.Equals(NS_LITERAL_STRING("moz-signature")))
          *checkSpelling = PR_FALSE;
      }

      nsCOMPtr<nsIDOMNode> nextParent;
      parent->GetParentNode(getter_AddRefs(nextParent));
      parent = nextParent;
    }
  }

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult mozInlineSpellChecker::SpellCheckAfterChange ( nsIDOMNode aCursorNode,
PRInt32  aCursorOffset,
nsIDOMNode aPreviousNode,
PRInt32  aPreviousOffset,
nsISelection aSpellCheckSelection 
)
void nsIInlineSpellChecker::spellCheckAfterEditorChange ( in long  aAction,
in nsISelection  aSelection,
in nsIDOMNode  aPreviousSelectedNode,
in long  aPreviousSelectedOffset,
in nsIDOMNode  aStartNode,
in long  aStartOffset,
in nsIDOMNode  aEndNode,
in long  aEndOffset 
) [inherited]
nsresult mozInlineSpellChecker::SpellCheckBetweenNodes ( nsIDOMNode aStartNode,
PRInt32  aStartOffset,
nsIDOMNode aEndNode,
PRInt32  aEndOffset 
)

Definition at line 1094 of file mozInlineSpellChecker.cpp.

{
  nsCOMPtr<nsIDOMRange> range;
  nsresult rv = MakeSpellCheckRange(aStartNode, aStartOffset,
                                    aEndNode, aEndOffset,
                                    getter_AddRefs(range));
  NS_ENSURE_SUCCESS(rv, rv);

  if (! range)
    return NS_OK; // range is empty: nothing to do

  mozInlineSpellStatus status(this);
  rv = status.InitForRange(range);
  NS_ENSURE_SUCCESS(rv, rv);
  return ScheduleSpellCheck(status);
}

Here is the call graph for this function:

Definition at line 291 of file mozInlineSpellChecker.h.

Here is the caller graph for this function:

Definition at line 691 of file mozInlineSpellChecker.cpp.

{
  nsCOMPtr<nsIEditor> editor (do_QueryReferent(mEditor));
  NS_ENSURE_TRUE(editor, NS_ERROR_NULL_POINTER);

  editor->RemoveEditActionListener(this);

  nsCOMPtr<nsIDOMDocument> doc;
  editor->GetDocument(getter_AddRefs(doc));
  NS_ENSURE_TRUE(doc, NS_ERROR_NULL_POINTER);
  
  nsCOMPtr<nsIDOMEventReceiver> eventReceiver = do_QueryInterface(doc);
  NS_ENSURE_TRUE(eventReceiver, NS_ERROR_NULL_POINTER);

  eventReceiver->RemoveEventListenerByIID(NS_STATIC_CAST(nsIDOMMouseListener*, this), NS_GET_IID(nsIDOMMouseListener));
  eventReceiver->RemoveEventListenerByIID(NS_STATIC_CAST(nsIDOMKeyListener*, this), NS_GET_IID(nsIDOMKeyListener));
  
  return NS_OK;
}

Here is the call graph for this function:

void nsIEditActionListener::WillCreateNode ( in DOMString  aTag,
in nsIDOMNode  aParent,
in long  aPosition 
) [inherited]

Called before the editor creates a node.

Parameters:
aTagThe tag name of the DOM Node to create.
aParentThe node to insert the new object into
aPositionThe place in aParent to insert the new node 0=first child, 1=second child, etc. any number > number of current children = last child

Called before the editor deletes a node.

Parameters:
aChildThe node to delete

Called before the editor deletes the selection.

Parameters:
aSelectionThe selection to be deleted

Here is the caller graph for this function:

void nsIEditActionListener::WillDeleteText ( in nsIDOMCharacterData  aTextNode,
in long  aOffset,
in long  aLength 
) [inherited]

Called before the editor deletes text.

Parameters:
aTextNodeThis node getting text deleted
aOffsetThe offset in aTextNode to delete at.
aLengthThe amount of text to delete.

Here is the caller graph for this function:

void nsIEditActionListener::WillInsertNode ( in nsIDOMNode  aNode,
in nsIDOMNode  aParent,
in long  aPosition 
) [inherited]

Called before the editor inserts a node.

Parameters:
aNodeThe DOM Node to insert.
aParentThe node to insert the new object into
aPositionThe place in aParent to insert the new node 0=first child, 1=second child, etc. any number > number of current children = last child
void nsIEditActionListener::WillInsertText ( in nsIDOMCharacterData  aTextNode,
in long  aOffset,
in DOMString  aString 
) [inherited]

Called before the editor inserts text.

Parameters:
aTextNodeThis node getting inserted text
aOffsetThe offset in aTextNode to insert at.
aStringThe string that gets inserted.

Here is the caller graph for this function:

void nsIEditActionListener::WillJoinNodes ( in nsIDOMNode  aLeftNode,
in nsIDOMNode  aRightNode,
in nsIDOMNode  aParent 
) [inherited]

Called before the editor joins 2 nodes.

Parameters:
aLeftNodeThis node will be merged into the right node
aRightNodeThe node that will be merged into. There is no requirement that the two nodes be of the same type.
aParentThe parent of aRightNode
void nsIEditActionListener::WillSplitNode ( in nsIDOMNode  aExistingRightNode,
in long  aOffset 
) [inherited]

Called before the editor splits a node.

Parameters:
aExistingRightNodethe node to split. It will become the new node's next sibling.
aOffsetthe offset of aExistingRightNode's content|children to do the split at
aNewLeftNode[OUT] the new node resulting from the split, becomes aExistingRightNode's previous sibling.

Friends And Related Function Documentation

friend class mozInlineSpellStatus [friend]

Definition at line 146 of file mozInlineSpellChecker.h.


Member Data Documentation

Definition at line 55 of file nsIInlineSpellChecker.idl.

Definition at line 158 of file mozInlineSpellChecker.h.

Definition at line 172 of file mozInlineSpellChecker.h.

Definition at line 173 of file mozInlineSpellChecker.h.

Definition at line 154 of file mozInlineSpellChecker.h.

Definition at line 180 of file mozInlineSpellChecker.h.

Definition at line 168 of file mozInlineSpellChecker.h.

Definition at line 161 of file mozInlineSpellChecker.h.

Definition at line 177 of file mozInlineSpellChecker.h.

Definition at line 160 of file mozInlineSpellChecker.h.

Definition at line 155 of file mozInlineSpellChecker.h.

Definition at line 156 of file mozInlineSpellChecker.h.

Definition at line 157 of file mozInlineSpellChecker.h.

Definition at line 50 of file nsIInlineSpellChecker.idl.


The documentation for this class was generated from the following files: