| 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 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 | 166 |
| 167 // TODO(xiaochengh): Deduplicate with SpellChecker::chunkAndMarkAllMisspellings. | 167 // TODO(xiaochengh): Deduplicate with SpellChecker::chunkAndMarkAllMisspellings. |
| 168 void IdleSpellCheckCallback::chunkAndRequestFullCheckingFor( | 168 void IdleSpellCheckCallback::chunkAndRequestFullCheckingFor( |
| 169 const Element& editable) { | 169 const Element& editable) { |
| 170 const EphemeralRange& fullRange = EphemeralRange::rangeOfContents(editable); | 170 const EphemeralRange& fullRange = EphemeralRange::rangeOfContents(editable); |
| 171 const int fullLength = TextIterator::rangeLength(fullRange.startPosition(), | 171 const int fullLength = TextIterator::rangeLength(fullRange.startPosition(), |
| 172 fullRange.endPosition()); | 172 fullRange.endPosition()); |
| 173 | 173 |
| 174 // Check the full content if it is short. | 174 // Check the full content if it is short. |
| 175 if (fullLength <= kColdModeChunkSize) { | 175 if (fullLength <= kColdModeChunkSize) { |
| 176 SpellCheckRequest* fullRequest = SpellCheckRequest::create(fullRange); | 176 spellCheckRequester().requestCheckingFor(fullRange); |
| 177 spellCheckRequester().requestCheckingFor(fullRequest); | |
| 178 return; | 177 return; |
| 179 } | 178 } |
| 180 | 179 |
| 181 // TODO(xiaochengh): Figure out if this is going to cause performance issues. | 180 // TODO(xiaochengh): Figure out if this is going to cause performance issues. |
| 182 // In that case, we need finer-grained control over request generation. | 181 // In that case, we need finer-grained control over request generation. |
| 183 Position chunkStart = fullRange.startPosition(); | 182 Position chunkStart = fullRange.startPosition(); |
| 184 const int chunkLimit = fullLength / kColdModeChunkSize + 1; | 183 const int chunkLimit = fullLength / kColdModeChunkSize + 1; |
| 185 for (int chunkIndex = 0; chunkIndex <= chunkLimit; ++chunkIndex) { | 184 for (int chunkIndex = 0; chunkIndex <= chunkLimit; ++chunkIndex) { |
| 186 const Position& chunkEnd = | 185 const Position& chunkEnd = |
| 187 calculateCharacterSubrange( | 186 calculateCharacterSubrange( |
| 188 EphemeralRange(chunkStart, fullRange.endPosition()), 0, | 187 EphemeralRange(chunkStart, fullRange.endPosition()), 0, |
| 189 kColdModeChunkSize) | 188 kColdModeChunkSize) |
| 190 .endPosition(); | 189 .endPosition(); |
| 191 if (chunkEnd <= chunkStart) | 190 if (chunkEnd <= chunkStart) |
| 192 break; | 191 break; |
| 193 const EphemeralRange chunkRange(chunkStart, chunkEnd); | 192 const EphemeralRange chunkRange(chunkStart, chunkEnd); |
| 194 const EphemeralRange& checkRange = | 193 const EphemeralRange& checkRange = |
| 195 chunkIndex >= 1 ? expandEndToSentenceBoundary(chunkRange) | 194 chunkIndex >= 1 ? expandEndToSentenceBoundary(chunkRange) |
| 196 : expandRangeToSentenceBoundary(chunkRange); | 195 : expandRangeToSentenceBoundary(chunkRange); |
| 197 | 196 |
| 198 SpellCheckRequest* chunkRequest = | 197 spellCheckRequester().requestCheckingFor(checkRange, chunkIndex); |
| 199 SpellCheckRequest::create(checkRange, chunkIndex); | |
| 200 spellCheckRequester().requestCheckingFor(chunkRequest); | |
| 201 | 198 |
| 202 chunkStart = checkRange.endPosition(); | 199 chunkStart = checkRange.endPosition(); |
| 203 } | 200 } |
| 204 } | 201 } |
| 205 | 202 |
| 206 void IdleSpellCheckCallback::coldModeInvocation(IdleDeadline* deadline) { | 203 void IdleSpellCheckCallback::coldModeInvocation(IdleDeadline* deadline) { |
| 207 TRACE_EVENT0("blink", "IdleSpellCheckCallback::coldModeInvocation"); | 204 TRACE_EVENT0("blink", "IdleSpellCheckCallback::coldModeInvocation"); |
| 208 | 205 |
| 209 Node* body = frame().document()->body(); | 206 Node* body = frame().document()->body(); |
| 210 if (!body) { | 207 if (!body) { |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 } | 305 } |
| 309 } | 306 } |
| 310 | 307 |
| 311 void IdleSpellCheckCallback::skipColdModeTimerForTesting() { | 308 void IdleSpellCheckCallback::skipColdModeTimerForTesting() { |
| 312 DCHECK(m_coldModeTimer.isActive()); | 309 DCHECK(m_coldModeTimer.isActive()); |
| 313 m_coldModeTimer.stop(); | 310 m_coldModeTimer.stop(); |
| 314 coldModeTimerFired(&m_coldModeTimer); | 311 coldModeTimerFired(&m_coldModeTimer); |
| 315 } | 312 } |
| 316 | 313 |
| 317 } // namespace blink | 314 } // namespace blink |
| OLD | NEW |