haikuwebkit/LayoutTests/fast/events/before-input-events-differe...

44 lines
1.1 KiB
HTML
Raw Permalink Normal View History

Support onbeforeinput event handling for the new InputEvent spec https://bugs.webkit.org/show_bug.cgi?id=163021 <rdar://problem/28658073> Reviewed by Darin Adler. Source/WebCore: Adds support for parsing the onbeforeinput attribute, and for sending default-preventable `beforeinput` InputEvents to the page. To do this, we introduce two new virtual methods: willApplyCommand and didApplyCommand on the CompositeEditCommand that are called before and after CompositeEditCommand::doApply, respectively. willApplyCommand indicates whether or not the composite editor command should proceed with applying the command. Tweaks existing layout tests and adds new tests. Tests: fast/events/before-input-events-different-start-end-elements.html fast/events/before-input-events-prevent-default-in-textfield.html fast/events/before-input-events-prevent-default.html * dom/Document.idl: * dom/Element.idl: * dom/EventNames.h: * dom/Node.cpp: (WebCore::Node::dispatchInputEvent): (WebCore::Node::defaultEventHandler): Currently, we fire input events in Node in response to dispatching a webkitEditableContentChangedEvent. After some discussion, Ryosuke and I believe that it will be ok to instead directly dispatch the input event where we would normally dispatch a webkitEditableContentChangedEvent. * editing/CompositeEditCommand.cpp: (WebCore::EditCommandComposition::unapply): (WebCore::EditCommandComposition::reapply): Added calls to Editor::willUnapplyEditing and Editor::willReapplyEditing. (WebCore::CompositeEditCommand::willApplyCommand): (WebCore::CompositeEditCommand::apply): (WebCore::CompositeEditCommand::didApplyCommand): Added new virtual functions, willApplyCommand and didApplyCommand, that surround a call to CompositeEditCommand::doApply. By default, they call willApplyEditing and appliedEditing on the editor, but may be overridden in special cases, such as in TypingCommand, where we invoke appliedEditing after adding a new typing command to the last open command. If willApplyCommand returns false, CompositeEditCommand::apply will bail and not proceed with the command. * editing/CompositeEditCommand.h: * editing/Editor.cpp: (WebCore::dispatchBeforeInputEvent): (WebCore::dispatchBeforeInputEvents): (WebCore::dispatchInputEvents): (WebCore::Editor::willApplyEditing): (WebCore::Editor::appliedEditing): (WebCore::Editor::willUnapplyEditing): (WebCore::Editor::unappliedEditing): (WebCore::Editor::willReapplyEditing): (WebCore::Editor::reappliedEditing): (WebCore::Editor::computeAndSetTypingStyle): (WebCore::dispatchEditableContentChangedEvents): Deleted. * editing/Editor.h: * editing/TypingCommand.cpp: (WebCore::TypingCommand::willApplyCommand): (WebCore::TypingCommand::didApplyCommand): (WebCore::TypingCommand::willAddTypingToOpenCommand): (WebCore::TypingCommand::insertTextRunWithoutNewlines): (WebCore::TypingCommand::insertLineBreak): (WebCore::TypingCommand::insertParagraphSeparator): (WebCore::TypingCommand::insertParagraphSeparatorInQuotedContent): (WebCore::TypingCommand::deleteKeyPressed): (WebCore::TypingCommand::forwardDeleteKeyPressed): (WebCore::TypingCommand::deleteSelection): These now invoke willAddTypingToOpenCommand before proceeding with creating the command and applying it. The flow is now: - willAddTypingToOpenCommand - create and apply a new command - typingAddedToOpenCommand * editing/TypingCommand.h: (WebCore::TypingCommand::preservesTypingStyle): Deleted. (WebCore::TypingCommand::shouldRetainAutocorrectionIndicator): Deleted. (WebCore::TypingCommand::setShouldRetainAutocorrectionIndicator): Deleted. (WebCore::TypingCommand::shouldStopCaretBlinking): Deleted. * html/HTMLAttributeNames.in: * html/HTMLElement.cpp: (WebCore::HTMLElement::createEventHandlerNameMap): LayoutTests: Tweak an existing test to hook into the 'input' event instead of 'webkitEditableContentChanged', as well as tests added in r206843 to verify that `onbeforeinput` handlers are invoked with InputEvents. Also introduces new unit tests verifying that calling preventDefault on InputEvents fired by `onbeforeinput` correctly prevent text from being inserted or deleted. * editing/undo/undo-after-event-edited.html: * fast/events/before-input-events-different-start-end-elements-expected.txt: Added. * fast/events/before-input-events-different-start-end-elements.html: Added. * fast/events/before-input-events-prevent-default-expected.txt: Added. * fast/events/before-input-events-prevent-default-in-textfield-expected.txt: Added. * fast/events/before-input-events-prevent-default-in-textfield.html: Added. * fast/events/before-input-events-prevent-default.html: Added. * fast/events/input-events-fired-when-typing-expected.txt: * fast/events/input-events-fired-when-typing.html: * platform/ios-simulator/TestExpectations: Canonical link: https://commits.webkit.org/180992@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@206944 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-10-07 23:47:18 +00:00
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<script src="../../resources/js-test-pre.js"></script>
<script>
function beginTest()
{
if (!window.eventSender || !window.internals || !window.testRunner)
return;
internals.settings.setInputEventsEnabled(true);
testRunner.dumpAsText();
document.querySelector("#foo").focus();
for (var i = 0; i < 11; i++)
eventSender.keyDown("delete");
}
function checkInputEvent(event)
{
debug("Fired `oninput` handler!");
}
function checkBeforeInputEvent(event)
{
debug("Fired `onbeforeinput` handler!");
}
</script>
</head>
<body onload=beginTest()>
<div id="foo" contenteditable oninput=checkInputEvent(event) onbeforeinput=checkBeforeInputEvent(event)>
<b>
abc
<i>def</i>
<u>ghi</u>
</b>
</div>
<script src="../../resources/js-test-post.js"></script>
</body>
</html>