2 * Copyright (C) 2011 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * 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 APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
27 #include "WebTextCheckerClient.h"
29 #include "ImmutableArray.h"
30 #include "WKAPICast.h"
31 #include "WKSharedAPICast.h"
32 #include "WebGrammarDetail.h"
33 #include "WebPageProxy.h"
34 #include <wtf/text/WTFString.h>
38 bool WebTextCheckerClient::continuousSpellCheckingAllowed()
40 if (!m_client.continuousSpellCheckingAllowed)
43 return m_client.continuousSpellCheckingAllowed(m_client.clientInfo);
46 bool WebTextCheckerClient::continuousSpellCheckingEnabled()
48 if (!m_client.continuousSpellCheckingEnabled)
51 return m_client.continuousSpellCheckingEnabled(m_client.clientInfo);
54 void WebTextCheckerClient::setContinuousSpellCheckingEnabled(bool enabled)
56 if (!m_client.setContinuousSpellCheckingEnabled)
59 m_client.setContinuousSpellCheckingEnabled(enabled, m_client.clientInfo);
62 bool WebTextCheckerClient::grammarCheckingEnabled()
64 if (!m_client.grammarCheckingEnabled)
67 return m_client.grammarCheckingEnabled(m_client.clientInfo);
70 void WebTextCheckerClient::setGrammarCheckingEnabled(bool enabled)
72 if (!m_client.setGrammarCheckingEnabled)
75 m_client.setGrammarCheckingEnabled(enabled, m_client.clientInfo);
78 uint64_t WebTextCheckerClient::uniqueSpellDocumentTag(WebPageProxy* page)
80 if (!m_client.uniqueSpellDocumentTag)
83 return m_client.uniqueSpellDocumentTag(toAPI(page), m_client.clientInfo);
86 void WebTextCheckerClient::closeSpellDocumentWithTag(uint64_t tag)
88 if (!m_client.closeSpellDocumentWithTag)
91 m_client.closeSpellDocumentWithTag(tag, m_client.clientInfo);
94 void WebTextCheckerClient::checkSpellingOfString(uint64_t tag, const String& text, int32_t& misspellingLocation, int32_t& misspellingLength)
96 if (!m_client.checkSpellingOfString)
99 m_client.checkSpellingOfString(tag, toAPI(text.impl()), &misspellingLocation, &misspellingLength, m_client.clientInfo);
102 void WebTextCheckerClient::checkGrammarOfString(uint64_t tag, const String& text, Vector<WebCore::GrammarDetail>& grammarDetails, int32_t& badGrammarLocation, int32_t& badGrammarLength)
104 if (!m_client.checkGrammarOfString)
107 WKArrayRef wkGrammarDetailsRef = 0;
108 m_client.checkGrammarOfString(tag, toAPI(text.impl()), &wkGrammarDetailsRef, &badGrammarLocation, &badGrammarLength, m_client.clientInfo);
110 RefPtr<ImmutableArray> wkGrammarDetails = adoptRef(toImpl(wkGrammarDetailsRef));
111 size_t numGrammarDetails = wkGrammarDetails->size();
112 for (size_t i = 0; i < numGrammarDetails; ++i)
113 grammarDetails.append(wkGrammarDetails->at<WebGrammarDetail>(i)->grammarDetail());
116 bool WebTextCheckerClient::spellingUIIsShowing()
118 if (!m_client.spellingUIIsShowing)
121 return m_client.spellingUIIsShowing(m_client.clientInfo);
124 void WebTextCheckerClient::toggleSpellingUIIsShowing()
126 if (!m_client.toggleSpellingUIIsShowing)
129 return m_client.toggleSpellingUIIsShowing(m_client.clientInfo);
132 void WebTextCheckerClient::updateSpellingUIWithMisspelledWord(uint64_t tag, const String& misspelledWord)
134 if (!m_client.updateSpellingUIWithMisspelledWord)
137 m_client.updateSpellingUIWithMisspelledWord(tag, toAPI(misspelledWord.impl()), m_client.clientInfo);
140 void WebTextCheckerClient::updateSpellingUIWithGrammarString(uint64_t tag, const String& badGrammarPhrase, const WebCore::GrammarDetail& grammarDetail)
142 if (!m_client.updateSpellingUIWithGrammarString)
145 m_client.updateSpellingUIWithGrammarString(tag, toAPI(badGrammarPhrase.impl()), toAPI(grammarDetail), m_client.clientInfo);
148 void WebTextCheckerClient::guessesForWord(uint64_t tag, const String& word, Vector<String>& guesses)
150 if (!m_client.guessesForWord)
153 RefPtr<ImmutableArray> wkGuesses = adoptRef(toImpl(m_client.guessesForWord(tag, toAPI(word.impl()), m_client.clientInfo)));
154 size_t numGuesses = wkGuesses->size();
155 for (size_t i = 0; i < numGuesses; ++i)
156 guesses.append(wkGuesses->at<WebString>(i)->string());
159 void WebTextCheckerClient::learnWord(uint64_t tag, const String& word)
161 if (!m_client.learnWord)
164 m_client.learnWord(tag, toAPI(word.impl()), m_client.clientInfo);
167 void WebTextCheckerClient::ignoreWord(uint64_t tag, const String& word)
169 if (!m_client.ignoreWord)
172 m_client.ignoreWord(tag, toAPI(word.impl()), m_client.clientInfo);
175 } // namespace WebKit