| 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* const caret_start_container = |
| 807 caret_range, DocumentMarker::MisspellingMarkers()); | 807 caret_range.StartPosition().ComputeContainerNode(); |
| 808 if (markers.size() < 1 || | 808 Node* const caret_end_container = |
| 809 markers[0]->StartOffset() >= markers[0]->EndOffset()) | 809 caret_range.EndPosition().ComputeContainerNode(); |
| 810 |
| 811 // We don't currently support the case where a misspelling spans multiple |
| 812 // nodes |
| 813 if (caret_start_container != caret_end_container) |
| 810 return; | 814 return; |
| 815 |
| 816 const unsigned caret_start_offset = |
| 817 caret_range.StartPosition().ComputeOffsetInContainerNode(); |
| 818 const unsigned caret_end_offset = |
| 819 caret_range.EndPosition().ComputeOffsetInContainerNode(); |
| 820 |
| 821 const DocumentMarkerVector& markers_in_node = |
| 822 GetFrame().GetDocument()->Markers().MarkersFor( |
| 823 caret_start_container, DocumentMarker::MisspellingMarkers()); |
| 824 |
| 825 const auto marker_it = |
| 826 std::find_if(markers_in_node.begin(), markers_in_node.end(), |
| 827 [=](const DocumentMarker* marker) { |
| 828 return marker->StartOffset() < caret_end_offset && |
| 829 marker->EndOffset() > caret_start_offset; |
| 830 }); |
| 831 if (marker_it == markers_in_node.end()) |
| 832 return; |
| 833 |
| 834 const DocumentMarker* found_marker = *marker_it; |
| 811 EphemeralRange marker_range = EphemeralRange( | 835 EphemeralRange marker_range = EphemeralRange( |
| 812 Position(caret_range.StartPosition().ComputeContainerNode(), | 836 Position(caret_start_container, found_marker->StartOffset()), |
| 813 markers[0]->StartOffset()), | 837 Position(caret_start_container, found_marker->EndOffset())); |
| 814 Position(caret_range.EndPosition().ComputeContainerNode(), | |
| 815 markers[0]->EndOffset())); | |
| 816 if (marker_range.IsNull()) | 838 if (marker_range.IsNull()) |
| 817 return; | 839 return; |
| 818 | 840 |
| 819 GetFrame().Selection().SetSelection( | 841 GetFrame().Selection().SetSelection( |
| 820 SelectionInDOMTree::Builder().SetBaseAndExtent(marker_range).Build()); | 842 SelectionInDOMTree::Builder().SetBaseAndExtent(marker_range).Build()); |
| 821 | 843 |
| 822 Document& current_document = *GetFrame().GetDocument(); | 844 Document& current_document = *GetFrame().GetDocument(); |
| 823 | 845 |
| 824 // Dispatch 'beforeinput'. | 846 // Dispatch 'beforeinput'. |
| 825 Element* const target = GetFrame().GetEditor().FindEventTargetFromSelection(); | 847 Element* const target = GetFrame().GetEditor().FindEventTargetFromSelection(); |
| (...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1198 if (!input.IsFocusedElementInDocument()) | 1220 if (!input.IsFocusedElementInDocument()) |
| 1199 return false; | 1221 return false; |
| 1200 } | 1222 } |
| 1201 } | 1223 } |
| 1202 HTMLElement* element = | 1224 HTMLElement* element = |
| 1203 Traversal<HTMLElement>::FirstAncestorOrSelf(*position.AnchorNode()); | 1225 Traversal<HTMLElement>::FirstAncestorOrSelf(*position.AnchorNode()); |
| 1204 return element && element->IsSpellCheckingEnabled(); | 1226 return element && element->IsSpellCheckingEnabled(); |
| 1205 } | 1227 } |
| 1206 | 1228 |
| 1207 } // namespace blink | 1229 } // namespace blink |
| OLD | NEW |