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

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

Issue 2618583003: [InputEvent] Add 'beforeinput' logic in |will*()| and guarded by a flag (3/11) (Closed)
Patch Set: Change target to |startingRootEditableElement()| Created 3 years, 11 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
« no previous file with comments | « third_party/WebKit/Source/core/editing/commands/CompositeEditCommand.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 9af08b291ac18bf1eda46a5e6735b82b10f32a4b..b0f9e330a7c84202514ec6d0b0b7887407d076ee 100644
--- a/third_party/WebKit/Source/core/editing/commands/CompositeEditCommand.cpp
+++ b/third_party/WebKit/Source/core/editing/commands/CompositeEditCommand.cpp
@@ -78,6 +78,19 @@
namespace blink {
+namespace {
+
+InputEvent::EventCancelable isCancelableFromCommand(
+ const CompositeEditCommand* command) {
+ if (command->isTypingCommand() &&
+ toTypingCommand(command)->compositionType() ==
+ TypingCommand::TextCompositionUpdate)
+ return InputEvent::NotCancelable;
+ return InputEvent::IsCancelable;
+}
+
+} // anonymous namespace
+
using namespace HTMLNames;
EditCommandComposition* EditCommandComposition::create(
@@ -150,14 +163,24 @@ void EditCommandComposition::reapply(EditCommandSource source) {
frame->editor().reappliedEditing(this);
}
-bool EditCommandComposition::willUnapply(EditCommandSource, BeforeInputTiming) {
- // TODO(chongz): Fire 'beforeinput' for 'historyUndo'.
- return true;
+bool EditCommandComposition::willUnapply(EditCommandSource source,
+ BeforeInputTiming beforeInputTiming) {
+ if (beforeInputTiming != BeforeInputTiming::kShouldFireInCommand)
+ return true;
+ return dispatchBeforeInputEvent(source, m_document->frame(), m_document,
+ InputEvent::InputType::HistoryUndo, nullAtom,
+ nullptr, InputEvent::IsCancelable,
+ InputEvent::NotComposing, nullptr);
}
-bool EditCommandComposition::willReapply(EditCommandSource, BeforeInputTiming) {
- // TODO(chongz): Fire 'beforeinput' for 'historyRedo'.
- return true;
+bool EditCommandComposition::willReapply(EditCommandSource source,
+ BeforeInputTiming beforeInputTiming) {
+ if (beforeInputTiming != BeforeInputTiming::kShouldFireInCommand)
+ return true;
+ return dispatchBeforeInputEvent(source, m_document->frame(), m_document,
+ InputEvent::InputType::HistoryRedo, nullAtom,
+ nullptr, InputEvent::IsCancelable,
+ InputEvent::NotComposing, nullptr);
}
void EditCommandComposition::append(SimpleEditCommand* command) {
@@ -227,6 +250,11 @@ bool CompositeEditCommand::apply(EditCommandSource source,
}
ensureComposition();
+ // Covers the initial TypingCommand and other top-level commands.
+ // TypingCommand::willAddTypingToOpenCommand() also calls willApplyEditing().
+ if (!willApplyEditing(source, beforeInputTiming))
+ 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
@@ -234,9 +262,6 @@ bool CompositeEditCommand::apply(EditCommandSource source,
// the creation of VisiblePositions).
document().updateStyleAndLayoutIgnorePendingStylesheets();
- if (!willApplyEditing(source, beforeInputTiming))
- return false;
-
LocalFrame* frame = document().frame();
DCHECK(frame);
EditingState editingState;
@@ -264,10 +289,17 @@ EditCommandComposition* CompositeEditCommand::ensureComposition() {
return command->m_composition.get();
}
-bool CompositeEditCommand::willApplyEditing(EditCommandSource,
- BeforeInputTiming) {
- // TODO(chongz): Move all the 'beforeinput' dispatching logic here.
- return true;
+bool CompositeEditCommand::willApplyEditing(
+ EditCommandSource source,
+ BeforeInputTiming beforeInputTiming) {
+ if (beforeInputTiming != BeforeInputTiming::kShouldFireInCommand)
+ return true;
+ return dispatchBeforeInputEvent(
+ source, document().frame(),
+ ensureComposition()->startingRootEditableElement(), inputType(),
+ textDataForInputEvent(), dataTransferForInputEvent(),
+ isCancelableFromCommand(this), isComposingFromCommand(this),
+ targetRangesForInputEvent());
}
InputEvent::InputType CompositeEditCommand::inputType() const {
« no previous file with comments | « third_party/WebKit/Source/core/editing/commands/CompositeEditCommand.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698