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 28 matching lines...) Expand all Loading... | |
| 39 | 39 |
| 40 namespace WebCore { | 40 namespace WebCore { |
| 41 | 41 |
| 42 SpellCheckRequest::SpellCheckRequest( | 42 SpellCheckRequest::SpellCheckRequest( |
| 43 PassRefPtr<Range> checkingRange, | 43 PassRefPtr<Range> checkingRange, |
| 44 PassRefPtr<Range> paragraphRange, | 44 PassRefPtr<Range> paragraphRange, |
| 45 const String& text, | 45 const String& text, |
| 46 TextCheckingTypeMask mask, | 46 TextCheckingTypeMask mask, |
| 47 TextCheckingProcessType processType, | 47 TextCheckingProcessType processType, |
| 48 const Vector<uint32_t>& documentMarkersInRange, | 48 const Vector<uint32_t>& documentMarkersInRange, |
| 49 const Vector<unsigned>& documentMarkerOffsets) | 49 const Vector<unsigned>& documentMarkerOffsets, |
| 50 int requestNumber) | |
| 50 : m_checker(0) | 51 : m_checker(0) |
| 51 , m_checkingRange(checkingRange) | 52 , m_checkingRange(checkingRange) |
| 52 , m_paragraphRange(paragraphRange) | 53 , m_paragraphRange(paragraphRange) |
| 53 , m_rootEditableElement(m_checkingRange->startContainer()->rootEditableEleme nt()) | 54 , m_rootEditableElement(m_checkingRange->startContainer()->rootEditableEleme nt()) |
| 54 , m_requestData(unrequestedTextCheckingSequence, text, mask, processType, do cumentMarkersInRange, documentMarkerOffsets) | 55 , m_requestData(unrequestedTextCheckingSequence, text, mask, processType, do cumentMarkersInRange, documentMarkerOffsets) |
| 56 , m_requestNumber(requestNumber) | |
| 55 { | 57 { |
| 56 } | 58 } |
| 57 | 59 |
| 58 SpellCheckRequest::~SpellCheckRequest() | 60 SpellCheckRequest::~SpellCheckRequest() |
| 59 { | 61 { |
| 60 } | 62 } |
| 61 | 63 |
| 62 // static | 64 // static |
| 63 PassRefPtr<SpellCheckRequest> SpellCheckRequest::create(TextCheckingTypeMask tex tCheckingOptions, TextCheckingProcessType processType, PassRefPtr<Range> checkin gRange, PassRefPtr<Range> paragraphRange) | 65 PassRefPtr<SpellCheckRequest> SpellCheckRequest::create(TextCheckingTypeMask tex tCheckingOptions, TextCheckingProcessType processType, PassRefPtr<Range> checkin gRange, PassRefPtr<Range> paragraphRange, int requestNubmer) |
| 64 { | 66 { |
| 65 ASSERT(checkingRange); | 67 ASSERT(checkingRange); |
| 66 ASSERT(paragraphRange); | 68 ASSERT(paragraphRange); |
| 67 | 69 |
| 68 String text = checkingRange->text(); | 70 String text = checkingRange->text(); |
| 69 if (!text.length()) | 71 if (!text.length()) |
| 70 return PassRefPtr<SpellCheckRequest>(); | 72 return PassRefPtr<SpellCheckRequest>(); |
| 71 | 73 |
| 72 const Vector<DocumentMarker*>& markers = checkingRange->ownerDocument()->mar kers()->markersInRange(checkingRange.get(), DocumentMarker::Spelling | DocumentM arker::Grammar); | 74 const Vector<DocumentMarker*>& markers = checkingRange->ownerDocument()->mar kers()->markersInRange(checkingRange.get(), DocumentMarker::Spelling | DocumentM arker::Grammar); |
| 73 Vector<uint32_t> hashes(markers.size()); | 75 Vector<uint32_t> hashes(markers.size()); |
| 74 Vector<unsigned> offsets(markers.size()); | 76 Vector<unsigned> offsets(markers.size()); |
| 75 for (size_t i = 0; i < markers.size(); i++) { | 77 for (size_t i = 0; i < markers.size(); i++) { |
| 76 hashes[i] = markers[i]->hash(); | 78 hashes[i] = markers[i]->hash(); |
| 77 offsets[i] = markers[i]->startOffset(); | 79 offsets[i] = markers[i]->startOffset(); |
| 78 } | 80 } |
| 79 | 81 |
| 80 return adoptRef(new SpellCheckRequest(checkingRange, paragraphRange, text, t extCheckingOptions, processType, hashes, offsets)); | 82 return adoptRef(new SpellCheckRequest(checkingRange, paragraphRange, text, t extCheckingOptions, processType, hashes, offsets, requestNubmer)); |
| 81 } | 83 } |
| 82 | 84 |
| 83 const TextCheckingRequestData& SpellCheckRequest::data() const | 85 const TextCheckingRequestData& SpellCheckRequest::data() const |
| 84 { | 86 { |
| 85 return m_requestData; | 87 return m_requestData; |
| 86 } | 88 } |
| 87 | 89 |
| 88 void SpellCheckRequest::didSucceed(const Vector<TextCheckingResult>& results) | 90 void SpellCheckRequest::didSucceed(const Vector<TextCheckingResult>& results) |
| 89 { | 91 { |
| 90 if (!m_checker) | 92 if (!m_checker) |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 200 ASSERT(!m_processingRequest); | 202 ASSERT(!m_processingRequest); |
| 201 if (!client()) | 203 if (!client()) |
| 202 return; | 204 return; |
| 203 m_processingRequest = request; | 205 m_processingRequest = request; |
| 204 client()->requestCheckingOfString(m_processingRequest); | 206 client()->requestCheckingOfString(m_processingRequest); |
| 205 } | 207 } |
| 206 | 208 |
| 207 void SpellChecker::enqueueRequest(PassRefPtr<SpellCheckRequest> request) | 209 void SpellChecker::enqueueRequest(PassRefPtr<SpellCheckRequest> request) |
| 208 { | 210 { |
| 209 ASSERT(request); | 211 ASSERT(request); |
| 212 bool continuation = false; | |
| 213 if (m_requestQueue.size() > 0) { | |
| 214 RefPtr<SpellCheckRequest> lastRequest = m_requestQueue.last(); | |
| 215 // It's a continuation if the number of the last request got incremented in the new one and | |
| 216 // both apply to the same editable. | |
|
please use gerrit instead
2013/08/14 17:30:28
Ah, I see what this is doing now. Enqueueing a req
| |
| 217 continuation = request->rootEditableElement() == lastRequest->rootEditab leElement() | |
| 218 && request->requestNumber() == lastRequest->requestNumber() + 1; | |
| 219 } | |
| 210 | 220 |
| 211 for (RequestQueue::iterator it = m_requestQueue.begin(); it != m_requestQueu e.end(); ++it) { | 221 if (!continuation) { |
|
please use gerrit instead
2013/08/14 17:30:28
Nit: Maybe add a comment here:
// Spellcheck requ
pstanek
2013/08/14 17:36:26
Done.
| |
| 212 if (request->rootEditableElement() != (*it)->rootEditableElement()) | 222 for (RequestQueue::iterator it = m_requestQueue.begin(); it != m_request Queue.end(); ++it) { |
| 213 continue; | 223 if (request->rootEditableElement() != (*it)->rootEditableElement()) |
| 224 continue; | |
| 214 | 225 |
| 215 *it = request; | 226 *it = request; |
| 216 return; | 227 return; |
| 228 } | |
| 217 } | 229 } |
| 218 | 230 |
| 219 m_requestQueue.append(request); | 231 m_requestQueue.append(request); |
| 220 } | 232 } |
| 221 | 233 |
| 222 void SpellChecker::didCheck(int sequence, const Vector<TextCheckingResult>& resu lts) | 234 void SpellChecker::didCheck(int sequence, const Vector<TextCheckingResult>& resu lts) |
| 223 { | 235 { |
| 224 ASSERT(m_processingRequest); | 236 ASSERT(m_processingRequest); |
| 225 ASSERT(m_processingRequest->data().sequence() == sequence); | 237 ASSERT(m_processingRequest->data().sequence() == sequence); |
| 226 if (m_processingRequest->data().sequence() != sequence) { | 238 if (m_processingRequest->data().sequence() != sequence) { |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 253 didCheck(sequence, results); | 265 didCheck(sequence, results); |
| 254 } | 266 } |
| 255 | 267 |
| 256 void SpellChecker::didCheckCancel(int sequence) | 268 void SpellChecker::didCheckCancel(int sequence) |
| 257 { | 269 { |
| 258 Vector<TextCheckingResult> results; | 270 Vector<TextCheckingResult> results; |
| 259 didCheck(sequence, results); | 271 didCheck(sequence, results); |
| 260 } | 272 } |
| 261 | 273 |
| 262 } // namespace WebCore | 274 } // namespace WebCore |
| OLD | NEW |