Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(434)

Side by Side Diff: Source/core/editing/spellcheck/SpellChecker.cpp

Issue 1313863002: Make SpellChecker::markAllMisspellingsAndBadGrammarInRanges() to take EphemeralRange (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: 2015-08-25T15:52:55 Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/core/editing/spellcheck/SpellChecker.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 textCheckingOptions |= TextCheckingTypeSpelling; 356 textCheckingOptions |= TextCheckingTypeSpelling;
357 357
358 if (isGrammarCheckingEnabled()) 358 if (isGrammarCheckingEnabled())
359 textCheckingOptions |= TextCheckingTypeGrammar; 359 textCheckingOptions |= TextCheckingTypeGrammar;
360 360
361 VisibleSelection wholeParagraph( 361 VisibleSelection wholeParagraph(
362 startOfParagraph(wordSelection.visibleStart()), 362 startOfParagraph(wordSelection.visibleStart()),
363 endOfParagraph(wordSelection.visibleEnd())); 363 endOfParagraph(wordSelection.visibleEnd()));
364 364
365 markAllMisspellingsAndBadGrammarInRanges( 365 markAllMisspellingsAndBadGrammarInRanges(
366 textCheckingOptions, wordSelection.toNormalizedRange().get(), 366 textCheckingOptions, wordSelection.toNormalizedEphemeralRange(),
367 wholeParagraph.toNormalizedRange().get()); 367 wholeParagraph.toNormalizedEphemeralRange());
368 } else { 368 } else {
369 RefPtrWillBeRawPtr<Range> misspellingRange = nullptr; 369 RefPtrWillBeRawPtr<Range> misspellingRange = nullptr;
370 markMisspellings(wordSelection, misspellingRange); 370 markMisspellings(wordSelection, misspellingRange);
371 } 371 }
372 } 372 }
373 373
374 void SpellChecker::markMisspellingsAfterTypingToWord(const VisiblePosition &word Start, const VisibleSelection& selectionAfterTyping) 374 void SpellChecker::markMisspellingsAfterTypingToWord(const VisiblePosition &word Start, const VisibleSelection& selectionAfterTyping)
375 { 375 {
376 TRACE_EVENT0("blink", "SpellChecker::markMisspellingsAfterTypingToWord"); 376 TRACE_EVENT0("blink", "SpellChecker::markMisspellingsAfterTypingToWord");
377 377
378 if (unifiedTextCheckerEnabled()) { 378 if (unifiedTextCheckerEnabled()) {
379 TextCheckingTypeMask textCheckingOptions = 0; 379 TextCheckingTypeMask textCheckingOptions = 0;
380 380
381 if (isContinuousSpellCheckingEnabled()) 381 if (isContinuousSpellCheckingEnabled())
382 textCheckingOptions |= TextCheckingTypeSpelling; 382 textCheckingOptions |= TextCheckingTypeSpelling;
383 383
384 if (!(textCheckingOptions & TextCheckingTypeSpelling)) 384 if (!(textCheckingOptions & TextCheckingTypeSpelling))
385 return; 385 return;
386 386
387 if (isGrammarCheckingEnabled()) 387 if (isGrammarCheckingEnabled())
388 textCheckingOptions |= TextCheckingTypeGrammar; 388 textCheckingOptions |= TextCheckingTypeGrammar;
389 389
390 VisibleSelection adjacentWords = VisibleSelection(startOfWord(wordStart, LeftWordIfOnBoundary), endOfWord(wordStart, RightWordIfOnBoundary)); 390 VisibleSelection adjacentWords = VisibleSelection(startOfWord(wordStart, LeftWordIfOnBoundary), endOfWord(wordStart, RightWordIfOnBoundary));
391 if (textCheckingOptions & TextCheckingTypeGrammar) { 391 if (textCheckingOptions & TextCheckingTypeGrammar) {
392 VisibleSelection selectedSentence = VisibleSelection(startOfSentence (wordStart), endOfSentence(wordStart)); 392 VisibleSelection selectedSentence = VisibleSelection(startOfSentence (wordStart), endOfSentence(wordStart));
393 markAllMisspellingsAndBadGrammarInRanges(textCheckingOptions, adjace ntWords.toNormalizedRange().get(), selectedSentence.toNormalizedRange().get()); 393 markAllMisspellingsAndBadGrammarInRanges(textCheckingOptions, adjace ntWords.toNormalizedEphemeralRange(), selectedSentence.toNormalizedEphemeralRang e());
394 } else { 394 } else {
395 markAllMisspellingsAndBadGrammarInRanges(textCheckingOptions, adjace ntWords.toNormalizedRange().get(), adjacentWords.toNormalizedRange().get()); 395 markAllMisspellingsAndBadGrammarInRanges(textCheckingOptions, adjace ntWords.toNormalizedEphemeralRange(), adjacentWords.toNormalizedEphemeralRange() );
396 } 396 }
397 return; 397 return;
398 } 398 }
399 399
400 if (!isContinuousSpellCheckingEnabled()) 400 if (!isContinuousSpellCheckingEnabled())
401 return; 401 return;
402 402
403 // Check spelling of one word 403 // Check spelling of one word
404 RefPtrWillBeRawPtr<Range> misspellingRange = nullptr; 404 RefPtrWillBeRawPtr<Range> misspellingRange = nullptr;
405 markMisspellings(VisibleSelection(startOfWord(wordStart, LeftWordIfOnBoundar y), endOfWord(wordStart, RightWordIfOnBoundary)), misspellingRange); 405 markMisspellings(VisibleSelection(startOfWord(wordStart, LeftWordIfOnBoundar y), endOfWord(wordStart, RightWordIfOnBoundary)), misspellingRange);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 { 461 {
462 markMisspellingsOrBadGrammar(selection, true, firstMisspellingRange); 462 markMisspellingsOrBadGrammar(selection, true, firstMisspellingRange);
463 } 463 }
464 464
465 void SpellChecker::markBadGrammar(const VisibleSelection& selection) 465 void SpellChecker::markBadGrammar(const VisibleSelection& selection)
466 { 466 {
467 RefPtrWillBeRawPtr<Range> firstMisspellingRange = nullptr; 467 RefPtrWillBeRawPtr<Range> firstMisspellingRange = nullptr;
468 markMisspellingsOrBadGrammar(selection, false, firstMisspellingRange); 468 markMisspellingsOrBadGrammar(selection, false, firstMisspellingRange);
469 } 469 }
470 470
471 void SpellChecker::markAllMisspellingsAndBadGrammarInRanges(TextCheckingTypeMask textCheckingOptions, Range* spellingRange, Range* grammarRange) 471 void SpellChecker::markAllMisspellingsAndBadGrammarInRanges(TextCheckingTypeMask textCheckingOptions, const EphemeralRange& spellingRange, const EphemeralRange& grammarRange)
472 { 472 {
473 ASSERT(unifiedTextCheckerEnabled()); 473 ASSERT(unifiedTextCheckerEnabled());
474 474
475 bool shouldMarkGrammar = textCheckingOptions & TextCheckingTypeGrammar; 475 bool shouldMarkGrammar = textCheckingOptions & TextCheckingTypeGrammar;
476 476
477 // This function is called with selections already expanded to word boundari es. 477 // This function is called with selections already expanded to word boundari es.
478 if (!spellingRange || (shouldMarkGrammar && !grammarRange)) 478 if (spellingRange.isNull() || (shouldMarkGrammar && grammarRange.isNull()))
479 return; 479 return;
480 480
481 // If we're not in an editable node, bail. 481 // If we're not in an editable node, bail.
482 Node* editableNode = spellingRange->startContainer(); 482 Node* editableNode = spellingRange.startPosition().computeContainerNode();
483 if (!editableNode || !editableNode->hasEditableStyle()) 483 if (!editableNode || !editableNode->hasEditableStyle())
484 return; 484 return;
485 485
486 if (!isSpellCheckingEnabledFor(editableNode)) 486 if (!isSpellCheckingEnabledFor(editableNode))
487 return; 487 return;
488 488
489 Range* rangeToCheck = shouldMarkGrammar ? grammarRange : spellingRange; 489 RefPtrWillBeRawPtr<Range> rangeToCheck = createRange(shouldMarkGrammar ? gra mmarRange : spellingRange);
490 TextCheckingParagraph fullParagraphToCheck(rangeToCheck); 490 TextCheckingParagraph fullParagraphToCheck(rangeToCheck);
491 491
492 bool asynchronous = frame().settings() && frame().settings()->asynchronousSp ellCheckingEnabled(); 492 bool asynchronous = frame().settings() && frame().settings()->asynchronousSp ellCheckingEnabled();
493 chunkAndMarkAllMisspellingsAndBadGrammar(textCheckingOptions, fullParagraphT oCheck, asynchronous); 493 chunkAndMarkAllMisspellingsAndBadGrammar(textCheckingOptions, fullParagraphT oCheck, asynchronous);
494 } 494 }
495 495
496 void SpellChecker::chunkAndMarkAllMisspellingsAndBadGrammar(Node* node) 496 void SpellChecker::chunkAndMarkAllMisspellingsAndBadGrammar(Node* node)
497 { 497 {
498 TRACE_EVENT0("blink", "SpellChecker::chunkAndMarkAllMisspellingsAndBadGramma r"); 498 TRACE_EVENT0("blink", "SpellChecker::chunkAndMarkAllMisspellingsAndBadGramma r");
499 if (!node) 499 if (!node)
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
636 void SpellChecker::markMisspellingsAndBadGrammar(const VisibleSelection& spellin gSelection, bool markGrammar, const VisibleSelection& grammarSelection) 636 void SpellChecker::markMisspellingsAndBadGrammar(const VisibleSelection& spellin gSelection, bool markGrammar, const VisibleSelection& grammarSelection)
637 { 637 {
638 if (unifiedTextCheckerEnabled()) { 638 if (unifiedTextCheckerEnabled()) {
639 if (!isContinuousSpellCheckingEnabled()) 639 if (!isContinuousSpellCheckingEnabled())
640 return; 640 return;
641 641
642 // markMisspellingsAndBadGrammar() is triggered by selection change, in which case we check spelling and grammar, but don't autocorrect misspellings. 642 // markMisspellingsAndBadGrammar() is triggered by selection change, in which case we check spelling and grammar, but don't autocorrect misspellings.
643 TextCheckingTypeMask textCheckingOptions = TextCheckingTypeSpelling; 643 TextCheckingTypeMask textCheckingOptions = TextCheckingTypeSpelling;
644 if (markGrammar && isGrammarCheckingEnabled()) 644 if (markGrammar && isGrammarCheckingEnabled())
645 textCheckingOptions |= TextCheckingTypeGrammar; 645 textCheckingOptions |= TextCheckingTypeGrammar;
646 markAllMisspellingsAndBadGrammarInRanges(textCheckingOptions, spellingSe lection.toNormalizedRange().get(), grammarSelection.toNormalizedRange().get()); 646 markAllMisspellingsAndBadGrammarInRanges(textCheckingOptions, spellingSe lection.toNormalizedEphemeralRange(), grammarSelection.toNormalizedEphemeralRang e());
647 return; 647 return;
648 } 648 }
649 649
650 RefPtrWillBeRawPtr<Range> firstMisspellingRange = nullptr; 650 RefPtrWillBeRawPtr<Range> firstMisspellingRange = nullptr;
651 markMisspellings(spellingSelection, firstMisspellingRange); 651 markMisspellings(spellingSelection, firstMisspellingRange);
652 if (markGrammar) 652 if (markGrammar)
653 markBadGrammar(grammarSelection); 653 markBadGrammar(grammarSelection);
654 } 654 }
655 655
656 void SpellChecker::updateMarkersForWordsAffectedByEditing(bool doNotRemoveIfSele ctionAtWordBoundary) 656 void SpellChecker::updateMarkersForWordsAffectedByEditing(bool doNotRemoveIfSele ctionAtWordBoundary)
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
937 m_spellCheckRequester->requestCheckingFor(SpellCheckRequest::create(TextChec kingTypeSpelling | TextCheckingTypeGrammar, TextCheckingProcessBatch, rangeToChe ck, rangeToCheck)); 937 m_spellCheckRequester->requestCheckingFor(SpellCheckRequest::create(TextChec kingTypeSpelling | TextCheckingTypeGrammar, TextCheckingProcessBatch, rangeToChe ck, rangeToCheck));
938 } 938 }
939 939
940 DEFINE_TRACE(SpellChecker) 940 DEFINE_TRACE(SpellChecker)
941 { 941 {
942 visitor->trace(m_frame); 942 visitor->trace(m_frame);
943 visitor->trace(m_spellCheckRequester); 943 visitor->trace(m_spellCheckRequester);
944 } 944 }
945 945
946 } // namespace blink 946 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/editing/spellcheck/SpellChecker.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698