Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(218)

Side by Side Diff: content/shell/renderer/test_runner/SpellCheckClient.cpp

Issue 410283003: test_runner: Migrate MockSpellCheck to Chromium C++ style. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updated Build.gn Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "content/shell/renderer/test_runner/SpellCheckClient.h" 5 #include "content/shell/renderer/test_runner/SpellCheckClient.h"
6 6
7 #include "content/shell/renderer/test_runner/WebTestDelegate.h" 7 #include "content/shell/renderer/test_runner/WebTestDelegate.h"
8 #include "content/shell/renderer/test_runner/mock_grammar_check.h" 8 #include "content/shell/renderer/test_runner/mock_grammar_check.h"
9 #include "content/shell/renderer/test_runner/web_test_proxy.h" 9 #include "content/shell/renderer/test_runner/web_test_proxy.h"
10 #include "third_party/WebKit/public/web/WebTextCheckingCompletion.h" 10 #include "third_party/WebKit/public/web/WebTextCheckingCompletion.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 44
45 void SpellCheckClient::setDelegate(WebTestDelegate* delegate) 45 void SpellCheckClient::setDelegate(WebTestDelegate* delegate)
46 { 46 {
47 m_delegate = delegate; 47 m_delegate = delegate;
48 } 48 }
49 49
50 // blink::WebSpellCheckClient 50 // blink::WebSpellCheckClient
51 void SpellCheckClient::spellCheck(const WebString& text, int& misspelledOffset, int& misspelledLength, WebVector<WebString>* optionalSuggestions) 51 void SpellCheckClient::spellCheck(const WebString& text, int& misspelledOffset, int& misspelledLength, WebVector<WebString>* optionalSuggestions)
52 { 52 {
53 // Check the spelling of the given text. 53 // Check the spelling of the given text.
54 m_spellcheck.spellCheckWord(text, &misspelledOffset, &misspelledLength); 54 m_spellcheck.SpellCheckWord(text, &misspelledOffset, &misspelledLength);
55 } 55 }
56 56
57 void SpellCheckClient::checkTextOfParagraph(const WebString& text, WebTextChecki ngTypeMask mask, WebVector<WebTextCheckingResult>* webResults) 57 void SpellCheckClient::checkTextOfParagraph(const WebString& text, WebTextChecki ngTypeMask mask, WebVector<WebTextCheckingResult>* webResults)
58 { 58 {
59 std::vector<WebTextCheckingResult> results; 59 std::vector<WebTextCheckingResult> results;
60 if (mask & WebTextCheckingTypeSpelling) { 60 if (mask & WebTextCheckingTypeSpelling) {
61 size_t offset = 0; 61 size_t offset = 0;
62 base::string16 data = text; 62 base::string16 data = text;
63 while (offset < data.length()) { 63 while (offset < data.length()) {
64 int misspelledPosition = 0; 64 int misspelledPosition = 0;
65 int misspelledLength = 0; 65 int misspelledLength = 0;
66 m_spellcheck.spellCheckWord(data.substr(offset), &misspelledPosition , &misspelledLength); 66 m_spellcheck.SpellCheckWord(
67 data.substr(offset), &misspelledPosition, &misspelledLength);
67 if (!misspelledLength) 68 if (!misspelledLength)
68 break; 69 break;
69 WebTextCheckingResult result; 70 WebTextCheckingResult result;
70 result.decoration = WebTextDecorationTypeSpelling; 71 result.decoration = WebTextDecorationTypeSpelling;
71 result.location = offset + misspelledPosition; 72 result.location = offset + misspelledPosition;
72 result.length = misspelledLength; 73 result.length = misspelledLength;
73 results.push_back(result); 74 results.push_back(result);
74 offset += misspelledPosition + misspelledLength; 75 offset += misspelledPosition + misspelledLength;
75 } 76 }
76 } 77 }
(...skipping 12 matching lines...) Expand all
89 if (completion) 90 if (completion)
90 completion->didCancelCheckingText(); 91 completion->didCancelCheckingText();
91 return; 92 return;
92 } 93 }
93 94
94 if (m_lastRequestedTextCheckingCompletion) 95 if (m_lastRequestedTextCheckingCompletion)
95 m_lastRequestedTextCheckingCompletion->didCancelCheckingText(); 96 m_lastRequestedTextCheckingCompletion->didCancelCheckingText();
96 97
97 m_lastRequestedTextCheckingCompletion = completion; 98 m_lastRequestedTextCheckingCompletion = completion;
98 m_lastRequestedTextCheckString = text; 99 m_lastRequestedTextCheckString = text;
99 if (m_spellcheck.hasInCache(text)) 100 if (m_spellcheck.HasInCache(text))
100 finishLastTextCheck(); 101 finishLastTextCheck();
101 else 102 else
102 m_delegate->postDelayedTask(new HostMethodTask(this, &SpellCheckClient:: finishLastTextCheck), 0); 103 m_delegate->postDelayedTask(new HostMethodTask(this, &SpellCheckClient:: finishLastTextCheck), 0);
103 } 104 }
104 105
105 void SpellCheckClient::finishLastTextCheck() 106 void SpellCheckClient::finishLastTextCheck()
106 { 107 {
107 if (!m_lastRequestedTextCheckingCompletion) 108 if (!m_lastRequestedTextCheckingCompletion)
108 return; 109 return;
109 std::vector<WebTextCheckingResult> results; 110 std::vector<WebTextCheckingResult> results;
110 int offset = 0; 111 int offset = 0;
111 base::string16 text = m_lastRequestedTextCheckString; 112 base::string16 text = m_lastRequestedTextCheckString;
112 if (!m_spellcheck.isMultiWordMisspelling(WebString(text), &results)) { 113 if (!m_spellcheck.IsMultiWordMisspelling(WebString(text), &results)) {
113 while (text.length()) { 114 while (text.length()) {
114 int misspelledPosition = 0; 115 int misspelledPosition = 0;
115 int misspelledLength = 0; 116 int misspelledLength = 0;
116 m_spellcheck.spellCheckWord(WebString(text), &misspelledPosition, &m isspelledLength); 117 m_spellcheck.SpellCheckWord(
118 WebString(text), &misspelledPosition, &misspelledLength);
117 if (!misspelledLength) 119 if (!misspelledLength)
118 break; 120 break;
119 WebVector<WebString> suggestions; 121 WebVector<WebString> suggestions;
120 m_spellcheck.fillSuggestionList(WebString(text.substr(misspelledPosi tion, misspelledLength)), &suggestions); 122 m_spellcheck.FillSuggestionList(
123 WebString(text.substr(misspelledPosition, misspelledLength)),
124 &suggestions);
121 results.push_back(WebTextCheckingResult(WebTextDecorationTypeSpellin g, offset + misspelledPosition, misspelledLength, suggestions.isEmpty() ? WebStr ing() : suggestions[0])); 125 results.push_back(WebTextCheckingResult(WebTextDecorationTypeSpellin g, offset + misspelledPosition, misspelledLength, suggestions.isEmpty() ? WebStr ing() : suggestions[0]));
122 text = text.substr(misspelledPosition + misspelledLength); 126 text = text.substr(misspelledPosition + misspelledLength);
123 offset += misspelledPosition + misspelledLength; 127 offset += misspelledPosition + misspelledLength;
124 } 128 }
125 MockGrammarCheck::CheckGrammarOfString(m_lastRequestedTextCheckString, & results); 129 MockGrammarCheck::CheckGrammarOfString(m_lastRequestedTextCheckString, & results);
126 } 130 }
127 m_lastRequestedTextCheckingCompletion->didFinishCheckingText(results); 131 m_lastRequestedTextCheckingCompletion->didFinishCheckingText(results);
128 m_lastRequestedTextCheckingCompletion = 0; 132 m_lastRequestedTextCheckingCompletion = 0;
129 133
130 m_webTestProxy->PostSpellCheckEvent(WebString("finishLastTextCheck")); 134 m_webTestProxy->PostSpellCheckEvent(WebString("finishLastTextCheck"));
131 } 135 }
132 136
133 WebString SpellCheckClient::autoCorrectWord(const WebString&) 137 WebString SpellCheckClient::autoCorrectWord(const WebString&)
134 { 138 {
135 // Returns an empty string as Mac WebKit ('WebKitSupport/WebEditorClient.mm' ) 139 // Returns an empty string as Mac WebKit ('WebKitSupport/WebEditorClient.mm' )
136 // does. (If this function returns a non-empty string, WebKit replaces the 140 // does. (If this function returns a non-empty string, WebKit replaces the
137 // given misspelled string with the result one. This process executes some 141 // given misspelled string with the result one. This process executes some
138 // editor commands and causes layout-test failures.) 142 // editor commands and causes layout-test failures.)
139 return WebString(); 143 return WebString();
140 } 144 }
141 145
142 } // namespace content 146 } // namespace content
OLDNEW
« no previous file with comments | « content/shell/renderer/test_runner/SpellCheckClient.h ('k') | content/shell/renderer/test_runner/event_sender.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698