Changeset 79130 in webkit
- Timestamp:
- Feb 19, 2011 1:06:04 PM (13 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/ChangeLog
r79096 r79130 1 2011-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 1 13 2011-02-18 Zan Dobersek <zandobersek@gmail.com> 2 14 -
trunk/Source/WebKit/gtk/ChangeLog
r79107 r79130 1 2011-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 1 36 2011-02-19 Charlie Reis <creis@chromium.org> 2 37 -
trunk/Source/WebKit/gtk/GNUmakefile.am
r77868 r79130 29 29 $(SYMBOL_VISIBILITY) \ 30 30 $(global_cflags) 31 32 if ENABLE_SPELLCHECK 33 webkitgtk_cppflags += \ 34 -DENABLE_SPELLCHECK=1 35 36 webkitgtk_sources += \ 37 Source/WebKit/gtk/WebCoreSupport/TextCheckerClientEnchant.cpp \ 38 Source/WebKit/gtk/WebCoreSupport/TextCheckerClientEnchant.h 39 endif 31 40 32 41 # When building WebCore/WebKit, we want WebCore/config.h and NOT JavaScriptCore/config.h, … … 48 57 $(webcoregtk_cppflags) \ 49 58 $(javascriptcore_cppflags) \ 59 $(webkitgtk_cppflags) \ 50 60 -fno-strict-aliasing \ 51 61 $(HILDON_CPPFLAGS) \ -
trunk/Source/WebKit/gtk/WebCoreSupport/EditorClientGtk.cpp
r78532 r79130 28 28 #include "EditCommand.h" 29 29 #include "Editor.h" 30 #include <enchant.h>31 30 #include "EventNames.h" 32 31 #include "FocusController.h" … … 843 842 EditorClient::EditorClient(WebKitWebView* webView) 844 843 : m_isInRedo(false) 844 #if ENABLE(SPELLCHECK) 845 , m_textCheckerClient(webView) 846 #endif 845 847 , m_webView(webView) 846 848 , m_preventNextCompositionCommit(false) … … 898 900 } 899 901 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 corresponding940 // 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't951 // 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 994 902 void EditorClient::updateSpellingUIWithGrammarString(const String&, const GrammarDetail&) 995 903 { … … 1013 921 } 1014 922 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 40 40 #include <wtf/gobject/GRefPtr.h> 41 41 42 #if ENABLE(SPELLCHECK) 43 #include "TextCheckerClientEnchant.h" 44 #else 45 #include "EmptyClients.h" 46 #endif 47 42 48 typedef struct _WebKitWebView WebKitWebView; 43 49 … … 49 55 namespace WebKit { 50 56 51 class EditorClient : public WebCore::EditorClient , public WebCore::TextCheckerClient{57 class EditorClient : public WebCore::EditorClient { 52 58 protected: 53 59 bool m_isInRedo; … … 124 130 virtual void textDidChangeInTextArea(WebCore::Element*); 125 131 126 virtual WebCore::TextCheckerClient* textChecker() { return this; }132 virtual WebCore::TextCheckerClient* textChecker() { return &m_textCheckerClient; } 127 133 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);133 134 virtual void updateSpellingUIWithGrammarString(const WTF::String&, const WebCore::GrammarDetail&); 134 135 virtual void updateSpellingUIWithMisspelledWord(const WTF::String&); 135 136 virtual void showSpellingUI(bool show); 136 137 virtual bool spellingUIIsShowing(); 137 virtual void getGuessesForWord(const WTF::String& word, const WTF::String& context, WTF::Vector<WTF::String>& guesses);138 138 virtual void willSetInputMethodState(); 139 139 virtual void setInputMethodState(bool enabled); 140 virtual void requestCheckingOfString(WebCore::SpellChecker*, int, const WTF::String&) {}141 140 142 141 private: 142 #if ENABLE(SPELLCHECK) 143 TextCheckerClientEnchant m_textCheckerClient; 144 #else 145 WebCore::EmptyTextCheckerClient m_textCheckerClient; 146 #endif 143 147 WebKitWebView* m_webView; 144 148 bool m_preventNextCompositionCommit; -
trunk/Source/WebKit/gtk/webkit/webkitwebsettings.cpp
r78749 r79130 35 35 #include "webkitversion.h" 36 36 #include "webkitwebsettingsprivate.h" 37 #include <enchant.h>38 37 #include <wtf/text/CString.h> 39 38 #include <wtf/text/StringConcatenate.h> … … 91 90 gboolean enable_spell_checking; 92 91 gchar* spell_checking_languages; 93 GSList* enchant_dicts;94 92 gboolean enable_caret_browsing; 95 93 gboolean enable_html5_database; … … 921 919 } 922 920 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 940 921 static void webkit_web_settings_finalize(GObject* object) 941 922 { … … 953 934 g_free(priv->spell_checking_languages); 954 935 955 g_slist_foreach(priv->enchant_dicts, free_spell_checking_language, 0);956 g_slist_free(priv->enchant_dicts);957 958 936 g_free(priv->user_agent); 959 937 960 938 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);968 939 } 969 940 … … 972 943 WebKitWebSettings* web_settings = WEBKIT_WEB_SETTINGS(object); 973 944 WebKitWebSettingsPrivate* priv = web_settings->priv; 974 EnchantBroker* broker;975 EnchantDict* dict;976 GSList* spellDictionaries = 0;977 945 978 946 switch(prop_id) { … … 1066 1034 g_free(priv->spell_checking_languages); 1067 1035 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 list1086 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;1097 1036 break; 1098 1037 case PROP_ENABLE_XSS_AUDITOR: … … 1422 1361 } 1423 1362 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 1433 1363 namespace WebKit { 1434 1364 -
trunk/Source/WebKit/gtk/webkit/webkitwebview.cpp
r78342 r79130 3486 3486 else if (name == g_intern_string("enable-hyperlink-auditing")) 3487 3487 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 3488 3494 else if (!g_object_class_find_property(G_OBJECT_GET_CLASS(webSettings), name)) 3489 3495 g_warning("Unexpected setting '%s'", name); -
trunk/configure.ac
r79096 r79130 287 287 AC_SUBST(PANGO_LIBS) 288 288 289 PKG_CHECK_MODULES(ENCHANT, enchant >= $ENCHANT_REQUIRED_VERSION) 289 AC_MSG_CHECKING([whether to enable spellcheck support]) 290 AC_ARG_ENABLE([spellcheck], 291 [AS_HELP_STRING([--enable-spellcheck],[enable support for spellcheck])], 292 [],[enable_spellcheck="yes"]) 293 AC_MSG_RESULT([$enable_spellcheck]) 294 295 if test "$enable_spellcheck" = "yes"; then 296 PKG_CHECK_MODULES(ENCHANT, enchant >= $ENCHANT_REQUIRED_VERSION, [], [enable_spellcheck="no"]) 290 297 AC_SUBST(ENCHANT_CFLAGS) 291 298 AC_SUBST(ENCHANT_LIBS) 299 fi 292 300 293 301 PKG_CHECK_MODULES(GAIL, $GAIL_PC_NAME >= $GAIL_REQUIRED_VERSION) … … 1043 1051 AM_CONDITIONAL([ENABLE_OPCODE_STATS],[test "$enable_opcode_stats" = "yes"]) 1044 1052 AM_CONDITIONAL([ENABLE_WEBKIT2],[test "$enable_webkit2" = "yes"]) 1053 AM_CONDITIONAL([ENABLE_SPELLCHECK],[test "$enable_spellcheck" = "yes"]) 1045 1054 1046 1055 # Gtk conditionals … … 1132 1141 XPATH support : $enable_xpath 1133 1142 XSLT support : $enable_xslt 1143 Spellcheck support : $enable_spellcheck 1134 1144 1135 1145 GTK+ configuration:
Note: See TracChangeset
for help on using the changeset viewer.