Chromium Code Reviews| 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 return m_webLocalFrame->viewImpl()->textCheckClient(); | |
|
haraken
2017/04/04 05:19:22
Add a TODO and mention that textCheckClient should
Xiaocheng
2017/04/04 19:28:56
Done.
| |
| 23 } | |
| 17 | 24 |
| 18 void TextCheckerClientImpl::checkSpellingOfString(const String& text, | 25 void TextCheckerClientImpl::checkSpellingOfString(const String& text, |
| 19 int* misspellingLocation, | 26 int* misspellingLocation, |
| 20 int* misspellingLength) { | 27 int* misspellingLength) { |
| 21 // SpellCheckWord will write (0, 0) into the output vars, which is what our | 28 // SpellCheckWord will write (0, 0) into the output vars, which is what our |
| 22 // caller expects if the word is spelled correctly. | 29 // caller expects if the word is spelled correctly. |
| 23 int spellLocation = -1; | 30 int spellLocation = -1; |
| 24 int spellLength = 0; | 31 int spellLength = 0; |
| 25 | 32 |
| 26 // Check to see if the provided text is spelled correctly. | 33 // Check to see if the provided text is spelled correctly. |
| 27 if (m_webView->textCheckClient()) { | 34 if (webTextCheckClient()) { |
| 28 m_webView->textCheckClient()->checkSpelling(text, spellLocation, | 35 webTextCheckClient()->checkSpelling(text, spellLocation, spellLength, |
| 29 spellLength, nullptr); | 36 nullptr); |
| 30 } else { | 37 } else { |
| 31 spellLocation = 0; | 38 spellLocation = 0; |
| 32 spellLength = 0; | 39 spellLength = 0; |
| 33 } | 40 } |
| 34 | 41 |
| 35 // Note: the Mac code checks if the pointers are null before writing to them, | 42 // Note: the Mac code checks if the pointers are null before writing to them, |
| 36 // so we do too. | 43 // so we do too. |
| 37 if (misspellingLocation) | 44 if (misspellingLocation) |
| 38 *misspellingLocation = spellLocation; | 45 *misspellingLocation = spellLocation; |
| 39 if (misspellingLength) | 46 if (misspellingLength) |
| 40 *misspellingLength = spellLength; | 47 *misspellingLength = spellLength; |
| 41 } | 48 } |
| 42 | 49 |
| 43 void TextCheckerClientImpl::requestCheckingOfString( | 50 void TextCheckerClientImpl::requestCheckingOfString( |
| 44 TextCheckingRequest* request) { | 51 TextCheckingRequest* request) { |
| 45 if (!m_webView->textCheckClient()) | 52 if (!webTextCheckClient()) |
| 46 return; | 53 return; |
| 47 const String& text = request->data().text(); | 54 const String& text = request->data().text(); |
| 48 m_webView->textCheckClient()->requestCheckingOfText( | 55 webTextCheckClient()->requestCheckingOfText( |
| 49 text, new WebTextCheckingCompletionImpl(request)); | 56 text, new WebTextCheckingCompletionImpl(request)); |
| 50 } | 57 } |
| 51 | 58 |
| 52 void TextCheckerClientImpl::cancelAllPendingRequests() { | 59 void TextCheckerClientImpl::cancelAllPendingRequests() { |
| 53 if (!m_webView->textCheckClient()) | 60 if (!webTextCheckClient()) |
| 54 return; | 61 return; |
| 55 m_webView->textCheckClient()->cancelAllPendingRequests(); | 62 webTextCheckClient()->cancelAllPendingRequests(); |
| 56 } | 63 } |
| 57 | 64 |
| 58 } // namespace blink | 65 } // namespace blink |
| OLD | NEW |