Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 26 #include "core/editing/spellcheck/SpellCheckRequester.h" | 26 #include "core/editing/spellcheck/SpellCheckRequester.h" |
| 27 | 27 |
| 28 #include "core/dom/Document.h" | 28 #include "core/dom/Document.h" |
| 29 #include "core/dom/Node.h" | 29 #include "core/dom/Node.h" |
| 30 #include "core/dom/TaskRunnerHelper.h" | 30 #include "core/dom/TaskRunnerHelper.h" |
| 31 #include "core/editing/EditingUtilities.h" | 31 #include "core/editing/EditingUtilities.h" |
| 32 #include "core/editing/markers/DocumentMarkerController.h" | 32 #include "core/editing/markers/DocumentMarkerController.h" |
| 33 #include "core/editing/spellcheck/SpellChecker.h" | 33 #include "core/editing/spellcheck/SpellChecker.h" |
| 34 #include "core/frame/LocalFrame.h" | 34 #include "core/frame/LocalFrame.h" |
| 35 #include "core/frame/Settings.h" | 35 #include "core/frame/Settings.h" |
| 36 #include "core/html/TextControlElement.h" | |
| 36 #include "platform/text/TextCheckerClient.h" | 37 #include "platform/text/TextCheckerClient.h" |
| 37 | 38 |
| 38 namespace blink { | 39 namespace blink { |
| 39 | 40 |
| 40 SpellCheckRequest::SpellCheckRequest( | 41 SpellCheckRequest::SpellCheckRequest( |
| 41 Range* checkingRange, | 42 Range* checkingRange, |
| 42 const String& text, | 43 const String& text, |
| 43 const Vector<uint32_t>& documentMarkersInRange, | 44 const Vector<uint32_t>& documentMarkersInRange, |
| 44 const Vector<unsigned>& documentMarkerOffsets, | 45 const Vector<unsigned>& documentMarkerOffsets, |
| 45 int requestNumber) | 46 int requestNumber) |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 219 // It's a continuation if the number of the last request got incremented in | 220 // It's a continuation if the number of the last request got incremented in |
| 220 // the new one and both apply to the same editable. | 221 // the new one and both apply to the same editable. |
| 221 continuation = | 222 continuation = |
| 222 request->rootEditableElement() == lastRequest->rootEditableElement() && | 223 request->rootEditableElement() == lastRequest->rootEditableElement() && |
| 223 request->requestNumber() == lastRequest->requestNumber() + 1; | 224 request->requestNumber() == lastRequest->requestNumber() + 1; |
| 224 } | 225 } |
| 225 | 226 |
| 226 // Spellcheck requests for chunks of text in the same element should not | 227 // Spellcheck requests for chunks of text in the same element should not |
| 227 // overwrite each other. | 228 // overwrite each other. |
| 228 if (!continuation) { | 229 if (!continuation) { |
| 229 for (auto& requestQueue : m_requestQueue) { | 230 for (RequestQueue::const_iterator iter = m_requestQueue.begin(); |
|
yosin_UTC9
2017/01/17 08:20:12
Can we use std::find_if()?
Xiaocheng
2017/01/17 08:48:18
Yes.Done.
| |
| 230 if (request->rootEditableElement() != requestQueue->rootEditableElement()) | 231 iter != m_requestQueue.end(); ++iter) { |
| 232 if (request->rootEditableElement() != (*iter)->rootEditableElement()) | |
| 231 continue; | 233 continue; |
| 232 | 234 |
| 233 requestQueue = request; | 235 m_requestQueue.remove(iter); |
| 234 return; | 236 break; |
| 235 } | 237 } |
| 236 } | 238 } |
| 237 | 239 |
| 238 m_requestQueue.append(request); | 240 m_requestQueue.append(request); |
| 239 } | 241 } |
| 240 | 242 |
| 241 void SpellCheckRequester::didCheck(int sequence, | 243 void SpellCheckRequester::didCheck(int sequence, |
| 242 const Vector<TextCheckingResult>& results) { | 244 const Vector<TextCheckingResult>& results) { |
| 243 DCHECK(m_processingRequest); | 245 DCHECK(m_processingRequest); |
| 244 DCHECK_EQ(m_processingRequest->data().sequence(), sequence); | 246 DCHECK_EQ(m_processingRequest->data().sequence(), sequence); |
| 245 if (m_processingRequest->data().sequence() != sequence) { | 247 if (m_processingRequest->data().sequence() != sequence) { |
| 246 m_requestQueue.clear(); | 248 m_requestQueue.clear(); |
| 247 return; | 249 return; |
| 248 } | 250 } |
| 249 | 251 |
| 250 frame().spellChecker().markAndReplaceFor(m_processingRequest, results); | 252 frame().spellChecker().markAndReplaceFor(m_processingRequest, results); |
| 251 | 253 |
| 252 if (m_lastProcessedSequence < sequence) | 254 DCHECK_LT(m_lastProcessedSequence, sequence); |
| 253 m_lastProcessedSequence = sequence; | 255 m_lastProcessedSequence = sequence; |
| 254 | 256 |
| 255 clearProcessingRequest(); | 257 clearProcessingRequest(); |
| 256 if (!m_requestQueue.isEmpty()) | 258 if (!m_requestQueue.isEmpty()) |
| 257 m_timerToProcessQueuedRequest.startOneShot(0, BLINK_FROM_HERE); | 259 m_timerToProcessQueuedRequest.startOneShot(0, BLINK_FROM_HERE); |
| 258 } | 260 } |
| 259 | 261 |
| 260 void SpellCheckRequester::didCheckSucceed( | 262 void SpellCheckRequester::didCheckSucceed( |
| 261 int sequence, | 263 int sequence, |
| 262 const Vector<TextCheckingResult>& results) { | 264 const Vector<TextCheckingResult>& results) { |
| 263 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets | 265 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 282 didCheck(sequence, results); | 284 didCheck(sequence, results); |
| 283 } | 285 } |
| 284 | 286 |
| 285 DEFINE_TRACE(SpellCheckRequester) { | 287 DEFINE_TRACE(SpellCheckRequester) { |
| 286 visitor->trace(m_frame); | 288 visitor->trace(m_frame); |
| 287 visitor->trace(m_processingRequest); | 289 visitor->trace(m_processingRequest); |
| 288 visitor->trace(m_requestQueue); | 290 visitor->trace(m_requestQueue); |
| 289 } | 291 } |
| 290 | 292 |
| 291 } // namespace blink | 293 } // namespace blink |
| OLD | NEW |