Chromium Code Reviews| 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) { |