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

Unified Diff: third_party/WebKit/Source/core/editing/commands/CompositeEditCommand.cpp

Issue 2558643003: [InputEvent] Move 'beforeinput' logic into |CompositeEditCommand::willApplyEditing()| (3/3) (Closed)
Patch Set: Retain the order of firing 'beforeinput' before 'compositionupdate' 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/commands/CompositeEditCommand.cpp
diff --git a/third_party/WebKit/Source/core/editing/commands/CompositeEditCommand.cpp b/third_party/WebKit/Source/core/editing/commands/CompositeEditCommand.cpp
index ee81dce271d7319aab59e5652f6a218db8f031a0..22edeafd43f2e2f52206c854da66af5d96a88573 100644
--- a/third_party/WebKit/Source/core/editing/commands/CompositeEditCommand.cpp
+++ b/third_party/WebKit/Source/core/editing/commands/CompositeEditCommand.cpp
@@ -56,6 +56,7 @@
#include "core/editing/commands/SplitElementCommand.h"
#include "core/editing/commands/SplitTextNodeCommand.h"
#include "core/editing/commands/SplitTextNodeContainingElementCommand.h"
+#include "core/editing/commands/TypingCommand.h"
#include "core/editing/commands/WrapContentsInDummySpanCommand.h"
#include "core/editing/iterators/TextIterator.h"
#include "core/editing/markers/DocumentMarkerController.h"
@@ -82,23 +83,20 @@ using namespace HTMLNames;
EditCommandComposition* EditCommandComposition::create(
Document* document,
const VisibleSelection& startingSelection,
- const VisibleSelection& endingSelection,
- InputEvent::InputType inputType) {
+ const VisibleSelection& endingSelection) {
return new EditCommandComposition(document, startingSelection,
- endingSelection, inputType);
+ endingSelection);
}
EditCommandComposition::EditCommandComposition(
Document* document,
const VisibleSelection& startingSelection,
- const VisibleSelection& endingSelection,
- InputEvent::InputType inputType)
+ const VisibleSelection& endingSelection)
: m_document(document),
m_startingSelection(startingSelection),
m_endingSelection(endingSelection),
m_startingRootEditableElement(startingSelection.rootEditableElement()),
- m_endingRootEditableElement(endingSelection.rootEditableElement()),
- m_inputType(inputType) {}
+ m_endingRootEditableElement(endingSelection.rootEditableElement()) {}
bool EditCommandComposition::belongsTo(const LocalFrame& frame) const {
DCHECK(m_document);
@@ -152,18 +150,18 @@ void EditCommandComposition::reapply(EditCommandSource source) {
frame->editor().reappliedEditing(this);
}
-bool EditCommandComposition::willUnapply(EditCommandSource) {
- // TODO(chongz): Fire 'beforeinput' for 'historyUndo'.
- return true;
-}
-
-bool EditCommandComposition::willReapply(EditCommandSource) {
- // TODO(chongz): Fire 'beforeinput' for 'historyRedo'.
- return true;
+bool EditCommandComposition::willUnapply(EditCommandSource source) {
+ return dispatchBeforeInputEvent(source, m_document->frame(), m_document,
+ InputEvent::InputType::HistoryUndo, nullAtom,
+ nullptr, InputEvent::IsCancelable,
+ InputEvent::NotComposing, nullptr);
}
-InputEvent::InputType EditCommandComposition::inputType() const {
- return m_inputType;
+bool EditCommandComposition::willReapply(EditCommandSource source) {
+ return dispatchBeforeInputEvent(source, m_document->frame(), m_document,
+ InputEvent::InputType::HistoryRedo, nullAtom,
+ nullptr, InputEvent::IsCancelable,
+ InputEvent::NotComposing, nullptr);
}
void EditCommandComposition::append(SimpleEditCommand* command) {
@@ -232,6 +230,11 @@ bool CompositeEditCommand::apply(EditCommandSource source) {
}
ensureComposition();
+ // Covers the initial TypingCommand and other top-level commands.
+ // TypingCommand::willAddTypingToOpenCommand() also calls willApplyEditing().
+ if (!willApplyEditing(source))
Xiaocheng 2016/12/20 05:49:57 Yeah, this should be the right place to fire the e
+ return false;
+
// Changes to the document may have been made since the last editing operation
// that require a layout, as in <rdar://problem/5658603>. Low level
// operations, like RemoveNodeCommand, don't require a layout because the high
@@ -239,9 +242,6 @@ bool CompositeEditCommand::apply(EditCommandSource source) {
// the creation of VisiblePositions).
document().updateStyleAndLayoutIgnorePendingStylesheets();
- if (!willApplyEditing(source))
- return false;
-
LocalFrame* frame = document().frame();
DCHECK(frame);
EditingState editingState;
@@ -262,15 +262,45 @@ EditCommandComposition* CompositeEditCommand::ensureComposition() {
CompositeEditCommand* command = this;
while (command && command->parent())
command = command->parent();
- if (!command->m_composition)
+ if (!command->m_composition) {
command->m_composition = EditCommandComposition::create(
- &document(), startingSelection(), endingSelection(), inputType());
+ &document(), startingSelection(), endingSelection());
+ }
return command->m_composition.get();
}
-bool CompositeEditCommand::willApplyEditing(EditCommandSource) {
- // TODO(chongz): Move all the 'beforeinput' dispatching logic here.
- return true;
+bool CompositeEditCommand::willApplyEditing(EditCommandSource source) {
+ // TODO(chongz): Remove the following code after we have ensured it's OK to
+ // fire 'beforeinput' after 'compositionupdate'.
+ // https://crbug.com/675820
+ if (isTypingCommand() && (toTypingCommand(this)->compositionType() ==
+ TypingCommand::TextCompositionUpdate ||
+ toTypingCommand(this)->compositionType() ==
+ TypingCommand::TextCompositionConfirm))
+ return true;
+ return dispatchBeforeInputEvent(
+ source, document().frame(), eventTargetNodeForDocument(&document()),
+ inputType(), textDataForInputEvent(), dataTransferForInputEvent(),
+ isCancelableFromCommand(this), isComposingFromCommand(this),
+ targetRangesForInputEvent());
+}
+
+InputEvent::InputType CompositeEditCommand::inputType() const {
+ return InputEvent::InputType::None;
+}
+
+String CompositeEditCommand::textDataForInputEvent() const {
+ return nullAtom;
+}
+
+DataTransfer* CompositeEditCommand::dataTransferForInputEvent() const {
+ return nullptr;
+}
+
+RangeVector* CompositeEditCommand::targetRangesForInputEvent() const {
+ if (!document().frame()->editor().canEditRichly())
+ return nullptr;
+ return new RangeVector(1, document().frame()->selection().firstRange());
}
bool CompositeEditCommand::preservesTypingStyle() const {

Powered by Google App Engine
This is Rietveld 408576698