Changeset 126298 in webkit


Ignore:
Timestamp:
Aug 22, 2012 6:34:13 AM (12 years ago)
Author:
Carlos Garcia Campos
Message:

[GTK] Preferred languages and spellchecker APIs are not consistent in WebKit2
https://bugs.webkit.org/show_bug.cgi?id=94683

Reviewed by Alejandro G. Castro.

Source/WebCore:

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):

Source/WebKit/gtk:

  • webkit/webkitspellcheckerenchant.cpp:

(updateSpellCheckingLanguages): Split the languages string to pass a
Vector to updateSpellCheckingLanguages().

Source/WebKit2:

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):

Location:
trunk/Source
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r126297 r126298  
     12012-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
    1172012-08-22  Pavel Feldman  <pfeldman@chromium.org>
    218
  • trunk/Source/WebCore/platform/text/gtk/TextCheckerEnchant.cpp

    r125791 r126298  
    156156}
    157157
    158 void TextCheckerEnchant::updateSpellCheckingLanguages(const String& languages)
     158void TextCheckerEnchant::updateSpellCheckingLanguages(const Vector<String>& languages)
    159159{
    160160    Vector<EnchantDict*> spellDictionaries;
    161161
    162162    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) {
    166164            CString currentLanguage = iter->utf8();
    167165            if (enchant_broker_dict_exists(m_broker, currentLanguage.data())) {
     
    189187}
    190188
    191 String TextCheckerEnchant::getSpellCheckingLanguages()
    192 {
     189Vector<String> TextCheckerEnchant::getSpellCheckingLanguages()
     190{
     191    Vector<String> languages;
    193192    if (m_enchantDictionaries.isEmpty())
    194         return String();
     193        return languages;
    195194
    196195    // Get a Vector<CString> with the list of languages in use.
     
    199198        enchant_dict_describe(*iter, enchantDictDescribeCallback, &currentDictionaries);
    200199
    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;
    209204}
    210205
  • trunk/Source/WebCore/platform/text/gtk/TextCheckerEnchant.h

    r124763 r126298  
    4242    void checkSpellingOfString(const String&, int& misspellingLocation, int& misspellingLength);
    4343    Vector<String> getGuessesForWord(const String&);
    44     void updateSpellCheckingLanguages(const String& languages);
    45     String getSpellCheckingLanguages();
     44    void updateSpellCheckingLanguages(const Vector<String>& languages);
     45    Vector<String> getSpellCheckingLanguages();
    4646
    4747private:
  • trunk/Source/WebKit/gtk/ChangeLog

    r126243 r126298  
     12012-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
    1122012-08-21  Joanmarie Diggs  <jdiggs@igalia.com>
    213        [Gtk] No accessible caret-moved events found in certain content
  • trunk/Source/WebKit/gtk/webkit/webkitspellcheckerenchant.cpp

    r124578 r126298  
    100100{
    101101    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);
    103106}
    104107
  • trunk/Source/WebKit2/ChangeLog

    r126296 r126298  
     12012-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
    1282012-08-22  Csaba Osztrogonác  <ossy@webkit.org>
    229
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitTextChecker.cpp

    r124763 r126298  
    3030
    3131#include "WebKitPrivate.h"
    32 #include <wtf/Vector.h>
    33 #include <wtf/text/CString.h>
    3432
    3533using namespace WebKit;
     
    141139}
    142140
    143 const CString& WebKitTextChecker::getSpellCheckingLanguages()
     141const char* const* WebKitTextChecker::getSpellCheckingLanguages()
    144142{
    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);
    148153}
    149154
    150 void WebKitTextChecker::setSpellCheckingLanguages(const CString& languages)
     155void WebKitTextChecker::setSpellCheckingLanguages(const char* const* languages)
    151156{
    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);
    153161}
    154162#endif // ENABLE(SPELLCHECK)
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitTextChecker.h

    r124763 r126298  
    2727#include <wtf/PassOwnPtr.h>
    2828#include <wtf/Vector.h>
     29#include <wtf/gobject/GRefPtr.h>
    2930#include <wtf/text/CString.h>
    3031
     
    4546
    4647    // 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);
    4950
    5051private:
     
    5253
    5354    OwnPtr<WebCore::TextCheckerEnchant> m_textChecker;
    54     CString m_spellCheckingLanguages;
     55    GRefPtr<GPtrArray> m_spellCheckingLanguages;
    5556    bool m_spellCheckingEnabled;
    5657};
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp

    r126152 r126298  
    496496 *
    497497 * 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 *
    501500 * See webkit_web_context_set_spell_checking_languages() for more
    502501 * details on the format of the languages in the list.
    503502 *
    504  * Returns: (transfer none): A comma separated list of languages if
    505  * 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 */
     506const gchar* const* webkit_web_context_get_spell_checking_languages(WebKitWebContext* context)
    508507{
    509508    g_return_val_if_fail(WEBKIT_IS_WEB_CONTEXT(context), 0);
    510509
    511510#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();
    516512#else
    517513    return 0;
     
    522518 * webkit_web_context_set_spell_checking_languages:
    523519 * @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
    526521 *
    527522 * Set the list of spell checking languages to be used for spell
    528  * checking, separated by commas.
     523 * checking.
    529524 *
    530525 * The locale string typically is in the form lang_COUNTRY, where lang
     
    537532 * in WebKit.
    538533 */
    539 void webkit_web_context_set_spell_checking_languages(WebKitWebContext* context, const gchar* languages)
     534void webkit_web_context_set_spell_checking_languages(WebKitWebContext* context, const gchar* const* languages)
    540535{
    541536    g_return_if_fail(WEBKIT_IS_WEB_CONTEXT(context));
     
    550545 * webkit_web_context_set_preferred_languages:
    551546 * @context: a #WebKitWebContext
    552  * @languages: (element-type utf8): a #GList of language identifiers
     547 * @languages: (allow-none) (array zero-terminated=1) (element-type utf8) (transfer none): a %NULL-terminated list of language identifiers
    553548 *
    554549 * Set the list of preferred languages, sorted from most desirable
     
    557552 * the #WebKitWebContext.
    558553 */
    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)
     554void 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)))
    564559        return;
    565560
    566561    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("_", "-"));
    569564
    570565    WebCore::overrideUserPreferredLanguages(languages);
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.h

    r126152 r126298  
    141141webkit_web_context_set_spell_checking_enabled       (WebKitWebContext              *context,
    142142                                                     gboolean                       enabled);
    143 WEBKIT_API const gchar *
     143WEBKIT_API const gchar * const *
    144144webkit_web_context_get_spell_checking_languages     (WebKitWebContext              *context);
    145145
    146146WEBKIT_API void
    147147webkit_web_context_set_spell_checking_languages     (WebKitWebContext              *context,
    148                                                      const gchar                   *languages);
     148                                                     const gchar * const           *languages);
    149149
    150150WEBKIT_API void
    151151webkit_web_context_set_preferred_languages          (WebKitWebContext              *context,
    152                                                      GList                         *languages);
     152                                                     const gchar * const           *languages);
    153153
    154154G_END_DECLS
  • trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebContext.cpp

    r126152 r126298  
    211211
    212212    // Check what happens if no spell checking language has been set.
    213     const gchar* currentLanguage = webkit_web_context_get_spell_checking_languages(webContext);
     213    const gchar* const* currentLanguage = webkit_web_context_get_spell_checking_languages(webContext);
    214214    g_assert(!currentLanguage);
    215215
    216216    // 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));
    218221    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");
    220224
    221225    // 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));
    223230    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");
    225234
    226235    // 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));
    228240    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");
    230244
    231245    // 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));
    233251    currentLanguage = webkit_web_context_get_spell_checking_languages(webContext);
    234252    g_assert(!currentLanguage);
     
    251269    g_assert(!strncmp(mainResourceData, expectedDefaultLanguage, mainResourceDataSize));
    252270
    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));
    258277
    259278    static const char* expectedLanguages = "en, es-es;q=0.90, de;q=0.80";
Note: See TracChangeset for help on using the changeset viewer.