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 857 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
868 } | 868 } |
869 | 869 |
870 Optional<std::pair<Node*, SpellCheckMarker*>> | 870 Optional<std::pair<Node*, SpellCheckMarker*>> |
871 SpellChecker::GetSpellCheckMarkerTouchingSelection() { | 871 SpellChecker::GetSpellCheckMarkerTouchingSelection() { |
872 const VisibleSelection& selection = | 872 const VisibleSelection& selection = |
873 GetFrame().Selection().ComputeVisibleSelectionInDOMTree(); | 873 GetFrame().Selection().ComputeVisibleSelectionInDOMTree(); |
874 if (selection.IsNone()) | 874 if (selection.IsNone()) |
875 return Optional<std::pair<Node*, SpellCheckMarker*>>(); | 875 return Optional<std::pair<Node*, SpellCheckMarker*>>(); |
876 | 876 |
877 const EphemeralRange& range_to_check = | 877 const EphemeralRange& range_to_check = |
878 ExpandSelectionRangeIfNecessary(selection); | 878 ExpandSelectionRangeIfNecessary(selection); |
rlanday
2017/06/22 04:05:13
I think I'm probably going to get rid of this and
| |
879 | 879 |
880 Node* const start_container = | 880 const Vector<std::pair<Node*, DocumentMarker*>>& node_marker_pairs = |
881 range_to_check.StartPosition().ComputeContainerNode(); | 881 GetFrame().GetDocument()->Markers().MarkersIntersectingRange( |
882 const unsigned start_offset = | 882 range_to_check, DocumentMarker::MisspellingMarkers()); |
883 range_to_check.StartPosition().ComputeOffsetInContainerNode(); | |
884 Node* const end_container = | |
885 range_to_check.EndPosition().ComputeContainerNode(); | |
886 const unsigned end_offset = | |
887 range_to_check.EndPosition().ComputeOffsetInContainerNode(); | |
888 | |
889 for (Node& node : range_to_check.Nodes()) { | |
890 const DocumentMarkerVector& markers_in_node = | |
891 GetFrame().GetDocument()->Markers().MarkersFor( | |
892 &node, DocumentMarker::MisspellingMarkers()); | |
893 for (DocumentMarker* marker : markers_in_node) { | |
894 if (node == start_container && marker->EndOffset() <= start_offset) | |
895 continue; | |
896 if (node == end_container && marker->StartOffset() >= end_offset) | |
897 continue; | |
898 | |
899 return std::make_pair(&node, &ToSpellCheckMarker(*marker)); | |
900 } | |
901 } | |
902 | 883 |
903 // No marker found | 884 // No marker found |
904 return Optional<std::pair<Node*, SpellCheckMarker*>>(); | 885 if (node_marker_pairs.IsEmpty()) |
886 return Optional<std::pair<Node*, SpellCheckMarker*>>(); | |
887 | |
888 return std::make_pair(node_marker_pairs.front().first, | |
889 ToSpellCheckMarker(node_marker_pairs.front().second)); | |
905 } | 890 } |
906 | 891 |
907 void SpellChecker::ReplaceMisspelledRange(const String& text) { | 892 void SpellChecker::ReplaceMisspelledRange(const String& text) { |
908 const Optional<std::pair<Node*, SpellCheckMarker*>>& node_and_marker = | 893 const Optional<std::pair<Node*, SpellCheckMarker*>>& node_and_marker = |
909 GetSpellCheckMarkerTouchingSelection(); | 894 GetSpellCheckMarkerTouchingSelection(); |
910 if (!node_and_marker) | 895 if (!node_and_marker) |
911 return; | 896 return; |
912 | 897 |
913 Node* const container_node = node_and_marker.value().first; | 898 Node* const container_node = node_and_marker.value().first; |
914 const SpellCheckMarker* const marker = node_and_marker.value().second; | 899 const SpellCheckMarker* const marker = node_and_marker.value().second; |
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1301 if (!input.IsFocusedElementInDocument()) | 1286 if (!input.IsFocusedElementInDocument()) |
1302 return false; | 1287 return false; |
1303 } | 1288 } |
1304 } | 1289 } |
1305 HTMLElement* element = | 1290 HTMLElement* element = |
1306 Traversal<HTMLElement>::FirstAncestorOrSelf(*position.AnchorNode()); | 1291 Traversal<HTMLElement>::FirstAncestorOrSelf(*position.AnchorNode()); |
1307 return element && element->IsSpellCheckingEnabled(); | 1292 return element && element->IsSpellCheckingEnabled(); |
1308 } | 1293 } |
1309 | 1294 |
1310 } // namespace blink | 1295 } // namespace blink |
OLD | NEW |