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

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

Issue 2457523003: Support 'insertReplacementText' for spellcheck (Closed)
Patch Set: fix for chongz's nit Created 4 years, 2 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 211578801ef98f5c767d334ebb432c78560ef178..3119d6bfc67ffb319075df357e2e92838984d6bd 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"
@@ -818,14 +820,34 @@ void SpellChecker::replaceMisspelledRange(const String& text) {
markers[0]->endOffset()));
if (markerRange.isNull())
return;
+
frame().selection().setSelection(
SelectionInDOMTree::Builder().setBaseAndExtent(markerRange).build());
+ // Dispatch 'beforeinput'.
+ Element* target = frame().editor().findEventTargetFromSelection();
+ RangeVector* ranges = new RangeVector(1, frame().selection().firstRange());
+ DataTransfer* dataTransfer = DataTransfer::create(
+ DataTransfer::DataTransferType::InsertReplacementText,
+ DataTransferAccessPolicy::DataTransferReadable,
+ DataObject::createFromString(text));
+
+ bool cancel = dispatchBeforeInputDataTransfer(
yosin_UTC9 2016/10/28 04:06:14 nit: s/bool/const bool/
+ target, InputEvent::InputType::InsertReplacementText,
+ dataTransfer, ranges) != DispatchEventResult::NotCanceled;
+
+ // 'beforeinput' event handler may destroy target frame.
+ if (frame().document()->frame() != m_frame)
+ 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) {
yosin_UTC9 2016/10/28 04:06:14 We prefer early-return style.
+ frame().editor().replaceSelectionWithText(
+ text, false, false, InputEvent::InputType::InsertReplacementText);
+ }
}
static bool shouldCheckOldSelection(const Position& oldSelectionStart) {

Powered by Google App Engine
This is Rietveld 408576698