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

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

Issue 2457523003: Support 'insertReplacementText' for spellcheck (Closed)
Patch Set: yosin@ comment#57 #58 addressed Created 4 years, 1 month 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 28960f632c6ea012421c3bdced75f7623d3bdb30..9c18fd832fa73fb35cf9663e3df546986f988396 100644
--- a/third_party/WebKit/Source/core/editing/spellcheck/SpellChecker.cpp
+++ b/third_party/WebKit/Source/core/editing/spellcheck/SpellChecker.cpp
@@ -28,10 +28,12 @@
#include "core/HTMLNames.h"
#include "core/InputTypeNames.h"
+#include "core/clipboard/DataObject.h"
#include "core/dom/Document.h"
#include "core/dom/Element.h"
#include "core/dom/ElementTraversal.h"
#include "core/dom/NodeTraversal.h"
+#include "core/dom/Range.h"
#include "core/editing/EditingUtilities.h"
#include "core/editing/Editor.h"
#include "core/editing/EphemeralRange.h"
@@ -816,14 +818,38 @@ void SpellChecker::replaceMisspelledRange(const String& text) {
markers[0]->endOffset()));
if (markerRange.isNull())
return;
+
frame().selection().setSelection(
SelectionInDOMTree::Builder().setBaseAndExtent(markerRange).build());
+ Document& currentDocument = *frame().document();
+
+ // Dispatch 'beforeinput'.
+ Element* const target = frame().editor().findEventTargetFromSelection();
+ RangeVector* const ranges =
+ new RangeVector(1, frame().selection().firstRange());
+ DataTransfer* const dataTransfer = DataTransfer::create(
+ DataTransfer::DataTransferType::InsertReplacementText,
+ DataTransferAccessPolicy::DataTransferReadable,
+ DataObject::createFromString(text));
+
+ const bool cancel =
+ dispatchBeforeInputDataTransfer(
+ target, InputEvent::InputType::InsertReplacementText, dataTransfer,
+ ranges) != DispatchEventResult::NotCanceled;
+
+ // 'beforeinput' event handler may destroy target frame.
+ if (currentDocument != frame().document())
+ return;
+
// TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets
// needs to be audited. See http://crbug.com/590369 for more details.
frame().document()->updateStyleAndLayoutIgnorePendingStylesheets();
- frame().editor().replaceSelectionWithText(text, false, false);
+ if (cancel)
+ return;
+ frame().editor().replaceSelectionWithText(
+ text, false, false, InputEvent::InputType::InsertReplacementText);
}
static bool shouldCheckOldSelection(const Position& oldSelectionStart) {

Powered by Google App Engine
This is Rietveld 408576698