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