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 for (int iter = 0; iter < kNumChunksToCheck; ++iter) { | |
| 1494 if (kNumChunksToCheck > 1 || !asynchronous) { | |
|
tony
2013/08/19 20:01:15
Having if (kNumChunksToCheck) conditions in the fo
| |
| 1495 checkRange = fullParagraphToCheck.subrange(currentChunkStart, kChunk Size); | |
| 1496 setStart(checkRange.get(), startOfSentence(checkRange->startPosition ())); | |
| 1497 setEnd(checkRange.get(), endOfSentence(checkRange->endPosition())); | |
| 1498 paragraphRange = checkRange; | |
| 1499 } | |
| 1484 | 1500 |
| 1485 // In asynchronous mode, we intentionally check paragraph-wide sentence. | 1501 TextCheckingParagraph sentenceToCheck(checkRange, paragraphRange); |
| 1486 RefPtr<SpellCheckRequest> request = SpellCheckRequest::create(resolveTextChe ckingTypeMask(textCheckingOptions), TextCheckingProcessIncremental, asynchronous ? paragraphRange : rangeToCheck, paragraphRange); | 1502 if (kNumChunksToCheck > 1) |
| 1503 currentChunkStart += sentenceToCheck.checkingLength(); | |
| 1487 | 1504 |
| 1488 if (asynchronous) { | 1505 RefPtr<SpellCheckRequest> request = SpellCheckRequest::create(resolveTex tCheckingTypeMask(textCheckingOptions), TextCheckingProcessBatch, checkRange, pa ragraphRange, iter); |
| 1489 m_spellCheckRequester->requestCheckingFor(request); | 1506 |
| 1490 return; | 1507 if (asynchronous) { |
| 1508 m_spellCheckRequester->requestCheckingFor(request); | |
| 1509 continue; | |
| 1510 } | |
| 1511 | |
| 1512 Vector<TextCheckingResult> results; | |
| 1513 checkTextOfParagraph(textChecker(), sentenceToCheck.text(), resolveTextC heckingTypeMask(textCheckingOptions), results); | |
| 1514 markAndReplaceFor(request, results); | |
| 1491 } | 1515 } |
| 1492 | |
| 1493 Vector<TextCheckingResult> results; | |
| 1494 checkTextOfParagraph(textChecker(), paragraphToCheck.text(), resolveTextChec kingTypeMask(textCheckingOptions), results); | |
| 1495 markAndReplaceFor(request, results); | |
| 1496 } | 1516 } |
| 1497 | 1517 |
| 1498 void Editor::markAndReplaceFor(PassRefPtr<SpellCheckRequest> request, const Vect or<TextCheckingResult>& results) | 1518 void Editor::markAndReplaceFor(PassRefPtr<SpellCheckRequest> request, const Vect or<TextCheckingResult>& results) |
| 1499 { | 1519 { |
| 1500 ASSERT(request); | 1520 ASSERT(request); |
| 1501 | 1521 |
| 1502 TextCheckingTypeMask textCheckingOptions = request->data().mask(); | 1522 TextCheckingTypeMask textCheckingOptions = request->data().mask(); |
| 1503 TextCheckingParagraph paragraph(request->checkingRange(), request->paragraph Range()); | 1523 TextCheckingParagraph paragraph(request->checkingRange(), request->paragraph Range()); |
| 1504 | 1524 |
| 1505 bool shouldMarkSpelling = textCheckingOptions & TextCheckingTypeSpelling; | 1525 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)) | 1541 if (selectionOffset > 0 && (static_cast<unsigned>(selectionOffset) > paragraph.text().length() || paragraph.textCharAt(selectionOffset - 1) == newli neCharacter)) |
| 1522 adjustSelectionForParagraphBoundaries = true; | 1542 adjustSelectionForParagraphBoundaries = true; |
| 1523 if (selectionOffset > 0 && static_cast<unsigned>(selectionOffset) <= paragraph.text().length() && isAmbiguousBoundaryCharacter(paragraph.textCharAt( selectionOffset - 1))) | 1543 if (selectionOffset > 0 && static_cast<unsigned>(selectionOffset) <= paragraph.text().length() && isAmbiguousBoundaryCharacter(paragraph.textCharAt( selectionOffset - 1))) |
| 1524 ambiguousBoundaryOffset = selectionOffset - 1; | 1544 ambiguousBoundaryOffset = selectionOffset - 1; |
| 1525 } | 1545 } |
| 1526 } | 1546 } |
| 1527 | 1547 |
| 1528 for (unsigned i = 0; i < results.size(); i++) { | 1548 for (unsigned i = 0; i < results.size(); i++) { |
| 1529 int spellingRangeEndOffset = paragraph.checkingEnd(); | 1549 int spellingRangeEndOffset = paragraph.checkingEnd(); |
| 1530 const TextCheckingResult* result = &results[i]; | 1550 const TextCheckingResult* result = &results[i]; |
| 1531 int resultLocation = result->location; | 1551 int resultLocation = result->location + paragraph.checkingStart(); |
| 1532 int resultLength = result->length; | 1552 int resultLength = result->length; |
| 1533 bool resultEndsAtAmbiguousBoundary = ambiguousBoundaryOffset >= 0 && res ultLocation + resultLength == ambiguousBoundaryOffset; | 1553 bool resultEndsAtAmbiguousBoundary = ambiguousBoundaryOffset >= 0 && res ultLocation + resultLength == ambiguousBoundaryOffset; |
| 1534 | 1554 |
| 1535 // Only mark misspelling if: | 1555 // Only mark misspelling if: |
| 1536 // 1. Current text checking isn't done for autocorrection, in which case shouldMarkSpelling is false. | 1556 // 1. Current text checking isn't done for autocorrection, in which case shouldMarkSpelling is false. |
| 1537 // 2. Result falls within spellingRange. | 1557 // 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 | 1558 // 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. | 1559 // "wouldn'" as misspelled right after apostrophe is typed. |
| 1540 if (shouldMarkSpelling && result->type == TextCheckingTypeSpelling && re sultLocation >= paragraph.checkingStart() && resultLocation + resultLength <= sp ellingRangeEndOffset && !resultEndsAtAmbiguousBoundary) { | 1560 if (shouldMarkSpelling && result->type == TextCheckingTypeSpelling && re sultLocation >= paragraph.checkingStart() && resultLocation + resultLength <= sp ellingRangeEndOffset && !resultEndsAtAmbiguousBoundary) { |
| 1541 ASSERT(resultLength > 0 && resultLocation >= 0); | 1561 ASSERT(resultLength > 0 && resultLocation >= 0); |
| (...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2145 return WebCore::unifiedTextCheckerEnabled(m_frame); | 2165 return WebCore::unifiedTextCheckerEnabled(m_frame); |
| 2146 } | 2166 } |
| 2147 | 2167 |
| 2148 void Editor::toggleOverwriteModeEnabled() | 2168 void Editor::toggleOverwriteModeEnabled() |
| 2149 { | 2169 { |
| 2150 m_overwriteModeEnabled = !m_overwriteModeEnabled; | 2170 m_overwriteModeEnabled = !m_overwriteModeEnabled; |
| 2151 frame()->selection()->setShouldShowBlockCursor(m_overwriteModeEnabled); | 2171 frame()->selection()->setShouldShowBlockCursor(m_overwriteModeEnabled); |
| 2152 }; | 2172 }; |
| 2153 | 2173 |
| 2154 } // namespace WebCore | 2174 } // namespace WebCore |
| OLD | NEW |