Changeset 132657 in webkit


Ignore:
Timestamp:
Oct 26, 2012 7:58:31 AM (12 years ago)
Author:
commit-queue@webkit.org
Message:

[EFL][WK2] Get rid of C'ism in text checker API
https://bugs.webkit.org/show_bug.cgi?id=100513

Patch by Christophe Dumez <Christophe Dumez> on 2012-10-26
Reviewed by Kenneth Rohde Christiansen.

Make Ewk_Text_Checker a C++ class and move the
WebKitTextChecker code to this new class. This
gets rid of the C'ism in the text checker code
and make it consistent with other Ewk classes.

  • PlatformEfl.cmake:
  • UIProcess/API/efl/ewk_context.cpp:

(Ewk_Context::Ewk_Context):

  • UIProcess/API/efl/ewk_settings.cpp:

(spellCheckingLanguagesSetUpdate):
(ewk_settings_continuous_spell_checking_enabled_set):
(ewk_settings_spell_checking_available_languages_get):
(ewk_settings_spell_checking_languages_get):

  • UIProcess/API/efl/ewk_text_checker.cpp:

(ClientCallbacks):
(textCheckerEnchant):
(clientCallbacks):
(isContinuousSpellCheckingEnabled):
(setContinuousSpellCheckingEnabled):
(uniqueSpellDocumentTag):
(closeSpellDocumentWithTag):
(checkSpellingOfString):
(guessesForWord):
(learnWord):
(ignoreWord):
(Ewk_Text_Checker):
(Ewk_Text_Checker::availableSpellCheckingLanguages):
(Ewk_Text_Checker::updateSpellCheckingLanguages):
(Ewk_Text_Checker::loadedSpellCheckingLanguages):
(Ewk_Text_Checker::initialize):

  • UIProcess/API/efl/ewk_text_checker_private.h:

(Ewk_Text_Checker):

  • UIProcess/efl/WebKitTextChecker.cpp: Removed.
  • UIProcess/efl/WebKitTextChecker.h: Removed.
