| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) | 3 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 if (currentStartOffset < currentEndOffset) { | 358 if (currentStartOffset < currentEndOffset) { |
| 359 String paragraphString = plainText(EphemeralRange(paragraphStart, pa
ragraphEnd)); | 359 String paragraphString = plainText(EphemeralRange(paragraphStart, pa
ragraphEnd)); |
| 360 if (paragraphString.length() > 0) { | 360 if (paragraphString.length() > 0) { |
| 361 bool foundGrammar = false; | 361 bool foundGrammar = false; |
| 362 int spellingLocation = 0; | 362 int spellingLocation = 0; |
| 363 int grammarPhraseLocation = 0; | 363 int grammarPhraseLocation = 0; |
| 364 int grammarDetailLocation = 0; | 364 int grammarDetailLocation = 0; |
| 365 unsigned grammarDetailIndex = 0; | 365 unsigned grammarDetailIndex = 0; |
| 366 | 366 |
| 367 Vector<TextCheckingResult> results; | 367 Vector<TextCheckingResult> results; |
| 368 TextCheckingTypeMask checkingTypes = TextCheckingTypeSpelling |
TextCheckingTypeGrammar; | 368 checkTextOfParagraph(m_client->textChecker(), paragraphString, r
esults); |
| 369 checkTextOfParagraph(m_client->textChecker(), paragraphString, c
heckingTypes, results); | |
| 370 | 369 |
| 371 for (unsigned i = 0; i < results.size(); i++) { | 370 for (unsigned i = 0; i < results.size(); i++) { |
| 372 const TextCheckingResult* result = &results[i]; | 371 const TextCheckingResult* result = &results[i]; |
| 373 if (result->decoration == TextDecorationTypeSpelling && resu
lt->location >= currentStartOffset && result->location + result->length <= curre
ntEndOffset) { | 372 if (result->decoration == TextDecorationTypeSpelling && resu
lt->location >= currentStartOffset && result->location + result->length <= curre
ntEndOffset) { |
| 374 DCHECK_GT(result->length, 0); | 373 DCHECK_GT(result->length, 0); |
| 375 DCHECK_GE(result->location, 0); | 374 DCHECK_GE(result->location, 0); |
| 376 spellingLocation = result->location; | 375 spellingLocation = result->location; |
| 377 misspelledWord = paragraphString.substring(result->locat
ion, result->length); | 376 misspelledWord = paragraphString.substring(result->locat
ion, result->length); |
| 378 DCHECK(misspelledWord.length()); | 377 DCHECK(misspelledWord.length()); |
| 379 break; | 378 break; |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 547 findFirstBadGrammar(ignoredGrammarDetail, ignoredOffset, true); | 546 findFirstBadGrammar(ignoredGrammarDetail, ignoredOffset, true); |
| 548 } | 547 } |
| 549 | 548 |
| 550 bool TextCheckingHelper::unifiedTextCheckerEnabled() const | 549 bool TextCheckingHelper::unifiedTextCheckerEnabled() const |
| 551 { | 550 { |
| 552 DCHECK(m_start.isNotNull()); | 551 DCHECK(m_start.isNotNull()); |
| 553 Document& doc = m_start.computeContainerNode()->document(); | 552 Document& doc = m_start.computeContainerNode()->document(); |
| 554 return blink::unifiedTextCheckerEnabled(doc.frame()); | 553 return blink::unifiedTextCheckerEnabled(doc.frame()); |
| 555 } | 554 } |
| 556 | 555 |
| 557 void checkTextOfParagraph(TextCheckerClient& client, const String& text, TextChe
ckingTypeMask checkingTypes, Vector<TextCheckingResult>& results) | 556 void checkTextOfParagraph(TextCheckerClient& client, const String& text, Vector<
TextCheckingResult>& results) |
| 558 { | 557 { |
| 559 Vector<UChar> characters; | 558 Vector<UChar> characters; |
| 560 text.appendTo(characters); | 559 text.appendTo(characters); |
| 561 unsigned length = text.length(); | 560 unsigned length = text.length(); |
| 562 | 561 |
| 563 Vector<TextCheckingResult> spellingResult; | 562 Vector<TextCheckingResult> spellingResult; |
| 564 if (checkingTypes & TextCheckingTypeSpelling) | 563 findMisspellings(client, characters.data(), 0, length, spellingResult); |
| 565 findMisspellings(client, characters.data(), 0, length, spellingResult); | 564 |
| 565 // Only checks grammartical error before the first misspellings |
| 566 int grammarCheckLength = length; |
| 567 for (const auto& spelling : spellingResult) { |
| 568 if (spelling.location < grammarCheckLength) |
| 569 grammarCheckLength = spelling.location; |
| 570 } |
| 566 | 571 |
| 567 Vector<TextCheckingResult> grammarResult; | 572 Vector<TextCheckingResult> grammarResult; |
| 568 if (checkingTypes & TextCheckingTypeGrammar) { | 573 findBadGrammars(client, characters.data(), 0, grammarCheckLength, grammarRes
ult); |
| 569 // Only checks grammartical error before the first misspellings | |
| 570 int grammarCheckLength = length; | |
| 571 for (const auto& spelling : spellingResult) { | |
| 572 if (spelling.location < grammarCheckLength) | |
| 573 grammarCheckLength = spelling.location; | |
| 574 } | |
| 575 | |
| 576 findBadGrammars(client, characters.data(), 0, grammarCheckLength, gramma
rResult); | |
| 577 } | |
| 578 | 574 |
| 579 if (grammarResult.size()) | 575 if (grammarResult.size()) |
| 580 results.swap(grammarResult); | 576 results.swap(grammarResult); |
| 581 | 577 |
| 582 if (spellingResult.size()) { | 578 if (spellingResult.size()) { |
| 583 if (results.isEmpty()) | 579 if (results.isEmpty()) |
| 584 results.swap(spellingResult); | 580 results.swap(spellingResult); |
| 585 else | 581 else |
| 586 results.appendVector(spellingResult); | 582 results.appendVector(spellingResult); |
| 587 } | 583 } |
| 588 } | 584 } |
| 589 | 585 |
| 590 bool unifiedTextCheckerEnabled(const LocalFrame* frame) | 586 bool unifiedTextCheckerEnabled(const LocalFrame* frame) |
| 591 { | 587 { |
| 592 if (!frame) | 588 if (!frame) |
| 593 return false; | 589 return false; |
| 594 | 590 |
| 595 const Settings* settings = frame->settings(); | 591 const Settings* settings = frame->settings(); |
| 596 if (!settings) | 592 if (!settings) |
| 597 return false; | 593 return false; |
| 598 | 594 |
| 599 return settings->unifiedTextCheckerEnabled(); | 595 return settings->unifiedTextCheckerEnabled(); |
| 600 } | 596 } |
| 601 | 597 |
| 602 } // namespace blink | 598 } // namespace blink |
| OLD | NEW |