initial import
[vuplus_webkit] / Source / WebKit / gtk / webkit / webkitspellchecker.cpp
1 /*
2  *  Copyright (C) 2011 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 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.
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  *  Lesser General Public License for more details.
13  *
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
17  */
18
19 #include "config.h"
20 #include "webkitspellchecker.h"
21
22 /**
23  * SECTION:webkitspellchecker
24  * @short_description: the spell checking API for WebKit
25  *
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.
31  */
32
33 G_DEFINE_INTERFACE(WebKitSpellChecker, webkit_spell_checker, G_TYPE_OBJECT);
34
35 static void webkit_spell_checker_default_init(WebKitSpellCheckerInterface* interface)
36 {
37 }
38
39 /**
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
45  *
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.
49  *
50  * Since: 1.5.1
51  **/
52 void webkit_spell_checker_check_spelling_of_string(WebKitSpellChecker* checker, const char* string, int* misspelling_location, int* misspelling_length)
53 {
54     g_return_if_fail(WEBKIT_IS_SPELL_CHECKER(checker));
55     g_return_if_fail(string);
56
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);
60 }
61
62 /**
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
67  *
68  * Returns a %NULL-terminated array of guesses for corrections of the
69  * misspelled word @word.
70  *
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.
74  *
75  * Since: 1.5.1
76  **/
77 char** webkit_spell_checker_get_guesses_for_word(WebKitSpellChecker* checker, const char* word, const char* context)
78 {
79     g_return_val_if_fail(WEBKIT_IS_SPELL_CHECKER(checker), 0);
80     g_return_val_if_fail(word, 0);
81
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);
85
86     return 0;
87 }
88
89 /**
90  * webkit_spell_checker_update_spell_checking_languages:
91  * @checker: a #WebKitSpellChecker
92  * @languages: (allow-none) a string of languages to use for @checker
93  *
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.
97  *
98  * Since: 1.5.1
99  **/
100 void webkit_spell_checker_update_spell_checking_languages(WebKitSpellChecker* checker, const char* languages)
101 {
102     g_return_if_fail(WEBKIT_IS_SPELL_CHECKER(checker));
103
104     WebKitSpellCheckerInterface* interface = WEBKIT_SPELL_CHECKER_GET_IFACE(checker);
105     if (interface->update_spell_checking_languages)
106         interface->update_spell_checking_languages(checker, languages);
107 }
108
109 /**
110  * webkit_spell_checker_get_autocorrect_suggestions_for_misspelled_word:
111  * @checker: a #WebKitSpellChecker
112  * @word: a misspelled word
113  *
114  * Returns a suggestion for a word to use in an "autocorrect" feature.
115  *
116  * Returns: (transfer full) the suggestion for the autocorrection of
117  * @word
118  *
119  * Since: 1.5.1
120  **/
121 char* webkit_spell_checker_get_autocorrect_suggestions_for_misspelled_word(WebKitSpellChecker* checker, const char* word)
122 {
123     g_return_val_if_fail(WEBKIT_IS_SPELL_CHECKER(checker), 0);
124     g_return_val_if_fail(word, 0);
125
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);
129
130     return 0;
131 }
132
133 /**
134  * webkit_spell_checker_learn_word:
135  * @checker: a #WebKitSpellChecker
136  * @word: the word to learn
137  *
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.
141  *
142  * Since: 1.5.1
143  **/
144 void webkit_spell_checker_learn_word(WebKitSpellChecker* checker, const char* word)
145 {
146     g_return_if_fail(WEBKIT_IS_SPELL_CHECKER(checker));
147     g_return_if_fail(word);
148
149     WebKitSpellCheckerInterface* interface = WEBKIT_SPELL_CHECKER_GET_IFACE(checker);
150     if (interface->learn_word)
151         interface->learn_word(checker, word);
152 }
153
154 /**
155  * webkit_spell_checker_ignore_word:
156  * @checker: a #WebKitSpellChecker
157  * @word: the word to ignore
158  *
159  * Instructs the @checker to ignore @word as a misspelling for this
160  * session.
161  *
162  * Since: 1.5.1
163  **/
164 void webkit_spell_checker_ignore_word(WebKitSpellChecker* checker, const char* word)
165 {
166     g_return_if_fail(WEBKIT_IS_SPELL_CHECKER(checker));
167     g_return_if_fail(word);
168
169     WebKitSpellCheckerInterface* interface = WEBKIT_SPELL_CHECKER_GET_IFACE(checker);
170     if (interface->ignore_word)
171         interface->ignore_word(checker, word);
172 }