/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
enum Operation {
eOpChange, // for SpellCheckAfterEditorChange except // deleteSelection
eOpChangeDelete, // for SpellCheckAfterEditorChange with // deleteSelection
eOpNavigation, // for HandleNavigationEvent
eOpSelection, // re-check all misspelled words
eOpResume
};
// See `mOp`.
Operation GetOperation() const { return mOp; }
// Used for events where we have already computed the range to use. It can // also be nullptr in these cases where we need to check the entire range.
RefPtr<nsRange> mRange;
private: // @param aSpellChecker must be non-nullptr. // @param aOp see mOp. // @param aRange see mRange. // @param aCreatedRange see mCreatedRange. // @param aAnchorRange see mAnchorRange. // @param aForceNavigationWordCheck see mForceNavigationWordCheck. // @param aNewNavigationPositionOffset see mNewNavigationPositionOffset. explicit mozInlineSpellStatus(mozInlineSpellChecker* aSpellChecker,
Operation aOp, RefPtr<nsRange>&& aRange,
RefPtr<nsRange>&& aCreatedRange,
RefPtr<nsRange>&& aAnchorRange, bool aForceNavigationWordCheck,
int32_t aNewNavigationPositionOffset);
// For resuming a previously started check. const Operation mOp;
// // If we happen to know something was inserted, this is that range. // Can be nullptr (this only allows an optimization, so not setting doesn't // hurt) const RefPtr<const nsRange> mCreatedRange;
// Contains the range computed for the current word. Can be nullptr.
RefPtr<nsRange> mNoCheckRange;
// Indicates the position of the cursor for the event (so we can compute // mNoCheckRange). It can be nullptr 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 const RefPtr<const nsRange> 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
RefPtr<nsRange> mOldNavigationAnchorRange;
// Set when we should force checking the current word. See // mozInlineSpellChecker::HandleNavigationEvent for a description of why we // have this. constbool mForceNavigationWordCheck;
// Contains the offset passed in to HandleNavigationEvent const int32_t mNewNavigationPositionOffset;
class mozInlineSpellChecker final : public nsIInlineSpellChecker, public nsIDOMEventListener, public nsSupportsWeakReference { private: friendclass mozInlineSpellStatus; friendclass InitEditorSpellCheckCallback; friendclass UpdateCurrentDictionaryCallback; friendclass AutoChangeNumPendingSpellChecks;
// 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<nsINode> mCurrentSelectionAnchorNode;
uint32_t mCurrentSelectionOffset;
// Tracks the number of pending spell checks *and* async operations that may // lead to spell checks, like updating the current dictionary. This is // necessary so that observers can know when to wait for spell check to // complete.
int32_t mNumPendingSpellChecks;
// The number of calls to UpdateCurrentDictionary that haven't finished yet.
int32_t mNumPendingUpdateCurrentDictionary;
// This number is incremented each time the spell checker is disabled so that // pending scheduled spell checks and UpdateCurrentDictionary calls can be // ignored when they finish.
uint32_t mDisabledAsyncToken;
// When mPendingSpellCheck is non-null, this is the callback passed when // it was initialized.
RefPtr<InitEditorSpellCheckCallback> mPendingInitEditorSpellCheckCallback;
// Set when we have spellchecked after the last edit operation. See the // commment at the top of the .cpp file for more info. bool mNeedsCheckAfterNavigation;
// Set when we have a pending mozInlineSpellResume which will check // the whole document. bool mFullSpellCheckScheduled;
// Set to true when this instance needs to listen to edit actions of // the editor. bool mIsListeningToEditSubActions;
// See `mDisabledAsyncToken`.
uint32_t GetDisabledAsyncToken() const { return mDisabledAsyncToken; }
// returns true if there are any spell checking dictionaries available staticbool CanEnableInlineSpellChecking(); // update the cached value whenever the list of available dictionaries changes staticvoid UpdateCanEnableInlineSpellChecking();
mozInlineSpellChecker();
// spell checks all of the words between two nodes
nsresult SpellCheckBetweenNodes(nsINode* aStartNode, int32_t aStartOffset,
nsINode* aEndNode, int32_t 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 // or an e-mail signature...) staticbool ShouldSpellCheckNode(mozilla::EditorBase* aEditorBase,
nsINode* aNode);
// spell check the text contained within aRange, potentially scheduling // another check in the future if the time threshold is reached
nsresult ScheduleSpellCheck(
mozilla::UniquePtr<mozInlineSpellStatus>&& aStatus);
// helper routine to determine if a point is inside of the passed in // selection. static nsresult IsPointInSelection(mozilla::dom::Selection& aSelection,
nsINode* aNode, uint32_t aOffset,
nsRange** aRange);
// Ensures that all misspelled words have corresponding ranges in // aSpellCheckerSelection. Reuses those of the old ranges, which still // correspond to misspelled words and adds new ranges for those misspelled // words for which no corresponding old range exists. // Removes the old ranges which aren't reused from aSpellCheckerSelection. // // @param aNodeOffsetRangesForWords corresponds to aIsMisspelled. // `aNodeOffsetRangesForWords.Length() == // aIsMisspelled.Length()`. // @param aOldRangesForSomeWords ranges belonging to aSpellCheckerSelection. // Its length may differ from // `aNodeOffsetRangesForWords.Length()`. // @param aIsMisspelled indicates which words are misspelled.
MOZ_CAN_RUN_SCRIPT_BOUNDARY void UpdateRangesForMisspelledWords( const nsTArray<NodeOffsetRange>& aNodeOffsetRangesForWords, const nsTArray<RefPtr<nsRange>>& aOldRangesForSomeWords, const nsTArray<bool>& aIsMisspelled,
mozilla::dom::Selection& aSpellCheckerSelection);
// called when async nsIEditorSpellCheck methods complete
nsresult EditorSpellCheckInited();
nsresult CurrentDictionaryUpdated();
// track the number of pending spell checks and async operations that may lead // to spell checks, notifying observers accordingly void ChangeNumPendingSpellChecks(int32_t aDelta,
mozilla::EditorBase* aEditorBase = nullptr); void NotifyObservers(constchar* aTopic, mozilla::EditorBase* aEditorBase);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.