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

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

Issue 22859062: Chunk up the text to spell check also when the text is pasted. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebase Created 7 years, 3 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
« no previous file with comments | « Source/core/editing/Editor.h ('k') | Source/core/editing/SpellCheckRequester.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 409 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 ReplaceSelectionCommand::create(*m_frame->document(), fragment, options, Edi tActionPaste)->apply(); 420 ReplaceSelectionCommand::create(*m_frame->document(), fragment, options, Edi tActionPaste)->apply();
421 revealSelectionAfterEditingOperation(); 421 revealSelectionAfterEditingOperation();
422 422
423 if (m_frame->selection().isInPasswordField() || !isContinuousSpellCheckingEn abled()) 423 if (m_frame->selection().isInPasswordField() || !isContinuousSpellCheckingEn abled())
424 return; 424 return;
425 Node* nodeToCheck = m_frame->selection().rootEditableElement(); 425 Node* nodeToCheck = m_frame->selection().rootEditableElement();
426 if (!nodeToCheck) 426 if (!nodeToCheck)
427 return; 427 return;
428 428
429 RefPtr<Range> rangeToCheck = Range::create(*m_frame->document(), firstPositi onInNode(nodeToCheck), lastPositionInNode(nodeToCheck)); 429 RefPtr<Range> rangeToCheck = Range::create(*m_frame->document(), firstPositi onInNode(nodeToCheck), lastPositionInNode(nodeToCheck));
430 m_spellCheckRequester->requestCheckingFor(SpellCheckRequest::create(resolveT extCheckingTypeMask(TextCheckingTypeSpelling | TextCheckingTypeGrammar), TextChe ckingProcessBatch, rangeToCheck, rangeToCheck)); 430 TextCheckingParagraph textToCheck(rangeToCheck, rangeToCheck);
431 bool asynchronous = true;
432 chunkAndMarkAllMisspellingsAndBadGrammar(resolveTextCheckingTypeMask(TextChe ckingTypeSpelling | TextCheckingTypeGrammar), textToCheck, asynchronous);
431 } 433 }
432 434
433 void Editor::replaceSelectionWithText(const String& text, bool selectReplacement , bool smartReplace) 435 void Editor::replaceSelectionWithText(const String& text, bool selectReplacement , bool smartReplace)
434 { 436 {
435 replaceSelectionWithFragment(createFragmentFromText(selectedRange().get(), t ext), selectReplacement, smartReplace, true); 437 replaceSelectionWithFragment(createFragmentFromText(selectedRange().get(), t ext), selectReplacement, smartReplace, true);
436 } 438 }
437 439
438 PassRefPtr<Range> Editor::selectedRange() 440 PassRefPtr<Range> Editor::selectedRange()
439 { 441 {
440 if (!m_frame) 442 if (!m_frame)
(...skipping 1087 matching lines...) Expand 10 before | Expand all | Expand 10 after
1528 // If we're not in an editable node, bail. 1530 // If we're not in an editable node, bail.
1529 Node* editableNode = spellingRange->startContainer(); 1531 Node* editableNode = spellingRange->startContainer();
1530 if (!editableNode || !editableNode->rendererIsEditable()) 1532 if (!editableNode || !editableNode->rendererIsEditable())
1531 return; 1533 return;
1532 1534
1533 if (!isSpellCheckingEnabledFor(editableNode)) 1535 if (!isSpellCheckingEnabledFor(editableNode))
1534 return; 1536 return;
1535 1537
1536 Range* rangeToCheck = shouldMarkGrammar ? grammarRange : spellingRange; 1538 Range* rangeToCheck = shouldMarkGrammar ? grammarRange : spellingRange;
1537 TextCheckingParagraph fullParagraphToCheck(rangeToCheck); 1539 TextCheckingParagraph fullParagraphToCheck(rangeToCheck);
1540
1541 bool asynchronous = m_frame && m_frame->settings() && m_frame->settings()->a synchronousSpellCheckingEnabled();
1542 chunkAndMarkAllMisspellingsAndBadGrammar(textCheckingOptions, fullParagraphT oCheck, asynchronous);
1543 }
1544
1545 void Editor::chunkAndMarkAllMisspellingsAndBadGrammar(TextCheckingTypeMask textC heckingOptions, const TextCheckingParagraph& fullParagraphToCheck, bool asynchro nous)
1546 {
1538 if (fullParagraphToCheck.isRangeEmpty() || fullParagraphToCheck.isEmpty()) 1547 if (fullParagraphToCheck.isRangeEmpty() || fullParagraphToCheck.isEmpty())
1539 return; 1548 return;
1540 1549
1541 // Since the text may be quite big chunk it up and adjust to the sentence bo undary. 1550 // Since the text may be quite big chunk it up and adjust to the sentence bo undary.
1542 const int kChunkSize = 16 * 1024; 1551 const int kChunkSize = 16 * 1024;
1543 int start = fullParagraphToCheck.checkingStart(); 1552 int start = fullParagraphToCheck.checkingStart();
1544 int end = fullParagraphToCheck.checkingEnd(); 1553 int end = fullParagraphToCheck.checkingEnd();
1545 start = std::min(start, end); 1554 start = std::min(start, end);
1546 end = std::max(start, end); 1555 end = std::max(start, end);
1547 bool asynchronous = m_frame && m_frame->settings() && m_frame->settings()->a synchronousSpellCheckingEnabled();
1548 const int kNumChunksToCheck = asynchronous ? (end - start + kChunkSize - 1) / (kChunkSize) : 1; 1556 const int kNumChunksToCheck = asynchronous ? (end - start + kChunkSize - 1) / (kChunkSize) : 1;
1549 int currentChunkStart = start; 1557 int currentChunkStart = start;
1550 RefPtr<Range> checkRange = asynchronous ? fullParagraphToCheck.paragraphRang e() : rangeToCheck; 1558 RefPtr<Range> checkRange = fullParagraphToCheck.checkingRange();
1551 RefPtr<Range> paragraphRange = fullParagraphToCheck.paragraphRange();
1552 if (kNumChunksToCheck == 1 && asynchronous) { 1559 if (kNumChunksToCheck == 1 && asynchronous) {
1553 markAllMisspellingsAndBadGrammarInRanges(textCheckingOptions, checkRange .get(), paragraphRange.get(), asynchronous, 0); 1560 markAllMisspellingsAndBadGrammarInRanges(textCheckingOptions, checkRange .get(), checkRange.get(), asynchronous, 0);
1554 return; 1561 return;
1555 } 1562 }
1556 1563
1557 for (int iter = 0; iter < kNumChunksToCheck; ++iter) { 1564 for (int iter = 0; iter < kNumChunksToCheck; ++iter) {
1558 checkRange = fullParagraphToCheck.subrange(currentChunkStart, kChunkSize ); 1565 checkRange = fullParagraphToCheck.subrange(currentChunkStart, kChunkSize );
1559 setStart(checkRange.get(), startOfSentence(checkRange->startPosition())) ; 1566 setStart(checkRange.get(), startOfSentence(checkRange->startPosition())) ;
1560 setEnd(checkRange.get(), endOfSentence(checkRange->endPosition())); 1567 setEnd(checkRange.get(), endOfSentence(checkRange->endPosition()));
1561 paragraphRange = checkRange;
1562 1568
1563 int checkingLength = 0; 1569 int checkingLength = 0;
1564 markAllMisspellingsAndBadGrammarInRanges(textCheckingOptions, checkRange .get(), paragraphRange.get(), asynchronous, iter, &checkingLength); 1570 markAllMisspellingsAndBadGrammarInRanges(textCheckingOptions, checkRange .get(), checkRange.get(), asynchronous, iter, &checkingLength);
1565 currentChunkStart += checkingLength; 1571 currentChunkStart += checkingLength;
1566 } 1572 }
1567 } 1573 }
1568 1574
1569 void Editor::markAllMisspellingsAndBadGrammarInRanges(TextCheckingTypeMask textC heckingOptions, Range* checkRange, Range* paragraphRange, bool asynchronous, int requestNumber, int* checkingLength) 1575 void Editor::markAllMisspellingsAndBadGrammarInRanges(TextCheckingTypeMask textC heckingOptions, Range* checkRange, Range* paragraphRange, bool asynchronous, int requestNumber, int* checkingLength)
1570 { 1576 {
1571 TextCheckingParagraph sentenceToCheck(checkRange, paragraphRange); 1577 TextCheckingParagraph sentenceToCheck(checkRange, paragraphRange);
1572 if (checkingLength) 1578 if (checkingLength)
1573 *checkingLength = sentenceToCheck.checkingLength(); 1579 *checkingLength = sentenceToCheck.checkingLength();
1574 1580
(...skipping 632 matching lines...) Expand 10 before | Expand all | Expand 10 after
2207 return WebCore::unifiedTextCheckerEnabled(m_frame); 2213 return WebCore::unifiedTextCheckerEnabled(m_frame);
2208 } 2214 }
2209 2215
2210 void Editor::toggleOverwriteModeEnabled() 2216 void Editor::toggleOverwriteModeEnabled()
2211 { 2217 {
2212 m_overwriteModeEnabled = !m_overwriteModeEnabled; 2218 m_overwriteModeEnabled = !m_overwriteModeEnabled;
2213 frame().selection().setShouldShowBlockCursor(m_overwriteModeEnabled); 2219 frame().selection().setShouldShowBlockCursor(m_overwriteModeEnabled);
2214 }; 2220 };
2215 2221
2216 } // namespace WebCore 2222 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/editing/Editor.h ('k') | Source/core/editing/SpellCheckRequester.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698