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

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

Issue 2947093003: [MarkersIntersectingRange #3] Optimize SpellChecker::GetSpellCheckMarkerUnderSelection() (Closed)
Patch Set: FirstEphemeralRangeOf(), return {} Created 3 years, 5 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 8d322133aae38681aa7fcab17abf1d4cd1747492..e9b038595ed2bcc949c7bbbeb76524d5ab1f6734 100644
--- a/third_party/WebKit/Source/core/editing/spellcheck/SpellChecker.cpp
+++ b/third_party/WebKit/Source/core/editing/spellcheck/SpellChecker.cpp
@@ -836,33 +836,35 @@ 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;
-
- return std::make_pair(&node, &ToSpellCheckMarker(*marker));
- }
- }
+ // Caret and range selections always return valid normalized ranges.
+ const EphemeralRange& selection_range = FirstEphemeralRangeOf(selection);
+
+ 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. See crbug.com/720065
+ if (selection_start_container != selection_end_container)
+ return {};
+
+ if (!selection_start_container->IsTextNode())
+ return {};
+
+ const unsigned selection_start_offset =
+ selection_range.StartPosition().ComputeOffsetInContainerNode();
+ const unsigned selection_end_offset =
+ selection_range.EndPosition().ComputeOffsetInContainerNode();
+
+ DocumentMarker* const marker =
+ GetFrame().GetDocument()->Markers().FirstMarkerIntersectingOffsetRange(
+ 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) {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698