1 | /* |
2 | * Copyright (C) 2012 Igalia S.L. |
3 | * |
4 | * This library is free software; you can redistribute it and/or |
5 | * modify it under the terms of the GNU Library General Public |
6 | * License as published by the Free Software Foundation; either |
7 | * version 2 of the License, or (at your option) any later version. |
8 | * |
9 | * This library is distributed in the hope that it will be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | * Library General Public License for more details. |
13 | * |
14 | * You should have received a copy of the GNU Library General Public License |
15 | * along with this library; see the file COPYING.LIB. If not, write to |
16 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
17 | * Boston, MA 02110-1301, USA. |
18 | */ |
19 | |
20 | #pragma once |
21 | |
22 | #if ENABLE(SPELLCHECK) |
23 | |
24 | #include <enchant.h> |
25 | #include <wtf/Forward.h> |
26 | #include <wtf/Vector.h> |
27 | |
28 | namespace WebCore { |
29 | |
30 | class TextCheckerEnchant { |
31 | WTF_MAKE_NONCOPYABLE(TextCheckerEnchant); WTF_MAKE_FAST_ALLOCATED; |
32 | friend class WTF::NeverDestroyed<TextCheckerEnchant>; |
33 | public: |
34 | static TextCheckerEnchant& singleton(); |
35 | |
36 | void ignoreWord(const String&); |
37 | void learnWord(const String&); |
38 | void checkSpellingOfString(const String&, int& misspellingLocation, int& misspellingLength); |
39 | Vector<String> getGuessesForWord(const String&); |
40 | void updateSpellCheckingLanguages(const Vector<String>& languages); |
41 | Vector<String> loadedSpellCheckingLanguages() const; |
42 | bool hasDictionary() const { return !m_enchantDictionaries.isEmpty(); } |
43 | Vector<String> availableSpellCheckingLanguages() const; |
44 | |
45 | private: |
46 | TextCheckerEnchant(); |
47 | ~TextCheckerEnchant() = delete; |
48 | |
49 | void checkSpellingOfWord(const String&, int start, int end, int& misspellingLocation, int& misspellingLength); |
50 | |
51 | struct EnchantDictDeleter { |
52 | void operator()(EnchantDict*) const; |
53 | }; |
54 | |
55 | using UniqueEnchantDict = std::unique_ptr<EnchantDict, EnchantDictDeleter>; |
56 | |
57 | EnchantBroker* m_broker; |
58 | Vector<UniqueEnchantDict> m_enchantDictionaries; |
59 | }; |
60 | |
61 | } // namespace WebCore |
62 | |
63 | #endif // ENABLE(SPELLCHECK) |
64 | |