Changeset 123967 in webkit


Ignore:
Timestamp:
Jul 28, 2012 11:45:12 AM (12 years ago)
Author:
mario@webkit.org
Message:

[WK2][GTK] Implement a new spell checker API for WebKit2GTK+
https://bugs.webkit.org/show_bug.cgi?id=90268

Reviewed by Martin Robinson.

Source/WebKit2:

Add a simple spell checking API to WK2, allowing to enable/disable
this feature and to define a list of languages associated to it.

  • GNUmakefile.am: Add flags to handle the SPELLCHECK feature.
  • GNUmakefile.list.am: Added new files

Added new internal class that will act both as the implementation
of TextCheckerClient and as the object WebKitWebContext will
depend on to implement the newly added API.

  • UIProcess/API/gtk/WebKitTextChecker.cpp: Added.

(toTextChecker):
(continuousSpellCheckingEnabledCallback):
(setContinuousSpellCheckingEnabledCallback):
(checkSpellingOfStringCallback):
(guessesForWordCallback):
(learnWordCallback):
(ignoreWordCallback):
(WebKitTextChecker::~WebKitTextChecker):
(WebKitTextChecker::create):
(WebKitTextChecker::WebKitTextChecker):
(WebKitTextChecker::checkSpellingOfString):
(WebKitTextChecker::getGuessesForWord):
(WebKitTextChecker::learnWord):
(WebKitTextChecker::ignoreWord):
(WebKitTextChecker::setSpellCheckingEnabled):
(WebKitTextChecker::setSpellCheckingLanguages):

  • UIProcess/API/gtk/WebKitTextChecker.h: Added.

(WebKitTextChecker):
(WebKitTextChecker::isSpellCheckingEnabled):
(WebKitTextChecker::getSpellCheckingLanguages):

Added WKTextChecker to WebKitPrivate.h, needed in WebKitTextChecker.

  • UIProcess/API/gtk/WebKitPrivate.h:

Add new API to WebKitWebContext to allow enabling/disabling this
spell checking feature, and to set/get the list of languages used
to decide which dictionaries will be consulted.

  • UIProcess/API/gtk/WebKitWebContext.cpp:

(_WebKitWebContextPrivate):
(createDefaultWebContext):
(webkit_web_context_get_spell_checking_enabled): New API.
(webkit_web_context_set_spell_checking_enabled): Ditto.
(webkit_web_context_get_spell_checking_languages): Ditto.
(webkit_web_context_set_spell_checking_languages): Ditto.

  • UIProcess/API/gtk/WebKitWebContext.h:

New tests for checking the new API added to WebKitWebContext.

  • UIProcess/API/gtk/tests/TestWebKitWebContext.cpp:

(testWebContextSpellChecker):
(beforeAll):

Update documentation with new sections and symbols.

  • UIProcess/API/gtk/docs/webkit2gtk-docs.sgml:
  • UIProcess/API/gtk/docs/webkit2gtk-sections.txt:

Tools:

Ignore WebKitTextChecker.* private files for gtk-doc.

  • gtk/generate-gtkdoc:

(get_webkit2_options):

