Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(356)

Side by Side Diff: third_party/WebKit/Source/core/editing/spellcheck/SpellCheckRequester.cpp

Issue 1878473002: ASSERT -> DCHECK in core/editing. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix compilation. Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 const Vector<uint32_t>& documentMarkersInRange, 44 const Vector<uint32_t>& documentMarkersInRange,
45 const Vector<unsigned>& documentMarkerOffsets, 45 const Vector<unsigned>& documentMarkerOffsets,
46 int requestNumber) 46 int requestNumber)
47 : m_requester(nullptr) 47 : m_requester(nullptr)
48 , m_checkingRange(checkingRange) 48 , m_checkingRange(checkingRange)
49 , m_paragraphRange(paragraphRange) 49 , m_paragraphRange(paragraphRange)
50 , m_rootEditableElement(m_checkingRange->startContainer()->rootEditableEleme nt()) 50 , m_rootEditableElement(m_checkingRange->startContainer()->rootEditableEleme nt())
51 , m_requestData(unrequestedTextCheckingSequence, text, mask, processType, do cumentMarkersInRange, documentMarkerOffsets) 51 , m_requestData(unrequestedTextCheckingSequence, text, mask, processType, do cumentMarkersInRange, documentMarkerOffsets)
52 , m_requestNumber(requestNumber) 52 , m_requestNumber(requestNumber)
53 { 53 {
54 ASSERT(m_checkingRange); 54 DCHECK(m_checkingRange);
55 ASSERT(m_checkingRange->inShadowIncludingDocument()); 55 DCHECK(m_checkingRange->inShadowIncludingDocument());
56 ASSERT(m_paragraphRange); 56 DCHECK(m_paragraphRange);
57 ASSERT(m_paragraphRange->inShadowIncludingDocument()); 57 DCHECK(m_paragraphRange->inShadowIncludingDocument());
58 ASSERT(m_rootEditableElement); 58 DCHECK(m_rootEditableElement);
59 } 59 }
60 60
61 SpellCheckRequest::~SpellCheckRequest() 61 SpellCheckRequest::~SpellCheckRequest()
62 { 62 {
63 } 63 }
64 64
65 DEFINE_TRACE(SpellCheckRequest) 65 DEFINE_TRACE(SpellCheckRequest)
66 { 66 {
67 visitor->trace(m_requester); 67 visitor->trace(m_requester);
68 visitor->trace(m_checkingRange); 68 visitor->trace(m_checkingRange);
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 { 133 {
134 if (!m_requester) 134 if (!m_requester)
135 return; 135 return;
136 SpellCheckRequester* requester = m_requester; 136 SpellCheckRequester* requester = m_requester;
137 m_requester = nullptr; 137 m_requester = nullptr;
138 requester->didCheckCancel(m_requestData.sequence()); 138 requester->didCheckCancel(m_requestData.sequence());
139 } 139 }
140 140
141 void SpellCheckRequest::setCheckerAndSequence(SpellCheckRequester* requester, in t sequence) 141 void SpellCheckRequest::setCheckerAndSequence(SpellCheckRequester* requester, in t sequence)
142 { 142 {
143 ASSERT(!m_requester); 143 DCHECK(!m_requester);
144 ASSERT(m_requestData.sequence() == unrequestedTextCheckingSequence); 144 DCHECK_EQ(m_requestData.sequence(), unrequestedTextCheckingSequence);
145 m_requester = requester; 145 m_requester = requester;
146 m_requestData.m_sequence = sequence; 146 m_requestData.m_sequence = sequence;
147 } 147 }
148 148
149 #if !ENABLE(OILPAN) 149 #if !ENABLE(OILPAN)
150 void SpellCheckRequest::requesterDestroyed() 150 void SpellCheckRequest::requesterDestroyed()
151 { 151 {
152 m_requester = nullptr; 152 m_requester = nullptr;
153 } 153 }
154 #endif 154 #endif
(...skipping 16 matching lines...) Expand all
171 #endif 171 #endif
172 } 172 }
173 173
174 TextCheckerClient& SpellCheckRequester::client() const 174 TextCheckerClient& SpellCheckRequester::client() const
175 { 175 {
176 return frame().spellChecker().textChecker(); 176 return frame().spellChecker().textChecker();
177 } 177 }
178 178
179 void SpellCheckRequester::timerFiredToProcessQueuedRequest(Timer<SpellCheckReque ster>*) 179 void SpellCheckRequester::timerFiredToProcessQueuedRequest(Timer<SpellCheckReque ster>*)
180 { 180 {
181 ASSERT(!m_requestQueue.isEmpty()); 181 DCHECK(!m_requestQueue.isEmpty());
182 if (m_requestQueue.isEmpty()) 182 if (m_requestQueue.isEmpty())
183 return; 183 return;
184 184
185 invokeRequest(m_requestQueue.takeFirst()); 185 invokeRequest(m_requestQueue.takeFirst());
186 } 186 }
187 187
188 bool SpellCheckRequester::canCheckAsynchronously(Range* range) const 188 bool SpellCheckRequester::canCheckAsynchronously(Range* range) const
189 { 189 {
190 return isCheckable(range); 190 return isCheckable(range);
191 } 191 }
192 192
193 bool SpellCheckRequester::isCheckable(Range* range) const 193 bool SpellCheckRequester::isCheckable(Range* range) const
194 { 194 {
195 if (!range || !range->firstNode() || !range->firstNode()->layoutObject()) 195 if (!range || !range->firstNode() || !range->firstNode()->layoutObject())
196 return false; 196 return false;
197 const Node* node = range->startContainer(); 197 const Node* node = range->startContainer();
198 if (node && node->isElementNode() && !toElement(node)->isSpellCheckingEnable d()) 198 if (node && node->isElementNode() && !toElement(node)->isSpellCheckingEnable d())
199 return false; 199 return false;
200 return true; 200 return true;
201 } 201 }
202 202
203 void SpellCheckRequester::requestCheckingFor(RawPtr<SpellCheckRequest> request) 203 void SpellCheckRequester::requestCheckingFor(RawPtr<SpellCheckRequest> request)
204 { 204 {
205 if (!request || !canCheckAsynchronously(request->paragraphRange().get())) 205 if (!request || !canCheckAsynchronously(request->paragraphRange().get()))
206 return; 206 return;
207 207
208 ASSERT(request->data().sequence() == unrequestedTextCheckingSequence); 208 DCHECK_EQ(request->data().sequence(), unrequestedTextCheckingSequence);
209 int sequence = ++m_lastRequestSequence; 209 int sequence = ++m_lastRequestSequence;
210 if (sequence == unrequestedTextCheckingSequence) 210 if (sequence == unrequestedTextCheckingSequence)
211 sequence = ++m_lastRequestSequence; 211 sequence = ++m_lastRequestSequence;
212 212
213 request->setCheckerAndSequence(this, sequence); 213 request->setCheckerAndSequence(this, sequence);
214 214
215 if (m_timerToProcessQueuedRequest.isActive() || m_processingRequest) { 215 if (m_timerToProcessQueuedRequest.isActive() || m_processingRequest) {
216 enqueueRequest(request); 216 enqueueRequest(request);
217 return; 217 return;
218 } 218 }
(...skipping 15 matching lines...) Expand all
234 // leaks, just async work items waiting to be processed. 234 // leaks, just async work items waiting to be processed.
235 // 235 //
236 // Rather than somehow wait for this async queue to drain before running 236 // Rather than somehow wait for this async queue to drain before running
237 // the leak detector, they're all cancelled to prevent flaky leaks being 237 // the leak detector, they're all cancelled to prevent flaky leaks being
238 // reported. 238 // reported.
239 m_requestQueue.clear(); 239 m_requestQueue.clear();
240 } 240 }
241 241
242 void SpellCheckRequester::invokeRequest(RawPtr<SpellCheckRequest> request) 242 void SpellCheckRequester::invokeRequest(RawPtr<SpellCheckRequest> request)
243 { 243 {
244 ASSERT(!m_processingRequest); 244 DCHECK(!m_processingRequest);
245 m_processingRequest = request; 245 m_processingRequest = request;
246 client().requestCheckingOfString(m_processingRequest); 246 client().requestCheckingOfString(m_processingRequest);
247 } 247 }
248 248
249 void SpellCheckRequester::clearProcessingRequest() 249 void SpellCheckRequester::clearProcessingRequest()
250 { 250 {
251 if (!m_processingRequest) 251 if (!m_processingRequest)
252 return; 252 return;
253 253
254 m_processingRequest->dispose(); 254 m_processingRequest->dispose();
255 m_processingRequest.clear(); 255 m_processingRequest.clear();
256 } 256 }
257 257
258 void SpellCheckRequester::enqueueRequest(RawPtr<SpellCheckRequest> request) 258 void SpellCheckRequester::enqueueRequest(RawPtr<SpellCheckRequest> request)
259 { 259 {
260 ASSERT(request); 260 DCHECK(request);
261 bool continuation = false; 261 bool continuation = false;
262 if (!m_requestQueue.isEmpty()) { 262 if (!m_requestQueue.isEmpty()) {
263 RawPtr<SpellCheckRequest> lastRequest = m_requestQueue.last(); 263 RawPtr<SpellCheckRequest> lastRequest = m_requestQueue.last();
264 // It's a continuation if the number of the last request got incremented in the new one and 264 // It's a continuation if the number of the last request got incremented in the new one and
265 // both apply to the same editable. 265 // both apply to the same editable.
266 continuation = request->rootEditableElement() == lastRequest->rootEditab leElement() 266 continuation = request->rootEditableElement() == lastRequest->rootEditab leElement()
267 && request->requestNumber() == lastRequest->requestNumber() + 1; 267 && request->requestNumber() == lastRequest->requestNumber() + 1;
268 } 268 }
269 269
270 // Spellcheck requests for chunks of text in the same element should not ove rwrite each other. 270 // Spellcheck requests for chunks of text in the same element should not ove rwrite each other.
271 if (!continuation) { 271 if (!continuation) {
272 for (auto& requestQueue : m_requestQueue) { 272 for (auto& requestQueue : m_requestQueue) {
273 if (request->rootEditableElement() != requestQueue->rootEditableElem ent()) 273 if (request->rootEditableElement() != requestQueue->rootEditableElem ent())
274 continue; 274 continue;
275 275
276 requestQueue = request; 276 requestQueue = request;
277 return; 277 return;
278 } 278 }
279 } 279 }
280 280
281 m_requestQueue.append(request); 281 m_requestQueue.append(request);
282 } 282 }
283 283
284 void SpellCheckRequester::didCheck(int sequence, const Vector<TextCheckingResult >& results) 284 void SpellCheckRequester::didCheck(int sequence, const Vector<TextCheckingResult >& results)
285 { 285 {
286 ASSERT(m_processingRequest); 286 DCHECK(m_processingRequest);
287 ASSERT(m_processingRequest->data().sequence() == sequence); 287 DCHECK_EQ(m_processingRequest->data().sequence(), sequence);
288 if (m_processingRequest->data().sequence() != sequence) { 288 if (m_processingRequest->data().sequence() != sequence) {
289 m_requestQueue.clear(); 289 m_requestQueue.clear();
290 return; 290 return;
291 } 291 }
292 292
293 frame().spellChecker().markAndReplaceFor(m_processingRequest, results); 293 frame().spellChecker().markAndReplaceFor(m_processingRequest, results);
294 294
295 if (m_lastProcessedSequence < sequence) 295 if (m_lastProcessedSequence < sequence)
296 m_lastProcessedSequence = sequence; 296 m_lastProcessedSequence = sequence;
297 297
(...skipping 26 matching lines...) Expand all
324 } 324 }
325 325
326 DEFINE_TRACE(SpellCheckRequester) 326 DEFINE_TRACE(SpellCheckRequester)
327 { 327 {
328 visitor->trace(m_frame); 328 visitor->trace(m_frame);
329 visitor->trace(m_processingRequest); 329 visitor->trace(m_processingRequest);
330 visitor->trace(m_requestQueue); 330 visitor->trace(m_requestQueue);
331 } 331 }
332 332
333 } // namespace blink 333 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698