Chromium Code Reviews| Index: third_party/WebKit/Source/core/editing/spellcheck/SpellChecker.cpp |
| diff --git a/third_party/WebKit/Source/core/editing/spellcheck/SpellChecker.cpp b/third_party/WebKit/Source/core/editing/spellcheck/SpellChecker.cpp |
| index 4e69d8174584049393daf796e751e0b766790766..5efb859e25e509d945f1021633b07653c752bc02 100644 |
| --- a/third_party/WebKit/Source/core/editing/spellcheck/SpellChecker.cpp |
| +++ b/third_party/WebKit/Source/core/editing/spellcheck/SpellChecker.cpp |
| @@ -835,33 +835,36 @@ SpellChecker::GetSpellCheckMarkerUnderSelection() { |
| if (selection.IsNone()) |
| return Optional<std::pair<Node*, SpellCheckMarker*>>(); |
| - const EphemeralRange& range_to_check = FirstEphemeralRangeOf(selection); |
| - |
| - Node* const start_container = |
| - range_to_check.StartPosition().ComputeContainerNode(); |
| - const unsigned start_offset = |
| - range_to_check.StartPosition().ComputeOffsetInContainerNode(); |
| - Node* const end_container = |
| - range_to_check.EndPosition().ComputeContainerNode(); |
| - const unsigned end_offset = |
| - range_to_check.EndPosition().ComputeOffsetInContainerNode(); |
| - |
| - for (Node& node : range_to_check.Nodes()) { |
| - const DocumentMarkerVector& markers_in_node = |
| - GetFrame().GetDocument()->Markers().MarkersFor( |
| - &node, DocumentMarker::MisspellingMarkers()); |
| - for (DocumentMarker* marker : markers_in_node) { |
| - if (node == start_container && marker->EndOffset() <= start_offset) |
| - continue; |
| - if (node == end_container && marker->StartOffset() >= end_offset) |
| - continue; |
| + // 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 |
|
Xiaocheng
2017/06/26 22:48:22
Please cite crbug.com/720065 here.
|
| + // nodes |
| + if (selection_start_container != selection_end_container) |
| + return Optional<std::pair<Node*, SpellCheckMarker*>>(); |
| - return std::make_pair(&node, &ToSpellCheckMarker(*marker)); |
| - } |
| - } |
| + if (!selection_start_container->IsTextNode()) |
| + return Optional<std::pair<Node*, SpellCheckMarker*>>(); |
| + |
| + const unsigned selection_start_offset = |
| + selection_range.StartPosition().ComputeOffsetInContainerNode(); |
| + const unsigned selection_end_offset = |
| + selection_range.EndPosition().ComputeOffsetInContainerNode(); |
| + |
| + DocumentMarker* const marker = |
| + GetFrame().GetDocument()->Markers().MarkerIntersectingRange( |
| + ToText(*selection_start_container), selection_start_offset, |
| + selection_end_offset, DocumentMarker::MisspellingMarkers()); |
| + if (!marker) |
| + return Optional<std::pair<Node*, SpellCheckMarker*>>(); |
| - // No marker found |
| - return Optional<std::pair<Node*, SpellCheckMarker*>>(); |
| + return std::make_pair(selection_start_container, ToSpellCheckMarker(marker)); |
| } |
| void SpellChecker::ReplaceMisspelledRange(const String& text) { |