Index: third_party/WebKit/Source/core/editing/Editor.cpp |
diff --git a/third_party/WebKit/Source/core/editing/Editor.cpp b/third_party/WebKit/Source/core/editing/Editor.cpp |
index 86376b21eec5af15966f5949931c02daf5ccb9a1..c2412767659fff5daf2b2d371a079e8e23123f64 100644 |
--- a/third_party/WebKit/Source/core/editing/Editor.cpp |
+++ b/third_party/WebKit/Source/core/editing/Editor.cpp |
@@ -542,7 +542,7 @@ void Editor::replaceSelectionWithFragment(DocumentFragment* fragment, bool selec |
if (matchStyle) |
options |= ReplaceSelectionCommand::MatchStyle; |
DCHECK(frame().document()); |
- ReplaceSelectionCommand::create(*frame().document(), fragment, options, InputEvent::InputType::Paste)->apply(); |
+ ReplaceSelectionCommand::create(*frame().document(), fragment, options, InputEvent::InputType::InsertFromPaste)->apply(); |
revealSelectionAfterEditingOperation(); |
} |
@@ -704,7 +704,7 @@ void Editor::requestSpellcheckingAfterApplyingCommand(CompositeEditCommand* cmd) |
// Note: Request spell checking for and only for |ReplaceSelectionCommand|s |
// created in |Editor::replaceSelectionWithFragment()|. |
// TODO(xiaochengh): May also need to do this after dragging crbug.com/298046. |
- if (cmd->inputType() != InputEvent::InputType::Paste) |
+ if (cmd->inputType() != InputEvent::InputType::InsertFromPaste) |
return; |
if (!spellChecker().isSpellCheckingEnabled()) |
return; |
@@ -888,7 +888,7 @@ bool Editor::insertParagraphSeparator() |
return true; |
} |
-void Editor::cut() |
+void Editor::cut(EditorCommandSource source) |
{ |
if (tryDHTMLCut()) |
return; // DHTML did the whole operation |
@@ -904,7 +904,15 @@ void Editor::cut() |
} else { |
writeSelectionToPasteboard(); |
} |
- deleteSelectionWithSmartDelete(canSmartCopyOrDelete(), InputEvent::InputType::Cut); |
+ |
+ if (source == CommandFromMenuOrKeyBinding) { |
+ if (dispatchBeforeInputDataTransfer(findEventTargetFromSelection(), InputEvent::InputType::DeleteByCut, nullptr, nullptr) != DispatchEventResult::NotCanceled) |
+ return; |
+ // 'beforeinput' event handler might destroy target. |
+ if (!m_frame) |
yosin_UTC9
2016/08/23 04:23:54
|Editor::m_frame| is never |nullptr|.
You can chec
|
+ return; |
+ } |
+ deleteSelectionWithSmartDelete(canSmartCopyOrDelete(), InputEvent::InputType::DeleteByCut); |
} |
} |
@@ -926,7 +934,7 @@ void Editor::copy() |
} |
} |
-void Editor::paste() |
+void Editor::paste(EditorCommandSource source) |
{ |
DCHECK(frame().document()); |
if (tryDHTMLPaste(AllMimeTypes)) |
@@ -936,13 +944,29 @@ void Editor::paste() |
spellChecker().updateMarkersForWordsAffectedByEditing(false); |
ResourceFetcher* loader = frame().document()->fetcher(); |
ResourceCacheValidationSuppressor validationSuppressor(loader); |
- if (frame().selection().isContentRichlyEditable()) |
+ |
+ PasteMode pasteMode = frame().selection().isContentRichlyEditable() ? AllMimeTypes : PlainTextOnly; |
+ |
+ if (source == CommandFromMenuOrKeyBinding) { |
+ DataTransfer* dataTransfer = DataTransfer::create( |
+ DataTransfer::CopyAndPaste, |
+ DataTransferReadable, |
+ DataObject::createFromPasteboard(pasteMode)); |
+ |
+ if (dispatchBeforeInputDataTransfer(findEventTargetFromSelection(), InputEvent::InputType::InsertFromPaste, dataTransfer, nullptr) != DispatchEventResult::NotCanceled) |
+ return; |
+ // 'beforeinput' event handler might destroy target. |
+ if (!m_frame) |
+ return; |
+ } |
+ |
+ if (pasteMode == AllMimeTypes) |
pasteWithPasteboard(Pasteboard::generalPasteboard()); |
else |
pasteAsPlainTextWithPasteboard(Pasteboard::generalPasteboard()); |
} |
-void Editor::pasteAsPlainText() |
+void Editor::pasteAsPlainText(EditorCommandSource source) |
{ |
if (tryDHTMLPaste(PlainTextOnly)) |
return; |