1/* 2 * Copyright (C) 2013 Samsung Electronics 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 13 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 14 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 22 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 26#ifndef TextCheckerClientEfl_h 27#define TextCheckerClientEfl_h 28 29#if ENABLE(SPELLCHECK) 30 31#include "TextCheckerEnchant.h" 32#include "Timer.h" 33#include <WebKit/WKTextChecker.h> 34#include <WebKit/ewk_text_checker_private.h> 35 36namespace WebKit { 37 38class TextCheckerClientEfl { 39public: 40 static TextCheckerClientEfl& instance(); 41 friend class NeverDestroyed<TextCheckerClientEfl>; 42 43 // Can be set by ewk APIs, by default they are 0. 44 ClientCallbacks& clientCallbacks() { return m_clientCallbacks; } 45 46 bool isContinuousSpellCheckingEnabled() const; 47 48 // Languages support. 49 void ensureSpellCheckingLanguage(); 50 Vector<String> availableSpellCheckingLanguages() const; 51 Vector<String> loadedSpellCheckingLanguages() const; 52 void updateSpellCheckingLanguages(const Vector<String>& defaultLanguages = Vector<String>()); 53 54private: 55 TextCheckerClientEfl(); 56 57 // To set languages on timer. 58 void languagesUpdateTimerFired(WebCore::Timer<TextCheckerClientEfl>*); 59 WebCore::Timer<TextCheckerClientEfl> m_languagesUpdateTimer; 60 Vector<String> m_spellCheckingLanguages; 61 62 // To notify the client about the setting change on timer. 63 void spellCheckingSettingChangeTimerFired(WebCore::Timer<TextCheckerClientEfl>*); 64 void callContinuousSpellCheckingChangeCallbackAsync(); 65 WebCore::Timer<TextCheckerClientEfl> m_spellCheckingSettingChangeTimer; 66 67 // WKTextCheckerClient callbacks. 68 static bool isContinuousSpellCheckingEnabledCallback(const void*); 69 static void setContinuousSpellCheckingEnabledCallback(bool, const void*); 70 static uint64_t uniqueSpellDocumentTagCallback(WKPageRef, const void*); 71 static void closeSpellDocumentWithTagCallback(uint64_t, const void*); 72 static void checkSpellingOfStringCallback(uint64_t, WKStringRef text, int32_t* misspellingLocation, int32_t* misspellingLength, const void*); 73 static WKArrayRef guessesForWordCallback(uint64_t, WKStringRef word, const void*); 74 static void learnWordCallback(uint64_t, WKStringRef word, const void*); 75 static void ignoreWordCallback(uint64_t, WKStringRef word, const void*); 76 77 ClientCallbacks m_clientCallbacks; 78 OwnPtr<WebCore::TextCheckerEnchant> m_textCheckerEnchant; 79}; 80 81} // namespace WebKit 82 83#endif // ENABLE(SPELLCHECK) 84#endif // TextCheckerClientEfl_h 85