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