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 5ef7ef6ffb8d1b7025917462fdcc47b144c52a51..7a59b4d5bd7f3b946578348d56c6e7f6b3f8b20f 100644 |
--- a/third_party/WebKit/Source/core/editing/spellcheck/SpellChecker.cpp |
+++ b/third_party/WebKit/Source/core/editing/spellcheck/SpellChecker.cpp |
@@ -133,6 +133,10 @@ EphemeralRange ExpandSelectionRangeIfNecessary( |
next_position.IsNull() ? caret_position.DeepEquivalent() : next_position); |
} |
+static bool IsWhiteSpaceOrPunctuation(UChar c) { |
+ return IsSpaceOrNewline(c) || WTF::Unicode::IsPunct(c); |
+} |
+ |
} // namespace |
SpellChecker* SpellChecker::Create(LocalFrame& frame) { |
@@ -904,6 +908,61 @@ SpellChecker::GetSpellCheckMarkerTouchingSelection() { |
return Optional<std::pair<Node*, SpellCheckMarker*>>(); |
} |
+String SpellChecker::SelectMisspellingAsync(String& description) { |
+ VisibleSelection selection = |
yosin_UTC9
2017/07/20 00:56:32
nit: s/VisbileSelection/const VisbileSelection/
|
+ GetFrame().Selection().ComputeVisibleSelectionInDOMTree(); |
+ if (selection.IsNone()) |
+ return String(); |
+ |
+ // 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 |
+ // nodes. See crbug.com/720065 |
+ if (selection_start_container != selection_end_container) |
+ return String(); |
+ |
+ const unsigned selection_start_offset = |
+ selection_range.StartPosition().ComputeOffsetInContainerNode(); |
+ const unsigned selection_end_offset = |
+ selection_range.EndPosition().ComputeOffsetInContainerNode(); |
+ |
+ const DocumentMarkerVector& markers_in_node = |
+ GetFrame().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 SpellCheckMarker* const found_marker = ToSpellCheckMarker(*marker_it); |
+ description = found_marker->Description(); |
+ |
+ Range* const marker_range = |
yosin_UTC9
2017/07/20 00:56:32
We should avoid to use temporary Range object for
Xiaocheng
2017/07/20 21:22:17
Shouldn't we do this change in a separate CL?
Doi
|
+ Range::Create(*GetFrame().GetDocument(), selection_start_container, |
+ found_marker->StartOffset(), selection_start_container, |
+ found_marker->EndOffset()); |
+ |
+ if (marker_range->GetText().StripWhiteSpace(&IsWhiteSpaceOrPunctuation) != |
+ CreateRange(selection_range) |
+ ->GetText() |
+ .StripWhiteSpace(&IsWhiteSpaceOrPunctuation)) |
+ return String(); |
+ |
+ return marker_range->GetText(); |
yosin_UTC9
2017/07/20 00:56:31
Please hold restul of Range::GetText() to avoid ca
Xiaocheng
2017/07/20 21:22:17
Ditto.
|
+} |
+ |
void SpellChecker::ReplaceMisspelledRange(const String& text) { |
const Optional<std::pair<Node*, SpellCheckMarker*>>& node_and_marker = |
GetSpellCheckMarkerTouchingSelection(); |