1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
|
/*
* Copyright (C) 2011 Igalia S.L.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "config.h"
#include "webkitspellcheckerenchant.h"
#if ENABLE(SPELLCHECK)
#include "TextCheckerEnchant.h"
#include "webkitspellchecker.h"
#include <gtk/gtk.h>
#include <wtf/OwnPtr.h>
#include <wtf/gobject/GOwnPtr.h>
#include <wtf/text/CString.h>
using namespace WebCore;
/**
* SECTION:webkitspellcheckerenchant
* @short_description: the default spell checking implementation for WebKitGTK+.
*
* #WebKitSpellCheckerEnchant is the default spell checking implementation for
* WebKitGTK+. It uses the Enchant dictionaries installed on the system to
* correct spelling.
*/
struct _WebKitSpellCheckerEnchantPrivate {
OwnPtr<TextCheckerEnchant> textCheckerEnchant;
};
static void webkit_spell_checker_enchant_spell_checker_interface_init(WebKitSpellCheckerInterface* checkerInterface);
G_DEFINE_TYPE_WITH_CODE(WebKitSpellCheckerEnchant, webkit_spell_checker_enchant, G_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE(WEBKIT_TYPE_SPELL_CHECKER,
webkit_spell_checker_enchant_spell_checker_interface_init))
static void webkit_spell_checker_enchant_finalize(GObject* object)
{
WebKitSpellCheckerEnchantPrivate* priv = WEBKIT_SPELL_CHECKER_ENCHANT(object)->priv;
priv->~WebKitSpellCheckerEnchantPrivate();
}
static void webkit_spell_checker_enchant_class_init(WebKitSpellCheckerEnchantClass* klass)
{
GObjectClass* objectClass = G_OBJECT_CLASS(klass);
objectClass->finalize = webkit_spell_checker_enchant_finalize;
g_type_class_add_private(klass, sizeof(WebKitSpellCheckerEnchantPrivate));
}
static void webkit_spell_checker_enchant_init(WebKitSpellCheckerEnchant* checker)
{
WebKitSpellCheckerEnchantPrivate* priv = G_TYPE_INSTANCE_GET_PRIVATE(checker, WEBKIT_TYPE_SPELL_CHECKER_ENCHANT, WebKitSpellCheckerEnchantPrivate);
checker->priv = priv;
new (priv) WebKitSpellCheckerEnchantPrivate();
priv->textCheckerEnchant = TextCheckerEnchant::create();
}
static void checkSpellingOfString(WebKitSpellChecker* checker, const char* string, int* misspellingLocation, int* misspellingLength)
{
WebKitSpellCheckerEnchantPrivate* priv = WEBKIT_SPELL_CHECKER_ENCHANT(checker)->priv;
priv->textCheckerEnchant->checkSpellingOfString(String::fromUTF8(string), *misspellingLocation, *misspellingLength);
}
static char** getGuessesForWord(WebKitSpellChecker* checker, const char* word, const char* context)
{
WebKitSpellCheckerEnchantPrivate* priv = WEBKIT_SPELL_CHECKER_ENCHANT(checker)->priv;
Vector<String> guesses = priv->textCheckerEnchant->getGuessesForWord(String::fromUTF8(word));
if (guesses.isEmpty())
return 0;
int i = 0;
int numberOfGuesses = guesses.size();
char** guessesArray = static_cast<char**>(g_malloc0((numberOfGuesses + 1) * sizeof(char*)));
for (Vector<String>::const_iterator iter = guesses.begin(); iter != guesses.end(); ++iter)
guessesArray[i++] = g_strdup(iter->utf8().data());
guessesArray[i] = 0;
return guessesArray;
}
static void updateSpellCheckingLanguages(WebKitSpellChecker* checker, const char* languages)
{
WebKitSpellCheckerEnchantPrivate* priv = WEBKIT_SPELL_CHECKER_ENCHANT(checker)->priv;
Vector<String> languagesVector;
String::fromUTF8(languages).split(static_cast<UChar>(','), languagesVector);
priv->textCheckerEnchant->updateSpellCheckingLanguages(languagesVector);
}
static char* getAutocorrectSuggestionsForMisspelledWord(WebKitSpellChecker* checker, const char* word)
{
return 0;
}
static void learnWord(WebKitSpellChecker* checker, const char* word)
{
WebKitSpellCheckerEnchantPrivate* priv = WEBKIT_SPELL_CHECKER_ENCHANT(checker)->priv;
priv->textCheckerEnchant->learnWord(String::fromUTF8(word));
}
static void ignoreWord(WebKitSpellChecker* checker, const char* word)
{
WebKitSpellCheckerEnchantPrivate* priv = WEBKIT_SPELL_CHECKER_ENCHANT(checker)->priv;
priv->textCheckerEnchant->ignoreWord(String::fromUTF8(word));
}
static void webkit_spell_checker_enchant_spell_checker_interface_init(WebKitSpellCheckerInterface* checkerInterface)
{
checkerInterface->check_spelling_of_string = checkSpellingOfString;
checkerInterface->get_guesses_for_word = getGuessesForWord;
checkerInterface->update_spell_checking_languages = updateSpellCheckingLanguages;
checkerInterface->get_autocorrect_suggestions_for_misspelled_word = getAutocorrectSuggestionsForMisspelledWord;
checkerInterface->learn_word = learnWord;
checkerInterface->ignore_word = ignoreWord;
}
#endif /* ENABLE(SPELLCHECK) */
|