Commit c4b039ad authored by kov@webkit.org's avatar kov@webkit.org

2009-04-24 Diego Escalante Urrelo <diegoe@gnome.org>

        Reviewed by Gustavo Noronha.

        https://bugs.webkit.org/show_bug.cgi?id=15616
        [GTK] Add spell checking

        Implement EditorClient::checkSpellingOfString; enabling spell checking
        to actually happen, this is the basis for other spelling functions.

        * WebCoreSupport/EditorClientGtk.cpp:
        (WebKit::EditorClient::checkSpellingOfString):

git-svn-id: svn://svn.chromium.org/blink/trunk@42819 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 6d7b2f0d
2009-04-24 Diego Escalante Urrelo <diegoe@gnome.org>
Reviewed by Gustavo Noronha.
https://bugs.webkit.org/show_bug.cgi?id=15616
[GTK] Add spell checking
Implement EditorClient::checkSpellingOfString; enabling spell checking
to actually happen, this is the basis for other spelling functions.
* WebCoreSupport/EditorClientGtk.cpp:
(WebKit::EditorClient::checkSpellingOfString):
2009-04-24 Diego Escalante Urrelo <diegoe@gnome.org> 2009-04-24 Diego Escalante Urrelo <diegoe@gnome.org>
Reviewed by Gustavo Noronha. Reviewed by Gustavo Noronha.
......
/* /*
* Copyright (C) 2007 Alp Toker <alp@atoker.com> * Copyright (C) 2007 Alp Toker <alp@atoker.com>
* Copyright (C) 2008 Nuanti Ltd. * Copyright (C) 2008 Nuanti Ltd.
* Copyright (C) 2009 Diego Escalante Urrelo <diegoe@gnome.org>
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
...@@ -23,8 +24,10 @@ ...@@ -23,8 +24,10 @@
#include "CString.h" #include "CString.h"
#include "EditCommand.h" #include "EditCommand.h"
#include "Editor.h" #include "Editor.h"
#include <enchant.h>
#include "FocusController.h" #include "FocusController.h"
#include "Frame.h" #include "Frame.h"
#include <glib.h>
#include "KeyboardCodes.h" #include "KeyboardCodes.h"
#include "KeyboardEvent.h" #include "KeyboardEvent.h"
#include "NotImplemented.h" #include "NotImplemented.h"
...@@ -524,9 +527,57 @@ void EditorClient::learnWord(const String&) ...@@ -524,9 +527,57 @@ void EditorClient::learnWord(const String&)
notImplemented(); notImplemented();
} }
void EditorClient::checkSpellingOfString(const UChar*, int, int*, int*) void EditorClient::checkSpellingOfString(const UChar* text, int length, int* misspellingLocation, int* misspellingLength)
{ {
notImplemented(); gchar* ctext = g_utf16_to_utf8(const_cast<gunichar2*>(text), length, 0, 0, 0);
int utflen = g_utf8_strlen(ctext, -1);
PangoLanguage* language = pango_language_get_default();
PangoLogAttr* attrs = g_new(PangoLogAttr, utflen+1);
// pango_get_log_attrs uses an aditional position at the end of the text.
pango_get_log_attrs(ctext, -1, -1, language, attrs, utflen+1);
for (int i = 0; i < length+1; i++) {
// We go through each character until we find an is_word_start,
// then we get into an inner loop to find the is_word_end corresponding
// to it.
if (attrs[i].is_word_start) {
int start = i;
int end = i;
int wordLength;
GSList* langs = webkit_web_settings_get_spell_languages(m_webView);
while (attrs[end].is_word_end < 1)
end++;
wordLength = end - start;
// Set the iterator to be at the current word end, so we don't
// check characters twice.
i = end;
for (; langs; langs = langs->next) {
SpellLanguage* lang = static_cast<SpellLanguage*>(langs->data);
gchar* cstart = g_utf8_offset_to_pointer(ctext, start);
gint bytes = static_cast<gint>(g_utf8_offset_to_pointer(ctext, end) - cstart);
gchar* word = g_new0(gchar, bytes+1);
int result;
g_utf8_strncpy(word, cstart, end - start);
result = enchant_dict_check(lang->speller, word, -1);
if (result) {
*misspellingLocation = start;
*misspellingLength = wordLength;
} else {
// Stop checking, this word is ok in at least one dict.
*misspellingLocation = -1;
*misspellingLength = 0;
break;
}
}
}
}
} }
void EditorClient::checkGrammarOfString(const UChar*, int, Vector<GrammarDetail>&, int*, int*) void EditorClient::checkGrammarOfString(const UChar*, int, Vector<GrammarDetail>&, int*, int*)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment