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

Side by Side Diff: Source/core/editing/SpellChecker.cpp

Issue 21130005: Trigger spell check/remove markers if spell checker gets enabled/disabled. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Added the comment clarifying things a bit more. Created 7 years, 4 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 28 matching lines...) Expand all
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
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) {
tony 2013/08/15 00:01:40 !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 }
210 220
211 for (RequestQueue::iterator it = m_requestQueue.begin(); it != m_requestQueu e.end(); ++it) { 221 // Spellcheck requests for chunks of text in the same element should not ove rwrite each other.
212 if (request->rootEditableElement() != (*it)->rootEditableElement()) 222 if (!continuation) {
213 continue; 223 for (RequestQueue::iterator it = m_requestQueue.begin(); it != m_request Queue.end(); ++it) {
224 if (request->rootEditableElement() != (*it)->rootEditableElement())
225 continue;
214 226
215 *it = request; 227 *it = request;
216 return; 228 return;
229 }
217 } 230 }
218 231
219 m_requestQueue.append(request); 232 m_requestQueue.append(request);
220 } 233 }
221 234
222 void SpellChecker::didCheck(int sequence, const Vector<TextCheckingResult>& resu lts) 235 void SpellChecker::didCheck(int sequence, const Vector<TextCheckingResult>& resu lts)
223 { 236 {
224 ASSERT(m_processingRequest); 237 ASSERT(m_processingRequest);
225 ASSERT(m_processingRequest->data().sequence() == sequence); 238 ASSERT(m_processingRequest->data().sequence() == sequence);
226 if (m_processingRequest->data().sequence() != sequence) { 239 if (m_processingRequest->data().sequence() != sequence) {
(...skipping 26 matching lines...) Expand all
253 didCheck(sequence, results); 266 didCheck(sequence, results);
254 } 267 }
255 268
256 void SpellChecker::didCheckCancel(int sequence) 269 void SpellChecker::didCheckCancel(int sequence)
257 { 270 {
258 Vector<TextCheckingResult> results; 271 Vector<TextCheckingResult> results;
259 didCheck(sequence, results); 272 didCheck(sequence, results);
260 } 273 }
261 274
262 } // namespace WebCore 275 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698