| 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_provider.h" | 5 #include "components/spellcheck/renderer/spellcheck_provider.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/metrics/histogram_macros.h" | 8 #include "base/metrics/histogram_macros.h" |
| 9 #include "components/spellcheck/common/spellcheck_marker.h" | 9 #include "components/spellcheck/common/spellcheck_marker.h" |
| 10 #include "components/spellcheck/common/spellcheck_messages.h" | 10 #include "components/spellcheck/common/spellcheck_messages.h" |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 | 293 |
| 294 frame->enableSpellChecking(enable); | 294 frame->enableSpellChecking(enable); |
| 295 if (!enable) | 295 if (!enable) |
| 296 frame->removeSpellingMarkers(); | 296 frame->removeSpellingMarkers(); |
| 297 } | 297 } |
| 298 | 298 |
| 299 bool SpellCheckProvider::SatisfyRequestFromCache( | 299 bool SpellCheckProvider::SatisfyRequestFromCache( |
| 300 const base::string16& text, | 300 const base::string16& text, |
| 301 WebTextCheckingCompletion* completion) { | 301 WebTextCheckingCompletion* completion) { |
| 302 size_t last_length = last_request_.length(); | 302 size_t last_length = last_request_.length(); |
| 303 if (!last_length) |
| 304 return false; |
| 303 | 305 |
| 304 // Send back the |last_results_| if the |last_request_| is a substring of | 306 // Send back the |last_results_| if the |last_request_| is a substring of |
| 305 // |text| and |text| does not have more words to check. Provider cannot cancel | 307 // |text| and |text| does not have more words to check. Provider cannot cancel |
| 306 // the spellcheck request here, because WebKit might have discarded the | 308 // the spellcheck request here, because WebKit might have discarded the |
| 307 // previous spellcheck results and erased the spelling markers in response to | 309 // previous spellcheck results and erased the spelling markers in response to |
| 308 // the user editing the text. | 310 // the user editing the text. |
| 309 base::string16 request(text); | 311 base::string16 request(text); |
| 310 size_t text_length = request.length(); | 312 size_t text_length = request.length(); |
| 311 if (text_length >= last_length && | 313 if (text_length >= last_length && |
| 312 !request.compare(0, last_length, last_request_)) { | 314 !request.compare(0, last_length, last_request_)) { |
| 313 if (text_length == last_length || !HasWordCharacters(text, last_length)) { | 315 if (text_length == last_length || !HasWordCharacters(text, last_length)) { |
| 314 completion->didFinishCheckingText(last_results_); | 316 completion->didFinishCheckingText(last_results_); |
| 315 return true; | 317 return true; |
| 316 } | 318 } |
| 317 int code = 0; | |
| 318 int length = static_cast<int>(text_length); | |
| 319 U16_PREV(text.data(), 0, length, code); | |
| 320 UErrorCode error = U_ZERO_ERROR; | |
| 321 if (uscript_getScript(code, &error) != USCRIPT_COMMON) { | |
| 322 completion->didCancelCheckingText(); | |
| 323 return true; | |
| 324 } | |
| 325 } | 319 } |
| 320 |
| 326 // Create a subset of the cached results and return it if the given text is a | 321 // Create a subset of the cached results and return it if the given text is a |
| 327 // substring of the cached text. | 322 // substring of the cached text. |
| 328 if (text_length < last_length && | 323 if (text_length < last_length && |
| 329 !last_request_.compare(0, text_length, request)) { | 324 !last_request_.compare(0, text_length, request)) { |
| 330 size_t result_size = 0; | 325 size_t result_size = 0; |
| 331 for (size_t i = 0; i < last_results_.size(); ++i) { | 326 for (size_t i = 0; i < last_results_.size(); ++i) { |
| 332 size_t start = last_results_[i].location; | 327 size_t start = last_results_[i].location; |
| 333 size_t end = start + last_results_[i].length; | 328 size_t end = start + last_results_[i].length; |
| 334 if (start <= text_length && end <= text_length) | 329 if (start <= text_length && end <= text_length) |
| 335 ++result_size; | 330 ++result_size; |
| 336 } | 331 } |
| 337 blink::WebVector<blink::WebTextCheckingResult> results(last_results_.data(), | 332 blink::WebVector<blink::WebTextCheckingResult> results(last_results_.data(), |
| 338 result_size); | 333 result_size); |
| 339 completion->didFinishCheckingText(results); | 334 completion->didFinishCheckingText(results); |
| 340 return true; | 335 return true; |
| 341 } | 336 } |
| 342 | 337 |
| 343 return false; | 338 return false; |
| 344 } | 339 } |
| 345 | 340 |
| 346 void SpellCheckProvider::OnDestruct() { | 341 void SpellCheckProvider::OnDestruct() { |
| 347 delete this; | 342 delete this; |
| 348 } | 343 } |
| OLD | NEW |