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