| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/test_runner/spell_check_client.h" | 5 #include "components/test_runner/spell_check_client.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 // blink::WebSpellCheckClient | 36 // blink::WebSpellCheckClient |
| 37 void SpellCheckClient::spellCheck( | 37 void SpellCheckClient::spellCheck( |
| 38 const blink::WebString& text, | 38 const blink::WebString& text, |
| 39 int& misspelled_offset, | 39 int& misspelled_offset, |
| 40 int& misspelled_length, | 40 int& misspelled_length, |
| 41 blink::WebVector<blink::WebString>* optional_suggestions) { | 41 blink::WebVector<blink::WebString>* optional_suggestions) { |
| 42 // Check the spelling of the given text. | 42 // Check the spelling of the given text. |
| 43 spell_check_.SpellCheckWord(text, &misspelled_offset, &misspelled_length); | 43 spell_check_.SpellCheckWord(text, &misspelled_offset, &misspelled_length); |
| 44 } | 44 } |
| 45 | 45 |
| 46 void SpellCheckClient::checkTextOfParagraph( | |
| 47 const blink::WebString& text, | |
| 48 blink::WebTextCheckingTypeMask mask, | |
| 49 blink::WebVector<blink::WebTextCheckingResult>* web_results) { | |
| 50 std::vector<blink::WebTextCheckingResult> results; | |
| 51 if (mask & blink::WebTextCheckingTypeSpelling) { | |
| 52 size_t offset = 0; | |
| 53 base::string16 data = text; | |
| 54 while (offset < data.length()) { | |
| 55 int misspelled_position = 0; | |
| 56 int misspelled_length = 0; | |
| 57 spell_check_.SpellCheckWord( | |
| 58 data.substr(offset), &misspelled_position, &misspelled_length); | |
| 59 if (!misspelled_length) | |
| 60 break; | |
| 61 blink::WebTextCheckingResult result; | |
| 62 result.decoration = blink::WebTextDecorationTypeSpelling; | |
| 63 result.location = offset + misspelled_position; | |
| 64 result.length = misspelled_length; | |
| 65 results.push_back(result); | |
| 66 offset += misspelled_position + misspelled_length; | |
| 67 } | |
| 68 } | |
| 69 if (mask & blink::WebTextCheckingTypeGrammar) | |
| 70 MockGrammarCheck::CheckGrammarOfString(text, &results); | |
| 71 web_results->assign(results); | |
| 72 } | |
| 73 | |
| 74 void SpellCheckClient::requestCheckingOfText( | 46 void SpellCheckClient::requestCheckingOfText( |
| 75 const blink::WebString& text, | 47 const blink::WebString& text, |
| 76 const blink::WebVector<uint32_t>& markers, | 48 const blink::WebVector<uint32_t>& markers, |
| 77 const blink::WebVector<unsigned>& marker_offsets, | 49 const blink::WebVector<unsigned>& marker_offsets, |
| 78 blink::WebTextCheckingCompletion* completion) { | 50 blink::WebTextCheckingCompletion* completion) { |
| 79 if (text.isEmpty()) { | 51 if (text.isEmpty()) { |
| 80 if (completion) | 52 if (completion) |
| 81 completion->didCancelCheckingText(); | 53 completion->didCancelCheckingText(); |
| 82 return; | 54 return; |
| 83 } | 55 } |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 &results); | 98 &results); |
| 127 } | 99 } |
| 128 last_requested_text_checking_completion_->didFinishCheckingText(results); | 100 last_requested_text_checking_completion_->didFinishCheckingText(results); |
| 129 last_requested_text_checking_completion_ = 0; | 101 last_requested_text_checking_completion_ = 0; |
| 130 | 102 |
| 131 if (test_runner_->shouldDumpSpellCheckCallbacks()) | 103 if (test_runner_->shouldDumpSpellCheckCallbacks()) |
| 132 delegate_->PrintMessage("SpellCheckEvent: FinishLastTextCheck\n"); | 104 delegate_->PrintMessage("SpellCheckEvent: FinishLastTextCheck\n"); |
| 133 } | 105 } |
| 134 | 106 |
| 135 } // namespace test_runner | 107 } // namespace test_runner |
| OLD | NEW |