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

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

Issue 2297503002: Fix usage of DocumentLifecycle::DisallowTransitionScope (Closed)
Patch Set: Add missing layout update Created 4 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
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 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 { 170 {
171 if (!isSpellCheckingEnabled()) 171 if (!isSpellCheckingEnabled())
172 return; 172 return;
173 173
174 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets 174 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets
175 // needs to be audited. See http://crbug.com/590369 for more details. 175 // needs to be audited. See http://crbug.com/590369 for more details.
176 // In the long term we should use idle time spell checker to prevent 176 // In the long term we should use idle time spell checker to prevent
177 // synchronous layout caused by spell checking (see crbug.com/517298). 177 // synchronous layout caused by spell checking (see crbug.com/517298).
178 frame().document()->updateStyleAndLayoutIgnorePendingStylesheets(); 178 frame().document()->updateStyleAndLayoutIgnorePendingStylesheets();
179 179
180 DocumentLifecycle::DisallowTransitionScope(frame().document()->lifecycle()); 180 DocumentLifecycle::DisallowTransitionScope disallowTransition(frame().docume nt()->lifecycle());
181 181
182 bool isTextField = false; 182 bool isTextField = false;
183 HTMLTextFormControlElement* enclosingHTMLTextFormControlElement = 0; 183 HTMLTextFormControlElement* enclosingHTMLTextFormControlElement = 0;
184 if (!isHTMLTextFormControlElement(*element)) 184 if (!isHTMLTextFormControlElement(*element))
185 enclosingHTMLTextFormControlElement = enclosingTextFormControl(Position: :firstPositionInNode(element)); 185 enclosingHTMLTextFormControlElement = enclosingTextFormControl(Position: :firstPositionInNode(element));
186 element = enclosingHTMLTextFormControlElement ? enclosingHTMLTextFormControl Element : element; 186 element = enclosingHTMLTextFormControlElement ? enclosingHTMLTextFormControl Element : element;
187 Element* parent = element; 187 Element* parent = element;
188 if (isHTMLTextFormControlElement(*element)) { 188 if (isHTMLTextFormControlElement(*element)) {
189 HTMLTextFormControlElement* textControl = toHTMLTextFormControlElement(e lement); 189 HTMLTextFormControlElement* textControl = toHTMLTextFormControlElement(e lement);
190 parent = textControl; 190 parent = textControl;
(...skipping 14 matching lines...) Expand all
205 } 205 }
206 } 206 }
207 207
208 void SpellChecker::ignoreSpelling() 208 void SpellChecker::ignoreSpelling()
209 { 209 {
210 removeMarkers(frame().selection().selection(), DocumentMarker::Spelling); 210 removeMarkers(frame().selection().selection(), DocumentMarker::Spelling);
211 } 211 }
212 212
213 void SpellChecker::advanceToNextMisspelling(bool startBeforeSelection) 213 void SpellChecker::advanceToNextMisspelling(bool startBeforeSelection)
214 { 214 {
215 DocumentLifecycle::DisallowTransitionScope(frame().document()->lifecycle()); 215 DocumentLifecycle::DisallowTransitionScope disallowTransition(frame().docume nt()->lifecycle());
216 216
217 // The basic approach is to search in two phases - from the selection end to the end of the doc, and 217 // The basic approach is to search in two phases - from the selection end to the end of the doc, and
218 // then we wrap and search from the doc start to (approximately) where we st arted. 218 // then we wrap and search from the doc start to (approximately) where we st arted.
219 219
220 // Start at the end of the selection, search to edge of document. Starting a t the selection end makes 220 // Start at the end of the selection, search to edge of document. Starting a t the selection end makes
221 // repeated "check spelling" commands work. 221 // repeated "check spelling" commands work.
222 VisibleSelection selection(frame().selection().selection()); 222 VisibleSelection selection(frame().selection().selection());
223 Position spellingSearchStart, spellingSearchEnd; 223 Position spellingSearchStart, spellingSearchEnd;
224 Range::selectNodeContents(frame().document(), spellingSearchStart, spellingS earchEnd); 224 Range::selectNodeContents(frame().document(), spellingSearchStart, spellingS earchEnd);
225 225
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 } 322 }
323 323
324 void SpellChecker::markMisspellingsAndBadGrammarForMovingParagraphs(const Visibl eSelection& movingSelection) 324 void SpellChecker::markMisspellingsAndBadGrammarForMovingParagraphs(const Visibl eSelection& movingSelection)
325 { 325 {
326 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets 326 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets
327 // needs to be audited. See http://crbug.com/590369 for more details. 327 // needs to be audited. See http://crbug.com/590369 for more details.
328 // In the long term we should use idle time spell checker to prevent 328 // In the long term we should use idle time spell checker to prevent
329 // synchronous layout caused by spell checking (see crbug.com/517298). 329 // synchronous layout caused by spell checking (see crbug.com/517298).
330 frame().document()->updateStyleAndLayoutIgnorePendingStylesheets(); 330 frame().document()->updateStyleAndLayoutIgnorePendingStylesheets();
331 331
332 DocumentLifecycle::DisallowTransitionScope(frame().document()->lifecycle()); 332 DocumentLifecycle::DisallowTransitionScope disallowTransition(frame().docume nt()->lifecycle());
333 333
334 markMisspellingsAndBadGrammar(movingSelection); 334 markMisspellingsAndBadGrammar(movingSelection);
335 } 335 }
336 336
337 void SpellChecker::markMisspellingsAndBadGrammar(const VisibleSelection& selecti on) 337 void SpellChecker::markMisspellingsAndBadGrammar(const VisibleSelection& selecti on)
338 { 338 {
339 if (!isSpellCheckingEnabled() || !isSpellCheckingEnabledFor(selection)) 339 if (!isSpellCheckingEnabled() || !isSpellCheckingEnabledFor(selection))
340 return; 340 return;
341 341
342 const EphemeralRange& range = selection.toNormalizedEphemeralRange(); 342 const EphemeralRange& range = selection.toNormalizedEphemeralRange();
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 TextCheckingParagraph paragraph(request->checkingRange(), request->checkingR ange()); 510 TextCheckingParagraph paragraph(request->checkingRange(), request->checkingR ange());
511 511
512 // Expand the range to encompass entire paragraphs, since text checking need s that much context. 512 // Expand the range to encompass entire paragraphs, since text checking need s that much context.
513 int selectionOffset = 0; 513 int selectionOffset = 0;
514 int ambiguousBoundaryOffset = -1; 514 int ambiguousBoundaryOffset = -1;
515 bool selectionChanged = false; 515 bool selectionChanged = false;
516 bool restoreSelectionAfterChange = false; 516 bool restoreSelectionAfterChange = false;
517 bool adjustSelectionForParagraphBoundaries = false; 517 bool adjustSelectionForParagraphBoundaries = false;
518 518
519 { 519 {
520 DocumentLifecycle::DisallowTransitionScope(frame().document()->lifecycle ()); 520 DocumentLifecycle::DisallowTransitionScope disallowTransition(frame().do cument()->lifecycle());
521 521
522 if (frame().selection().isCaret()) { 522 if (frame().selection().isCaret()) {
523 // Attempt to save the caret position so we can restore it later if needed 523 // Attempt to save the caret position so we can restore it later if needed
524 Position caretPosition = frame().selection().end(); 524 Position caretPosition = frame().selection().end();
525 selectionOffset = paragraph.offsetTo(caretPosition); 525 selectionOffset = paragraph.offsetTo(caretPosition);
526 restoreSelectionAfterChange = true; 526 restoreSelectionAfterChange = true;
527 if (selectionOffset > 0 && (static_cast<unsigned>(selectionOffset) > paragraph.text().length() || paragraph.textCharAt(selectionOffset - 1) == newli neCharacter)) 527 if (selectionOffset > 0 && (static_cast<unsigned>(selectionOffset) > paragraph.text().length() || paragraph.textCharAt(selectionOffset - 1) == newli neCharacter))
528 adjustSelectionForParagraphBoundaries = true; 528 adjustSelectionForParagraphBoundaries = true;
529 if (selectionOffset > 0 && static_cast<unsigned>(selectionOffset) <= paragraph.text().length() && isAmbiguousBoundaryCharacter(paragraph.textCharAt( selectionOffset - 1))) 529 if (selectionOffset > 0 && static_cast<unsigned>(selectionOffset) <= paragraph.text().length() && isAmbiguousBoundaryCharacter(paragraph.textCharAt( selectionOffset - 1)))
530 ambiguousBoundaryOffset = selectionOffset - 1; 530 ambiguousBoundaryOffset = selectionOffset - 1;
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
726 frame().document()->markers().removeMarkers(DocumentMarker::Spelling); 726 frame().document()->markers().removeMarkers(DocumentMarker::Spelling);
727 frame().document()->markers().removeMarkers(DocumentMarker::Grammar); 727 frame().document()->markers().removeMarkers(DocumentMarker::Grammar);
728 return; 728 return;
729 } 729 }
730 730
731 if (!(options & FrameSelection::CloseTyping)) 731 if (!(options & FrameSelection::CloseTyping))
732 return; 732 return;
733 if (!shouldCheckOldSelection(oldSelection)) 733 if (!shouldCheckOldSelection(oldSelection))
734 return; 734 return;
735 735
736 DocumentLifecycle::DisallowTransitionScope(frame().document()->lifecycle()); 736 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets
737 // needs to be audited. See http://crbug.com/590369 for more details.
738 // In the long term we should use idle time spell checker to prevent
739 // synchronous layout caused by spell checking (see crbug.com/517298).
740 frame().document()->updateStyleAndLayoutIgnorePendingStylesheets();
741
742 DocumentLifecycle::DisallowTransitionScope disallowTransition(frame().docume nt()->lifecycle());
737 743
738 VisibleSelection newAdjacentWords; 744 VisibleSelection newAdjacentWords;
739 const VisibleSelection newSelection = frame().selection().selection(); 745 const VisibleSelection newSelection = frame().selection().selection();
740 if (isSelectionInTextFormControl(newSelection)) { 746 if (isSelectionInTextFormControl(newSelection)) {
741 const Position newStart = newSelection.start(); 747 const Position newStart = newSelection.start();
742 newAdjacentWords.setWithoutValidation(HTMLTextFormControlElement::startO fWord(newStart), HTMLTextFormControlElement::endOfWord(newStart)); 748 newAdjacentWords.setWithoutValidation(HTMLTextFormControlElement::startO fWord(newStart), HTMLTextFormControlElement::endOfWord(newStart));
743 } else { 749 } else {
744 frame().document()->updateStyleAndLayoutIgnorePendingStylesheets();
745 const bool caretBrowsing = frame().settings() && frame().settings()->car etBrowsingEnabled(); 750 const bool caretBrowsing = frame().settings() && frame().settings()->car etBrowsingEnabled();
746 if (newSelection.isContentEditable() || caretBrowsing) { 751 if (newSelection.isContentEditable() || caretBrowsing) {
747 const VisiblePosition newStart(newSelection.visibleStart()); 752 const VisiblePosition newStart(newSelection.visibleStart());
748 newAdjacentWords = VisibleSelection(startOfWord(newStart, LeftWordIf OnBoundary), endOfWord(newStart, RightWordIfOnBoundary)); 753 newAdjacentWords = VisibleSelection(startOfWord(newStart, LeftWordIf OnBoundary), endOfWord(newStart, RightWordIfOnBoundary));
749 } 754 }
750 } 755 }
751 756
752 // When typing we check spelling elsewhere, so don't redo it here. 757 // When typing we check spelling elsewhere, so don't redo it here.
753 // If this is a change in selection resulting from a delete operation, 758 // If this is a change in selection resulting from a delete operation,
754 // oldSelection may no longer be in the document. 759 // oldSelection may no longer be in the document.
(...skipping 25 matching lines...) Expand all
780 // textFieldDidEndEditing() and textFieldDidBeginEditing() handle this. 785 // textFieldDidEndEditing() and textFieldDidBeginEditing() handle this.
781 return; 786 return;
782 } 787 }
783 788
784 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets 789 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets
785 // needs to be audited. See http://crbug.com/590369 for more details. 790 // needs to be audited. See http://crbug.com/590369 for more details.
786 // In the long term we should use idle time spell checker to prevent 791 // In the long term we should use idle time spell checker to prevent
787 // synchronous layout caused by spell checking (see crbug.com/517298). 792 // synchronous layout caused by spell checking (see crbug.com/517298).
788 frame().document()->updateStyleAndLayoutIgnorePendingStylesheets(); 793 frame().document()->updateStyleAndLayoutIgnorePendingStylesheets();
789 794
790 DocumentLifecycle::DisallowTransitionScope(frame().document()->lifecycle()); 795 DocumentLifecycle::DisallowTransitionScope disallowTransition(frame().docume nt()->lifecycle());
791 796
792 VisibleSelection empty; 797 VisibleSelection empty;
793 spellCheckOldSelection(frame().selection().selection(), empty); 798 spellCheckOldSelection(frame().selection().selection(), empty);
794 } 799 }
795 800
796 void SpellChecker::spellCheckOldSelection(const VisibleSelection& oldSelection, const VisibleSelection& newAdjacentWords) 801 void SpellChecker::spellCheckOldSelection(const VisibleSelection& oldSelection, const VisibleSelection& newAdjacentWords)
797 { 802 {
798 if (!isSpellCheckingEnabled()) 803 if (!isSpellCheckingEnabled())
799 return; 804 return;
800 805
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
980 VisiblePosition newParagraphStart = startOfNextParagraph(createVisiblePo sition(paragraphEnd)); 985 VisiblePosition newParagraphStart = startOfNextParagraph(createVisiblePo sition(paragraphEnd));
981 paragraphStart = newParagraphStart.toParentAnchoredPosition(); 986 paragraphStart = newParagraphStart.toParentAnchoredPosition();
982 paragraphEnd = endOfParagraph(newParagraphStart).toParentAnchoredPositio n(); 987 paragraphEnd = endOfParagraph(newParagraphStart).toParentAnchoredPositio n();
983 firstIteration = false; 988 firstIteration = false;
984 totalLengthProcessed += currentLength; 989 totalLengthProcessed += currentLength;
985 } 990 }
986 return std::make_pair(firstFoundItem, firstFoundOffset); 991 return std::make_pair(firstFoundItem, firstFoundOffset);
987 } 992 }
988 993
989 } // namespace blink 994 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698