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

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

Issue 2857173003: Remove DocumentMarkerController::MarkersInRange() (Closed)
Patch Set: Use std::find_if() 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..e954d10d6a5b37e77214013f15e0fb6e7f6a9272 100644
--- a/third_party/WebKit/Source/web/ContextMenuClientImpl.cpp
+++ b/third_party/WebKit/Source/web/ContextMenuClientImpl.cpp
@@ -112,23 +112,49 @@ 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* 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();
- 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());
+ 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 DocumentMarker* const found_marker = *marker_it;
+ description = found_marker->Description();
+
+ Range* const 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();

Powered by Google App Engine
This is Rietveld 408576698