| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "web/TextCheckerClientImpl.h" |
| 6 #include "public/web/WebSpellCheckClient.h" |
| 7 #include "public/web/WebTextCheckingResult.h" |
| 8 #include "web/WebTextCheckingCompletionImpl.h" |
| 9 #include "web/WebViewImpl.h" |
| 10 |
| 11 namespace blink { |
| 12 |
| 13 TextCheckerClientImpl::TextCheckerClientImpl(WebViewImpl* webView) |
| 14 : m_webView(webView) {} |
| 15 |
| 16 TextCheckerClientImpl::~TextCheckerClientImpl() = default; |
| 17 |
| 18 void TextCheckerClientImpl::checkSpellingOfString(const String& text, |
| 19 int* misspellingLocation, |
| 20 int* misspellingLength) { |
| 21 // SpellCheckWord will write (0, 0) into the output vars, which is what our |
| 22 // caller expects if the word is spelled correctly. |
| 23 int spellLocation = -1; |
| 24 int spellLength = 0; |
| 25 |
| 26 // Check to see if the provided text is spelled correctly. |
| 27 if (m_webView->spellCheckClient()) { |
| 28 m_webView->spellCheckClient()->checkSpelling(text, spellLocation, |
| 29 spellLength, nullptr); |
| 30 } else { |
| 31 spellLocation = 0; |
| 32 spellLength = 0; |
| 33 } |
| 34 |
| 35 // Note: the Mac code checks if the pointers are null before writing to them, |
| 36 // so we do too. |
| 37 if (misspellingLocation) |
| 38 *misspellingLocation = spellLocation; |
| 39 if (misspellingLength) |
| 40 *misspellingLength = spellLength; |
| 41 } |
| 42 |
| 43 void TextCheckerClientImpl::requestCheckingOfString( |
| 44 TextCheckingRequest* request) { |
| 45 if (!m_webView->spellCheckClient()) |
| 46 return; |
| 47 const String& text = request->data().text(); |
| 48 m_webView->spellCheckClient()->requestCheckingOfText( |
| 49 text, new WebTextCheckingCompletionImpl(request)); |
| 50 } |
| 51 |
| 52 void TextCheckerClientImpl::cancelAllPendingRequests() { |
| 53 if (!m_webView->spellCheckClient()) |
| 54 return; |
| 55 m_webView->spellCheckClient()->cancelAllPendingRequests(); |
| 56 } |
| 57 |
| 58 } // namespace blink |
| OLD | NEW |