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

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

Issue 2101263002: [Editing][CodeHealth] Refactor SpellChecker::respondToChangedSelection (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: update 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 | « 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 778 matching lines...) Expand 10 before | Expand all | Expand 10 after
789 oldSelection.start().document()->updateStyleAndLayoutIgnorePendingStylesheet s(); 789 oldSelection.start().document()->updateStyleAndLayoutIgnorePendingStylesheet s();
790 return oldSelection.isContentEditable(); 790 return oldSelection.isContentEditable();
791 } 791 }
792 792
793 void SpellChecker::respondToChangedSelection(const VisibleSelection& oldSelectio n, FrameSelection::SetSelectionOptions options) 793 void SpellChecker::respondToChangedSelection(const VisibleSelection& oldSelectio n, FrameSelection::SetSelectionOptions options)
794 { 794 {
795 TRACE_EVENT0("blink", "SpellChecker::respondToChangedSelection"); 795 TRACE_EVENT0("blink", "SpellChecker::respondToChangedSelection");
796 if (!isSpellCheckingEnabledFor(oldSelection)) 796 if (!isSpellCheckingEnabledFor(oldSelection))
797 return; 797 return;
798 798
799 bool closeTyping = options & FrameSelection::CloseTyping; 799 // When continuous spell checking is off, existing markers disappear after t he selection changes.
800 bool isContinuousSpellCheckingEnabled = this->isContinuousSpellCheckingEnabl ed(); 800 if (!this->isContinuousSpellCheckingEnabled()) {
yosin_UTC9 2016/07/01 08:57:09 nit: s/this->// since we don't have local variable
yoichio 2016/07/04 02:23:20 What do you mean?
yosin_UTC9 2016/07/04 04:29:30 Before your patch, L800 has |bool isContinuousSpel
yoichio 2016/07/04 05:00:44 I see. Done.
801 bool isContinuousGrammarCheckingEnabled = isContinuousSpellCheckingEnabled; 801 frame().document()->markers().removeMarkers(DocumentMarker::Spelling);
802 if (isContinuousSpellCheckingEnabled && closeTyping && shouldCheckOldSelecti on(oldSelection)) { 802 frame().document()->markers().removeMarkers(DocumentMarker::Grammar);
803 VisibleSelection newAdjacentWords; 803 return;
804 bool caretBrowsing = frame().settings() && frame().settings()->caretBrow singEnabled();
805 const VisibleSelection newSelection = frame().selection().selection();
806 if (isSelectionInTextFormControl(newSelection)) {
807 Position newStart = newSelection.start();
808 newAdjacentWords.setWithoutValidation(HTMLTextFormControlElement::st artOfWord(newStart), HTMLTextFormControlElement::endOfWord(newStart));
809 } else {
810 frame().document()->updateStyleAndLayoutIgnorePendingStylesheets();
811 if (newSelection.isContentEditable() || caretBrowsing) {
812 VisiblePosition newStart(newSelection.visibleStart());
813 newAdjacentWords = VisibleSelection(startOfWord(newStart, LeftWo rdIfOnBoundary), endOfWord(newStart, RightWordIfOnBoundary));
814 }
815 }
816
817 // When typing we check spelling elsewhere, so don't redo it here.
818 // If this is a change in selection resulting from a delete operation,
819 // oldSelection may no longer be in the document.
820 // FIXME(http://crbug.com/382809): if oldSelection is on a textarea
821 // element, we cause synchronous layout.
822 spellCheckOldSelection(oldSelection, newAdjacentWords);
823 } 804 }
824 805
825 // When continuous spell checking is off, existing markers disappear after t he selection changes. 806 if (!(options & FrameSelection::CloseTyping))
826 if (!isContinuousSpellCheckingEnabled) 807 return;
827 frame().document()->markers().removeMarkers(DocumentMarker::Spelling); 808 if (!shouldCheckOldSelection(oldSelection))
828 if (!isContinuousGrammarCheckingEnabled) 809 return;
829 frame().document()->markers().removeMarkers(DocumentMarker::Grammar); 810
811 VisibleSelection newAdjacentWords;
812 const VisibleSelection newSelection = frame().selection().selection();
813 if (isSelectionInTextFormControl(newSelection)) {
814 const Position newStart = newSelection.start();
815 newAdjacentWords.setWithoutValidation(HTMLTextFormControlElement::startO fWord(newStart), HTMLTextFormControlElement::endOfWord(newStart));
816 } else {
817 frame().document()->updateStyleAndLayoutIgnorePendingStylesheets();
818 const bool caretBrowsing = frame().settings() && frame().settings()->car etBrowsingEnabled();
819 if (newSelection.isContentEditable() || caretBrowsing) {
820 const VisiblePosition newStart(newSelection.visibleStart());
821 newAdjacentWords = VisibleSelection(startOfWord(newStart, LeftWordIf OnBoundary), endOfWord(newStart, RightWordIfOnBoundary));
822 }
823 }
824
825 // When typing we check spelling elsewhere, so don't redo it here.
826 // If this is a change in selection resulting from a delete operation,
827 // oldSelection may no longer be in the document.
828 // FIXME(http://crbug.com/382809): if oldSelection is on a textarea
829 // element, we cause synchronous layout.
830 spellCheckOldSelection(oldSelection, newAdjacentWords);
830 } 831 }
831 832
832 void SpellChecker::removeSpellingMarkers() 833 void SpellChecker::removeSpellingMarkers()
833 { 834 {
834 frame().document()->markers().removeMarkers(DocumentMarker::MisspellingMarke rs()); 835 frame().document()->markers().removeMarkers(DocumentMarker::MisspellingMarke rs());
835 } 836 }
836 837
837 void SpellChecker::removeSpellingMarkersUnderWords(const Vector<String>& words) 838 void SpellChecker::removeSpellingMarkersUnderWords(const Vector<String>& words)
838 { 839 {
839 MarkerRemoverPredicate removerPredicate(words); 840 MarkerRemoverPredicate removerPredicate(words);
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
957 visitor->trace(m_frame); 958 visitor->trace(m_frame);
958 visitor->trace(m_spellCheckRequester); 959 visitor->trace(m_spellCheckRequester);
959 } 960 }
960 961
961 void SpellChecker::prepareForLeakDetection() 962 void SpellChecker::prepareForLeakDetection()
962 { 963 {
963 m_spellCheckRequester->prepareForLeakDetection(); 964 m_spellCheckRequester->prepareForLeakDetection();
964 } 965 }
965 966
966 } // namespace blink 967 } // 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