| 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) | |
| 51 : m_requester(0) | 50 : m_requester(0) |
| 52 , m_checkingRange(checkingRange) | 51 , m_checkingRange(checkingRange) |
| 53 , m_paragraphRange(paragraphRange) | 52 , m_paragraphRange(paragraphRange) |
| 54 , m_rootEditableElement(m_checkingRange->startContainer()->rootEditableEleme
nt()) | 53 , m_rootEditableElement(m_checkingRange->startContainer()->rootEditableEleme
nt()) |
| 55 , m_requestData(unrequestedTextCheckingSequence, text, mask, processType, do
cumentMarkersInRange, documentMarkerOffsets) | 54 , m_requestData(unrequestedTextCheckingSequence, text, mask, processType, do
cumentMarkersInRange, documentMarkerOffsets) |
| 56 , m_requestNumber(requestNumber) | |
| 57 { | 55 { |
| 58 } | 56 } |
| 59 | 57 |
| 60 SpellCheckRequest::~SpellCheckRequest() | 58 SpellCheckRequest::~SpellCheckRequest() |
| 61 { | 59 { |
| 62 } | 60 } |
| 63 | 61 |
| 64 // static | 62 // static |
| 65 PassRefPtr<SpellCheckRequest> SpellCheckRequest::create(TextCheckingTypeMask tex
tCheckingOptions, TextCheckingProcessType processType, PassRefPtr<Range> checkin
gRange, PassRefPtr<Range> paragraphRange, int requestNubmer) | 63 PassRefPtr<SpellCheckRequest> SpellCheckRequest::create(TextCheckingTypeMask tex
tCheckingOptions, TextCheckingProcessType processType, PassRefPtr<Range> checkin
gRange, PassRefPtr<Range> paragraphRange) |
| 66 { | 64 { |
| 67 ASSERT(checkingRange); | 65 ASSERT(checkingRange); |
| 68 ASSERT(paragraphRange); | 66 ASSERT(paragraphRange); |
| 69 | 67 |
| 70 String text = checkingRange->text(); | 68 String text = checkingRange->text(); |
| 71 if (!text.length()) | 69 if (!text.length()) |
| 72 return PassRefPtr<SpellCheckRequest>(); | 70 return PassRefPtr<SpellCheckRequest>(); |
| 73 | 71 |
| 74 const Vector<DocumentMarker*>& markers = checkingRange->ownerDocument()->mar
kers()->markersInRange(checkingRange.get(), DocumentMarker::Spelling | DocumentM
arker::Grammar); | 72 const Vector<DocumentMarker*>& markers = checkingRange->ownerDocument()->mar
kers()->markersInRange(checkingRange.get(), DocumentMarker::Spelling | DocumentM
arker::Grammar); |
| 75 Vector<uint32_t> hashes(markers.size()); | 73 Vector<uint32_t> hashes(markers.size()); |
| 76 Vector<unsigned> offsets(markers.size()); | 74 Vector<unsigned> offsets(markers.size()); |
| 77 for (size_t i = 0; i < markers.size(); i++) { | 75 for (size_t i = 0; i < markers.size(); i++) { |
| 78 hashes[i] = markers[i]->hash(); | 76 hashes[i] = markers[i]->hash(); |
| 79 offsets[i] = markers[i]->startOffset(); | 77 offsets[i] = markers[i]->startOffset(); |
| 80 } | 78 } |
| 81 | 79 |
| 82 return adoptRef(new SpellCheckRequest(checkingRange, paragraphRange, text, t
extCheckingOptions, processType, hashes, offsets, requestNubmer)); | 80 return adoptRef(new SpellCheckRequest(checkingRange, paragraphRange, text, t
extCheckingOptions, processType, hashes, offsets)); |
| 83 } | 81 } |
| 84 | 82 |
| 85 const TextCheckingRequestData& SpellCheckRequest::data() const | 83 const TextCheckingRequestData& SpellCheckRequest::data() const |
| 86 { | 84 { |
| 87 return m_requestData; | 85 return m_requestData; |
| 88 } | 86 } |
| 89 | 87 |
| 90 void SpellCheckRequest::didSucceed(const Vector<TextCheckingResult>& results) | 88 void SpellCheckRequest::didSucceed(const Vector<TextCheckingResult>& results) |
| 91 { | 89 { |
| 92 if (!m_requester) | 90 if (!m_requester) |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 ASSERT(!m_processingRequest); | 200 ASSERT(!m_processingRequest); |
| 203 if (!client()) | 201 if (!client()) |
| 204 return; | 202 return; |
| 205 m_processingRequest = request; | 203 m_processingRequest = request; |
| 206 client()->requestCheckingOfString(m_processingRequest); | 204 client()->requestCheckingOfString(m_processingRequest); |
| 207 } | 205 } |
| 208 | 206 |
| 209 void SpellCheckRequester::enqueueRequest(PassRefPtr<SpellCheckRequest> request) | 207 void SpellCheckRequester::enqueueRequest(PassRefPtr<SpellCheckRequest> request) |
| 210 { | 208 { |
| 211 ASSERT(request); | 209 ASSERT(request); |
| 212 bool continuation = false; | |
| 213 if (!m_requestQueue.isEmpty()) { | |
| 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. | |
| 217 continuation = request->rootEditableElement() == lastRequest->rootEditab
leElement() | |
| 218 && request->requestNumber() == lastRequest->requestNumber() + 1; | |
| 219 } | |
| 220 | 210 |
| 221 // Spellcheck requests for chunks of text in the same element should not ove
rwrite each other. | 211 for (RequestQueue::iterator it = m_requestQueue.begin(); it != m_requestQueu
e.end(); ++it) { |
| 222 if (!continuation) { | 212 if (request->rootEditableElement() != (*it)->rootEditableElement()) |
| 223 for (RequestQueue::iterator it = m_requestQueue.begin(); it != m_request
Queue.end(); ++it) { | 213 continue; |
| 224 if (request->rootEditableElement() != (*it)->rootEditableElement()) | |
| 225 continue; | |
| 226 | 214 |
| 227 *it = request; | 215 *it = request; |
| 228 return; | 216 return; |
| 229 } | |
| 230 } | 217 } |
| 231 | 218 |
| 232 m_requestQueue.append(request); | 219 m_requestQueue.append(request); |
| 233 } | 220 } |
| 234 | 221 |
| 235 void SpellCheckRequester::didCheck(int sequence, const Vector<TextCheckingResult
>& results) | 222 void SpellCheckRequester::didCheck(int sequence, const Vector<TextCheckingResult
>& results) |
| 236 { | 223 { |
| 237 ASSERT(m_processingRequest); | 224 ASSERT(m_processingRequest); |
| 238 ASSERT(m_processingRequest->data().sequence() == sequence); | 225 ASSERT(m_processingRequest->data().sequence() == sequence); |
| 239 if (m_processingRequest->data().sequence() != sequence) { | 226 if (m_processingRequest->data().sequence() != sequence) { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 266 didCheck(sequence, results); | 253 didCheck(sequence, results); |
| 267 } | 254 } |
| 268 | 255 |
| 269 void SpellCheckRequester::didCheckCancel(int sequence) | 256 void SpellCheckRequester::didCheckCancel(int sequence) |
| 270 { | 257 { |
| 271 Vector<TextCheckingResult> results; | 258 Vector<TextCheckingResult> results; |
| 272 didCheck(sequence, results); | 259 didCheck(sequence, results); |
| 273 } | 260 } |
| 274 | 261 |
| 275 } // namespace WebCore | 262 } // namespace WebCore |
| OLD | NEW |