Chromium Code Reviews| 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 7b841d30d774d3562888f5fdaec1d2c8d928c168..6da568c9c29a722191d26e68ff53e5733c38da30 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(); |
| } |
| @@ -868,7 +868,7 @@ bool Editor::insertParagraphSeparator() |
| return true; |
| } |
| -void Editor::cut() |
| +void Editor::cut(EditorCommandSource source) |
| { |
| if (tryDHTMLCut()) |
| return; // DHTML did the whole operation |
| @@ -884,7 +884,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 may destroy target frame. |
| + if (!m_frame->document()->frame()) |
| + return; |
|
chongz
2016/08/24 01:43:27
Compare document won't work, have to do this...
yosin_UTC9
2016/08/24 02:11:44
How about
|m_frame->document()->frame() != m_fram
chongz
2016/08/24 02:42:01
Done.
|
| + } |
| + deleteSelectionWithSmartDelete(canSmartCopyOrDelete(), InputEvent::InputType::DeleteByCut); |
| } |
| } |
| @@ -906,7 +914,7 @@ void Editor::copy() |
| } |
| } |
| -void Editor::paste() |
| +void Editor::paste(EditorCommandSource source) |
| { |
| DCHECK(frame().document()); |
| if (tryDHTMLPaste(AllMimeTypes)) |
| @@ -916,13 +924,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 may destroy target frame. |
| + if (!m_frame->document()->frame()) |
| + return; |
| + } |
| + |
| + if (pasteMode == AllMimeTypes) |
| pasteWithPasteboard(Pasteboard::generalPasteboard()); |
| else |
| pasteAsPlainTextWithPasteboard(Pasteboard::generalPasteboard()); |
| } |
| -void Editor::pasteAsPlainText() |
| +void Editor::pasteAsPlainText(EditorCommandSource source) |
| { |
| if (tryDHTMLPaste(PlainTextOnly)) |
| return; |