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

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: Support cut/paste with |dataTransfer| field and correct event order 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 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;

Powered by Google App Engine
This is Rietveld 408576698