Chromium Code Reviews| Index: third_party/WebKit/Source/web/ContextMenuClientImpl.cpp |
| diff --git a/third_party/WebKit/Source/web/ContextMenuClientImpl.cpp b/third_party/WebKit/Source/web/ContextMenuClientImpl.cpp |
| index f5151fa215c236921294a946d95afa6d4661da0d..22c4d41d5bcb9e75adc48c328662d97d5bbf33fb 100644 |
| --- a/third_party/WebKit/Source/web/ContextMenuClientImpl.cpp |
| +++ b/third_party/WebKit/Source/web/ContextMenuClientImpl.cpp |
| @@ -112,23 +112,46 @@ static String SelectMisspellingAsync(LocalFrame* selected_frame, |
| return String(); |
| // Caret and range selections always return valid normalized ranges. |
| - Range* selection_range = CreateRange(selection.ToNormalizedEphemeralRange()); |
| - DocumentMarkerVector markers = |
| - selected_frame->GetDocument()->Markers().MarkersInRange( |
| - EphemeralRange(selection_range), |
| - DocumentMarker::MisspellingMarkers()); |
| - if (markers.size() != 1) |
| + const EphemeralRange& selection_range = |
| + selection.ToNormalizedEphemeralRange(); |
| + |
| + // We don't currently support the case where a misspelling spans multiple |
| + // nodes, so we assume this is the same as selection_end_container |
| + Node* selection_start_container = |
|
Xiaocheng
2017/05/10 23:55:15
Same here, we should return if |selection_start_co
|
| + selection_range.StartPosition().ComputeContainerNode(); |
| + const unsigned selection_start_offset = |
| + selection_range.StartPosition().ComputeOffsetInContainerNode(); |
| + const unsigned selection_end_offset = |
| + selection_range.EndPosition().ComputeOffsetInContainerNode(); |
| + |
| + const DocumentMarker* found_marker = nullptr; |
| + const DocumentMarkerVector& markers_in_node = |
| + selected_frame->GetDocument()->Markers().MarkersFor( |
| + selection_start_container, DocumentMarker::MisspellingMarkers()); |
| + for (DocumentMarker* marker : markers_in_node) { |
| + if (marker->EndOffset() <= selection_start_offset) |
| + continue; |
| + if (marker->StartOffset() >= selection_end_offset) |
| + continue; |
| + |
| + found_marker = marker; |
| + break; |
| + } |
| + |
| + if (!found_marker) |
| return String(); |
| - description = markers[0]->Description(); |
| - // Cloning a range fails only for invalid ranges. |
| - Range* marker_range = selection_range->cloneRange(); |
| - marker_range->setStart(marker_range->startContainer(), |
| - markers[0]->StartOffset()); |
| - marker_range->setEnd(marker_range->endContainer(), markers[0]->EndOffset()); |
| + description = found_marker->Description(); |
| + |
| + Range* marker_range = |
| + Range::Create(*selected_frame->GetDocument(), selection_start_container, |
| + found_marker->StartOffset(), selection_start_container, |
| + found_marker->EndOffset()); |
| if (marker_range->GetText().StripWhiteSpace(&IsWhiteSpaceOrPunctuation) != |
| - selection_range->GetText().StripWhiteSpace(&IsWhiteSpaceOrPunctuation)) |
| + CreateRange(selection_range) |
| + ->GetText() |
| + .StripWhiteSpace(&IsWhiteSpaceOrPunctuation)) |
| return String(); |
| return marker_range->GetText(); |