Changeset 79130 in webkit


Ignore:
Timestamp:
Feb 19, 2011 1:06:04 PM (13 years ago)
Author:
commit-queue@webkit.org
Message:

2011-02-19 Ryuan Choi <ryuan.choi@samsung.com>

Reviewed by Martin Robinson.

[GTK] Remove mandatory Enchant dependency
https://bugs.webkit.org/show_bug.cgi?id=51587

Add enable-spellcheck option which decides whether to use enchant.
If disabled, WebKitGTK+ will not use enchant library.

  • configure.ac:

2011-02-19 Ryuan Choi <ryuan.choi@samsung.com>

Reviewed by Martin Robinson.

[GTK] Remove mandatory Enchant dependency
https://bugs.webkit.org/show_bug.cgi?id=51587

Extract TextCheckerClientEnchant From EditorClientGtk and remove
enchant dependency from other files.

  • GNUmakefile.am:
  • WebCoreSupport/EditorClientGtk.cpp: (WebKit::EditorClient::EditorClient):
  • WebCoreSupport/EditorClientGtk.h: (WebKit::EditorClient::textChecker):
  • WebCoreSupport/TextCheckerClientEnchant.cpp: Added. (WebKit::TextCheckerClientEnchant::TextCheckerClientEnchant): (WebKit::TextCheckerClientEnchant::~TextCheckerClientEnchant): (WebKit::TextCheckerClientEnchant::ignoreWordInSpellDocument): (WebKit::TextCheckerClientEnchant::learnWord): (WebKit::TextCheckerClientEnchant::checkSpellingOfString): (WebKit::TextCheckerClientEnchant::getAutoCorrectSuggestionForMisspelledWord): (WebKit::TextCheckerClientEnchant::checkGrammarOfString): (WebKit::TextCheckerClientEnchant::getGuessesForWord): (WebKit::getAvailableDictionariesCallback): (WebKit::TextCheckerClientEnchant::updateSpellCheckingLanguage): (WebKit::TextCheckerClientEnchant::freeSpellCheckingLanguage):
  • WebCoreSupport/TextCheckerClientEnchant.h: Added. (WebKit::TextCheckerClientEnchant::requestCheckingOfString):
  • webkit/webkitwebsettings.cpp: (webkit_web_settings_finalize): (webkit_web_settings_set_property):
  • webkit/webkitwebview.cpp: (webkit_web_view_settings_notify):
