Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(178)

Side by Side Diff: Source/core/editing/Editor.cpp

Issue 23297002: Revert "Trigger spell check/remove markers if spell checker gets enabled/disabled." (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 fullParagraphToCheck(rangeToCheck); 1506 TextCheckingParagraph paragraphToCheck(rangeToCheck);
1507 if (fullParagraphToCheck.isRangeEmpty() || fullParagraphToCheck.isEmpty()) 1507 if (paragraphToCheck.isRangeEmpty() || paragraphToCheck.isEmpty())
1508 return; 1508 return;
1509 RefPtr<Range> paragraphRange = paragraphToCheck.paragraphRange();
1509 1510
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);
1516 bool asynchronous = m_frame && m_frame->settings() && m_frame->settings()->a synchronousSpellCheckingEnabled(); 1511 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);
1524 1512
1525 currentChunkStart += sentenceToCheck.checkingLength(); 1513 // In asynchronous mode, we intentionally check paragraph-wide sentence.
1514 RefPtr<SpellCheckRequest> request = SpellCheckRequest::create(resolveTextChe ckingTypeMask(textCheckingOptions), TextCheckingProcessIncremental, asynchronous ? paragraphRange : rangeToCheck, paragraphRange);
1526 1515
1527 RefPtr<SpellCheckRequest> request = SpellCheckRequest::create(resolveTex tCheckingTypeMask(textCheckingOptions), TextCheckingProcessBatch, checkRange, ch eckRange, iter); 1516 if (asynchronous) {
1517 m_spellCheckRequester->requestCheckingFor(request);
1518 return;
1519 }
1528 1520
1529 if (asynchronous) { 1521 Vector<TextCheckingResult> results;
1530 m_spellCheckRequester->requestCheckingFor(request); 1522 checkTextOfParagraph(textChecker(), paragraphToCheck.text(), resolveTextChec kingTypeMask(textCheckingOptions), results);
1531 continue; 1523 markAndReplaceFor(request, results);
1532 }
1533
1534 Vector<TextCheckingResult> results;
1535 checkTextOfParagraph(textChecker(), sentenceToCheck.text(), resolveTextC heckingTypeMask(textCheckingOptions), results);
1536 markAndReplaceFor(request, results);
1537 }
1538 } 1524 }
1539 1525
1540 void Editor::markAndReplaceFor(PassRefPtr<SpellCheckRequest> request, const Vect or<TextCheckingResult>& results) 1526 void Editor::markAndReplaceFor(PassRefPtr<SpellCheckRequest> request, const Vect or<TextCheckingResult>& results)
1541 { 1527 {
1542 ASSERT(request); 1528 ASSERT(request);
1543 1529
1544 TextCheckingTypeMask textCheckingOptions = request->data().mask(); 1530 TextCheckingTypeMask textCheckingOptions = request->data().mask();
1545 TextCheckingParagraph paragraph(request->checkingRange(), request->paragraph Range()); 1531 TextCheckingParagraph paragraph(request->checkingRange(), request->paragraph Range());
1546 1532
1547 bool shouldMarkSpelling = textCheckingOptions & TextCheckingTypeSpelling; 1533 bool shouldMarkSpelling = textCheckingOptions & TextCheckingTypeSpelling;
(...skipping 15 matching lines...) Expand all
1563 if (selectionOffset > 0 && (static_cast<unsigned>(selectionOffset) > paragraph.text().length() || paragraph.textCharAt(selectionOffset - 1) == newli neCharacter)) 1549 if (selectionOffset > 0 && (static_cast<unsigned>(selectionOffset) > paragraph.text().length() || paragraph.textCharAt(selectionOffset - 1) == newli neCharacter))
1564 adjustSelectionForParagraphBoundaries = true; 1550 adjustSelectionForParagraphBoundaries = true;
1565 if (selectionOffset > 0 && static_cast<unsigned>(selectionOffset) <= paragraph.text().length() && isAmbiguousBoundaryCharacter(paragraph.textCharAt( selectionOffset - 1))) 1551 if (selectionOffset > 0 && static_cast<unsigned>(selectionOffset) <= paragraph.text().length() && isAmbiguousBoundaryCharacter(paragraph.textCharAt( selectionOffset - 1)))
1566 ambiguousBoundaryOffset = selectionOffset - 1; 1552 ambiguousBoundaryOffset = selectionOffset - 1;
1567 } 1553 }
1568 } 1554 }
1569 1555
1570 for (unsigned i = 0; i < results.size(); i++) { 1556 for (unsigned i = 0; i < results.size(); i++) {
1571 int spellingRangeEndOffset = paragraph.checkingEnd(); 1557 int spellingRangeEndOffset = paragraph.checkingEnd();
1572 const TextCheckingResult* result = &results[i]; 1558 const TextCheckingResult* result = &results[i];
1573 int resultLocation = result->location + paragraph.checkingStart(); 1559 int resultLocation = result->location;
1574 int resultLength = result->length; 1560 int resultLength = result->length;
1575 bool resultEndsAtAmbiguousBoundary = ambiguousBoundaryOffset >= 0 && res ultLocation + resultLength == ambiguousBoundaryOffset; 1561 bool resultEndsAtAmbiguousBoundary = ambiguousBoundaryOffset >= 0 && res ultLocation + resultLength == ambiguousBoundaryOffset;
1576 1562
1577 // Only mark misspelling if: 1563 // Only mark misspelling if:
1578 // 1. Current text checking isn't done for autocorrection, in which case shouldMarkSpelling is false. 1564 // 1. Current text checking isn't done for autocorrection, in which case shouldMarkSpelling is false.
1579 // 2. Result falls within spellingRange. 1565 // 2. Result falls within spellingRange.
1580 // 3. The word in question doesn't end at an ambiguous boundary. For ins tance, we would not mark 1566 // 3. The word in question doesn't end at an ambiguous boundary. For ins tance, we would not mark
1581 // "wouldn'" as misspelled right after apostrophe is typed. 1567 // "wouldn'" as misspelled right after apostrophe is typed.
1582 if (shouldMarkSpelling && result->type == TextCheckingTypeSpelling && re sultLocation >= paragraph.checkingStart() && resultLocation + resultLength <= sp ellingRangeEndOffset && !resultEndsAtAmbiguousBoundary) { 1568 if (shouldMarkSpelling && result->type == TextCheckingTypeSpelling && re sultLocation >= paragraph.checkingStart() && resultLocation + resultLength <= sp ellingRangeEndOffset && !resultEndsAtAmbiguousBoundary) {
1583 ASSERT(resultLength > 0 && resultLocation >= 0); 1569 ASSERT(resultLength > 0 && resultLocation >= 0);
(...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after
2192 return WebCore::unifiedTextCheckerEnabled(m_frame); 2178 return WebCore::unifiedTextCheckerEnabled(m_frame);
2193 } 2179 }
2194 2180
2195 void Editor::toggleOverwriteModeEnabled() 2181 void Editor::toggleOverwriteModeEnabled()
2196 { 2182 {
2197 m_overwriteModeEnabled = !m_overwriteModeEnabled; 2183 m_overwriteModeEnabled = !m_overwriteModeEnabled;
2198 frame()->selection()->setShouldShowBlockCursor(m_overwriteModeEnabled); 2184 frame()->selection()->setShouldShowBlockCursor(m_overwriteModeEnabled);
2199 }; 2185 };
2200 2186
2201 } // namespace WebCore 2187 } // namespace WebCore
OLDNEW
« no previous file with comments | « LayoutTests/editing/spelling/spelling-huge-text-sync-expected.txt ('k') | Source/core/editing/SpellCheckRequester.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698