2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 #ifndef SpellChecker_h
27 #define SpellChecker_h
29 #include "core/clipboard/ClipboardAccessPolicy.h"
30 #include "core/dom/DocumentMarker.h"
31 #include "core/editing/FrameSelection.h"
32 #include "core/editing/VisibleSelection.h"
33 #include "platform/text/TextChecking.h"
38 class SpellCheckerClient;
39 class SpellCheckRequest;
40 class SpellCheckRequester;
41 class TextCheckerClient;
42 class TextCheckingParagraph;
43 struct TextCheckingResult;
46 WTF_MAKE_NONCOPYABLE(SpellChecker);
48 static PassOwnPtr<SpellChecker> create(Frame&);
52 SpellCheckerClient& spellCheckerClient() const;
53 TextCheckerClient& textChecker() const;
55 bool isContinuousSpellCheckingEnabled() const;
56 void toggleContinuousSpellChecking();
57 bool isGrammarCheckingEnabled();
58 void ignoreSpelling();
59 bool isSpellCheckingEnabledInFocusedNode() const;
60 bool isSpellCheckingEnabledFor(Node*) const;
61 void markMisspellingsAfterTypingToWord(const VisiblePosition &wordStart, const VisibleSelection& selectionAfterTyping);
62 void markMisspellings(const VisibleSelection&, RefPtr<Range>& firstMisspellingRange);
63 void markBadGrammar(const VisibleSelection&);
64 void markMisspellingsAndBadGrammar(const VisibleSelection& spellingSelection, bool markGrammar, const VisibleSelection& grammarSelection);
65 void markAndReplaceFor(PassRefPtr<SpellCheckRequest>, const Vector<TextCheckingResult>&);
66 void markAllMisspellingsAndBadGrammarInRanges(TextCheckingTypeMask, Range* spellingRange, Range* grammarRange);
67 void advanceToNextMisspelling(bool startBeforeSelection = false);
68 void showSpellingGuessPanel();
69 void didBeginEditing(Element*);
70 void clearMisspellingsAndBadGrammar(const VisibleSelection&);
71 void markMisspellingsAndBadGrammar(const VisibleSelection&);
72 void respondToChangedSelection(const VisibleSelection& oldSelection, FrameSelection::SetSelectionOptions);
73 void spellCheckAfterBlur();
74 void spellCheckOldSelection(const VisibleSelection& oldSelection, const VisibleSelection& newAdjacentWords, const VisibleSelection& newSelectedSentence);
76 void didEndEditingOnTextField(Element*);
77 bool selectionStartHasMarkerFor(DocumentMarker::MarkerType, int from, int length) const;
78 void updateMarkersForWordsAffectedByEditing(bool onlyHandleWordsContainingSelection);
80 void chunkAndMarkAllMisspellingsAndBadGrammar(Node*);
81 void requestTextChecking(const Element&);
83 // Exposed for testing only
84 SpellCheckRequester& spellCheckRequester() const { return *m_spellCheckRequester; }
88 const OwnPtr<SpellCheckRequester> m_spellCheckRequester;
90 explicit SpellChecker(Frame&);
92 void markMisspellingsOrBadGrammar(const VisibleSelection&, bool checkSpelling, RefPtr<Range>& firstMisspellingRange);
93 TextCheckingTypeMask resolveTextCheckingTypeMask(TextCheckingTypeMask);
95 bool unifiedTextCheckerEnabled() const;
97 void chunkAndMarkAllMisspellingsAndBadGrammar(TextCheckingTypeMask textCheckingOptions, const TextCheckingParagraph& fullParagraphToCheck, bool asynchronous);
98 void markAllMisspellingsAndBadGrammarInRanges(TextCheckingTypeMask textCheckingOptions, Range* checkingRange, Range* paragraphRange, bool asynchronous, int requestNumber, int* checkingLength = 0);
101 } // namespace WebCore
103 #endif // SpellChecker_h