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" | 13 #include "components/test_runner/mock_grammar_check.h" |
14 #include "components/test_runner/test_runner.h" | 14 #include "components/test_runner/test_runner.h" |
15 #include "components/test_runner/web_task.h" | 15 #include "components/test_runner/web_task.h" |
16 #include "components/test_runner/web_test_delegate.h" | 16 #include "components/test_runner/web_test_delegate.h" |
17 #include "third_party/WebKit/public/web/WebTextCheckingCompletion.h" | 17 #include "third_party/WebKit/public/web/WebTextCheckingCompletion.h" |
18 #include "third_party/WebKit/public/web/WebTextCheckingResult.h" | 18 #include "third_party/WebKit/public/web/WebTextCheckingResult.h" |
19 | 19 |
20 namespace test_runner { | 20 namespace test_runner { |
21 | 21 |
22 SpellCheckClient::SpellCheckClient(TestRunner* test_runner) | 22 SpellCheckClient::SpellCheckClient(TestRunner* test_runner) |
23 : last_requested_text_checking_completion_(nullptr), | 23 : enabled_(false), |
yosin_UTC9
2016/08/24 08:00:38
nit: let's initialize |enabled_| in class declarat
Xiaocheng
2016/08/24 08:28:23
Done.
| |
24 last_requested_text_checking_completion_(nullptr), | |
24 test_runner_(test_runner), | 25 test_runner_(test_runner), |
25 weak_factory_(this) { | 26 weak_factory_(this) { |
26 DCHECK(test_runner); | 27 DCHECK(test_runner); |
27 } | 28 } |
28 | 29 |
29 SpellCheckClient::~SpellCheckClient() { | 30 SpellCheckClient::~SpellCheckClient() { |
30 } | 31 } |
31 | 32 |
32 void SpellCheckClient::SetDelegate(WebTestDelegate* delegate) { | 33 void SpellCheckClient::SetDelegate(WebTestDelegate* delegate) { |
33 delegate_ = delegate; | 34 delegate_ = delegate; |
34 } | 35 } |
35 | 36 |
37 void SpellCheckClient::SetEnabled(bool enabled) { | |
38 enabled_ = enabled; | |
39 } | |
40 | |
36 // blink::WebSpellCheckClient | 41 // blink::WebSpellCheckClient |
37 void SpellCheckClient::spellCheck( | 42 void SpellCheckClient::spellCheck( |
38 const blink::WebString& text, | 43 const blink::WebString& text, |
39 int& misspelled_offset, | 44 int& misspelled_offset, |
40 int& misspelled_length, | 45 int& misspelled_length, |
41 blink::WebVector<blink::WebString>* optional_suggestions) { | 46 blink::WebVector<blink::WebString>* optional_suggestions) { |
47 if (!enabled_) { | |
48 misspelled_offset = 0; | |
49 misspelled_length = 0; | |
50 return; | |
51 } | |
52 | |
42 // Check the spelling of the given text. | 53 // Check the spelling of the given text. |
43 spell_check_.SpellCheckWord(text, &misspelled_offset, &misspelled_length); | 54 spell_check_.SpellCheckWord(text, &misspelled_offset, &misspelled_length); |
44 } | 55 } |
45 | 56 |
46 void SpellCheckClient::requestCheckingOfText( | 57 void SpellCheckClient::requestCheckingOfText( |
47 const blink::WebString& text, | 58 const blink::WebString& text, |
48 const blink::WebVector<uint32_t>& markers, | 59 const blink::WebVector<uint32_t>& markers, |
49 const blink::WebVector<unsigned>& marker_offsets, | 60 const blink::WebVector<unsigned>& marker_offsets, |
50 blink::WebTextCheckingCompletion* completion) { | 61 blink::WebTextCheckingCompletion* completion) { |
51 if (text.isEmpty()) { | 62 if (!enabled_ || text.isEmpty()) { |
52 if (completion) | 63 if (completion) |
53 completion->didCancelCheckingText(); | 64 completion->didCancelCheckingText(); |
54 return; | 65 return; |
55 } | 66 } |
56 | 67 |
57 if (last_requested_text_checking_completion_) | 68 if (last_requested_text_checking_completion_) |
58 last_requested_text_checking_completion_->didCancelCheckingText(); | 69 last_requested_text_checking_completion_->didCancelCheckingText(); |
59 | 70 |
60 last_requested_text_checking_completion_ = completion; | 71 last_requested_text_checking_completion_ = completion; |
61 last_requested_text_check_string_ = text; | 72 last_requested_text_check_string_ = text; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
105 &results); | 116 &results); |
106 } | 117 } |
107 last_requested_text_checking_completion_->didFinishCheckingText(results); | 118 last_requested_text_checking_completion_->didFinishCheckingText(results); |
108 last_requested_text_checking_completion_ = 0; | 119 last_requested_text_checking_completion_ = 0; |
109 | 120 |
110 if (test_runner_->shouldDumpSpellCheckCallbacks()) | 121 if (test_runner_->shouldDumpSpellCheckCallbacks()) |
111 delegate_->PrintMessage("SpellCheckEvent: FinishLastTextCheck\n"); | 122 delegate_->PrintMessage("SpellCheckEvent: FinishLastTextCheck\n"); |
112 } | 123 } |
113 | 124 |
114 } // namespace test_runner | 125 } // namespace test_runner |
OLD | NEW |