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

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

Issue 2785103005: Remove stale spellcheck markers at idle time (Closed)
Patch Set: Created 3 years, 8 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 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "core/editing/spellcheck/HotModeSpellCheckRequester.h" 5 #include "core/editing/spellcheck/HotModeSpellCheckRequester.h"
6 6
7 #include "core/editing/EditingUtilities.h" 7 #include "core/editing/EditingUtilities.h"
8 #include "core/editing/Editor.h" 8 #include "core/editing/Editor.h"
9 #include "core/editing/VisiblePosition.h" 9 #include "core/editing/VisiblePosition.h"
10 #include "core/editing/commands/CompositeEditCommand.h" 10 #include "core/editing/commands/CompositeEditCommand.h"
11 #include "core/editing/commands/TypingCommand.h" 11 #include "core/editing/commands/TypingCommand.h"
12 #include "core/editing/iterators/BackwardsCharacterIterator.h" 12 #include "core/editing/iterators/BackwardsCharacterIterator.h"
13 #include "core/editing/iterators/CharacterIterator.h" 13 #include "core/editing/iterators/CharacterIterator.h"
14 #include "core/editing/markers/DocumentMarkerController.h"
14 #include "core/editing/spellcheck/SpellCheckRequester.h" 15 #include "core/editing/spellcheck/SpellCheckRequester.h"
15 #include "core/editing/spellcheck/SpellChecker.h" 16 #include "core/editing/spellcheck/SpellChecker.h"
16 17
17 namespace blink { 18 namespace blink {
18 19
19 namespace { 20 namespace {
20 21
21 const int kHotModeChunkSize = 1024; 22 const int kHotModeChunkSize = 1024;
22 23
23 bool isInOrAdjacentToWord(const Position& pos) { 24 EphemeralRange adjacentWordIfExists(const Position& pos) {
24 const VisiblePosition& visiblePos = createVisiblePosition(pos); 25 const VisiblePosition& visiblePos = createVisiblePosition(pos);
25 const VisiblePosition& wordStart = previousWordPosition(visiblePos); 26 const VisiblePosition& wordStart = previousWordPosition(visiblePos);
26 if (wordStart.isNull()) 27 if (wordStart.isNull())
27 return false; 28 return EphemeralRange();
28 const VisiblePosition& wordEnd = endOfWord(wordStart); 29 const VisiblePosition& wordEnd = endOfWord(wordStart);
29 if (wordEnd.isNull()) 30 if (wordEnd.isNull())
30 return false; 31 return EphemeralRange();
31 return comparePositions(visiblePos, wordEnd) <= 0; 32 if (comparePositions(visiblePos, wordEnd) > 0)
yosin_UTC9 2017/04/05 01:52:35 nit: We can use |visiblePos > wordEnd|
Xiaocheng 2017/04/05 02:08:33 We can't... error: invalid operands to binary exp
33 return EphemeralRange();
34 return EphemeralRange(wordStart.deepEquivalent(), wordEnd.deepEquivalent());
32 } 35 }
33 36
34 bool isTypingInPartialWord(const Element& editable) { 37 EphemeralRange currentWordIfTypingInPartialWord(const Element& editable) {
35 const LocalFrame& frame = *editable.document().frame(); 38 const LocalFrame& frame = *editable.document().frame();
36 const SelectionInDOMTree& selection = frame.selection().selectionInDOMTree(); 39 const SelectionInDOMTree& selection = frame.selection().selectionInDOMTree();
37 if (!selection.isCaret()) 40 if (!selection.isCaret())
38 return false; 41 return EphemeralRange();
39 if (rootEditableElementOf(selection.base()) != &editable) 42 if (rootEditableElementOf(selection.base()) != &editable)
40 return false; 43 return EphemeralRange();
41 44
42 CompositeEditCommand* typingCommand = 45 CompositeEditCommand* typingCommand =
43 frame.editor().lastTypingCommandIfStillOpenForTyping(); 46 frame.editor().lastTypingCommandIfStillOpenForTyping();
44 if (!typingCommand) 47 if (!typingCommand)
45 return false; 48 return EphemeralRange();
46 if (typingCommand->endingSelection().asSelection() != selection) 49 if (typingCommand->endingSelection().asSelection() != selection)
47 return false; 50 return EphemeralRange();
48 return isInOrAdjacentToWord(selection.base()); 51 return adjacentWordIfExists(selection.base());
49 } 52 }
50 53
51 bool shouldCheckRootEditableInHotMode(const Element& editable, 54 bool isUnderActiveEditing(const Element& editable, const Position& position) {
52 const Position& position) {
53 if (!editable.isSpellCheckingEnabled() && 55 if (!editable.isSpellCheckingEnabled() &&
54 !SpellChecker::isSpellCheckingEnabledAt(position)) 56 !SpellChecker::isSpellCheckingEnabledAt(position))
55 return false; 57 return false;
56 if (editable.visibleBoundsInVisualViewport().isEmpty()) 58 if (editable.visibleBoundsInVisualViewport().isEmpty())
57 return false; 59 return false;
58 // TODO(xiaochengh): Design more aggressive strategies to reduce checking when 60 // TODO(xiaochengh): Design more aggressive strategies to reduce checking when
59 // we are just moving selection around without modifying anything. 61 // we are just moving selection around without modifying anything.
60 return !isTypingInPartialWord(editable); 62 return true;
61 } 63 }
62 64
63 EphemeralRange calculateHotModeCheckingRange(const Element& editable, 65 EphemeralRange calculateHotModeCheckingRange(const Element& editable,
64 const Position& position) { 66 const Position& position) {
65 const EphemeralRange& fullRange = EphemeralRange::rangeOfContents(editable); 67 const EphemeralRange& fullRange = EphemeralRange::rangeOfContents(editable);
66 const int fullLength = TextIterator::rangeLength(fullRange.startPosition(), 68 const int fullLength = TextIterator::rangeLength(fullRange.startPosition(),
67 fullRange.endPosition()); 69 fullRange.endPosition());
68 if (fullLength <= kHotModeChunkSize) 70 if (fullLength <= kHotModeChunkSize)
69 return fullRange; 71 return fullRange;
70 72
(...skipping 21 matching lines...) Expand all
92 94
93 void HotModeSpellCheckRequester::checkSpellingAt(const Position& position) { 95 void HotModeSpellCheckRequester::checkSpellingAt(const Position& position) {
94 const Element* rootEditable = rootEditableElementOf(position); 96 const Element* rootEditable = rootEditableElementOf(position);
95 if (!rootEditable || !rootEditable->isConnected()) 97 if (!rootEditable || !rootEditable->isConnected())
96 return; 98 return;
97 99
98 if (m_processedRootEditables.contains(rootEditable)) 100 if (m_processedRootEditables.contains(rootEditable))
99 return; 101 return;
100 m_processedRootEditables.push_back(rootEditable); 102 m_processedRootEditables.push_back(rootEditable);
101 103
102 if (!shouldCheckRootEditableInHotMode(*rootEditable, position)) 104 if (!isUnderActiveEditing(*rootEditable, position))
103 return; 105 return;
104 106
107 const EphemeralRange& currentWord =
108 currentWordIfTypingInPartialWord(*rootEditable);
109 if (currentWord.isNotNull()) {
110 rootEditable->document().markers().removeMarkers(
111 currentWord, DocumentMarker::MisspellingMarkers(),
112 DocumentMarkerController::RemovePartiallyOverlappingMarker);
113 return;
114 }
115
105 const EphemeralRange& checkingRange = 116 const EphemeralRange& checkingRange =
106 calculateHotModeCheckingRange(*rootEditable, position); 117 calculateHotModeCheckingRange(*rootEditable, position);
107 m_requester->requestCheckingFor(checkingRange); 118 m_requester->requestCheckingFor(checkingRange);
108 } 119 }
109 120
110 } // namespace blink 121 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698