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

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: copy&paste bug fixed 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 requestNo)
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_requestNo(requestNo)
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)
64 { 66 {
67 return SpellCheckRequest::create(textCheckingOptions, processType, checkingR ange, paragraphRange, 0);
68 }
69
70 // static
71 PassRefPtr<SpellCheckRequest> SpellCheckRequest::create(TextCheckingTypeMask tex tCheckingOptions, TextCheckingProcessType processType, PassRefPtr<Range> checkin gRange, PassRefPtr<Range> paragraphRange, int requestNo)
72 {
65 ASSERT(checkingRange); 73 ASSERT(checkingRange);
66 ASSERT(paragraphRange); 74 ASSERT(paragraphRange);
67 75
68 String text = checkingRange->text(); 76 String text = checkingRange->text();
69 if (!text.length()) 77 if (!text.length())
70 return PassRefPtr<SpellCheckRequest>(); 78 return PassRefPtr<SpellCheckRequest>();
71 79
72 const Vector<DocumentMarker*>& markers = checkingRange->ownerDocument()->mar kers()->markersInRange(checkingRange.get(), DocumentMarker::Spelling | DocumentM arker::Grammar); 80 const Vector<DocumentMarker*>& markers = checkingRange->ownerDocument()->mar kers()->markersInRange(checkingRange.get(), DocumentMarker::Spelling | DocumentM arker::Grammar);
73 Vector<uint32_t> hashes(markers.size()); 81 Vector<uint32_t> hashes(markers.size());
74 Vector<unsigned> offsets(markers.size()); 82 Vector<unsigned> offsets(markers.size());
75 for (size_t i = 0; i < markers.size(); i++) { 83 for (size_t i = 0; i < markers.size(); i++) {
76 hashes[i] = markers[i]->hash(); 84 hashes[i] = markers[i]->hash();
77 offsets[i] = markers[i]->startOffset(); 85 offsets[i] = markers[i]->startOffset();
78 } 86 }
79 87
80 return adoptRef(new SpellCheckRequest(checkingRange, paragraphRange, text, t extCheckingOptions, processType, hashes, offsets)); 88 return adoptRef(new SpellCheckRequest(checkingRange, paragraphRange, text, t extCheckingOptions, processType, hashes, offsets, requestNo));
81 } 89 }
82 90
83 const TextCheckingRequestData& SpellCheckRequest::data() const 91 const TextCheckingRequestData& SpellCheckRequest::data() const
84 { 92 {
85 return m_requestData; 93 return m_requestData;
86 } 94 }
87 95
88 void SpellCheckRequest::didSucceed(const Vector<TextCheckingResult>& results) 96 void SpellCheckRequest::didSucceed(const Vector<TextCheckingResult>& results)
89 { 97 {
90 if (!m_checker) 98 if (!m_checker)
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 ASSERT(!m_processingRequest); 208 ASSERT(!m_processingRequest);
201 if (!client()) 209 if (!client())
202 return; 210 return;
203 m_processingRequest = request; 211 m_processingRequest = request;
204 client()->requestCheckingOfString(m_processingRequest); 212 client()->requestCheckingOfString(m_processingRequest);
205 } 213 }
206 214
207 void SpellChecker::enqueueRequest(PassRefPtr<SpellCheckRequest> request) 215 void SpellChecker::enqueueRequest(PassRefPtr<SpellCheckRequest> request)
208 { 216 {
209 ASSERT(request); 217 ASSERT(request);
218 bool continuation = false;
219 if (m_requestQueue.size() > 0) {
220 RefPtr<SpellCheckRequest> lastRequest = m_requestQueue.last();
221 continuation = request->rootEditableElement() == lastRequest->rootEditab leElement()
222 && request->requestNo() == lastRequest->requestNo() + 1;
223 }
210 224
211 for (RequestQueue::iterator it = m_requestQueue.begin(); it != m_requestQueu e.end(); ++it) { 225 if (!continuation) {
212 if (request->rootEditableElement() != (*it)->rootEditableElement()) 226 for (RequestQueue::iterator it = m_requestQueue.begin(); it != m_request Queue.end(); ++it) {
213 continue; 227 if (request->rootEditableElement() != (*it)->rootEditableElement())
228 continue;
214 229
215 *it = request; 230 *it = request;
216 return; 231 return;
232 }
217 } 233 }
218 234
219 m_requestQueue.append(request); 235 m_requestQueue.append(request);
220 } 236 }
221 237
222 void SpellChecker::didCheck(int sequence, const Vector<TextCheckingResult>& resu lts) 238 void SpellChecker::didCheck(int sequence, const Vector<TextCheckingResult>& resu lts)
223 { 239 {
224 ASSERT(m_processingRequest); 240 ASSERT(m_processingRequest);
225 ASSERT(m_processingRequest->data().sequence() == sequence); 241 ASSERT(m_processingRequest->data().sequence() == sequence);
226 if (m_processingRequest->data().sequence() != sequence) { 242 if (m_processingRequest->data().sequence() != sequence) {
(...skipping 26 matching lines...) Expand all
253 didCheck(sequence, results); 269 didCheck(sequence, results);
254 } 270 }
255 271
256 void SpellChecker::didCheckCancel(int sequence) 272 void SpellChecker::didCheckCancel(int sequence)
257 { 273 {
258 Vector<TextCheckingResult> results; 274 Vector<TextCheckingResult> results;
259 didCheck(sequence, results); 275 didCheck(sequence, results);
260 } 276 }
261 277
262 } // namespace WebCore 278 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698