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

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

Issue 1878473002: ASSERT -> DCHECK in core/editing. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Output info for some DCHECKs, add TODOs. 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) 2006, 2007 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
3 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) 3 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 int checkLocation = start; 46 int checkLocation = start;
47 int checkLength = length; 47 int checkLength = length;
48 48
49 while (0 < checkLength) { 49 while (0 < checkLength) {
50 int badGrammarLocation = -1; 50 int badGrammarLocation = -1;
51 int badGrammarLength = 0; 51 int badGrammarLength = 0;
52 Vector<GrammarDetail> badGrammarDetails; 52 Vector<GrammarDetail> badGrammarDetails;
53 client.checkGrammarOfString(String(text + checkLocation, checkLength), b adGrammarDetails, &badGrammarLocation, &badGrammarLength); 53 client.checkGrammarOfString(String(text + checkLocation, checkLength), b adGrammarDetails, &badGrammarLocation, &badGrammarLength);
54 if (!badGrammarLength) 54 if (!badGrammarLength)
55 break; 55 break;
56 ASSERT(0 <= badGrammarLocation && badGrammarLocation <= checkLength); 56 DCHECK_LE(0, badGrammarLocation);
57 ASSERT(0 < badGrammarLength && badGrammarLocation + badGrammarLength <= checkLength); 57 DCHECK_LE(badGrammarLocation, checkLength);
58 DCHECK_LT(0, badGrammarLength);
59 DCHECK_LE(badGrammarLocation + badGrammarLength, checkLength);
58 TextCheckingResult badGrammar; 60 TextCheckingResult badGrammar;
59 badGrammar.decoration = TextDecorationTypeGrammar; 61 badGrammar.decoration = TextDecorationTypeGrammar;
60 badGrammar.location = checkLocation + badGrammarLocation; 62 badGrammar.location = checkLocation + badGrammarLocation;
61 badGrammar.length = badGrammarLength; 63 badGrammar.length = badGrammarLength;
62 badGrammar.details.swap(badGrammarDetails); 64 badGrammar.details.swap(badGrammarDetails);
63 results.append(badGrammar); 65 results.append(badGrammar);
64 66
65 checkLocation += (badGrammarLocation + badGrammarLength); 67 checkLocation += (badGrammarLocation + badGrammarLength);
66 checkLength -= (badGrammarLocation + badGrammarLength); 68 checkLength -= (badGrammarLocation + badGrammarLength);
67 } 69 }
68 } 70 }
69 71
70 static void findMisspellings(TextCheckerClient& client, const UChar* text, int s tart, int length, Vector<TextCheckingResult>& results) 72 static void findMisspellings(TextCheckerClient& client, const UChar* text, int s tart, int length, Vector<TextCheckingResult>& results)
71 { 73 {
72 TextBreakIterator* iterator = wordBreakIterator(text + start, length); 74 TextBreakIterator* iterator = wordBreakIterator(text + start, length);
73 if (!iterator) 75 if (!iterator)
74 return; 76 return;
75 int wordStart = iterator->current(); 77 int wordStart = iterator->current();
76 while (0 <= wordStart) { 78 while (0 <= wordStart) {
77 int wordEnd = iterator->next(); 79 int wordEnd = iterator->next();
78 if (wordEnd < 0) 80 if (wordEnd < 0)
79 break; 81 break;
80 int wordLength = wordEnd - wordStart; 82 int wordLength = wordEnd - wordStart;
81 int misspellingLocation = -1; 83 int misspellingLocation = -1;
82 int misspellingLength = 0; 84 int misspellingLength = 0;
83 client.checkSpellingOfString(String(text + start + wordStart, wordLength ), &misspellingLocation, &misspellingLength); 85 client.checkSpellingOfString(String(text + start + wordStart, wordLength ), &misspellingLocation, &misspellingLength);
84 if (0 < misspellingLength) { 86 if (0 < misspellingLength) {
85 ASSERT(0 <= misspellingLocation && misspellingLocation <= wordLength ); 87 DCHECK_LE(0, misspellingLocation);
86 ASSERT(0 < misspellingLength && misspellingLocation + misspellingLen gth <= wordLength); 88 DCHECK_LE(misspellingLocation, wordLength);
89 DCHECK_LT(0, misspellingLength);
90 DCHECK_LE(misspellingLocation + misspellingLength, wordLength);
87 TextCheckingResult misspelling; 91 TextCheckingResult misspelling;
88 misspelling.decoration = TextDecorationTypeSpelling; 92 misspelling.decoration = TextDecorationTypeSpelling;
89 misspelling.location = start + wordStart + misspellingLocation; 93 misspelling.location = start + wordStart + misspellingLocation;
90 misspelling.length = misspellingLength; 94 misspelling.length = misspellingLength;
91 results.append(misspelling); 95 results.append(misspelling);
92 } 96 }
93 97
94 wordStart = wordEnd; 98 wordStart = wordEnd;
95 } 99 }
96 } 100 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 , m_checkingLength(-1) 139 , m_checkingLength(-1)
136 { 140 {
137 } 141 }
138 142
139 TextCheckingParagraph::~TextCheckingParagraph() 143 TextCheckingParagraph::~TextCheckingParagraph()
140 { 144 {
141 } 145 }
142 146
143 void TextCheckingParagraph::expandRangeToNextEnd() 147 void TextCheckingParagraph::expandRangeToNextEnd()
144 { 148 {
145 ASSERT(m_checkingRange.isNotNull()); 149 DCHECK(m_checkingRange.isNotNull());
146 setParagraphRange(EphemeralRange(paragraphRange().startPosition(), endOfPara graph(startOfNextParagraph(createVisiblePosition(paragraphRange().startPosition( )))).deepEquivalent())); 150 setParagraphRange(EphemeralRange(paragraphRange().startPosition(), endOfPara graph(startOfNextParagraph(createVisiblePosition(paragraphRange().startPosition( )))).deepEquivalent()));
147 invalidateParagraphRangeValues(); 151 invalidateParagraphRangeValues();
148 } 152 }
149 153
150 void TextCheckingParagraph::invalidateParagraphRangeValues() 154 void TextCheckingParagraph::invalidateParagraphRangeValues()
151 { 155 {
152 m_checkingStart = m_checkingEnd = -1; 156 m_checkingStart = m_checkingEnd = -1;
153 m_offsetAsRange = EphemeralRange(); 157 m_offsetAsRange = EphemeralRange();
154 m_text = String(); 158 m_text = String();
155 } 159 }
156 160
157 int TextCheckingParagraph::rangeLength() const 161 int TextCheckingParagraph::rangeLength() const
158 { 162 {
159 ASSERT(m_checkingRange.isNotNull()); 163 DCHECK(m_checkingRange.isNotNull());
160 return TextIterator::rangeLength(paragraphRange().startPosition(), paragraph Range().endPosition()); 164 return TextIterator::rangeLength(paragraphRange().startPosition(), paragraph Range().endPosition());
161 } 165 }
162 166
163 EphemeralRange TextCheckingParagraph::paragraphRange() const 167 EphemeralRange TextCheckingParagraph::paragraphRange() const
164 { 168 {
165 ASSERT(m_checkingRange.isNotNull()); 169 DCHECK(m_checkingRange.isNotNull());
166 if (m_paragraphRange.isNull()) 170 if (m_paragraphRange.isNull())
167 m_paragraphRange = expandToParagraphBoundary(checkingRange()); 171 m_paragraphRange = expandToParagraphBoundary(checkingRange());
168 return m_paragraphRange; 172 return m_paragraphRange;
169 } 173 }
170 174
171 void TextCheckingParagraph::setParagraphRange(const EphemeralRange& range) 175 void TextCheckingParagraph::setParagraphRange(const EphemeralRange& range)
172 { 176 {
173 m_paragraphRange = range; 177 m_paragraphRange = range;
174 } 178 }
175 179
176 EphemeralRange TextCheckingParagraph::subrange(int characterOffset, int characte rCount) const 180 EphemeralRange TextCheckingParagraph::subrange(int characterOffset, int characte rCount) const
177 { 181 {
178 ASSERT(m_checkingRange.isNotNull()); 182 DCHECK(m_checkingRange.isNotNull());
179 return calculateCharacterSubrange(paragraphRange(), characterOffset, charact erCount); 183 return calculateCharacterSubrange(paragraphRange(), characterOffset, charact erCount);
180 } 184 }
181 185
182 int TextCheckingParagraph::offsetTo(const Position& position) const 186 int TextCheckingParagraph::offsetTo(const Position& position) const
183 { 187 {
184 ASSERT(m_checkingRange.isNotNull()); 188 DCHECK(m_checkingRange.isNotNull());
185 return TextIterator::rangeLength(offsetAsRange().startPosition(), position); 189 return TextIterator::rangeLength(offsetAsRange().startPosition(), position);
186 } 190 }
187 191
188 bool TextCheckingParagraph::isEmpty() const 192 bool TextCheckingParagraph::isEmpty() const
189 { 193 {
190 // Both predicates should have same result, but we check both just to be sur e. 194 // Both predicates should have same result, but we check both just to be sur e.
191 // We need to investigate to remove this redundancy. 195 // We need to investigate to remove this redundancy.
192 return isRangeEmpty() || isTextEmpty(); 196 return isRangeEmpty() || isTextEmpty();
193 } 197 }
194 198
195 EphemeralRange TextCheckingParagraph::offsetAsRange() const 199 EphemeralRange TextCheckingParagraph::offsetAsRange() const
196 { 200 {
197 ASSERT(m_checkingRange.isNotNull()); 201 DCHECK(m_checkingRange.isNotNull());
198 if (m_offsetAsRange.isNull()) 202 if (m_offsetAsRange.isNull())
199 m_offsetAsRange = EphemeralRange(paragraphRange().startPosition(), check ingRange().startPosition()); 203 m_offsetAsRange = EphemeralRange(paragraphRange().startPosition(), check ingRange().startPosition());
200 204
201 return m_offsetAsRange; 205 return m_offsetAsRange;
202 } 206 }
203 207
204 const String& TextCheckingParagraph::text() const 208 const String& TextCheckingParagraph::text() const
205 { 209 {
206 ASSERT(m_checkingRange.isNotNull()); 210 DCHECK(m_checkingRange.isNotNull());
207 if (m_text.isEmpty()) 211 if (m_text.isEmpty())
208 m_text = plainText(paragraphRange()); 212 m_text = plainText(paragraphRange());
209 return m_text; 213 return m_text;
210 } 214 }
211 215
212 int TextCheckingParagraph::checkingStart() const 216 int TextCheckingParagraph::checkingStart() const
213 { 217 {
214 ASSERT(m_checkingRange.isNotNull()); 218 DCHECK(m_checkingRange.isNotNull());
215 if (m_checkingStart == -1) 219 if (m_checkingStart == -1)
216 m_checkingStart = TextIterator::rangeLength(offsetAsRange().startPositio n(), offsetAsRange().endPosition()); 220 m_checkingStart = TextIterator::rangeLength(offsetAsRange().startPositio n(), offsetAsRange().endPosition());
217 return m_checkingStart; 221 return m_checkingStart;
218 } 222 }
219 223
220 int TextCheckingParagraph::checkingEnd() const 224 int TextCheckingParagraph::checkingEnd() const
221 { 225 {
222 ASSERT(m_checkingRange.isNotNull()); 226 DCHECK(m_checkingRange.isNotNull());
223 if (m_checkingEnd == -1) 227 if (m_checkingEnd == -1)
224 m_checkingEnd = checkingStart() + TextIterator::rangeLength(checkingRang e().startPosition(), checkingRange().endPosition()); 228 m_checkingEnd = checkingStart() + TextIterator::rangeLength(checkingRang e().startPosition(), checkingRange().endPosition());
225 return m_checkingEnd; 229 return m_checkingEnd;
226 } 230 }
227 231
228 int TextCheckingParagraph::checkingLength() const 232 int TextCheckingParagraph::checkingLength() const
229 { 233 {
230 ASSERT(m_checkingRange.isNotNull()); 234 DCHECK(m_checkingRange.isNotNull());
231 if (-1 == m_checkingLength) 235 if (-1 == m_checkingLength)
232 m_checkingLength = TextIterator::rangeLength(checkingRange().startPositi on(), checkingRange().endPosition()); 236 m_checkingLength = TextIterator::rangeLength(checkingRange().startPositi on(), checkingRange().endPosition());
233 return m_checkingLength; 237 return m_checkingLength;
234 } 238 }
235 239
236 TextCheckingHelper::TextCheckingHelper(SpellCheckerClient& client, const Positio n& start, const Position& end) 240 TextCheckingHelper::TextCheckingHelper(SpellCheckerClient& client, const Positio n& start, const Position& end)
237 : m_client(&client) 241 : m_client(&client)
238 , m_start(start) 242 , m_start(start)
239 , m_end(end) 243 , m_end(end)
240 { 244 {
(...skipping 17 matching lines...) Expand all
258 // Skip some work for one-space-char hunks 262 // Skip some work for one-space-char hunks
259 if (!(length == 1 && it.characterAt(0) == ' ')) { 263 if (!(length == 1 && it.characterAt(0) == ' ')) {
260 264
261 int misspellingLocation = -1; 265 int misspellingLocation = -1;
262 int misspellingLength = 0; 266 int misspellingLength = 0;
263 m_client->textChecker().checkSpellingOfString(it.substring(0, length ), &misspellingLocation, &misspellingLength); 267 m_client->textChecker().checkSpellingOfString(it.substring(0, length ), &misspellingLocation, &misspellingLength);
264 268
265 // 5490627 shows that there was some code path here where the String constructor below crashes. 269 // 5490627 shows that there was some code path here where the String constructor below crashes.
266 // We don't know exactly what combination of bad input caused this, so we're making this much 270 // We don't know exactly what combination of bad input caused this, so we're making this much
267 // more robust against bad input on release builds. 271 // more robust against bad input on release builds.
268 ASSERT(misspellingLength >= 0); 272 DCHECK_GE(misspellingLength, 0);
269 ASSERT(misspellingLocation >= -1); 273 DCHECK_GE(misspellingLocation, -1);
270 ASSERT(!misspellingLength || misspellingLocation >= 0); 274 DCHECK(!misspellingLength || misspellingLocation >= 0);
271 ASSERT(misspellingLocation < length); 275 DCHECK_LT(misspellingLocation, length);
272 ASSERT(misspellingLength <= length); 276 DCHECK_LE(misspellingLength, length);
273 ASSERT(misspellingLocation + misspellingLength <= length); 277 DCHECK_LE(misspellingLocation + misspellingLength, length);
274 278
275 if (misspellingLocation >= 0 && misspellingLength > 0 && misspelling Location < length && misspellingLength <= length && misspellingLocation + misspe llingLength <= length) { 279 if (misspellingLocation >= 0 && misspellingLength > 0 && misspelling Location < length && misspellingLength <= length && misspellingLocation + misspe llingLength <= length) {
276 280
277 // Compute range of misspelled word 281 // Compute range of misspelled word
278 const EphemeralRange misspellingRange = calculateCharacterSubran ge(EphemeralRange(m_start, m_end), currentChunkOffset + misspellingLocation, mis spellingLength); 282 const EphemeralRange misspellingRange = calculateCharacterSubran ge(EphemeralRange(m_start, m_end), currentChunkOffset + misspellingLocation, mis spellingLength);
279 283
280 // Remember first-encountered misspelling and its offset. 284 // Remember first-encountered misspelling and its offset.
281 if (!firstMisspelling) { 285 if (!firstMisspelling) {
282 firstMisspellingOffset = currentChunkOffset + misspellingLoc ation; 286 firstMisspellingOffset = currentChunkOffset + misspellingLoc ation;
283 firstMisspelling = it.substring(misspellingLocation, misspel lingLength); 287 firstMisspelling = it.substring(misspellingLocation, misspel lingLength);
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 int grammarDetailLocation = 0; 353 int grammarDetailLocation = 0;
350 unsigned grammarDetailIndex = 0; 354 unsigned grammarDetailIndex = 0;
351 355
352 Vector<TextCheckingResult> results; 356 Vector<TextCheckingResult> results;
353 TextCheckingTypeMask checkingTypes = TextCheckingTypeSpelling | TextCheckingTypeGrammar; 357 TextCheckingTypeMask checkingTypes = TextCheckingTypeSpelling | TextCheckingTypeGrammar;
354 checkTextOfParagraph(m_client->textChecker(), paragraphString, c heckingTypes, results); 358 checkTextOfParagraph(m_client->textChecker(), paragraphString, c heckingTypes, results);
355 359
356 for (unsigned i = 0; i < results.size(); i++) { 360 for (unsigned i = 0; i < results.size(); i++) {
357 const TextCheckingResult* result = &results[i]; 361 const TextCheckingResult* result = &results[i];
358 if (result->decoration == TextDecorationTypeSpelling && resu lt->location >= currentStartOffset && result->location + result->length <= curre ntEndOffset) { 362 if (result->decoration == TextDecorationTypeSpelling && resu lt->location >= currentStartOffset && result->location + result->length <= curre ntEndOffset) {
359 ASSERT(result->length > 0 && result->location >= 0); 363 DCHECK_GT(result->length, 0);
364 DCHECK_GE(result->location, 0);
360 spellingLocation = result->location; 365 spellingLocation = result->location;
361 misspelledWord = paragraphString.substring(result->locat ion, result->length); 366 misspelledWord = paragraphString.substring(result->locat ion, result->length);
362 ASSERT(misspelledWord.length()); 367 DCHECK(misspelledWord.length());
363 break; 368 break;
364 } 369 }
365 if (result->decoration == TextDecorationTypeGrammar && resul t->location < currentEndOffset && result->location + result->length > currentSta rtOffset) { 370 if (result->decoration == TextDecorationTypeGrammar && resul t->location < currentEndOffset && result->location + result->length > currentSta rtOffset) {
366 ASSERT(result->length > 0 && result->location >= 0); 371 DCHECK_GT(result->length, 0);
372 DCHECK_GE(result->location, 0);
367 // We can't stop after the first grammar result, since t here might still be a spelling result after 373 // We can't stop after the first grammar result, since t here might still be a spelling result after
368 // it begins but before the first detail in it, but we c an stop if we find a second grammar result. 374 // it begins but before the first detail in it, but we c an stop if we find a second grammar result.
369 if (foundGrammar) 375 if (foundGrammar)
370 break; 376 break;
371 for (unsigned j = 0; j < result->details.size(); j++) { 377 for (unsigned j = 0; j < result->details.size(); j++) {
372 const GrammarDetail* detail = &result->details[j]; 378 const GrammarDetail* detail = &result->details[j];
373 ASSERT(detail->length > 0 && detail->location >= 0); 379 DCHECK_GT(detail->length, 0);
380 DCHECK_GE(detail->location, 0);
374 if (result->location + detail->location >= currentSt artOffset && result->location + detail->location + detail->length <= currentEndO ffset && (!foundGrammar || result->location + detail->location < grammarDetailLo cation)) { 381 if (result->location + detail->location >= currentSt artOffset && result->location + detail->location + detail->length <= currentEndO ffset && (!foundGrammar || result->location + detail->location < grammarDetailLo cation)) {
375 grammarDetailIndex = j; 382 grammarDetailIndex = j;
376 grammarDetailLocation = result->location + detai l->location; 383 grammarDetailLocation = result->location + detai l->location;
377 foundGrammar = true; 384 foundGrammar = true;
378 } 385 }
379 } 386 }
380 if (foundGrammar) { 387 if (foundGrammar) {
381 grammarPhraseLocation = result->location; 388 grammarPhraseLocation = result->location;
382 outGrammarDetail = result->details[grammarDetailInde x]; 389 outGrammarDetail = result->details[grammarDetailInde x];
383 badGrammarPhrase = paragraphString.substring(result- >location, result->length); 390 badGrammarPhrase = paragraphString.substring(result- >location, result->length);
384 ASSERT(badGrammarPhrase.length()); 391 DCHECK(badGrammarPhrase.length());
385 } 392 }
386 } 393 }
387 } 394 }
388 395
389 if (!misspelledWord.isEmpty() && (badGrammarPhrase.isEmpty() || spellingLocation <= grammarDetailLocation)) { 396 if (!misspelledWord.isEmpty() && (badGrammarPhrase.isEmpty() || spellingLocation <= grammarDetailLocation)) {
390 int spellingOffset = spellingLocation - currentStartOffset; 397 int spellingOffset = spellingLocation - currentStartOffset;
391 if (!firstIteration) 398 if (!firstIteration)
392 spellingOffset += TextIterator::rangeLength(m_start, par agraphStart); 399 spellingOffset += TextIterator::rangeLength(m_start, par agraphStart);
393 outIsSpelling = true; 400 outIsSpelling = true;
394 outFirstFoundOffset = spellingOffset; 401 outFirstFoundOffset = spellingOffset;
(...skipping 23 matching lines...) Expand all
418 } 425 }
419 426
420 int TextCheckingHelper::findFirstGrammarDetail(const Vector<GrammarDetail>& gram marDetails, int badGrammarPhraseLocation, int startOffset, int endOffset, bool m arkAll) const 427 int TextCheckingHelper::findFirstGrammarDetail(const Vector<GrammarDetail>& gram marDetails, int badGrammarPhraseLocation, int startOffset, int endOffset, bool m arkAll) const
421 { 428 {
422 // Found some bad grammar. Find the earliest detail range that starts in our search range (if any). 429 // Found some bad grammar. Find the earliest detail range that starts in our search range (if any).
423 // Optionally add a DocumentMarker for each detail in the range. 430 // Optionally add a DocumentMarker for each detail in the range.
424 int earliestDetailLocationSoFar = -1; 431 int earliestDetailLocationSoFar = -1;
425 int earliestDetailIndex = -1; 432 int earliestDetailIndex = -1;
426 for (unsigned i = 0; i < grammarDetails.size(); i++) { 433 for (unsigned i = 0; i < grammarDetails.size(); i++) {
427 const GrammarDetail* detail = &grammarDetails[i]; 434 const GrammarDetail* detail = &grammarDetails[i];
428 ASSERT(detail->length > 0 && detail->location >= 0); 435 DCHECK_GT(detail->length, 0);
436 DCHECK_GE(detail->location, 0);
429 437
430 int detailStartOffsetInParagraph = badGrammarPhraseLocation + detail->lo cation; 438 int detailStartOffsetInParagraph = badGrammarPhraseLocation + detail->lo cation;
431 439
432 // Skip this detail if it starts before the original search range 440 // Skip this detail if it starts before the original search range
433 if (detailStartOffsetInParagraph < startOffset) 441 if (detailStartOffsetInParagraph < startOffset)
434 continue; 442 continue;
435 443
436 // Skip this detail if it starts after the original search range 444 // Skip this detail if it starts after the original search range
437 if (detailStartOffsetInParagraph >= endOffset) 445 if (detailStartOffsetInParagraph >= endOffset)
438 continue; 446 continue;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 478
471 // Start checking from beginning of paragraph, but skip past results that oc cur before the start of the original search range. 479 // Start checking from beginning of paragraph, but skip past results that oc cur before the start of the original search range.
472 int startOffset = 0; 480 int startOffset = 0;
473 while (startOffset < paragraph.checkingEnd()) { 481 while (startOffset < paragraph.checkingEnd()) {
474 Vector<GrammarDetail> grammarDetails; 482 Vector<GrammarDetail> grammarDetails;
475 int badGrammarPhraseLocation = -1; 483 int badGrammarPhraseLocation = -1;
476 int badGrammarPhraseLength = 0; 484 int badGrammarPhraseLength = 0;
477 m_client->textChecker().checkGrammarOfString(paragraph.textSubstring(sta rtOffset), grammarDetails, &badGrammarPhraseLocation, &badGrammarPhraseLength); 485 m_client->textChecker().checkGrammarOfString(paragraph.textSubstring(sta rtOffset), grammarDetails, &badGrammarPhraseLocation, &badGrammarPhraseLength);
478 486
479 if (!badGrammarPhraseLength) { 487 if (!badGrammarPhraseLength) {
480 ASSERT(badGrammarPhraseLocation == -1); 488 DCHECK_EQ(badGrammarPhraseLocation, -1);
481 return String(); 489 return String();
482 } 490 }
483 491
484 ASSERT(badGrammarPhraseLocation >= 0); 492 DCHECK_GE(badGrammarPhraseLocation, 0);
485 badGrammarPhraseLocation += startOffset; 493 badGrammarPhraseLocation += startOffset;
486 494
487 495
488 // Found some bad grammar. Find the earliest detail range that starts in our search range (if any). 496 // Found some bad grammar. Find the earliest detail range that starts in our search range (if any).
489 int badGrammarIndex = findFirstGrammarDetail(grammarDetails, badGrammarP hraseLocation, paragraph.checkingStart(), paragraph.checkingEnd(), markAll); 497 int badGrammarIndex = findFirstGrammarDetail(grammarDetails, badGrammarP hraseLocation, paragraph.checkingStart(), paragraph.checkingEnd(), markAll);
490 if (badGrammarIndex >= 0) { 498 if (badGrammarIndex >= 0) {
491 ASSERT(static_cast<unsigned>(badGrammarIndex) < grammarDetails.size( )); 499 DCHECK_LT(static_cast<unsigned>(badGrammarIndex), grammarDetails.siz e());
492 outGrammarDetail = grammarDetails[badGrammarIndex]; 500 outGrammarDetail = grammarDetails[badGrammarIndex];
493 } 501 }
494 502
495 // If we found a detail in range, then we have found the first bad phras e (unless we found one earlier but 503 // If we found a detail in range, then we have found the first bad phras e (unless we found one earlier but
496 // kept going so we could mark all instances). 504 // kept going so we could mark all instances).
497 if (badGrammarIndex >= 0 && firstBadGrammarPhrase.isEmpty()) { 505 if (badGrammarIndex >= 0 && firstBadGrammarPhrase.isEmpty()) {
498 outGrammarPhraseOffset = badGrammarPhraseLocation - paragraph.checki ngStart(); 506 outGrammarPhraseOffset = badGrammarPhraseLocation - paragraph.checki ngStart();
499 firstBadGrammarPhrase = paragraph.textSubstring(badGrammarPhraseLoca tion, badGrammarPhraseLength); 507 firstBadGrammarPhrase = paragraph.textSubstring(badGrammarPhraseLoca tion, badGrammarPhraseLength);
500 508
501 // Found one. We're done now, unless we're marking each instance. 509 // Found one. We're done now, unless we're marking each instance.
(...skipping 21 matching lines...) Expand all
523 { 531 {
524 // Use the "markAll" feature of findFirstBadGrammar. Ignore the return value and "out parameters"; all we need to 532 // Use the "markAll" feature of findFirstBadGrammar. Ignore the return value and "out parameters"; all we need to
525 // do is mark every instance. 533 // do is mark every instance.
526 GrammarDetail ignoredGrammarDetail; 534 GrammarDetail ignoredGrammarDetail;
527 int ignoredOffset; 535 int ignoredOffset;
528 findFirstBadGrammar(ignoredGrammarDetail, ignoredOffset, true); 536 findFirstBadGrammar(ignoredGrammarDetail, ignoredOffset, true);
529 } 537 }
530 538
531 bool TextCheckingHelper::unifiedTextCheckerEnabled() const 539 bool TextCheckingHelper::unifiedTextCheckerEnabled() const
532 { 540 {
533 ASSERT(m_start.isNotNull()); 541 DCHECK(m_start.isNotNull());
534 Document& doc = m_start.computeContainerNode()->document(); 542 Document& doc = m_start.computeContainerNode()->document();
535 return blink::unifiedTextCheckerEnabled(doc.frame()); 543 return blink::unifiedTextCheckerEnabled(doc.frame());
536 } 544 }
537 545
538 void checkTextOfParagraph(TextCheckerClient& client, const String& text, TextChe ckingTypeMask checkingTypes, Vector<TextCheckingResult>& results) 546 void checkTextOfParagraph(TextCheckerClient& client, const String& text, TextChe ckingTypeMask checkingTypes, Vector<TextCheckingResult>& results)
539 { 547 {
540 Vector<UChar> characters; 548 Vector<UChar> characters;
541 text.appendTo(characters); 549 text.appendTo(characters);
542 unsigned length = text.length(); 550 unsigned length = text.length();
543 551
(...skipping 30 matching lines...) Expand all
574 return false; 582 return false;
575 583
576 const Settings* settings = frame->settings(); 584 const Settings* settings = frame->settings();
577 if (!settings) 585 if (!settings)
578 return false; 586 return false;
579 587
580 return settings->unifiedTextCheckerEnabled(); 588 return settings->unifiedTextCheckerEnabled();
581 } 589 }
582 590
583 } // namespace blink 591 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698