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

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

Issue 2558643003: [InputEvent] Move 'beforeinput' logic into |CompositeEditCommand::willApplyEditing()| (3/3) (Closed)
Patch Set: xiaocheng's review: Isolate |UndoStep| code; Move attribuates to private Created 4 years 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 2954891283900e17fad5cad4257946cc1f26294c..8133490428652cae100563e86a578ff26f696c56 100644
--- a/third_party/WebKit/Source/core/editing/Editor.cpp
+++ b/third_party/WebKit/Source/core/editing/Editor.cpp
@@ -86,6 +86,7 @@
#include "core/page/Page.h"
#include "core/svg/SVGImageElement.h"
#include "platform/KillRing.h"
+#include "platform/clipboard/ClipboardMimeTypes.h"
Xiaocheng 2016/12/21 02:56:38 What needs it?
chongz 2016/12/21 23:59:24 My mistake, removed. It was added for |dispatchBef
#include "platform/weborigin/KURL.h"
#include "wtf/PtrUtil.h"
#include "wtf/text/CharacterNames.h"
@@ -104,12 +105,10 @@ void dispatchInputEvent(Element* target,
InputEvent::EventIsComposing isComposing) {
if (!RuntimeEnabledFeatures::inputEventEnabled())
return;
- if (!target)
+ if (!target || !target->isConnected())
Xiaocheng 2016/12/21 02:56:38 This part doesn't seem relevant to beforeinput.
chongz 2016/12/21 23:59:24 Moved to the end of 'EditingUtilities.cpp::dispatc
return;
- // TODO(chongz): Pass appreciate |ranges| after it's defined on spec.
- // http://w3c.github.io/editing/input-events.html#dom-inputevent-inputtype
InputEvent* inputEvent =
- InputEvent::createInput(inputType, data, isComposing, nullptr);
+ InputEvent::createInput(inputType, data, isComposing);
target->dispatchScopedEvent(inputEvent);
}
@@ -125,15 +124,6 @@ void dispatchInputEventEditableContentChanged(
dispatchInputEvent(endRoot, inputType, data, isComposing);
}
-InputEvent::EventIsComposing isComposingFromCommand(
chongz 2016/12/20 23:27:51 Moved to |EditingUtilities.cpp::isComposingFromCom
- const CompositeEditCommand* command) {
- if (command->isTypingCommand() &&
- toTypingCommand(command)->compositionType() !=
- TypingCommand::TextCompositionNone)
- return InputEvent::EventIsComposing::IsComposing;
- return InputEvent::EventIsComposing::NotComposing;
-}
-
} // anonymous namespace
Editor::RevealSelectionScope::RevealSelectionScope(Editor* editor)
@@ -623,63 +613,6 @@ void Editor::replaceSelectionAfterDragging(DocumentFragment* fragment,
->apply(EditCommandSource::kMenuOrKeyBinding);
}
-bool Editor::deleteSelectionAfterDraggingWithEvents(
chongz 2016/12/20 23:27:51 See header file.
- Element* dragSource,
- DeleteMode deleteMode,
- const Position& referenceMovePosition) {
- if (!dragSource || !dragSource->isConnected())
- return true;
-
- // Dispatch 'beforeinput'.
- const bool shouldDelete = dispatchBeforeInputEditorCommand(
- dragSource, InputEvent::InputType::DeleteByDrag,
- nullptr) == DispatchEventResult::NotCanceled;
-
- // 'beforeinput' event handler may destroy frame, return false to cancel
- // remaining actions;
- if (m_frame->document()->frame() != m_frame)
- return false;
-
- if (shouldDelete && dragSource->isConnected()) {
- deleteSelectionWithSmartDelete(
- EditCommandSource::kMenuOrKeyBinding, deleteMode,
- InputEvent::InputType::DeleteByDrag, referenceMovePosition);
- }
-
- return true;
-}
-
-bool Editor::replaceSelectionAfterDraggingWithEvents(
- Element* dropTarget,
- DragData* dragData,
- DocumentFragment* fragment,
- Range* dropCaretRange,
- InsertMode insertMode,
- DragSourceType dragSourceType) {
- if (!dropTarget || !dropTarget->isConnected())
- return true;
-
- // Dispatch 'beforeinput'.
- DataTransfer* dataTransfer =
- DataTransfer::create(DataTransfer::DragAndDrop, DataTransferReadable,
- dragData->platformData());
- dataTransfer->setSourceOperation(dragData->draggingSourceOperationMask());
- const bool shouldInsert =
- dispatchBeforeInputDataTransfer(
- dropTarget, InputEvent::InputType::InsertFromDrop, dataTransfer,
- nullptr) == DispatchEventResult::NotCanceled;
-
- // 'beforeinput' event handler may destroy frame, return false to cancel
- // remaining actions;
- if (m_frame->document()->frame() != m_frame)
- return false;
-
- if (shouldInsert && dropTarget->isConnected())
- replaceSelectionAfterDragging(fragment, insertMode, dragSourceType);
-
- return true;
-}
-
EphemeralRange Editor::selectedRange() {
return frame().selection().selection().toNormalizedEphemeralRange();
}
@@ -1069,16 +1002,6 @@ void Editor::cut(EditCommandSource source) {
writeSelectionToPasteboard();
}
- if (source == EditCommandSource::kMenuOrKeyBinding) {
- if (dispatchBeforeInputDataTransfer(findEventTargetFromSelection(),
chongz 2016/12/20 23:27:51 Removed, cut was covered by |DeleteSelectionComman
- InputEvent::InputType::DeleteByCut,
- nullptr, nullptr) !=
- DispatchEventResult::NotCanceled)
- return;
- // 'beforeinput' event handler may destroy target frame.
- if (m_frame->document()->frame() != m_frame)
- return;
- }
deleteSelectionWithSmartDelete(
source, canSmartCopyOrDelete() ? DeleteMode::Smart : DeleteMode::Simple,
InputEvent::InputType::DeleteByCut);
@@ -1113,7 +1036,9 @@ void Editor::copy() {
}
}
-void Editor::paste(EditCommandSource source) {
+// TODO(chongz): Pass |EditCommandSource| to |TextEvent| and don't fire
+// 'beforeinput' for JS triggered paste.
+void Editor::paste(EditCommandSource) {
DCHECK(frame().document());
if (tryDHTMLPaste(AllMimeTypes))
return; // DHTML did the whole operation
@@ -1127,21 +1052,6 @@ void Editor::paste(EditCommandSource source) {
? AllMimeTypes
: PlainTextOnly;
- if (source == EditCommandSource::kMenuOrKeyBinding) {
- DataTransfer* dataTransfer =
- DataTransfer::create(DataTransfer::CopyAndPaste, DataTransferReadable,
- DataObject::createFromPasteboard(pasteMode));
-
- if (dispatchBeforeInputDataTransfer(findEventTargetFromSelection(),
chongz 2016/12/20 23:27:51 Removed, paste was covered by |ReplaceSelectionCom
- 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
@@ -1296,7 +1206,7 @@ void Editor::setBaseWritingDirection(WritingDirection direction) {
void Editor::revealSelectionAfterEditingOperation(
const ScrollAlignment& alignment,
RevealExtentOption revealExtentOption) {
- if (m_preventRevealSelection)
+ if (m_preventRevealSelection || !m_frame->selection().isAvailable())
Xiaocheng 2016/12/21 02:56:38 This part seems to be a bug fix. Does any test cas
chongz 2016/12/21 23:59:24 The test case is "fast/events/inputevents/beforein
return;
frame().selection().revealSelection(alignment, revealExtentOption);
}

Powered by Google App Engine
This is Rietveld 408576698