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

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

Issue 2092063002: Make SpellChecker::respondToChangedSelection() to update layout tree explicitly (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 2016-06-27T12:44:31 Created 4 years, 5 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 | « third_party/WebKit/LayoutTests/TestExpectations ('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 758 matching lines...) Expand 10 before | Expand all | Expand 10 after
769 DocumentMarkerVector markers = frame().document()->markers().markersInRange( caretRange, DocumentMarker::MisspellingMarkers()); 769 DocumentMarkerVector markers = frame().document()->markers().markersInRange( caretRange, DocumentMarker::MisspellingMarkers());
770 if (markers.size() < 1 || markers[0]->startOffset() >= markers[0]->endOffset ()) 770 if (markers.size() < 1 || markers[0]->startOffset() >= markers[0]->endOffset ())
771 return; 771 return;
772 EphemeralRange markerRange = EphemeralRange(Position(caretRange.startPositio n().computeContainerNode(), markers[0]->startOffset()), Position(caretRange.endP osition().computeContainerNode(), markers[0]->endOffset())); 772 EphemeralRange markerRange = EphemeralRange(Position(caretRange.startPositio n().computeContainerNode(), markers[0]->startOffset()), Position(caretRange.endP osition().computeContainerNode(), markers[0]->endOffset()));
773 if (markerRange.isNull()) 773 if (markerRange.isNull())
774 return; 774 return;
775 frame().selection().setSelection(VisibleSelection(markerRange), CharacterGra nularity); 775 frame().selection().setSelection(VisibleSelection(markerRange), CharacterGra nularity);
776 frame().editor().replaceSelectionWithText(text, false, false); 776 frame().editor().replaceSelectionWithText(text, false, false);
777 } 777 }
778 778
779 static bool shouldCheckOldSelection(const VisibleSelection& oldSelection)
780 {
781 if (!oldSelection.start().inShadowIncludingDocument())
782 return false;
783 if (isSelectionInTextField(oldSelection))
784 return false;
785 if (isSelectionInTextArea(oldSelection))
786 return true;
787 oldSelection.start().document()->updateStyleAndLayoutIgnorePendingStylesheet s();
788 return oldSelection.isContentEditable();
789 }
790
779 void SpellChecker::respondToChangedSelection(const VisibleSelection& oldSelectio n, FrameSelection::SetSelectionOptions options) 791 void SpellChecker::respondToChangedSelection(const VisibleSelection& oldSelectio n, FrameSelection::SetSelectionOptions options)
780 { 792 {
781 TRACE_EVENT0("blink", "SpellChecker::respondToChangedSelection"); 793 TRACE_EVENT0("blink", "SpellChecker::respondToChangedSelection");
782 if (!isSpellCheckingEnabledFor(oldSelection)) 794 if (!isSpellCheckingEnabledFor(oldSelection))
783 return; 795 return;
784 796
785 bool closeTyping = options & FrameSelection::CloseTyping; 797 bool closeTyping = options & FrameSelection::CloseTyping;
786 bool isContinuousSpellCheckingEnabled = this->isContinuousSpellCheckingEnabl ed(); 798 bool isContinuousSpellCheckingEnabled = this->isContinuousSpellCheckingEnabl ed();
787 bool isContinuousGrammarCheckingEnabled = isContinuousSpellCheckingEnabled; 799 bool isContinuousGrammarCheckingEnabled = isContinuousSpellCheckingEnabled;
788 if (isContinuousSpellCheckingEnabled) { 800 if (isContinuousSpellCheckingEnabled && closeTyping && shouldCheckOldSelecti on(oldSelection)) {
789 VisibleSelection newAdjacentWords; 801 VisibleSelection newAdjacentWords;
790 bool caretBrowsing = frame().settings() && frame().settings()->caretBrow singEnabled(); 802 bool caretBrowsing = frame().settings() && frame().settings()->caretBrow singEnabled();
791 const VisibleSelection newSelection = frame().selection().selection(); 803 const VisibleSelection newSelection = frame().selection().selection();
792 if (isSelectionInTextFormControl(newSelection)) { 804 if (isSelectionInTextFormControl(newSelection)) {
793 Position newStart = newSelection.start(); 805 Position newStart = newSelection.start();
794 newAdjacentWords.setWithoutValidation(HTMLTextFormControlElement::st artOfWord(newStart), HTMLTextFormControlElement::endOfWord(newStart)); 806 newAdjacentWords.setWithoutValidation(HTMLTextFormControlElement::st artOfWord(newStart), HTMLTextFormControlElement::endOfWord(newStart));
795 } else if (newSelection.isContentEditable() || caretBrowsing) { 807 } else {
796 VisiblePosition newStart(newSelection.visibleStart()); 808 frame().document()->updateStyleAndLayoutIgnorePendingStylesheets();
797 newAdjacentWords = VisibleSelection(startOfWord(newStart, LeftWordIf OnBoundary), endOfWord(newStart, RightWordIfOnBoundary)); 809 if (newSelection.isContentEditable() || caretBrowsing) {
810 VisiblePosition newStart(newSelection.visibleStart());
811 newAdjacentWords = VisibleSelection(startOfWord(newStart, LeftWo rdIfOnBoundary), endOfWord(newStart, RightWordIfOnBoundary));
812 }
798 } 813 }
799 814
800 // When typing we check spelling elsewhere, so don't redo it here. 815 // When typing we check spelling elsewhere, so don't redo it here.
801 // If this is a change in selection resulting from a delete operation, 816 // If this is a change in selection resulting from a delete operation,
802 // oldSelection may no longer be in the document. 817 // oldSelection may no longer be in the document.
803 // FIXME(http://crbug.com/382809): if oldSelection is on a textarea 818 // FIXME(http://crbug.com/382809): if oldSelection is on a textarea
804 // element, we cause synchronous layout. 819 // element, we cause synchronous layout.
805 if (closeTyping 820 spellCheckOldSelection(oldSelection, newAdjacentWords);
806 && !isSelectionInTextField(oldSelection)
807 && (isSelectionInTextArea(oldSelection) || oldSelection.isContentEdi table())
808 && oldSelection.start().inShadowIncludingDocument()) {
809 spellCheckOldSelection(oldSelection, newAdjacentWords);
810 }
811 } 821 }
812 822
813 // When continuous spell checking is off, existing markers disappear after t he selection changes. 823 // When continuous spell checking is off, existing markers disappear after t he selection changes.
814 if (!isContinuousSpellCheckingEnabled) 824 if (!isContinuousSpellCheckingEnabled)
815 frame().document()->markers().removeMarkers(DocumentMarker::Spelling); 825 frame().document()->markers().removeMarkers(DocumentMarker::Spelling);
816 if (!isContinuousGrammarCheckingEnabled) 826 if (!isContinuousGrammarCheckingEnabled)
817 frame().document()->markers().removeMarkers(DocumentMarker::Grammar); 827 frame().document()->markers().removeMarkers(DocumentMarker::Grammar);
818 } 828 }
819 829
820 void SpellChecker::removeSpellingMarkers() 830 void SpellChecker::removeSpellingMarkers()
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
945 visitor->trace(m_frame); 955 visitor->trace(m_frame);
946 visitor->trace(m_spellCheckRequester); 956 visitor->trace(m_spellCheckRequester);
947 } 957 }
948 958
949 void SpellChecker::prepareForLeakDetection() 959 void SpellChecker::prepareForLeakDetection()
950 { 960 {
951 m_spellCheckRequester->prepareForLeakDetection(); 961 m_spellCheckRequester->prepareForLeakDetection();
952 } 962 }
953 963
954 } // namespace blink 964 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/LayoutTests/TestExpectations ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698