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