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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 | 60 |
61 DEFINE_TRACE(SpellCheckRequest) | 61 DEFINE_TRACE(SpellCheckRequest) |
62 { | 62 { |
63 visitor->trace(m_requester); | 63 visitor->trace(m_requester); |
64 visitor->trace(m_checkingRange); | 64 visitor->trace(m_checkingRange); |
65 visitor->trace(m_paragraphRange); | 65 visitor->trace(m_paragraphRange); |
66 visitor->trace(m_rootEditableElement); | 66 visitor->trace(m_rootEditableElement); |
67 TextCheckingRequest::trace(visitor); | 67 TextCheckingRequest::trace(visitor); |
68 } | 68 } |
69 | 69 |
| 70 void SpellCheckRequest::dispose() |
| 71 { |
| 72 if (m_checkingRange) |
| 73 m_checkingRange->dispose(); |
| 74 if (m_paragraphRange && m_paragraphRange != m_checkingRange) |
| 75 m_paragraphRange->dispose(); |
| 76 } |
| 77 |
70 // static | 78 // static |
71 PassRefPtrWillBeRawPtr<SpellCheckRequest> SpellCheckRequest::create(TextChecking
TypeMask textCheckingOptions, TextCheckingProcessType processType, PassRefPtrWil
lBeRawPtr<Range> checkingRange, PassRefPtrWillBeRawPtr<Range> paragraphRange, in
t requestNumber) | 79 PassRefPtrWillBeRawPtr<SpellCheckRequest> SpellCheckRequest::create(TextChecking
TypeMask textCheckingOptions, TextCheckingProcessType processType, const Ephemer
alRange& checkingRange, const EphemeralRange& paragraphRange, int requestNumber) |
72 { | 80 { |
73 ASSERT(checkingRange); | 81 String text = plainText(checkingRange, TextIteratorEmitsObjectReplacementCha
racter); |
74 ASSERT(paragraphRange); | 82 if (text.isEmpty()) |
75 | |
76 String text = checkingRange->text(); | |
77 if (!text.length()) | |
78 return nullptr; | 83 return nullptr; |
79 | 84 |
80 const DocumentMarkerVector& markers = checkingRange->ownerDocument().markers
().markersInRange(EphemeralRange(checkingRange.get()), DocumentMarker::SpellChec
kClientMarkers()); | 85 RefPtrWillBeRawPtr<Range> checkingRangeObject = createRange(checkingRange); |
| 86 RefPtrWillBeRawPtr<Range> paragraphRangeObject = nullptr; |
| 87 // Share identical Range objects. |
| 88 if (checkingRange == paragraphRange) |
| 89 paragraphRangeObject = checkingRangeObject; |
| 90 else |
| 91 paragraphRangeObject = createRange(paragraphRange); |
| 92 |
| 93 const DocumentMarkerVector& markers = checkingRangeObject->ownerDocument().m
arkers().markersInRange(checkingRange, DocumentMarker::SpellCheckClientMarkers()
); |
81 Vector<uint32_t> hashes(markers.size()); | 94 Vector<uint32_t> hashes(markers.size()); |
82 Vector<unsigned> offsets(markers.size()); | 95 Vector<unsigned> offsets(markers.size()); |
83 for (size_t i = 0; i < markers.size(); i++) { | 96 for (size_t i = 0; i < markers.size(); ++i) { |
84 hashes[i] = markers[i]->hash(); | 97 hashes[i] = markers[i]->hash(); |
85 offsets[i] = markers[i]->startOffset(); | 98 offsets[i] = markers[i]->startOffset(); |
86 } | 99 } |
87 | 100 |
88 return adoptRefWillBeNoop(new SpellCheckRequest(checkingRange, paragraphRang
e, text, textCheckingOptions, processType, hashes, offsets, requestNumber)); | 101 return adoptRefWillBeNoop(new SpellCheckRequest(checkingRangeObject, paragra
phRangeObject, text, textCheckingOptions, processType, hashes, offsets, requestN
umber)); |
89 } | 102 } |
90 | 103 |
91 const TextCheckingRequestData& SpellCheckRequest::data() const | 104 const TextCheckingRequestData& SpellCheckRequest::data() const |
92 { | 105 { |
93 return m_requestData; | 106 return m_requestData; |
94 } | 107 } |
95 | 108 |
96 void SpellCheckRequest::didSucceed(const Vector<TextCheckingResult>& results) | 109 void SpellCheckRequest::didSucceed(const Vector<TextCheckingResult>& results) |
97 { | 110 { |
98 if (!m_requester) | 111 if (!m_requester) |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 | 219 |
207 void SpellCheckRequester::invokeRequest(PassRefPtrWillBeRawPtr<SpellCheckRequest
> request) | 220 void SpellCheckRequester::invokeRequest(PassRefPtrWillBeRawPtr<SpellCheckRequest
> request) |
208 { | 221 { |
209 ASSERT(!m_processingRequest); | 222 ASSERT(!m_processingRequest); |
210 m_processingRequest = request; | 223 m_processingRequest = request; |
211 client().requestCheckingOfString(m_processingRequest); | 224 client().requestCheckingOfString(m_processingRequest); |
212 } | 225 } |
213 | 226 |
214 void SpellCheckRequester::clearProcessingRequest() | 227 void SpellCheckRequester::clearProcessingRequest() |
215 { | 228 { |
216 // This assumes that m_processingRequest's Ranges aren't shared. | 229 if (!m_processingRequest) |
217 if (m_processingRequest->checkingRange()) | 230 return; |
218 m_processingRequest->checkingRange()->dispose(); | |
219 if (m_processingRequest->paragraphRange()) | |
220 m_processingRequest->paragraphRange()->dispose(); | |
221 | 231 |
| 232 m_processingRequest->dispose(); |
222 m_processingRequest.clear(); | 233 m_processingRequest.clear(); |
223 } | 234 } |
224 | 235 |
225 void SpellCheckRequester::enqueueRequest(PassRefPtrWillBeRawPtr<SpellCheckReques
t> request) | 236 void SpellCheckRequester::enqueueRequest(PassRefPtrWillBeRawPtr<SpellCheckReques
t> request) |
226 { | 237 { |
227 ASSERT(request); | 238 ASSERT(request); |
228 bool continuation = false; | 239 bool continuation = false; |
229 if (!m_requestQueue.isEmpty()) { | 240 if (!m_requestQueue.isEmpty()) { |
230 RefPtrWillBeRawPtr<SpellCheckRequest> lastRequest = m_requestQueue.last(
); | 241 RefPtrWillBeRawPtr<SpellCheckRequest> lastRequest = m_requestQueue.last(
); |
231 // It's a continuation if the number of the last request got incremented
in the new one and | 242 // It's a continuation if the number of the last request got incremented
in the new one and |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 } | 300 } |
290 | 301 |
291 DEFINE_TRACE(SpellCheckRequester) | 302 DEFINE_TRACE(SpellCheckRequester) |
292 { | 303 { |
293 visitor->trace(m_frame); | 304 visitor->trace(m_frame); |
294 visitor->trace(m_processingRequest); | 305 visitor->trace(m_processingRequest); |
295 visitor->trace(m_requestQueue); | 306 visitor->trace(m_requestQueue); |
296 } | 307 } |
297 | 308 |
298 } // namespace blink | 309 } // namespace blink |
OLD | NEW |