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 818 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
829 } | 829 } |
830 } | 830 } |
831 | 831 |
832 Optional<std::pair<Node*, SpellCheckMarker*>> | 832 Optional<std::pair<Node*, SpellCheckMarker*>> |
833 SpellChecker::GetSpellCheckMarkerUnderSelection() { | 833 SpellChecker::GetSpellCheckMarkerUnderSelection() { |
834 const VisibleSelection& selection = | 834 const VisibleSelection& selection = |
835 GetFrame().Selection().ComputeVisibleSelectionInDOMTree(); | 835 GetFrame().Selection().ComputeVisibleSelectionInDOMTree(); |
836 if (selection.IsNone()) | 836 if (selection.IsNone()) |
837 return Optional<std::pair<Node*, SpellCheckMarker*>>(); | 837 return Optional<std::pair<Node*, SpellCheckMarker*>>(); |
838 | 838 |
839 const EphemeralRange& range_to_check = FirstEphemeralRangeOf(selection); | 839 // Caret and range selections always return valid normalized ranges. |
| 840 const EphemeralRange& selection_range = FirstEphemeralRangeOf(selection); |
840 | 841 |
841 Node* const start_container = | 842 Node* const selection_start_container = |
842 range_to_check.StartPosition().ComputeContainerNode(); | 843 selection_range.StartPosition().ComputeContainerNode(); |
843 const unsigned start_offset = | 844 Node* const selection_end_container = |
844 range_to_check.StartPosition().ComputeOffsetInContainerNode(); | 845 selection_range.EndPosition().ComputeContainerNode(); |
845 Node* const end_container = | |
846 range_to_check.EndPosition().ComputeContainerNode(); | |
847 const unsigned end_offset = | |
848 range_to_check.EndPosition().ComputeOffsetInContainerNode(); | |
849 | 846 |
850 for (Node& node : range_to_check.Nodes()) { | 847 // We don't currently support the case where a misspelling spans multiple |
851 const DocumentMarkerVector& markers_in_node = | 848 // nodes. See crbug.com/720065 |
852 GetFrame().GetDocument()->Markers().MarkersFor( | 849 if (selection_start_container != selection_end_container) |
853 &node, DocumentMarker::MisspellingMarkers()); | 850 return {}; |
854 for (DocumentMarker* marker : markers_in_node) { | |
855 if (node == start_container && marker->EndOffset() <= start_offset) | |
856 continue; | |
857 if (node == end_container && marker->StartOffset() >= end_offset) | |
858 continue; | |
859 | 851 |
860 return std::make_pair(&node, &ToSpellCheckMarker(*marker)); | 852 if (!selection_start_container->IsTextNode()) |
861 } | 853 return {}; |
862 } | |
863 | 854 |
864 // No marker found | 855 const unsigned selection_start_offset = |
865 return Optional<std::pair<Node*, SpellCheckMarker*>>(); | 856 selection_range.StartPosition().ComputeOffsetInContainerNode(); |
| 857 const unsigned selection_end_offset = |
| 858 selection_range.EndPosition().ComputeOffsetInContainerNode(); |
| 859 |
| 860 DocumentMarker* const marker = |
| 861 GetFrame().GetDocument()->Markers().FirstMarkerIntersectingOffsetRange( |
| 862 ToText(*selection_start_container), selection_start_offset, |
| 863 selection_end_offset, DocumentMarker::MisspellingMarkers()); |
| 864 if (!marker) |
| 865 return Optional<std::pair<Node*, SpellCheckMarker*>>(); |
| 866 |
| 867 return std::make_pair(selection_start_container, ToSpellCheckMarker(marker)); |
866 } | 868 } |
867 | 869 |
868 void SpellChecker::ReplaceMisspelledRange(const String& text) { | 870 void SpellChecker::ReplaceMisspelledRange(const String& text) { |
869 const Optional<std::pair<Node*, SpellCheckMarker*>>& node_and_marker = | 871 const Optional<std::pair<Node*, SpellCheckMarker*>>& node_and_marker = |
870 GetSpellCheckMarkerUnderSelection(); | 872 GetSpellCheckMarkerUnderSelection(); |
871 if (!node_and_marker) | 873 if (!node_and_marker) |
872 return; | 874 return; |
873 | 875 |
874 Node* const container_node = node_and_marker.value().first; | 876 Node* const container_node = node_and_marker.value().first; |
875 const SpellCheckMarker* const marker = node_and_marker.value().second; | 877 const SpellCheckMarker* const marker = node_and_marker.value().second; |
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1262 if (!input.IsFocusedElementInDocument()) | 1264 if (!input.IsFocusedElementInDocument()) |
1263 return false; | 1265 return false; |
1264 } | 1266 } |
1265 } | 1267 } |
1266 HTMLElement* element = | 1268 HTMLElement* element = |
1267 Traversal<HTMLElement>::FirstAncestorOrSelf(*position.AnchorNode()); | 1269 Traversal<HTMLElement>::FirstAncestorOrSelf(*position.AnchorNode()); |
1268 return element && element->IsSpellCheckingEnabled(); | 1270 return element && element->IsSpellCheckingEnabled(); |
1269 } | 1271 } |
1270 | 1272 |
1271 } // namespace blink | 1273 } // namespace blink |
OLD | NEW |