Chromium Code Reviews| 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 1457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1468 | 1468 |
| 1469 // If we're not in an editable node, bail. | 1469 // If we're not in an editable node, bail. |
| 1470 Node* editableNode = spellingRange->startContainer(); | 1470 Node* editableNode = spellingRange->startContainer(); |
| 1471 if (!editableNode || !editableNode->rendererIsEditable()) | 1471 if (!editableNode || !editableNode->rendererIsEditable()) |
| 1472 return; | 1472 return; |
| 1473 | 1473 |
| 1474 if (!isSpellCheckingEnabledFor(editableNode)) | 1474 if (!isSpellCheckingEnabledFor(editableNode)) |
| 1475 return; | 1475 return; |
| 1476 | 1476 |
| 1477 Range* rangeToCheck = shouldMarkGrammar ? grammarRange : spellingRange; | 1477 Range* rangeToCheck = shouldMarkGrammar ? grammarRange : spellingRange; |
| 1478 TextCheckingParagraph paragraphToCheck(rangeToCheck); | 1478 TextCheckingParagraph fullParagraphToCheck(rangeToCheck); |
| 1479 if (paragraphToCheck.isRangeEmpty() || paragraphToCheck.isEmpty()) | 1479 if (fullParagraphToCheck.isRangeEmpty() || fullParagraphToCheck.isEmpty()) |
| 1480 return; | 1480 return; |
| 1481 RefPtr<Range> paragraphRange = paragraphToCheck.paragraphRange(); | |
| 1482 | 1481 |
| 1482 // Since the text may be quite big chunk it up and adjust to the sentence bo undary. | |
| 1483 const int kChunkSize = 16 * 1024; | |
| 1484 int start = fullParagraphToCheck.checkingStart(); | |
| 1485 int end = fullParagraphToCheck.checkingEnd(); | |
| 1486 start = std::min(start, end); | |
| 1487 end = std::max(start, end); | |
| 1483 bool asynchronous = m_frame && m_frame->settings() && m_frame->settings()->a synchronousSpellCheckingEnabled(); | 1488 bool asynchronous = m_frame && m_frame->settings() && m_frame->settings()->a synchronousSpellCheckingEnabled(); |
| 1489 const int kNumChunksToCheck = asynchronous ? (end - start + kChunkSize - 1) / (kChunkSize) : 1; | |
| 1490 int currentChunkStart = start; | |
| 1491 RefPtr<Range> checkRange = asynchronous ? fullParagraphToCheck.paragraphRang e() : rangeToCheck; | |
| 1492 RefPtr<Range> paragraphRange = fullParagraphToCheck.paragraphRange(); | |
| 1493 if (kNumChunksToCheck == 1 && asynchronous) { | |
| 1494 markAllMisspellingsAndBadGrammarInRanges(textCheckingOptions, checkRange .get(), paragraphRange.get(), true, 0); | |
|
tony
2013/08/19 21:50:02
Nit: true -> asynchronous.
| |
| 1495 return; | |
| 1496 } | |
| 1484 | 1497 |
| 1485 // In asynchronous mode, we intentionally check paragraph-wide sentence. | 1498 for (int iter = 0; iter < kNumChunksToCheck; ++iter) { |
| 1486 RefPtr<SpellCheckRequest> request = SpellCheckRequest::create(resolveTextChe ckingTypeMask(textCheckingOptions), TextCheckingProcessIncremental, asynchronous ? paragraphRange : rangeToCheck, paragraphRange); | 1499 checkRange = fullParagraphToCheck.subrange(currentChunkStart, kChunkSize ); |
| 1500 setStart(checkRange.get(), startOfSentence(checkRange->startPosition())) ; | |
| 1501 setEnd(checkRange.get(), endOfSentence(checkRange->endPosition())); | |
| 1502 paragraphRange = checkRange; | |
| 1503 | |
| 1504 int checkingLength = 0; | |
| 1505 markAllMisspellingsAndBadGrammarInRanges(textCheckingOptions, checkRange .get(), paragraphRange.get(), asynchronous, iter, &checkingLength); | |
| 1506 currentChunkStart += checkingLength; | |
| 1507 } | |
| 1508 } | |
| 1509 | |
| 1510 void Editor::markAllMisspellingsAndBadGrammarInRanges(TextCheckingTypeMask textC heckingOptions, Range* checkRange, Range* paragraphRange, bool asynchronous, int requestNumber, int* checkingLength) | |
| 1511 { | |
| 1512 TextCheckingParagraph sentenceToCheck(checkRange, paragraphRange); | |
| 1513 if (checkingLength) | |
| 1514 *checkingLength = sentenceToCheck.checkingLength(); | |
| 1515 | |
| 1516 RefPtr<SpellCheckRequest> request = SpellCheckRequest::create(resolveTextChe ckingTypeMask(textCheckingOptions), TextCheckingProcessBatch, checkRange, paragr aphRange, requestNumber); | |
| 1487 | 1517 |
| 1488 if (asynchronous) { | 1518 if (asynchronous) { |
| 1489 m_spellCheckRequester->requestCheckingFor(request); | 1519 m_spellCheckRequester->requestCheckingFor(request); |
| 1490 return; | 1520 } else { |
| 1521 Vector<TextCheckingResult> results; | |
| 1522 checkTextOfParagraph(textChecker(), sentenceToCheck.text(), resolveTextC heckingTypeMask(textCheckingOptions), results); | |
| 1523 markAndReplaceFor(request, results); | |
| 1491 } | 1524 } |
| 1492 | |
| 1493 Vector<TextCheckingResult> results; | |
| 1494 checkTextOfParagraph(textChecker(), paragraphToCheck.text(), resolveTextChec kingTypeMask(textCheckingOptions), results); | |
| 1495 markAndReplaceFor(request, results); | |
| 1496 } | 1525 } |
| 1497 | 1526 |
| 1498 void Editor::markAndReplaceFor(PassRefPtr<SpellCheckRequest> request, const Vect or<TextCheckingResult>& results) | 1527 void Editor::markAndReplaceFor(PassRefPtr<SpellCheckRequest> request, const Vect or<TextCheckingResult>& results) |
| 1499 { | 1528 { |
| 1500 ASSERT(request); | 1529 ASSERT(request); |
| 1501 | 1530 |
| 1502 TextCheckingTypeMask textCheckingOptions = request->data().mask(); | 1531 TextCheckingTypeMask textCheckingOptions = request->data().mask(); |
| 1503 TextCheckingParagraph paragraph(request->checkingRange(), request->paragraph Range()); | 1532 TextCheckingParagraph paragraph(request->checkingRange(), request->paragraph Range()); |
| 1504 | 1533 |
| 1505 bool shouldMarkSpelling = textCheckingOptions & TextCheckingTypeSpelling; | 1534 bool shouldMarkSpelling = textCheckingOptions & TextCheckingTypeSpelling; |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 1521 if (selectionOffset > 0 && (static_cast<unsigned>(selectionOffset) > paragraph.text().length() || paragraph.textCharAt(selectionOffset - 1) == newli neCharacter)) | 1550 if (selectionOffset > 0 && (static_cast<unsigned>(selectionOffset) > paragraph.text().length() || paragraph.textCharAt(selectionOffset - 1) == newli neCharacter)) |
| 1522 adjustSelectionForParagraphBoundaries = true; | 1551 adjustSelectionForParagraphBoundaries = true; |
| 1523 if (selectionOffset > 0 && static_cast<unsigned>(selectionOffset) <= paragraph.text().length() && isAmbiguousBoundaryCharacter(paragraph.textCharAt( selectionOffset - 1))) | 1552 if (selectionOffset > 0 && static_cast<unsigned>(selectionOffset) <= paragraph.text().length() && isAmbiguousBoundaryCharacter(paragraph.textCharAt( selectionOffset - 1))) |
| 1524 ambiguousBoundaryOffset = selectionOffset - 1; | 1553 ambiguousBoundaryOffset = selectionOffset - 1; |
| 1525 } | 1554 } |
| 1526 } | 1555 } |
| 1527 | 1556 |
| 1528 for (unsigned i = 0; i < results.size(); i++) { | 1557 for (unsigned i = 0; i < results.size(); i++) { |
| 1529 int spellingRangeEndOffset = paragraph.checkingEnd(); | 1558 int spellingRangeEndOffset = paragraph.checkingEnd(); |
| 1530 const TextCheckingResult* result = &results[i]; | 1559 const TextCheckingResult* result = &results[i]; |
| 1531 int resultLocation = result->location; | 1560 int resultLocation = result->location + paragraph.checkingStart(); |
| 1532 int resultLength = result->length; | 1561 int resultLength = result->length; |
| 1533 bool resultEndsAtAmbiguousBoundary = ambiguousBoundaryOffset >= 0 && res ultLocation + resultLength == ambiguousBoundaryOffset; | 1562 bool resultEndsAtAmbiguousBoundary = ambiguousBoundaryOffset >= 0 && res ultLocation + resultLength == ambiguousBoundaryOffset; |
| 1534 | 1563 |
| 1535 // Only mark misspelling if: | 1564 // Only mark misspelling if: |
| 1536 // 1. Current text checking isn't done for autocorrection, in which case shouldMarkSpelling is false. | 1565 // 1. Current text checking isn't done for autocorrection, in which case shouldMarkSpelling is false. |
| 1537 // 2. Result falls within spellingRange. | 1566 // 2. Result falls within spellingRange. |
| 1538 // 3. The word in question doesn't end at an ambiguous boundary. For ins tance, we would not mark | 1567 // 3. The word in question doesn't end at an ambiguous boundary. For ins tance, we would not mark |
| 1539 // "wouldn'" as misspelled right after apostrophe is typed. | 1568 // "wouldn'" as misspelled right after apostrophe is typed. |
| 1540 if (shouldMarkSpelling && result->type == TextCheckingTypeSpelling && re sultLocation >= paragraph.checkingStart() && resultLocation + resultLength <= sp ellingRangeEndOffset && !resultEndsAtAmbiguousBoundary) { | 1569 if (shouldMarkSpelling && result->type == TextCheckingTypeSpelling && re sultLocation >= paragraph.checkingStart() && resultLocation + resultLength <= sp ellingRangeEndOffset && !resultEndsAtAmbiguousBoundary) { |
| 1541 ASSERT(resultLength > 0 && resultLocation >= 0); | 1570 ASSERT(resultLength > 0 && resultLocation >= 0); |
| (...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2145 return WebCore::unifiedTextCheckerEnabled(m_frame); | 2174 return WebCore::unifiedTextCheckerEnabled(m_frame); |
| 2146 } | 2175 } |
| 2147 | 2176 |
| 2148 void Editor::toggleOverwriteModeEnabled() | 2177 void Editor::toggleOverwriteModeEnabled() |
| 2149 { | 2178 { |
| 2150 m_overwriteModeEnabled = !m_overwriteModeEnabled; | 2179 m_overwriteModeEnabled = !m_overwriteModeEnabled; |
| 2151 frame()->selection()->setShouldShowBlockCursor(m_overwriteModeEnabled); | 2180 frame()->selection()->setShouldShowBlockCursor(m_overwriteModeEnabled); |
| 2152 }; | 2181 }; |
| 2153 | 2182 |
| 2154 } // namespace WebCore | 2183 } // namespace WebCore |
| OLD | NEW |