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

Side by Side Diff: third_party/WebKit/Source/core/editing/spellcheck/SpellChecker.cpp

Issue 2199743003: Remove some grammar checking code from SpellChecker (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address review comments Created 4 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
« no previous file with comments | « third_party/WebKit/Source/core/editing/spellcheck/SpellChecker.h ('k') | no next file » | 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 374 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 } else { 385 } else {
386 markAllMisspellingsAndBadGrammarInRanges(textCheckingOptions, adjace ntWords.toNormalizedEphemeralRange(), adjacentWords.toNormalizedEphemeralRange() ); 386 markAllMisspellingsAndBadGrammarInRanges(textCheckingOptions, adjace ntWords.toNormalizedEphemeralRange(), adjacentWords.toNormalizedEphemeralRange() );
387 } 387 }
388 return; 388 return;
389 } 389 }
390 390
391 if (!isContinuousSpellCheckingEnabled()) 391 if (!isContinuousSpellCheckingEnabled())
392 return; 392 return;
393 393
394 // Check spelling of one word 394 // Check spelling of one word
395 bool result = markMisspellings(VisibleSelection(startOfWord(wordStart, LeftW ordIfOnBoundary), endOfWord(wordStart, RightWordIfOnBoundary))); 395 markMisspellings(VisibleSelection(startOfWord(wordStart, LeftWordIfOnBoundar y), endOfWord(wordStart, RightWordIfOnBoundary)));
396
397 if (!result)
398 return;
399
400 // Check grammar of entire sentence
401 markBadGrammar(VisibleSelection(startOfSentence(wordStart), endOfSentence(wo rdStart)));
402 }
403
404 bool SpellChecker::markMisspellingsOrBadGrammar(const VisibleSelection& selectio n, bool checkSpelling)
405 {
406 // This function is called with a selection already expanded to word boundar ies.
407 // Might be nice to assert that here.
408
409 // This function is used only for as-you-type checking, so if that's off we do nothing. Note that
410 // grammar checking can only be on if spell checking is also on.
411 if (!isContinuousSpellCheckingEnabled())
412 return false;
413
414 TRACE_EVENT0("blink", "SpellChecker::markMisspellingsOrBadGrammar");
415
416 const EphemeralRange range = selection.toNormalizedEphemeralRange();
417 if (range.isNull())
418 return false;
419
420 // If we're not in an editable node, bail.
421 Node* editableNode = range.startPosition().computeContainerNode();
422 if (!editableNode || !hasEditableStyle(*editableNode))
423 return false;
424
425 if (!isSpellCheckingEnabledFor(editableNode))
426 return false;
427
428 TextCheckingHelper checker(spellCheckerClient(), range.startPosition(), rang e.endPosition());
429 if (checkSpelling)
430 return checker.markAllMisspellings();
431
432 checker.markAllBadGrammar();
433 return false;
434 } 396 }
435 397
436 bool SpellChecker::isSpellCheckingEnabledFor(Node* node) const 398 bool SpellChecker::isSpellCheckingEnabledFor(Node* node) const
437 { 399 {
438 if (!node) 400 if (!node)
439 return false; 401 return false;
440 const Element* focusedElement = node->isElementNode() ? toElement(node) : no de->parentElement(); 402 const Element* focusedElement = node->isElementNode() ? toElement(node) : no de->parentElement();
441 if (!focusedElement) 403 if (!focusedElement)
442 return false; 404 return false;
443 return focusedElement->isSpellCheckingEnabled(); 405 return focusedElement->isSpellCheckingEnabled();
(...skipping 14 matching lines...) Expand all
458 if (isHTMLInputElement(textControl) && toHTMLInputElement(textControl)-> type() == InputTypeNames::password) 420 if (isHTMLInputElement(textControl) && toHTMLInputElement(textControl)-> type() == InputTypeNames::password)
459 return false; 421 return false;
460 } 422 }
461 if (HTMLElement* element = Traversal<HTMLElement>::firstAncestorOrSelf(*sele ction.start().anchorNode())) { 423 if (HTMLElement* element = Traversal<HTMLElement>::firstAncestorOrSelf(*sele ction.start().anchorNode())) {
462 if (element->spellcheck()) 424 if (element->spellcheck())
463 return true; 425 return true;
464 } 426 }
465 return false; 427 return false;
466 } 428 }
467 429
468 bool SpellChecker::markMisspellings(const VisibleSelection& selection) 430 void SpellChecker::markMisspellings(const VisibleSelection& selection)
469 { 431 {
470 return markMisspellingsOrBadGrammar(selection, true); 432 // This function is called with a selection already expanded to word boundar ies.
471 } 433 // TODO(xiaochengh): Might be nice to assert that here.
472 434
473 void SpellChecker::markBadGrammar(const VisibleSelection& selection) 435 // This function is used only for as-you-type checking, so if that's off we do nothing. Note that
474 { 436 // grammar checking can only be on if spell checking is also on.
475 markMisspellingsOrBadGrammar(selection, false); 437 if (!isContinuousSpellCheckingEnabled())
438 return;
439
440 TRACE_EVENT0("blink", "SpellChecker::markMisspellings");
441
442 const EphemeralRange& range = selection.toNormalizedEphemeralRange();
443 if (range.isNull())
444 return;
445
446 // If we're not in an editable node, bail.
447 Node* editableNode = range.startPosition().computeContainerNode();
448 if (!editableNode || !hasEditableStyle(*editableNode))
449 return;
450
451 if (!isSpellCheckingEnabledFor(editableNode))
452 return;
453
454 TextCheckingHelper checker(spellCheckerClient(), range.startPosition(), rang e.endPosition());
455 checker.markAllMisspellings();
476 } 456 }
477 457
478 void SpellChecker::markAllMisspellingsAndBadGrammarInRanges(TextCheckingTypeMask textCheckingOptions, const EphemeralRange& spellingRange, const EphemeralRange& grammarRange) 458 void SpellChecker::markAllMisspellingsAndBadGrammarInRanges(TextCheckingTypeMask textCheckingOptions, const EphemeralRange& spellingRange, const EphemeralRange& grammarRange)
479 { 459 {
480 DCHECK(unifiedTextCheckerEnabled()); 460 DCHECK(unifiedTextCheckerEnabled());
481 461
482 bool shouldMarkGrammar = textCheckingOptions & TextCheckingTypeGrammar; 462 bool shouldMarkGrammar = textCheckingOptions & TextCheckingTypeGrammar;
483 463
484 // This function is called with selections already expanded to word boundari es. 464 // This function is called with selections already expanded to word boundari es.
485 if (spellingRange.isNull() || (shouldMarkGrammar && grammarRange.isNull())) 465 if (spellingRange.isNull() || (shouldMarkGrammar && grammarRange.isNull()))
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
674 654
675 // markMisspellingsAndBadGrammar() is triggered by selection change, in which case we check spelling and grammar, but don't autocorrect misspellings. 655 // markMisspellingsAndBadGrammar() is triggered by selection change, in which case we check spelling and grammar, but don't autocorrect misspellings.
676 TextCheckingTypeMask textCheckingOptions = TextCheckingTypeSpelling; 656 TextCheckingTypeMask textCheckingOptions = TextCheckingTypeSpelling;
677 if (markGrammar) 657 if (markGrammar)
678 textCheckingOptions |= TextCheckingTypeGrammar; 658 textCheckingOptions |= TextCheckingTypeGrammar;
679 markAllMisspellingsAndBadGrammarInRanges(textCheckingOptions, spellingSe lection.toNormalizedEphemeralRange(), grammarSelection.toNormalizedEphemeralRang e()); 659 markAllMisspellingsAndBadGrammarInRanges(textCheckingOptions, spellingSe lection.toNormalizedEphemeralRange(), grammarSelection.toNormalizedEphemeralRang e());
680 return; 660 return;
681 } 661 }
682 662
683 markMisspellings(spellingSelection); 663 markMisspellings(spellingSelection);
684 if (markGrammar)
685 markBadGrammar(grammarSelection);
686 } 664 }
687 665
688 void SpellChecker::updateMarkersForWordsAffectedByEditing(bool doNotRemoveIfSele ctionAtWordBoundary) 666 void SpellChecker::updateMarkersForWordsAffectedByEditing(bool doNotRemoveIfSele ctionAtWordBoundary)
689 { 667 {
690 DCHECK(frame().selection().isAvailable()); 668 DCHECK(frame().selection().isAvailable());
691 TRACE_EVENT0("blink", "SpellChecker::updateMarkersForWordsAffectedByEditing" ); 669 TRACE_EVENT0("blink", "SpellChecker::updateMarkersForWordsAffectedByEditing" );
692 if (!isSpellCheckingEnabledFor(frame().selection().selection())) 670 if (!isSpellCheckingEnabledFor(frame().selection().selection()))
693 return; 671 return;
694 672
695 // We want to remove the markers from a word if an editing command will chan ge the word. This can happen in one of 673 // We want to remove the markers from a word if an editing command will chan ge the word. This can happen in one of
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
978 visitor->trace(m_frame); 956 visitor->trace(m_frame);
979 visitor->trace(m_spellCheckRequester); 957 visitor->trace(m_spellCheckRequester);
980 } 958 }
981 959
982 void SpellChecker::prepareForLeakDetection() 960 void SpellChecker::prepareForLeakDetection()
983 { 961 {
984 m_spellCheckRequester->prepareForLeakDetection(); 962 m_spellCheckRequester->prepareForLeakDetection();
985 } 963 }
986 964
987 } // namespace blink 965 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/editing/spellcheck/SpellChecker.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698