WebKit Bugzilla
New
Browse
Search+
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
[patch]
Patch
wk2-languages-api.diff (text/plain), 20.78 KB, created by
Carlos Garcia Campos
on 2012-08-22 02:15:20 PDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Carlos Garcia Campos
Created:
2012-08-22 02:15:20 PDT
Size:
20.78 KB
patch
obsolete
>diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog >index 851a277..3235c53 100644 >--- a/Source/WebCore/ChangeLog >+++ b/Source/WebCore/ChangeLog >@@ -1,3 +1,19 @@ >+2012-08-22 Carlos Garcia Campos <cgarcia@igalia.com> >+ >+ [GTK] Preferred languages and spellchecker APIs are not consistent in WebKit2 >+ https://bugs.webkit.org/show_bug.cgi?id=94683 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Use a Vector<String> instead of a comma-separated string to >+ get/set languages. >+ >+ * platform/text/gtk/TextCheckerEnchant.cpp: >+ (TextCheckerEnchant::updateSpellCheckingLanguages): >+ (TextCheckerEnchant::getSpellCheckingLanguages): >+ * platform/text/gtk/TextCheckerEnchant.h: >+ (TextCheckerEnchant): >+ > 2012-08-21 Kentaro Hara <haraken@chromium.org> > > [V8] Move String related code in V8Binding to a separate file >diff --git a/Source/WebKit/gtk/ChangeLog b/Source/WebKit/gtk/ChangeLog >index 2ef7919..2ad918e 100644 >--- a/Source/WebKit/gtk/ChangeLog >+++ b/Source/WebKit/gtk/ChangeLog >@@ -1,3 +1,14 @@ >+2012-08-22 Carlos Garcia Campos <cgarcia@igalia.com> >+ >+ [GTK] Preferred languages and spellchecker APIs are not consistent in WebKit2 >+ https://bugs.webkit.org/show_bug.cgi?id=94683 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ * webkit/webkitspellcheckerenchant.cpp: >+ (updateSpellCheckingLanguages): Split the languages string to pass a >+ Vector to updateSpellCheckingLanguages(). >+ > 2012-08-21 Joanmarie Diggs <jdiggs@igalia.com> > [Gtk] No accessible caret-moved events found in certain content > https://bugs.webkit.org/show_bug.cgi?id=72811 >diff --git a/Source/WebKit2/ChangeLog b/Source/WebKit2/ChangeLog >index 36d5d46..a8048c4 100644 >--- a/Source/WebKit2/ChangeLog >+++ b/Source/WebKit2/ChangeLog >@@ -1,3 +1,30 @@ >+2012-08-22 Carlos Garcia Campos <cgarcia@igalia.com> >+ >+ [GTK] Preferred languages and spellchecker APIs are not consistent in WebKit2 >+ https://bugs.webkit.org/show_bug.cgi?id=94683 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Change spell-checker and preferred languages API to use a GStrv >+ instead of a comma-separated string and GList. This makes the API >+ more consistent and convenient to use. >+ >+ * UIProcess/API/gtk/WebKitTextChecker.cpp: >+ (WebKitTextChecker::getSpellCheckingLanguages): Return a >+ Vector<String> instead of a String. >+ (WebKitTextChecker::setSpellCheckingLanguages): Receive a >+ Vector<String> instead of a String. >+ * UIProcess/API/gtk/WebKitTextChecker.h: >+ (WebKitTextChecker): Use a GPtrArray to cache languages. >+ * UIProcess/API/gtk/WebKitWebContext.cpp: >+ (webkit_web_context_get_spell_checking_languages): >+ (webkit_web_context_set_spell_checking_languages): >+ (webkit_web_context_set_preferred_languages): >+ * UIProcess/API/gtk/WebKitWebContext.h: >+ * UIProcess/API/gtk/tests/TestWebKitWebContext.cpp: >+ (testWebContextSpellChecker): >+ (testWebContextLanguages): >+ > 2012-08-21 Sheriff Bot <webkit.review.bot@gmail.com> > > Unreviewed, rolling out r126216. >diff --git a/Source/WebCore/platform/text/gtk/TextCheckerEnchant.cpp b/Source/WebCore/platform/text/gtk/TextCheckerEnchant.cpp >index f3f60e6..11a3ef2 100644 >--- a/Source/WebCore/platform/text/gtk/TextCheckerEnchant.cpp >+++ b/Source/WebCore/platform/text/gtk/TextCheckerEnchant.cpp >@@ -155,14 +155,12 @@ Vector<String> TextCheckerEnchant::getGuessesForWord(const String& word) > return guesses; > } > >-void TextCheckerEnchant::updateSpellCheckingLanguages(const String& languages) >+void TextCheckerEnchant::updateSpellCheckingLanguages(const Vector<String>& languages) > { > Vector<EnchantDict*> spellDictionaries; > > if (!languages.isEmpty()) { >- Vector<String> languagesVector; >- languages.split(static_cast<UChar>(','), languagesVector); >- for (Vector<String>::const_iterator iter = languagesVector.begin(); iter != languagesVector.end(); ++iter) { >+ for (Vector<String>::const_iterator iter = languages.begin(); iter != languages.end(); ++iter) { > CString currentLanguage = iter->utf8(); > if (enchant_broker_dict_exists(m_broker, currentLanguage.data())) { > EnchantDict* dict = enchant_broker_request_dict(m_broker, currentLanguage.data()); >@@ -188,24 +186,21 @@ void TextCheckerEnchant::updateSpellCheckingLanguages(const String& languages) > m_enchantDictionaries = spellDictionaries; > } > >-String TextCheckerEnchant::getSpellCheckingLanguages() >+Vector<String> TextCheckerEnchant::getSpellCheckingLanguages() > { >+ Vector<String> languages; > if (m_enchantDictionaries.isEmpty()) >- return String(); >+ return languages; > > // Get a Vector<CString> with the list of languages in use. > Vector<CString> currentDictionaries; > for (Vector<EnchantDict*>::const_iterator iter = m_enchantDictionaries.begin(); iter != m_enchantDictionaries.end(); ++iter) > enchant_dict_describe(*iter, enchantDictDescribeCallback, ¤tDictionaries); > >- // Build the result String; >- StringBuilder builder; >- for (Vector<CString>::const_iterator iter = currentDictionaries.begin(); iter != currentDictionaries.end(); ++iter) { >- if (iter != currentDictionaries.begin()) >- builder.append(","); >- builder.append(String::fromUTF8(iter->data())); >- } >- return builder.toString(); >+ for (Vector<CString>::const_iterator iter = currentDictionaries.begin(); iter != currentDictionaries.end(); ++iter) >+ languages.append(String::fromUTF8(iter->data())); >+ >+ return languages; > } > > void TextCheckerEnchant::freeEnchantBrokerDictionaries() >diff --git a/Source/WebCore/platform/text/gtk/TextCheckerEnchant.h b/Source/WebCore/platform/text/gtk/TextCheckerEnchant.h >index e7a9809..1780b45 100644 >--- a/Source/WebCore/platform/text/gtk/TextCheckerEnchant.h >+++ b/Source/WebCore/platform/text/gtk/TextCheckerEnchant.h >@@ -41,8 +41,8 @@ public: > void learnWord(const String&); > void checkSpellingOfString(const String&, int& misspellingLocation, int& misspellingLength); > Vector<String> getGuessesForWord(const String&); >- void updateSpellCheckingLanguages(const String& languages); >- String getSpellCheckingLanguages(); >+ void updateSpellCheckingLanguages(const Vector<String>& languages); >+ Vector<String> getSpellCheckingLanguages(); > > private: > TextCheckerEnchant(); >diff --git a/Source/WebKit/gtk/webkit/webkitspellcheckerenchant.cpp b/Source/WebKit/gtk/webkit/webkitspellcheckerenchant.cpp >index 07d34d1..83be3a3 100644 >--- a/Source/WebKit/gtk/webkit/webkitspellcheckerenchant.cpp >+++ b/Source/WebKit/gtk/webkit/webkitspellcheckerenchant.cpp >@@ -99,7 +99,10 @@ static char** getGuessesForWord(WebKitSpellChecker* checker, const char* word, c > static void updateSpellCheckingLanguages(WebKitSpellChecker* checker, const char* languages) > { > WebKitSpellCheckerEnchantPrivate* priv = WEBKIT_SPELL_CHECKER_ENCHANT(checker)->priv; >- priv->textCheckerEnchant->updateSpellCheckingLanguages(String::fromUTF8(languages)); >+ >+ Vector<String> languagesVector; >+ String::fromUTF8(languages).split(static_cast<UChar>(','), languagesVector); >+ priv->textCheckerEnchant->updateSpellCheckingLanguages(languagesVector); > } > > static char* getAutocorrectSuggestionsForMisspelledWord(WebKitSpellChecker* checker, const char* word) >diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitTextChecker.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitTextChecker.cpp >index 5ae62c6..39f4022 100644 >--- a/Source/WebKit2/UIProcess/API/gtk/WebKitTextChecker.cpp >+++ b/Source/WebKit2/UIProcess/API/gtk/WebKitTextChecker.cpp >@@ -29,8 +29,6 @@ > #if ENABLE(SPELLCHECK) > > #include "WebKitPrivate.h" >-#include <wtf/Vector.h> >-#include <wtf/text/CString.h> > > using namespace WebKit; > >@@ -140,15 +138,25 @@ void WebKitTextChecker::setSpellCheckingEnabled(bool enabled) > WKTextCheckerContinuousSpellCheckingEnabledStateChanged(enabled); > } > >-const CString& WebKitTextChecker::getSpellCheckingLanguages() >+const char* const* WebKitTextChecker::getSpellCheckingLanguages() > { >- String spellCheckingLanguages = m_textChecker->getSpellCheckingLanguages(); >- m_spellCheckingLanguages = spellCheckingLanguages.isEmpty() ? CString() : spellCheckingLanguages.utf8(); >- return m_spellCheckingLanguages; >+ Vector<String> spellCheckingLanguages = m_textChecker->getSpellCheckingLanguages(); >+ if (spellCheckingLanguages.isEmpty()) >+ return 0; >+ >+ m_spellCheckingLanguages = adoptGRef(g_ptr_array_new_with_free_func(g_free)); >+ for (size_t i = 0; i < spellCheckingLanguages.size(); ++i) >+ g_ptr_array_add(m_spellCheckingLanguages.get(), g_strdup(spellCheckingLanguages[i].utf8().data())); >+ g_ptr_array_add(m_spellCheckingLanguages.get(), 0); >+ >+ return reinterpret_cast<char**>(m_spellCheckingLanguages->pdata); > } > >-void WebKitTextChecker::setSpellCheckingLanguages(const CString& languages) >+void WebKitTextChecker::setSpellCheckingLanguages(const char* const* languages) > { >- m_textChecker->updateSpellCheckingLanguages(String::fromUTF8(languages.data())); >+ Vector<String> spellCheckingLanguages; >+ for (size_t i = 0; languages[i]; ++i) >+ spellCheckingLanguages.append(String::fromUTF8(languages[i])); >+ m_textChecker->updateSpellCheckingLanguages(spellCheckingLanguages); > } > #endif // ENABLE(SPELLCHECK) >diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitTextChecker.h b/Source/WebKit2/UIProcess/API/gtk/WebKitTextChecker.h >index 3cca562..15f764f 100644 >--- a/Source/WebKit2/UIProcess/API/gtk/WebKitTextChecker.h >+++ b/Source/WebKit2/UIProcess/API/gtk/WebKitTextChecker.h >@@ -26,6 +26,7 @@ > #include <wtf/FastAllocBase.h> > #include <wtf/PassOwnPtr.h> > #include <wtf/Vector.h> >+#include <wtf/gobject/GRefPtr.h> > #include <wtf/text/CString.h> > > class WebKitTextChecker { >@@ -44,14 +45,14 @@ public: > void ignoreWord(const String& word); > > // To be called from WebKitWebContext only. >- const CString& getSpellCheckingLanguages(); >- void setSpellCheckingLanguages(const CString& spellCheckingLanguages); >+ const char* const* getSpellCheckingLanguages(); >+ void setSpellCheckingLanguages(const char* const* spellCheckingLanguages); > > private: > WebKitTextChecker(); > > OwnPtr<WebCore::TextCheckerEnchant> m_textChecker; >- CString m_spellCheckingLanguages; >+ GRefPtr<GPtrArray> m_spellCheckingLanguages; > bool m_spellCheckingEnabled; > }; > >diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp >index 211133f..e9231e4 100644 >--- a/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp >+++ b/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp >@@ -495,24 +495,20 @@ void webkit_web_context_set_spell_checking_enabled(WebKitWebContext* context, gb > * @context: a #WebKitWebContext > * > * Get the the list of spell checking languages associated with >- * @context separated by commas, or %NULL if no languages have been >- * previously set. >- >+ * @context, or %NULL if no languages have been previously set. >+ * > * See webkit_web_context_set_spell_checking_languages() for more > * details on the format of the languages in the list. > * >- * Returns: (transfer none): A comma separated list of languages if >- * available, or %NULL otherwise. >+ * Returns: (array zero-terminated=1) (element-type utf8) (transfer none): A %NULL-terminated >+ * array of languages if available, or %NULL otherwise. > */ >-const gchar* webkit_web_context_get_spell_checking_languages(WebKitWebContext* context) >+const gchar* const* webkit_web_context_get_spell_checking_languages(WebKitWebContext* context) > { > g_return_val_if_fail(WEBKIT_IS_WEB_CONTEXT(context), 0); > > #if ENABLE(SPELLCHECK) >- CString spellCheckingLanguages = context->priv->textChecker->getSpellCheckingLanguages(); >- if (spellCheckingLanguages.isNull()) >- return 0; >- return spellCheckingLanguages.data(); >+ return context->priv->textChecker->getSpellCheckingLanguages(); > #else > return 0; > #endif >@@ -521,11 +517,10 @@ const gchar* webkit_web_context_get_spell_checking_languages(WebKitWebContext* c > /** > * webkit_web_context_set_spell_checking_languages: > * @context: a #WebKitWebContext >- * @languages: new list of spell checking languages separated by >- * commas >+ * @languages: (array zero-terminated=1) (transfer none): a %NULL-terminated list of spell checking languages > * > * Set the list of spell checking languages to be used for spell >- * checking, separated by commas. >+ * checking. > * > * The locale string typically is in the form lang_COUNTRY, where lang > * is an ISO-639 language code, and COUNTRY is an ISO-3166 country code. >@@ -536,7 +531,7 @@ const gchar* webkit_web_context_get_spell_checking_languages(WebKitWebContext* c > * least once in order to properly enable the spell checking feature > * in WebKit. > */ >-void webkit_web_context_set_spell_checking_languages(WebKitWebContext* context, const gchar* languages) >+void webkit_web_context_set_spell_checking_languages(WebKitWebContext* context, const gchar* const* languages) > { > g_return_if_fail(WEBKIT_IS_WEB_CONTEXT(context)); > g_return_if_fail(languages); >@@ -549,23 +544,23 @@ void webkit_web_context_set_spell_checking_languages(WebKitWebContext* context, > /** > * webkit_web_context_set_preferred_languages: > * @context: a #WebKitWebContext >- * @languages: (element-type utf8): a #GList of language identifiers >+ * @languages: (allow-none) (array zero-terminated=1) (element-type utf8) (transfer none): a %NULL-terminated list of language identifiers > * > * Set the list of preferred languages, sorted from most desirable > * to least desirable. The list will be used to build the "Accept-Language" > * header that will be included in the network requests started by > * the #WebKitWebContext. > */ >-void webkit_web_context_set_preferred_languages(WebKitWebContext* context, GList* languageList) >+void webkit_web_context_set_preferred_languages(WebKitWebContext* context, const gchar* const* languageList) > { > g_return_if_fail(WEBKIT_IS_WEB_CONTEXT(context)); > >- if (!languageList) >+ if (!languageList || !g_strv_length(const_cast<char**>(languageList))) > return; > > Vector<String> languages; >- for (GList* iter = languageList; iter; iter = g_list_next(iter)) >- languages.append(String::fromUTF8(static_cast<char*>(iter->data)).lower().replace("_", "-")); >+ for (size_t i = 0; languageList[i]; ++i) >+ languages.append(String::fromUTF8(languageList[i]).lower().replace("_", "-")); > > WebCore::overrideUserPreferredLanguages(languages); > WebCore::languageDidChange(); >diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.h b/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.h >index 3c97c71..a2bf573 100644 >--- a/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.h >+++ b/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.h >@@ -140,16 +140,16 @@ webkit_web_context_get_spell_checking_enabled (WebKitWebContext > WEBKIT_API void > webkit_web_context_set_spell_checking_enabled (WebKitWebContext *context, > gboolean enabled); >-WEBKIT_API const gchar * >+WEBKIT_API const gchar * const * > webkit_web_context_get_spell_checking_languages (WebKitWebContext *context); > > WEBKIT_API void > webkit_web_context_set_spell_checking_languages (WebKitWebContext *context, >- const gchar *languages); >+ const gchar * const *languages); > > WEBKIT_API void > webkit_web_context_set_preferred_languages (WebKitWebContext *context, >- GList *languages); >+ const gchar * const *languages); > > G_END_DECLS > >diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebContext.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebContext.cpp >index 27f6a54..7c71224 100644 >--- a/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebContext.cpp >+++ b/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebContext.cpp >@@ -210,26 +210,44 @@ static void testWebContextSpellChecker(Test* test, gconstpointer) > WebKitWebContext* webContext = webkit_web_context_get_default(); > > // Check what happens if no spell checking language has been set. >- const gchar* currentLanguage = webkit_web_context_get_spell_checking_languages(webContext); >+ const gchar* const* currentLanguage = webkit_web_context_get_spell_checking_languages(webContext); > g_assert(!currentLanguage); > > // Set the language to a specific one. >- webkit_web_context_set_spell_checking_languages(webContext, "en_US"); >+ GRefPtr<GPtrArray> languages = adoptGRef(g_ptr_array_new()); >+ g_ptr_array_add(languages.get(), const_cast<gpointer>(static_cast<const void*>("en_US"))); >+ g_ptr_array_add(languages.get(), 0); >+ webkit_web_context_set_spell_checking_languages(webContext, reinterpret_cast<const char* const*>(languages->pdata)); > currentLanguage = webkit_web_context_get_spell_checking_languages(webContext); >- g_assert_cmpstr(currentLanguage, ==, "en_US"); >+ g_assert_cmpuint(g_strv_length(const_cast<char**>(currentLanguage)), ==, 1); >+ g_assert_cmpstr(currentLanguage[0], ==, "en_US"); > > // Set the language string to list of valid languages. >- webkit_web_context_set_spell_checking_languages(webContext, "en_GB,en_US"); >+ g_ptr_array_remove_index_fast(languages.get(), languages->len - 1); >+ g_ptr_array_add(languages.get(), const_cast<gpointer>(static_cast<const void*>("en_GB"))); >+ g_ptr_array_add(languages.get(), 0); >+ webkit_web_context_set_spell_checking_languages(webContext, reinterpret_cast<const char* const*>(languages->pdata)); > currentLanguage = webkit_web_context_get_spell_checking_languages(webContext); >- g_assert_cmpstr(currentLanguage, ==, "en_GB,en_US"); >+ g_assert_cmpuint(g_strv_length(const_cast<char**>(currentLanguage)), ==, 2); >+ g_assert_cmpstr(currentLanguage[0], ==, "en_US"); >+ g_assert_cmpstr(currentLanguage[1], ==, "en_GB"); > > // Try passing a wrong language along with good ones. >- webkit_web_context_set_spell_checking_languages(webContext, "bd_WR,en_US,en_GB"); >+ g_ptr_array_remove_index_fast(languages.get(), languages->len - 1); >+ g_ptr_array_add(languages.get(), const_cast<gpointer>(static_cast<const void*>("bd_WR"))); >+ g_ptr_array_add(languages.get(), 0); >+ webkit_web_context_set_spell_checking_languages(webContext, reinterpret_cast<const char* const*>(languages->pdata)); > currentLanguage = webkit_web_context_get_spell_checking_languages(webContext); >- g_assert_cmpstr(currentLanguage, ==, "en_US,en_GB"); >+ g_assert_cmpuint(g_strv_length(const_cast<char**>(currentLanguage)), ==, 2); >+ g_assert_cmpstr(currentLanguage[0], ==, "en_US"); >+ g_assert_cmpstr(currentLanguage[1], ==, "en_GB"); > > // Try passing a list with only wrong languages. >- webkit_web_context_set_spell_checking_languages(webContext, "bd_WR,wr_BD"); >+ languages = adoptGRef(g_ptr_array_new()); >+ g_ptr_array_add(languages.get(), const_cast<gpointer>(static_cast<const void*>("bd_WR"))); >+ g_ptr_array_add(languages.get(), const_cast<gpointer>(static_cast<const void*>("wr_BD"))); >+ g_ptr_array_add(languages.get(), 0); >+ webkit_web_context_set_spell_checking_languages(webContext, reinterpret_cast<const char* const*>(languages->pdata)); > currentLanguage = webkit_web_context_get_spell_checking_languages(webContext); > g_assert(!currentLanguage); > >@@ -250,11 +268,12 @@ static void testWebContextLanguages(WebViewTest* test, gconstpointer) > g_assert_cmpuint(mainResourceDataSize, ==, strlen(expectedDefaultLanguage)); > g_assert(!strncmp(mainResourceData, expectedDefaultLanguage, mainResourceDataSize)); > >- GList* languages = g_list_prepend(0, const_cast<gpointer>(static_cast<const void*>("dE"))); >- languages = g_list_prepend(languages, const_cast<gpointer>(static_cast<const void*>("ES_es"))); >- languages = g_list_prepend(languages, const_cast<gpointer>(static_cast<const void*>("en"))); >- webkit_web_context_set_preferred_languages(webkit_web_context_get_default(), languages); >- g_list_free(languages); >+ GRefPtr<GPtrArray> languages = adoptGRef(g_ptr_array_new()); >+ g_ptr_array_add(languages.get(), const_cast<gpointer>(static_cast<const void*>("en"))); >+ g_ptr_array_add(languages.get(), const_cast<gpointer>(static_cast<const void*>("ES_es"))); >+ g_ptr_array_add(languages.get(), const_cast<gpointer>(static_cast<const void*>("dE"))); >+ g_ptr_array_add(languages.get(), 0); >+ webkit_web_context_set_preferred_languages(webkit_web_context_get_default(), reinterpret_cast<const char* const*>(languages->pdata)); > > static const char* expectedLanguages = "en, es-es;q=0.90, de;q=0.80"; > test->loadURI(kServer->getURIForPath("/").data());
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Flags:
alex
:
review+
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 94683
: 159886