OLD | NEW |
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/Editor.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 | 27 |
28 namespace { | 28 namespace { |
29 | 29 |
30 const int kColdModeTimerIntervalMS = 1000; | 30 const int kColdModeTimerIntervalMS = 1000; |
31 const int kConsecutiveColdModeTimerIntervalMS = 200; | 31 const int kConsecutiveColdModeTimerIntervalMS = 200; |
32 const int kHotModeRequestTimeoutMS = 200; | 32 const int kHotModeRequestTimeoutMS = 200; |
33 const int kInvalidHandle = -1; | 33 const int kInvalidHandle = -1; |
34 const int kDummyHandleForForcedInvocation = -2; | 34 const int kDummyHandleForForcedInvocation = -2; |
35 const double kForcedInvocationDeadlineSeconds = 10; | 35 const double kForcedInvocationDeadlineSeconds = 10; |
36 | 36 |
| 37 Position CorrectedReferencePosition(const Position& position, |
| 38 const Document& document) { |
| 39 if (!position.IsConnected() || position.GetDocument() != document) |
| 40 return Position(); |
| 41 return CreateVisiblePosition(position).DeepEquivalent(); |
| 42 } |
| 43 |
37 } // namespace | 44 } // namespace |
38 | 45 |
39 IdleSpellCheckCallback::~IdleSpellCheckCallback() {} | 46 IdleSpellCheckCallback::~IdleSpellCheckCallback() {} |
40 | 47 |
41 DEFINE_TRACE(IdleSpellCheckCallback) { | 48 DEFINE_TRACE(IdleSpellCheckCallback) { |
42 visitor->Trace(frame_); | 49 visitor->Trace(frame_); |
43 visitor->Trace(cold_mode_requester_); | 50 visitor->Trace(cold_mode_requester_); |
44 IdleRequestCallback::Trace(visitor); | 51 IdleRequestCallback::Trace(visitor); |
45 SynchronousMutationObserver::Trace(visitor); | 52 SynchronousMutationObserver::Trace(visitor); |
46 } | 53 } |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 | 155 |
149 const uint64_t watermark = last_processed_undo_step_sequence_; | 156 const uint64_t watermark = last_processed_undo_step_sequence_; |
150 for (const UndoStep* step : | 157 for (const UndoStep* step : |
151 GetFrame().GetEditor().GetUndoStack().UndoSteps()) { | 158 GetFrame().GetEditor().GetUndoStack().UndoSteps()) { |
152 if (step->SequenceNumber() <= watermark) | 159 if (step->SequenceNumber() <= watermark) |
153 break; | 160 break; |
154 last_processed_undo_step_sequence_ = | 161 last_processed_undo_step_sequence_ = |
155 std::max(step->SequenceNumber(), last_processed_undo_step_sequence_); | 162 std::max(step->SequenceNumber(), last_processed_undo_step_sequence_); |
156 if (deadline->timeRemaining() == 0) | 163 if (deadline->timeRemaining() == 0) |
157 break; | 164 break; |
158 requester.CheckSpellingAt(step->EndingSelection().Extent()); | 165 // The reference position stored in undo stack can be invalid, disconnected |
| 166 // or have been moved to another document, in which case it should be |
| 167 // corrected. |
| 168 const Position& stored_position = step->EndingSelection().Extent(); |
| 169 const Position& corrected_position = |
| 170 CorrectedReferencePosition(stored_position, *GetFrame().GetDocument()); |
| 171 requester.CheckSpellingAt(corrected_position); |
159 } | 172 } |
160 } | 173 } |
161 | 174 |
162 void IdleSpellCheckCallback::handleEvent(IdleDeadline* deadline) { | 175 void IdleSpellCheckCallback::handleEvent(IdleDeadline* deadline) { |
163 DCHECK(RuntimeEnabledFeatures::idleTimeSpellCheckingEnabled()); | 176 DCHECK(RuntimeEnabledFeatures::idleTimeSpellCheckingEnabled()); |
164 DCHECK(GetFrame().GetDocument()); | 177 DCHECK(GetFrame().GetDocument()); |
165 DCHECK(GetFrame().GetDocument()->IsActive()); | 178 DCHECK(GetFrame().GetDocument()->IsActive()); |
166 DCHECK_NE(idle_callback_handle_, kInvalidHandle); | 179 DCHECK_NE(idle_callback_handle_, kInvalidHandle); |
167 idle_callback_handle_ = kInvalidHandle; | 180 idle_callback_handle_ = kInvalidHandle; |
168 | 181 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 DCHECK(cold_mode_timer_.IsActive()); | 241 DCHECK(cold_mode_timer_.IsActive()); |
229 cold_mode_timer_.Stop(); | 242 cold_mode_timer_.Stop(); |
230 ColdModeTimerFired(&cold_mode_timer_); | 243 ColdModeTimerFired(&cold_mode_timer_); |
231 } | 244 } |
232 | 245 |
233 void IdleSpellCheckCallback::SetNeedsMoreColdModeInvocationForTesting() { | 246 void IdleSpellCheckCallback::SetNeedsMoreColdModeInvocationForTesting() { |
234 cold_mode_requester_->SetNeedsMoreInvocationForTesting(); | 247 cold_mode_requester_->SetNeedsMoreInvocationForTesting(); |
235 } | 248 } |
236 | 249 |
237 } // namespace blink | 250 } // namespace blink |
OLD | NEW |