Changeset 126298 in webkit
- Timestamp:
- Aug 22, 2012 6:34:13 AM (12 years ago)
- Location:
- trunk/Source
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r126297 r126298 1 2012-08-22 Carlos Garcia Campos <cgarcia@igalia.com> 2 3 [GTK] Preferred languages and spellchecker APIs are not consistent in WebKit2 4 https://bugs.webkit.org/show_bug.cgi?id=94683 5 6 Reviewed by Alejandro G. Castro. 7 8 Use a Vector<String> instead of a comma-separated string to 9 get/set languages. 10 11 * platform/text/gtk/TextCheckerEnchant.cpp: 12 (TextCheckerEnchant::updateSpellCheckingLanguages): 13 (TextCheckerEnchant::getSpellCheckingLanguages): 14 * platform/text/gtk/TextCheckerEnchant.h: 15 (TextCheckerEnchant): 16 1 17 2012-08-22 Pavel Feldman <pfeldman@chromium.org> 2 18 -
trunk/Source/WebCore/platform/text/gtk/TextCheckerEnchant.cpp
r125791 r126298 156 156 } 157 157 158 void TextCheckerEnchant::updateSpellCheckingLanguages(const String& languages)158 void TextCheckerEnchant::updateSpellCheckingLanguages(const Vector<String>& languages) 159 159 { 160 160 Vector<EnchantDict*> spellDictionaries; 161 161 162 162 if (!languages.isEmpty()) { 163 Vector<String> languagesVector; 164 languages.split(static_cast<UChar>(','), languagesVector); 165 for (Vector<String>::const_iterator iter = languagesVector.begin(); iter != languagesVector.end(); ++iter) { 163 for (Vector<String>::const_iterator iter = languages.begin(); iter != languages.end(); ++iter) { 166 164 CString currentLanguage = iter->utf8(); 167 165 if (enchant_broker_dict_exists(m_broker, currentLanguage.data())) { … … 189 187 } 190 188 191 String TextCheckerEnchant::getSpellCheckingLanguages() 192 { 189 Vector<String> TextCheckerEnchant::getSpellCheckingLanguages() 190 { 191 Vector<String> languages; 193 192 if (m_enchantDictionaries.isEmpty()) 194 return String();193 return languages; 195 194 196 195 // Get a Vector<CString> with the list of languages in use. … … 199 198 enchant_dict_describe(*iter, enchantDictDescribeCallback, ¤tDictionaries); 200 199 201 // Build the result String; 202 StringBuilder builder; 203 for (Vector<CString>::const_iterator iter = currentDictionaries.begin(); iter != currentDictionaries.end(); ++iter) { 204 if (iter != currentDictionaries.begin()) 205 builder.append(","); 206 builder.append(String::fromUTF8(iter->data())); 207 } 208 return builder.toString(); 200 for (Vector<CString>::const_iterator iter = currentDictionaries.begin(); iter != currentDictionaries.end(); ++iter) 201 languages.append(String::fromUTF8(iter->data())); 202 203 return languages; 209 204 } 210 205 -
trunk/Source/WebCore/platform/text/gtk/TextCheckerEnchant.h
r124763 r126298 42 42 void checkSpellingOfString(const String&, int& misspellingLocation, int& misspellingLength); 43 43 Vector<String> getGuessesForWord(const String&); 44 void updateSpellCheckingLanguages(const String& languages);45 StringgetSpellCheckingLanguages();44 void updateSpellCheckingLanguages(const Vector<String>& languages); 45 Vector<String> getSpellCheckingLanguages(); 46 46 47 47 private: -
trunk/Source/WebKit/gtk/ChangeLog
r126243 r126298 1 2012-08-22 Carlos Garcia Campos <cgarcia@igalia.com> 2 3 [GTK] Preferred languages and spellchecker APIs are not consistent in WebKit2 4 https://bugs.webkit.org/show_bug.cgi?id=94683 5 6 Reviewed by Alejandro G. Castro. 7 8 * webkit/webkitspellcheckerenchant.cpp: 9 (updateSpellCheckingLanguages): Split the languages string to pass a 10 Vector to updateSpellCheckingLanguages(). 11 1 12 2012-08-21 Joanmarie Diggs <jdiggs@igalia.com> 2 13 [Gtk] No accessible caret-moved events found in certain content -
trunk/Source/WebKit/gtk/webkit/webkitspellcheckerenchant.cpp
r124578 r126298 100 100 { 101 101 WebKitSpellCheckerEnchantPrivate* priv = WEBKIT_SPELL_CHECKER_ENCHANT(checker)->priv; 102 priv->textCheckerEnchant->updateSpellCheckingLanguages(String::fromUTF8(languages)); 102 103 Vector<String> languagesVector; 104 String::fromUTF8(languages).split(static_cast<UChar>(','), languagesVector); 105 priv->textCheckerEnchant->updateSpellCheckingLanguages(languagesVector); 103 106 } 104 107 -
trunk/Source/WebKit2/ChangeLog
r126296 r126298 1 2012-08-22 Carlos Garcia Campos <cgarcia@igalia.com> 2 3 [GTK] Preferred languages and spellchecker APIs are not consistent in WebKit2 4 https://bugs.webkit.org/show_bug.cgi?id=94683 5 6 Reviewed by Alejandro G. Castro. 7 8 Change spell-checker and preferred languages API to use a GStrv 9 instead of a comma-separated string and GList. This makes the API 10 more consistent and convenient to use. 11 12 * UIProcess/API/gtk/WebKitTextChecker.cpp: 13 (WebKitTextChecker::getSpellCheckingLanguages): Return a 14 Vector<String> instead of a String. 15 (WebKitTextChecker::setSpellCheckingLanguages): Receive a 16 Vector<String> instead of a String. 17 * UIProcess/API/gtk/WebKitTextChecker.h: 18 (WebKitTextChecker): Use a GPtrArray to cache languages. 19 * UIProcess/API/gtk/WebKitWebContext.cpp: 20 (webkit_web_context_get_spell_checking_languages): 21 (webkit_web_context_set_spell_checking_languages): 22 (webkit_web_context_set_preferred_languages): 23 * UIProcess/API/gtk/WebKitWebContext.h: 24 * UIProcess/API/gtk/tests/TestWebKitWebContext.cpp: 25 (testWebContextSpellChecker): 26 (testWebContextLanguages): 27 1 28 2012-08-22 Csaba Osztrogonác <ossy@webkit.org> 2 29 -
trunk/Source/WebKit2/UIProcess/API/gtk/WebKitTextChecker.cpp
r124763 r126298 30 30 31 31 #include "WebKitPrivate.h" 32 #include <wtf/Vector.h>33 #include <wtf/text/CString.h>34 32 35 33 using namespace WebKit; … … 141 139 } 142 140 143 const CString&WebKitTextChecker::getSpellCheckingLanguages()141 const char* const* WebKitTextChecker::getSpellCheckingLanguages() 144 142 { 145 String spellCheckingLanguages = m_textChecker->getSpellCheckingLanguages(); 146 m_spellCheckingLanguages = spellCheckingLanguages.isEmpty() ? CString() : spellCheckingLanguages.utf8(); 147 return m_spellCheckingLanguages; 143 Vector<String> spellCheckingLanguages = m_textChecker->getSpellCheckingLanguages(); 144 if (spellCheckingLanguages.isEmpty()) 145 return 0; 146 147 m_spellCheckingLanguages = adoptGRef(g_ptr_array_new_with_free_func(g_free)); 148 for (size_t i = 0; i < spellCheckingLanguages.size(); ++i) 149 g_ptr_array_add(m_spellCheckingLanguages.get(), g_strdup(spellCheckingLanguages[i].utf8().data())); 150 g_ptr_array_add(m_spellCheckingLanguages.get(), 0); 151 152 return reinterpret_cast<char**>(m_spellCheckingLanguages->pdata); 148 153 } 149 154 150 void WebKitTextChecker::setSpellCheckingLanguages(const CString&languages)155 void WebKitTextChecker::setSpellCheckingLanguages(const char* const* languages) 151 156 { 152 m_textChecker->updateSpellCheckingLanguages(String::fromUTF8(languages.data())); 157 Vector<String> spellCheckingLanguages; 158 for (size_t i = 0; languages[i]; ++i) 159 spellCheckingLanguages.append(String::fromUTF8(languages[i])); 160 m_textChecker->updateSpellCheckingLanguages(spellCheckingLanguages); 153 161 } 154 162 #endif // ENABLE(SPELLCHECK) -
trunk/Source/WebKit2/UIProcess/API/gtk/WebKitTextChecker.h
r124763 r126298 27 27 #include <wtf/PassOwnPtr.h> 28 28 #include <wtf/Vector.h> 29 #include <wtf/gobject/GRefPtr.h> 29 30 #include <wtf/text/CString.h> 30 31 … … 45 46 46 47 // To be called from WebKitWebContext only. 47 const CString&getSpellCheckingLanguages();48 void setSpellCheckingLanguages(const CString&spellCheckingLanguages);48 const char* const* getSpellCheckingLanguages(); 49 void setSpellCheckingLanguages(const char* const* spellCheckingLanguages); 49 50 50 51 private: … … 52 53 53 54 OwnPtr<WebCore::TextCheckerEnchant> m_textChecker; 54 CStringm_spellCheckingLanguages;55 GRefPtr<GPtrArray> m_spellCheckingLanguages; 55 56 bool m_spellCheckingEnabled; 56 57 }; -
trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp
r126152 r126298 496 496 * 497 497 * Get the the list of spell checking languages associated with 498 * @context separated by commas, or %NULL if no languages have been 499 * previously set. 500 498 * @context, or %NULL if no languages have been previously set. 499 * 501 500 * See webkit_web_context_set_spell_checking_languages() for more 502 501 * details on the format of the languages in the list. 503 502 * 504 * Returns: ( transfer none): A comma separated list of languages if505 * available, or %NULL otherwise.506 */ 507 const gchar* webkit_web_context_get_spell_checking_languages(WebKitWebContext* context)503 * Returns: (array zero-terminated=1) (element-type utf8) (transfer none): A %NULL-terminated 504 * array of languages if available, or %NULL otherwise. 505 */ 506 const gchar* const* webkit_web_context_get_spell_checking_languages(WebKitWebContext* context) 508 507 { 509 508 g_return_val_if_fail(WEBKIT_IS_WEB_CONTEXT(context), 0); 510 509 511 510 #if ENABLE(SPELLCHECK) 512 CString spellCheckingLanguages = context->priv->textChecker->getSpellCheckingLanguages(); 513 if (spellCheckingLanguages.isNull()) 514 return 0; 515 return spellCheckingLanguages.data(); 511 return context->priv->textChecker->getSpellCheckingLanguages(); 516 512 #else 517 513 return 0; … … 522 518 * webkit_web_context_set_spell_checking_languages: 523 519 * @context: a #WebKitWebContext 524 * @languages: new list of spell checking languages separated by 525 * commas 520 * @languages: (array zero-terminated=1) (transfer none): a %NULL-terminated list of spell checking languages 526 521 * 527 522 * Set the list of spell checking languages to be used for spell 528 * checking , separated by commas.523 * checking. 529 524 * 530 525 * The locale string typically is in the form lang_COUNTRY, where lang … … 537 532 * in WebKit. 538 533 */ 539 void webkit_web_context_set_spell_checking_languages(WebKitWebContext* context, const gchar* languages)534 void webkit_web_context_set_spell_checking_languages(WebKitWebContext* context, const gchar* const* languages) 540 535 { 541 536 g_return_if_fail(WEBKIT_IS_WEB_CONTEXT(context)); … … 550 545 * webkit_web_context_set_preferred_languages: 551 546 * @context: a #WebKitWebContext 552 * @languages: ( element-type utf8): a #GList of language identifiers547 * @languages: (allow-none) (array zero-terminated=1) (element-type utf8) (transfer none): a %NULL-terminated list of language identifiers 553 548 * 554 549 * Set the list of preferred languages, sorted from most desirable … … 557 552 * the #WebKitWebContext. 558 553 */ 559 void webkit_web_context_set_preferred_languages(WebKitWebContext* context, GList* languageList)560 { 561 g_return_if_fail(WEBKIT_IS_WEB_CONTEXT(context)); 562 563 if (!languageList )554 void webkit_web_context_set_preferred_languages(WebKitWebContext* context, const gchar* const* languageList) 555 { 556 g_return_if_fail(WEBKIT_IS_WEB_CONTEXT(context)); 557 558 if (!languageList || !g_strv_length(const_cast<char**>(languageList))) 564 559 return; 565 560 566 561 Vector<String> languages; 567 for ( GList* iter = languageList; iter; iter = g_list_next(iter))568 languages.append(String::fromUTF8( static_cast<char*>(iter->data)).lower().replace("_", "-"));562 for (size_t i = 0; languageList[i]; ++i) 563 languages.append(String::fromUTF8(languageList[i]).lower().replace("_", "-")); 569 564 570 565 WebCore::overrideUserPreferredLanguages(languages); -
trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.h
r126152 r126298 141 141 webkit_web_context_set_spell_checking_enabled (WebKitWebContext *context, 142 142 gboolean enabled); 143 WEBKIT_API const gchar * 143 WEBKIT_API const gchar * const * 144 144 webkit_web_context_get_spell_checking_languages (WebKitWebContext *context); 145 145 146 146 WEBKIT_API void 147 147 webkit_web_context_set_spell_checking_languages (WebKitWebContext *context, 148 const gchar 148 const gchar * const *languages); 149 149 150 150 WEBKIT_API void 151 151 webkit_web_context_set_preferred_languages (WebKitWebContext *context, 152 GList*languages);152 const gchar * const *languages); 153 153 154 154 G_END_DECLS -
trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebContext.cpp
r126152 r126298 211 211 212 212 // Check what happens if no spell checking language has been set. 213 const gchar* c urrentLanguage = webkit_web_context_get_spell_checking_languages(webContext);213 const gchar* const* currentLanguage = webkit_web_context_get_spell_checking_languages(webContext); 214 214 g_assert(!currentLanguage); 215 215 216 216 // Set the language to a specific one. 217 webkit_web_context_set_spell_checking_languages(webContext, "en_US"); 217 GRefPtr<GPtrArray> languages = adoptGRef(g_ptr_array_new()); 218 g_ptr_array_add(languages.get(), const_cast<gpointer>(static_cast<const void*>("en_US"))); 219 g_ptr_array_add(languages.get(), 0); 220 webkit_web_context_set_spell_checking_languages(webContext, reinterpret_cast<const char* const*>(languages->pdata)); 218 221 currentLanguage = webkit_web_context_get_spell_checking_languages(webContext); 219 g_assert_cmpstr(currentLanguage, ==, "en_US"); 222 g_assert_cmpuint(g_strv_length(const_cast<char**>(currentLanguage)), ==, 1); 223 g_assert_cmpstr(currentLanguage[0], ==, "en_US"); 220 224 221 225 // Set the language string to list of valid languages. 222 webkit_web_context_set_spell_checking_languages(webContext, "en_GB,en_US"); 226 g_ptr_array_remove_index_fast(languages.get(), languages->len - 1); 227 g_ptr_array_add(languages.get(), const_cast<gpointer>(static_cast<const void*>("en_GB"))); 228 g_ptr_array_add(languages.get(), 0); 229 webkit_web_context_set_spell_checking_languages(webContext, reinterpret_cast<const char* const*>(languages->pdata)); 223 230 currentLanguage = webkit_web_context_get_spell_checking_languages(webContext); 224 g_assert_cmpstr(currentLanguage, ==, "en_GB,en_US"); 231 g_assert_cmpuint(g_strv_length(const_cast<char**>(currentLanguage)), ==, 2); 232 g_assert_cmpstr(currentLanguage[0], ==, "en_US"); 233 g_assert_cmpstr(currentLanguage[1], ==, "en_GB"); 225 234 226 235 // Try passing a wrong language along with good ones. 227 webkit_web_context_set_spell_checking_languages(webContext, "bd_WR,en_US,en_GB"); 236 g_ptr_array_remove_index_fast(languages.get(), languages->len - 1); 237 g_ptr_array_add(languages.get(), const_cast<gpointer>(static_cast<const void*>("bd_WR"))); 238 g_ptr_array_add(languages.get(), 0); 239 webkit_web_context_set_spell_checking_languages(webContext, reinterpret_cast<const char* const*>(languages->pdata)); 228 240 currentLanguage = webkit_web_context_get_spell_checking_languages(webContext); 229 g_assert_cmpstr(currentLanguage, ==, "en_US,en_GB"); 241 g_assert_cmpuint(g_strv_length(const_cast<char**>(currentLanguage)), ==, 2); 242 g_assert_cmpstr(currentLanguage[0], ==, "en_US"); 243 g_assert_cmpstr(currentLanguage[1], ==, "en_GB"); 230 244 231 245 // Try passing a list with only wrong languages. 232 webkit_web_context_set_spell_checking_languages(webContext, "bd_WR,wr_BD"); 246 languages = adoptGRef(g_ptr_array_new()); 247 g_ptr_array_add(languages.get(), const_cast<gpointer>(static_cast<const void*>("bd_WR"))); 248 g_ptr_array_add(languages.get(), const_cast<gpointer>(static_cast<const void*>("wr_BD"))); 249 g_ptr_array_add(languages.get(), 0); 250 webkit_web_context_set_spell_checking_languages(webContext, reinterpret_cast<const char* const*>(languages->pdata)); 233 251 currentLanguage = webkit_web_context_get_spell_checking_languages(webContext); 234 252 g_assert(!currentLanguage); … … 251 269 g_assert(!strncmp(mainResourceData, expectedDefaultLanguage, mainResourceDataSize)); 252 270 253 GList* languages = g_list_prepend(0, const_cast<gpointer>(static_cast<const void*>("dE"))); 254 languages = g_list_prepend(languages, const_cast<gpointer>(static_cast<const void*>("ES_es"))); 255 languages = g_list_prepend(languages, const_cast<gpointer>(static_cast<const void*>("en"))); 256 webkit_web_context_set_preferred_languages(webkit_web_context_get_default(), languages); 257 g_list_free(languages); 271 GRefPtr<GPtrArray> languages = adoptGRef(g_ptr_array_new()); 272 g_ptr_array_add(languages.get(), const_cast<gpointer>(static_cast<const void*>("en"))); 273 g_ptr_array_add(languages.get(), const_cast<gpointer>(static_cast<const void*>("ES_es"))); 274 g_ptr_array_add(languages.get(), const_cast<gpointer>(static_cast<const void*>("dE"))); 275 g_ptr_array_add(languages.get(), 0); 276 webkit_web_context_set_preferred_languages(webkit_web_context_get_default(), reinterpret_cast<const char* const*>(languages->pdata)); 258 277 259 278 static const char* expectedLanguages = "en, es-es;q=0.90, de;q=0.80";
Note: See TracChangeset
for help on using the changeset viewer.