| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/spellcheck/renderer/spellcheck.h" | 5 #include "components/spellcheck/renderer/spellcheck.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 DocumentMarkersCollector collector; | 256 DocumentMarkersCollector collector; |
| 257 content::RenderView::ForEach(&collector); | 257 content::RenderView::ForEach(&collector); |
| 258 content::RenderThread::Get()->Send( | 258 content::RenderThread::Get()->Send( |
| 259 new SpellCheckHostMsg_RespondDocumentMarkers(collector.markers())); | 259 new SpellCheckHostMsg_RespondDocumentMarkers(collector.markers())); |
| 260 } | 260 } |
| 261 | 261 |
| 262 // TODO(groby): Make sure we always have a spelling engine, even before | 262 // TODO(groby): Make sure we always have a spelling engine, even before |
| 263 // AddSpellcheckLanguage() is called. | 263 // AddSpellcheckLanguage() is called. |
| 264 void SpellCheck::AddSpellcheckLanguage(base::File file, | 264 void SpellCheck::AddSpellcheckLanguage(base::File file, |
| 265 const std::string& language) { | 265 const std::string& language) { |
| 266 languages_.push_back(base::MakeUnique<SpellcheckLanguage>()); | 266 languages_.push_back(new SpellcheckLanguage()); |
| 267 languages_.back()->Init(std::move(file), language); | 267 languages_.back()->Init(std::move(file), language); |
| 268 } | 268 } |
| 269 | 269 |
| 270 bool SpellCheck::SpellCheckWord( | 270 bool SpellCheck::SpellCheckWord( |
| 271 const base::char16* text_begin, | 271 const base::char16* text_begin, |
| 272 int position_in_text, | 272 int position_in_text, |
| 273 int text_length, | 273 int text_length, |
| 274 int tag, | 274 int tag, |
| 275 int* misspelling_start, | 275 int* misspelling_start, |
| 276 int* misspelling_len, | 276 int* misspelling_len, |
| (...skipping 23 matching lines...) Expand all Loading... |
| 300 // skippable. | 300 // skippable. |
| 301 for (; position_in_text <= text_length; | 301 for (; position_in_text <= text_length; |
| 302 position_in_text += agreed_skippable_len) { | 302 position_in_text += agreed_skippable_len) { |
| 303 // Reseting |agreed_skippable_len| to the worst-case length each time | 303 // Reseting |agreed_skippable_len| to the worst-case length each time |
| 304 // prevents some unnecessary iterations. | 304 // prevents some unnecessary iterations. |
| 305 agreed_skippable_len = text_length; | 305 agreed_skippable_len = text_length; |
| 306 *misspelling_start = 0; | 306 *misspelling_start = 0; |
| 307 *misspelling_len = 0; | 307 *misspelling_len = 0; |
| 308 suggestions_list.clear(); | 308 suggestions_list.clear(); |
| 309 | 309 |
| 310 for (auto language = languages_.begin(); language != languages_.end();) { | 310 for (ScopedVector<SpellcheckLanguage>::iterator language = |
| 311 languages_.begin(); |
| 312 language != languages_.end();) { |
| 311 language_suggestions.clear(); | 313 language_suggestions.clear(); |
| 312 SpellcheckLanguage::SpellcheckWordResult result = | 314 SpellcheckLanguage::SpellcheckWordResult result = |
| 313 (*language)->SpellCheckWord( | 315 (*language)->SpellCheckWord( |
| 314 text_begin, position_in_text, text_length, tag, | 316 text_begin, position_in_text, text_length, tag, |
| 315 &possible_misspelling_start, &possible_misspelling_len, | 317 &possible_misspelling_start, &possible_misspelling_len, |
| 316 optional_suggestions ? &language_suggestions : nullptr); | 318 optional_suggestions ? &language_suggestions : nullptr); |
| 317 | 319 |
| 318 switch (result) { | 320 switch (result) { |
| 319 case SpellcheckLanguage::SpellcheckWordResult::IS_CORRECT: | 321 case SpellcheckLanguage::SpellcheckWordResult::IS_CORRECT: |
| 320 *misspelling_start = 0; | 322 *misspelling_start = 0; |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 430 | 432 |
| 431 PostDelayedSpellCheckTask(pending_request_param_.release()); | 433 PostDelayedSpellCheckTask(pending_request_param_.release()); |
| 432 } | 434 } |
| 433 #endif | 435 #endif |
| 434 | 436 |
| 435 bool SpellCheck::InitializeIfNeeded() { | 437 bool SpellCheck::InitializeIfNeeded() { |
| 436 if (languages_.empty()) | 438 if (languages_.empty()) |
| 437 return true; | 439 return true; |
| 438 | 440 |
| 439 bool initialize_if_needed = false; | 441 bool initialize_if_needed = false; |
| 440 for (auto& language : languages_) | 442 for (SpellcheckLanguage* language : languages_) |
| 441 initialize_if_needed |= language->InitializeIfNeeded(); | 443 initialize_if_needed |= language->InitializeIfNeeded(); |
| 442 | 444 |
| 443 return initialize_if_needed; | 445 return initialize_if_needed; |
| 444 } | 446 } |
| 445 | 447 |
| 446 // OSX and Android don't have |pending_request_param_| | 448 // OSX and Android don't have |pending_request_param_| |
| 447 #if !BUILDFLAG(USE_BROWSER_SPELLCHECKER) | 449 #if !BUILDFLAG(USE_BROWSER_SPELLCHECKER) |
| 448 void SpellCheck::PostDelayedSpellCheckTask(SpellcheckRequest* request) { | 450 void SpellCheck::PostDelayedSpellCheckTask(SpellcheckRequest* request) { |
| 449 if (!request) | 451 if (!request) |
| 450 return; | 452 return; |
| 451 | 453 |
| 452 base::ThreadTaskRunnerHandle::Get()->PostTask( | 454 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 453 FROM_HERE, base::Bind(&SpellCheck::PerformSpellCheck, AsWeakPtr(), | 455 FROM_HERE, base::Bind(&SpellCheck::PerformSpellCheck, AsWeakPtr(), |
| 454 base::Owned(request))); | 456 base::Owned(request))); |
| 455 } | 457 } |
| 456 #endif | 458 #endif |
| 457 | 459 |
| 458 // Mac and Android use their platform engines instead. | 460 // Mac and Android use their platform engines instead. |
| 459 #if !BUILDFLAG(USE_BROWSER_SPELLCHECKER) | 461 #if !BUILDFLAG(USE_BROWSER_SPELLCHECKER) |
| 460 void SpellCheck::PerformSpellCheck(SpellcheckRequest* param) { | 462 void SpellCheck::PerformSpellCheck(SpellcheckRequest* param) { |
| 461 DCHECK(param); | 463 DCHECK(param); |
| 462 | 464 |
| 463 if (languages_.empty() || | 465 if (languages_.empty() || |
| 464 std::find_if(languages_.begin(), languages_.end(), | 466 std::find_if(languages_.begin(), languages_.end(), |
| 465 [](std::unique_ptr<SpellcheckLanguage>& language) { | 467 [](SpellcheckLanguage* language) { |
| 466 return !language->IsEnabled(); | 468 return !language->IsEnabled(); |
| 467 }) != languages_.end()) { | 469 }) != languages_.end()) { |
| 468 param->completion()->didCancelCheckingText(); | 470 param->completion()->didCancelCheckingText(); |
| 469 } else { | 471 } else { |
| 470 WebVector<blink::WebTextCheckingResult> results; | 472 WebVector<blink::WebTextCheckingResult> results; |
| 471 SpellCheckParagraph(param->text(), &results); | 473 SpellCheckParagraph(param->text(), &results); |
| 472 param->completion()->didFinishCheckingText(results); | 474 param->completion()->didFinishCheckingText(results); |
| 473 } | 475 } |
| 474 } | 476 } |
| 475 #endif | 477 #endif |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 531 | 533 |
| 532 textcheck_results->assign(results); | 534 textcheck_results->assign(results); |
| 533 } | 535 } |
| 534 | 536 |
| 535 bool SpellCheck::IsSpellcheckEnabled() { | 537 bool SpellCheck::IsSpellcheckEnabled() { |
| 536 #if defined(OS_ANDROID) | 538 #if defined(OS_ANDROID) |
| 537 if (!spellcheck::IsAndroidSpellCheckFeatureEnabled()) return false; | 539 if (!spellcheck::IsAndroidSpellCheckFeatureEnabled()) return false; |
| 538 #endif | 540 #endif |
| 539 return spellcheck_enabled_; | 541 return spellcheck_enabled_; |
| 540 } | 542 } |
| OLD | NEW |