| 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 {
|
|
|