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 27 matching lines...) Expand all Loading... | |
| 38 | 38 |
| 39 SpellCheckRequest::SpellCheckRequest( | 39 SpellCheckRequest::SpellCheckRequest( |
| 40 PassRefPtrWillBeRawPtr<Range> checkingRange, | 40 PassRefPtrWillBeRawPtr<Range> checkingRange, |
| 41 PassRefPtrWillBeRawPtr<Range> paragraphRange, | 41 PassRefPtrWillBeRawPtr<Range> paragraphRange, |
| 42 const String& text, | 42 const String& text, |
| 43 TextCheckingTypeMask mask, | 43 TextCheckingTypeMask mask, |
| 44 TextCheckingProcessType processType, | 44 TextCheckingProcessType processType, |
| 45 const Vector<uint32_t>& documentMarkersInRange, | 45 const Vector<uint32_t>& documentMarkersInRange, |
| 46 const Vector<unsigned>& documentMarkerOffsets, | 46 const Vector<unsigned>& documentMarkerOffsets, |
| 47 int requestNumber) | 47 int requestNumber) |
| 48 : m_requester(0) | 48 : m_requester(nullptr) |
| 49 , m_checkingRange(checkingRange) | 49 , m_checkingRange(checkingRange) |
| 50 , m_paragraphRange(paragraphRange) | 50 , m_paragraphRange(paragraphRange) |
| 51 , m_rootEditableElement(m_checkingRange->startContainer()->rootEditableEleme nt()) | 51 , m_rootEditableElement(m_checkingRange->startContainer()->rootEditableEleme nt()) |
| 52 , m_requestData(unrequestedTextCheckingSequence, text, mask, processType, do cumentMarkersInRange, documentMarkerOffsets) | 52 , m_requestData(unrequestedTextCheckingSequence, text, mask, processType, do cumentMarkersInRange, documentMarkerOffsets) |
| 53 , m_requestNumber(requestNumber) | 53 , m_requestNumber(requestNumber) |
| 54 { | 54 { |
| 55 } | 55 } |
| 56 | 56 |
| 57 SpellCheckRequest::~SpellCheckRequest() | 57 SpellCheckRequest::~SpellCheckRequest() |
| 58 { | 58 { |
| 59 } | 59 } |
| 60 | 60 |
| 61 void SpellCheckRequest::trace(Visitor* visitor) | |
| 62 { | |
| 63 visitor->trace(m_requester); | |
| 64 visitor->trace(m_checkingRange); | |
| 65 visitor->trace(m_paragraphRange); | |
| 66 visitor->trace(m_rootEditableElement); | |
| 67 TextCheckingRequest::trace(visitor); | |
| 68 } | |
| 69 | |
| 61 // static | 70 // static |
| 62 PassRefPtr<SpellCheckRequest> SpellCheckRequest::create(TextCheckingTypeMask tex tCheckingOptions, TextCheckingProcessType processType, PassRefPtrWillBeRawPtr<Ra nge> checkingRange, PassRefPtrWillBeRawPtr<Range> paragraphRange, int requestNum ber) | 71 PassRefPtrWillBeRawPtr<SpellCheckRequest> SpellCheckRequest::create(TextChecking TypeMask textCheckingOptions, TextCheckingProcessType processType, PassRefPtrWil lBeRawPtr<Range> checkingRange, PassRefPtrWillBeRawPtr<Range> paragraphRange, in t requestNumber) |
| 63 { | 72 { |
| 64 ASSERT(checkingRange); | 73 ASSERT(checkingRange); |
| 65 ASSERT(paragraphRange); | 74 ASSERT(paragraphRange); |
| 66 | 75 |
| 67 String text = checkingRange->text(); | 76 String text = checkingRange->text(); |
| 68 if (!text.length()) | 77 if (!text.length()) |
| 69 return PassRefPtr<SpellCheckRequest>(); | 78 return PassRefPtrWillBeRawPtr<SpellCheckRequest>(); |
|
haraken
2014/09/08 07:25:57
nullptr
sof
2014/09/08 21:17:45
Simplified.
| |
| 70 | 79 |
| 71 const DocumentMarkerVector& markers = checkingRange->ownerDocument().markers ().markersInRange(checkingRange.get(), DocumentMarker::SpellCheckClientMarkers() ); | 80 const DocumentMarkerVector& markers = checkingRange->ownerDocument().markers ().markersInRange(checkingRange.get(), DocumentMarker::SpellCheckClientMarkers() ); |
| 72 Vector<uint32_t> hashes(markers.size()); | 81 Vector<uint32_t> hashes(markers.size()); |
| 73 Vector<unsigned> offsets(markers.size()); | 82 Vector<unsigned> offsets(markers.size()); |
| 74 for (size_t i = 0; i < markers.size(); i++) { | 83 for (size_t i = 0; i < markers.size(); i++) { |
| 75 hashes[i] = markers[i]->hash(); | 84 hashes[i] = markers[i]->hash(); |
| 76 offsets[i] = markers[i]->startOffset(); | 85 offsets[i] = markers[i]->startOffset(); |
| 77 } | 86 } |
| 78 | 87 |
| 79 return adoptRef(new SpellCheckRequest(checkingRange, paragraphRange, text, t extCheckingOptions, processType, hashes, offsets, requestNumber)); | 88 return adoptRefWillBeNoop(new SpellCheckRequest(checkingRange, paragraphRang e, text, textCheckingOptions, processType, hashes, offsets, requestNumber)); |
| 80 } | 89 } |
| 81 | 90 |
| 82 const TextCheckingRequestData& SpellCheckRequest::data() const | 91 const TextCheckingRequestData& SpellCheckRequest::data() const |
| 83 { | 92 { |
| 84 return m_requestData; | 93 return m_requestData; |
| 85 } | 94 } |
| 86 | 95 |
| 87 void SpellCheckRequest::didSucceed(const Vector<TextCheckingResult>& results) | 96 void SpellCheckRequest::didSucceed(const Vector<TextCheckingResult>& results) |
| 88 { | 97 { |
| 89 if (!m_requester) | 98 if (!m_requester) |
| 90 return; | 99 return; |
| 91 SpellCheckRequester* requester = m_requester; | 100 SpellCheckRequester* requester = m_requester; |
| 92 m_requester = 0; | 101 m_requester = nullptr; |
| 93 requester->didCheckSucceed(m_requestData.sequence(), results); | 102 requester->didCheckSucceed(m_requestData.sequence(), results); |
| 94 } | 103 } |
| 95 | 104 |
| 96 void SpellCheckRequest::didCancel() | 105 void SpellCheckRequest::didCancel() |
| 97 { | 106 { |
| 98 if (!m_requester) | 107 if (!m_requester) |
| 99 return; | 108 return; |
| 100 SpellCheckRequester* requester = m_requester; | 109 SpellCheckRequester* requester = m_requester; |
| 101 m_requester = 0; | 110 m_requester = nullptr; |
| 102 requester->didCheckCancel(m_requestData.sequence()); | 111 requester->didCheckCancel(m_requestData.sequence()); |
| 103 } | 112 } |
| 104 | 113 |
| 105 void SpellCheckRequest::setCheckerAndSequence(SpellCheckRequester* requester, in t sequence) | 114 void SpellCheckRequest::setCheckerAndSequence(SpellCheckRequester* requester, in t sequence) |
| 106 { | 115 { |
| 107 ASSERT(!m_requester); | 116 ASSERT(!m_requester); |
| 108 ASSERT(m_requestData.sequence() == unrequestedTextCheckingSequence); | 117 ASSERT(m_requestData.sequence() == unrequestedTextCheckingSequence); |
| 109 m_requester = requester; | 118 m_requester = requester; |
| 110 m_requestData.m_sequence = sequence; | 119 m_requestData.m_sequence = sequence; |
| 111 } | 120 } |
| 112 | 121 |
| 122 #if !ENABLE(OILPAN) | |
| 113 void SpellCheckRequest::requesterDestroyed() | 123 void SpellCheckRequest::requesterDestroyed() |
| 114 { | 124 { |
| 115 m_requester = 0; | 125 m_requester = nullptr; |
| 116 } | 126 } |
| 127 #endif | |
| 117 | 128 |
| 118 SpellCheckRequester::SpellCheckRequester(LocalFrame& frame) | 129 SpellCheckRequester::SpellCheckRequester(LocalFrame& frame) |
| 119 : m_frame(frame) | 130 : m_frame(&frame) |
| 120 , m_lastRequestSequence(0) | 131 , m_lastRequestSequence(0) |
| 121 , m_lastProcessedSequence(0) | 132 , m_lastProcessedSequence(0) |
| 122 , m_timerToProcessQueuedRequest(this, &SpellCheckRequester::timerFiredToProc essQueuedRequest) | 133 , m_timerToProcessQueuedRequest(this, &SpellCheckRequester::timerFiredToProc essQueuedRequest) |
| 123 { | 134 { |
| 124 } | 135 } |
| 125 | 136 |
| 126 SpellCheckRequester::~SpellCheckRequester() | 137 SpellCheckRequester::~SpellCheckRequester() |
| 127 { | 138 { |
| 139 #if !ENABLE(OILPAN) | |
| 128 if (m_processingRequest) | 140 if (m_processingRequest) |
| 129 m_processingRequest->requesterDestroyed(); | 141 m_processingRequest->requesterDestroyed(); |
| 130 for (RequestQueue::iterator i = m_requestQueue.begin(); i != m_requestQueue. end(); ++i) | 142 for (RequestQueue::iterator i = m_requestQueue.begin(); i != m_requestQueue. end(); ++i) |
| 131 (*i)->requesterDestroyed(); | 143 (*i)->requesterDestroyed(); |
| 144 #endif | |
| 132 } | 145 } |
| 133 | 146 |
| 134 TextCheckerClient& SpellCheckRequester::client() const | 147 TextCheckerClient& SpellCheckRequester::client() const |
| 135 { | 148 { |
| 136 return m_frame.spellChecker().textChecker(); | 149 return m_frame->spellChecker().textChecker(); |
| 137 } | 150 } |
| 138 | 151 |
| 139 void SpellCheckRequester::timerFiredToProcessQueuedRequest(Timer<SpellCheckReque ster>*) | 152 void SpellCheckRequester::timerFiredToProcessQueuedRequest(Timer<SpellCheckReque ster>*) |
| 140 { | 153 { |
| 141 ASSERT(!m_requestQueue.isEmpty()); | 154 ASSERT(!m_requestQueue.isEmpty()); |
| 142 if (m_requestQueue.isEmpty()) | 155 if (m_requestQueue.isEmpty()) |
| 143 return; | 156 return; |
| 144 | 157 |
| 145 invokeRequest(m_requestQueue.takeFirst()); | 158 invokeRequest(m_requestQueue.takeFirst()); |
| 146 } | 159 } |
| 147 | 160 |
| 148 bool SpellCheckRequester::isAsynchronousEnabled() const | 161 bool SpellCheckRequester::isAsynchronousEnabled() const |
| 149 { | 162 { |
| 150 return m_frame.settings() && m_frame.settings()->asynchronousSpellCheckingEn abled(); | 163 return m_frame->settings() && m_frame->settings()->asynchronousSpellChecking Enabled(); |
| 151 } | 164 } |
| 152 | 165 |
| 153 bool SpellCheckRequester::canCheckAsynchronously(Range* range) const | 166 bool SpellCheckRequester::canCheckAsynchronously(Range* range) const |
| 154 { | 167 { |
| 155 return isCheckable(range) && isAsynchronousEnabled(); | 168 return isCheckable(range) && isAsynchronousEnabled(); |
| 156 } | 169 } |
| 157 | 170 |
| 158 bool SpellCheckRequester::isCheckable(Range* range) const | 171 bool SpellCheckRequester::isCheckable(Range* range) const |
| 159 { | 172 { |
| 160 if (!range || !range->firstNode() || !range->firstNode()->renderer()) | 173 if (!range || !range->firstNode() || !range->firstNode()->renderer()) |
| 161 return false; | 174 return false; |
| 162 const Node* node = range->startContainer(); | 175 const Node* node = range->startContainer(); |
| 163 if (node && node->isElementNode() && !toElement(node)->isSpellCheckingEnable d()) | 176 if (node && node->isElementNode() && !toElement(node)->isSpellCheckingEnable d()) |
| 164 return false; | 177 return false; |
| 165 return true; | 178 return true; |
| 166 } | 179 } |
| 167 | 180 |
| 168 void SpellCheckRequester::requestCheckingFor(PassRefPtr<SpellCheckRequest> reque st) | 181 void SpellCheckRequester::requestCheckingFor(PassRefPtrWillBeRawPtr<SpellCheckRe quest> request) |
| 169 { | 182 { |
| 170 if (!request || !canCheckAsynchronously(request->paragraphRange().get())) | 183 if (!request || !canCheckAsynchronously(request->paragraphRange().get())) |
| 171 return; | 184 return; |
| 172 | 185 |
| 173 ASSERT(request->data().sequence() == unrequestedTextCheckingSequence); | 186 ASSERT(request->data().sequence() == unrequestedTextCheckingSequence); |
| 174 int sequence = ++m_lastRequestSequence; | 187 int sequence = ++m_lastRequestSequence; |
| 175 if (sequence == unrequestedTextCheckingSequence) | 188 if (sequence == unrequestedTextCheckingSequence) |
| 176 sequence = ++m_lastRequestSequence; | 189 sequence = ++m_lastRequestSequence; |
| 177 | 190 |
| 178 request->setCheckerAndSequence(this, sequence); | 191 request->setCheckerAndSequence(this, sequence); |
| 179 | 192 |
| 180 if (m_timerToProcessQueuedRequest.isActive() || m_processingRequest) { | 193 if (m_timerToProcessQueuedRequest.isActive() || m_processingRequest) { |
| 181 enqueueRequest(request); | 194 enqueueRequest(request); |
| 182 return; | 195 return; |
| 183 } | 196 } |
| 184 | 197 |
| 185 invokeRequest(request); | 198 invokeRequest(request); |
| 186 } | 199 } |
| 187 | 200 |
| 188 void SpellCheckRequester::cancelCheck() | 201 void SpellCheckRequester::cancelCheck() |
| 189 { | 202 { |
| 190 if (m_processingRequest) | 203 if (m_processingRequest) |
| 191 m_processingRequest->didCancel(); | 204 m_processingRequest->didCancel(); |
| 192 } | 205 } |
| 193 | 206 |
| 194 void SpellCheckRequester::invokeRequest(PassRefPtr<SpellCheckRequest> request) | 207 void SpellCheckRequester::invokeRequest(PassRefPtrWillBeRawPtr<SpellCheckRequest > request) |
| 195 { | 208 { |
| 196 ASSERT(!m_processingRequest); | 209 ASSERT(!m_processingRequest); |
| 197 m_processingRequest = request; | 210 m_processingRequest = request; |
| 198 client().requestCheckingOfString(m_processingRequest); | 211 client().requestCheckingOfString(m_processingRequest); |
| 199 } | 212 } |
| 200 | 213 |
| 201 void SpellCheckRequester::enqueueRequest(PassRefPtr<SpellCheckRequest> request) | 214 void SpellCheckRequester::enqueueRequest(PassRefPtrWillBeRawPtr<SpellCheckReques t> request) |
| 202 { | 215 { |
| 203 ASSERT(request); | 216 ASSERT(request); |
| 204 bool continuation = false; | 217 bool continuation = false; |
| 205 if (!m_requestQueue.isEmpty()) { | 218 if (!m_requestQueue.isEmpty()) { |
| 206 RefPtr<SpellCheckRequest> lastRequest = m_requestQueue.last(); | 219 RefPtrWillBeRawPtr<SpellCheckRequest> lastRequest = m_requestQueue.last( ); |
| 207 // It's a continuation if the number of the last request got incremented in the new one and | 220 // It's a continuation if the number of the last request got incremented in the new one and |
| 208 // both apply to the same editable. | 221 // both apply to the same editable. |
| 209 continuation = request->rootEditableElement() == lastRequest->rootEditab leElement() | 222 continuation = request->rootEditableElement() == lastRequest->rootEditab leElement() |
| 210 && request->requestNumber() == lastRequest->requestNumber() + 1; | 223 && request->requestNumber() == lastRequest->requestNumber() + 1; |
| 211 } | 224 } |
| 212 | 225 |
| 213 // Spellcheck requests for chunks of text in the same element should not ove rwrite each other. | 226 // Spellcheck requests for chunks of text in the same element should not ove rwrite each other. |
| 214 if (!continuation) { | 227 if (!continuation) { |
| 215 for (RequestQueue::iterator it = m_requestQueue.begin(); it != m_request Queue.end(); ++it) { | 228 for (RequestQueue::iterator it = m_requestQueue.begin(); it != m_request Queue.end(); ++it) { |
| 216 if (request->rootEditableElement() != (*it)->rootEditableElement()) | 229 if (request->rootEditableElement() != (*it)->rootEditableElement()) |
| 217 continue; | 230 continue; |
| 218 | 231 |
| 219 *it = request; | 232 *it = request; |
| 220 return; | 233 return; |
| 221 } | 234 } |
| 222 } | 235 } |
| 223 | 236 |
| 224 m_requestQueue.append(request); | 237 m_requestQueue.append(request); |
| 225 } | 238 } |
| 226 | 239 |
| 227 void SpellCheckRequester::didCheck(int sequence, const Vector<TextCheckingResult >& results) | 240 void SpellCheckRequester::didCheck(int sequence, const Vector<TextCheckingResult >& results) |
| 228 { | 241 { |
| 229 ASSERT(m_processingRequest); | 242 ASSERT(m_processingRequest); |
| 230 ASSERT(m_processingRequest->data().sequence() == sequence); | 243 ASSERT(m_processingRequest->data().sequence() == sequence); |
| 231 if (m_processingRequest->data().sequence() != sequence) { | 244 if (m_processingRequest->data().sequence() != sequence) { |
| 232 m_requestQueue.clear(); | 245 m_requestQueue.clear(); |
| 233 return; | 246 return; |
| 234 } | 247 } |
| 235 | 248 |
| 236 m_frame.spellChecker().markAndReplaceFor(m_processingRequest, results); | 249 m_frame->spellChecker().markAndReplaceFor(m_processingRequest, results); |
| 237 | 250 |
| 238 if (m_lastProcessedSequence < sequence) | 251 if (m_lastProcessedSequence < sequence) |
| 239 m_lastProcessedSequence = sequence; | 252 m_lastProcessedSequence = sequence; |
| 240 | 253 |
| 241 m_processingRequest.clear(); | 254 m_processingRequest.clear(); |
| 242 if (!m_requestQueue.isEmpty()) | 255 if (!m_requestQueue.isEmpty()) |
| 243 m_timerToProcessQueuedRequest.startOneShot(0, FROM_HERE); | 256 m_timerToProcessQueuedRequest.startOneShot(0, FROM_HERE); |
| 244 } | 257 } |
| 245 | 258 |
| 246 void SpellCheckRequester::didCheckSucceed(int sequence, const Vector<TextCheckin gResult>& results) | 259 void SpellCheckRequester::didCheckSucceed(int sequence, const Vector<TextCheckin gResult>& results) |
| 247 { | 260 { |
| 248 TextCheckingRequestData requestData = m_processingRequest->data(); | 261 TextCheckingRequestData requestData = m_processingRequest->data(); |
| 249 if (requestData.sequence() == sequence) { | 262 if (requestData.sequence() == sequence) { |
| 250 DocumentMarker::MarkerTypes markers = DocumentMarker::SpellCheckClientMa rkers(); | 263 DocumentMarker::MarkerTypes markers = DocumentMarker::SpellCheckClientMa rkers(); |
| 251 if (!requestData.maskContains(TextCheckingTypeSpelling)) | 264 if (!requestData.maskContains(TextCheckingTypeSpelling)) |
| 252 markers.remove(DocumentMarker::Spelling); | 265 markers.remove(DocumentMarker::Spelling); |
| 253 if (!requestData.maskContains(TextCheckingTypeGrammar)) | 266 if (!requestData.maskContains(TextCheckingTypeGrammar)) |
| 254 markers.remove(DocumentMarker::Grammar); | 267 markers.remove(DocumentMarker::Grammar); |
| 255 m_frame.document()->markers().removeMarkers(m_processingRequest->checkin gRange().get(), markers); | 268 if (m_frame->document()) |
|
haraken
2014/09/08 07:25:57
Why do we need to introduce this check in this CL?
sof
2014/09/08 21:17:45
Thanks for bringing this up. With the prompt dispo
| |
| 269 m_frame->document()->markers().removeMarkers(m_processingRequest->ch eckingRange().get(), markers); | |
| 256 } | 270 } |
| 257 didCheck(sequence, results); | 271 didCheck(sequence, results); |
| 258 } | 272 } |
| 259 | 273 |
| 260 void SpellCheckRequester::didCheckCancel(int sequence) | 274 void SpellCheckRequester::didCheckCancel(int sequence) |
| 261 { | 275 { |
| 262 Vector<TextCheckingResult> results; | 276 Vector<TextCheckingResult> results; |
| 263 didCheck(sequence, results); | 277 didCheck(sequence, results); |
| 264 } | 278 } |
| 265 | 279 |
| 280 void SpellCheckRequester::trace(Visitor* visitor) | |
| 281 { | |
| 282 visitor->trace(m_frame); | |
| 283 visitor->trace(m_processingRequest); | |
| 284 visitor->trace(m_requestQueue); | |
| 285 } | |
| 286 | |
| 266 } // namespace blink | 287 } // namespace blink |
| OLD | NEW |