Chromium Code Reviews| Index: third_party/WebKit/Source/core/editing/EditingUtilities.cpp |
| diff --git a/third_party/WebKit/Source/core/editing/EditingUtilities.cpp b/third_party/WebKit/Source/core/editing/EditingUtilities.cpp |
| index bfd1a9634913f1e8b65a58c433aa38f45b9bc062..1f6eb1b1f5c04fa28ad94df922166440ba041b04 100644 |
| --- a/third_party/WebKit/Source/core/editing/EditingUtilities.cpp |
| +++ b/third_party/WebKit/Source/core/editing/EditingUtilities.cpp |
| @@ -41,6 +41,8 @@ |
| #include "core/editing/VisiblePosition.h" |
| #include "core/editing/VisibleSelection.h" |
| #include "core/editing/VisibleUnits.h" |
| +#include "core/editing/commands/CompositeEditCommand.h" |
| +#include "core/editing/commands/TypingCommand.h" |
| #include "core/editing/iterators/TextIterator.h" |
| #include "core/editing/serializers/HTMLInterchange.h" |
| #include "core/editing/state_machines/BackspaceStateMachine.h" |
| @@ -58,7 +60,6 @@ |
| #include "core/html/HTMLUListElement.h" |
| #include "core/layout/LayoutObject.h" |
| #include "core/layout/LayoutTableCell.h" |
| -#include "platform/clipboard/ClipboardMimeTypes.h" |
| #include "wtf/Assertions.h" |
| #include "wtf/StdLibExtras.h" |
| #include "wtf/text/StringBuilder.h" |
| @@ -2047,85 +2048,6 @@ bool isTextSecurityNode(const Node* node) { |
| node->layoutObject()->style()->textSecurity() != TSNONE; |
| } |
| -DispatchEventResult dispatchBeforeInputInsertText(EventTarget* target, |
|
chongz
2016/12/20 23:27:51
See header file.
|
| - const String& data) { |
| - if (!RuntimeEnabledFeatures::inputEventEnabled()) |
| - return DispatchEventResult::NotCanceled; |
| - if (!target) |
| - return DispatchEventResult::NotCanceled; |
| - // TODO(chongz): Pass appropriate |ranges| after it's defined on spec. |
| - // http://w3c.github.io/editing/input-events.html#dom-inputevent-inputtype |
| - InputEvent* beforeInputEvent = InputEvent::createBeforeInput( |
| - InputEvent::InputType::InsertText, data, |
| - InputEvent::EventCancelable::IsCancelable, |
| - InputEvent::EventIsComposing::NotComposing, nullptr); |
| - return target->dispatchEvent(beforeInputEvent); |
| -} |
| - |
| -DispatchEventResult dispatchBeforeInputFromComposition( |
| - EventTarget* target, |
| - InputEvent::InputType inputType, |
| - const String& data, |
| - InputEvent::EventCancelable cancelable) { |
| - if (!RuntimeEnabledFeatures::inputEventEnabled()) |
| - return DispatchEventResult::NotCanceled; |
| - if (!target) |
| - return DispatchEventResult::NotCanceled; |
| - // TODO(chongz): Pass appropriate |ranges| after it's defined on spec. |
| - // http://w3c.github.io/editing/input-events.html#dom-inputevent-inputtype |
| - InputEvent* beforeInputEvent = InputEvent::createBeforeInput( |
| - inputType, data, cancelable, InputEvent::EventIsComposing::IsComposing, |
| - nullptr); |
| - return target->dispatchEvent(beforeInputEvent); |
| -} |
| - |
| -DispatchEventResult dispatchBeforeInputEditorCommand( |
| - EventTarget* target, |
| - InputEvent::InputType inputType, |
| - const RangeVector* ranges) { |
| - if (!RuntimeEnabledFeatures::inputEventEnabled()) |
| - return DispatchEventResult::NotCanceled; |
| - if (!target) |
| - return DispatchEventResult::NotCanceled; |
| - InputEvent* beforeInputEvent = InputEvent::createBeforeInput( |
| - inputType, nullAtom, InputEvent::EventCancelable::IsCancelable, |
| - InputEvent::EventIsComposing::NotComposing, ranges); |
| - return target->dispatchEvent(beforeInputEvent); |
| -} |
| - |
| -DispatchEventResult dispatchBeforeInputDataTransfer( |
| - EventTarget* target, |
| - InputEvent::InputType inputType, |
| - DataTransfer* dataTransfer, |
| - const RangeVector* ranges) { |
| - if (!RuntimeEnabledFeatures::inputEventEnabled()) |
| - return DispatchEventResult::NotCanceled; |
| - if (!target) |
| - return DispatchEventResult::NotCanceled; |
| - |
| - DCHECK(inputType == InputEvent::InputType::InsertFromPaste || |
| - inputType == InputEvent::InputType::InsertReplacementText || |
| - inputType == InputEvent::InputType::InsertFromDrop || |
| - inputType == InputEvent::InputType::DeleteByCut) |
| - << "Unsupported inputType: " << (int)inputType; |
| - |
| - InputEvent* beforeInputEvent; |
| - |
| - if (hasRichlyEditableStyle(*(target->toNode())) || !dataTransfer) { |
|
chongz
2016/12/21 23:59:24
This logic for data vs. dataTransfer are only used
|
| - beforeInputEvent = InputEvent::createBeforeInput( |
| - inputType, dataTransfer, InputEvent::EventCancelable::IsCancelable, |
| - InputEvent::EventIsComposing::NotComposing, ranges); |
| - } else { |
| - const String& data = dataTransfer->getData(mimeTypeTextPlain); |
| - // TODO(chongz): Pass appropriate |ranges| after it's defined on spec. |
| - // http://w3c.github.io/editing/input-events.html#dom-inputevent-inputtype |
| - beforeInputEvent = InputEvent::createBeforeInput( |
| - inputType, data, InputEvent::EventCancelable::IsCancelable, |
| - InputEvent::EventIsComposing::NotComposing, nullptr); |
| - } |
| - return target->dispatchEvent(beforeInputEvent); |
| -} |
| - |
| InputEvent::InputType deletionInputTypeFromTextGranularity( |
| DeleteDirection direction, |
| TextGranularity granularity) { |
| @@ -2148,4 +2070,64 @@ InputEvent::InputType deletionInputTypeFromTextGranularity( |
| } |
| } |
| +InputEvent::EventIsComposing isComposingFromCommand( |
|
chongz
2016/12/20 23:27:51
See header file.
|
| + const CompositeEditCommand* command) { |
| + if (command->isTypingCommand() && |
| + toTypingCommand(command)->compositionType() != |
| + TypingCommand::TextCompositionNone) |
| + return InputEvent::IsComposing; |
| + return InputEvent::NotComposing; |
| +} |
| + |
| +InputEvent::EventCancelable isCancelableFromCommand( |
| + const CompositeEditCommand* command) { |
| + if (command->isTypingCommand() && |
| + toTypingCommand(command)->compositionType() == |
| + TypingCommand::TextCompositionUpdate) |
| + return InputEvent::NotCancelable; |
| + return InputEvent::IsCancelable; |
| +} |
| + |
| +bool dispatchBeforeInputEvent(EditCommandSource source, |
| + LocalFrame* frame, |
| + Node* target, |
| + InputEvent::InputType inputType, |
| + const String& data, |
| + DataTransfer* dataTransfer, |
| + InputEvent::EventCancelable isCancelable, |
| + InputEvent::EventIsComposing isComposing, |
| + const RangeVector* ranges) { |
| + // Don't fire 'beforeinput', return true to continue. |
| + if (source != EditCommandSource::kMenuOrKeyBinding || |
| + inputType == InputEvent::InputType::None) |
| + return true; |
| + if (!RuntimeEnabledFeatures::inputEventEnabled()) |
| + return true; |
| + if (!frame || !target || !target->isConnected()) |
| + return true; |
| + |
| + if (!hasRichlyEditableStyle(*target)) { |
| + // Plain-text only elements (<input>, <textarea>, etc.) don't support |
| + // DataTransfer or Range. |
| + dataTransfer = nullptr; |
| + ranges = nullptr; |
| + } |
| + |
| + InputEvent* beforeInputEvent; |
| + |
| + if (dataTransfer) { |
| + beforeInputEvent = InputEvent::createBeforeInput( |
| + inputType, dataTransfer, isCancelable, isComposing, ranges); |
| + } else { |
| + beforeInputEvent = InputEvent::createBeforeInput( |
| + inputType, data, isCancelable, isComposing, ranges); |
| + } |
| + |
| + DispatchEventResult result = target->dispatchEvent(beforeInputEvent); |
| + // 'beforeinput' event handler may destroy target frame. |
| + if (frame->document()->frame() != frame) |
|
Xiaocheng
2016/12/21 02:56:38
Is |frame->document()| still non-null after the ev
chongz
2016/12/21 23:59:24
Added check for |frame->document()|, but according
Xiaocheng
2016/12/22 06:26:20
Thanks for the clarification.
I thought |frame->d
|
| + return false; |
| + return result == DispatchEventResult::NotCanceled; |
| +} |
| + |
| } // namespace blink |