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

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

Issue 23332004: Trigger spell check/remove markers if spell checker gets enabled/disabled. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: true=>asynchronous 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
« no previous file with comments | « Source/core/editing/SpellCheckRequester.h ('k') | Source/web/EditorClientImpl.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_requester(0) 51 : m_requester(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_requester) 92 if (!m_requester)
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 ASSERT(!m_processingRequest); 200 ASSERT(!m_processingRequest);
199 if (!client()) 201 if (!client())
200 return; 202 return;
201 m_processingRequest = request; 203 m_processingRequest = request;
202 client()->requestCheckingOfString(m_processingRequest); 204 client()->requestCheckingOfString(m_processingRequest);
203 } 205 }
204 206
205 void SpellCheckRequester::enqueueRequest(PassRefPtr<SpellCheckRequest> request) 207 void SpellCheckRequester::enqueueRequest(PassRefPtr<SpellCheckRequest> request)
206 { 208 {
207 ASSERT(request); 209 ASSERT(request);
210 bool continuation = false;
211 if (!m_requestQueue.isEmpty()) {
212 RefPtr<SpellCheckRequest> lastRequest = m_requestQueue.last();
213 // It's a continuation if the number of the last request got incremented in the new one and
214 // both apply to the same editable.
215 continuation = request->rootEditableElement() == lastRequest->rootEditab leElement()
216 && request->requestNumber() == lastRequest->requestNumber() + 1;
217 }
208 218
209 for (RequestQueue::iterator it = m_requestQueue.begin(); it != m_requestQueu e.end(); ++it) { 219 // Spellcheck requests for chunks of text in the same element should not ove rwrite each other.
210 if (request->rootEditableElement() != (*it)->rootEditableElement()) 220 if (!continuation) {
211 continue; 221 for (RequestQueue::iterator it = m_requestQueue.begin(); it != m_request Queue.end(); ++it) {
222 if (request->rootEditableElement() != (*it)->rootEditableElement())
223 continue;
212 224
213 *it = request; 225 *it = request;
214 return; 226 return;
227 }
215 } 228 }
216 229
217 m_requestQueue.append(request); 230 m_requestQueue.append(request);
218 } 231 }
219 232
220 void SpellCheckRequester::didCheck(int sequence, const Vector<TextCheckingResult >& results) 233 void SpellCheckRequester::didCheck(int sequence, const Vector<TextCheckingResult >& results)
221 { 234 {
222 ASSERT(m_processingRequest); 235 ASSERT(m_processingRequest);
223 ASSERT(m_processingRequest->data().sequence() == sequence); 236 ASSERT(m_processingRequest->data().sequence() == sequence);
224 if (m_processingRequest->data().sequence() != sequence) { 237 if (m_processingRequest->data().sequence() != sequence) {
(...skipping 26 matching lines...) Expand all
251 didCheck(sequence, results); 264 didCheck(sequence, results);
252 } 265 }
253 266
254 void SpellCheckRequester::didCheckCancel(int sequence) 267 void SpellCheckRequester::didCheckCancel(int sequence)
255 { 268 {
256 Vector<TextCheckingResult> results; 269 Vector<TextCheckingResult> results;
257 didCheck(sequence, results); 270 didCheck(sequence, results);
258 } 271 }
259 272
260 } // namespace WebCore 273 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/editing/SpellCheckRequester.h ('k') | Source/web/EditorClientImpl.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698