Back to index

lightning-sunbird  0.9+nobinonly
Public Types | Public Member Functions | Public Attributes | Protected Member Functions
mozInlineSpellStatus Class Reference

#include <mozInlineSpellChecker.h>

Collaboration diagram for mozInlineSpellStatus:
Collaboration graph
[legend]

List of all members.

Public Types

enum  Operation {
  eOpChange, eOpChangeDelete, eOpNavigation, eOpSelection,
  eOpResume
}

Public Member Functions

 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)

Public Attributes

nsRefPtr< mozInlineSpellCheckermSpellChecker
PRInt32 mWordCount
Operation mOp
nsCOMPtr< nsIDOMRangemRange
nsCOMPtr< nsIDOMRangemCreatedRange
nsCOMPtr< nsIDOMRangemNoCheckRange
nsCOMPtr< nsIDOMRangemAnchorRange
nsCOMPtr< nsIDOMRangemOldNavigationAnchorRange
PRBool mForceNavigationWordCheck
PRInt32 mNewNavigationPositionOffset

Protected Member Functions

nsresult FinishNavigationEvent (mozInlineSpellWordUtil &aWordUtil)
nsresult FillNoCheckRangeFromAnchor (mozInlineSpellWordUtil &aWordUtil)
nsresult GetDocumentRange (nsIDOMDocumentRange **aDocRange)
nsresult PositionToCollapsedRange (nsIDOMDocumentRange *aDocRange, nsIDOMNode *aNode, PRInt32 aOffset, nsIDOMRange **aRange)

Detailed Description

Definition at line 63 of file mozInlineSpellChecker.h.


Member Enumeration Documentation

Enumerator:
eOpChange 
eOpChangeDelete 
eOpNavigation 
eOpSelection 
eOpResume 

