| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006, 2007, 2008, 2011 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007, 2008, 2011 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 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 | 342 |
| 343 void SpellChecker::markMisspellingsAfterLineBreak(const VisibleSelection& wordSe
lection) | 343 void SpellChecker::markMisspellingsAfterLineBreak(const VisibleSelection& wordSe
lection) |
| 344 { | 344 { |
| 345 TRACE_EVENT0("blink", "SpellChecker::markMisspellingsAfterLineBreak"); | 345 TRACE_EVENT0("blink", "SpellChecker::markMisspellingsAfterLineBreak"); |
| 346 | 346 |
| 347 if (!unifiedTextCheckerEnabled()) { | 347 if (!unifiedTextCheckerEnabled()) { |
| 348 markMisspellings(wordSelection); | 348 markMisspellings(wordSelection); |
| 349 return; | 349 return; |
| 350 } | 350 } |
| 351 | 351 |
| 352 TextCheckingTypeMask textCheckingOptions = TextCheckingTypeGrammar; | |
| 353 | |
| 354 if (isContinuousSpellCheckingEnabled()) | 352 if (isContinuousSpellCheckingEnabled()) |
| 355 textCheckingOptions |= TextCheckingTypeSpelling; | 353 markAllMisspellingsInRange(wordSelection.toNormalizedEphemeralRange()); |
| 356 | |
| 357 VisibleSelection wholeParagraph( | |
| 358 startOfParagraph(wordSelection.visibleStart()), | |
| 359 endOfParagraph(wordSelection.visibleEnd())); | |
| 360 | |
| 361 markAllMisspellingsAndBadGrammarInRanges( | |
| 362 textCheckingOptions, wordSelection.toNormalizedEphemeralRange(), | |
| 363 wholeParagraph.toNormalizedEphemeralRange()); | |
| 364 } | 354 } |
| 365 | 355 |
| 366 void SpellChecker::markMisspellingsAfterTypingToWord(const VisiblePosition &word
Start, const VisibleSelection& selectionAfterTyping) | 356 void SpellChecker::markMisspellingsAfterTypingToWord(const VisiblePosition &word
Start, const VisibleSelection& selectionAfterTyping) |
| 367 { | 357 { |
| 368 TRACE_EVENT0("blink", "SpellChecker::markMisspellingsAfterTypingToWord"); | 358 TRACE_EVENT0("blink", "SpellChecker::markMisspellingsAfterTypingToWord"); |
| 369 | 359 |
| 370 if (unifiedTextCheckerEnabled()) { | 360 if (unifiedTextCheckerEnabled()) { |
| 371 TextCheckingTypeMask textCheckingOptions = 0; | 361 TextCheckingTypeMask textCheckingOptions = 0; |
| 372 | 362 |
| 373 if (isContinuousSpellCheckingEnabled()) | 363 if (isContinuousSpellCheckingEnabled()) |
| 374 textCheckingOptions |= TextCheckingTypeSpelling; | 364 textCheckingOptions |= TextCheckingTypeSpelling; |
| 375 | 365 |
| 376 if (!(textCheckingOptions & TextCheckingTypeSpelling)) | 366 if (!(textCheckingOptions & TextCheckingTypeSpelling)) |
| 377 return; | 367 return; |
| 378 | 368 |
| 379 textCheckingOptions |= TextCheckingTypeGrammar; | |
| 380 | |
| 381 VisibleSelection adjacentWords = VisibleSelection(startOfWord(wordStart,
LeftWordIfOnBoundary), endOfWord(wordStart, RightWordIfOnBoundary)); | 369 VisibleSelection adjacentWords = VisibleSelection(startOfWord(wordStart,
LeftWordIfOnBoundary), endOfWord(wordStart, RightWordIfOnBoundary)); |
| 382 if (textCheckingOptions & TextCheckingTypeGrammar) { | 370 markAllMisspellingsInRange(adjacentWords.toNormalizedEphemeralRange()); |
| 383 VisibleSelection selectedSentence = VisibleSelection(startOfSentence
(wordStart), endOfSentence(wordStart)); | |
| 384 markAllMisspellingsAndBadGrammarInRanges(textCheckingOptions, adjace
ntWords.toNormalizedEphemeralRange(), selectedSentence.toNormalizedEphemeralRang
e()); | |
| 385 } else { | |
| 386 markAllMisspellingsAndBadGrammarInRanges(textCheckingOptions, adjace
ntWords.toNormalizedEphemeralRange(), adjacentWords.toNormalizedEphemeralRange()
); | |
| 387 } | |
| 388 return; | 371 return; |
| 389 } | 372 } |
| 390 | 373 |
| 391 if (!isContinuousSpellCheckingEnabled()) | 374 if (!isContinuousSpellCheckingEnabled()) |
| 392 return; | 375 return; |
| 393 | 376 |
| 394 // Check spelling of one word | 377 // Check spelling of one word |
| 395 bool result = markMisspellings(VisibleSelection(startOfWord(wordStart, LeftW
ordIfOnBoundary), endOfWord(wordStart, RightWordIfOnBoundary))); | 378 bool result = markMisspellings(VisibleSelection(startOfWord(wordStart, LeftW
ordIfOnBoundary), endOfWord(wordStart, RightWordIfOnBoundary))); |
| 396 | 379 |
| 397 if (!result) | 380 if (!result) |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 468 bool SpellChecker::markMisspellings(const VisibleSelection& selection) | 451 bool SpellChecker::markMisspellings(const VisibleSelection& selection) |
| 469 { | 452 { |
| 470 return markMisspellingsOrBadGrammar(selection, true); | 453 return markMisspellingsOrBadGrammar(selection, true); |
| 471 } | 454 } |
| 472 | 455 |
| 473 void SpellChecker::markBadGrammar(const VisibleSelection& selection) | 456 void SpellChecker::markBadGrammar(const VisibleSelection& selection) |
| 474 { | 457 { |
| 475 markMisspellingsOrBadGrammar(selection, false); | 458 markMisspellingsOrBadGrammar(selection, false); |
| 476 } | 459 } |
| 477 | 460 |
| 478 void SpellChecker::markAllMisspellingsAndBadGrammarInRanges(TextCheckingTypeMask
textCheckingOptions, const EphemeralRange& spellingRange, const EphemeralRange&
grammarRange) | 461 void SpellChecker::markAllMisspellingsInRange(const EphemeralRange& spellingRang
e) |
| 479 { | 462 { |
| 480 DCHECK(unifiedTextCheckerEnabled()); | 463 DCHECK(unifiedTextCheckerEnabled()); |
| 481 | 464 |
| 482 bool shouldMarkGrammar = textCheckingOptions & TextCheckingTypeGrammar; | |
| 483 | |
| 484 // This function is called with selections already expanded to word boundari
es. | 465 // This function is called with selections already expanded to word boundari
es. |
| 485 if (spellingRange.isNull() || (shouldMarkGrammar && grammarRange.isNull())) | 466 if (spellingRange.isNull()) |
| 486 return; | 467 return; |
| 487 | 468 |
| 488 // If we're not in an editable node, bail. | 469 // If we're not in an editable node, bail. |
| 489 Node* editableNode = spellingRange.startPosition().computeContainerNode(); | 470 Node* editableNode = spellingRange.startPosition().computeContainerNode(); |
| 490 if (!editableNode || !hasEditableStyle(*editableNode)) | 471 if (!editableNode || !hasEditableStyle(*editableNode)) |
| 491 return; | 472 return; |
| 492 | 473 |
| 493 if (!isSpellCheckingEnabledFor(editableNode)) | 474 if (!isSpellCheckingEnabledFor(editableNode)) |
| 494 return; | 475 return; |
| 495 | 476 |
| 496 TextCheckingParagraph fullParagraphToCheck(shouldMarkGrammar ? grammarRange
: spellingRange); | 477 TextCheckingParagraph fullParagraphToCheck(spellingRange); |
| 497 chunkAndMarkAllMisspellingsAndBadGrammar(textCheckingOptions, fullParagraphT
oCheck); | 478 chunkAndMarkAllMisspellingsAndBadGrammar(TextCheckingTypeSpelling, fullParag
raphToCheck); |
| 498 } | 479 } |
| 499 | 480 |
| 500 static EphemeralRange expandEndToSentenceBoundary(const EphemeralRange& range) | 481 static EphemeralRange expandEndToSentenceBoundary(const EphemeralRange& range) |
| 501 { | 482 { |
| 502 DCHECK(range.isNotNull()); | 483 DCHECK(range.isNotNull()); |
| 503 const VisiblePosition& visibleEnd = createVisiblePosition(range.endPosition(
)); | 484 const VisiblePosition& visibleEnd = createVisiblePosition(range.endPosition(
)); |
| 504 DCHECK(visibleEnd.isNotNull()); | 485 DCHECK(visibleEnd.isNotNull()); |
| 505 const Position& sentenceEnd = endOfSentence(visibleEnd).deepEquivalent(); | 486 const Position& sentenceEnd = endOfSentence(visibleEnd).deepEquivalent(); |
| 506 return EphemeralRange(range.startPosition(), sentenceEnd.isNotNull() ? sente
nceEnd : range.endPosition()); | 487 return EphemeralRange(range.startPosition(), sentenceEnd.isNotNull() ? sente
nceEnd : range.endPosition()); |
| 507 } | 488 } |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 666 } | 647 } |
| 667 } | 648 } |
| 668 | 649 |
| 669 void SpellChecker::markMisspellingsAndBadGrammar(const VisibleSelection& spellin
gSelection, bool markGrammar, const VisibleSelection& grammarSelection) | 650 void SpellChecker::markMisspellingsAndBadGrammar(const VisibleSelection& spellin
gSelection, bool markGrammar, const VisibleSelection& grammarSelection) |
| 670 { | 651 { |
| 671 if (unifiedTextCheckerEnabled()) { | 652 if (unifiedTextCheckerEnabled()) { |
| 672 if (!isContinuousSpellCheckingEnabled()) | 653 if (!isContinuousSpellCheckingEnabled()) |
| 673 return; | 654 return; |
| 674 | 655 |
| 675 // markMisspellingsAndBadGrammar() is triggered by selection change, in
which case we check spelling and grammar, but don't autocorrect misspellings. | 656 // markMisspellingsAndBadGrammar() is triggered by selection change, in
which case we check spelling and grammar, but don't autocorrect misspellings. |
| 676 TextCheckingTypeMask textCheckingOptions = TextCheckingTypeSpelling; | 657 markAllMisspellingsInRange(spellingSelection.toNormalizedEphemeralRange(
)); |
| 677 if (markGrammar) | |
| 678 textCheckingOptions |= TextCheckingTypeGrammar; | |
| 679 markAllMisspellingsAndBadGrammarInRanges(textCheckingOptions, spellingSe
lection.toNormalizedEphemeralRange(), grammarSelection.toNormalizedEphemeralRang
e()); | |
| 680 return; | 658 return; |
| 681 } | 659 } |
| 682 | 660 |
| 683 markMisspellings(spellingSelection); | 661 markMisspellings(spellingSelection); |
| 684 if (markGrammar) | 662 if (markGrammar) |
| 685 markBadGrammar(grammarSelection); | 663 markBadGrammar(grammarSelection); |
| 686 } | 664 } |
| 687 | 665 |
| 688 void SpellChecker::updateMarkersForWordsAffectedByEditing(bool doNotRemoveIfSele
ctionAtWordBoundary) | 666 void SpellChecker::updateMarkersForWordsAffectedByEditing(bool doNotRemoveIfSele
ctionAtWordBoundary) |
| 689 { | 667 { |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 978 visitor->trace(m_frame); | 956 visitor->trace(m_frame); |
| 979 visitor->trace(m_spellCheckRequester); | 957 visitor->trace(m_spellCheckRequester); |
| 980 } | 958 } |
| 981 | 959 |
| 982 void SpellChecker::prepareForLeakDetection() | 960 void SpellChecker::prepareForLeakDetection() |
| 983 { | 961 { |
| 984 m_spellCheckRequester->prepareForLeakDetection(); | 962 m_spellCheckRequester->prepareForLeakDetection(); |
| 985 } | 963 } |
| 986 | 964 |
| 987 } // namespace blink | 965 } // namespace blink |
| OLD | NEW |