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

Unified Diff: third_party/WebKit/Source/core/editing/Editor.cpp

Issue 2258663003: [InputEvent] Support |deleteByCut|&|insertFromPaste| with |dataTransfer| field (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: yosin's review2, fix nits Created 4 years, 4 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/Editor.cpp
diff --git a/third_party/WebKit/Source/core/editing/Editor.cpp b/third_party/WebKit/Source/core/editing/Editor.cpp
index 7b841d30d774d3562888f5fdaec1d2c8d928c168..428331d3e5ae2796fbebc10dec8be0ffe18ef462 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() != m_frame)
+ return;
+ }
+ 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() != 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;

Powered by Google App Engine
This is Rietveld 408576698