Definition at line 90 of file mozInlineSpellChecker.h.

                 { 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

Constructor & Destructor Documentation

Definition at line 121 of file mozInlineSpellChecker.cpp.

    : mSpellChecker(aSpellChecker), mWordCount(0)
{
}

Member Function Documentation

Definition at line 414 of file mozInlineSpellChecker.cpp.

{
  nsCOMPtr<nsIDOMNode> anchorNode;
  nsresult rv = mAnchorRange->GetStartContainer(getter_AddRefs(anchorNode));
  NS_ENSURE_SUCCESS(rv, rv);

  PRInt32 anchorOffset;
  rv = mAnchorRange->GetStartOffset(&anchorOffset);
  NS_ENSURE_SUCCESS(rv, rv);

  return aWordUtil.GetRangeForWord(anchorNode, anchorOffset,
                                   getter_AddRefs(mNoCheckRange));
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 302 of file mozInlineSpellChecker.cpp.

{
  nsresult rv;
  if (! mRange) {
    rv = mSpellChecker->MakeSpellCheckRange(nsnull, 0, nsnull, 0,
                                            getter_AddRefs(mRange));
    NS_ENSURE_SUCCESS(rv, rv);
  }

  switch (mOp) {
    case eOpChange:
      if (mAnchorRange)
        return FillNoCheckRangeFromAnchor(aWordUtil);
      break;
    case eOpChangeDelete:
      if (mAnchorRange) {
        rv = FillNoCheckRangeFromAnchor(aWordUtil);
        NS_ENSURE_SUCCESS(rv, rv);
      }
      // Delete events will have no range for the changed text (because it was
      // deleted), and InitForEditorChange will set it to NULL. Here, we select
      // the entire word to cause any underlining to be removed.
      mRange = mNoCheckRange;
      break;
    case eOpNavigation:
      return FinishNavigationEvent(aWordUtil);
    case eOpSelection:
      // this gets special handling in ResumeCheck
      break;
    case eOpResume:
      // everything should be initialized already in this case
      break;
    default:
      NS_NOTREACHED("Bad operation");
      return NS_ERROR_NOT_INITIALIZED;
  }
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 355 of file mozInlineSpellChecker.cpp.

{
  NS_ASSERTION(mAnchorRange, "No anchor for navigation!");
  nsCOMPtr<nsIDOMNode> newAnchorNode, oldAnchorNode;
  PRInt32 newAnchorOffset, oldAnchorOffset;

  // get the DOM position of the old caret, the range should be collapsed
  nsresult rv = mOldNavigationAnchorRange->GetStartContainer(
      getter_AddRefs(oldAnchorNode));
  NS_ENSURE_SUCCESS(rv, rv);
  rv = mOldNavigationAnchorRange->GetStartOffset(&oldAnchorOffset);
  NS_ENSURE_SUCCESS(rv, rv);

  // find the word on the old caret position, this is the one that we MAY need
  // to check
  nsCOMPtr<nsIDOMRange> oldWord;
  rv = aWordUtil.GetRangeForWord(oldAnchorNode, oldAnchorOffset,
                                 getter_AddRefs(oldWord));
  NS_ENSURE_SUCCESS(rv, rv);
  nsCOMPtr<nsIDOMNSRange> oldWordNS = do_QueryInterface(oldWord, &rv);
  NS_ENSURE_SUCCESS(rv, rv);

  // get the DOM position of the new caret, the range should be collapsed
  rv = mAnchorRange->GetStartContainer(getter_AddRefs(newAnchorNode));
  NS_ENSURE_SUCCESS(rv, rv);
  rv = mAnchorRange->GetStartOffset(&newAnchorOffset);
  NS_ENSURE_SUCCESS(rv, rv);

  // see if the new cursor position is in the word of the old cursor position
  PRBool isInRange = PR_FALSE;
  if (! mForceNavigationWordCheck) {
    rv = oldWordNS->IsPointInRange(newAnchorNode,
                                   newAnchorOffset + mNewNavigationPositionOffset,
                                   &isInRange);
    NS_ENSURE_SUCCESS(rv, rv);
  }

  if (isInRange) {
    // caller should give up
    mRange = nsnull;
  } else {
    // check the old word
    mRange = oldWord;

    // Once we've spellchecked the current word, we don't need to spellcheck
    // for any more navigation events.
    mSpellChecker->mNeedsCheckAfterNavigation = PR_FALSE;
  }
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 435 of file mozInlineSpellChecker.cpp.

{
  nsresult rv;
  *aDocRange = nsnull;
  if (! mSpellChecker->mEditor)
    return NS_ERROR_UNEXPECTED;

  nsCOMPtr<nsIEditor> editor = do_QueryReferent(mSpellChecker->mEditor, &rv);
  NS_ENSURE_SUCCESS(rv, rv);

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

  nsCOMPtr<nsIDOMDocumentRange> docRange = do_QueryInterface(domDoc, &rv);
  NS_ENSURE_SUCCESS(rv, rv);

  docRange.swap(*aDocRange);
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult mozInlineSpellStatus::InitForEditorChange ( PRInt32  aAction,
nsIDOMNode aAnchorNode,
PRInt32  aAnchorOffset,
nsIDOMNode aPreviousNode,
PRInt32  aPreviousOffset,
nsIDOMNode aStartNode,
PRInt32  aStartOffset,
nsIDOMNode aEndNode,
PRInt32  aEndOffset 
)

Definition at line 134 of file mozInlineSpellChecker.cpp.

{
  nsresult rv;

  nsCOMPtr<nsIDOMDocumentRange> docRange;
  rv = GetDocumentRange(getter_AddRefs(docRange));
  NS_ENSURE_SUCCESS(rv, rv);

  // save the anchor point as a range so we can find the current word later
  rv = PositionToCollapsedRange(docRange, aAnchorNode, aAnchorOffset,
                                getter_AddRefs(mAnchorRange));
  NS_ENSURE_SUCCESS(rv, rv);

  if (aAction == mozInlineSpellChecker::kOpDeleteSelection) {
    // Deletes are easy, the range is just the current anchor. We set the range
    // to check to be empty, FinishInitOnEvent will fill in the range to be
    // the current word.
    mOp = eOpChangeDelete;
    mRange = nsnull;
    return NS_OK;
  }

  mOp = eOpChange;

  // range to check
  rv = docRange->CreateRange(getter_AddRefs(mRange));
  NS_ENSURE_SUCCESS(rv, rv);

  // ...we need to put the start and end in the correct order
  nsCOMPtr<nsIDOMNSRange> nsrange = do_QueryInterface(mAnchorRange, &rv);
  NS_ENSURE_SUCCESS(rv, rv);
  PRInt16 cmpResult;
  rv = nsrange->ComparePoint(aPreviousNode, aPreviousOffset, &cmpResult);
  NS_ENSURE_SUCCESS(rv, rv);
  if (cmpResult < 0) {
    // previous anchor node is before the current anchor
    rv = mRange->SetStart(aPreviousNode, aPreviousOffset);
    NS_ENSURE_SUCCESS(rv, rv);
    rv = mRange->SetEnd(aAnchorNode, aAnchorOffset);
  } else {
    // previous anchor node is after (or the same as) the current anchor
    rv = mRange->SetStart(aAnchorNode, aAnchorOffset);
    NS_ENSURE_SUCCESS(rv, rv);
    rv = mRange->SetEnd(aPreviousNode, aPreviousOffset);
  }
  NS_ENSURE_SUCCESS(rv, rv);

  // On insert save this range: DoSpellCheck optimizes things in this range.
  // Otherwise, just leave this NULL.
  if (aAction == mozInlineSpellChecker::kOpInsertText)
    mCreatedRange = mRange;

  // if we were given a range, we need to expand our range to encompass it
  if (aStartNode && aEndNode) {
    nsrange = do_QueryInterface(mRange, &rv);
    NS_ENSURE_SUCCESS(rv, rv);

    rv = nsrange->ComparePoint(aStartNode, aStartOffset, &cmpResult);
    NS_ENSURE_SUCCESS(rv, rv);
    if (cmpResult < 0) { // given range starts before
      rv = mRange->SetStart(aStartNode, aStartOffset);
      NS_ENSURE_SUCCESS(rv, rv);
    }

    rv = nsrange->ComparePoint(aEndNode, aEndOffset, &cmpResult);
    NS_ENSURE_SUCCESS(rv, rv);
    if (cmpResult > 0) { // given range ends after
      rv = mRange->SetEnd(aEndNode, aEndOffset);
      NS_ENSURE_SUCCESS(rv, rv);
    }
  }

  return NS_OK;
}

Here is the call graph for this function:

nsresult mozInlineSpellStatus::InitForNavigation ( PRBool  aForceCheck,
PRInt32  aNewPositionOffset,
nsIDOMNode aOldAnchorNode,
PRInt32  aOldAnchorOffset,
nsIDOMNode aNewAnchorNode,
PRInt32  aNewAnchorOffset,
PRBool aContinue 
)

Definition at line 222 of file mozInlineSpellChecker.cpp.

{
  nsresult rv;
  mOp = eOpNavigation;

  mForceNavigationWordCheck = aForceCheck;
  mNewNavigationPositionOffset = aNewPositionOffset;

  // get the root node for checking
  nsCOMPtr<nsIEditor> editor = do_QueryReferent(mSpellChecker->mEditor, &rv);
  NS_ENSURE_SUCCESS(rv, rv);
  nsCOMPtr<nsIDOMElement> rootElt;
  rv = editor->GetRootElement(getter_AddRefs(rootElt));
  NS_ENSURE_SUCCESS(rv, rv);

  // the anchor node might not be in the DOM anymore, check
  nsCOMPtr<nsIContent> root = do_QueryInterface(rootElt, &rv);
  NS_ENSURE_SUCCESS(rv, rv);
  nsCOMPtr<nsIContent> currentAnchor = do_QueryInterface(aOldAnchorNode, &rv);
  NS_ENSURE_SUCCESS(rv, rv);
  if (root && currentAnchor && ! ContentIsDescendantOf(currentAnchor, root)) {
    *aContinue = PR_FALSE;
    return NS_OK;
  }

  nsCOMPtr<nsIDOMDocumentRange> docRange;
  rv = GetDocumentRange(getter_AddRefs(docRange));
  NS_ENSURE_SUCCESS(rv, rv);

  rv = PositionToCollapsedRange(docRange, aOldAnchorNode, aOldAnchorOffset,
                                getter_AddRefs(mOldNavigationAnchorRange));
  NS_ENSURE_SUCCESS(rv, rv);
  rv = PositionToCollapsedRange(docRange, aNewAnchorNode, aNewAnchorOffset,
                                getter_AddRefs(mAnchorRange));
  NS_ENSURE_SUCCESS(rv, rv);

  *aContinue = PR_TRUE;
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 284 of file mozInlineSpellChecker.cpp.

{
  mOp = eOpChange;
  mRange = aRange;
  return NS_OK;
}

Here is the caller graph for this function:

Definition at line 272 of file mozInlineSpellChecker.cpp.

{
  mOp = eOpSelection;
  return NS_OK;
}
nsresult mozInlineSpellStatus::PositionToCollapsedRange ( nsIDOMDocumentRange aDocRange,
nsIDOMNode aNode,
PRInt32  aOffset,
nsIDOMRange **  aRange 
) [protected]

Definition at line 463 of file mozInlineSpellChecker.cpp.

{
  *aRange = nsnull;
  nsCOMPtr<nsIDOMRange> range;
  nsresult rv = aDocRange->CreateRange(getter_AddRefs(range));
  NS_ENSURE_SUCCESS(rv, rv);

  rv = range->SetStart(aNode, aOffset);
  NS_ENSURE_SUCCESS(rv, rv);
  rv = range->SetEnd(aNode, aOffset);
  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:


Member Data Documentation

Definition at line 113 of file mozInlineSpellChecker.h.

Definition at line 103 of file mozInlineSpellChecker.h.

Definition at line 126 of file mozInlineSpellChecker.h.

Definition at line 129 of file mozInlineSpellChecker.h.

Definition at line 106 of file mozInlineSpellChecker.h.

Definition at line 121 of file mozInlineSpellChecker.h.

Definition at line 95 of file mozInlineSpellChecker.h.

Definition at line 99 of file mozInlineSpellChecker.h.

Definition at line 82 of file mozInlineSpellChecker.h.

Definition at line 87 of file mozInlineSpellChecker.h.


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