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" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "components/test_runner/mock_grammar_check.h" | |
14 #include "components/test_runner/test_runner.h" | 13 #include "components/test_runner/test_runner.h" |
15 #include "components/test_runner/web_task.h" | 14 #include "components/test_runner/web_task.h" |
16 #include "components/test_runner/web_test_delegate.h" | 15 #include "components/test_runner/web_test_delegate.h" |
17 #include "third_party/WebKit/public/web/WebTextCheckingCompletion.h" | 16 #include "third_party/WebKit/public/web/WebTextCheckingCompletion.h" |
18 #include "third_party/WebKit/public/web/WebTextCheckingResult.h" | 17 #include "third_party/WebKit/public/web/WebTextCheckingResult.h" |
19 | 18 |
20 namespace test_runner { | 19 namespace test_runner { |
21 | 20 |
22 SpellCheckClient::SpellCheckClient(TestRunner* test_runner) | 21 SpellCheckClient::SpellCheckClient(TestRunner* test_runner) |
23 : last_requested_text_checking_completion_(nullptr), | 22 : last_requested_text_checking_completion_(nullptr), |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 if (!misspelled_length) | 58 if (!misspelled_length) |
60 break; | 59 break; |
61 blink::WebTextCheckingResult result; | 60 blink::WebTextCheckingResult result; |
62 result.decoration = blink::WebTextDecorationTypeSpelling; | 61 result.decoration = blink::WebTextDecorationTypeSpelling; |
63 result.location = offset + misspelled_position; | 62 result.location = offset + misspelled_position; |
64 result.length = misspelled_length; | 63 result.length = misspelled_length; |
65 results.push_back(result); | 64 results.push_back(result); |
66 offset += misspelled_position + misspelled_length; | 65 offset += misspelled_position + misspelled_length; |
67 } | 66 } |
68 } | 67 } |
69 if (mask & blink::WebTextCheckingTypeGrammar) | |
70 MockGrammarCheck::CheckGrammarOfString(text, &results); | |
71 web_results->assign(results); | 68 web_results->assign(results); |
72 } | 69 } |
73 | 70 |
74 void SpellCheckClient::requestCheckingOfText( | 71 void SpellCheckClient::requestCheckingOfText( |
75 const blink::WebString& text, | 72 const blink::WebString& text, |
76 const blink::WebVector<uint32_t>& markers, | 73 const blink::WebVector<uint32_t>& markers, |
77 const blink::WebVector<unsigned>& marker_offsets, | 74 const blink::WebVector<unsigned>& marker_offsets, |
78 blink::WebTextCheckingCompletion* completion) { | 75 blink::WebTextCheckingCompletion* completion) { |
79 if (text.isEmpty()) { | 76 if (text.isEmpty()) { |
80 if (completion) | 77 if (completion) |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 blink::WebString(text.substr(misspelled_position, misspelled_length)), | 112 blink::WebString(text.substr(misspelled_position, misspelled_length)), |
116 &suggestions); | 113 &suggestions); |
117 results.push_back(blink::WebTextCheckingResult( | 114 results.push_back(blink::WebTextCheckingResult( |
118 blink::WebTextDecorationTypeSpelling, | 115 blink::WebTextDecorationTypeSpelling, |
119 offset + misspelled_position, | 116 offset + misspelled_position, |
120 misspelled_length, | 117 misspelled_length, |
121 suggestions.isEmpty() ? blink::WebString() : suggestions[0])); | 118 suggestions.isEmpty() ? blink::WebString() : suggestions[0])); |
122 text = text.substr(misspelled_position + misspelled_length); | 119 text = text.substr(misspelled_position + misspelled_length); |
123 offset += misspelled_position + misspelled_length; | 120 offset += misspelled_position + misspelled_length; |
124 } | 121 } |
125 MockGrammarCheck::CheckGrammarOfString(last_requested_text_check_string_, | |
126 &results); | |
127 } | 122 } |
128 last_requested_text_checking_completion_->didFinishCheckingText(results); | 123 last_requested_text_checking_completion_->didFinishCheckingText(results); |
129 last_requested_text_checking_completion_ = 0; | 124 last_requested_text_checking_completion_ = 0; |
130 | 125 |
131 if (test_runner_->shouldDumpSpellCheckCallbacks()) | 126 if (test_runner_->shouldDumpSpellCheckCallbacks()) |
132 delegate_->PrintMessage("SpellCheckEvent: FinishLastTextCheck\n"); | 127 delegate_->PrintMessage("SpellCheckEvent: FinishLastTextCheck\n"); |
133 } | 128 } |
134 | 129 |
135 } // namespace test_runner | 130 } // namespace test_runner |
OLD | NEW |