2 * Copyright (C) 2011 Igalia S.L.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser 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.
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 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 #include "webkitspellchecker.h"
23 * SECTION:webkitspellchecker
24 * @short_description: the spell checking API for WebKit
26 * #WebKitSpellChecker provides APIs for the spell checking
27 * functionality used internally by WebKit to perform spell checking
28 * in editable areas. This can be used, for example, by browsers to
29 * implement custom spell checking context menus or sophisticated
30 * auto-correct features.
33 G_DEFINE_INTERFACE(WebKitSpellChecker, webkit_spell_checker, G_TYPE_OBJECT);
35 static void webkit_spell_checker_default_init(WebKitSpellCheckerInterface* interface)
40 * webkit_spell_checker_check_spelling_of_string:
41 * @checker: a #WebKitSpellChecker
42 * @string: the string to check for misspellings
43 * @misspelling_location: (out) (allow-none) a pointer to an integer to store the location of the first misspelling
44 * @misspelling_length: (out) (allow-none) a pointer to an integer to store the length of the first misspelling
46 * Checks @string for misspellings using @checker, storing the
47 * location and length of the first misspelling in
48 * @misspelling_location and @misspelling_length respectively.
52 void webkit_spell_checker_check_spelling_of_string(WebKitSpellChecker* checker, const char* string, int* misspelling_location, int* misspelling_length)
54 g_return_if_fail(WEBKIT_IS_SPELL_CHECKER(checker));
55 g_return_if_fail(string);
57 WebKitSpellCheckerInterface* interface = WEBKIT_SPELL_CHECKER_GET_IFACE(checker);
58 if (interface->check_spelling_of_string)
59 interface->check_spelling_of_string(checker, string, misspelling_location, misspelling_length);
63 * webkit_spell_checker_get_guesses_for_word:
64 * @checker: a #WebKitSpellChecker
65 * @word: the misspelled word
66 * @context: (allow-none) the surrounding context of the misspelled word
68 * Returns a %NULL-terminated array of guesses for corrections of the
69 * misspelled word @word.
71 * Returns: (transfer full) a newly allocated %NULL-terminated array
72 * of suggested corrections for a misspelled word @word. Free it with
73 * %g_strfreev when done with it.
77 char** webkit_spell_checker_get_guesses_for_word(WebKitSpellChecker* checker, const char* word, const char* context)
79 g_return_val_if_fail(WEBKIT_IS_SPELL_CHECKER(checker), 0);
80 g_return_val_if_fail(word, 0);
82 WebKitSpellCheckerInterface* interface = WEBKIT_SPELL_CHECKER_GET_IFACE(checker);
83 if (interface->get_guesses_for_word)
84 return interface->get_guesses_for_word(checker, word, context);
90 * webkit_spell_checker_update_spell_checking_languages:
91 * @checker: a #WebKitSpellChecker
92 * @languages: (allow-none) a string of languages to use for @checker
94 * Sets @languages as the list of languages to use by @checker. The
95 * accepted format is a list of comma (',') separated language codes
96 * of the form 'en_US', ie, language_VARIANT.
100 void webkit_spell_checker_update_spell_checking_languages(WebKitSpellChecker* checker, const char* languages)
102 g_return_if_fail(WEBKIT_IS_SPELL_CHECKER(checker));
104 WebKitSpellCheckerInterface* interface = WEBKIT_SPELL_CHECKER_GET_IFACE(checker);
105 if (interface->update_spell_checking_languages)
106 interface->update_spell_checking_languages(checker, languages);
110 * webkit_spell_checker_get_autocorrect_suggestions_for_misspelled_word:
111 * @checker: a #WebKitSpellChecker
112 * @word: a misspelled word
114 * Returns a suggestion for a word to use in an "autocorrect" feature.
116 * Returns: (transfer full) the suggestion for the autocorrection of
121 char* webkit_spell_checker_get_autocorrect_suggestions_for_misspelled_word(WebKitSpellChecker* checker, const char* word)
123 g_return_val_if_fail(WEBKIT_IS_SPELL_CHECKER(checker), 0);
124 g_return_val_if_fail(word, 0);
126 WebKitSpellCheckerInterface* interface = WEBKIT_SPELL_CHECKER_GET_IFACE(checker);
127 if (interface->get_autocorrect_suggestions_for_misspelled_word)
128 return interface->get_autocorrect_suggestions_for_misspelled_word(checker, word);
134 * webkit_spell_checker_learn_word:
135 * @checker: a #WebKitSpellChecker
136 * @word: the word to learn
138 * Instructs the @checker to add @word to its dictionary as a properly
139 * spelled word. The word will be learned permanently in the user's
140 * personal dictionary.
144 void webkit_spell_checker_learn_word(WebKitSpellChecker* checker, const char* word)
146 g_return_if_fail(WEBKIT_IS_SPELL_CHECKER(checker));
147 g_return_if_fail(word);
149 WebKitSpellCheckerInterface* interface = WEBKIT_SPELL_CHECKER_GET_IFACE(checker);
150 if (interface->learn_word)
151 interface->learn_word(checker, word);
155 * webkit_spell_checker_ignore_word:
156 * @checker: a #WebKitSpellChecker
157 * @word: the word to ignore
159 * Instructs the @checker to ignore @word as a misspelling for this
164 void webkit_spell_checker_ignore_word(WebKitSpellChecker* checker, const char* word)
166 g_return_if_fail(WEBKIT_IS_SPELL_CHECKER(checker));
167 g_return_if_fail(word);
169 WebKitSpellCheckerInterface* interface = WEBKIT_SPELL_CHECKER_GET_IFACE(checker);
170 if (interface->ignore_word)
171 interface->ignore_word(checker, word);