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

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

Issue 15179002: Remove code that is unused after ContextMenu cleanup (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Remove canHandleRequest code from DRT Created 7 years, 7 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
« no previous file with comments | « Source/core/editing/TextCheckingHelper.h ('k') | Source/core/history/BackForwardController.h » ('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 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2007 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 485 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 } 496 }
497 497
498 // These results were all between the start of the paragraph and the sta rt of the search range; look 498 // These results were all between the start of the paragraph and the sta rt of the search range; look
499 // beyond this phrase. 499 // beyond this phrase.
500 startOffset = badGrammarPhraseLocation + badGrammarPhraseLength; 500 startOffset = badGrammarPhraseLocation + badGrammarPhraseLength;
501 } 501 }
502 502
503 return firstBadGrammarPhrase; 503 return firstBadGrammarPhrase;
504 } 504 }
505 505
506
507 bool TextCheckingHelper::isUngrammatical(Vector<String>& guessesVector) const
508 {
509 if (!m_client)
510 return false;
511
512 if (!m_range || m_range->collapsed(IGNORE_EXCEPTION))
513 return false;
514
515 // Returns true only if the passed range exactly corresponds to a bad gramma r detail range. This is analogous
516 // to isSelectionMisspelled. It's not good enough for there to be some bad g rammar somewhere in the range,
517 // or overlapping the range; the ranges must exactly match.
518 guessesVector.clear();
519 int grammarPhraseOffset;
520
521 GrammarDetail grammarDetail;
522 String badGrammarPhrase = const_cast<TextCheckingHelper*>(this)->findFirstBa dGrammar(grammarDetail, grammarPhraseOffset, false);
523
524 // No bad grammar in these parts at all.
525 if (badGrammarPhrase.isEmpty())
526 return false;
527
528 // Bad grammar, but phrase (e.g. sentence) starts beyond start of range.
529 if (grammarPhraseOffset > 0)
530 return false;
531
532 ASSERT(grammarDetail.location >= 0 && grammarDetail.length > 0);
533
534 // Bad grammar, but start of detail (e.g. ungrammatical word) doesn't match start of range
535 if (grammarDetail.location + grammarPhraseOffset)
536 return false;
537
538 // Bad grammar at start of range, but end of bad grammar is before or after end of range
539 if (grammarDetail.length != TextIterator::rangeLength(m_range.get()))
540 return false;
541
542 return true;
543 }
544
545 Vector<String> TextCheckingHelper::guessesForMisspelledOrUngrammaticalRange(bool checkGrammar, bool& misspelled, bool& ungrammatical) const
546 {
547 if (!unifiedTextCheckerEnabled())
548 return Vector<String>();
549
550 Vector<String> guesses;
551 misspelled = false;
552 ungrammatical = false;
553
554 if (!m_client || !m_range || m_range->collapsed(IGNORE_EXCEPTION))
555 return guesses;
556
557 // Expand the range to encompass entire paragraphs, since text checking need s that much context.
558 TextCheckingParagraph paragraph(m_range);
559 if (paragraph.isEmpty())
560 return guesses;
561
562 Vector<TextCheckingResult> results;
563 TextCheckingTypeMask checkingTypes = checkGrammar ? (TextCheckingTypeSpellin g | TextCheckingTypeGrammar) : TextCheckingTypeSpelling;
564 checkTextOfParagraph(m_client->textChecker(), paragraph.textCharacters(), pa ragraph.textLength(), checkingTypes, results);
565
566 for (unsigned i = 0; i < results.size(); i++) {
567 const TextCheckingResult* result = &results[i];
568 if (result->type == TextCheckingTypeSpelling && paragraph.checkingRangeM atches(result->location, result->length)) {
569 String misspelledWord = paragraph.checkingSubstring();
570 ASSERT(misspelledWord.length());
571 m_client->updateSpellingUIWithMisspelledWord(misspelledWord);
572 misspelled = true;
573 return guesses;
574 }
575 }
576
577 if (!checkGrammar)
578 return guesses;
579
580 for (unsigned i = 0; i < results.size(); i++) {
581 const TextCheckingResult* result = &results[i];
582 if (result->type == TextCheckingTypeGrammar && paragraph.isCheckingRange CoveredBy(result->location, result->length)) {
583 for (unsigned j = 0; j < result->details.size(); j++) {
584 const GrammarDetail* detail = &result->details[j];
585 ASSERT(detail->length > 0 && detail->location >= 0);
586 if (paragraph.checkingRangeMatches(result->location + detail->lo cation, detail->length)) {
587 for (unsigned k = 0; k < detail->guesses.size(); k++)
588 guesses.append(detail->guesses[k]);
589 ungrammatical = true;
590 return guesses;
591 }
592 }
593 }
594 }
595 return guesses;
596 }
597
598
599 void TextCheckingHelper::markAllMisspellings(RefPtr<Range>& firstMisspellingRang e) 506 void TextCheckingHelper::markAllMisspellings(RefPtr<Range>& firstMisspellingRang e)
600 { 507 {
601 // Use the "markAll" feature of findFirstMisspelling. Ignore the return valu e and the "out parameter"; 508 // Use the "markAll" feature of findFirstMisspelling. Ignore the return valu e and the "out parameter";
602 // all we need to do is mark every instance. 509 // all we need to do is mark every instance.
603 int ignoredOffset; 510 int ignoredOffset;
604 findFirstMisspelling(ignoredOffset, true, firstMisspellingRange); 511 findFirstMisspelling(ignoredOffset, true, firstMisspellingRange);
605 } 512 }
606 513
607 void TextCheckingHelper::markAllBadGrammar() 514 void TextCheckingHelper::markAllBadGrammar()
608 { 515 {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
661 return false; 568 return false;
662 569
663 const Settings* settings = frame->settings(); 570 const Settings* settings = frame->settings();
664 if (!settings) 571 if (!settings)
665 return false; 572 return false;
666 573
667 return settings->unifiedTextCheckerEnabled(); 574 return settings->unifiedTextCheckerEnabled();
668 } 575 }
669 576
670 } 577 }
OLDNEW
« no previous file with comments | « Source/core/editing/TextCheckingHelper.h ('k') | Source/core/history/BackForwardController.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698