| 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 1485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1496 | 1496 |
| 1497 // If we're not in an editable node, bail. | 1497 // If we're not in an editable node, bail. |
| 1498 Node* editableNode = spellingRange->startContainer(); | 1498 Node* editableNode = spellingRange->startContainer(); |
| 1499 if (!editableNode || !editableNode->rendererIsEditable()) | 1499 if (!editableNode || !editableNode->rendererIsEditable()) |
| 1500 return; | 1500 return; |
| 1501 | 1501 |
| 1502 if (!isSpellCheckingEnabledFor(editableNode)) | 1502 if (!isSpellCheckingEnabledFor(editableNode)) |
| 1503 return; | 1503 return; |
| 1504 | 1504 |
| 1505 Range* rangeToCheck = shouldMarkGrammar ? grammarRange : spellingRange; | 1505 Range* rangeToCheck = shouldMarkGrammar ? grammarRange : spellingRange; |
| 1506 TextCheckingParagraph paragraphToCheck(rangeToCheck); | 1506 TextCheckingParagraph fullParagraphToCheck(rangeToCheck); |
| 1507 if (paragraphToCheck.isRangeEmpty() || paragraphToCheck.isEmpty()) | 1507 if (fullParagraphToCheck.isRangeEmpty() || fullParagraphToCheck.isEmpty()) |
| 1508 return; | 1508 return; |
| 1509 RefPtr<Range> paragraphRange = paragraphToCheck.paragraphRange(); | |
| 1510 | 1509 |
| 1510 // Since the text may be quite big chunk it up and adjust to the sentence bo
undary. |
| 1511 const int kChunkSize = 16 * 1024; |
| 1512 int start = fullParagraphToCheck.checkingStart(); |
| 1513 int end = fullParagraphToCheck.checkingEnd(); |
| 1514 start = std::min(start, end); |
| 1515 end = std::max(start, end); |
| 1511 bool asynchronous = m_frame && m_frame->settings() && m_frame->settings()->a
synchronousSpellCheckingEnabled(); | 1516 bool asynchronous = m_frame && m_frame->settings() && m_frame->settings()->a
synchronousSpellCheckingEnabled(); |
| 1517 const int kNumChunksToCheck = asynchronous ? (end - start + kChunkSize - 1)
/ (kChunkSize) : 1; |
| 1518 int currentChunkStart = start; |
| 1519 for (int iter = 0; iter < kNumChunksToCheck; ++iter) { |
| 1520 RefPtr<Range> checkRange = fullParagraphToCheck.subrange(currentChunkSta
rt, kChunkSize); |
| 1521 setStart(checkRange.get(), startOfSentence(checkRange->startPosition()))
; |
| 1522 setEnd(checkRange.get(), endOfSentence(checkRange->endPosition())); |
| 1523 TextCheckingParagraph sentenceToCheck(checkRange, checkRange); |
| 1512 | 1524 |
| 1513 // In asynchronous mode, we intentionally check paragraph-wide sentence. | 1525 currentChunkStart += sentenceToCheck.checkingLength(); |
| 1514 RefPtr<SpellCheckRequest> request = SpellCheckRequest::create(resolveTextChe
ckingTypeMask(textCheckingOptions), TextCheckingProcessIncremental, asynchronous
? paragraphRange : rangeToCheck, paragraphRange); | |
| 1515 | 1526 |
| 1516 if (asynchronous) { | 1527 RefPtr<SpellCheckRequest> request = SpellCheckRequest::create(resolveTex
tCheckingTypeMask(textCheckingOptions), TextCheckingProcessBatch, checkRange, ch
eckRange, iter); |
| 1517 m_spellCheckRequester->requestCheckingFor(request); | 1528 |
| 1518 return; | 1529 if (asynchronous) { |
| 1530 m_spellCheckRequester->requestCheckingFor(request); |
| 1531 continue; |
| 1532 } |
| 1533 |
| 1534 Vector<TextCheckingResult> results; |
| 1535 checkTextOfParagraph(textChecker(), sentenceToCheck.text(), resolveTextC
heckingTypeMask(textCheckingOptions), results); |
| 1536 markAndReplaceFor(request, results); |
| 1519 } | 1537 } |
| 1520 | |
| 1521 Vector<TextCheckingResult> results; | |
| 1522 checkTextOfParagraph(textChecker(), paragraphToCheck.text(), resolveTextChec
kingTypeMask(textCheckingOptions), results); | |
| 1523 markAndReplaceFor(request, results); | |
| 1524 } | 1538 } |
| 1525 | 1539 |
| 1526 void Editor::markAndReplaceFor(PassRefPtr<SpellCheckRequest> request, const Vect
or<TextCheckingResult>& results) | 1540 void Editor::markAndReplaceFor(PassRefPtr<SpellCheckRequest> request, const Vect
or<TextCheckingResult>& results) |
| 1527 { | 1541 { |
| 1528 ASSERT(request); | 1542 ASSERT(request); |
| 1529 | 1543 |
| 1530 TextCheckingTypeMask textCheckingOptions = request->data().mask(); | 1544 TextCheckingTypeMask textCheckingOptions = request->data().mask(); |
| 1531 TextCheckingParagraph paragraph(request->checkingRange(), request->paragraph
Range()); | 1545 TextCheckingParagraph paragraph(request->checkingRange(), request->paragraph
Range()); |
| 1532 | 1546 |
| 1533 bool shouldMarkSpelling = textCheckingOptions & TextCheckingTypeSpelling; | 1547 bool shouldMarkSpelling = textCheckingOptions & TextCheckingTypeSpelling; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1549 if (selectionOffset > 0 && (static_cast<unsigned>(selectionOffset) >
paragraph.text().length() || paragraph.textCharAt(selectionOffset - 1) == newli
neCharacter)) | 1563 if (selectionOffset > 0 && (static_cast<unsigned>(selectionOffset) >
paragraph.text().length() || paragraph.textCharAt(selectionOffset - 1) == newli
neCharacter)) |
| 1550 adjustSelectionForParagraphBoundaries = true; | 1564 adjustSelectionForParagraphBoundaries = true; |
| 1551 if (selectionOffset > 0 && static_cast<unsigned>(selectionOffset) <=
paragraph.text().length() && isAmbiguousBoundaryCharacter(paragraph.textCharAt(
selectionOffset - 1))) | 1565 if (selectionOffset > 0 && static_cast<unsigned>(selectionOffset) <=
paragraph.text().length() && isAmbiguousBoundaryCharacter(paragraph.textCharAt(
selectionOffset - 1))) |
| 1552 ambiguousBoundaryOffset = selectionOffset - 1; | 1566 ambiguousBoundaryOffset = selectionOffset - 1; |
| 1553 } | 1567 } |
| 1554 } | 1568 } |
| 1555 | 1569 |
| 1556 for (unsigned i = 0; i < results.size(); i++) { | 1570 for (unsigned i = 0; i < results.size(); i++) { |
| 1557 int spellingRangeEndOffset = paragraph.checkingEnd(); | 1571 int spellingRangeEndOffset = paragraph.checkingEnd(); |
| 1558 const TextCheckingResult* result = &results[i]; | 1572 const TextCheckingResult* result = &results[i]; |
| 1559 int resultLocation = result->location; | 1573 int resultLocation = result->location + paragraph.checkingStart(); |
| 1560 int resultLength = result->length; | 1574 int resultLength = result->length; |
| 1561 bool resultEndsAtAmbiguousBoundary = ambiguousBoundaryOffset >= 0 && res
ultLocation + resultLength == ambiguousBoundaryOffset; | 1575 bool resultEndsAtAmbiguousBoundary = ambiguousBoundaryOffset >= 0 && res
ultLocation + resultLength == ambiguousBoundaryOffset; |
| 1562 | 1576 |
| 1563 // Only mark misspelling if: | 1577 // Only mark misspelling if: |
| 1564 // 1. Current text checking isn't done for autocorrection, in which case
shouldMarkSpelling is false. | 1578 // 1. Current text checking isn't done for autocorrection, in which case
shouldMarkSpelling is false. |
| 1565 // 2. Result falls within spellingRange. | 1579 // 2. Result falls within spellingRange. |
| 1566 // 3. The word in question doesn't end at an ambiguous boundary. For ins
tance, we would not mark | 1580 // 3. The word in question doesn't end at an ambiguous boundary. For ins
tance, we would not mark |
| 1567 // "wouldn'" as misspelled right after apostrophe is typed. | 1581 // "wouldn'" as misspelled right after apostrophe is typed. |
| 1568 if (shouldMarkSpelling && result->type == TextCheckingTypeSpelling && re
sultLocation >= paragraph.checkingStart() && resultLocation + resultLength <= sp
ellingRangeEndOffset && !resultEndsAtAmbiguousBoundary) { | 1582 if (shouldMarkSpelling && result->type == TextCheckingTypeSpelling && re
sultLocation >= paragraph.checkingStart() && resultLocation + resultLength <= sp
ellingRangeEndOffset && !resultEndsAtAmbiguousBoundary) { |
| 1569 ASSERT(resultLength > 0 && resultLocation >= 0); | 1583 ASSERT(resultLength > 0 && resultLocation >= 0); |
| (...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2178 return WebCore::unifiedTextCheckerEnabled(m_frame); | 2192 return WebCore::unifiedTextCheckerEnabled(m_frame); |
| 2179 } | 2193 } |
| 2180 | 2194 |
| 2181 void Editor::toggleOverwriteModeEnabled() | 2195 void Editor::toggleOverwriteModeEnabled() |
| 2182 { | 2196 { |
| 2183 m_overwriteModeEnabled = !m_overwriteModeEnabled; | 2197 m_overwriteModeEnabled = !m_overwriteModeEnabled; |
| 2184 frame()->selection()->setShouldShowBlockCursor(m_overwriteModeEnabled); | 2198 frame()->selection()->setShouldShowBlockCursor(m_overwriteModeEnabled); |
| 2185 }; | 2199 }; |
| 2186 | 2200 |
| 2187 } // namespace WebCore | 2201 } // namespace WebCore |
| OLD | NEW |