- add third_party src.
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / editing / SpellChecker.h
1 /*
2  * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
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.
12  *
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.
24  */
25
26 #ifndef SpellChecker_h
27 #define SpellChecker_h
28
29 #include "core/dom/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"
34
35 namespace WebCore {
36
37 class EditorClient;
38 class Frame;
39 class SpellCheckRequest;
40 class SpellCheckRequester;
41 class TextCheckerClient;
42 class TextCheckingParagraph;
43 struct TextCheckingResult;
44
45 class SpellChecker {
46     WTF_MAKE_NONCOPYABLE(SpellChecker);
47 public:
48     static PassOwnPtr<SpellChecker> create(Frame&);
49
50     ~SpellChecker();
51
52     EditorClient& editorClient() const;
53     TextCheckerClient& textChecker() const;
54
55     bool isContinuousSpellCheckingEnabled() const;
56     void toggleContinuousSpellChecking();
57     bool isGrammarCheckingEnabled();
58     void ignoreSpelling();
59     String misspelledWordAtCaretOrRange(Node* clickedNode) const;
60     bool isSpellCheckingEnabledInFocusedNode() const;
61     bool isSpellCheckingEnabledFor(Node*) const;
62     void markMisspellingsAfterTypingToWord(const VisiblePosition &wordStart, const VisibleSelection& selectionAfterTyping);
63     void markMisspellings(const VisibleSelection&, RefPtr<Range>& firstMisspellingRange);
64     void markBadGrammar(const VisibleSelection&);
65     void markMisspellingsAndBadGrammar(const VisibleSelection& spellingSelection, bool markGrammar, const VisibleSelection& grammarSelection);
66     void markAndReplaceFor(PassRefPtr<SpellCheckRequest>, const Vector<TextCheckingResult>&);
67     void markAllMisspellingsAndBadGrammarInRanges(TextCheckingTypeMask, Range* spellingRange, Range* grammarRange);
68     void advanceToNextMisspelling(bool startBeforeSelection = false);
69     void showSpellingGuessPanel();
70     void didBeginEditing(Element*);
71     void clearMisspellingsAndBadGrammar(const VisibleSelection&);
72     void markMisspellingsAndBadGrammar(const VisibleSelection&);
73     void respondToChangedSelection(const VisibleSelection& oldSelection, FrameSelection::SetSelectionOptions);
74     void spellCheckAfterBlur();
75     void spellCheckOldSelection(const VisibleSelection& oldSelection, const VisibleSelection& newAdjacentWords, const VisibleSelection& newSelectedSentence);
76
77     void didEndEditingOnTextField(Element*);
78     bool selectionStartHasMarkerFor(DocumentMarker::MarkerType, int from, int length) const;
79     void updateMarkersForWordsAffectedByEditing(bool onlyHandleWordsContainingSelection);
80     void cancelCheck();
81     void chunkAndMarkAllMisspellingsAndBadGrammar(Node*);
82     void requestTextChecking(const Element&);
83
84     // Exposed for testing only
85     SpellCheckRequester& spellCheckRequester() const { return *m_spellCheckRequester; }
86
87 private:
88     Frame& m_frame;
89     const OwnPtr<SpellCheckRequester> m_spellCheckRequester;
90
91     explicit SpellChecker(Frame&);
92
93     void markMisspellingsOrBadGrammar(const VisibleSelection&, bool checkSpelling, RefPtr<Range>& firstMisspellingRange);
94     TextCheckingTypeMask resolveTextCheckingTypeMask(TextCheckingTypeMask);
95
96     bool unifiedTextCheckerEnabled() const;
97
98     void chunkAndMarkAllMisspellingsAndBadGrammar(TextCheckingTypeMask textCheckingOptions, const TextCheckingParagraph& fullParagraphToCheck, bool asynchronous);
99     void markAllMisspellingsAndBadGrammarInRanges(TextCheckingTypeMask textCheckingOptions, Range* checkingRange, Range* paragraphRange, bool asynchronous, int requestNumber, int* checkingLength = 0);
100 };
101
102 } // namespace WebCore
103
104 #endif // SpellChecker_h