Location:
trunk
Files:
2 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/ChangeLog

    r79096 r79130  
     12011-02-19  Ryuan Choi  <ryuan.choi@samsung.com>
     2
     3        Reviewed by Martin Robinson.
     4
     5        [GTK] Remove mandatory Enchant dependency
     6        https://bugs.webkit.org/show_bug.cgi?id=51587
     7
     8        Add enable-spellcheck option which decides whether to use enchant.
     9        If disabled, WebKitGTK+ will not use enchant library.
     10
     11        * configure.ac:
     12
    1132011-02-18  Zan Dobersek  <zandobersek@gmail.com>
    214
  • trunk/Source/WebKit/gtk/ChangeLog

    r79107 r79130  
     12011-02-19  Ryuan Choi  <ryuan.choi@samsung.com>
     2
     3        Reviewed by Martin Robinson.
     4
     5        [GTK] Remove mandatory Enchant dependency
     6        https://bugs.webkit.org/show_bug.cgi?id=51587
     7
     8        Extract TextCheckerClientEnchant From EditorClientGtk and remove
     9        enchant dependency from other files.
     10
     11        * GNUmakefile.am:
     12        * WebCoreSupport/EditorClientGtk.cpp:
     13        (WebKit::EditorClient::EditorClient):
     14        * WebCoreSupport/EditorClientGtk.h:
     15        (WebKit::EditorClient::textChecker):
     16        * WebCoreSupport/TextCheckerClientEnchant.cpp: Added.
     17        (WebKit::TextCheckerClientEnchant::TextCheckerClientEnchant):
     18        (WebKit::TextCheckerClientEnchant::~TextCheckerClientEnchant):
     19        (WebKit::TextCheckerClientEnchant::ignoreWordInSpellDocument):
     20        (WebKit::TextCheckerClientEnchant::learnWord):
     21        (WebKit::TextCheckerClientEnchant::checkSpellingOfString):
     22        (WebKit::TextCheckerClientEnchant::getAutoCorrectSuggestionForMisspelledWord):
     23        (WebKit::TextCheckerClientEnchant::checkGrammarOfString):
     24        (WebKit::TextCheckerClientEnchant::getGuessesForWord):
     25        (WebKit::getAvailableDictionariesCallback):
     26        (WebKit::TextCheckerClientEnchant::updateSpellCheckingLanguage):
     27        (WebKit::TextCheckerClientEnchant::freeSpellCheckingLanguage):
     28        * WebCoreSupport/TextCheckerClientEnchant.h: Added.
     29        (WebKit::TextCheckerClientEnchant::requestCheckingOfString):
     30        * webkit/webkitwebsettings.cpp:
     31        (webkit_web_settings_finalize):
     32        (webkit_web_settings_set_property):
     33        * webkit/webkitwebview.cpp:
     34        (webkit_web_view_settings_notify):
     35
    1362011-02-19  Charlie Reis  <creis@chromium.org>
    237
  • trunk/Source/WebKit/gtk/GNUmakefile.am

    r77868 r79130  
    2929        $(SYMBOL_VISIBILITY) \
    3030        $(global_cflags)
     31
     32if ENABLE_SPELLCHECK
     33webkitgtk_cppflags += \
     34        -DENABLE_SPELLCHECK=1
     35
     36webkitgtk_sources += \
     37        Source/WebKit/gtk/WebCoreSupport/TextCheckerClientEnchant.cpp \
     38        Source/WebKit/gtk/WebCoreSupport/TextCheckerClientEnchant.h
     39endif
    3140
    3241# When building WebCore/WebKit, we want WebCore/config.h and NOT JavaScriptCore/config.h,
     
    4857        $(webcoregtk_cppflags) \
    4958        $(javascriptcore_cppflags) \
     59        $(webkitgtk_cppflags) \
    5060        -fno-strict-aliasing \
    5161        $(HILDON_CPPFLAGS) \
  • trunk/Source/WebKit/gtk/WebCoreSupport/EditorClientGtk.cpp

    r78532 r79130  
    2828#include "EditCommand.h"
    2929#include "Editor.h"
    30 #include <enchant.h>
    3130#include "EventNames.h"
    3231#include "FocusController.h"
     
    843842EditorClient::EditorClient(WebKitWebView* webView)
    844843    : m_isInRedo(false)
     844#if ENABLE(SPELLCHECK)
     845    , m_textCheckerClient(webView)
     846#endif
    845847    , m_webView(webView)
    846848    , m_preventNextCompositionCommit(false)
     
    898900}
    899901
    900 void EditorClient::ignoreWordInSpellDocument(const String& text)
    901 {
    902     GSList* dicts = webkitWebViewGetEnchantDicts(m_webView);
    903 
    904     for (; dicts; dicts = dicts->next) {
    905         EnchantDict* dict = static_cast<EnchantDict*>(dicts->data);
    906 
    907         enchant_dict_add_to_session(dict, text.utf8().data(), -1);
    908     }
    909 }
    910 
    911 void EditorClient::learnWord(const String& text)
    912 {
    913     GSList* dicts = webkitWebViewGetEnchantDicts(m_webView);
    914 
    915     for (; dicts; dicts = dicts->next) {
    916         EnchantDict* dict = static_cast<EnchantDict*>(dicts->data);
    917 
    918         enchant_dict_add_to_personal(dict, text.utf8().data(), -1);
    919     }
    920 }
    921 
    922 void EditorClient::checkSpellingOfString(const UChar* text, int length, int* misspellingLocation, int* misspellingLength)
    923 {
    924     GSList* dicts = webkitWebViewGetEnchantDicts(m_webView);
    925     if (!dicts)
    926         return;
    927 
    928     gchar* ctext = g_utf16_to_utf8(const_cast<gunichar2*>(text), length, 0, 0, 0);
    929     int utflen = g_utf8_strlen(ctext, -1);
    930 
    931     PangoLanguage* language = pango_language_get_default();
    932     PangoLogAttr* attrs = g_new(PangoLogAttr, utflen+1);
    933 
    934     // pango_get_log_attrs uses an aditional position at the end of the text.
    935     pango_get_log_attrs(ctext, -1, -1, language, attrs, utflen+1);
    936 
    937     for (int i = 0; i < length+1; i++) {
    938         // We go through each character until we find an is_word_start,
    939         // then we get into an inner loop to find the is_word_end corresponding
    940         // to it.
    941         if (attrs[i].is_word_start) {
    942             int start = i;
    943             int end = i;
    944             int wordLength;
    945 
    946             while (attrs[end].is_word_end < 1)
    947                 end++;
    948 
    949             wordLength = end - start;
    950             // Set the iterator to be at the current word end, so we don't
    951             // check characters twice.
    952             i = end;
    953 
    954             for (; dicts; dicts = dicts->next) {
    955                 EnchantDict* dict = static_cast<EnchantDict*>(dicts->data);
    956                 gchar* cstart = g_utf8_offset_to_pointer(ctext, start);
    957                 gint bytes = static_cast<gint>(g_utf8_offset_to_pointer(ctext, end) - cstart);
    958                 gchar* word = g_new0(gchar, bytes+1);
    959                 int result;
    960 
    961                 g_utf8_strncpy(word, cstart, end - start);
    962 
    963                 result = enchant_dict_check(dict, word, -1);
    964                 g_free(word);
    965                 if (result) {
    966                     *misspellingLocation = start;
    967                     *misspellingLength = wordLength;
    968                 } else {
    969                     // Stop checking, this word is ok in at least one dict.
    970                     *misspellingLocation = -1;
    971                     *misspellingLength = 0;
    972                     break;
    973                 }
    974             }
    975         }
    976     }
    977 
    978     g_free(attrs);
    979     g_free(ctext);
    980 }
    981 
    982 String EditorClient::getAutoCorrectSuggestionForMisspelledWord(const String& inputWord)
    983 {
    984     // This method can be implemented using customized algorithms for the particular browser.
    985     // Currently, it computes an empty string.
    986     return String();
    987 }
    988 
    989 void EditorClient::checkGrammarOfString(const UChar*, int, Vector<GrammarDetail>&, int*, int*)
    990 {
    991     notImplemented();
    992 }
    993 
    994902void EditorClient::updateSpellingUIWithGrammarString(const String&, const GrammarDetail&)
    995903{
     
    1013921}
    1014922
    1015 void EditorClient::getGuessesForWord(const String& word, const String& context, WTF::Vector<String>& guesses)
    1016 {
    1017     GSList* dicts = webkitWebViewGetEnchantDicts(m_webView);
    1018     guesses.clear();
    1019 
    1020     for (; dicts; dicts = dicts->next) {
    1021         size_t numberOfSuggestions;
    1022         size_t i;
    1023 
    1024         EnchantDict* dict = static_cast<EnchantDict*>(dicts->data);
    1025         gchar** suggestions = enchant_dict_suggest(dict, word.utf8().data(), -1, &numberOfSuggestions);
    1026 
    1027         for (i = 0; i < numberOfSuggestions && i < 10; i++)
    1028             guesses.append(String::fromUTF8(suggestions[i]));
    1029 
    1030         if (numberOfSuggestions > 0)
    1031             enchant_dict_free_suggestions(dict, suggestions);
    1032     }
    1033 }
    1034 
    1035 }
     923}
  • trunk/Source/WebKit/gtk/WebCoreSupport/EditorClientGtk.h

    r78533 r79130  
    4040#include <wtf/gobject/GRefPtr.h>
    4141
     42#if ENABLE(SPELLCHECK)
     43#include "TextCheckerClientEnchant.h"
     44#else
     45#include "EmptyClients.h"
     46#endif
     47
    4248typedef struct _WebKitWebView WebKitWebView;
    4349
     
    4955namespace WebKit {
    5056
    51 class EditorClient : public WebCore::EditorClient,  public WebCore::TextCheckerClient {
     57class EditorClient : public WebCore::EditorClient {
    5258    protected:
    5359        bool m_isInRedo;
     
    124130        virtual void textDidChangeInTextArea(WebCore::Element*);
    125131
    126         virtual WebCore::TextCheckerClient* textChecker() { return this; }
     132        virtual WebCore::TextCheckerClient* textChecker() { return &m_textCheckerClient; }
    127133
    128         virtual void ignoreWordInSpellDocument(const WTF::String&);
    129         virtual void learnWord(const WTF::String&);
    130         virtual void checkSpellingOfString(const UChar*, int length, int* misspellingLocation, int* misspellingLength);
    131         virtual WTF::String getAutoCorrectSuggestionForMisspelledWord(const WTF::String&);
    132         virtual void checkGrammarOfString(const UChar*, int length, WTF::Vector<WebCore::GrammarDetail>&, int* badGrammarLocation, int* badGrammarLength);
    133134        virtual void updateSpellingUIWithGrammarString(const WTF::String&, const WebCore::GrammarDetail&);
    134135        virtual void updateSpellingUIWithMisspelledWord(const WTF::String&);
    135136        virtual void showSpellingUI(bool show);
    136137        virtual bool spellingUIIsShowing();
    137         virtual void getGuessesForWord(const WTF::String& word, const WTF::String& context, WTF::Vector<WTF::String>& guesses);
    138138        virtual void willSetInputMethodState();
    139139        virtual void setInputMethodState(bool enabled);
    140         virtual void requestCheckingOfString(WebCore::SpellChecker*, int, const WTF::String&) {}
    141140
    142141    private:
     142#if ENABLE(SPELLCHECK)
     143        TextCheckerClientEnchant m_textCheckerClient;
     144#else
     145        WebCore::EmptyTextCheckerClient m_textCheckerClient;
     146#endif
    143147        WebKitWebView* m_webView;
    144148        bool m_preventNextCompositionCommit;
  • trunk/Source/WebKit/gtk/webkit/webkitwebsettings.cpp

    r78749 r79130  
    3535#include "webkitversion.h"
    3636#include "webkitwebsettingsprivate.h"
    37 #include <enchant.h>
    3837#include <wtf/text/CString.h>
    3938#include <wtf/text/StringConcatenate.h>
     
    9190    gboolean enable_spell_checking;
    9291    gchar* spell_checking_languages;
    93     GSList* enchant_dicts;
    9492    gboolean enable_caret_browsing;
    9593    gboolean enable_html5_database;
     
    921919}
    922920
    923 static EnchantBroker* get_enchant_broker()
    924 {
    925     static EnchantBroker* broker = 0;
    926     if (!broker)
    927         broker = enchant_broker_init();
    928 
    929     return broker;
    930 }
    931 
    932 static void free_spell_checking_language(gpointer data, gpointer user_data)
    933 {
    934     EnchantDict* dict = static_cast<EnchantDict*>(data);
    935     EnchantBroker* broker = get_enchant_broker();
    936 
    937     enchant_broker_free_dict(broker, dict);
    938 }
    939 
    940921static void webkit_web_settings_finalize(GObject* object)
    941922{
     
    953934    g_free(priv->spell_checking_languages);
    954935
    955     g_slist_foreach(priv->enchant_dicts, free_spell_checking_language, 0);
    956     g_slist_free(priv->enchant_dicts);
    957 
    958936    g_free(priv->user_agent);
    959937
    960938    G_OBJECT_CLASS(webkit_web_settings_parent_class)->finalize(object);
    961 }
    962 
    963 static void getAvailableDictionariesCallback(const char* const languageTag, const char* const, const char* const, const char* const, void* data)
    964 {
    965     Vector<CString>* dicts = static_cast<Vector<CString>*>(data);
    966 
    967     dicts->append(languageTag);
    968939}
    969940
     
    972943    WebKitWebSettings* web_settings = WEBKIT_WEB_SETTINGS(object);
    973944    WebKitWebSettingsPrivate* priv = web_settings->priv;
    974     EnchantBroker* broker;
    975     EnchantDict* dict;
    976     GSList* spellDictionaries = 0;
    977945
    978946    switch(prop_id) {
     
    10661034        g_free(priv->spell_checking_languages);
    10671035        priv->spell_checking_languages = g_strdup(g_value_get_string(value));
    1068 
    1069         broker = get_enchant_broker();
    1070         if (priv->spell_checking_languages) {
    1071             char** langs = g_strsplit(priv->spell_checking_languages, ",", -1);
    1072             for (int i = 0; langs[i]; i++) {
    1073                 if (enchant_broker_dict_exists(broker, langs[i])) {
    1074                     dict = enchant_broker_request_dict(broker, langs[i]);
    1075                     spellDictionaries = g_slist_append(spellDictionaries, dict);
    1076                 }
    1077             }
    1078             g_strfreev(langs);
    1079         } else {
    1080             const char* language = pango_language_to_string(gtk_get_default_language());
    1081             if (enchant_broker_dict_exists(broker, language)) {
    1082                 dict = enchant_broker_request_dict(broker, language);
    1083                 spellDictionaries = g_slist_append(spellDictionaries, dict);
    1084             } else {
    1085                 // No dictionaries selected, we get one from the list
    1086                 Vector<CString> allDictionaries;
    1087                 enchant_broker_list_dicts(broker, getAvailableDictionariesCallback, &allDictionaries);
    1088                 if (!allDictionaries.isEmpty()) {
    1089                     dict = enchant_broker_request_dict(broker, allDictionaries[0].data());
    1090                     spellDictionaries = g_slist_append(spellDictionaries, dict);
    1091                 }
    1092             }
    1093         }
    1094         g_slist_foreach(priv->enchant_dicts, free_spell_checking_language, 0);
    1095         g_slist_free(priv->enchant_dicts);
    1096         priv->enchant_dicts = spellDictionaries;
    10971036        break;
    10981037    case PROP_ENABLE_XSS_AUDITOR:
     
    14221361}
    14231362
    1424 GSList* webkitWebViewGetEnchantDicts(WebKitWebView* webView)
    1425 {
    1426     g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), 0);
    1427 
    1428     WebKitWebSettings* settings = webkit_web_view_get_settings(webView);
    1429 
    1430     return settings->priv->enchant_dicts;
    1431 }
    1432 
    14331363namespace WebKit {
    14341364
  • trunk/Source/WebKit/gtk/webkit/webkitwebview.cpp

    r78342 r79130  
    34863486    else if (name == g_intern_string("enable-hyperlink-auditing"))
    34873487        settings->setHyperlinkAuditingEnabled(g_value_get_boolean(&value));
     3488#if ENABLE(SPELLCHECK)
     3489    else if (name == g_intern_string("spell-checking-languages")) {
     3490        WebKit::EditorClient* client = static_cast<WebKit::EditorClient*>(core(webView)->editorClient());
     3491        static_cast<WebKit::TextCheckerClientEnchant*>(client->textChecker())->updateSpellCheckingLanguage(g_value_get_string(&value));
     3492    }
     3493#endif
    34883494    else if (!g_object_class_find_property(G_OBJECT_GET_CLASS(webSettings), name))
    34893495        g_warning("Unexpected setting '%s'", name);
  • trunk/configure.ac

    r79096 r79130  
    287287AC_SUBST(PANGO_LIBS)
    288288
    289 PKG_CHECK_MODULES(ENCHANT, enchant >= $ENCHANT_REQUIRED_VERSION)
     289AC_MSG_CHECKING([whether to enable spellcheck support])
     290AC_ARG_ENABLE([spellcheck],
     291  [AS_HELP_STRING([--enable-spellcheck],[enable support for spellcheck])],
     292  [],[enable_spellcheck="yes"])
     293AC_MSG_RESULT([$enable_spellcheck])
     294
     295if test "$enable_spellcheck" = "yes"; then
     296PKG_CHECK_MODULES(ENCHANT, enchant >= $ENCHANT_REQUIRED_VERSION, [], [enable_spellcheck="no"])
    290297AC_SUBST(ENCHANT_CFLAGS)
    291298AC_SUBST(ENCHANT_LIBS)
     299fi
    292300
    293301PKG_CHECK_MODULES(GAIL, $GAIL_PC_NAME >= $GAIL_REQUIRED_VERSION)
     
    10431051AM_CONDITIONAL([ENABLE_OPCODE_STATS],[test "$enable_opcode_stats" = "yes"])
    10441052AM_CONDITIONAL([ENABLE_WEBKIT2],[test "$enable_webkit2" = "yes"])
     1053AM_CONDITIONAL([ENABLE_SPELLCHECK],[test "$enable_spellcheck" = "yes"])
    10451054
    10461055# Gtk conditionals
     
    11321141 XPATH support                                            : $enable_xpath
    11331142 XSLT support                                             : $enable_xslt
     1143 Spellcheck support                                       : $enable_spellcheck
    11341144
    11351145GTK+ configuration:
Note: See TracChangeset for help on using the changeset viewer.