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

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

Issue 2390573002: Reland of Prune CreateVisibleSelectionDeprecated from SpellChecker (Closed)
Patch Set: Rebased on clang reformatting Created 4 years, 2 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 | « no previous file | 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 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 findFirstMisspelling(spellingSearchStart, spellingSearchEnd); 316 findFirstMisspelling(spellingSearchStart, spellingSearchEnd);
317 } 317 }
318 318
319 if (!misspelledWord.isEmpty()) { 319 if (!misspelledWord.isEmpty()) {
320 // We found a misspelling. Select the misspelling, update the spelling panel , and store 320 // We found a misspelling. Select the misspelling, update the spelling panel , and store
321 // a marker so we draw the red squiggle later. 321 // a marker so we draw the red squiggle later.
322 322
323 const EphemeralRange misspellingRange = calculateCharacterSubrange( 323 const EphemeralRange misspellingRange = calculateCharacterSubrange(
324 EphemeralRange(spellingSearchStart, spellingSearchEnd), 324 EphemeralRange(spellingSearchStart, spellingSearchEnd),
325 misspellingOffset, misspelledWord.length()); 325 misspellingOffset, misspelledWord.length());
326 frame().selection().setSelection( 326 frame().selection().setSelection(createVisibleSelection(misspellingRange));
327 createVisibleSelectionDeprecated(misspellingRange));
328 frame().selection().revealSelection(); 327 frame().selection().revealSelection();
329 spellCheckerClient().updateSpellingUIWithMisspelledWord(misspelledWord); 328 spellCheckerClient().updateSpellingUIWithMisspelledWord(misspelledWord);
330 frame().document()->markers().addMarker(misspellingRange.startPosition(), 329 frame().document()->markers().addMarker(misspellingRange.startPosition(),
331 misspellingRange.endPosition(), 330 misspellingRange.endPosition(),
332 DocumentMarker::Spelling); 331 DocumentMarker::Spelling);
333 } 332 }
334 } 333 }
335 334
336 void SpellChecker::showSpellingGuessPanel() { 335 void SpellChecker::showSpellingGuessPanel() {
337 if (spellCheckerClient().spellingUIIsShowing()) { 336 if (spellCheckerClient().spellingUIIsShowing()) {
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 VisiblePosition start = createVisiblePosition( 418 VisiblePosition start = createVisiblePosition(
420 cmd.endingSelection().start(), cmd.endingSelection().affinity()); 419 cmd.endingSelection().start(), cmd.endingSelection().affinity());
421 VisiblePosition previous = previousPositionOf(start); 420 VisiblePosition previous = previousPositionOf(start);
422 421
423 VisiblePosition wordStartOfPrevious = 422 VisiblePosition wordStartOfPrevious =
424 startOfWord(previous, LeftWordIfOnBoundary); 423 startOfWord(previous, LeftWordIfOnBoundary);
425 424
426 if (cmd.commandTypeOfOpenCommand() == 425 if (cmd.commandTypeOfOpenCommand() ==
427 TypingCommand::InsertParagraphSeparator) { 426 TypingCommand::InsertParagraphSeparator) {
428 VisiblePosition nextWord = nextWordPosition(start); 427 VisiblePosition nextWord = nextWordPosition(start);
429 VisibleSelection words = createVisibleSelectionDeprecated( 428 VisibleSelection words =
430 wordStartOfPrevious, endOfWord(nextWord)); 429 createVisibleSelection(wordStartOfPrevious, endOfWord(nextWord));
431 markMisspellingsAfterLineBreak(words); 430 markMisspellingsAfterLineBreak(words);
432 return; 431 return;
433 } 432 }
434 433
435 if (previous.isNull()) 434 if (previous.isNull())
436 return; 435 return;
437 VisiblePosition currentWordStart = startOfWord(start, LeftWordIfOnBoundary); 436 VisiblePosition currentWordStart = startOfWord(start, LeftWordIfOnBoundary);
438 if (wordStartOfPrevious.deepEquivalent() == currentWordStart.deepEquivalent()) 437 if (wordStartOfPrevious.deepEquivalent() == currentWordStart.deepEquivalent())
439 return; 438 return;
440 markMisspellingsAfterTypingToWord(wordStartOfPrevious); 439 markMisspellingsAfterTypingToWord(wordStartOfPrevious);
441 } 440 }
442 441
443 void SpellChecker::markMisspellingsAfterLineBreak( 442 void SpellChecker::markMisspellingsAfterLineBreak(
444 const VisibleSelection& wordSelection) { 443 const VisibleSelection& wordSelection) {
445 TRACE_EVENT0("blink", "SpellChecker::markMisspellingsAfterLineBreak"); 444 TRACE_EVENT0("blink", "SpellChecker::markMisspellingsAfterLineBreak");
446 445
447 markMisspellingsAndBadGrammar(wordSelection); 446 markMisspellingsAndBadGrammar(wordSelection);
448 } 447 }
449 448
450 void SpellChecker::markMisspellingsAfterTypingToWord( 449 void SpellChecker::markMisspellingsAfterTypingToWord(
451 const VisiblePosition& wordStart) { 450 const VisiblePosition& wordStart) {
452 TRACE_EVENT0("blink", "SpellChecker::markMisspellingsAfterTypingToWord"); 451 TRACE_EVENT0("blink", "SpellChecker::markMisspellingsAfterTypingToWord");
453 452
454 VisibleSelection adjacentWords = createVisibleSelectionDeprecated( 453 VisibleSelection adjacentWords =
455 startOfWord(wordStart, LeftWordIfOnBoundary), 454 createVisibleSelection(startOfWord(wordStart, LeftWordIfOnBoundary),
456 endOfWord(wordStart, RightWordIfOnBoundary)); 455 endOfWord(wordStart, RightWordIfOnBoundary));
457 markMisspellingsAndBadGrammar(adjacentWords); 456 markMisspellingsAndBadGrammar(adjacentWords);
458 } 457 }
459 458
460 bool SpellChecker::isSpellCheckingEnabledInFocusedNode() const { 459 bool SpellChecker::isSpellCheckingEnabledInFocusedNode() const {
461 Node* focusedNode = frame().selection().start().anchorNode(); 460 Node* focusedNode = frame().selection().start().anchorNode();
462 if (!focusedNode) 461 if (!focusedNode)
463 return false; 462 return false;
464 const Element* focusedElement = focusedNode->isElementNode() 463 const Element* focusedElement = focusedNode->isElementNode()
465 ? toElement(focusedNode) 464 ? toElement(focusedNode)
466 : focusedNode->parentElement(); 465 : focusedNode->parentElement();
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
790 if (markers.size() < 1 || 789 if (markers.size() < 1 ||
791 markers[0]->startOffset() >= markers[0]->endOffset()) 790 markers[0]->startOffset() >= markers[0]->endOffset())
792 return; 791 return;
793 EphemeralRange markerRange = 792 EphemeralRange markerRange =
794 EphemeralRange(Position(caretRange.startPosition().computeContainerNode(), 793 EphemeralRange(Position(caretRange.startPosition().computeContainerNode(),
795 markers[0]->startOffset()), 794 markers[0]->startOffset()),
796 Position(caretRange.endPosition().computeContainerNode(), 795 Position(caretRange.endPosition().computeContainerNode(),
797 markers[0]->endOffset())); 796 markers[0]->endOffset()));
798 if (markerRange.isNull()) 797 if (markerRange.isNull())
799 return; 798 return;
800 frame().selection().setSelection( 799 frame().selection().setSelection(createVisibleSelection(markerRange),
801 createVisibleSelectionDeprecated(markerRange), CharacterGranularity); 800 CharacterGranularity);
802 801
803 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets 802 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets
804 // needs to be audited. See http://crbug.com/590369 for more details. 803 // needs to be audited. See http://crbug.com/590369 for more details.
805 frame().document()->updateStyleAndLayoutIgnorePendingStylesheets(); 804 frame().document()->updateStyleAndLayoutIgnorePendingStylesheets();
806 805
807 frame().editor().replaceSelectionWithText(text, false, false); 806 frame().editor().replaceSelectionWithText(text, false, false);
808 } 807 }
809 808
810 static bool shouldCheckOldSelection(const VisibleSelection& oldSelection) { 809 static bool shouldCheckOldSelection(const VisibleSelection& oldSelection) {
811 if (!oldSelection.start().isConnected()) 810 if (!oldSelection.start().isConnected())
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
859 if (isSelectionInTextFormControl(newSelection)) { 858 if (isSelectionInTextFormControl(newSelection)) {
860 const Position newStart = newSelection.start(); 859 const Position newStart = newSelection.start();
861 newAdjacentWords.setWithoutValidation( 860 newAdjacentWords.setWithoutValidation(
862 HTMLTextFormControlElement::startOfWord(newStart), 861 HTMLTextFormControlElement::startOfWord(newStart),
863 HTMLTextFormControlElement::endOfWord(newStart)); 862 HTMLTextFormControlElement::endOfWord(newStart));
864 } else { 863 } else {
865 const bool caretBrowsing = 864 const bool caretBrowsing =
866 frame().settings() && frame().settings()->caretBrowsingEnabled(); 865 frame().settings() && frame().settings()->caretBrowsingEnabled();
867 if (newSelection.isContentEditable() || caretBrowsing) { 866 if (newSelection.isContentEditable() || caretBrowsing) {
868 const VisiblePosition newStart(newSelection.visibleStart()); 867 const VisiblePosition newStart(newSelection.visibleStart());
869 newAdjacentWords = createVisibleSelectionDeprecated( 868 newAdjacentWords =
870 startOfWord(newStart, LeftWordIfOnBoundary), 869 createVisibleSelection(startOfWord(newStart, LeftWordIfOnBoundary),
871 endOfWord(newStart, RightWordIfOnBoundary)); 870 endOfWord(newStart, RightWordIfOnBoundary));
872 } 871 }
873 } 872 }
874 873
875 // When typing we check spelling elsewhere, so don't redo it here. 874 // When typing we check spelling elsewhere, so don't redo it here.
876 // If this is a change in selection resulting from a delete operation, 875 // If this is a change in selection resulting from a delete operation,
877 // oldSelection may no longer be in the document. 876 // oldSelection may no longer be in the document.
878 // FIXME(http://crbug.com/382809): if oldSelection is on a textarea 877 // FIXME(http://crbug.com/382809): if oldSelection is on a textarea
879 // element, we cause synchronous layout. 878 // element, we cause synchronous layout.
880 spellCheckOldSelection(oldSelection, newAdjacentWords); 879 spellCheckOldSelection(oldSelection, newAdjacentWords);
881 } 880 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
918 917
919 void SpellChecker::spellCheckOldSelection( 918 void SpellChecker::spellCheckOldSelection(
920 const VisibleSelection& oldSelection, 919 const VisibleSelection& oldSelection,
921 const VisibleSelection& newAdjacentWords) { 920 const VisibleSelection& newAdjacentWords) {
922 if (!isSpellCheckingEnabled()) 921 if (!isSpellCheckingEnabled())
923 return; 922 return;
924 923
925 TRACE_EVENT0("blink", "SpellChecker::spellCheckOldSelection"); 924 TRACE_EVENT0("blink", "SpellChecker::spellCheckOldSelection");
926 925
927 VisiblePosition oldStart(oldSelection.visibleStart()); 926 VisiblePosition oldStart(oldSelection.visibleStart());
928 VisibleSelection oldAdjacentWords = createVisibleSelectionDeprecated( 927 VisibleSelection oldAdjacentWords =
929 startOfWord(oldStart, LeftWordIfOnBoundary), 928 createVisibleSelection(startOfWord(oldStart, LeftWordIfOnBoundary),
930 endOfWord(oldStart, RightWordIfOnBoundary)); 929 endOfWord(oldStart, RightWordIfOnBoundary));
931 if (oldAdjacentWords == newAdjacentWords) 930 if (oldAdjacentWords == newAdjacentWords)
932 return; 931 return;
933 markMisspellingsAndBadGrammar(oldAdjacentWords); 932 markMisspellingsAndBadGrammar(oldAdjacentWords);
934 } 933 }
935 934
936 static Node* findFirstMarkable(Node* node) { 935 static Node* findFirstMarkable(Node* node) {
937 while (node) { 936 while (node) {
938 if (!node->layoutObject()) 937 if (!node->layoutObject())
939 return 0; 938 return 0;
940 if (node->layoutObject()->isText()) 939 if (node->layoutObject()->isText())
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
1124 startOfNextParagraph(createVisiblePosition(paragraphEnd)); 1123 startOfNextParagraph(createVisiblePosition(paragraphEnd));
1125 paragraphStart = newParagraphStart.toParentAnchoredPosition(); 1124 paragraphStart = newParagraphStart.toParentAnchoredPosition();
1126 paragraphEnd = endOfParagraph(newParagraphStart).toParentAnchoredPosition(); 1125 paragraphEnd = endOfParagraph(newParagraphStart).toParentAnchoredPosition();
1127 firstIteration = false; 1126 firstIteration = false;
1128 totalLengthProcessed += currentLength; 1127 totalLengthProcessed += currentLength;
1129 } 1128 }
1130 return std::make_pair(firstFoundItem, firstFoundOffset); 1129 return std::make_pair(firstFoundItem, firstFoundOffset);
1131 } 1130 }
1132 1131
1133 } // namespace blink 1132 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698