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

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: Check if merging checks are needed at all 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
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 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 if (matchStyle) 412 if (matchStyle)
413 options |= ReplaceSelectionCommand::MatchStyle; 413 options |= ReplaceSelectionCommand::MatchStyle;
414 applyCommand(ReplaceSelectionCommand::create(m_frame->document(), fragment, options, EditActionPaste)); 414 applyCommand(ReplaceSelectionCommand::create(m_frame->document(), fragment, options, EditActionPaste));
415 revealSelectionAfterEditingOperation(); 415 revealSelectionAfterEditingOperation();
416 416
417 if (m_frame->selection()->isInPasswordField() || !isContinuousSpellCheckingE nabled()) 417 if (m_frame->selection()->isInPasswordField() || !isContinuousSpellCheckingE nabled())
418 return; 418 return;
419 Node* nodeToCheck = m_frame->selection()->rootEditableElement(); 419 Node* nodeToCheck = m_frame->selection()->rootEditableElement();
420 if (!nodeToCheck) 420 if (!nodeToCheck)
421 return; 421 return;
422
423 RefPtr<Range> rangeToCheck = Range::create(m_frame->document(), firstPositio nInNode(nodeToCheck), lastPositionInNode(nodeToCheck)); 422 RefPtr<Range> rangeToCheck = Range::create(m_frame->document(), firstPositio nInNode(nodeToCheck), lastPositionInNode(nodeToCheck));
424 m_spellCheckRequester->requestCheckingFor(SpellCheckRequest::create(resolveT extCheckingTypeMask(TextCheckingTypeSpelling | TextCheckingTypeGrammar), TextChe ckingProcessBatch, rangeToCheck, rangeToCheck)); 423 TextCheckingParagraph textToCheck(rangeToCheck, rangeToCheck);
424 chunkAndMarkAllMisspellingsAndBadGrammar(resolveTextCheckingTypeMask(TextChe ckingTypeSpelling | TextCheckingTypeGrammar), textToCheck, true);
tony 2013/08/29 22:44:45 Please use "bool asynchronous = true" and pass asy
425 } 425 }
426 426
427 void Editor::replaceSelectionWithText(const String& text, bool selectReplacement , bool smartReplace) 427 void Editor::replaceSelectionWithText(const String& text, bool selectReplacement , bool smartReplace)
428 { 428 {
429 replaceSelectionWithFragment(createFragmentFromText(selectedRange().get(), t ext), selectReplacement, smartReplace, true); 429 replaceSelectionWithFragment(createFragmentFromText(selectedRange().get(), t ext), selectReplacement, smartReplace, true);
430 } 430 }
431 431
432 PassRefPtr<Range> Editor::selectedRange() 432 PassRefPtr<Range> Editor::selectedRange()
433 { 433 {
434 if (!m_frame) 434 if (!m_frame)
(...skipping 1067 matching lines...) Expand 10 before | Expand all | Expand 10 after
1502 // If we're not in an editable node, bail. 1502 // If we're not in an editable node, bail.
1503 Node* editableNode = spellingRange->startContainer(); 1503 Node* editableNode = spellingRange->startContainer();
1504 if (!editableNode || !editableNode->rendererIsEditable()) 1504 if (!editableNode || !editableNode->rendererIsEditable())
1505 return; 1505 return;
1506 1506
1507 if (!isSpellCheckingEnabledFor(editableNode)) 1507 if (!isSpellCheckingEnabledFor(editableNode))
1508 return; 1508 return;
1509 1509
1510 Range* rangeToCheck = shouldMarkGrammar ? grammarRange : spellingRange; 1510 Range* rangeToCheck = shouldMarkGrammar ? grammarRange : spellingRange;
1511 TextCheckingParagraph fullParagraphToCheck(rangeToCheck); 1511 TextCheckingParagraph fullParagraphToCheck(rangeToCheck);
1512
1513 bool asynchronous = m_frame && m_frame->settings() && m_frame->settings()->a synchronousSpellCheckingEnabled();
1514 chunkAndMarkAllMisspellingsAndBadGrammar(textCheckingOptions, fullParagraphT oCheck, asynchronous);
1515 }
1516
1517 void Editor::chunkAndMarkAllMisspellingsAndBadGrammar(TextCheckingTypeMask textC heckingOptions, const TextCheckingParagraph& fullParagraphToCheck, bool asynchro nous)
1518 {
1512 if (fullParagraphToCheck.isRangeEmpty() || fullParagraphToCheck.isEmpty()) 1519 if (fullParagraphToCheck.isRangeEmpty() || fullParagraphToCheck.isEmpty())
1513 return; 1520 return;
1514 1521
1515 // Since the text may be quite big chunk it up and adjust to the sentence bo undary. 1522 // Since the text may be quite big chunk it up and adjust to the sentence bo undary.
1516 const int kChunkSize = 16 * 1024; 1523 const int kChunkSize = 16 * 1024;
1517 int start = fullParagraphToCheck.checkingStart(); 1524 int start = fullParagraphToCheck.checkingStart();
1518 int end = fullParagraphToCheck.checkingEnd(); 1525 int end = fullParagraphToCheck.checkingEnd();
1519 start = std::min(start, end); 1526 start = std::min(start, end);
1520 end = std::max(start, end); 1527 end = std::max(start, end);
1521 bool asynchronous = m_frame && m_frame->settings() && m_frame->settings()->a synchronousSpellCheckingEnabled();
1522 const int kNumChunksToCheck = asynchronous ? (end - start + kChunkSize - 1) / (kChunkSize) : 1; 1528 const int kNumChunksToCheck = asynchronous ? (end - start + kChunkSize - 1) / (kChunkSize) : 1;
1523 int currentChunkStart = start; 1529 int currentChunkStart = start;
1524 RefPtr<Range> checkRange = asynchronous ? fullParagraphToCheck.paragraphRang e() : rangeToCheck; 1530 RefPtr<Range> checkRange = fullParagraphToCheck.checkingRange();
1525 RefPtr<Range> paragraphRange = fullParagraphToCheck.paragraphRange();
1526 if (kNumChunksToCheck == 1 && asynchronous) { 1531 if (kNumChunksToCheck == 1 && asynchronous) {
1527 markAllMisspellingsAndBadGrammarInRanges(textCheckingOptions, checkRange .get(), paragraphRange.get(), asynchronous, 0); 1532 markAllMisspellingsAndBadGrammarInRanges(textCheckingOptions, checkRange .get(), checkRange.get(), asynchronous, 0);
1528 return; 1533 return;
1529 } 1534 }
1530 1535
1531 for (int iter = 0; iter < kNumChunksToCheck; ++iter) { 1536 for (int iter = 0; iter < kNumChunksToCheck; ++iter) {
1532 checkRange = fullParagraphToCheck.subrange(currentChunkStart, kChunkSize ); 1537 checkRange = fullParagraphToCheck.subrange(currentChunkStart, kChunkSize );
1533 setStart(checkRange.get(), startOfSentence(checkRange->startPosition())) ; 1538 setStart(checkRange.get(), startOfSentence(checkRange->startPosition())) ;
1534 setEnd(checkRange.get(), endOfSentence(checkRange->endPosition())); 1539 setEnd(checkRange.get(), endOfSentence(checkRange->endPosition()));
1535 paragraphRange = checkRange;
1536 1540
1537 int checkingLength = 0; 1541 int checkingLength = 0;
1538 markAllMisspellingsAndBadGrammarInRanges(textCheckingOptions, checkRange .get(), paragraphRange.get(), asynchronous, iter, &checkingLength); 1542 markAllMisspellingsAndBadGrammarInRanges(textCheckingOptions, checkRange .get(), checkRange.get(), asynchronous, iter, &checkingLength);
1539 currentChunkStart += checkingLength; 1543 currentChunkStart += checkingLength;
1540 } 1544 }
1541 } 1545 }
1542 1546
1543 void Editor::markAllMisspellingsAndBadGrammarInRanges(TextCheckingTypeMask textC heckingOptions, Range* checkRange, Range* paragraphRange, bool asynchronous, int requestNumber, int* checkingLength) 1547 void Editor::markAllMisspellingsAndBadGrammarInRanges(TextCheckingTypeMask textC heckingOptions, Range* checkRange, Range* paragraphRange, bool asynchronous, int requestNumber, int* checkingLength)
1544 { 1548 {
1545 TextCheckingParagraph sentenceToCheck(checkRange, paragraphRange); 1549 TextCheckingParagraph sentenceToCheck(checkRange, paragraphRange);
1546 if (checkingLength) 1550 if (checkingLength)
1547 *checkingLength = sentenceToCheck.checkingLength(); 1551 *checkingLength = sentenceToCheck.checkingLength();
1548 1552
(...skipping 653 matching lines...) Expand 10 before | Expand all | Expand 10 after
2202 return WebCore::unifiedTextCheckerEnabled(m_frame); 2206 return WebCore::unifiedTextCheckerEnabled(m_frame);
2203 } 2207 }
2204 2208
2205 void Editor::toggleOverwriteModeEnabled() 2209 void Editor::toggleOverwriteModeEnabled()
2206 { 2210 {
2207 m_overwriteModeEnabled = !m_overwriteModeEnabled; 2211 m_overwriteModeEnabled = !m_overwriteModeEnabled;
2208 frame().selection()->setShouldShowBlockCursor(m_overwriteModeEnabled); 2212 frame().selection()->setShouldShowBlockCursor(m_overwriteModeEnabled);
2209 }; 2213 };
2210 2214
2211 } // namespace WebCore 2215 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698