Changeset 148670 in webkit
- Timestamp:
- Apr 18, 2013 6:04:15 AM (11 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit2/ChangeLog
r148666 r148670 1 2013-04-18 Grzegorz Czajkowski <g.czajkowski@samsung.com> 2 3 [WK2][EFL] Text Checker's settings refactor 4 https://bugs.webkit.org/show_bug.cgi?id=111713 5 6 Reviewed by Andreas Kling. 7 8 Use WK2's TextCheckerState object as the store for the text checker settings. 9 It's shared between the client (Ewk API part) and WebProcess (read only). 10 Thanks to it, we don't have to keep any additional structure with 11 the settings on ewk side. 12 13 In the consistency with WKTextChecker C API, move the Ewk's text checker settings APIs 14 to the ewk_text_checker.h/cpp. They're not connected to Ewk_View/Ewk_Settings object to 15 keep them in ewk_setting.h/cpp. 16 17 Introduce a new class to implement WKTextCheckerClient callbacks to call spelling 18 methods through WK2 C API. 19 The main purpose of this change is to detach text checker initialization from ewk_context. 20 21 * PlatformEfl.cmake: 22 Add a new files to the build. 23 24 * UIProcess/API/efl/ewk_context.cpp: 25 (EwkContext::EwkContext): 26 Detach the text checker initialization from context. 27 There might be more than default context. 28 There is one text checker object per application. 29 30 * UIProcess/API/efl/ewk_settings.cpp: 31 * UIProcess/API/efl/ewk_settings.h: 32 Remove the text checker settings. 33 34 * UIProcess/API/efl/ewk_text_checker.cpp: 35 Add the text checker settings to the ewk_text_checker.h/cpp 36 37 (convertLanguagesToEinaList): 38 Add helper function to convert Vector's values to Eina_List. 39 40 (clientCallbacks): 41 Add the client callback responsible for the continuous spell checking 42 setting change to the struct. 43 44 (ewk_text_checker_continuous_spell_checking_enabled_set): 45 Do not call the client's callback responsible for the setting 46 change unless WebKit changes the setting (trough the context 47 'Check Spelling While Typing' option). 48 49 * UIProcess/API/efl/ewk_text_checker.h: 50 Adjust APIs name to the ewk_text_checker syntax. 51 Update the documentation according to the changes. 52 53 * UIProcess/API/efl/ewk_text_checker_private.h: 54 (ClientCallbacks): 55 Move ClientCallbacks structure to TextCheckerClientEfl. 56 The client callbacks (Ewk API) have to be accessible in WKTextCheckerClient callbacks 57 to choose what implementation will be used - the client's (if definied) or Enchant impl. 58 59 * UIProcess/API/efl/tests/test_ewk2_text_checker.cpp: 60 Update the unit tests according to the APIs change. 61 Update the test responsible for the notification about the setting change 62 according to changes in 'ewk_text_checker_continuous_spell_checking_enabled_set'. 63 64 * UIProcess/efl/TextCheckerClientEfl.cpp: Added. 65 Implement WKTextCheckerClient callbacks. 66 67 (TextCheckerClientEfl::TextCheckerClientEfl): 68 (TextCheckerClientEfl::instance): 69 Allow to get and create TextCheckerClientEfl object. 70 71 (TextCheckerClientEfl::isContinuousSpellCheckingEnabled): 72 Get the setting value based on WK2 C API. 73 74 (TextCheckerClientEfl::ensureSpellCheckingLanguage): 75 Load the default languages if user didn't specify any. 76 77 (TextCheckerClientEfl::updateSpellCheckingLanguages): 78 (TextCheckerClientEfl::languagesUpdateTimerFired): 79 (TextCheckerClientEfl::availableSpellCheckingLanguages): 80 (TextCheckerClientEfl::loadedSpellCheckingLanguages): 81 (TextCheckerClientEfl::availableSpellCheckingLanguages): 82 (TextCheckerClientEfl::loadedSpellCheckingLanguages): 83 Provide support for languages. 84 85 (TextCheckerClientEfl::spellCheckingSettingChangeTimerFired): 86 (TextCheckerClientEfl::callContinuousSpellCheckingChangeCallbackAsync): 87 Notify the client about the setting change. 88 89 (TextCheckerClientEfl::isContinuousSpellCheckingEnabledCallback): 90 (TextCheckerClientEfl::setContinuousSpellCheckingEnabledCallback): 91 (TextCheckerClientEfl::uniqueSpellDocumentTagCallback): 92 (TextCheckerClientEfl::closeSpellDocumentWithTagCallback): 93 (TextCheckerClientEfl::checkSpellingOfStringCallback): 94 (TextCheckerClientEfl::guessesForWordCallback): 95 (TextCheckerClientEfl::learnWordCallback): 96 (TextCheckerClientEfl::ignoreWordCallback): 97 WKTextCheckerClient callbacks implementation. 98 99 * UIProcess/efl/TextCheckerClientEfl.h: Added. 100 (TextCheckerClientEfl): 101 (TextCheckerClientEfl::clientCallbacks): 102 Return the client callbacks to be used in ewk_text_checker.cpp. 103 104 * UIProcess/efl/TextCheckerEfl.cpp: 105 (WebKit::TextChecker::state): 106 Initialize the TextCheckerState's members to false. 107 108 (WebKit::TextChecker::setContinuousSpellCheckingEnabled): 109 Set the default language if user didn't specify any. 110 Notify the client about the setting change. 111 This method is called when context menu 'Check Spelling While Typing' 112 option has been toggled. 113 114 (WebKit::TextChecker::continuousSpellCheckingEnabledStateChanged): 115 Set the default language if user didn't specify any. 116 Called by WKTextChecker's API. 117 1 118 2013-04-18 Manuel Rego Casasnovas <rego@igalia.com> 2 119 -
trunk/Source/WebKit2/PlatformEfl.cmake
r148025 r148670 108 108 UIProcess/efl/PageViewportControllerClientEfl.cpp 109 109 UIProcess/efl/RequestManagerClientEfl.cpp 110 UIProcess/efl/TextCheckerClientEfl.cpp 110 111 UIProcess/efl/TextCheckerEfl.cpp 111 112 UIProcess/efl/VibrationClientEfl.cpp -
trunk/Source/WebKit2/UIProcess/API/efl/ewk_context.cpp
r145535 r148670 45 45 #include <wtf/text/WTFString.h> 46 46 47 #if ENABLE(SPELLCHECK)48 #include "ewk_settings.h"49 #include "ewk_text_checker_private.h"50 #endif51 52 47 using namespace WebCore; 53 48 using namespace WebKit; … … 87 82 } 88 83 #endif 89 90 #if ENABLE(SPELLCHECK)91 Ewk_Text_Checker::initialize();92 if (ewk_settings_continuous_spell_checking_enabled_get()) {93 // Load the default language.94 ewk_settings_spell_checking_languages_set(0);95 }96 #endif97 84 } 98 85 -
trunk/Source/WebKit2/UIProcess/API/efl/ewk_settings.cpp
r140686 r148670 34 34 #include <WebKit2/WebPreferences.h> 35 35 36 #if ENABLE(SPELLCHECK)37 #include "WKTextChecker.h"38 #include "ewk_text_checker_private.h"39 #include <Ecore.h>40 #include <wtf/Vector.h>41 #include <wtf/text/CString.h>42 #endif43 44 36 using namespace WebKit; 45 37 … … 53 45 return m_view->page()->pageGroup()->preferences(); 54 46 } 55 56 #if ENABLE(SPELLCHECK)57 static struct {58 bool isContinuousSpellCheckingEnabled : 1;59 Vector<String> spellCheckingLanguages;60 Ewk_Settings_Continuous_Spell_Checking_Change_Cb onContinuousSpellChecking;61 } ewkTextCheckerSettings = { false, Vector<String>(), 0 };62 63 static Eina_Bool onContinuousSpellCheckingIdler(void*)64 {65 if (ewkTextCheckerSettings.onContinuousSpellChecking)66 ewkTextCheckerSettings.onContinuousSpellChecking(ewkTextCheckerSettings.isContinuousSpellCheckingEnabled);67 68 return ECORE_CALLBACK_CANCEL;69 }70 71 static Eina_Bool spellCheckingLanguagesSetUpdate(void*)72 {73 // FIXME: Consider to delegate calling of this method in WebProcess to do not delay/block UIProcess.74 Ewk_Text_Checker::updateSpellCheckingLanguages(ewkTextCheckerSettings.spellCheckingLanguages);75 return ECORE_CALLBACK_CANCEL;76 }77 78 static void spellCheckingLanguagesSet(const Vector<String>& newLanguages)79 {80 ewkTextCheckerSettings.spellCheckingLanguages = newLanguages;81 ecore_idler_add(spellCheckingLanguagesSetUpdate, 0);82 }83 #endif // ENABLE(SPELLCHECK)84 47 85 48 Eina_Bool ewk_settings_fullscreen_enabled_set(Ewk_Settings* settings, Eina_Bool enable) … … 203 166 } 204 167 205 void ewk_settings_continuous_spell_checking_change_cb_set(Ewk_Settings_Continuous_Spell_Checking_Change_Cb callback)206 {207 #if ENABLE(SPELLCHECK)208 ewkTextCheckerSettings.onContinuousSpellChecking = callback;209 #endif210 }211 212 Eina_Bool ewk_settings_continuous_spell_checking_enabled_get()213 {214 #if ENABLE(SPELLCHECK)215 return ewkTextCheckerSettings.isContinuousSpellCheckingEnabled;216 #else217 return false;218 #endif219 }220 221 void ewk_settings_continuous_spell_checking_enabled_set(Eina_Bool enable)222 {223 #if ENABLE(SPELLCHECK)224 enable = !!enable;225 if (ewkTextCheckerSettings.isContinuousSpellCheckingEnabled != enable) {226 ewkTextCheckerSettings.isContinuousSpellCheckingEnabled = enable;227 228 WKTextCheckerContinuousSpellCheckingEnabledStateChanged(enable);229 230 // Sets the default language if user didn't specify any.231 if (enable && !Ewk_Text_Checker::hasDictionary())232 spellCheckingLanguagesSet(Vector<String>());233 234 if (ewkTextCheckerSettings.onContinuousSpellChecking)235 ecore_idler_add(onContinuousSpellCheckingIdler, 0);236 }237 #endif238 }239 240 Eina_List* ewk_settings_spell_checking_available_languages_get()241 {242 Eina_List* listOflanguages = 0;243 #if ENABLE(SPELLCHECK)244 const Vector<String>& languages = Ewk_Text_Checker::availableSpellCheckingLanguages();245 size_t numberOfLanuages = languages.size();246 247 for (size_t i = 0; i < numberOfLanuages; ++i)248 listOflanguages = eina_list_append(listOflanguages, eina_stringshare_add(languages[i].utf8().data()));249 #endif250 return listOflanguages;251 }252 253 void ewk_settings_spell_checking_languages_set(const char* languages)254 {255 #if ENABLE(SPELLCHECK)256 Vector<String> newLanguages;257 String::fromUTF8(languages).split(',', newLanguages);258 259 spellCheckingLanguagesSet(newLanguages);260 #endif261 }262 263 Eina_List* ewk_settings_spell_checking_languages_get()264 {265 Eina_List* listOflanguages = 0;266 #if ENABLE(SPELLCHECK)267 Vector<String> languages = Ewk_Text_Checker::loadedSpellCheckingLanguages();268 size_t numberOfLanuages = languages.size();269 270 for (size_t i = 0; i < numberOfLanuages; ++i)271 listOflanguages = eina_list_append(listOflanguages, eina_stringshare_add(languages[i].utf8().data()));272 273 #endif274 return listOflanguages;275 }276 277 168 Eina_Bool ewk_settings_encoding_detector_enabled_set(Ewk_Settings* settings, Eina_Bool enable) 278 169 { -
trunk/Source/WebKit2/UIProcess/API/efl/ewk_settings.h
r136941 r148670 44 44 typedef struct EwkSettings Ewk_Settings; 45 45 46 /**47 * Creates a type name for the callback function used to notify the client when48 * the continuous spell checking setting was changed by WebKit.49 *50 * @param enable @c EINA_TRUE if continuous spell checking is enabled or @c EINA_FALSE if it's disabled51 */52 typedef void (*Ewk_Settings_Continuous_Spell_Checking_Change_Cb)(Eina_Bool enable);53 54 46 55 47 /** … … 228 220 */ 229 221 EAPI Eina_Bool ewk_settings_dns_prefetching_enabled_get(const Ewk_Settings *settings); 230 231 /**232 * Sets a callback function used to notify the client when233 * the continuous spell checking setting was changed by WebKit.234 *235 * Specifying of this callback is needed if the application wants to receive notifications236 * once WebKit changes this setting.237 * If the application is not interested, this callback is not set.238 * Changing of this setting at the WebKit level can be made as a result of modifying239 * options in a Context Menu by a user.240 *241 * @param cb a new callback function to set or @c NULL to invalidate the previous one242 */243 EAPI void ewk_settings_continuous_spell_checking_change_cb_set(Ewk_Settings_Continuous_Spell_Checking_Change_Cb cb);244 245 /**246 * Queries if continuous spell checking is enabled.247 *248 * @return @c EINA_TRUE if continuous spell checking is enabled or @c EINA_FALSE if it's disabled249 */250 EAPI Eina_Bool ewk_settings_continuous_spell_checking_enabled_get(void);251 252 /**253 * Enables/disables continuous spell checking.254 *255 * Additionally, this function calls a callback function (if defined) to notify256 * the client about the change of the setting.257 * This feature is disabled by default.258 *259 * @see ewk_settings_continuous_spell_checking_change_cb_set260 *261 * @param enable @c EINA_TRUE to enable continuous spell checking or @c EINA_FALSE to disable262 */263 EAPI void ewk_settings_continuous_spell_checking_enabled_set(Eina_Bool enable);264 265 /**266 * Gets the the list of all available the spell checking languages to use.267 *268 * @see ewk_settings_spell_checking_languages_set269 *270 * @return the list with available spell checking languages, or @c NULL on failure271 * the Eina_List and its items should be freed after, use eina_stringshare_del()272 */273 EAPI Eina_List *ewk_settings_spell_checking_available_languages_get(void);274 275 /**276 * Sets @a languages as the list of languages to use by default WebKit277 * implementation of spellchecker feature with Enchant library support.278 *279 * If @languages is @c NULL, the default language is used.280 * If the default language can not be determined then any available dictionary will be used.281 *282 * @note This function invalidates the previously set languages.283 * The dictionaries are requested asynchronously.284 *285 * @param languages a list of comma (',') separated language codes286 * of the form 'en_US', ie, language_VARIANT, may be @c NULL.287 */288 EAPI void ewk_settings_spell_checking_languages_set(const char *languages);289 290 /**291 * Gets the the list of the spell checking languages in use.292 *293 * @see ewk_settings_spell_checking_available_languages_get294 * @see ewk_settings_spell_checking_languages_set295 *296 * @return the list with the spell checking languages in use,297 * the Eina_List and its items should be freed after, use eina_stringshare_del()298 */299 EAPI Eina_List *ewk_settings_spell_checking_languages_get(void);300 222 301 223 /** -
trunk/Source/WebKit2/UIProcess/API/efl/ewk_text_checker.cpp
r145880 r148670 1 1 /* 2 * Copyright (C) 2012 Samsung Electronics2 * Copyright (C) 2012-2013 Samsung Electronics 3 3 * Copyright (C) 2012 Intel Corporation 4 4 * … … 29 29 30 30 #if ENABLE(SPELLCHECK) 31 #include "TextCheckerClientEfl.h" 32 #else 33 #include <wtf/UnusedParam.h> 34 #endif // ENABLE(SPELLCHECK) 31 35 32 #include "EwkView.h" 33 #include "TextCheckerEnchant.h" 34 #include "WKAPICast.h" 35 #include "WKEinaSharedString.h" 36 #include "WKMutableArray.h" 37 #include "WKRetainPtr.h" 38 #include "WKString.h" 39 #include "WKTextChecker.h" 40 #include "WebPageProxy.h" 41 #include "ewk_settings.h" 42 #include "ewk_text_checker_private.h" 43 #include <Eina.h> 44 #include <wtf/OwnPtr.h> 36 #if ENABLE(SPELLCHECK) 45 37 46 38 using namespace WebCore; 47 39 using namespace WebKit; 48 40 49 /** 50 * @brief Structure to store client callback functions. 51 * 52 * @internal 53 */ 54 struct 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; 61 }; 41 static Eina_List* convertLanguagesToEinaList(const Vector<String>& languages) 42 { 43 Eina_List* listOflanguages = 0; 44 size_t numberOfLanguages = languages.size(); 62 45 63 static inline TextCheckerEnchant* textCheckerEnchant()64 { 65 static OwnPtr<TextCheckerEnchant> textCheckerEnchant = TextCheckerEnchant::create(); 66 return textCheckerEnchant.get();46 for (size_t i = 0; i < numberOfLanguages; ++i) 47 listOflanguages = eina_list_append(listOflanguages, eina_stringshare_add(languages[i].utf8().data())); 48 49 return listOflanguages; 67 50 } 68 51 69 static inline ClientCallbacks& clientCallbacks() 70 { 71 DEFINE_STATIC_LOCAL(ClientCallbacks, clientCallbacks, ()); 72 return clientCallbacks; 73 } 74 75 static bool isContinuousSpellCheckingEnabled(const void*) 76 { 77 return ewk_settings_continuous_spell_checking_enabled_get(); 78 } 79 80 static void setContinuousSpellCheckingEnabled(bool enabled, const void*) 81 { 82 ewk_settings_continuous_spell_checking_enabled_set(enabled); 83 } 84 85 static uint64_t uniqueSpellDocumentTag(WKPageRef page, const void*) 86 { 87 if (clientCallbacks().unique_spell_document_tag_get) 88 return clientCallbacks().unique_spell_document_tag_get(EwkView::toEvasObject(page)); 89 90 return 0; 91 } 92 93 static 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 99 static 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, WKEinaSharedString(text), misspellingLocation, misspellingLength); 103 else 104 textCheckerEnchant()->checkSpellingOfString(toWTFString(text), *misspellingLocation, *misspellingLength); 105 } 106 107 static 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, WKEinaSharedString(word)); 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(toWTFString(word)); 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 132 static void learnWord(uint64_t tag, WKStringRef word, const void*) 133 { 134 if (clientCallbacks().word_learn) 135 clientCallbacks().word_learn(tag, WKEinaSharedString(word)); 136 else 137 textCheckerEnchant()->learnWord(toWTFString(word)); 138 } 139 140 static void ignoreWord(uint64_t tag, WKStringRef word, const void*) 141 { 142 if (clientCallbacks().word_ignore) 143 clientCallbacks().word_ignore(tag, WKEinaSharedString(word)); 144 else 145 textCheckerEnchant()->ignoreWord(toWTFString(word)); 146 } 147 148 namespace Ewk_Text_Checker { 149 150 Vector<String> availableSpellCheckingLanguages() 151 { 152 return textCheckerEnchant()->availableSpellCheckingLanguages(); 153 } 154 155 void updateSpellCheckingLanguages(const Vector<String>& languages) 156 { 157 textCheckerEnchant()->updateSpellCheckingLanguages(languages); 158 } 159 160 Vector<String> loadedSpellCheckingLanguages() 161 { 162 return textCheckerEnchant()->loadedSpellCheckingLanguages(); 163 } 164 165 bool hasDictionary() 166 { 167 return textCheckerEnchant()->hasDictionary(); 168 } 169 170 /** 171 * Initializes spellcheck feature. 172 * 173 * @internal 174 * 175 * The default spellcheck feature is based on Enchant library. 176 * Client may use own spellcheck implementation previously set 177 * through the callback functions. 178 */ 179 void initialize() 180 { 181 static bool didInitializeTextCheckerClient = false; 182 if (didInitializeTextCheckerClient) 183 return; 184 185 WKTextCheckerClient textCheckerClient = { 186 kWKTextCheckerClientCurrentVersion, 187 0, // clientInfo 188 0, // isContinuousSpellCheckingAllowed 189 isContinuousSpellCheckingEnabled, 190 setContinuousSpellCheckingEnabled, 191 0, // isGrammarCheckingEnabled 192 0, // setGrammarCheckingEnabled 193 uniqueSpellDocumentTag, 194 closeSpellDocumentWithTag, 195 checkSpellingOfString, 196 0, // checkGrammarOfString 197 0, // spellingUIIsShowing 198 0, // toggleSpellingUIIsShowing 199 0, // updateSpellingUIWithMisspelledWord 200 0, // updateSpellingUIWithGrammarString 201 guessesForWord, 202 learnWord, 203 ignoreWord 204 }; 205 WKTextCheckerSetClient(&textCheckerClient); 206 207 didInitializeTextCheckerClient = true; 208 } 209 210 } // namespace Ewk_Text_Checker 211 212 #define EWK_TEXT_CHECKER_CALLBACK_SET(TYPE_NAME, NAME) \ 213 void ewk_text_checker_##NAME##_cb_set(TYPE_NAME cb) \ 214 { \ 215 clientCallbacks().NAME = cb; \ 52 #define EWK_TEXT_CHECKER_CALLBACK_SET(TYPE_NAME, NAME) \ 53 void ewk_text_checker_##NAME##_cb_set(TYPE_NAME cb) \ 54 { \ 55 TextCheckerClientEfl::instance().clientCallbacks().NAME = cb; \ 216 56 } 217 57 … … 225 65 #endif // ENABLE(SPELLCHECK) 226 66 67 Eina_Bool ewk_text_checker_continuous_spell_checking_enabled_get() 68 { 69 #if ENABLE(SPELLCHECK) 70 return TextCheckerClientEfl::instance().isContinuousSpellCheckingEnabled(); 71 #else 72 return false; 73 #endif 74 } 75 76 void ewk_text_checker_continuous_spell_checking_enabled_set(Eina_Bool enable) 77 { 78 #if ENABLE(SPELLCHECK) 79 WKTextCheckerContinuousSpellCheckingEnabledStateChanged(!!enable); 80 #else 81 UNUSED_PARAM(enable); 82 #endif 83 } 84 85 Eina_List* ewk_text_checker_spell_checking_available_languages_get() 86 { 87 Eina_List* listOflanguages = 0; 88 #if ENABLE(SPELLCHECK) 89 // FIXME: Expose WK2 C API to get available spell checking languages. 90 listOflanguages = convertLanguagesToEinaList(TextCheckerClientEfl::instance().availableSpellCheckingLanguages()); 91 #endif 92 return listOflanguages; 93 } 94 95 void ewk_text_checker_spell_checking_languages_set(const char* languages) 96 { 97 #if ENABLE(SPELLCHECK) 98 Vector<String> newLanguages; 99 String::fromUTF8(languages).split(',', newLanguages); 100 101 // FIXME: Expose WK2 C API to set spell checking languages. 102 TextCheckerClientEfl::instance().updateSpellCheckingLanguages(newLanguages); 103 #else 104 UNUSED_PARAM(languages); 105 #endif 106 } 107 108 Eina_List* ewk_text_checker_spell_checking_languages_get() 109 { 110 Eina_List* listOflanguages = 0; 111 #if ENABLE(SPELLCHECK) 112 // FIXME: Expose WK2 C API to get loaded spell checking languages. 113 listOflanguages = convertLanguagesToEinaList(TextCheckerClientEfl::instance().loadedSpellCheckingLanguages()); 114 #endif 115 return listOflanguages; 116 } 117 118 EWK_TEXT_CHECKER_CALLBACK_SET(Ewk_Text_Checker_Continuous_Spell_Checking_Change_Cb, continuous_spell_checking_change) 227 119 EWK_TEXT_CHECKER_CALLBACK_SET(Ewk_Text_Checker_Unique_Spell_Document_Tag_Get_Cb, unique_spell_document_tag_get) 228 120 EWK_TEXT_CHECKER_CALLBACK_SET(Ewk_Text_Checker_Unique_Spell_Document_Tag_Close_Cb, unique_spell_document_tag_close) -
trunk/Source/WebKit2/UIProcess/API/efl/ewk_text_checker.h
r131579 r148670 1 1 /* 2 * Copyright (C) 2012 Samsung Electronics2 * Copyright (C) 2012-2013 Samsung Electronics 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 26 26 /** 27 27 * @file ewk_text_checker.h 28 * @brief Provides API to overwrite the default WebKit spellchecker implementation. 29 * 30 * There is one spellchecker object per application and it's disabled by default. 28 * @brief Provides API to overwrite the default WebKit spellchecker implementation 29 * and contains API to manipulate spellchecker settings. 30 * 31 * There is one spellchecker object per application. 31 32 * It allows to check spelling in the editable areas. 32 * If application wants to enable the feature, API from ewk_settings.h 33 * 34 * The feature is disabled by default. 35 * If application wants to enable it, ewk_text_checker_continuous_spell_checking_enabled_set API 33 36 * should be used. 34 37 * … … 47 50 extern "C" { 48 51 #endif 52 53 /** 54 * Creates a type name for the callback function used to notify the client when 55 * the continuous spell checking setting was changed by WebKit. 56 * 57 * @param enable @c EINA_TRUE if continuous spell checking is enabled or @c EINA_FALSE if it's disabled 58 */ 59 typedef void (*Ewk_Text_Checker_Continuous_Spell_Checking_Change_Cb)(Eina_Bool enable); 49 60 50 61 /** … … 109 120 typedef void (*Ewk_Text_Checker_Word_Ignore_Cb)(uint64_t tag, const char *word); 110 121 122 123 /** 124 * Queries if continuous spell checking is enabled. 125 * 126 * @return @c EINA_TRUE if continuous spell checking is enabled or @c EINA_FALSE if it's disabled 127 */ 128 EAPI Eina_Bool ewk_text_checker_continuous_spell_checking_enabled_get(void); 129 130 /** 131 * Enables/disables continuous spell checking. 132 * 133 * This feature is disabled by default. 134 * 135 * @see ewk_text_checker_continuous_spell_checking_change_cb_set 136 * 137 * @param enable @c EINA_TRUE to enable continuous spell checking or @c EINA_FALSE to disable 138 */ 139 EAPI void ewk_text_checker_continuous_spell_checking_enabled_set(Eina_Bool enable); 140 141 /** 142 * Gets the the list of all available the spell checking languages to use. 143 * 144 * @see ewk_settings_spell_checking_languages_set 145 * 146 * @return the list with available spell checking languages, or @c NULL on failure 147 * the Eina_List and its items should be freed after, use eina_stringshare_del() 148 */ 149 EAPI Eina_List *ewk_text_checker_spell_checking_available_languages_get(void); 150 151 /** 152 * Sets @a languages as the list of languages to use by default WebKit 153 * implementation of spellchecker feature with Enchant library support. 154 * 155 * If @languages is @c NULL, the default language is used. 156 * If the default language can not be determined then any available dictionary will be used. 157 * 158 * @note This function invalidates the previously set languages. 159 * The dictionaries are requested asynchronously. 160 * 161 * @param languages a list of comma (',') separated language codes 162 * of the form 'en_US', ie, language_VARIANT, may be @c NULL. 163 */ 164 EAPI void ewk_text_checker_spell_checking_languages_set(const char *languages); 165 166 /** 167 * Gets the the list of the spell checking languages in use. 168 * 169 * @see ewk_settings_spell_checking_available_languages_get 170 * @see ewk_settings_spell_checking_languages_set 171 * 172 * @return the list with the spell checking languages in use, 173 * the Eina_List and its items should be freed after, use eina_stringshare_del() 174 */ 175 EAPI Eina_List *ewk_text_checker_spell_checking_languages_get(void); 176 177 /** 178 * Sets a callback function used to notify the client when 179 * the continuous spell checking setting was changed by WebKit. 180 * 181 * Specifying of this callback is needed if the application wants to receive notifications 182 * once WebKit changes this setting. 183 * If the application is not interested, this callback is not set. 184 * Changing of this setting at the WebKit level can be made as a result of modifying 185 * options in a Context Menu by a user. 186 * 187 * @param cb a new callback function to set or @c NULL to invalidate the previous one 188 */ 189 EAPI void ewk_text_checker_continuous_spell_checking_change_cb_set(Ewk_Text_Checker_Continuous_Spell_Checking_Change_Cb cb); 190 111 191 /** 112 192 * Sets a callback function to get a unique spell document tag. -
trunk/Source/WebKit2/UIProcess/API/efl/ewk_text_checker_private.h
r134021 r148670 1 1 /* 2 * Copyright (C) 2012 Samsung Electronics2 * Copyright (C) 2012-2013 Samsung Electronics 3 3 * Copyright (C) 2012 Intel Corporation 4 4 * … … 32 32 #include "ewk_text_checker.h" 33 33 34 namespace Ewk_Text_Checker { 35 36 void initialize(); 37 38 // Enchant helpers. 39 Vector<String> availableSpellCheckingLanguages(); 40 void updateSpellCheckingLanguages(const Vector<String>& languages); 41 Vector<String> loadedSpellCheckingLanguages(); 42 bool hasDictionary(); 43 44 } 34 /** 35 * @brief Structure to store client callback functions. 36 * 37 * @internal 38 */ 39 struct ClientCallbacks { 40 Ewk_Text_Checker_Continuous_Spell_Checking_Change_Cb continuous_spell_checking_change; 41 Ewk_Text_Checker_Unique_Spell_Document_Tag_Get_Cb unique_spell_document_tag_get; 42 Ewk_Text_Checker_Unique_Spell_Document_Tag_Close_Cb unique_spell_document_tag_close; 43 Ewk_Text_Checker_String_Spelling_Check_Cb string_spelling_check; 44 Ewk_Text_Checker_Word_Guesses_Get_Cb word_guesses_get; 45 Ewk_Text_Checker_Word_Learn_Cb word_learn; 46 Ewk_Text_Checker_Word_Ignore_Cb word_ignore; 47 }; 45 48 46 49 #endif // ENABLE(SPELLCHECK) -
trunk/Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_text_checker.cpp
r135349 r148670 214 214 215 215 /** 216 * Test setter/getter for the contin ous spell checking:217 * - ewk_ settings_continuous_spell_checking_enabled_get218 * - ewk_ settings_continuous_spell_checking_enabled_set219 */ 220 TEST_F(EWK2UnitTestBase, ewk_ settings_continuous_spell_checking_enabled)221 { 222 ewk_ settings_continuous_spell_checking_enabled_set(true);216 * Test setter/getter for the continuous spell checking: 217 * - ewk_text_checker_continuous_spell_checking_enabled_get 218 * - ewk_text_checker_continuous_spell_checking_enabled_set 219 */ 220 TEST_F(EWK2UnitTestBase, ewk_text_checker_continuous_spell_checking_enabled) 221 { 222 ewk_text_checker_continuous_spell_checking_enabled_set(true); 223 223 #if ENABLE(SPELLCHECK) 224 EXPECT_TRUE(ewk_ settings_continuous_spell_checking_enabled_get());224 EXPECT_TRUE(ewk_text_checker_continuous_spell_checking_enabled_get()); 225 225 226 226 // When the spell checking has been enabled, the default language is set (if the user … … 229 229 ecore_main_loop_begin(); 230 230 231 Eina_List* loadedLanguages = ewk_ settings_spell_checking_languages_get();231 Eina_List* loadedLanguages = ewk_text_checker_spell_checking_languages_get(); 232 232 // No dictionary is available/installed. 233 233 if (!loadedLanguages) … … 240 240 eina_stringshare_del(static_cast<const char*>(data)); 241 241 #else 242 EXPECT_FALSE(ewk_ settings_continuous_spell_checking_enabled_get());242 EXPECT_FALSE(ewk_text_checker_continuous_spell_checking_enabled_get()); 243 243 #endif 244 244 245 ewk_settings_continuous_spell_checking_enabled_set(false); 246 EXPECT_FALSE(ewk_settings_continuous_spell_checking_enabled_get()); 247 } 248 249 /** 250 * Test whether the callback is called when the spell checking setting has been changed. 251 */ 252 TEST_F(EWK2UnitTestBase, ewk_settings_continuous_spell_checking_change_cb_set) 253 { 254 ewk_settings_continuous_spell_checking_change_cb_set(onSettingChange); 255 256 isSettingEnabled = ewk_settings_continuous_spell_checking_enabled_get(); 245 ewk_text_checker_continuous_spell_checking_enabled_set(false); 246 EXPECT_FALSE(ewk_text_checker_continuous_spell_checking_enabled_get()); 247 } 248 249 /** 250 * Test whether the callback is called when the spell checking setting was changed by WebKit. 251 * Changing of this setting at the WebKit level can be made as a result of modifying 252 * options in a Context Menu by a user. 253 */ 254 TEST_F(EWK2UnitTestBase, ewk_text_checker_continuous_spell_checking_change_cb_set) 255 { 256 ewk_text_checker_continuous_spell_checking_change_cb_set(onSettingChange); 257 258 isSettingEnabled = ewk_text_checker_continuous_spell_checking_enabled_get(); 257 259 isSettingEnabled = !isSettingEnabled; 258 ewk_settings_continuous_spell_checking_enabled_set(isSettingEnabled); 260 // The notifications about the setting change shouldn't be sent if the change was made 261 // on the client's request (public API). 262 ewk_text_checker_continuous_spell_checking_enabled_set(isSettingEnabled); 259 263 260 264 timeoutTimer = ecore_timer_add(defaultTimeoutInSeconds, onTimeout, 0); … … 265 269 ecore_main_loop_begin(); 266 270 267 #if ENABLE(SPELLCHECK)268 EXPECT_FALSE(timeoutTimer);269 #else270 271 EXPECT_TRUE(timeoutTimer); 271 #endif 272 273 // The callback shouldn't be called if the setting option is already set. 274 isSettingEnabled = ewk_settings_continuous_spell_checking_enabled_get(); 275 ewk_settings_continuous_spell_checking_enabled_set(isSettingEnabled); 276 277 timeoutTimer = ecore_timer_add(defaultTimeoutInSeconds, onTimeout, 0); 278 ecore_main_loop_begin(); 279 280 // When the SPELLCHECK macro is disabled the callback won't be called too. 281 EXPECT_TRUE(timeoutTimer); 282 283 // The callback shouldn't be called if the user has invalidated it. 284 ewk_settings_continuous_spell_checking_change_cb_set(0); 285 isSettingEnabled = ewk_settings_continuous_spell_checking_enabled_get(); 286 isSettingEnabled = !isSettingEnabled; 287 ewk_settings_continuous_spell_checking_enabled_set(isSettingEnabled); 288 289 timeoutTimer = ecore_timer_add(defaultTimeoutInSeconds, onTimeout, 0); 290 ecore_main_loop_begin(); 291 292 // If the SPELLCHECK macro is disabled, the callback is not set. 293 EXPECT_TRUE(timeoutTimer); 272 273 /* The callback should be called if the context menu "Check Spelling While Typing" option 274 was toggled by the user. 275 FIXME: 276 1) Invoke the context menu on the input field. 277 2) Choose the sub menu "Spelling and Grammar" option (not implemented for WK2). 278 3) Toggle "Check Spelling While Typing" option. 279 4) Check whether the callback is called. */ 280 281 /* The callback shouldn't be called if the user has invalidated it. 282 FIXME: 283 1) Call ewk_text_checker_continuous_spell_checking_change_cb_set(0) to notify the WebKit that 284 the client is not interested in the setting change. 285 2) Invoke the context menu on the input field. 286 3) Choose the sub menu "Spelling and Grammar" option (not implemented for WK2). 287 4) Toggle "Check Spelling While Typing" option. 288 5) Check whether the callback was called. */ 294 289 } 295 290 … … 299 294 * All the dictionaries from the list can be set to perform spellchecking. 300 295 */ 301 TEST_F(EWK2UnitTestBase, ewk_ settings_spell_checking_available_languages_get)302 { 303 Eina_List* availableLanguages = ewk_ settings_spell_checking_available_languages_get();296 TEST_F(EWK2UnitTestBase, ewk_text_checker_spell_checking_available_languages_get) 297 { 298 Eina_List* availableLanguages = ewk_text_checker_spell_checking_available_languages_get(); 304 299 // No dictionary is available/installed or the SPELLCHECK macro is disabled. 305 300 if (!availableLanguages) … … 320 315 321 316 // Set all available languages. 322 ewk_ settings_spell_checking_languages_set(languages.toString().utf8().data());317 ewk_text_checker_spell_checking_languages_set(languages.toString().utf8().data()); 323 318 324 319 // Languages are being loaded on the idler, wait for them. … … 327 322 328 323 // Get the languages in use. 329 Eina_List* loadedLanguages = ewk_ settings_spell_checking_languages_get();324 Eina_List* loadedLanguages = ewk_text_checker_spell_checking_languages_get(); 330 325 ASSERT_EQ(eina_list_count(loadedLanguages), eina_list_count(availableLanguages)); 331 326 … … 351 346 * - if two arbitrarily selected dictionaries are set correctly. 352 347 */ 353 TEST_F(EWK2UnitTestBase, ewk_ settings_spell_checking_languages)348 TEST_F(EWK2UnitTestBase, ewk_text_checker_spell_checking_languages) 354 349 { 355 350 // Set the default language. 356 ewk_ settings_spell_checking_languages_set(0);351 ewk_text_checker_spell_checking_languages_set(0); 357 352 358 353 // Languages are being loaded on the idler, wait for them. … … 360 355 ecore_main_loop_begin(); 361 356 362 Eina_List* loadedLanguages = ewk_ settings_spell_checking_languages_get();357 Eina_List* loadedLanguages = ewk_text_checker_spell_checking_languages_get(); 363 358 // No dictionary is available/installed or the SPELLCHECK macro is disabled. 364 359 if (!loadedLanguages) … … 373 368 374 369 // Get the first and last language from installed dictionaries. 375 Eina_List* availableLanguages = ewk_ settings_spell_checking_available_languages_get();370 Eina_List* availableLanguages = ewk_text_checker_spell_checking_available_languages_get(); 376 371 unsigned numberOfAvailableLanguages = eina_list_count(availableLanguages); 377 372 // We assume that user has installed at lest two dictionaries. … … 390 385 391 386 // Set both languages (the first and the last) from the list. 392 ewk_ settings_spell_checking_languages_set(languages.toString().utf8().data());387 ewk_text_checker_spell_checking_languages_set(languages.toString().utf8().data()); 393 388 394 389 timeoutTimer = ecore_timer_add(defaultTimeoutInSeconds, onTimeout, 0); 395 390 ecore_main_loop_begin(); 396 391 397 loadedLanguages = ewk_ settings_spell_checking_languages_get();392 loadedLanguages = ewk_text_checker_spell_checking_languages_get(); 398 393 ASSERT_EQ(2, eina_list_count(loadedLanguages)); 399 394 … … 415 410 { 416 411 resetCallbacksExecutionStats(); 417 ewk_ settings_continuous_spell_checking_enabled_set(true);412 ewk_text_checker_continuous_spell_checking_enabled_set(true); 418 413 419 414 ASSERT_TRUE(loadUrlSync(environment->urlForResource("spelling_test.html").data())); … … 437 432 resetCallbacksExecutionStats(); 438 433 defaultView = webView(); 439 ewk_ settings_continuous_spell_checking_enabled_set(true);434 ewk_text_checker_continuous_spell_checking_enabled_set(true); 440 435 441 436 ewk_text_checker_unique_spell_document_tag_get_cb_set(onSpellDocumentTag); … … 459 454 resetCallbacksExecutionStats(); 460 455 defaultView = webView(); 461 ewk_ settings_continuous_spell_checking_enabled_set(true);456 ewk_text_checker_continuous_spell_checking_enabled_set(true); 462 457 463 458 ewk_text_checker_string_spelling_check_cb_set(onSpellingCheck); … … 477 472 resetCallbacksExecutionStats(); 478 473 defaultView = webView(); 479 ewk_ settings_continuous_spell_checking_enabled_set(true);474 ewk_text_checker_continuous_spell_checking_enabled_set(true); 480 475 481 476 ewk_text_checker_word_guesses_get_cb_set(onWordGuesses); … … 499 494 resetCallbacksExecutionStats(); 500 495 defaultView = webView(); 501 ewk_ settings_continuous_spell_checking_enabled_set(true);496 ewk_text_checker_continuous_spell_checking_enabled_set(true); 502 497 503 498 ewk_text_checker_word_learn_cb_set(onWordLearn); … … 519 514 resetCallbacksExecutionStats(); 520 515 defaultView = webView(); 521 ewk_ settings_continuous_spell_checking_enabled_set(true);516 ewk_text_checker_continuous_spell_checking_enabled_set(true); 522 517 523 518 ewk_text_checker_word_ignore_cb_set(onWordIgnore); -
trunk/Source/WebKit2/UIProcess/efl/TextCheckerEfl.cpp
r147993 r148670 2 2 * Copyright (C) 2010 Apple Inc. All rights reserved. 3 3 * Portions Copyright (c) 2010 Motorola Mobility, Inc. All rights reserved. 4 * Copyright (C) 2011-201 2Samsung Electronics4 * Copyright (C) 2011-2013 Samsung Electronics 5 5 * 6 6 * Redistribution and use in source and binary forms, with or without … … 34 34 #if ENABLE(SPELLCHECK) 35 35 #include "TextBreakIterator.h" 36 #include "TextCheckerClientEfl.h" 36 37 #include "WebTextChecker.h" 37 38 #endif … … 45 46 const TextCheckerState& TextChecker::state() 46 47 { 47 #if ENABLE(SPELLCHECK)48 48 static bool didInitializeState = false; 49 49 if (didInitializeState) 50 50 return textCheckerState; 51 51 52 WebTextCheckerClient& client = WebTextChecker::shared()->client(); 53 textCheckerState.isContinuousSpellCheckingEnabled = client.continuousSpellCheckingEnabled(); 54 textCheckerState.isGrammarCheckingEnabled = client.grammarCheckingEnabled(); 52 textCheckerState.isContinuousSpellCheckingEnabled = false; 53 textCheckerState.isGrammarCheckingEnabled = false; 55 54 56 55 didInitializeState = true; 57 #endif 56 58 57 return textCheckerState; 59 58 } … … 72 71 73 72 textCheckerState.isContinuousSpellCheckingEnabled = isContinuousSpellCheckingEnabled; 73 74 if (isContinuousSpellCheckingEnabled) 75 TextCheckerClientEfl::instance().ensureSpellCheckingLanguage(); 76 77 // Notify the client about the setting change. 74 78 WebTextChecker::shared()->client().setContinuousSpellCheckingEnabled(isContinuousSpellCheckingEnabled); 75 79 #else … … 85 89 void TextChecker::continuousSpellCheckingEnabledStateChanged(bool enabled) 86 90 { 87 TextChecker::setContinuousSpellCheckingEnabled(enabled); 91 #if ENABLE(SPELLCHECK) 92 if (state().isContinuousSpellCheckingEnabled == enabled) 93 return; 94 95 textCheckerState.isContinuousSpellCheckingEnabled = enabled; 96 97 if (enabled) 98 TextCheckerClientEfl::instance().ensureSpellCheckingLanguage(); 99 #else 100 UNUSED_PARAM(enabled); 101 #endif 88 102 } 89 103 -
trunk/Tools/ChangeLog
r148662 r148670 1 2013-04-18 Grzegorz Czajkowski <g.czajkowski@samsung.com> 2 3 [WK2][EFL] Text Checker's settings refactor 4 https://bugs.webkit.org/show_bug.cgi?id=111713 5 6 Reviewed by Andreas Kling. 7 8 * MiniBrowser/efl/main.c: 9 (window_create): 10 Use a new text checker API to enable spell checking. 11 1 12 2013-04-18 Seokju Kwon <seokju.kwon@gmail.com> 2 13 -
trunk/Tools/MiniBrowser/efl/main.c
r148662 r148670 1545 1545 ewk_settings_developer_extras_enabled_set(settings, EINA_TRUE); 1546 1546 ewk_settings_preferred_minimum_contents_width_set(settings, 0); 1547 ewk_ settings_continuous_spell_checking_enabled_set(spell_checking_enabled);1547 ewk_text_checker_continuous_spell_checking_enabled_set(spell_checking_enabled); 1548 1548 1549 1549 evas_object_smart_callback_add(window->ewk_view, "authentication,request", on_authentication_request, window);
Note: See TracChangeset
for help on using the changeset viewer.