initial import
[vuplus_webkit] / Source / WebKit / gtk / WebCoreSupport / TextCheckerClientGtk.cpp
1 /*
2  *  Copyright (C) 2007 Alp Toker <alp@atoker.com>
3  *  Copyright (C) 2008 Nuanti Ltd.
4  *  Copyright (C) 2009 Diego Escalante Urrelo <diegoe@gnome.org>
5  *  Copyright (C) 2006, 2007 Apple Inc.  All rights reserved.
6  *  Copyright (C) 2009, 2010, 2011 Igalia S.L.
7  *  Copyright (C) 2010, Martin Robinson <mrobinson@webkit.org>
8  *
9  *  This library is free software; you can redistribute it and/or
10  *  modify it under the terms of the GNU Lesser General Public
11  *  License as published by the Free Software Foundation; either
12  *  version 2 of the License, or (at your option) any later version.
13  *
14  *  This library is distributed in the hope that it will be useful,
15  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  *  Lesser General Public License for more details.
18  *
19  *  You should have received a copy of the GNU Lesser General Public
20  *  License along with this library; if not, write to the Free Software
21  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22  */
23
24 #include "config.h"
25 #include "TextCheckerClientGtk.h"
26
27 #include "GOwnPtr.h"
28 #include "NotImplemented.h"
29 #include "webkitspellchecker.h"
30 #include "webkitwebsettingsprivate.h"
31 #include <glib.h>
32 #include <wtf/text/CString.h>
33
34 using namespace WebCore;
35
36 namespace WebKit {
37
38 TextCheckerClientGtk::TextCheckerClientGtk(WebKitSpellChecker* spellChecker)
39     : m_spellChecker(spellChecker)
40 {
41 }
42
43 TextCheckerClientGtk::~TextCheckerClientGtk()
44 {
45 }
46
47 void TextCheckerClientGtk::ignoreWordInSpellDocument(const String& text)
48 {
49     webkit_spell_checker_ignore_word(m_spellChecker.get(), text.utf8().data());
50 }
51
52 void TextCheckerClientGtk::learnWord(const String& text)
53 {
54     webkit_spell_checker_learn_word(m_spellChecker.get(), text.utf8().data());
55 }
56
57 void TextCheckerClientGtk::checkSpellingOfString(const UChar* text, int length, int* misspellingLocation, int* misspellingLength)
58 {
59     GOwnPtr<gchar> utf8Text(g_utf16_to_utf8(const_cast<gunichar2*>(text), length, 0, 0, 0));
60     webkit_spell_checker_check_spelling_of_string(m_spellChecker.get(), utf8Text.get(), misspellingLocation, misspellingLength);
61 }
62
63 String TextCheckerClientGtk::getAutoCorrectSuggestionForMisspelledWord(const String& inputWord)
64 {
65     return webkit_spell_checker_get_autocorrect_suggestions_for_misspelled_word(m_spellChecker.get(), inputWord.utf8().data());
66 }
67
68 void TextCheckerClientGtk::checkGrammarOfString(const UChar*, int, Vector<GrammarDetail>&, int*, int*)
69 {
70     notImplemented();
71 }
72
73 void TextCheckerClientGtk::getGuessesForWord(const String& word, const String& context, WTF::Vector<String>& guesses)
74 {
75     char** suggestions = webkit_spell_checker_get_guesses_for_word(m_spellChecker.get(), word.utf8().data(), context.utf8().data());
76     if (!suggestions)
77         return;
78
79     guesses.clear();
80
81     for (int i = 0; suggestions[i]; i++)
82         guesses.append(String::fromUTF8(suggestions[i]));
83
84     g_strfreev(suggestions);
85 }
86
87 void TextCheckerClientGtk::updateSpellCheckingLanguage(const char* spellCheckingLanguages)
88 {
89     webkit_spell_checker_update_spell_checking_languages(m_spellChecker.get(), spellCheckingLanguages);
90 }
91 }