Location:
trunk/Source/WebKit2
Files:
2 deleted
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r132647 r132657  
     12012-10-26  Christophe Dumez  <christophe.dumez@intel.com>
     2
     3        [EFL][WK2] Get rid of C'ism in text checker API
     4        https://bugs.webkit.org/show_bug.cgi?id=100513
     5
     6        Reviewed by Kenneth Rohde Christiansen.
     7
     8        Make Ewk_Text_Checker a C++ class and move the
     9        WebKitTextChecker code to this new class. This
     10        gets rid of the C'ism in the text checker code
     11        and make it consistent with other Ewk classes.
     12
     13        * PlatformEfl.cmake:
     14        * UIProcess/API/efl/ewk_context.cpp:
     15        (Ewk_Context::Ewk_Context):
     16        * UIProcess/API/efl/ewk_settings.cpp:
     17        (spellCheckingLanguagesSetUpdate):
     18        (ewk_settings_continuous_spell_checking_enabled_set):
     19        (ewk_settings_spell_checking_available_languages_get):
     20        (ewk_settings_spell_checking_languages_get):
     21        * UIProcess/API/efl/ewk_text_checker.cpp:
     22        (ClientCallbacks):
     23        (textCheckerEnchant):
     24        (clientCallbacks):
     25        (isContinuousSpellCheckingEnabled):
     26        (setContinuousSpellCheckingEnabled):
     27        (uniqueSpellDocumentTag):
     28        (closeSpellDocumentWithTag):
     29        (checkSpellingOfString):
     30        (guessesForWord):
     31        (learnWord):
     32        (ignoreWord):
     33        (Ewk_Text_Checker):
     34        (Ewk_Text_Checker::availableSpellCheckingLanguages):
     35        (Ewk_Text_Checker::updateSpellCheckingLanguages):
     36        (Ewk_Text_Checker::loadedSpellCheckingLanguages):
     37        (Ewk_Text_Checker::initialize):
     38        * UIProcess/API/efl/ewk_text_checker_private.h:
     39        (Ewk_Text_Checker):
     40        * UIProcess/efl/WebKitTextChecker.cpp: Removed.
     41        * UIProcess/efl/WebKitTextChecker.h: Removed.
     42
    1432012-10-26  Mikhail Pozdnyakov  <mikhail.pozdnyakov@intel.com>
    244
  • trunk/Source/WebKit2/PlatformEfl.cmake

    r132617 r132657  
    8888    UIProcess/efl/WebFullScreenManagerProxyEfl.cpp
    8989    UIProcess/efl/WebInspectorProxyEfl.cpp
    90     UIProcess/efl/WebKitTextChecker.cpp
    9190    UIProcess/efl/WebPageProxyEfl.cpp
    9291    UIProcess/efl/WebPopupMenuProxyEfl.cpp
  • trunk/Source/WebKit2/UIProcess/API/efl/ewk_context.cpp

    r132643 r132657  
    9191
    9292#if ENABLE(SPELLCHECK)
    93     ewk_text_checker_client_attach();
     93    Ewk_Text_Checker::initialize();
    9494    if (ewk_settings_continuous_spell_checking_enabled_get()) {
    9595        // Load the default language.
  • trunk/Source/WebKit2/UIProcess/API/efl/ewk_settings.cpp

    r132647 r132657  
    3636#if ENABLE(SPELLCHECK)
    3737#include "WKTextChecker.h"
    38 #include "WebKitTextChecker.h"
     38#include "ewk_text_checker_private.h"
    3939#include <Ecore.h>
    4040#include <wtf/Vector.h>
     
    7272{
    7373    // FIXME: Consider to delegate calling of this method in WebProcess to do not delay/block UIProcess.
    74     updateSpellCheckingLanguages(ewkTextCheckerSettings.spellCheckingLanguages);
     74    Ewk_Text_Checker::updateSpellCheckingLanguages(ewkTextCheckerSettings.spellCheckingLanguages);
    7575    return ECORE_CALLBACK_CANCEL;
    7676}
     
    226226
    227227        // Sets the default language if user didn't specify any.
    228         if (enable && loadedSpellCheckingLanguages().isEmpty())
     228        if (enable && Ewk_Text_Checker::loadedSpellCheckingLanguages().isEmpty())
    229229            spellCheckingLanguagesSet(Vector<String>());
    230230
     
    239239    Eina_List* listOflanguages = 0;
    240240#if ENABLE(SPELLCHECK)
    241     Vector<String> languages = availableSpellCheckingLanguages();
     241    const Vector<String>& languages = Ewk_Text_Checker::availableSpellCheckingLanguages();
    242242    size_t numberOfLanuages = languages.size();
    243243
     
    262262    Eina_List* listOflanguages = 0;
    263263#if ENABLE(SPELLCHECK)
    264     Vector<String> languages = loadedSpellCheckingLanguages();
     264    Vector<String> languages = Ewk_Text_Checker::loadedSpellCheckingLanguages();
    265265    size_t numberOfLanuages = languages.size();
    266266
  • trunk/Source/WebKit2/UIProcess/API/efl/ewk_text_checker.cpp

    r131579 r132657  
    11/*
    22 * Copyright (C) 2012 Samsung Electronics
     3 * Copyright (C) 2012 Intel Corporation
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    2930#if ENABLE(SPELLCHECK)
    3031
     32#include "TextCheckerEnchant.h"
     33#include "WKAPICast.h"
     34#include "WKMutableArray.h"
     35#include "WKRetainPtr.h"
     36#include "WKString.h"
    3137#include "WKTextChecker.h"
    32 #include "WebKitTextChecker.h"
     38#include "WebPageProxy.h"
     39#include "WebString.h"
     40#include "ewk_settings.h"
    3341#include "ewk_text_checker_private.h"
    34 
     42#include <Eina.h>
     43#include <wtf/OwnPtr.h>
     44#include <wtf/text/CString.h>
     45
     46using namespace WebCore;
    3547using namespace WebKit;
    3648
    37 // Initializes the client's functions to @c 0 to be sure that they are not defined.
    38 static Ewk_Text_Checker ewkTextCheckerCallbacks = {
    39     0, // unique_spell_document_tag_get
    40     0, // unique_spell_document_tag_close
    41     0, // string_spelling_check
    42     0, // word_guesses_get
    43     0, // word_learn
    44     0 // word_ignore
     49/**
     50 * @brief Structure to store client callback functions.
     51 *
     52 * @internal
     53 */
     54struct ClientCallbacks {
     55    Ewk_Text_Checker_Unique_Spell_Document_Tag_Get_Cb unique_spell_document_tag_get;
     56    Ewk_Text_Checker_Unique_Spell_Document_Tag_Close_Cb unique_spell_document_tag_close;
     57    Ewk_Text_Checker_String_Spelling_Check_Cb string_spelling_check;
     58    Ewk_Text_Checker_Word_Guesses_Get_Cb word_guesses_get;
     59    Ewk_Text_Checker_Word_Learn_Cb word_learn;
     60    Ewk_Text_Checker_Word_Ignore_Cb word_ignore;
    4561};
    4662
    47 #define EWK_TEXT_CHECKER_CALLBACK_SET(TYPE_NAME, NAME)  \
    48 void ewk_text_checker_##NAME##_cb_set(TYPE_NAME cb)     \
    49 {                                                       \
    50     ewkTextCheckerCallbacks.NAME = cb;                  \
     63static inline TextCheckerEnchant* textCheckerEnchant()
     64{
     65    static OwnPtr<TextCheckerEnchant> textCheckerEnchant = TextCheckerEnchant::create();
     66    return textCheckerEnchant.get();
     67}
     68
     69static inline ClientCallbacks& clientCallbacks()
     70{
     71    DEFINE_STATIC_LOCAL(ClientCallbacks, clientCallbacks, ());
     72    return clientCallbacks;
     73}
     74
     75static bool isContinuousSpellCheckingEnabled(const void*)
     76{
     77    return ewk_settings_continuous_spell_checking_enabled_get();
     78}
     79
     80static void setContinuousSpellCheckingEnabled(bool enabled, const void*)
     81{
     82    ewk_settings_continuous_spell_checking_enabled_set(enabled);
     83}
     84
     85static uint64_t uniqueSpellDocumentTag(WKPageRef page, const void*)
     86{
     87    if (clientCallbacks().unique_spell_document_tag_get)
     88        return clientCallbacks().unique_spell_document_tag_get(toImpl(page)->viewWidget());
     89
     90    return 0;
     91}
     92
     93static void closeSpellDocumentWithTag(uint64_t tag, const void*)
     94{
     95    if (clientCallbacks().unique_spell_document_tag_close)
     96        clientCallbacks().unique_spell_document_tag_close(tag);
     97}
     98
     99static void checkSpellingOfString(uint64_t tag, WKStringRef text, int32_t* misspellingLocation, int32_t* misspellingLength, const void*)
     100{
     101    if (clientCallbacks().string_spelling_check)
     102        clientCallbacks().string_spelling_check(tag, toImpl(text)->string().utf8().data(), misspellingLocation, misspellingLength);
     103    else
     104        textCheckerEnchant()->checkSpellingOfString(toImpl(text)->string(), *misspellingLocation, *misspellingLength);
     105}
     106
     107static WKArrayRef guessesForWord(uint64_t tag, WKStringRef word, const void*)
     108{
     109    WKMutableArrayRef suggestionsForWord = WKMutableArrayCreate();
     110
     111    if (clientCallbacks().word_guesses_get) {
     112        Eina_List* list = clientCallbacks().word_guesses_get(tag, toImpl(word)->string().utf8().data());
     113        void* item;
     114
     115        EINA_LIST_FREE(list, item) {
     116            WKRetainPtr<WKStringRef> suggestion(AdoptWK, WKStringCreateWithUTF8CString(static_cast<const char*>(item)));
     117            WKArrayAppendItem(suggestionsForWord, suggestion.get());
     118            free(item);
     119        }
     120    } else {
     121        const Vector<String>& guesses = textCheckerEnchant()->getGuessesForWord(toImpl(word)->string());
     122        size_t numberOfGuesses = guesses.size();
     123        for (size_t i = 0; i < numberOfGuesses; ++i) {
     124            WKRetainPtr<WKStringRef> suggestion(AdoptWK, WKStringCreateWithUTF8CString(guesses[i].utf8().data()));
     125            WKArrayAppendItem(suggestionsForWord, suggestion.get());
     126        }
     127    }
     128
     129    return suggestionsForWord;
     130}
     131
     132static void learnWord(uint64_t tag, WKStringRef word, const void*)
     133{
     134    if (clientCallbacks().word_learn)
     135        clientCallbacks().word_learn(tag, toImpl(word)->string().utf8().data());
     136    else
     137        textCheckerEnchant()->learnWord(toImpl(word)->string());
     138}
     139
     140static void ignoreWord(uint64_t tag, WKStringRef word, const void*)
     141{
     142    if (clientCallbacks().word_ignore)
     143        clientCallbacks().word_ignore(tag, toImpl(word)->string().utf8().data());
     144    else
     145        textCheckerEnchant()->ignoreWord(toImpl(word)->string());
     146}
     147
     148namespace Ewk_Text_Checker {
     149
     150Vector<String> availableSpellCheckingLanguages()
     151{
     152    return textCheckerEnchant()->availableSpellCheckingLanguages();
     153}
     154
     155void updateSpellCheckingLanguages(const Vector<String>& languages)
     156{
     157    textCheckerEnchant()->updateSpellCheckingLanguages(languages);
     158}
     159
     160Vector<String> loadedSpellCheckingLanguages()
     161{
     162    return textCheckerEnchant()->loadedSpellCheckingLanguages();
    51163}
    52164
    53165/**
    54  * Attaches spellchecker feature.
     166 * Initializes spellcheck feature.
    55167 *
    56168 * @internal
    57169 *
    58  * The default spellchecker feature is based on Enchant library.
    59  * Client may use own implementation of spellchecker previously set
     170 * The default spellcheck feature is based on Enchant library.
     171 * Client may use own spellcheck implementation previously set
    60172 * through the callback functions.
    61173 */
    62 void ewk_text_checker_client_attach()
     174void initialize()
    63175{
    64176    static bool didInitializeTextCheckerClient = false;
     
    91203}
    92204
    93 /*
    94  * Gets the client's callbacks.
    95  *
    96  * @internal
    97  *
    98  * The client't callbacks are not defined by default.
    99  * If the client hasn't set the callback, the corresponding callback will
    100  * return @c 0 and the default WebKit implementation will be used for this
    101  * functionality.
    102  *
    103  * @return the struct with the client's callbacks.
    104  */
    105 Ewk_Text_Checker* ewk_text_checker_callbacks_get()
    106 {
    107     return &ewkTextCheckerCallbacks;
     205} // namespace Ewk_Text_Checker
     206
     207#define EWK_TEXT_CHECKER_CALLBACK_SET(TYPE_NAME, NAME)  \
     208void ewk_text_checker_##NAME##_cb_set(TYPE_NAME cb)     \
     209{                                                       \
     210    clientCallbacks().NAME = cb;      \
    108211}
    109212
  • trunk/Source/WebKit2/UIProcess/API/efl/ewk_text_checker_private.h

    r131712 r132657  
    11/*
    22 * Copyright (C) 2012 Samsung Electronics
     3 * Copyright (C) 2012 Intel Corporation
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    3132#include "ewk_text_checker.h"
    3233
    33 /**
    34  * @brief Structure keeps client's callback functions.
    35  *
    36  * @internal
    37  */
    38 struct Ewk_Text_Checker {
    39     Ewk_Text_Checker_Unique_Spell_Document_Tag_Get_Cb unique_spell_document_tag_get;
    40     Ewk_Text_Checker_Unique_Spell_Document_Tag_Close_Cb unique_spell_document_tag_close;
    41     Ewk_Text_Checker_String_Spelling_Check_Cb string_spelling_check;
    42     Ewk_Text_Checker_Word_Guesses_Get_Cb word_guesses_get;
    43     Ewk_Text_Checker_Word_Learn_Cb word_learn;
    44     Ewk_Text_Checker_Word_Ignore_Cb word_ignore;
    45 };
     34namespace Ewk_Text_Checker {
    4635
    47 Ewk_Text_Checker* ewk_text_checker_callbacks_get();
     36void initialize();
    4837
    49 // Makes it visible for WTR.
    50 EAPI void ewk_text_checker_client_attach();
     38// Enchant helpers.
     39Vector<String> availableSpellCheckingLanguages();
     40void updateSpellCheckingLanguages(const Vector<String>& languages);
     41Vector<String> loadedSpellCheckingLanguages();
     42
     43}
    5144
    5245#endif // ENABLE(SPELLCHECK)
Note: See TracChangeset for help on using the changeset viewer.