Location:
trunk
Files:
2 added
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r123933 r123967  
     12012-07-28  Mario Sanchez Prada  <msanchez@igalia.com>
     2
     3        [WK2][GTK] Implement a new spell checker API for WebKit2GTK+
     4        https://bugs.webkit.org/show_bug.cgi?id=90268
     5
     6        Reviewed by Martin Robinson.
     7
     8        Add a simple spell checking API to WK2, allowing to enable/disable
     9        this feature and to define a list of languages associated to it.
     10
     11        * GNUmakefile.am: Add flags to handle the SPELLCHECK feature.
     12        * GNUmakefile.list.am: Added new files
     13
     14        Added new internal class that will act both as the implementation
     15        of TextCheckerClient and as the object WebKitWebContext will
     16        depend on to implement the newly added API.
     17
     18        * UIProcess/API/gtk/WebKitTextChecker.cpp: Added.
     19        (toTextChecker):
     20        (continuousSpellCheckingEnabledCallback):
     21        (setContinuousSpellCheckingEnabledCallback):
     22        (checkSpellingOfStringCallback):
     23        (guessesForWordCallback):
     24        (learnWordCallback):
     25        (ignoreWordCallback):
     26        (WebKitTextChecker::~WebKitTextChecker):
     27        (WebKitTextChecker::create):
     28        (WebKitTextChecker::WebKitTextChecker):
     29        (WebKitTextChecker::checkSpellingOfString):
     30        (WebKitTextChecker::getGuessesForWord):
     31        (WebKitTextChecker::learnWord):
     32        (WebKitTextChecker::ignoreWord):
     33        (WebKitTextChecker::setSpellCheckingEnabled):
     34        (WebKitTextChecker::setSpellCheckingLanguages):
     35        * UIProcess/API/gtk/WebKitTextChecker.h: Added.
     36        (WebKitTextChecker):
     37        (WebKitTextChecker::isSpellCheckingEnabled):
     38        (WebKitTextChecker::getSpellCheckingLanguages):
     39
     40        Added WKTextChecker to WebKitPrivate.h, needed in WebKitTextChecker.
     41
     42        * UIProcess/API/gtk/WebKitPrivate.h:
     43
     44        Add new API to WebKitWebContext to allow enabling/disabling this
     45        spell checking feature, and to set/get the list of languages used
     46        to decide which dictionaries will be consulted.
     47
     48        * UIProcess/API/gtk/WebKitWebContext.cpp:
     49        (_WebKitWebContextPrivate):
     50        (createDefaultWebContext):
     51        (webkit_web_context_get_spell_checking_enabled): New API.
     52        (webkit_web_context_set_spell_checking_enabled): Ditto.
     53        (webkit_web_context_get_spell_checking_languages): Ditto.
     54        (webkit_web_context_set_spell_checking_languages): Ditto.
     55        * UIProcess/API/gtk/WebKitWebContext.h:
     56
     57        New tests for checking the new API added to WebKitWebContext.
     58
     59        * UIProcess/API/gtk/tests/TestWebKitWebContext.cpp:
     60        (testWebContextSpellChecker):
     61        (beforeAll):
     62
     63        Update documentation with new sections and symbols.
     64
     65        * UIProcess/API/gtk/docs/webkit2gtk-docs.sgml:
     66        * UIProcess/API/gtk/docs/webkit2gtk-sections.txt:
     67
    1682012-07-27  Christophe Dumez  <christophe.dumez@intel.com>
    269
  • trunk/Source/WebKit2/GNUmakefile.am

    r123019 r123967  
    163163        $(CAIRO_LIBS) \
    164164        $(COVERAGE_LDFLAGS) \
    165         $(ENCHANT_LIBS) \
    166165        $(GAIL_LIBS) \
    167166        $(GAMEPAD_LIBS) \
     
    183182        $(XT_LIBS) \
    184183        $(ZLIB_LIBS)
     184
     185if ENABLE_SPELLCHECK
     186libwebkit2gtk_@WEBKITGTK_API_MAJOR_VERSION@_@WEBKITGTK_API_MINOR_VERSION@_la_CPPFLAGS += \
     187        -DENABLE_SPELLCHECK=1 \
     188        $(ENCHANT_CFLAGS)
     189
     190libwebkit2gtk_@WEBKITGTK_API_MAJOR_VERSION@_@WEBKITGTK_API_MINOR_VERSION@_la_LIBADD += \
     191        $(ENCHANT_LIBS)
     192endif
     193
    185194
    186195if ENABLE_WEBKIT2
  • trunk/Source/WebKit2/GNUmakefile.list.am

    r123778 r123967  
    702702        Source/WebKit2/UIProcess/API/gtk/WebKitSettings.h \
    703703        Source/WebKit2/UIProcess/API/gtk/WebKitSettingsPrivate.h \
     704        Source/WebKit2/UIProcess/API/gtk/WebKitTextChecker.cpp \
     705        Source/WebKit2/UIProcess/API/gtk/WebKitTextChecker.h \
    704706        Source/WebKit2/UIProcess/API/gtk/WebKitUIClient.cpp \
    705707        Source/WebKit2/UIProcess/API/gtk/WebKitUIClient.h \
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitPrivate.h

    r119700 r123967  
    4141#include <WebKit2/WKSoupRequestManager.h>
    4242#include <WebKit2/WKString.h>
     43#include <WebKit2/WKTextChecker.h>
    4344#include <WebKit2/WebKit2.h>
    4445#include <glib.h>
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp

    r122223 r123967  
    2929#include "WebKitPrivate.h"
    3030#include "WebKitRequestManagerClient.h"
     31#include "WebKitTextChecker.h"
    3132#include "WebKitURISchemeRequestPrivate.h"
    3233#include "WebKitWebContextPrivate.h"
    3334#include <WebCore/FileSystem.h>
    3435#include <wtf/HashMap.h>
     36#include <wtf/OwnPtr.h>
     37#include <wtf/gobject/GOwnPtr.h>
    3538#include <wtf/gobject/GRefPtr.h>
    3639#include <wtf/text/CString.h>
     
    7275#if ENABLE(GEOLOCATION)
    7376    RefPtr<WebKitGeolocationProvider> geolocationProvider;
     77#endif
     78#if ENABLE(SPELLCHECK)
     79    OwnPtr<WebKitTextChecker> textChecker;
     80    GOwnPtr<gchar> spellCheckingLanguages;
    7481#endif
    7582};
     
    127134    WKGeolocationManagerRef wkGeolocationManager = WKContextGetGeolocationManager(webContext->priv->context.get());
    128135    webContext->priv->geolocationProvider = WebKitGeolocationProvider::create(wkGeolocationManager);
     136#endif
     137#if ENABLE(SPELLCHECK)
     138    webContext->priv->textChecker = WebKitTextChecker::create();
    129139#endif
    130140    return webContext.get();
     
    419429}
    420430
     431/**
     432 * webkit_web_context_get_spell_checking_enabled:
     433 * @context: a #WebKitWebContext
     434 *
     435 * Get the current status of the spell checking feature.
     436 *
     437 * Returns: %TRUE If spell checking is enabled, or %FALSE otherwise.
     438 */
     439gboolean webkit_web_context_get_spell_checking_enabled(WebKitWebContext* context)
     440{
     441    g_return_val_if_fail(WEBKIT_IS_WEB_CONTEXT(context), FALSE);
     442
     443#if ENABLE(SPELLCHECK)
     444    return context->priv->textChecker->isSpellCheckingEnabled();
     445#else
     446    return false;
     447#endif
     448}
     449
     450/**
     451 * webkit_web_context_set_spell_checking_enabled:
     452 * @context: a #WebKitWebContext
     453 * @enabled: Value to be set
     454 *
     455 * Enable or disable the spell checking feature.
     456 */
     457void webkit_web_context_set_spell_checking_enabled(WebKitWebContext* context, gboolean enabled)
     458{
     459    g_return_if_fail(WEBKIT_IS_WEB_CONTEXT(context));
     460
     461#if ENABLE(SPELLCHECK)
     462    context->priv->textChecker->setSpellCheckingEnabled(enabled);
     463#endif
     464}
     465
     466/**
     467 * webkit_web_context_get_spell_checking_languages:
     468 * @context: a #WebKitWebContext
     469 *
     470 * 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.
     476 */
     477const gchar* webkit_web_context_get_spell_checking_languages(WebKitWebContext* context)
     478{
     479    g_return_val_if_fail(WEBKIT_IS_WEB_CONTEXT(context), 0);
     480
     481#if ENABLE(SPELLCHECK)
     482    return context->priv->spellCheckingLanguages.get();
     483#else
     484    return 0;
     485#endif
     486}
     487
     488/**
     489 * webkit_web_context_set_spell_checking_languages:
     490 * @context: a #WebKitWebContext
     491 * @languages: (allow-none): new list of spell checking
     492 * languages separated by commas, or %NULL
     493 *
     494 * 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.
     497 *
     498 * The locale string typically is in the form lang_COUNTRY, where lang
     499 * is an ISO-639 language code, and COUNTRY is an ISO-3166 country code.
     500 * For instance, sv_FI for Swedish as written in Finland or pt_BR
     501 * for Portuguese as written in Brazil.
     502 */
     503void webkit_web_context_set_spell_checking_languages(WebKitWebContext* context, const gchar* languages)
     504{
     505    g_return_if_fail(WEBKIT_IS_WEB_CONTEXT(context));
     506
     507#if ENABLE(SPELLCHECK)
     508    context->priv->textChecker->setSpellCheckingLanguages(String(languages));
     509    context->priv->spellCheckingLanguages.set(g_strdup(languages));
     510#endif
     511}
     512
    421513WebKitDownload* webkitWebContextGetOrCreateDownload(WKDownloadRef wkDownload)
    422514{
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.h

    r122223 r123967  
    133133                                                     WebKitURISchemeRequestCallback callback,
    134134                                                     gpointer                       user_data);
     135
     136WEBKIT_API gboolean
     137webkit_web_context_get_spell_checking_enabled       (WebKitWebContext              *context);
     138
     139WEBKIT_API void
     140webkit_web_context_set_spell_checking_enabled       (WebKitWebContext              *context,
     141                                                     gboolean                       enabled);
     142WEBKIT_API const gchar *
     143webkit_web_context_get_spell_checking_languages     (WebKitWebContext              *context);
     144
     145WEBKIT_API void
     146webkit_web_context_set_spell_checking_languages     (WebKitWebContext              *context,
     147                                                     const gchar                   *languages);
     148
    135149G_END_DECLS
    136150
  • trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt

    r122961 r123967  
    3434webkit_web_context_get_plugins
    3535webkit_web_context_get_plugins_finish
     36webkit_web_context_get_spell_checking_enabled
     37webkit_web_context_set_spell_checking_enabled
     38webkit_web_context_get_spell_checking_languages
     39webkit_web_context_set_spell_checking_languages
    3640
    3741<SUBSECTION URI Scheme>
  • trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebContext.cpp

    r119700 r123967  
    232232}
    233233
     234static void testWebContextSpellChecker(Test* test, gconstpointer)
     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()));
     241    g_assert_cmpstr(currentLanguage, ==, "en_US");
     242
     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");
     250
     251    // 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);
     258}
     259
    234260void beforeAll()
    235261{
     
    237263    PluginsTest::add("WebKitWebContext", "get-plugins", testWebContextGetPlugins);
    238264    URISchemeTest::add("WebKitWebContext", "uri-scheme", testWebContextURIScheme);
     265    Test::add("WebKitWebContext", "spell-checker", testWebContextSpellChecker);
    239266}
    240267
  • trunk/Tools/ChangeLog

    r123959 r123967  
     12012-07-28  Mario Sanchez Prada  <msanchez@igalia.com>
     2
     3        [WK2][GTK] Implement a new spell checker API for WebKit2GTK+
     4        https://bugs.webkit.org/show_bug.cgi?id=90268
     5
     6        Reviewed by Martin Robinson.
     7
     8        Ignore WebKitTextChecker.* private files for gtk-doc.
     9
     10        * gtk/generate-gtkdoc:
     11        (get_webkit2_options):
     12
    1132012-07-28  Philippe Normand  <pnormand@igalia.com>
    214
  • trunk/Tools/gtk/generate-gtkdoc

    r119837 r123967  
    100100                         glob.glob(src_path('WebKitWebViewBaseAccessible.*')) + \
    101101                         glob.glob(src_path('WebKitGeolocationProvider.*')) + \
     102                         glob.glob(src_path('WebKitTextChecker.*')) + \
    102103                         glob.glob(derived_sources_path('webkit2gtk', 'webkit2', 'WebKitMarshal.*')) + \
    103104                         glob.glob(derived_sources_path('webkit2gtk', 'webkit2', 'WebKitEnumTypes.*')) + \
Note: See TracChangeset for help on using the changeset viewer.