Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(92)

Unified Diff: third_party/WebKit/Source/web/ContextMenuClientImpl.cpp

Issue 2857173003: Remove DocumentMarkerController::MarkersInRange() (Closed)
Patch Set: Fix WebFrameTest.cpp Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..c652e68f721b33874e77f7f7f5c88ed41e68834c 100644
--- a/third_party/WebKit/Source/web/ContextMenuClientImpl.cpp
+++ b/third_party/WebKit/Source/web/ContextMenuClientImpl.cpp
@@ -112,23 +112,55 @@ 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();
+
+ Node* selection_start_container =
+ selection_range.StartPosition().ComputeContainerNode();
+ const unsigned selection_start_offset =
+ selection_range.StartPosition().ComputeOffsetInContainerNode();
+ Node* selection_end_container =
+ selection_range.EndPosition().ComputeContainerNode();
+ const unsigned selection_end_offset =
+ selection_range.EndPosition().ComputeOffsetInContainerNode();
+
+ Node* found_marker_anchor_node = nullptr;
+ const DocumentMarker* found_marker = nullptr;
+ for (Node& node : selection_range.Nodes()) {
Xiaocheng 2017/05/10 22:54:22 Same here. No need to iterate over all nodes.
+ if (found_marker)
+ break;
+
+ const DocumentMarkerVector& markers_in_node =
+ selected_frame->GetDocument()->Markers().MarkersFor(
+ &node, DocumentMarker::MisspellingMarkers());
+ for (DocumentMarker* marker : markers_in_node) {
+ if (&node == selection_start_container &&
+ marker->EndOffset() <= selection_start_offset)
+ continue;
+ if (&node == selection_end_container &&
+ marker->StartOffset() >= selection_end_offset)
+ continue;
+
+ found_marker_anchor_node = &node;
+ found_marker = markers_in_node[0];
+ break;
+ }
+ }
+
+ if (!found_marker)
return String();
- description = markers[0]->Description();
- // Cloning a range fails only for invalid ranges.
- Range* marker_range = selection_range->cloneRange();
Xiaocheng 2017/05/10 22:54:22 Same here. The existing code doesn't work when the
- 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(), found_marker_anchor_node,
+ found_marker->StartOffset(), found_marker_anchor_node,
+ 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();

Powered by Google App Engine
This is Rietveld 408576698