OLD | NEW |
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 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
530 chunk_range.EndPosition(), check_range.EndPosition())); | 530 chunk_range.EndPosition(), check_range.EndPosition())); |
531 } | 531 } |
532 } | 532 } |
533 } | 533 } |
534 | 534 |
535 static void AddMarker(Document* document, | 535 static void AddMarker(Document* document, |
536 const EphemeralRange& checking_range, | 536 const EphemeralRange& checking_range, |
537 DocumentMarker::MarkerType type, | 537 DocumentMarker::MarkerType type, |
538 int location, | 538 int location, |
539 int length, | 539 int length, |
540 const Vector<String>& descriptions) { | 540 const String& description) { |
541 DCHECK(type == DocumentMarker::kSpelling || type == DocumentMarker::kGrammar) | 541 DCHECK(type == DocumentMarker::kSpelling || type == DocumentMarker::kGrammar) |
542 << type; | 542 << type; |
543 DCHECK_GT(length, 0); | 543 DCHECK_GT(length, 0); |
544 DCHECK_GE(location, 0); | 544 DCHECK_GE(location, 0); |
545 const EphemeralRange& range_to_mark = | 545 const EphemeralRange& range_to_mark = |
546 CalculateCharacterSubrange(checking_range, location, length); | 546 CalculateCharacterSubrange(checking_range, location, length); |
547 if (!SpellChecker::IsSpellCheckingEnabledAt(range_to_mark.StartPosition())) | 547 if (!SpellChecker::IsSpellCheckingEnabledAt(range_to_mark.StartPosition())) |
548 return; | 548 return; |
549 if (!SpellChecker::IsSpellCheckingEnabledAt(range_to_mark.EndPosition())) | 549 if (!SpellChecker::IsSpellCheckingEnabledAt(range_to_mark.EndPosition())) |
550 return; | 550 return; |
551 | 551 |
552 String description; | |
553 for (size_t i = 0; i < descriptions.size(); ++i) { | |
554 if (i != 0) | |
555 description.append('\n'); | |
556 description.append(descriptions[i]); | |
557 } | |
558 | |
559 if (type == DocumentMarker::kSpelling) { | 552 if (type == DocumentMarker::kSpelling) { |
560 document->Markers().AddSpellingMarker(range_to_mark.StartPosition(), | 553 document->Markers().AddSpellingMarker(range_to_mark.StartPosition(), |
561 range_to_mark.EndPosition(), | 554 range_to_mark.EndPosition(), |
562 description); | 555 description); |
563 return; | 556 return; |
564 } | 557 } |
565 | 558 |
566 DCHECK_EQ(type, DocumentMarker::kGrammar); | 559 DCHECK_EQ(type, DocumentMarker::kGrammar); |
567 document->Markers().AddGrammarMarker( | 560 document->Markers().AddGrammarMarker( |
568 range_to_mark.StartPosition(), range_to_mark.EndPosition(), description); | 561 range_to_mark.StartPosition(), range_to_mark.EndPosition(), description); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
644 // instance, we would not mark "wouldn'" as misspelled right after | 637 // instance, we would not mark "wouldn'" as misspelled right after |
645 // apostrophe is typed. | 638 // apostrophe is typed. |
646 switch (result.decoration) { | 639 switch (result.decoration) { |
647 case kTextDecorationTypeSpelling: | 640 case kTextDecorationTypeSpelling: |
648 if (result_location < paragraph.CheckingStart() || | 641 if (result_location < paragraph.CheckingStart() || |
649 result_location + result_length > spelling_range_end_offset || | 642 result_location + result_length > spelling_range_end_offset || |
650 result_ends_at_ambiguous_boundary) | 643 result_ends_at_ambiguous_boundary) |
651 continue; | 644 continue; |
652 AddMarker(GetFrame().GetDocument(), paragraph.CheckingRange(), | 645 AddMarker(GetFrame().GetDocument(), paragraph.CheckingRange(), |
653 DocumentMarker::kSpelling, result_location, result_length, | 646 DocumentMarker::kSpelling, result_location, result_length, |
654 result.replacements); | 647 result.replacement); |
655 continue; | 648 continue; |
656 | 649 |
657 case kTextDecorationTypeGrammar: | 650 case kTextDecorationTypeGrammar: |
658 if (!paragraph.CheckingRangeCovers(result_location, result_length)) | 651 if (!paragraph.CheckingRangeCovers(result_location, result_length)) |
659 continue; | 652 continue; |
660 DCHECK_GT(result_length, 0); | 653 DCHECK_GT(result_length, 0); |
661 DCHECK_GE(result_location, 0); | 654 DCHECK_GE(result_location, 0); |
662 for (const GrammarDetail& detail : result.details) { | 655 for (const GrammarDetail& detail : result.details) { |
663 DCHECK_GT(detail.length, 0); | 656 DCHECK_GT(detail.length, 0); |
664 DCHECK_GE(detail.location, 0); | 657 DCHECK_GE(detail.location, 0); |
665 if (!paragraph.CheckingRangeCovers(result_location + detail.location, | 658 if (!paragraph.CheckingRangeCovers(result_location + detail.location, |
666 detail.length)) | 659 detail.length)) |
667 continue; | 660 continue; |
668 AddMarker(GetFrame().GetDocument(), paragraph.CheckingRange(), | 661 AddMarker(GetFrame().GetDocument(), paragraph.CheckingRange(), |
669 DocumentMarker::kGrammar, result_location + detail.location, | 662 DocumentMarker::kGrammar, result_location + detail.location, |
670 detail.length, result.replacements); | 663 detail.length, result.replacement); |
671 } | 664 } |
672 continue; | 665 continue; |
673 } | 666 } |
674 NOTREACHED(); | 667 NOTREACHED(); |
675 } | 668 } |
676 } | 669 } |
677 | 670 |
678 void SpellChecker::UpdateMarkersForWordsAffectedByEditing( | 671 void SpellChecker::UpdateMarkersForWordsAffectedByEditing( |
679 bool do_not_remove_if_selection_at_word_boundary) { | 672 bool do_not_remove_if_selection_at_word_boundary) { |
680 if (RuntimeEnabledFeatures::idleTimeSpellCheckingEnabled()) | 673 if (RuntimeEnabledFeatures::idleTimeSpellCheckingEnabled()) |
(...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1237 if (!input.IsFocusedElementInDocument()) | 1230 if (!input.IsFocusedElementInDocument()) |
1238 return false; | 1231 return false; |
1239 } | 1232 } |
1240 } | 1233 } |
1241 HTMLElement* element = | 1234 HTMLElement* element = |
1242 Traversal<HTMLElement>::FirstAncestorOrSelf(*position.AnchorNode()); | 1235 Traversal<HTMLElement>::FirstAncestorOrSelf(*position.AnchorNode()); |
1243 return element && element->IsSpellCheckingEnabled(); | 1236 return element && element->IsSpellCheckingEnabled(); |
1244 } | 1237 } |
1245 | 1238 |
1246 } // namespace blink | 1239 } // namespace blink |
OLD | NEW |