Chromium Code Reviews| Index: third_party/WebKit/Source/core/page/ContextMenuClient.cpp |
| diff --git a/third_party/WebKit/Source/core/page/ContextMenuClient.cpp b/third_party/WebKit/Source/core/page/ContextMenuClient.cpp |
| index 3c99562d960a366178575b360e97914a104dde8c..63c57f1f7075f749ac2be5bc7202240df8acd31d 100644 |
| --- a/third_party/WebKit/Source/core/page/ContextMenuClient.cpp |
| +++ b/third_party/WebKit/Source/core/page/ContextMenuClient.cpp |
| @@ -109,50 +109,25 @@ static bool IsWhiteSpaceOrPunctuation(UChar c) { |
| static String SelectMisspellingAsync(LocalFrame* selected_frame, |
| String& description) { |
| - VisibleSelection selection = |
| - selected_frame->Selection().ComputeVisibleSelectionInDOMTree(); |
| - if (selection.IsNone()) |
| + const Optional<std::pair<Node*, SpellCheckMarker*>>& node_and_marker = |
| + selected_frame->GetSpellChecker().GetSpellCheckMarkerUnderSelection(); |
| + if (!node_and_marker) |
|
yosin_UTC9
2017/07/20 01:19:07
How about using |pair.first| which is Node*, as no
rlanday
2017/07/21 00:16:04
I put up a separate CL for this: https://chromium-
|
| return String(); |
| - // Caret and range selections always return valid normalized ranges. |
| - const EphemeralRange& selection_range = |
| - selection.ToNormalizedEphemeralRange(); |
| - |
| - Node* const selection_start_container = |
| - selection_range.StartPosition().ComputeContainerNode(); |
| - Node* const selection_end_container = |
| - selection_range.EndPosition().ComputeContainerNode(); |
| - |
| - // We don't currently support the case where a misspelling spans multiple |
| - // nodes |
| - if (selection_start_container != selection_end_container) |
| - return String(); |
| - |
| - const unsigned selection_start_offset = |
| - selection_range.StartPosition().ComputeOffsetInContainerNode(); |
| - const unsigned selection_end_offset = |
| - selection_range.EndPosition().ComputeOffsetInContainerNode(); |
| - |
| - const DocumentMarkerVector& markers_in_node = |
| - selected_frame->GetDocument()->Markers().MarkersFor( |
| - selection_start_container, DocumentMarker::MisspellingMarkers()); |
| - |
| - const auto marker_it = |
| - std::find_if(markers_in_node.begin(), markers_in_node.end(), |
| - [=](const DocumentMarker* marker) { |
| - return marker->StartOffset() < selection_end_offset && |
| - marker->EndOffset() > selection_start_offset; |
| - }); |
| - if (marker_it == markers_in_node.end()) |
| - return String(); |
| - |
| - const SpellCheckMarker* const found_marker = ToSpellCheckMarker(*marker_it); |
| - description = found_marker->Description(); |
| + Node* const marker_node = node_and_marker.value().first; |
| + const SpellCheckMarker* const marker = node_and_marker.value().second; |
| + description = marker->Description(); |
| Range* const marker_range = |
| - Range::Create(*selected_frame->GetDocument(), selection_start_container, |
| - found_marker->StartOffset(), selection_start_container, |
| - found_marker->EndOffset()); |
| + Range::Create(*selected_frame->GetDocument(), marker_node, |
|
yosin_UTC9
2017/07/20 01:19:07
Could you avoid to use temporary Range make this c
|
| + marker->StartOffset(), marker_node, marker->EndOffset()); |
| + |
| + VisibleSelection selection = |
| + selected_frame->Selection().ComputeVisibleSelectionInDOMTree(); |
| + // Caret and range selections (one of which we must have since we found a |
| + // marker) always return valid normalized ranges. |
| + const EphemeralRange& selection_range = |
| + selection.ToNormalizedEphemeralRange(); |
| if (marker_range->GetText().StripWhiteSpace(&IsWhiteSpaceOrPunctuation) != |
| CreateRange(selection_range) |