OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2006, 2007, 2008, 2011 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007, 2008, 2011 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 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 return; | 306 return; |
307 | 307 |
308 // If we're not in an editable node, bail. | 308 // If we're not in an editable node, bail. |
309 Node* editableNode = range.startPosition().computeContainerNode(); | 309 Node* editableNode = range.startPosition().computeContainerNode(); |
310 if (!editableNode || !hasEditableStyle(*editableNode)) | 310 if (!editableNode || !hasEditableStyle(*editableNode)) |
311 return; | 311 return; |
312 | 312 |
313 if (!isSpellCheckingEnabledFor(editableNode)) | 313 if (!isSpellCheckingEnabledFor(editableNode)) |
314 return; | 314 return; |
315 | 315 |
316 TextCheckingParagraph fullParagraphToCheck(expandRangeToSentenceBoundary(ran
ge)); | 316 chunkAndMarkAllMisspellingsAndBadGrammar(range); |
317 chunkAndMarkAllMisspellingsAndBadGrammar(fullParagraphToCheck); | |
318 } | 317 } |
319 | 318 |
320 void SpellChecker::markMisspellingsAfterApplyingCommand(const CompositeEditComma
nd& cmd) | 319 void SpellChecker::markMisspellingsAfterApplyingCommand(const CompositeEditComma
nd& cmd) |
321 { | 320 { |
322 if (!isSpellCheckingEnabled()) | 321 if (!isSpellCheckingEnabled()) |
323 return; | 322 return; |
324 if (!isSpellCheckingEnabledFor(cmd.endingSelection())) | 323 if (!isSpellCheckingEnabledFor(cmd.endingSelection())) |
325 return; | 324 return; |
326 | 325 |
327 // Use type-based conditioning instead of polymorphism so that all spell | 326 // Use type-based conditioning instead of polymorphism so that all spell |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
416 if (element->spellcheck()) | 415 if (element->spellcheck()) |
417 return true; | 416 return true; |
418 } | 417 } |
419 return false; | 418 return false; |
420 } | 419 } |
421 | 420 |
422 void SpellChecker::markMisspellingsAfterReplaceSelectionCommand(const ReplaceSel
ectionCommand& cmd) | 421 void SpellChecker::markMisspellingsAfterReplaceSelectionCommand(const ReplaceSel
ectionCommand& cmd) |
423 { | 422 { |
424 TRACE_EVENT0("blink", "SpellChecker::markMisspellingsAfterReplaceSelectionCo
mmand"); | 423 TRACE_EVENT0("blink", "SpellChecker::markMisspellingsAfterReplaceSelectionCo
mmand"); |
425 | 424 |
426 const EphemeralRange& insertedRange = cmd.insertedRange(); | 425 chunkAndMarkAllMisspellingsAndBadGrammar(cmd.insertedRange()); |
427 if (insertedRange.isNull()) | 426 } |
| 427 |
| 428 void SpellChecker::chunkAndMarkAllMisspellingsAndBadGrammar(const EphemeralRange
& range) |
| 429 { |
| 430 if (range.isNull()) |
428 return; | 431 return; |
429 | 432 |
430 Node* node = cmd.endingSelection().rootEditableElement(); | 433 Node* rootEditableElement = rootEditableElementOf(range.startPosition()); |
431 if (!node) | 434 if (!rootEditableElement) |
432 return; | 435 return; |
433 | 436 |
434 EphemeralRange paragraphRange(Position::firstPositionInNode(node), Position:
:lastPositionInNode(node)); | 437 const EphemeralRange& fullTextRange = EphemeralRange::rangeOfContents(*rootE
ditableElement); |
435 TextCheckingParagraph textToCheck(insertedRange, paragraphRange); | 438 int fullTextLength = TextIterator::rangeLength(fullTextRange.startPosition()
, fullTextRange.endPosition()); |
436 chunkAndMarkAllMisspellingsAndBadGrammar(textToCheck); | 439 if (fullTextLength <= 0) |
437 } | |
438 | |
439 void SpellChecker::chunkAndMarkAllMisspellingsAndBadGrammar(const TextCheckingPa
ragraph& fullParagraphToCheck) | |
440 { | |
441 if (fullParagraphToCheck.isEmpty()) | |
442 return; | 440 return; |
443 const EphemeralRange& paragraphRange = fullParagraphToCheck.paragraphRange()
; | |
444 | 441 |
445 // Since the text may be quite big chunk it up and adjust to the sentence bo
undary. | 442 // Since the text may be quite big chunk it up and adjust to the sentence bo
undary. |
446 const int kChunkSize = 16 * 1024; | 443 const int kChunkSize = 16 * 1024; |
447 | 444 |
448 // Check the full paragraph instead if the paragraph is short, which saves | 445 // Check the full paragraph instead if the paragraph is short, which saves |
449 // the cost on sentence boundary finding. | 446 // the cost on sentence boundary finding. |
450 if (fullParagraphToCheck.rangeLength() <= kChunkSize) { | 447 if (fullTextLength <= kChunkSize) { |
451 SpellCheckRequest* request = SpellCheckRequest::create(TextCheckingProce
ssBatch, paragraphRange, 0); | 448 SpellCheckRequest* request = SpellCheckRequest::create(TextCheckingProce
ssBatch, fullTextRange, 0); |
452 if (request) | 449 if (request) |
453 m_spellCheckRequester->requestCheckingFor(request); | 450 m_spellCheckRequester->requestCheckingFor(request); |
454 return; | 451 return; |
455 } | 452 } |
456 | 453 |
457 CharacterIterator checkRangeIterator(fullParagraphToCheck.checkingRange(), T
extIteratorEmitsObjectReplacementCharacter); | 454 CharacterIterator checkRangeIterator(range, TextIteratorEmitsObjectReplaceme
ntCharacter); |
458 for (int requestNum = 0; !checkRangeIterator.atEnd(); requestNum++) { | 455 for (int requestNum = 0; !checkRangeIterator.atEnd(); requestNum++) { |
459 EphemeralRange chunkRange = checkRangeIterator.calculateCharacterSubrang
e(0, kChunkSize); | 456 EphemeralRange chunkRange = checkRangeIterator.calculateCharacterSubrang
e(0, kChunkSize); |
460 EphemeralRange checkRange = requestNum ? expandEndToSentenceBoundary(chu
nkRange) : expandRangeToSentenceBoundary(chunkRange); | 457 EphemeralRange checkRange = requestNum ? expandEndToSentenceBoundary(chu
nkRange) : expandRangeToSentenceBoundary(chunkRange); |
461 | 458 |
462 SpellCheckRequest* request = SpellCheckRequest::create(TextCheckingProce
ssBatch, checkRange, requestNum); | 459 SpellCheckRequest* request = SpellCheckRequest::create(TextCheckingProce
ssBatch, checkRange, requestNum); |
463 if (request) | 460 if (request) |
464 m_spellCheckRequester->requestCheckingFor(request); | 461 m_spellCheckRequester->requestCheckingFor(request); |
465 | 462 |
466 if (!checkRangeIterator.atEnd()) { | 463 if (!checkRangeIterator.atEnd()) { |
467 checkRangeIterator.advance(1); | 464 checkRangeIterator.advance(1); |
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
950 VisiblePosition newParagraphStart = startOfNextParagraph(createVisiblePo
sition(paragraphEnd)); | 947 VisiblePosition newParagraphStart = startOfNextParagraph(createVisiblePo
sition(paragraphEnd)); |
951 paragraphStart = newParagraphStart.toParentAnchoredPosition(); | 948 paragraphStart = newParagraphStart.toParentAnchoredPosition(); |
952 paragraphEnd = endOfParagraph(newParagraphStart).toParentAnchoredPositio
n(); | 949 paragraphEnd = endOfParagraph(newParagraphStart).toParentAnchoredPositio
n(); |
953 firstIteration = false; | 950 firstIteration = false; |
954 totalLengthProcessed += currentLength; | 951 totalLengthProcessed += currentLength; |
955 } | 952 } |
956 return std::make_pair(firstFoundItem, firstFoundOffset); | 953 return std::make_pair(firstFoundItem, firstFoundOffset); |
957 } | 954 } |
958 | 955 |
959 } // namespace blink | 956 } // namespace blink |
OLD | NEW |