| 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 3d52f33c4ce7ab1e423ee88a80188faa17a9049f..9281164365a7f115cbc2cbe52997ce122c51d71a 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,
|
| - 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) {
|
| - 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,65 @@ InputEvent::InputType deletionInputTypeFromTextGranularity(
|
| }
|
| }
|
|
|
| +InputEvent::EventIsComposing isComposingFromCommand(
|
| + 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->document()->frame() != frame ||
|
| + !target->isConnected())
|
| + return false;
|
| + return result == DispatchEventResult::NotCanceled;
|
| +}
|
| +
|
| } // namespace blink
|
|
|