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

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

Issue 2720193002: Implement hot mode invocation for idle time spell checker (Closed)
Patch Set: style fix Created 3 years, 9 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/Source/core/editing/spellcheck/IdleSpellCheckCallback.h ('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 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/IdleSpellCheckCallback.h" 5 #include "core/editing/spellcheck/IdleSpellCheckCallback.h"
6 6
7 #include "core/dom/IdleRequestOptions.h" 7 #include "core/dom/IdleRequestOptions.h"
8 #include "core/dom/TaskRunnerHelper.h" 8 #include "core/dom/TaskRunnerHelper.h"
9 #include "core/editing/EditingUtilities.h" 9 #include "core/editing/EditingUtilities.h"
10 #include "core/editing/Editor.h"
10 #include "core/editing/FrameSelection.h" 11 #include "core/editing/FrameSelection.h"
11 #include "core/editing/VisibleSelection.h" 12 #include "core/editing/VisibleSelection.h"
12 #include "core/editing/VisibleUnits.h" 13 #include "core/editing/VisibleUnits.h"
13 #include "core/editing/commands/CompositeEditCommand.h" 14 #include "core/editing/commands/UndoStack.h"
14 #include "core/editing/commands/UndoStep.h" 15 #include "core/editing/commands/UndoStep.h"
15 #include "core/editing/iterators/BackwardsCharacterIterator.h" 16 #include "core/editing/spellcheck/HotModeSpellCheckRequester.h"
16 #include "core/editing/iterators/CharacterIterator.h"
17 #include "core/editing/spellcheck/SpellCheckRequester.h" 17 #include "core/editing/spellcheck/SpellCheckRequester.h"
18 #include "core/editing/spellcheck/SpellChecker.h" 18 #include "core/editing/spellcheck/SpellChecker.h"
19 #include "core/frame/FrameView.h"
20 #include "core/frame/LocalFrame.h" 19 #include "core/frame/LocalFrame.h"
21 #include "core/html/TextControlElement.h"
22 #include "core/layout/LayoutObject.h"
23 #include "platform/RuntimeEnabledFeatures.h" 20 #include "platform/RuntimeEnabledFeatures.h"
24 #include "platform/instrumentation/tracing/TraceEvent.h" 21 #include "platform/instrumentation/tracing/TraceEvent.h"
25 #include "wtf/CurrentTime.h" 22 #include "wtf/CurrentTime.h"
26 23
27 namespace blink { 24 namespace blink {
28 25
29 namespace { 26 namespace {
30 27
31 const int kColdModeTimerIntervalMS = 1000; 28 const int kColdModeTimerIntervalMS = 1000;
32 const int kConsecutiveColdModeTimerIntervalMS = 200; 29 const int kConsecutiveColdModeTimerIntervalMS = 200;
(...skipping 14 matching lines...) Expand all
47 44
48 IdleSpellCheckCallback* IdleSpellCheckCallback::create(LocalFrame& frame) { 45 IdleSpellCheckCallback* IdleSpellCheckCallback::create(LocalFrame& frame) {
49 return new IdleSpellCheckCallback(frame); 46 return new IdleSpellCheckCallback(frame);
50 } 47 }
51 48
52 IdleSpellCheckCallback::IdleSpellCheckCallback(LocalFrame& frame) 49 IdleSpellCheckCallback::IdleSpellCheckCallback(LocalFrame& frame)
53 : m_state(State::kInactive), 50 : m_state(State::kInactive),
54 m_idleCallbackHandle(kInvalidHandle), 51 m_idleCallbackHandle(kInvalidHandle),
55 m_needsMoreColdModeInvocationForTesting(false), 52 m_needsMoreColdModeInvocationForTesting(false),
56 m_frame(frame), 53 m_frame(frame),
54 m_lastProcessedUndoStepSequence(0),
57 m_coldModeTimer(TaskRunnerHelper::get(TaskType::UnspecedTimer, &frame), 55 m_coldModeTimer(TaskRunnerHelper::get(TaskType::UnspecedTimer, &frame),
58 this, 56 this,
59 &IdleSpellCheckCallback::coldModeTimerFired) {} 57 &IdleSpellCheckCallback::coldModeTimerFired) {}
60 58
61 SpellCheckRequester& IdleSpellCheckCallback::spellCheckRequester() const { 59 SpellCheckRequester& IdleSpellCheckCallback::spellCheckRequester() const {
62 return frame().spellChecker().spellCheckRequester(); 60 return frame().spellChecker().spellCheckRequester();
63 } 61 }
64 62
65 bool IdleSpellCheckCallback::isSpellCheckingEnabled() const { 63 bool IdleSpellCheckCallback::isSpellCheckingEnabled() const {
66 return frame().spellChecker().isSpellCheckingEnabled(); 64 return frame().spellChecker().isSpellCheckingEnabled();
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 if (!isSpellCheckingEnabled()) { 124 if (!isSpellCheckingEnabled()) {
127 deactivate(); 125 deactivate();
128 return; 126 return;
129 } 127 }
130 128
131 requestInvocation(); 129 requestInvocation();
132 m_state = State::kColdModeRequested; 130 m_state = State::kColdModeRequested;
133 } 131 }
134 132
135 void IdleSpellCheckCallback::hotModeInvocation(IdleDeadline* deadline) { 133 void IdleSpellCheckCallback::hotModeInvocation(IdleDeadline* deadline) {
136 // TODO(xiaochengh): Implementation. 134 TRACE_EVENT0("blink", "IdleSpellCheckCallback::hotModeInvocation");
135
136 // TODO(xiaochengh): Figure out if this has any performance impact.
137 frame().document()->updateStyleAndLayout();
138
139 HotModeSpellCheckRequester requester(spellCheckRequester());
140
141 requester.checkSpellingAt(frame().selection().selectionInDOMTree().extent());
142
143 const uint64_t watermark = m_lastProcessedUndoStepSequence;
144 for (const UndoStep* step : frame().editor().undoStack().undoSteps()) {
145 if (step->sequenceNumber() <= watermark)
146 break;
147 m_lastProcessedUndoStepSequence =
148 std::max(step->sequenceNumber(), m_lastProcessedUndoStepSequence);
149 if (deadline->timeRemaining() == 0)
150 break;
151 requester.checkSpellingAt(step->endingSelection().extent());
152 }
137 } 153 }
138 154
139 void IdleSpellCheckCallback::coldModeInvocation(IdleDeadline* deadline) { 155 void IdleSpellCheckCallback::coldModeInvocation(IdleDeadline* deadline) {
140 // TODO(xiaochengh): Implementation. 156 // TODO(xiaochengh): Implementation.
141 } 157 }
142 158
143 bool IdleSpellCheckCallback::coldModeFinishesFullDocument() const { 159 bool IdleSpellCheckCallback::coldModeFinishesFullDocument() const {
144 if (m_needsMoreColdModeInvocationForTesting) { 160 if (m_needsMoreColdModeInvocationForTesting) {
145 m_needsMoreColdModeInvocationForTesting = false; 161 m_needsMoreColdModeInvocationForTesting = false;
146 return false; 162 return false;
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 } 229 }
214 } 230 }
215 231
216 void IdleSpellCheckCallback::skipColdModeTimerForTesting() { 232 void IdleSpellCheckCallback::skipColdModeTimerForTesting() {
217 DCHECK(m_coldModeTimer.isActive()); 233 DCHECK(m_coldModeTimer.isActive());
218 m_coldModeTimer.stop(); 234 m_coldModeTimer.stop();
219 coldModeTimerFired(&m_coldModeTimer); 235 coldModeTimerFired(&m_coldModeTimer);
220 } 236 }
221 237
222 } // namespace blink 238 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/editing/spellcheck/IdleSpellCheckCallback.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698