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 784 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
795 } | 795 } |
796 } | 796 } |
797 | 797 |
798 void SpellChecker::ReplaceMisspelledRange(const String& text) { | 798 void SpellChecker::ReplaceMisspelledRange(const String& text) { |
799 EphemeralRange caret_range = GetFrame() | 799 EphemeralRange caret_range = GetFrame() |
800 .Selection() | 800 .Selection() |
801 .ComputeVisibleSelectionInDOMTree() | 801 .ComputeVisibleSelectionInDOMTree() |
802 .ToNormalizedEphemeralRange(); | 802 .ToNormalizedEphemeralRange(); |
803 if (caret_range.IsNull()) | 803 if (caret_range.IsNull()) |
804 return; | 804 return; |
805 DocumentMarkerVector markers = | 805 |
806 GetFrame().GetDocument()->Markers().MarkersInRange( | 806 Node* found_marker_anchor_node = nullptr; |
807 caret_range, DocumentMarker::MisspellingMarkers()); | 807 const DocumentMarker* found_marker = nullptr; |
808 if (markers.size() < 1 || | 808 for (Node& node : caret_range.Nodes()) { |
809 markers[0]->StartOffset() >= markers[0]->EndOffset()) | 809 const DocumentMarkerVector& markers_in_node = |
| 810 GetFrame().GetDocument()->Markers().MarkersFor( |
| 811 &node, DocumentMarker::MisspellingMarkers()); |
| 812 for (const DocumentMarker* marker : markers_in_node) { |
| 813 if (marker->StartOffset() < marker->EndOffset()) { |
| 814 found_marker_anchor_node = &node; |
| 815 found_marker = marker; |
| 816 break; |
| 817 } |
| 818 } |
| 819 } |
| 820 |
| 821 if (!found_marker) |
810 return; | 822 return; |
| 823 |
811 EphemeralRange marker_range = EphemeralRange( | 824 EphemeralRange marker_range = EphemeralRange( |
812 Position(caret_range.StartPosition().ComputeContainerNode(), | 825 Position(found_marker_anchor_node, found_marker->StartOffset()), |
813 markers[0]->StartOffset()), | 826 Position(found_marker_anchor_node, found_marker->EndOffset())); |
814 Position(caret_range.EndPosition().ComputeContainerNode(), | |
815 markers[0]->EndOffset())); | |
816 if (marker_range.IsNull()) | 827 if (marker_range.IsNull()) |
817 return; | 828 return; |
818 | 829 |
819 GetFrame().Selection().SetSelection( | 830 GetFrame().Selection().SetSelection( |
820 SelectionInDOMTree::Builder().SetBaseAndExtent(marker_range).Build()); | 831 SelectionInDOMTree::Builder().SetBaseAndExtent(marker_range).Build()); |
821 | 832 |
822 Document& current_document = *GetFrame().GetDocument(); | 833 Document& current_document = *GetFrame().GetDocument(); |
823 | 834 |
824 // Dispatch 'beforeinput'. | 835 // Dispatch 'beforeinput'. |
825 Element* const target = GetFrame().GetEditor().FindEventTargetFromSelection(); | 836 Element* const target = GetFrame().GetEditor().FindEventTargetFromSelection(); |
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1198 if (!input.IsFocusedElementInDocument()) | 1209 if (!input.IsFocusedElementInDocument()) |
1199 return false; | 1210 return false; |
1200 } | 1211 } |
1201 } | 1212 } |
1202 HTMLElement* element = | 1213 HTMLElement* element = |
1203 Traversal<HTMLElement>::FirstAncestorOrSelf(*position.AnchorNode()); | 1214 Traversal<HTMLElement>::FirstAncestorOrSelf(*position.AnchorNode()); |
1204 return element && element->IsSpellCheckingEnabled(); | 1215 return element && element->IsSpellCheckingEnabled(); |
1205 } | 1216 } |
1206 | 1217 |
1207 } // namespace blink | 1218 } // namespace blink |
OLD | NEW |