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 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 { | 174 { |
175 // Both predicates should have same result, but we check both just for sure. | 175 // Both predicates should have same result, but we check both just for sure. |
176 // We need to investigate to remove this redundancy. | 176 // We need to investigate to remove this redundancy. |
177 return isRangeEmpty() || isTextEmpty(); | 177 return isRangeEmpty() || isTextEmpty(); |
178 } | 178 } |
179 | 179 |
180 PassRefPtr<Range> TextCheckingParagraph::offsetAsRange() const | 180 PassRefPtr<Range> TextCheckingParagraph::offsetAsRange() const |
181 { | 181 { |
182 ASSERT(m_checkingRange); | 182 ASSERT(m_checkingRange); |
183 if (!m_offsetAsRange) | 183 if (!m_offsetAsRange) |
184 m_offsetAsRange = Range::create(¶graphRange()->startContainer()->doc
ument(), paragraphRange()->startPosition(), checkingRange()->startPosition()); | 184 m_offsetAsRange = Range::create(paragraphRange()->startContainer()->docu
ment(), paragraphRange()->startPosition(), checkingRange()->startPosition()); |
185 | 185 |
186 return m_offsetAsRange; | 186 return m_offsetAsRange; |
187 } | 187 } |
188 | 188 |
189 const String& TextCheckingParagraph::text() const | 189 const String& TextCheckingParagraph::text() const |
190 { | 190 { |
191 ASSERT(m_checkingRange); | 191 ASSERT(m_checkingRange); |
192 if (m_text.isEmpty()) | 192 if (m_text.isEmpty()) |
193 m_text = plainText(paragraphRange().get()); | 193 m_text = plainText(paragraphRange().get()); |
194 return m_text; | 194 return m_text; |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 outGrammarDetail.userDescription = ""; | 303 outGrammarDetail.userDescription = ""; |
304 | 304 |
305 // Expand the search range to encompass entire paragraphs, since text checki
ng needs that much context. | 305 // Expand the search range to encompass entire paragraphs, since text checki
ng needs that much context. |
306 // Determine the character offset from the start of the paragraph to the sta
rt of the original search range, | 306 // Determine the character offset from the start of the paragraph to the sta
rt of the original search range, |
307 // since we will want to ignore results in this area. | 307 // since we will want to ignore results in this area. |
308 RefPtr<Range> paragraphRange = m_range->cloneRange(IGNORE_EXCEPTION); | 308 RefPtr<Range> paragraphRange = m_range->cloneRange(IGNORE_EXCEPTION); |
309 setStart(paragraphRange.get(), startOfParagraph(m_range->startPosition())); | 309 setStart(paragraphRange.get(), startOfParagraph(m_range->startPosition())); |
310 int totalRangeLength = TextIterator::rangeLength(paragraphRange.get()); | 310 int totalRangeLength = TextIterator::rangeLength(paragraphRange.get()); |
311 setEnd(paragraphRange.get(), endOfParagraph(m_range->startPosition())); | 311 setEnd(paragraphRange.get(), endOfParagraph(m_range->startPosition())); |
312 | 312 |
313 RefPtr<Range> offsetAsRange = Range::create(¶graphRange->startContainer(
)->document(), paragraphRange->startPosition(), m_range->startPosition()); | 313 RefPtr<Range> offsetAsRange = Range::create(paragraphRange->startContainer()
->document(), paragraphRange->startPosition(), m_range->startPosition()); |
314 int rangeStartOffset = TextIterator::rangeLength(offsetAsRange.get()); | 314 int rangeStartOffset = TextIterator::rangeLength(offsetAsRange.get()); |
315 int totalLengthProcessed = 0; | 315 int totalLengthProcessed = 0; |
316 | 316 |
317 bool firstIteration = true; | 317 bool firstIteration = true; |
318 bool lastIteration = false; | 318 bool lastIteration = false; |
319 while (totalLengthProcessed < totalRangeLength) { | 319 while (totalLengthProcessed < totalRangeLength) { |
320 // Iterate through the search range by paragraphs, checking each one for
spelling and grammar. | 320 // Iterate through the search range by paragraphs, checking each one for
spelling and grammar. |
321 int currentLength = TextIterator::rangeLength(paragraphRange.get()); | 321 int currentLength = TextIterator::rangeLength(paragraphRange.get()); |
322 int currentStartOffset = firstIteration ? rangeStartOffset : 0; | 322 int currentStartOffset = firstIteration ? rangeStartOffset : 0; |
323 int currentEndOffset = currentLength; | 323 int currentEndOffset = currentLength; |
324 if (inSameParagraph(paragraphRange->startPosition(), m_range->endPositio
n())) { | 324 if (inSameParagraph(paragraphRange->startPosition(), m_range->endPositio
n())) { |
325 // Determine the character offset from the end of the original searc
h range to the end of the paragraph, | 325 // Determine the character offset from the end of the original searc
h range to the end of the paragraph, |
326 // since we will want to ignore results in this area. | 326 // since we will want to ignore results in this area. |
327 RefPtr<Range> endOffsetAsRange = Range::create(¶graphRange->star
tContainer()->document(), paragraphRange->startPosition(), m_range->endPosition(
)); | 327 RefPtr<Range> endOffsetAsRange = Range::create(paragraphRange->start
Container()->document(), paragraphRange->startPosition(), m_range->endPosition()
); |
328 currentEndOffset = TextIterator::rangeLength(endOffsetAsRange.get())
; | 328 currentEndOffset = TextIterator::rangeLength(endOffsetAsRange.get())
; |
329 lastIteration = true; | 329 lastIteration = true; |
330 } | 330 } |
331 if (currentStartOffset < currentEndOffset) { | 331 if (currentStartOffset < currentEndOffset) { |
332 String paragraphString = plainText(paragraphRange.get()); | 332 String paragraphString = plainText(paragraphRange.get()); |
333 if (paragraphString.length() > 0) { | 333 if (paragraphString.length() > 0) { |
334 bool foundGrammar = false; | 334 bool foundGrammar = false; |
335 int spellingLocation = 0; | 335 int spellingLocation = 0; |
336 int grammarPhraseLocation = 0; | 336 int grammarPhraseLocation = 0; |
337 int grammarDetailLocation = 0; | 337 int grammarDetailLocation = 0; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 outGrammarDetail = result->details[grammarDetailInde
x]; | 370 outGrammarDetail = result->details[grammarDetailInde
x]; |
371 badGrammarPhrase = paragraphString.substring(result-
>location, result->length); | 371 badGrammarPhrase = paragraphString.substring(result-
>location, result->length); |
372 ASSERT(badGrammarPhrase.length()); | 372 ASSERT(badGrammarPhrase.length()); |
373 } | 373 } |
374 } | 374 } |
375 } | 375 } |
376 | 376 |
377 if (!misspelledWord.isEmpty() && (!checkGrammar || badGrammarPhr
ase.isEmpty() || spellingLocation <= grammarDetailLocation)) { | 377 if (!misspelledWord.isEmpty() && (!checkGrammar || badGrammarPhr
ase.isEmpty() || spellingLocation <= grammarDetailLocation)) { |
378 int spellingOffset = spellingLocation - currentStartOffset; | 378 int spellingOffset = spellingLocation - currentStartOffset; |
379 if (!firstIteration) { | 379 if (!firstIteration) { |
380 RefPtr<Range> paragraphOffsetAsRange = Range::create(&pa
ragraphRange->startContainer()->document(), m_range->startPosition(), paragraphR
ange->startPosition()); | 380 RefPtr<Range> paragraphOffsetAsRange = Range::create(par
agraphRange->startContainer()->document(), m_range->startPosition(), paragraphRa
nge->startPosition()); |
381 spellingOffset += TextIterator::rangeLength(paragraphOff
setAsRange.get()); | 381 spellingOffset += TextIterator::rangeLength(paragraphOff
setAsRange.get()); |
382 } | 382 } |
383 outIsSpelling = true; | 383 outIsSpelling = true; |
384 outFirstFoundOffset = spellingOffset; | 384 outFirstFoundOffset = spellingOffset; |
385 firstFoundItem = misspelledWord; | 385 firstFoundItem = misspelledWord; |
386 break; | 386 break; |
387 } | 387 } |
388 if (checkGrammar && !badGrammarPhrase.isEmpty()) { | 388 if (checkGrammar && !badGrammarPhrase.isEmpty()) { |
389 int grammarPhraseOffset = grammarPhraseLocation - currentSta
rtOffset; | 389 int grammarPhraseOffset = grammarPhraseLocation - currentSta
rtOffset; |
390 if (!firstIteration) { | 390 if (!firstIteration) { |
391 RefPtr<Range> paragraphOffsetAsRange = Range::create(&pa
ragraphRange->startContainer()->document(), m_range->startPosition(), paragraphR
ange->startPosition()); | 391 RefPtr<Range> paragraphOffsetAsRange = Range::create(par
agraphRange->startContainer()->document(), m_range->startPosition(), paragraphRa
nge->startPosition()); |
392 grammarPhraseOffset += TextIterator::rangeLength(paragra
phOffsetAsRange.get()); | 392 grammarPhraseOffset += TextIterator::rangeLength(paragra
phOffsetAsRange.get()); |
393 } | 393 } |
394 outIsSpelling = false; | 394 outIsSpelling = false; |
395 outFirstFoundOffset = grammarPhraseOffset; | 395 outFirstFoundOffset = grammarPhraseOffset; |
396 firstFoundItem = badGrammarPhrase; | 396 firstFoundItem = badGrammarPhrase; |
397 break; | 397 break; |
398 } | 398 } |
399 } | 399 } |
400 } | 400 } |
401 if (lastIteration || totalLengthProcessed + currentLength >= totalRangeL
ength) | 401 if (lastIteration || totalLengthProcessed + currentLength >= totalRangeL
ength) |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
518 GrammarDetail ignoredGrammarDetail; | 518 GrammarDetail ignoredGrammarDetail; |
519 int ignoredOffset; | 519 int ignoredOffset; |
520 findFirstBadGrammar(ignoredGrammarDetail, ignoredOffset, true); | 520 findFirstBadGrammar(ignoredGrammarDetail, ignoredOffset, true); |
521 } | 521 } |
522 | 522 |
523 bool TextCheckingHelper::unifiedTextCheckerEnabled() const | 523 bool TextCheckingHelper::unifiedTextCheckerEnabled() const |
524 { | 524 { |
525 if (!m_range) | 525 if (!m_range) |
526 return false; | 526 return false; |
527 | 527 |
528 Document* doc = m_range->ownerDocument(); | 528 Document& doc = m_range->ownerDocument(); |
529 if (!doc) | 529 return WebCore::unifiedTextCheckerEnabled(doc.frame()); |
530 return false; | |
531 | |
532 return WebCore::unifiedTextCheckerEnabled(doc->frame()); | |
533 } | 530 } |
534 | 531 |
535 void checkTextOfParagraph(TextCheckerClient& client, const String& text, TextChe
ckingTypeMask checkingTypes, Vector<TextCheckingResult>& results) | 532 void checkTextOfParagraph(TextCheckerClient& client, const String& text, TextChe
ckingTypeMask checkingTypes, Vector<TextCheckingResult>& results) |
536 { | 533 { |
537 Vector<UChar> characters; | 534 Vector<UChar> characters; |
538 text.appendTo(characters); | 535 text.appendTo(characters); |
539 unsigned length = text.length(); | 536 unsigned length = text.length(); |
540 | 537 |
541 Vector<TextCheckingResult> spellingResult; | 538 Vector<TextCheckingResult> spellingResult; |
542 if (checkingTypes & TextCheckingTypeSpelling) | 539 if (checkingTypes & TextCheckingTypeSpelling) |
(...skipping 28 matching lines...) Expand all Loading... |
571 return false; | 568 return false; |
572 | 569 |
573 const Settings* settings = frame->settings(); | 570 const Settings* settings = frame->settings(); |
574 if (!settings) | 571 if (!settings) |
575 return false; | 572 return false; |
576 | 573 |
577 return settings->unifiedTextCheckerEnabled(); | 574 return settings->unifiedTextCheckerEnabled(); |
578 } | 575 } |
579 | 576 |
580 } | 577 } |
OLD | NEW |