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

Unified Diff: third_party/WebKit/Source/core/editing/spellcheck/SpellChecker.cpp

Issue 2857173003: Remove DocumentMarkerController::MarkersInRange() (Closed)
Patch Set: Simplify unnecessarily complicated logic 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/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 71a48a56cc62fbfd9098153f1efa18d809a453f9..4a2989c5425e8c6db773a3eab1d6d3cff538199f 100644
--- a/third_party/WebKit/Source/core/editing/spellcheck/SpellChecker.cpp
+++ b/third_party/WebKit/Source/core/editing/spellcheck/SpellChecker.cpp
@@ -802,17 +802,36 @@ void SpellChecker::ReplaceMisspelledRange(const String& text) {
.ToNormalizedEphemeralRange();
if (caret_range.IsNull())
return;
- DocumentMarkerVector markers =
- GetFrame().GetDocument()->Markers().MarkersInRange(
- caret_range, DocumentMarker::MisspellingMarkers());
- if (markers.size() < 1 ||
- markers[0]->StartOffset() >= markers[0]->EndOffset())
+
+ // We don't currently support the case where a misspelling spans multiple
+ // nodes, so we assume this is the same as caret_end_container
+ Node* caret_start_container =
Xiaocheng 2017/05/10 23:55:15 We should return if |caret_end_container != caret_
+ caret_range.StartPosition().ComputeContainerNode();
+ const unsigned caret_start_offset =
+ caret_range.StartPosition().ComputeOffsetInContainerNode();
+ const unsigned caret_end_offset =
+ caret_range.EndPosition().ComputeOffsetInContainerNode();
+
+ const DocumentMarker* found_marker = nullptr;
+ const DocumentMarkerVector& markers_in_node =
Xiaocheng 2017/05/10 23:55:15 This chunk of code is still duplicated with that i
yosin_UTC9 2017/05/11 01:03:41 I prefer std::find_if() to reduce # of API in DMC.
+ GetFrame().GetDocument()->Markers().MarkersFor(
+ caret_start_container, DocumentMarker::MisspellingMarkers());
+ for (DocumentMarker* marker : markers_in_node) {
+ if (marker->EndOffset() <= caret_start_offset)
+ continue;
+ if (marker->StartOffset() >= caret_end_offset)
+ continue;
+
+ found_marker = marker;
+ break;
+ }
+
+ if (!found_marker)
return;
+
EphemeralRange marker_range = EphemeralRange(
- Position(caret_range.StartPosition().ComputeContainerNode(),
- markers[0]->StartOffset()),
- Position(caret_range.EndPosition().ComputeContainerNode(),
- markers[0]->EndOffset()));
+ Position(caret_start_container, found_marker->StartOffset()),
+ Position(caret_start_container, found_marker->EndOffset()));
if (marker_range.IsNull())
return;

Powered by Google App Engine
This is Rietveld 408576698