Changeset 124763 in webkit
- Timestamp:
- Aug 6, 2012 6:43:07 AM (12 years ago)
- Location:
- trunk/Source
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r124760 r124763 1 2012-08-06 Mario Sanchez Prada <msanchez@igalia.com> 2 3 [WK2][GTK] Improvements for the new spell-checking API 4 https://bugs.webkit.org/show_bug.cgi?id=93262 5 6 Reviewed by Carlos Garcia Campos. 7 8 Provide a way to ask TextCheckerEnchant helper class for the list 9 of languages currently available for the spell checking feature. 10 11 * platform/text/gtk/TextCheckerEnchant.cpp: 12 (enchantDictDescribeCallback): Renamed from 13 getAvailableDictionariesCallback, for consistency. 14 (TextCheckerEnchant::updateSpellCheckingLanguages): Updated usage 15 of getAvailableDictionariesCallback to enchantDictDescribeCallback. 16 (TextCheckerEnchant::getSpellCheckingLanguages): New. Will build 17 and return a String with a comma-separated list of languages 18 currently in use by the spell checking feature. 19 * platform/text/gtk/TextCheckerEnchant.h: 20 (TextCheckerEnchant): Added new function getSpellCheckingLanguages. 21 1 22 2012-08-06 Andreas Kling <kling@webkit.org> 2 23 -
trunk/Source/WebCore/platform/text/gtk/TextCheckerEnchant.cpp
r124578 r124763 25 25 #include <wtf/gobject/GOwnPtr.h> 26 26 #include <wtf/text/CString.h> 27 #include <wtf/text/StringBuilder.h> 27 28 28 29 using namespace WebCore; … … 30 31 static const size_t maximumNumberOfSuggestions = 10; 31 32 32 static void getAvailableDictionariesCallback(const char* const languageTag, const char* const, const char* const, const char* const, void* data)33 static void enchantDictDescribeCallback(const char* const languageTag, const char* const, const char* const, const char* const, void* data) 33 34 { 34 35 Vector<CString>* dictionaries = static_cast<Vector<CString>*>(data); … … 177 178 // No dictionaries selected, we get one from the list. 178 179 Vector<CString> allDictionaries; 179 enchant_broker_list_dicts(m_broker, getAvailableDictionariesCallback, &allDictionaries);180 enchant_broker_list_dicts(m_broker, enchantDictDescribeCallback, &allDictionaries); 180 181 if (!allDictionaries.isEmpty()) { 181 182 EnchantDict* dict = enchant_broker_request_dict(m_broker, allDictionaries[0].data()); … … 188 189 } 189 190 191 String TextCheckerEnchant::getSpellCheckingLanguages() 192 { 193 if (m_enchantDictionaries.isEmpty()) 194 return String(); 195 196 // Get a Vector<CString> with the list of languages in use. 197 Vector<CString> currentDictionaries; 198 for (Vector<EnchantDict*>::const_iterator iter = m_enchantDictionaries.begin(); iter != m_enchantDictionaries.end(); ++iter) 199 enchant_dict_describe(*iter, enchantDictDescribeCallback, ¤tDictionaries); 200 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(); 209 } 210 190 211 void TextCheckerEnchant::freeEnchantBrokerDictionaries() 191 212 { -
trunk/Source/WebCore/platform/text/gtk/TextCheckerEnchant.h
r124578 r124763 43 43 Vector<String> getGuessesForWord(const String&); 44 44 void updateSpellCheckingLanguages(const String& languages); 45 String getSpellCheckingLanguages(); 45 46 46 47 private: -
trunk/Source/WebKit2/ChangeLog
r124758 r124763 1 2012-08-06 Mario Sanchez Prada <msanchez@igalia.com> 2 3 [WK2][GTK] Improvements for the new spell-checking API 4 https://bugs.webkit.org/show_bug.cgi?id=93262 5 6 Reviewed by Carlos Garcia Campos. 7 8 Improve the way the new spell-checking API is implemented, by 9 using better internal representations for data, documenting better 10 the new functions and using better unit tests. 11 12 * UIProcess/API/gtk/WebKitTextChecker.cpp: 13 (WebKitTextChecker::getSpellCheckingLanguages): Just return the 14 value previously cached when calling to the setter function. 15 (WebKitTextChecker::setSpellCheckingLanguages): Update the text 16 checker in WebCore and cache the value returned from it. 17 * UIProcess/API/gtk/WebKitTextChecker.h: 18 (WebKitTextChecker): Use a CString instead of an String to cache 19 the list of spell checking languages. Update getter and setter. 20 * UIProcess/API/gtk/WebKitWebContext.cpp: 21 (_WebKitWebContextPrivate): No need to cache the spell checking 22 languages here anymore. 23 (webkit_web_context_get_spell_checking_languages): Improve 24 both implementation and documentation to be more consistent. 25 (webkit_web_context_set_spell_checking_languages): Make 26 'languages' a mandatory (non-NULL) parameter. Update documentation. 27 * UIProcess/API/gtk/tests/TestWebKitWebContext.cpp: 28 (testWebContextSpellChecker): Test even more situations. 29 1 30 2012-08-06 Andras Becsi <andras.becsi@nokia.com> 2 31 -
trunk/Source/WebKit2/UIProcess/API/gtk/WebKitTextChecker.cpp
r124741 r124763 141 141 } 142 142 143 void WebKitTextChecker::setSpellCheckingLanguages(const String& languages)143 const CString& WebKitTextChecker::getSpellCheckingLanguages() 144 144 { 145 if (m_spellCheckingLanguages == languages) 146 return; 147 m_spellCheckingLanguages = languages; 145 String spellCheckingLanguages = m_textChecker->getSpellCheckingLanguages(); 146 m_spellCheckingLanguages = spellCheckingLanguages.isEmpty() ? CString() : spellCheckingLanguages.utf8(); 147 return m_spellCheckingLanguages; 148 } 148 149 149 // We need to update the languages in the enchant-based checker too. 150 m_textChecker->updateSpellCheckingLanguages(languages); 150 void WebKitTextChecker::setSpellCheckingLanguages(const CString& languages) 151 { 152 m_textChecker->updateSpellCheckingLanguages(String::fromUTF8(languages.data())); 151 153 } 152 154 #endif // ENABLE(SPELLCHECK) -
trunk/Source/WebKit2/UIProcess/API/gtk/WebKitTextChecker.h
r124741 r124763 27 27 #include <wtf/PassOwnPtr.h> 28 28 #include <wtf/Vector.h> 29 #include <wtf/text/CString.h> 29 30 30 31 class WebKitTextChecker { … … 44 45 45 46 // To be called from WebKitWebContext only. 46 const String getSpellCheckingLanguages() { return m_spellCheckingLanguages; }47 void setSpellCheckingLanguages(const String& spellCheckingLanguages);47 const CString& getSpellCheckingLanguages(); 48 void setSpellCheckingLanguages(const CString& spellCheckingLanguages); 48 49 49 50 private: … … 51 52 52 53 OwnPtr<WebCore::TextCheckerEnchant> m_textChecker; 53 String m_spellCheckingLanguages;54 CString m_spellCheckingLanguages; 54 55 bool m_spellCheckingEnabled; 55 56 }; -
trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp
r124741 r124763 78 78 #if ENABLE(SPELLCHECK) 79 79 OwnPtr<WebKitTextChecker> textChecker; 80 GOwnPtr<gchar> spellCheckingLanguages;81 80 #endif 82 81 }; … … 433 432 * @context: a #WebKitWebContext 434 433 * 435 * Get the current status of the spell checking feature.434 * Get whether spell checking feature is currently enabled. 436 435 * 437 436 * Returns: %TRUE If spell checking is enabled, or %FALSE otherwise. … … 469 468 * 470 469 * Get the the list of spell checking languages associated with 471 * @context, separated by commas. See 472 * webkit_web_context_set_spell_checking_languages() for more details 473 * on the format of the languages in the list. 474 * 475 * Returns: (transfer none): A comma separated list of languages. 470 * @context separated by commas, or %NULL if no languages have been 471 * previously set. 472 473 * See webkit_web_context_set_spell_checking_languages() for more 474 * details on the format of the languages in the list. 475 * 476 * Returns: (transfer none): A comma separated list of languages if 477 * available, or %NULL otherwise. 476 478 */ 477 479 const gchar* webkit_web_context_get_spell_checking_languages(WebKitWebContext* context) … … 480 482 481 483 #if ENABLE(SPELLCHECK) 482 return context->priv->spellCheckingLanguages.get(); 484 CString spellCheckingLanguages = context->priv->textChecker->getSpellCheckingLanguages(); 485 if (spellCheckingLanguages.isNull()) 486 return 0; 487 return spellCheckingLanguages.data(); 483 488 #else 484 489 return 0; … … 489 494 * webkit_web_context_set_spell_checking_languages: 490 495 * @context: a #WebKitWebContext 491 * @languages: (allow-none): new list of spell checking492 * languages separated by commas, or %NULL496 * @languages: new list of spell checking languages separated by 497 * commas 493 498 * 494 499 * Set the list of spell checking languages to be used for spell 495 * checking, separated by commas. In case %NULL is passed, the default 496 * value as returned by gtk_get_default_language() will be used. 500 * checking, separated by commas. 497 501 * 498 502 * The locale string typically is in the form lang_COUNTRY, where lang … … 500 504 * For instance, sv_FI for Swedish as written in Finland or pt_BR 501 505 * for Portuguese as written in Brazil. 506 * 507 * You need to call this function with a valid list of languages at 508 * least once in order to properly enable the spell checking feature 509 * in WebKit. 502 510 */ 503 511 void webkit_web_context_set_spell_checking_languages(WebKitWebContext* context, const gchar* languages) 504 512 { 505 513 g_return_if_fail(WEBKIT_IS_WEB_CONTEXT(context)); 514 g_return_if_fail(languages); 506 515 507 516 #if ENABLE(SPELLCHECK) 508 context->priv->textChecker->setSpellCheckingLanguages(String(languages)); 509 context->priv->spellCheckingLanguages.set(g_strdup(languages)); 517 context->priv->textChecker->setSpellCheckingLanguages(languages); 510 518 #endif 511 519 } -
trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebContext.cpp
r124741 r124763 234 234 static void testWebContextSpellChecker(Test* test, gconstpointer) 235 235 { 236 GRefPtr<WebKitWebContext> webContext(webkit_web_context_get_default()); 237 238 // Set the language to a specific one, an empty one and a list of them. 239 webkit_web_context_set_spell_checking_languages(webContext.get(), "en_US"); 240 const gchar* currentLanguage(webkit_web_context_get_spell_checking_languages(webContext.get())); 236 WebKitWebContext* webContext = webkit_web_context_get_default(); 237 238 // Check what happens if no spell checking language has been set. 239 const gchar* currentLanguage = webkit_web_context_get_spell_checking_languages(webContext); 240 g_assert(!currentLanguage); 241 242 // Set the language to a specific one. 243 webkit_web_context_set_spell_checking_languages(webContext, "en_US"); 244 currentLanguage = webkit_web_context_get_spell_checking_languages(webContext); 241 245 g_assert_cmpstr(currentLanguage, ==, "en_US"); 242 246 243 webkit_web_context_set_spell_checking_languages(webContext.get(), 0); 244 currentLanguage = webkit_web_context_get_spell_checking_languages(webContext.get()); 245 g_assert_cmpstr(currentLanguage, ==, 0); 246 247 webkit_web_context_set_spell_checking_languages(webContext.get(), "es_ES,en_US"); 248 currentLanguage = webkit_web_context_get_spell_checking_languages(webContext.get()); 249 g_assert_cmpstr(currentLanguage, ==, "es_ES,en_US"); 247 // Set the language string to list of valid languages. 248 webkit_web_context_set_spell_checking_languages(webContext, "en_GB,en_US"); 249 currentLanguage = webkit_web_context_get_spell_checking_languages(webContext); 250 g_assert_cmpstr(currentLanguage, ==, "en_GB,en_US"); 251 252 // Try passing a wrong language along with good ones. 253 webkit_web_context_set_spell_checking_languages(webContext, "bd_WR,en_US,en_GB"); 254 currentLanguage = webkit_web_context_get_spell_checking_languages(webContext); 255 g_assert_cmpstr(currentLanguage, ==, "en_US,en_GB"); 256 257 // Try passing a list with only wrong languages. 258 webkit_web_context_set_spell_checking_languages(webContext, "bd_WR,wr_BD"); 259 currentLanguage = webkit_web_context_get_spell_checking_languages(webContext); 260 g_assert(!currentLanguage); 250 261 251 262 // Check disabling and re-enabling spell checking. 252 webkit_web_context_set_spell_checking_enabled(webContext.get(), FALSE); 253 gboolean isSpellCheckingEnabled = webkit_web_context_get_spell_checking_enabled(webContext.get()); 254 g_assert(!isSpellCheckingEnabled); 255 webkit_web_context_set_spell_checking_enabled(webContext.get(), TRUE); 256 isSpellCheckingEnabled = webkit_web_context_get_spell_checking_enabled(webContext.get()); 257 g_assert(isSpellCheckingEnabled); 263 webkit_web_context_set_spell_checking_enabled(webContext, FALSE); 264 g_assert(!webkit_web_context_get_spell_checking_enabled(webContext)); 265 webkit_web_context_set_spell_checking_enabled(webContext, TRUE); 266 g_assert(webkit_web_context_get_spell_checking_enabled(webContext)); 258 267 } 259 268
Note: See TracChangeset
for help on using the changeset viewer.