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