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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
126 | 126 |
127 const Position& next_position = | 127 const Position& next_position = |
128 NextPositionOf(caret_position).DeepEquivalent(); | 128 NextPositionOf(caret_position).DeepEquivalent(); |
129 | 129 |
130 return EphemeralRange( | 130 return EphemeralRange( |
131 previous_position.IsNull() ? caret_position.DeepEquivalent() | 131 previous_position.IsNull() ? caret_position.DeepEquivalent() |
132 : previous_position, | 132 : previous_position, |
133 next_position.IsNull() ? caret_position.DeepEquivalent() : next_position); | 133 next_position.IsNull() ? caret_position.DeepEquivalent() : next_position); |
134 } | 134 } |
135 | 135 |
136 static bool IsWhiteSpaceOrPunctuation(UChar c) { | |
137 return IsSpaceOrNewline(c) || WTF::Unicode::IsPunct(c); | |
138 } | |
139 | |
136 } // namespace | 140 } // namespace |
137 | 141 |
138 SpellChecker* SpellChecker::Create(LocalFrame& frame) { | 142 SpellChecker* SpellChecker::Create(LocalFrame& frame) { |
139 return new SpellChecker(frame); | 143 return new SpellChecker(frame); |
140 } | 144 } |
141 | 145 |
142 static SpellCheckerClient& GetEmptySpellCheckerClient() { | 146 static SpellCheckerClient& GetEmptySpellCheckerClient() { |
143 DEFINE_STATIC_LOCAL(EmptySpellCheckerClient, client, ()); | 147 DEFINE_STATIC_LOCAL(EmptySpellCheckerClient, client, ()); |
144 return client; | 148 return client; |
145 } | 149 } |
(...skipping 751 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
897 continue; | 901 continue; |
898 | 902 |
899 return std::make_pair(&node, &ToSpellCheckMarker(*marker)); | 903 return std::make_pair(&node, &ToSpellCheckMarker(*marker)); |
900 } | 904 } |
901 } | 905 } |
902 | 906 |
903 // No marker found | 907 // No marker found |
904 return Optional<std::pair<Node*, SpellCheckMarker*>>(); | 908 return Optional<std::pair<Node*, SpellCheckMarker*>>(); |
905 } | 909 } |
906 | 910 |
911 String SpellChecker::SelectMisspellingAsync(String& description) { | |
912 VisibleSelection selection = | |
yosin_UTC9
2017/07/20 00:56:32
nit: s/VisbileSelection/const VisbileSelection/
| |
913 GetFrame().Selection().ComputeVisibleSelectionInDOMTree(); | |
914 if (selection.IsNone()) | |
915 return String(); | |
916 | |
917 // Caret and range selections always return valid normalized ranges. | |
918 const EphemeralRange& selection_range = | |
919 selection.ToNormalizedEphemeralRange(); | |
920 | |
921 Node* const selection_start_container = | |
922 selection_range.StartPosition().ComputeContainerNode(); | |
923 Node* const selection_end_container = | |
924 selection_range.EndPosition().ComputeContainerNode(); | |
925 | |
926 // We don't currently support the case where a misspelling spans multiple | |
927 // nodes. See crbug.com/720065 | |
928 if (selection_start_container != selection_end_container) | |
929 return String(); | |
930 | |
931 const unsigned selection_start_offset = | |
932 selection_range.StartPosition().ComputeOffsetInContainerNode(); | |
933 const unsigned selection_end_offset = | |
934 selection_range.EndPosition().ComputeOffsetInContainerNode(); | |
935 | |
936 const DocumentMarkerVector& markers_in_node = | |
937 GetFrame().GetDocument()->Markers().MarkersFor( | |
938 selection_start_container, DocumentMarker::MisspellingMarkers()); | |
939 | |
940 const auto marker_it = | |
941 std::find_if(markers_in_node.begin(), markers_in_node.end(), | |
942 [=](const DocumentMarker* marker) { | |
943 return marker->StartOffset() < selection_end_offset && | |
944 marker->EndOffset() > selection_start_offset; | |
945 }); | |
946 if (marker_it == markers_in_node.end()) | |
947 return String(); | |
948 | |
949 const SpellCheckMarker* const found_marker = ToSpellCheckMarker(*marker_it); | |
950 description = found_marker->Description(); | |
951 | |
952 Range* const marker_range = | |
yosin_UTC9
2017/07/20 00:56:32
We should avoid to use temporary Range object for
Xiaocheng
2017/07/20 21:22:17
Shouldn't we do this change in a separate CL?
Doi
| |
953 Range::Create(*GetFrame().GetDocument(), selection_start_container, | |
954 found_marker->StartOffset(), selection_start_container, | |
955 found_marker->EndOffset()); | |
956 | |
957 if (marker_range->GetText().StripWhiteSpace(&IsWhiteSpaceOrPunctuation) != | |
958 CreateRange(selection_range) | |
959 ->GetText() | |
960 .StripWhiteSpace(&IsWhiteSpaceOrPunctuation)) | |
961 return String(); | |
962 | |
963 return marker_range->GetText(); | |
yosin_UTC9
2017/07/20 00:56:31
Please hold restul of Range::GetText() to avoid ca
Xiaocheng
2017/07/20 21:22:17
Ditto.
| |
964 } | |
965 | |
907 void SpellChecker::ReplaceMisspelledRange(const String& text) { | 966 void SpellChecker::ReplaceMisspelledRange(const String& text) { |
908 const Optional<std::pair<Node*, SpellCheckMarker*>>& node_and_marker = | 967 const Optional<std::pair<Node*, SpellCheckMarker*>>& node_and_marker = |
909 GetSpellCheckMarkerTouchingSelection(); | 968 GetSpellCheckMarkerTouchingSelection(); |
910 if (!node_and_marker) | 969 if (!node_and_marker) |
911 return; | 970 return; |
912 | 971 |
913 Node* const container_node = node_and_marker.value().first; | 972 Node* const container_node = node_and_marker.value().first; |
914 const SpellCheckMarker* const marker = node_and_marker.value().second; | 973 const SpellCheckMarker* const marker = node_and_marker.value().second; |
915 | 974 |
916 GetFrame().Selection().SetSelection( | 975 GetFrame().Selection().SetSelection( |
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1301 if (!input.IsFocusedElementInDocument()) | 1360 if (!input.IsFocusedElementInDocument()) |
1302 return false; | 1361 return false; |
1303 } | 1362 } |
1304 } | 1363 } |
1305 HTMLElement* element = | 1364 HTMLElement* element = |
1306 Traversal<HTMLElement>::FirstAncestorOrSelf(*position.AnchorNode()); | 1365 Traversal<HTMLElement>::FirstAncestorOrSelf(*position.AnchorNode()); |
1307 return element && element->IsSpellCheckingEnabled(); | 1366 return element && element->IsSpellCheckingEnabled(); |
1308 } | 1367 } |
1309 | 1368 |
1310 } // namespace blink | 1369 } // namespace blink |
OLD | NEW |