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

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

Issue 2966223003: [SelectMisspellingAsync #1] Move SelectMisspellingAsync() from ContextMenuClient.cpp to SpellChecker (Closed)
Patch Set: Rebase 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
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 eb4aaa750b5ef613b2ad7fec13d5a73d57e3463b..6b0d4b48baa2134574fcaff24012bd4c09f3a720 100644
--- a/third_party/WebKit/Source/core/editing/spellcheck/SpellChecker.cpp
+++ b/third_party/WebKit/Source/core/editing/spellcheck/SpellChecker.cpp
@@ -94,6 +94,10 @@ SelectionInDOMTree SelectWord(const VisiblePosition& position) {
.Build();
}
+static bool IsWhiteSpaceOrPunctuation(UChar c) {
+ return IsSpaceOrNewline(c) || WTF::Unicode::IsPunct(c);
+}
+
} // namespace
SpellChecker* SpellChecker::Create(LocalFrame& frame) {
@@ -867,6 +871,36 @@ SpellChecker::GetSpellCheckMarkerUnderSelection() {
return std::make_pair(selection_start_container, ToSpellCheckMarker(marker));
}
+String SpellChecker::SelectMisspellingAsync(String& description) {
+ const Optional<std::pair<Node*, SpellCheckMarker*>>& node_and_marker =
+ GetSpellCheckMarkerUnderSelection();
+ if (!node_and_marker)
+ return String();
+
+ Node* const marker_node = node_and_marker.value().first;
+ const SpellCheckMarker* const marker = node_and_marker.value().second;
+ description = marker->Description();
+
+ Range* const marker_range =
+ Range::Create(*GetFrame().GetDocument(), marker_node,
+ marker->StartOffset(), marker_node, marker->EndOffset());
+
+ VisibleSelection selection =
+ GetFrame().Selection().ComputeVisibleSelectionInDOMTree();
+ // Caret and range selections (one of which we must have since we found a
+ // marker) always return valid normalized ranges.
+ const EphemeralRange& selection_range =
+ selection.ToNormalizedEphemeralRange();
+
+ if (marker_range->GetText().StripWhiteSpace(&IsWhiteSpaceOrPunctuation) !=
+ CreateRange(selection_range)
+ ->GetText()
+ .StripWhiteSpace(&IsWhiteSpaceOrPunctuation))
+ return String();
+
+ return marker_range->GetText();
+}
+
void SpellChecker::ReplaceMisspelledRange(const String& text) {
const Optional<std::pair<Node*, SpellCheckMarker*>>& node_and_marker =
GetSpellCheckMarkerUnderSelection();

Powered by Google App Engine
This is Rietveld 408576698