| Index: chrome/renderer/spellchecker/spellcheck_provider.cc
|
| diff --git a/chrome/renderer/spellchecker/spellcheck_provider.cc b/chrome/renderer/spellchecker/spellcheck_provider.cc
|
| index 9f643b43f6e1b2dac0835b6358e0f72d734ab158..c71e415adff3f91635fbe1320b5c25b39c2dfecb 100644
|
| --- a/chrome/renderer/spellchecker/spellcheck_provider.cc
|
| +++ b/chrome/renderer/spellchecker/spellcheck_provider.cc
|
| @@ -41,28 +41,6 @@ COMPILE_ASSERT(int(WebKit::WebTextCheckingTypeCorrection) ==
|
| COMPILE_ASSERT(int(WebKit::WebTextCheckingTypeShowCorrectionPanel) ==
|
| int(SpellCheckResult::SHOWCORRECTIONPANEL), mismatching_enums);
|
|
|
| -namespace {
|
| -
|
| -// Converts a vector of SpellCheckResult objects (used by Chrome) to a vector of
|
| -// WebTextCheckingResult objects (used by WebKit).
|
| -void CreateTextCheckingResults(
|
| - int offset,
|
| - const std::vector<SpellCheckResult>& spellcheck_results,
|
| - WebKit::WebVector<WebKit::WebTextCheckingResult>* textcheck_results) {
|
| - size_t result_size = spellcheck_results.size();
|
| - WebKit::WebVector<WebKit::WebTextCheckingResult> list(result_size);
|
| - for (size_t i = 0; i < result_size; ++i) {
|
| - list[i] = WebTextCheckingResult(
|
| - static_cast<WebTextCheckingType>(spellcheck_results[i].type),
|
| - spellcheck_results[i].location + offset,
|
| - spellcheck_results[i].length,
|
| - spellcheck_results[i].replacement);
|
| - }
|
| - textcheck_results->swap(list);
|
| -}
|
| -
|
| -} // namespace
|
| -
|
| SpellCheckProvider::SpellCheckProvider(
|
| content::RenderView* render_view,
|
| SpellCheck* spellcheck)
|
| @@ -70,14 +48,14 @@ SpellCheckProvider::SpellCheckProvider(
|
| content::RenderViewObserverTracker<SpellCheckProvider>(render_view),
|
| spelling_panel_visible_(false),
|
| spellcheck_(spellcheck) {
|
| + DCHECK(spellcheck_);
|
| if (render_view) // NULL in unit tests.
|
| render_view->GetWebView()->setSpellCheckClient(this);
|
| }
|
|
|
| SpellCheckProvider::~SpellCheckProvider() {
|
| #if defined(OS_MACOSX)
|
| - Send(new SpellCheckHostMsg_DocumentClosed(
|
| - routing_id(), routing_id()));
|
| + Send(new SpellCheckHostMsg_DocumentClosed(routing_id(), routing_id()));
|
| #endif
|
| }
|
|
|
| @@ -111,7 +89,6 @@ void SpellCheckProvider::RequestTextChecking(
|
| last_request_.clear();
|
| last_results_.assign(WebKit::WebVector<WebKit::WebTextCheckingResult>());
|
|
|
| -
|
| Send(new SpellCheckHostMsg_CallSpellingService(
|
| routing_id(),
|
| text_check_completions_.Add(completion),
|
| @@ -163,19 +140,16 @@ void SpellCheckProvider::spellCheck(
|
| int& length,
|
| WebVector<WebString>* optional_suggestions) {
|
| string16 word(text);
|
| - // Will be NULL during unit tests.
|
| - if (spellcheck_) {
|
| - std::vector<string16> suggestions;
|
| - spellcheck_->SpellCheckWord(
|
| - word.c_str(), word.size(), routing_id(),
|
| - &offset, &length, optional_suggestions ? & suggestions : NULL);
|
| - if (optional_suggestions)
|
| - *optional_suggestions = suggestions;
|
| - if (!optional_suggestions) {
|
| - // If optional_suggestions is not requested, the API is called
|
| - // for marking. So we use this for counting markable words.
|
| - Send(new SpellCheckHostMsg_NotifyChecked(routing_id(), word, 0 < length));
|
| - }
|
| + std::vector<string16> suggestions;
|
| + spellcheck_->SpellCheckWord(
|
| + word.c_str(), word.size(), routing_id(),
|
| + &offset, &length, optional_suggestions ? & suggestions : NULL);
|
| + if (optional_suggestions)
|
| + *optional_suggestions = suggestions;
|
| + if (!optional_suggestions) {
|
| + // If optional_suggestions is not requested, the API is called
|
| + // for marking. So we use this for counting markable words.
|
| + Send(new SpellCheckHostMsg_NotifyChecked(routing_id(), word, 0 < length));
|
| }
|
| }
|
|
|
| @@ -192,10 +166,6 @@ void SpellCheckProvider::checkTextOfParagraph(
|
| if (!(mask & WebKit::WebTextCheckingTypeSpelling))
|
| return;
|
|
|
| - // Will be NULL during unit tets.
|
| - if (!spellcheck_)
|
| - return;
|
| -
|
| spellcheck_->SpellCheckParagraph(string16(text), results);
|
| #endif
|
| }
|
| @@ -208,12 +178,8 @@ void SpellCheckProvider::requestCheckingOfText(
|
|
|
| WebString SpellCheckProvider::autoCorrectWord(const WebString& word) {
|
| const CommandLine& command_line = *CommandLine::ForCurrentProcess();
|
| - if (command_line.HasSwitch(switches::kEnableSpellingAutoCorrect)) {
|
| - // Will be NULL during unit tests.
|
| - if (spellcheck_) {
|
| - return spellcheck_->GetAutoCorrectionWord(word, routing_id());
|
| - }
|
| - }
|
| + if (command_line.HasSwitch(switches::kEnableSpellingAutoCorrect))
|
| + return spellcheck_->GetAutoCorrectionWord(word, routing_id());
|
| return string16();
|
| }
|
|
|
| @@ -250,22 +216,18 @@ void SpellCheckProvider::OnRespondSpellingService(
|
|
|
| // If |succeeded| is false, we use local spellcheck as a fallback.
|
| if (!succeeded) {
|
| - // |spellcheck_| may be NULL in unit tests.
|
| - if (spellcheck_) {
|
| - spellcheck_->RequestTextChecking(line, offset, completion);
|
| - return;
|
| - }
|
| + spellcheck_->RequestTextChecking(line, offset, completion);
|
| + return;
|
| }
|
|
|
| // Double-check the returned spellchecking results with our spellchecker to
|
| // visualize the differences between ours and the on-line spellchecker.
|
| WebKit::WebVector<WebKit::WebTextCheckingResult> textcheck_results;
|
| - if (spellcheck_) {
|
| - spellcheck_->CreateTextCheckingResults(
|
| - offset, line, results, &textcheck_results);
|
| - } else {
|
| - CreateTextCheckingResults(offset, results, &textcheck_results);
|
| - }
|
| + spellcheck_->CreateTextCheckingResults(SpellCheck::USE_NATIVE_CHECKER,
|
| + offset,
|
| + line,
|
| + results,
|
| + &textcheck_results);
|
| completion->didFinishCheckingText(textcheck_results);
|
|
|
| // Cache the request and the converted results.
|
| @@ -300,13 +262,18 @@ void SpellCheckProvider::OnAdvanceToNextMisspelling() {
|
| void SpellCheckProvider::OnRespondTextCheck(
|
| int identifier,
|
| const std::vector<SpellCheckResult>& results) {
|
| + DCHECK(spellcheck_);
|
| WebTextCheckingCompletion* completion =
|
| text_check_completions_.Lookup(identifier);
|
| if (!completion)
|
| return;
|
| text_check_completions_.Remove(identifier);
|
| WebKit::WebVector<WebKit::WebTextCheckingResult> textcheck_results;
|
| - CreateTextCheckingResults(0, results, &textcheck_results);
|
| + spellcheck_->CreateTextCheckingResults(SpellCheck::DO_NOT_MODIFY,
|
| + 0,
|
| + string16(),
|
| + results,
|
| + &textcheck_results);
|
| completion->didFinishCheckingText(textcheck_results);
|
| }
|
|
|
|
|