Implement InputEvent.getTargetRanges() for the input events spec
authorwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 21 Oct 2016 15:51:28 +0000 (15:51 +0000)
committerwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 21 Oct 2016 15:51:28 +0000 (15:51 +0000)
https://bugs.webkit.org/show_bug.cgi?id=162947
<rdar://problem/28853079>

Reviewed by Darin Adler.

Source/JavaScriptCore:

Boilerplate change to add a runtime guard for InputEvents-related IDL interfaces. See WebCore ChangeLog entry
for more details.

* runtime/CommonIdentifiers.h:

Source/WebCore:

Implements InputEvent.getTargetRanges(). See individual method changes below for more details. Adds a new hook
for subclasses of CompositeEditCommand to vend a list of target StaticRanges when retrieving target ranges for
an editing command on a contenteditable area.

Tests: fast/events/before-input-delete-empty-list-target-ranges.html
       fast/events/before-input-delete-text-target-ranges.html
       fast/events/before-input-replace-text-target-ranges.html

* CMakeLists.txt:
* DerivedSources.make:
* WebCore.xcodeproj/project.pbxproj:

Add StaticRange.idl, StaticRange.cpp and StaticRange.h.

* bindings/generic/RuntimeEnabledFeatures.h:
(WebCore::RuntimeEnabledFeatures::setInputEventsEnabled):
(WebCore::RuntimeEnabledFeatures::inputEventsEnabled):

Add a new runtime bindings flag for InputEvents and guard both InputEvent and StaticRange behind it.

* dom/DOMAllInOne.cpp:
* dom/InputEvent.cpp:
(WebCore::InputEvent::InputEvent):
* dom/InputEvent.h:
* dom/InputEvent.idl:
* dom/StaticRange.cpp: Copied from Source/WebCore/dom/InputEvent.cpp.
(WebCore::StaticRange::StaticRange):
(WebCore::StaticRange::create):
(WebCore::StaticRange::createFromRange):

Convenience method for creating a StaticRange from a Range's start/end container and offset.

(WebCore::StaticRange::startContainer):
(WebCore::StaticRange::endContainer):
(WebCore::StaticRange::collapsed):
* dom/StaticRange.h: Copied from Source/WebCore/dom/InputEvent.cpp.
(WebCore::StaticRange::startOffset):
(WebCore::StaticRange::endOffset):
* dom/StaticRange.idl: Copied from Source/WebCore/editing/ReplaceRangeWithTextCommand.h.
* editing/CompositeEditCommand.cpp:
(WebCore::CompositeEditCommand::willApplyCommand):
(WebCore::CompositeEditCommand::targetRanges):

Virtual method that returns a list of target ranges which are associated with this command.

(WebCore::CompositeEditCommand::targetRangesForBindings):

Non-virtual method that calls the above targetRanges(). Takes whether or not the CompositeEditCommand is editing
a textarea or plain text input into account.

(WebCore::CompositeEditCommand::moveParagraphs):
* editing/CompositeEditCommand.h:
* editing/EditCommand.cpp:
(WebCore::EditCommand::frame):
* editing/EditCommand.h:
(WebCore::EditCommand::document):
* editing/Editor.cpp:
(WebCore::dispatchBeforeInputEvent):
(WebCore::dispatchInputEvent):
(WebCore::dispatchBeforeInputEvents):

Changed the `beforeinput` event dispatch to use the regular Node::dispatchEvent instead of dispatchScopedEvent.
This is because if the page prevents the `beforeinput` event, we need to know immediately in order to bail from
the default action.

(WebCore::dispatchInputEvents):
(WebCore::Editor::willApplyEditing):

Added a list of static ranges as a parameter when calling on the Editor to dispatch `beforeinput` events.
By default, this uses the composite edit command's targetRangesForBindings(), though it may be special cased
by subclasses of CompositeEditCommand (see ReplaceRangeWithTextCommand, SpellingCorrectionCommand, and
TypingCommand).

* editing/Editor.h:
* editing/ReplaceRangeWithTextCommand.cpp:
(WebCore::ReplaceRangeWithTextCommand::targetRanges):
* editing/ReplaceRangeWithTextCommand.h:
* editing/SpellingCorrectionCommand.cpp:
(WebCore::SpellingCorrectionCommand::targetRanges):
* editing/SpellingCorrectionCommand.h:
* editing/TypingCommand.cpp:
(WebCore::editActionIsDeleteByTyping):
(WebCore::TypingCommand::shouldDeferWillApplyCommandUntilAddingTypingCommand):
(WebCore::TypingCommand::willApplyCommand):
(WebCore::TypingCommand::willAddTypingToOpenCommand):
(WebCore::TypingCommand::deleteKeyPressed):
(WebCore::TypingCommand::forwardDeleteKeyPressed):

Moves the firing of the `beforeinput` until after the selection range to delete has been computed.

* editing/TypingCommand.h:

Source/WebKit2:

Boilerplate change to add a runtime guard for InputEvents-related IDL interfaces. See WebCore ChangeLog entry
for more details.

* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::updatePreferences):

LayoutTests:

Adds 3 new layout tests and tweaks some existing unit tests. See WebCore ChangeLog entry for more details.
Tests verify the result of getTargetRanges() when breaking out of a list, deleting backwards and forwards at
all text granularities, deleting selected text, and spell checking (candidate text replacement).

* fast/events/before-input-delete-empty-list-target-ranges-expected.txt: Added.
* fast/events/before-input-delete-empty-list-target-ranges.html: Added.
* fast/events/before-input-delete-text-target-ranges-expected.txt: Added.
* fast/events/before-input-delete-text-target-ranges.html: Added.
* fast/events/before-input-events-prevent-default-in-textfield.html:
* fast/events/before-input-replace-text-target-ranges-expected.txt: Added.
* fast/events/before-input-replace-text-target-ranges.html: Added.
* fast/events/input-events-fired-when-typing-expected.txt:
* fast/events/input-events-fired-when-typing.html:
* js/dom/global-constructors-attributes-expected.txt:
* platform/ios-simulator/TestExpectations:
* platform/mac-wk1/js/dom/global-constructors-attributes-expected.txt:
* platform/mac-yosemite/js/dom/global-constructors-attributes-expected.txt:
* platform/mac/js/dom/global-constructors-attributes-expected.txt:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@207670 268f45cc-cd09-0410-ab3c-d52691b4dbfc

43 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/events/before-input-delete-empty-list-target-ranges-expected.txt [new file with mode: 0644]
LayoutTests/fast/events/before-input-delete-empty-list-target-ranges.html [new file with mode: 0644]
LayoutTests/fast/events/before-input-delete-text-target-ranges-expected.txt [new file with mode: 0644]
LayoutTests/fast/events/before-input-delete-text-target-ranges.html [new file with mode: 0644]
LayoutTests/fast/events/before-input-events-prevent-default-in-textfield.html
LayoutTests/fast/events/before-input-replace-text-target-ranges-expected.txt [new file with mode: 0644]
LayoutTests/fast/events/before-input-replace-text-target-ranges.html [new file with mode: 0644]
LayoutTests/fast/events/input-events-fired-when-typing-expected.txt
LayoutTests/fast/events/input-events-fired-when-typing.html
LayoutTests/js/dom/global-constructors-attributes-expected.txt
LayoutTests/platform/ios-simulator/TestExpectations
LayoutTests/platform/mac-wk1/js/dom/global-constructors-attributes-expected.txt
LayoutTests/platform/mac-yosemite/js/dom/global-constructors-attributes-expected.txt
LayoutTests/platform/mac/js/dom/global-constructors-attributes-expected.txt
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/runtime/CommonIdentifiers.h
Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
Source/WebCore/DerivedSources.make
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/bindings/generic/RuntimeEnabledFeatures.h
Source/WebCore/dom/DOMAllInOne.cpp
Source/WebCore/dom/InputEvent.cpp
Source/WebCore/dom/InputEvent.h
Source/WebCore/dom/InputEvent.idl
Source/WebCore/dom/StaticRange.cpp [new file with mode: 0644]
Source/WebCore/dom/StaticRange.h [new file with mode: 0644]
Source/WebCore/dom/StaticRange.idl [new file with mode: 0644]
Source/WebCore/editing/CompositeEditCommand.cpp
Source/WebCore/editing/CompositeEditCommand.h
Source/WebCore/editing/EditCommand.cpp
Source/WebCore/editing/EditCommand.h
Source/WebCore/editing/Editor.cpp
Source/WebCore/editing/Editor.h
Source/WebCore/editing/ReplaceRangeWithTextCommand.cpp
Source/WebCore/editing/ReplaceRangeWithTextCommand.h
Source/WebCore/editing/SpellingCorrectionCommand.cpp
Source/WebCore/editing/SpellingCorrectionCommand.h
Source/WebCore/editing/TypingCommand.cpp
Source/WebCore/editing/TypingCommand.h
Source/WebKit2/ChangeLog
Source/WebKit2/WebProcess/WebPage/WebPage.cpp

index 6325438..dced0ae 100644 (file)
@@ -1,3 +1,30 @@
+2016-10-21  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        Implement InputEvent.getTargetRanges() for the input events spec
+        https://bugs.webkit.org/show_bug.cgi?id=162947
+        <rdar://problem/28853079>
+
+        Reviewed by Darin Adler.
+
+        Adds 3 new layout tests and tweaks some existing unit tests. See WebCore ChangeLog entry for more details.
+        Tests verify the result of getTargetRanges() when breaking out of a list, deleting backwards and forwards at
+        all text granularities, deleting selected text, and spell checking (candidate text replacement).
+
+        * fast/events/before-input-delete-empty-list-target-ranges-expected.txt: Added.
+        * fast/events/before-input-delete-empty-list-target-ranges.html: Added.
+        * fast/events/before-input-delete-text-target-ranges-expected.txt: Added.
+        * fast/events/before-input-delete-text-target-ranges.html: Added.
+        * fast/events/before-input-events-prevent-default-in-textfield.html:
+        * fast/events/before-input-replace-text-target-ranges-expected.txt: Added.
+        * fast/events/before-input-replace-text-target-ranges.html: Added.
+        * fast/events/input-events-fired-when-typing-expected.txt:
+        * fast/events/input-events-fired-when-typing.html:
+        * js/dom/global-constructors-attributes-expected.txt:
+        * platform/ios-simulator/TestExpectations:
+        * platform/mac-wk1/js/dom/global-constructors-attributes-expected.txt:
+        * platform/mac-yosemite/js/dom/global-constructors-attributes-expected.txt:
+        * platform/mac/js/dom/global-constructors-attributes-expected.txt:
+
 2016-10-21  Javier Fernandez  <jfernandez@igalia.com>
 
         [css-grid] Content Alignment broken with indefinite sized grid container
diff --git a/LayoutTests/fast/events/before-input-delete-empty-list-target-ranges-expected.txt b/LayoutTests/fast/events/before-input-delete-empty-list-target-ranges-expected.txt
new file mode 100644 (file)
index 0000000..567812a
--- /dev/null
@@ -0,0 +1,17 @@
+To manually test this, delete the empty list element and observe the output.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS event.getTargetRanges().length is 1
+PASS range.startContainer.nodeName is '#text'
+PASS range.startContainer.textContent is 'foo'
+PASS range.endContainer is item
+PASS range.startOffset is 3
+PASS range.endOffset is 0
+PASS successfullyParsed is true
+
+TEST COMPLETE
+foo
+
+
diff --git a/LayoutTests/fast/events/before-input-delete-empty-list-target-ranges.html b/LayoutTests/fast/events/before-input-delete-empty-list-target-ranges.html
new file mode 100644 (file)
index 0000000..25226e0
--- /dev/null
@@ -0,0 +1,36 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <script src="../../resources/js-test-pre.js"></script>
+</head>
+<body>
+    <div id="editable" contenteditable onbeforeinput=beforeinput(event)>foo<div><ul><li id="item"><br></li></ul></div></div>
+    <script type="text/javascript">
+        description("To manually test this, delete the empty list element and observe the output.");
+
+        editable.focus();
+        getSelection().setPosition(item);
+
+        if (window.internals)
+            internals.settings.setInputEventsEnabled(true);
+
+        if (window.testRunner)
+            testRunner.execCommand("deleteBackward");
+
+        function beforeinput(event)
+        {
+            shouldBe("event.getTargetRanges().length", "1");
+            for (let range of event.getTargetRanges()) {
+                window.range = range;
+                shouldBe("range.startContainer.nodeName", "'#text'");
+                shouldBe("range.startContainer.textContent", "'foo'");
+                shouldBe("range.endContainer", "item");
+                shouldBe("range.startOffset", "3");
+                shouldBe("range.endOffset", "0");
+            }
+            event.preventDefault();
+        }
+    </script>
+    <script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
\ No newline at end of file
diff --git a/LayoutTests/fast/events/before-input-delete-text-target-ranges-expected.txt b/LayoutTests/fast/events/before-input-delete-text-target-ranges-expected.txt
new file mode 100644 (file)
index 0000000..e72b7ac
--- /dev/null
@@ -0,0 +1,33 @@
+To manually test this, try deleting backwards/forwards at various text granularities and observe the output.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS event.inputType.startsWith('delete') is true
+PASS deletionRange.startContainer is deletionRange.endContainer
+Deleting text in range: [0, 1]
+PASS event.inputType.startsWith('delete') is true
+PASS deletionRange.startContainer is deletionRange.endContainer
+Deleting text in range: [3, 4]
+PASS event.inputType.startsWith('delete') is true
+PASS deletionRange.startContainer is deletionRange.endContainer
+Deleting text in range: [2, 3]
+PASS event.inputType.startsWith('delete') is true
+PASS deletionRange.startContainer is deletionRange.endContainer
+Deleting text in range: [16, 17]
+PASS event.inputType.startsWith('delete') is true
+PASS deletionRange.startContainer is deletionRange.endContainer
+Deleting text in range: [0, 17]
+PASS event.inputType.startsWith('delete') is true
+PASS deletionRange.startContainer is deletionRange.endContainer
+Deleting text in range: [4, 7]
+PASS event.inputType.startsWith('delete') is true
+PASS deletionRange.startContainer is deletionRange.endContainer
+Deleting text in range: [7, 10]
+PASS event.inputType.startsWith('delete') is true
+PASS deletionRange.startContainer is deletionRange.endContainer
+Deleting text in range: [0, 10]
+PASS successfullyParsed is true
+
+TEST COMPLETE
+foo barbaz garply
diff --git a/LayoutTests/fast/events/before-input-delete-text-target-ranges.html b/LayoutTests/fast/events/before-input-delete-text-target-ranges.html
new file mode 100644 (file)
index 0000000..e8a77bc
--- /dev/null
@@ -0,0 +1,59 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <script src="../../resources/js-test-pre.js"></script>
+</head>
+<body>
+    <div id="editable" contenteditable onbeforeinput=beforeinput(event)>foo barbaz garply</div>
+    <script type="text/javascript">
+        description("To manually test this, try deleting backwards/forwards at various text granularities and observe the output.");
+
+        editable.focus();
+
+        if (window.internals)
+            internals.settings.setInputEventsEnabled(true);
+
+        if (window.testRunner) {
+            select(0, 0);
+            testRunner.execCommand("deleteForward");
+
+            select(3, 3);
+            testRunner.execCommand("deleteForward");
+            testRunner.execCommand("deleteBackward");
+
+            select(17, 17);
+            testRunner.execCommand("deleteBackward");
+            testRunner.execCommand("deleteToBeginningOfLine");
+
+            select(7, 7);
+            testRunner.execCommand("deleteWordBackward");
+            testRunner.execCommand("deleteWordForward");
+
+            select(0, 10);
+            testRunner.execCommand("deleteBackward");
+        }
+
+        function beforeinput(event)
+        {
+            shouldBeTrue("event.inputType.startsWith('delete')");
+
+            window.deletionRange = event.getTargetRanges()[0];
+            shouldBe("deletionRange.startContainer", "deletionRange.endContainer");
+            debug(`Deleting text in range: [${deletionRange.startOffset}, ${deletionRange.endOffset}]`)
+            event.preventDefault();
+        }
+
+        function select(startOffset, endOffset)
+        {
+            let range = document.createRange();
+            let textNode = editable.childNodes[0];
+
+            getSelection().removeAllRanges();
+            range.setStart(textNode, startOffset);
+            range.setEnd(textNode, endOffset);
+            getSelection().addRange(range);
+        }
+    </script>
+    <script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
\ No newline at end of file
index c6273bb..2ee3dcb 100644 (file)
@@ -22,7 +22,7 @@
 
             preventDefaultInputEvents = true;
 
-            eventSender.keyDown("delete");
+            testRunner.execCommand("DeleteBackward");
             debug(`The final value is: ${input.value}`);
         }
 
diff --git a/LayoutTests/fast/events/before-input-replace-text-target-ranges-expected.txt b/LayoutTests/fast/events/before-input-replace-text-target-ranges-expected.txt
new file mode 100644 (file)
index 0000000..84f0cd0
--- /dev/null
@@ -0,0 +1,13 @@
+To manually test this, type "hllo" and trigger spell checking. Select a spell checking candidate.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS replacementRange.startOffset is 0
+PASS replacementRange.endOffset is 4
+PASS replacementRange.startContainer is editable.childNodes[0]
+PASS replacementRange.endContainer is editable.childNodes[0]
+PASS successfullyParsed is true
+
+TEST COMPLETE
+hllo
diff --git a/LayoutTests/fast/events/before-input-replace-text-target-ranges.html b/LayoutTests/fast/events/before-input-replace-text-target-ranges.html
new file mode 100644 (file)
index 0000000..37aeaca
--- /dev/null
@@ -0,0 +1,37 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <script src="../../resources/js-test-pre.js"></script>
+</head>
+<body>
+    <div id="editable" contenteditable onbeforeinput=beforeinput(event)></div>
+    <script type="text/javascript">
+        description("To manually test this, type \"hllo\" and trigger spell checking. Select a spell checking candidate.");
+
+        editable.focus();
+
+        if (window.eventSender && window.internals) {
+            internals.settings.setInputEventsEnabled(true);
+            eventSender.keyDown("h");
+            eventSender.keyDown("l");
+            eventSender.keyDown("l");
+            eventSender.keyDown("o");
+            internals.handleAcceptedCandidate("hello", 0, 4);
+        }
+
+        function beforeinput(event)
+        {
+            if (event.inputType !== "insertReplacementText")
+                return;
+
+            window.replacementRange = event.getTargetRanges()[0];
+            shouldBe("replacementRange.startOffset", "0");
+            shouldBe("replacementRange.endOffset", "4");
+            shouldBe("replacementRange.startContainer", "editable.childNodes[0]");
+            shouldBe("replacementRange.endContainer", "editable.childNodes[0]");
+            event.preventDefault();
+        }
+    </script>
+    <script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
\ No newline at end of file
index 2e20fcc..a5d6d07 100644 (file)
@@ -4,7 +4,7 @@ TEST COMPLETE
 Fired `onbeforeinput`!
 PASS event.__lookupGetter__('inputType') is defined.
 PASS event.__lookupGetter__('data') is defined.
-PASS Object.getPrototypeOf(event) is InputEvent.prototype
+PASS event.getTargetRanges is defined.
 PASS event.target.id is expectedTargetID
 PASS event.bubbles is true
 PASS event.cancelable is true
@@ -12,7 +12,7 @@ PASS event.composed is true
 Fired `oninput`!
 PASS event.__lookupGetter__('inputType') is defined.
 PASS event.__lookupGetter__('data') is defined.
-PASS Object.getPrototypeOf(event) is InputEvent.prototype
+PASS event.getTargetRanges is defined.
 PASS event.target.id is expectedTargetID
 PASS event.bubbles is true
 PASS event.cancelable is false
@@ -20,7 +20,7 @@ PASS event.composed is true
 Fired `onbeforeinput`!
 PASS event.__lookupGetter__('inputType') is defined.
 PASS event.__lookupGetter__('data') is defined.
-PASS Object.getPrototypeOf(event) is InputEvent.prototype
+PASS event.getTargetRanges is defined.
 PASS event.target.id is expectedTargetID
 PASS event.bubbles is true
 PASS event.cancelable is true
@@ -28,7 +28,7 @@ PASS event.composed is true
 Fired `oninput`!
 PASS event.__lookupGetter__('inputType') is defined.
 PASS event.__lookupGetter__('data') is defined.
-PASS Object.getPrototypeOf(event) is InputEvent.prototype
+PASS event.getTargetRanges is defined.
 PASS event.target.id is expectedTargetID
 PASS event.bubbles is true
 PASS event.cancelable is false
index 6203860..e9c1227 100644 (file)
@@ -36,7 +36,7 @@
             debug("Fired `oninput`!");
             shouldBeDefined("event.__lookupGetter__('inputType')");
             shouldBeDefined("event.__lookupGetter__('data')");
-            shouldBe("Object.getPrototypeOf(event)", "InputEvent.prototype");
+            shouldBeDefined("event.getTargetRanges");
             shouldBe("event.target.id", "expectedTargetID");
             shouldBe("event.bubbles", "true");
             shouldBe("event.cancelable", "false");
@@ -48,7 +48,7 @@
             debug("Fired `onbeforeinput`!");
             shouldBeDefined("event.__lookupGetter__('inputType')");
             shouldBeDefined("event.__lookupGetter__('data')");
-            shouldBe("Object.getPrototypeOf(event)", "InputEvent.prototype");
+            shouldBeDefined("event.getTargetRanges");
             shouldBe("event.target.id", "expectedTargetID");
             shouldBe("event.bubbles", "true");
             shouldBe("event.cancelable", "true");
index e59a60a..ef9cb7d 100644 (file)
@@ -1798,6 +1798,11 @@ PASS Object.getOwnPropertyDescriptor(global, 'SpeechSynthesisUtterance').hasOwnP
 PASS Object.getOwnPropertyDescriptor(global, 'SpeechSynthesisUtterance').hasOwnProperty('set') is false
 PASS Object.getOwnPropertyDescriptor(global, 'SpeechSynthesisUtterance').enumerable is false
 PASS Object.getOwnPropertyDescriptor(global, 'SpeechSynthesisUtterance').configurable is true
+PASS Object.getOwnPropertyDescriptor(global, 'StaticRange').value is StaticRange
+PASS Object.getOwnPropertyDescriptor(global, 'StaticRange').hasOwnProperty('get') is false
+PASS Object.getOwnPropertyDescriptor(global, 'StaticRange').hasOwnProperty('set') is false
+PASS Object.getOwnPropertyDescriptor(global, 'StaticRange').enumerable is false
+PASS Object.getOwnPropertyDescriptor(global, 'StaticRange').configurable is true
 PASS Object.getOwnPropertyDescriptor(global, 'Storage').value is Storage
 PASS Object.getOwnPropertyDescriptor(global, 'Storage').hasOwnProperty('get') is false
 PASS Object.getOwnPropertyDescriptor(global, 'Storage').hasOwnProperty('set') is false
index 5090f28..14f37b4 100644 (file)
@@ -1217,6 +1217,9 @@ fast/events/before-input-prevent-cut.html [ Failure ]
 fast/events/before-input-prevent-paste.html [ Failure ]
 fast/events/before-input-prevent-undo.html [ Failure ]
 fast/events/before-input-prevent-typing.html [ Failure ]
+fast/events/before-input-delete-text-target-ranges.html [ Failure ]
+fast/events/before-input-replace-text-target-ranges.html [ Failure ]
+fast/events/before-input-delete-empty-list-target-ranges.html [ Failure ]
 fast/events/key-events-in-input-button.html [ Failure ]
 fast/events/keydown-1.html [ Failure ]
 fast/events/keydown-leftright-keys.html [ Failure ]
index a7fb086..3bf65a8 100644 (file)
@@ -923,11 +923,6 @@ PASS Object.getOwnPropertyDescriptor(global, 'ImageData').hasOwnProperty('get')
 PASS Object.getOwnPropertyDescriptor(global, 'ImageData').hasOwnProperty('set') is false
 PASS Object.getOwnPropertyDescriptor(global, 'ImageData').enumerable is false
 PASS Object.getOwnPropertyDescriptor(global, 'ImageData').configurable is true
-PASS Object.getOwnPropertyDescriptor(global, 'InputEvent').value is InputEvent
-PASS Object.getOwnPropertyDescriptor(global, 'InputEvent').hasOwnProperty('get') is false
-PASS Object.getOwnPropertyDescriptor(global, 'InputEvent').hasOwnProperty('set') is false
-PASS Object.getOwnPropertyDescriptor(global, 'InputEvent').enumerable is false
-PASS Object.getOwnPropertyDescriptor(global, 'InputEvent').configurable is true
 PASS Object.getOwnPropertyDescriptor(global, 'Int16Array').value is Int16Array
 PASS Object.getOwnPropertyDescriptor(global, 'Int16Array').hasOwnProperty('get') is false
 PASS Object.getOwnPropertyDescriptor(global, 'Int16Array').hasOwnProperty('set') is false
index 729e2c1..9df56a1 100644 (file)
@@ -2038,6 +2038,11 @@ PASS Object.getOwnPropertyDescriptor(global, 'SpeechSynthesisUtterance').hasOwnP
 PASS Object.getOwnPropertyDescriptor(global, 'SpeechSynthesisUtterance').hasOwnProperty('set') is false
 PASS Object.getOwnPropertyDescriptor(global, 'SpeechSynthesisUtterance').enumerable is false
 PASS Object.getOwnPropertyDescriptor(global, 'SpeechSynthesisUtterance').configurable is true
+PASS Object.getOwnPropertyDescriptor(global, 'StaticRange').value is StaticRange
+PASS Object.getOwnPropertyDescriptor(global, 'StaticRange').hasOwnProperty('get') is false
+PASS Object.getOwnPropertyDescriptor(global, 'StaticRange').hasOwnProperty('set') is false
+PASS Object.getOwnPropertyDescriptor(global, 'StaticRange').enumerable is false
+PASS Object.getOwnPropertyDescriptor(global, 'StaticRange').configurable is true
 PASS Object.getOwnPropertyDescriptor(global, 'Storage').value is Storage
 PASS Object.getOwnPropertyDescriptor(global, 'Storage').hasOwnProperty('get') is false
 PASS Object.getOwnPropertyDescriptor(global, 'Storage').hasOwnProperty('set') is false
index 0718f82..16e276b 100644 (file)
@@ -2038,6 +2038,11 @@ PASS Object.getOwnPropertyDescriptor(global, 'SpeechSynthesisUtterance').hasOwnP
 PASS Object.getOwnPropertyDescriptor(global, 'SpeechSynthesisUtterance').hasOwnProperty('set') is false
 PASS Object.getOwnPropertyDescriptor(global, 'SpeechSynthesisUtterance').enumerable is false
 PASS Object.getOwnPropertyDescriptor(global, 'SpeechSynthesisUtterance').configurable is true
+PASS Object.getOwnPropertyDescriptor(global, 'StaticRange').value is StaticRange
+PASS Object.getOwnPropertyDescriptor(global, 'StaticRange').hasOwnProperty('get') is false
+PASS Object.getOwnPropertyDescriptor(global, 'StaticRange').hasOwnProperty('set') is false
+PASS Object.getOwnPropertyDescriptor(global, 'StaticRange').enumerable is false
+PASS Object.getOwnPropertyDescriptor(global, 'StaticRange').configurable is true
 PASS Object.getOwnPropertyDescriptor(global, 'Storage').value is Storage
 PASS Object.getOwnPropertyDescriptor(global, 'Storage').hasOwnProperty('get') is false
 PASS Object.getOwnPropertyDescriptor(global, 'Storage').hasOwnProperty('set') is false
index b5279e1..760db37 100644 (file)
@@ -1,3 +1,16 @@
+2016-10-21  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        Implement InputEvent.getTargetRanges() for the input events spec
+        https://bugs.webkit.org/show_bug.cgi?id=162947
+        <rdar://problem/28853079>
+
+        Reviewed by Darin Adler.
+
+        Boilerplate change to add a runtime guard for InputEvents-related IDL interfaces. See WebCore ChangeLog entry
+        for more details.
+
+        * runtime/CommonIdentifiers.h:
+
 2016-10-20  Zan Dobersek  <zdobersek@igalia.com>
 
         Fix JSC cast-align compiler warnings on ARMv7
index 7ae17d3..5c8c76f 100644 (file)
@@ -63,6 +63,7 @@
     macro(IDBTransaction) \
     macro(IDBVersionChangeEvent) \
     macro(Infinity) \
+    macro(InputEvent) \
     macro(Intl) \
     macro(JSON) \
     macro(Loader) \
@@ -88,6 +89,7 @@
     macro(Set)\
     macro(SetIterator)\
     macro(ShadowRoot) \
+    macro(StaticRange) \
     macro(String) \
     macro(Symbol) \
     macro(SyntaxError) \
index 74803a5..b6a70fe 100644 (file)
@@ -440,6 +440,7 @@ set(WebCore_NON_SVG_IDL_FILES
     dom/SecurityPolicyViolationEvent.idl
     dom/ShadowRoot.idl
     dom/Slotable.idl
+    dom/StaticRange.idl
     dom/StringCallback.idl
     dom/Text.idl
     dom/TextEvent.idl
@@ -1507,6 +1508,7 @@ set(WebCore_SOURCES
     dom/SlotAssignment.cpp
     dom/SpaceSplitString.cpp
     dom/StaticNodeList.cpp
+    dom/StaticRange.cpp
     dom/StringCallback.cpp
     dom/StyledElement.cpp
     dom/TagCollection.cpp
index 8b9f4f8..3baefcb 100644 (file)
@@ -1,3 +1,103 @@
+2016-10-21  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        Implement InputEvent.getTargetRanges() for the input events spec
+        https://bugs.webkit.org/show_bug.cgi?id=162947
+        <rdar://problem/28853079>
+
+        Reviewed by Darin Adler.
+
+        Implements InputEvent.getTargetRanges(). See individual method changes below for more details. Adds a new hook
+        for subclasses of CompositeEditCommand to vend a list of target StaticRanges when retrieving target ranges for
+        an editing command on a contenteditable area.
+
+        Tests: fast/events/before-input-delete-empty-list-target-ranges.html
+               fast/events/before-input-delete-text-target-ranges.html
+               fast/events/before-input-replace-text-target-ranges.html
+
+        * CMakeLists.txt:
+        * DerivedSources.make:
+        * WebCore.xcodeproj/project.pbxproj:
+
+        Add StaticRange.idl, StaticRange.cpp and StaticRange.h.
+
+        * bindings/generic/RuntimeEnabledFeatures.h:
+        (WebCore::RuntimeEnabledFeatures::setInputEventsEnabled):
+        (WebCore::RuntimeEnabledFeatures::inputEventsEnabled):
+
+        Add a new runtime bindings flag for InputEvents and guard both InputEvent and StaticRange behind it.
+
+        * dom/DOMAllInOne.cpp:
+        * dom/InputEvent.cpp:
+        (WebCore::InputEvent::InputEvent):
+        * dom/InputEvent.h:
+        * dom/InputEvent.idl:
+        * dom/StaticRange.cpp: Copied from Source/WebCore/dom/InputEvent.cpp.
+        (WebCore::StaticRange::StaticRange):
+        (WebCore::StaticRange::create):
+        (WebCore::StaticRange::createFromRange):
+
+        Convenience method for creating a StaticRange from a Range's start/end container and offset.
+
+        (WebCore::StaticRange::startContainer):
+        (WebCore::StaticRange::endContainer):
+        (WebCore::StaticRange::collapsed):
+        * dom/StaticRange.h: Copied from Source/WebCore/dom/InputEvent.cpp.
+        (WebCore::StaticRange::startOffset):
+        (WebCore::StaticRange::endOffset):
+        * dom/StaticRange.idl: Copied from Source/WebCore/editing/ReplaceRangeWithTextCommand.h.
+        * editing/CompositeEditCommand.cpp:
+        (WebCore::CompositeEditCommand::willApplyCommand):
+        (WebCore::CompositeEditCommand::targetRanges):
+
+        Virtual method that returns a list of target ranges which are associated with this command.
+
+        (WebCore::CompositeEditCommand::targetRangesForBindings):
+
+        Non-virtual method that calls the above targetRanges(). Takes whether or not the CompositeEditCommand is editing
+        a textarea or plain text input into account.
+
+        (WebCore::CompositeEditCommand::moveParagraphs):
+        * editing/CompositeEditCommand.h:
+        * editing/EditCommand.cpp:
+        (WebCore::EditCommand::frame):
+        * editing/EditCommand.h:
+        (WebCore::EditCommand::document):
+        * editing/Editor.cpp:
+        (WebCore::dispatchBeforeInputEvent):
+        (WebCore::dispatchInputEvent):
+        (WebCore::dispatchBeforeInputEvents):
+
+        Changed the `beforeinput` event dispatch to use the regular Node::dispatchEvent instead of dispatchScopedEvent.
+        This is because if the page prevents the `beforeinput` event, we need to know immediately in order to bail from
+        the default action.
+
+        (WebCore::dispatchInputEvents):
+        (WebCore::Editor::willApplyEditing):
+
+        Added a list of static ranges as a parameter when calling on the Editor to dispatch `beforeinput` events.
+        By default, this uses the composite edit command's targetRangesForBindings(), though it may be special cased
+        by subclasses of CompositeEditCommand (see ReplaceRangeWithTextCommand, SpellingCorrectionCommand, and
+        TypingCommand).
+
+        * editing/Editor.h:
+        * editing/ReplaceRangeWithTextCommand.cpp:
+        (WebCore::ReplaceRangeWithTextCommand::targetRanges):
+        * editing/ReplaceRangeWithTextCommand.h:
+        * editing/SpellingCorrectionCommand.cpp:
+        (WebCore::SpellingCorrectionCommand::targetRanges):
+        * editing/SpellingCorrectionCommand.h:
+        * editing/TypingCommand.cpp:
+        (WebCore::editActionIsDeleteByTyping):
+        (WebCore::TypingCommand::shouldDeferWillApplyCommandUntilAddingTypingCommand):
+        (WebCore::TypingCommand::willApplyCommand):
+        (WebCore::TypingCommand::willAddTypingToOpenCommand):
+        (WebCore::TypingCommand::deleteKeyPressed):
+        (WebCore::TypingCommand::forwardDeleteKeyPressed):
+
+        Moves the firing of the `beforeinput` until after the selection range to delete has been computed.
+
+        * editing/TypingCommand.h:
+
 2016-10-21  Antti Koivisto  <antti@apple.com>
 
         Style resolver should be updated lazily
index 818ad90..2dc4ea7 100644 (file)
@@ -350,6 +350,7 @@ JS_BINDING_IDLS = \
     $(WebCore)/dom/SecurityPolicyViolationEvent.idl \
     $(WebCore)/dom/ShadowRoot.idl \
     $(WebCore)/dom/Slotable.idl \
+    $(WebCore)/dom/StaticRange.idl \
     $(WebCore)/dom/StringCallback.idl \
     $(WebCore)/dom/Text.idl \
     $(WebCore)/dom/TextEvent.idl \
index 5a809db..e26f1b2 100644 (file)
                A86629D209DA2B48009633A5 /* JSMouseEvent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A86629CC09DA2B47009633A5 /* JSMouseEvent.cpp */; };
                A86629D309DA2B48009633A5 /* JSKeyboardEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = A86629CD09DA2B47009633A5 /* JSKeyboardEvent.h */; };
                A86629D309DA2B48009633A6 /* JSInputEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = A86629CD09DA2B47009633A6 /* JSInputEvent.h */; };
+               A86629D309DA2B48009633A7 /* JSStaticRange.h in Headers */ = {isa = PBXBuildFile; fileRef = A86629CD09DA2B47009633A7 /* JSStaticRange.h */; };
                A86629D409DA2B48009633A5 /* JSKeyboardEvent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A86629CE09DA2B47009633A5 /* JSKeyboardEvent.cpp */; };
                A86629D409DA2B48009633A6 /* JSInputEvent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A86629CE09DA2B47009633A6 /* JSInputEvent.cpp */; };
+               A86629D409DA2B48009633A7 /* JSStaticRange.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A86629CE09DA2B47009633A7 /* JSStaticRange.cpp */; };
                A871D4560A127CBC00B12A68 /* HTMLPlugInElement.h in Headers */ = {isa = PBXBuildFile; fileRef = A871D44C0A127CBC00B12A68 /* HTMLPlugInElement.h */; settings = {ATTRIBUTES = (Private, ); }; };
                A871D4570A127CBC00B12A68 /* HTMLPlugInElement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A871D44D0A127CBC00B12A68 /* HTMLPlugInElement.cpp */; };
                A871D4580A127CBC00B12A68 /* HTMLParamElement.h in Headers */ = {isa = PBXBuildFile; fileRef = A871D44E0A127CBC00B12A68 /* HTMLParamElement.h */; settings = {ATTRIBUTES = (Private, ); }; };
                F3F5CF1112ED81A80084C569 /* InspectorConsoleInstrumentation.h in Headers */ = {isa = PBXBuildFile; fileRef = F3F5CF1012ED81A80084C569 /* InspectorConsoleInstrumentation.h */; };
                F40EA8AB1B867E4400CE5581 /* NSScrollingInputFilterSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = F40EA8AA1B867D6500CE5581 /* NSScrollingInputFilterSPI.h */; settings = {ATTRIBUTES = (Private, ); }; };
                F42FFB461984B71600F6837F /* LengthRepeat.h in Headers */ = {isa = PBXBuildFile; fileRef = F42FFB451984B71600F6837F /* LengthRepeat.h */; };
+               F44EBBD91DB5D21400277334 /* StaticRange.h in Headers */ = {isa = PBXBuildFile; fileRef = F44EBBD81DB5D21400277334 /* StaticRange.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               F44EBBDB1DB5DD9D00277334 /* StaticRange.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F44EBBDA1DB5DD9D00277334 /* StaticRange.cpp */; };
                F45C231D1995B73B00A6E2E3 /* AxisScrollSnapOffsets.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F45C231B1995B73B00A6E2E3 /* AxisScrollSnapOffsets.cpp */; };
                F45C231E1995B73B00A6E2E3 /* AxisScrollSnapOffsets.h in Headers */ = {isa = PBXBuildFile; fileRef = F45C231C1995B73B00A6E2E3 /* AxisScrollSnapOffsets.h */; settings = {ATTRIBUTES = (Private, ); }; };
                F478755419983AFF0024A287 /* ScrollSnapAnimatorState.h in Headers */ = {isa = PBXBuildFile; fileRef = F478755219983AFF0024A287 /* ScrollSnapAnimatorState.h */; settings = {ATTRIBUTES = (Private, ); }; };
                A86629CC09DA2B47009633A5 /* JSMouseEvent.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = JSMouseEvent.cpp; sourceTree = "<group>"; };
                A86629CD09DA2B47009633A5 /* JSKeyboardEvent.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = JSKeyboardEvent.h; sourceTree = "<group>"; };
                A86629CD09DA2B47009633A6 /* JSInputEvent.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = JSInputEvent.h; sourceTree = "<group>"; };
+               A86629CD09DA2B47009633A7 /* JSStaticRange.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = JSStaticRange.h; sourceTree = "<group>"; };
                A86629CE09DA2B47009633A5 /* JSKeyboardEvent.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = JSKeyboardEvent.cpp; sourceTree = "<group>"; };
                A86629CE09DA2B47009633A6 /* JSInputEvent.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = JSInputEvent.cpp; sourceTree = "<group>"; };
+               A86629CE09DA2B47009633A7 /* JSStaticRange.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = JSStaticRange.cpp; sourceTree = "<group>"; };
                A871D44C0A127CBC00B12A68 /* HTMLPlugInElement.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = HTMLPlugInElement.h; sourceTree = "<group>"; };
                A871D44D0A127CBC00B12A68 /* HTMLPlugInElement.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = HTMLPlugInElement.cpp; sourceTree = "<group>"; };
                A871D44E0A127CBC00B12A68 /* HTMLParamElement.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = HTMLParamElement.h; sourceTree = "<group>"; };
                F3F5CF1012ED81A80084C569 /* InspectorConsoleInstrumentation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InspectorConsoleInstrumentation.h; sourceTree = "<group>"; };
                F40EA8AA1B867D6500CE5581 /* NSScrollingInputFilterSPI.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NSScrollingInputFilterSPI.h; sourceTree = "<group>"; };
                F42FFB451984B71600F6837F /* LengthRepeat.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LengthRepeat.h; sourceTree = "<group>"; };
+               F44EBBD61DB5D1B600277334 /* StaticRange.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = StaticRange.idl; sourceTree = "<group>"; };
+               F44EBBD81DB5D21400277334 /* StaticRange.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StaticRange.h; sourceTree = "<group>"; };
+               F44EBBDA1DB5DD9D00277334 /* StaticRange.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StaticRange.cpp; sourceTree = "<group>"; };
                F45C231B1995B73B00A6E2E3 /* AxisScrollSnapOffsets.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AxisScrollSnapOffsets.cpp; sourceTree = "<group>"; };
                F45C231C1995B73B00A6E2E3 /* AxisScrollSnapOffsets.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AxisScrollSnapOffsets.h; sourceTree = "<group>"; };
                F478755219983AFF0024A287 /* ScrollSnapAnimatorState.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScrollSnapAnimatorState.h; sourceTree = "<group>"; };
                                8482B7501198CB6B00BFB005 /* JSHashChangeEvent.h */,
                                A86629CE09DA2B47009633A6 /* JSInputEvent.cpp */,
                                A86629CD09DA2B47009633A6 /* JSInputEvent.h */,
+                               A86629CE09DA2B47009633A7 /* JSStaticRange.cpp */,
+                               A86629CD09DA2B47009633A7 /* JSStaticRange.h */,
                                A86629CE09DA2B47009633A5 /* JSKeyboardEvent.cpp */,
                                A86629CD09DA2B47009633A5 /* JSKeyboardEvent.h */,
                                E107400B0E77BDC00033AF24 /* JSMessageChannel.cpp */,
                                D01A27AC10C9BFD800026A42 /* SpaceSplitString.h */,
                                BC7FA62C0D1F0EFF00DB22A9 /* StaticNodeList.cpp */,
                                BC7FA62B0D1F0EFF00DB22A9 /* StaticNodeList.h */,
+                               F44EBBDA1DB5DD9D00277334 /* StaticRange.cpp */,
+                               F44EBBD81DB5D21400277334 /* StaticRange.h */,
+                               F44EBBD61DB5D1B600277334 /* StaticRange.idl */,
                                8102C5871325BB1100DDE67A /* StringCallback.cpp */,
                                81AC6C35131C57D30009A7E0 /* StringCallback.h */,
                                81AC6C34131C57C20009A7E0 /* StringCallback.idl */,
                                A77979290D6B9E64003851B9 /* JSImageData.h in Headers */,
                                A86629D309DA2B48009633A6 /* JSInputEvent.h in Headers */,
                                7A0E771F10C00DB100A0276E /* JSInspectorFrontendHost.h in Headers */,
+                               A86629D309DA2B48009633A7 /* JSStaticRange.h in Headers */,
                                A86629D309DA2B48009633A5 /* JSKeyboardEvent.h in Headers */,
                                12A253E11C8FFF6600C22295 /* JSKeyframeEffect.h in Headers */,
                                935F45430F7C3B5F00D7C1FB /* JSLazyEventListener.h in Headers */,
                                BCE4413412F748E2009B84B8 /* RenderCombineText.h in Headers */,
                                9392F1420AD185F400691BD4 /* RenderCounter.h in Headers */,
                                BCEA486E097D93020094C9E4 /* RenderDeprecatedFlexibleBox.h in Headers */,
+                               F44EBBD91DB5D21400277334 /* StaticRange.h in Headers */,
                                836DAA061CEAB80D00A2B707 /* RenderDescendantIterator.h in Headers */,
                                D302754A12A5FE84004BD828 /* RenderDetailsMarker.h in Headers */,
                                A76E5F7F135E0DCF00A69837 /* RenderedDocumentMarker.h in Headers */,
                                BCA83E520D7CE205003421A8 /* JSDataTransferCustom.cpp in Sources */,
                                4162A4571011464700DFF3ED /* JSDedicatedWorkerGlobalScope.cpp in Sources */,
                                4162A454101145E300DFF3ED /* JSDedicatedWorkerGlobalScopeCustom.cpp in Sources */,
+                               F44EBBDB1DB5DD9D00277334 /* StaticRange.cpp in Sources */,
                                FDA15ED112B03F94003A583A /* JSDelayNode.cpp in Sources */,
                                31FB1A65120A5D3F00DC02A0 /* JSDeviceMotionEvent.cpp in Sources */,
                                31FB1A6C120A5D6900DC02A0 /* JSDeviceMotionEventCustom.cpp in Sources */,
                                A86629D409DA2B48009633A6 /* JSInputEvent.cpp in Sources */,
                                7A0E771E10C00DB100A0276E /* JSInspectorFrontendHost.cpp in Sources */,
                                7A74ECBD101839DA00BF939E /* JSInspectorFrontendHostCustom.cpp in Sources */,
+                               A86629D409DA2B48009633A7 /* JSStaticRange.cpp in Sources */,
                                A86629D409DA2B48009633A5 /* JSKeyboardEvent.cpp in Sources */,
                                12A253E01C8FFF6600C22295 /* JSKeyframeEffect.cpp in Sources */,
                                935F45420F7C3B5F00D7C1FB /* JSLazyEventListener.cpp in Sources */,
index cd365ca..e6893eb 100644 (file)
@@ -198,6 +198,9 @@ public:
     void setShadowDOMEnabled(bool isEnabled) { m_isShadowDOMEnabled = isEnabled; }
     bool shadowDOMEnabled() const { return m_isShadowDOMEnabled; }
 
+    void setInputEventsEnabled(bool isEnabled) { m_inputEventsEnabled = isEnabled; }
+    bool inputEventsEnabled() const { return m_inputEventsEnabled; }
+
     void setInteractiveFormValidationEnabled(bool isEnabled) { m_isInteractiveFormValidationEnabled = isEnabled; }
     bool interactiveFormValidationEnabled() const { return m_isInteractiveFormValidationEnabled; }
 
@@ -321,6 +324,8 @@ private:
     
     bool m_isShadowDOMEnabled;
 
+    bool m_inputEventsEnabled;
+
     bool m_isInteractiveFormValidationEnabled { false };
 
 #if ENABLE(CUSTOM_ELEMENTS)
index d9f0403..b339c90 100644 (file)
 #include "SlotAssignment.cpp"
 #include "SpaceSplitString.cpp"
 #include "StaticNodeList.cpp"
+#include "StaticRange.cpp"
 #include "StringCallback.cpp"
 #include "StyledElement.cpp"
 #include "TagCollection.cpp"
index 70e9efd..460bb1d 100644 (file)
 
 #include "DOMWindow.h"
 #include "EventNames.h"
+#include "Node.h"
 #include "NotImplemented.h"
 #include <wtf/NeverDestroyed.h>
 #include <wtf/Vector.h>
 
 namespace WebCore {
 
-InputEvent::InputEvent(const AtomicString& eventType, const String& inputType, bool canBubble, bool cancelable, DOMWindow* view, const String& data, int detail)
+InputEvent::InputEvent(const AtomicString& eventType, const String& inputType, bool canBubble, bool cancelable, DOMWindow* view, const String& data, const Vector<RefPtr<StaticRange>>& targetRanges, int detail)
     : UIEvent(eventType, canBubble, cancelable, view, detail)
     , m_inputType(inputType)
     , m_data(data)
+    , m_targetRanges(targetRanges)
 {
 }
 
index 4c78957..cf3a3bc 100644 (file)
@@ -25,6 +25,7 @@
 
 #pragma once
 
+#include "StaticRange.h"
 #include "UIEvent.h"
 
 namespace WebCore {
@@ -34,9 +35,9 @@ class DataTransfer;
 
 class InputEvent final : public UIEvent {
 public:
-    static Ref<InputEvent> create(const AtomicString& eventType, const String& inputType, bool canBubble, bool cancelable, DOMWindow* view, const String& data, int detail)
+    static Ref<InputEvent> create(const AtomicString& eventType, const String& inputType, bool canBubble, bool cancelable, DOMWindow* view, const String& data, const Vector<RefPtr<StaticRange>>& targetRanges, int detail)
     {
-        return adoptRef(*new InputEvent(eventType, inputType, canBubble, cancelable, view, data, detail));
+        return adoptRef(*new InputEvent(eventType, inputType, canBubble, cancelable, view, data, targetRanges, detail));
     }
 
     struct Init : UIEventInit {
@@ -48,7 +49,7 @@ public:
         return adoptRef(*new InputEvent(type, initializer, isTrusted));
     }
 
-    InputEvent(const AtomicString& eventType, const String& inputType, bool canBubble, bool cancelable, DOMWindow*, const String& data, int detail);
+    InputEvent(const AtomicString& eventType, const String& inputType, bool canBubble, bool cancelable, DOMWindow*, const String& data, const Vector<RefPtr<StaticRange>>& targetRanges, int detail);
     InputEvent(const AtomicString& eventType, const Init&, IsTrusted);
 
     virtual ~InputEvent() { }
@@ -57,10 +58,12 @@ public:
     EventInterface eventInterface() const final { return InputEventInterfaceType; }
     const String& inputType() const { return m_inputType; }
     const String& data() const { return m_data; }
+    const Vector<RefPtr<StaticRange>>& getTargetRanges() { return m_targetRanges; }
 
 private:
     String m_inputType;
     String m_data;
+    Vector<RefPtr<StaticRange>> m_targetRanges;
 };
 
 } // namespace WebCore
index d12b3a6..d6c8880 100644 (file)
 
 [
     Constructor(DOMString type, optional InputEventInit eventInitDict),
+    EnabledAtRuntime=InputEvents,
 ] interface InputEvent : UIEvent {
     readonly attribute DOMString inputType;
     readonly attribute DOMString? data;
+
+    sequence<StaticRange> getTargetRanges();
 };
 
 dictionary InputEventInit : UIEventInit {
diff --git a/Source/WebCore/dom/StaticRange.cpp b/Source/WebCore/dom/StaticRange.cpp
new file mode 100644 (file)
index 0000000..4509adf
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "StaticRange.h"
+
+#include "Node.h"
+#include "Range.h"
+
+namespace WebCore {
+
+StaticRange::StaticRange(Ref<Node>&& startContainer, unsigned startOffset, Ref<Node>&& endContainer, unsigned endOffset)
+    : m_startContainer(WTFMove(startContainer))
+    , m_startOffset(startOffset)
+    , m_endContainer(WTFMove(endContainer))
+    , m_endOffset(endOffset)
+{
+}
+
+Ref<StaticRange> StaticRange::create(Ref<WebCore::Node> &&startContainer, unsigned startOffset, Ref<WebCore::Node> &&endContainer, unsigned endOffset)
+{
+    return adoptRef(*new StaticRange(WTFMove(startContainer), startOffset, WTFMove(endContainer), endOffset));
+}
+
+Ref<StaticRange> StaticRange::createFromRange(const Range& range)
+{
+    return StaticRange::create(range.startContainer(), range.startOffset(), range.endContainer(), range.endOffset());
+}
+
+Node* StaticRange::startContainer() const
+{
+    return (Node*)m_startContainer.ptr();
+}
+
+Node* StaticRange::endContainer() const
+{
+    return (Node*)m_endContainer.ptr();
+}
+
+bool StaticRange::collapsed() const
+{
+    return m_startOffset == m_endOffset && m_startContainer.ptr() == m_endContainer.ptr();
+}
+
+}
diff --git a/Source/WebCore/dom/StaticRange.h b/Source/WebCore/dom/StaticRange.h
new file mode 100644 (file)
index 0000000..4b86786
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include <wtf/RefCounted.h>
+#include <wtf/RefPtr.h>
+
+namespace WebCore {
+
+class Node;
+class Range;
+
+class StaticRange : public RefCounted<StaticRange> {
+public:
+    static Ref<StaticRange> createFromRange(const Range&);
+    static Ref<StaticRange> create(Ref<Node>&& startContainer, unsigned startOffset, Ref<Node>&& endContainer, unsigned endOffset);
+
+    unsigned startOffset() const { return m_startOffset; }
+    unsigned endOffset() const { return m_endOffset; }
+    Node* startContainer() const;
+    Node* endContainer() const;
+    bool collapsed() const;
+
+private:
+    StaticRange(Ref<Node>&& startContainer, unsigned startOffset, Ref<Node>&& endContainer, unsigned endOffset);
+
+    Ref<Node> m_startContainer;
+    unsigned m_startOffset;
+    Ref<Node> m_endContainer;
+    unsigned m_endOffset;
+};
+
+}
diff --git a/Source/WebCore/dom/StaticRange.idl b/Source/WebCore/dom/StaticRange.idl
new file mode 100644 (file)
index 0000000..4059584
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2016 Apple, Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+[
+    EnabledAtRuntime=InputEvents,
+    ImplementationLacksVTable,
+] interface StaticRange {
+    readonly attribute unsigned long startOffset;
+    readonly attribute unsigned long endOffset;
+    readonly attribute Node startContainer;
+    readonly attribute Node endContainer;
+    readonly attribute boolean collapsed;
+};
index 2976095..e346000 100644 (file)
@@ -68,6 +68,7 @@
 #include "SplitElementCommand.h"
 #include "SplitTextNodeCommand.h"
 #include "SplitTextNodeContainingElementCommand.h"
+#include "StaticRange.h"
 #include "Text.h"
 #include "TextIterator.h"
 #include "VisibleUnits.h"
@@ -319,7 +320,7 @@ CompositeEditCommand::~CompositeEditCommand()
 
 bool CompositeEditCommand::willApplyCommand()
 {
-    return frame().editor().willApplyEditing(*this);
+    return frame().editor().willApplyEditing(*this, targetRangesForBindings());
 }
 
 void CompositeEditCommand::apply()
@@ -375,6 +376,25 @@ void CompositeEditCommand::didApplyCommand()
     frame().editor().appliedEditing(this);
 }
 
+Vector<RefPtr<StaticRange>> CompositeEditCommand::targetRanges() const
+{
+    ASSERT(!isEditingTextAreaOrTextInput());
+    auto firstRange = frame().selection().selection().firstRange();
+    if (!firstRange)
+        return { };
+
+    RefPtr<StaticRange> range = StaticRange::createFromRange(*firstRange);
+    return { 1, range };
+}
+
+Vector<RefPtr<StaticRange>> CompositeEditCommand::targetRangesForBindings() const
+{
+    if (isEditingTextAreaOrTextInput())
+        return { };
+
+    return targetRanges();
+}
+
 EditCommandComposition* CompositeEditCommand::ensureComposition()
 {
     CompositeEditCommand* command = this;
@@ -1496,24 +1516,34 @@ void CompositeEditCommand::moveParagraphs(const VisiblePosition& startOfParagrap
     }
 }
 
-// FIXME: Send an appropriate shouldDeleteRange call.
-bool CompositeEditCommand::breakOutOfEmptyListItem()
+Optional<VisibleSelection> CompositeEditCommand::shouldBreakOutOfEmptyListItem() const
 {
-    RefPtr<Node> emptyListItem = enclosingEmptyListItem(endingSelection().visibleStart());
+    auto emptyListItem = enclosingEmptyListItem(endingSelection().visibleStart());
     if (!emptyListItem)
-        return false;
+        return Nullopt;
 
-    RefPtr<EditingStyle> style = EditingStyle::create(endingSelection().start());
-    style->mergeTypingStyle(document());
-
-    RefPtr<ContainerNode> listNode = emptyListItem->parentNode();
+    auto listNode = emptyListItem->parentNode();
     // FIXME: Can't we do something better when the immediate parent wasn't a list node?
     if (!listNode
         || (!listNode->hasTagName(ulTag) && !listNode->hasTagName(olTag))
         || !listNode->hasEditableStyle()
         || listNode == emptyListItem->rootEditableElement())
+        return Nullopt;
+
+    return VisibleSelection(endingSelection().start().previous(BackwardDeletion), endingSelection().end());
+}
+
+// FIXME: Send an appropriate shouldDeleteRange call.
+bool CompositeEditCommand::breakOutOfEmptyListItem()
+{
+    if (!shouldBreakOutOfEmptyListItem())
         return false;
 
+    auto emptyListItem = enclosingEmptyListItem(endingSelection().visibleStart());
+    auto listNode = emptyListItem->parentNode();
+    auto style = EditingStyle::create(endingSelection().start());
+    style->mergeTypingStyle(document());
+
     RefPtr<Element> newBlock;
     if (ContainerNode* blockEnclosingList = listNode->parentNode()) {
         if (is<HTMLLIElement>(*blockEnclosingList)) { // listNode is inside another list item
@@ -1538,7 +1568,7 @@ bool CompositeEditCommand::breakOutOfEmptyListItem()
     if (isListItem(nextListNode.get()) || isListHTMLElement(nextListNode.get())) {
         // If emptyListItem follows another list item or nested list, split the list node.
         if (isListItem(previousListNode.get()) || isListHTMLElement(previousListNode.get()))
-            splitElement(downcast<Element>(listNode.get()), emptyListItem);
+            splitElement(downcast<Element>(listNode), emptyListItem);
 
         // If emptyListItem is followed by other list item or nested list, then insert newBlock before the list node.
         // Because we have splitted the element, emptyListItem is the first element in the list node.
@@ -1549,7 +1579,7 @@ bool CompositeEditCommand::breakOutOfEmptyListItem()
         // When emptyListItem does not follow any list item or nested list, insert newBlock after the enclosing list node.
         // Remove the enclosing node if emptyListItem is the only child; otherwise just remove emptyListItem.
         insertNodeAfter(newBlock, listNode);
-        removeNode(isListItem(previousListNode.get()) || isListHTMLElement(previousListNode.get()) ? emptyListItem.get() : listNode.get());
+        removeNode(isListItem(previousListNode.get()) || isListHTMLElement(previousListNode.get()) ? emptyListItem : listNode);
     }
 
     appendBlockPlaceholder(newBlock);
@@ -1557,7 +1587,7 @@ bool CompositeEditCommand::breakOutOfEmptyListItem()
 
     style->prepareToApplyAt(endingSelection().start());
     if (!style->isEmpty())
-        applyStyle(style.get());
+        applyStyle(style.ptr());
 
     return true;
 }
index 63faa9a..3149437 100644 (file)
@@ -36,6 +36,7 @@ namespace WebCore {
 
 class EditingStyle;
 class HTMLElement;
+class StaticRange;
 class StyledElement;
 class Text;
 
@@ -115,6 +116,7 @@ public:
     virtual bool shouldStopCaretBlinking() const { return false; }
     virtual String inputEventTypeName() const;
     virtual String inputEventData() const { return { }; }
+    Vector<RefPtr<StaticRange>> targetRangesForBindings() const;
 
 protected:
     explicit CompositeEditCommand(Document&, EditAction = EditActionUnspecified);
@@ -123,6 +125,8 @@ protected:
     virtual bool willApplyCommand();
     virtual void didApplyCommand();
 
+    virtual Vector<RefPtr<StaticRange>> targetRanges() const;
+
     //
     // sugary-sweet convenience functions to help create and apply edit commands in composite commands
     //
@@ -193,6 +197,7 @@ protected:
     void cloneParagraphUnderNewElement(const Position& start, const Position& end, Node* outerNode, Element* blockElement);
     void cleanupAfterDeletion(VisiblePosition destination = VisiblePosition());
     
+    Optional<VisibleSelection> shouldBreakOutOfEmptyListItem() const;
     bool breakOutOfEmptyListItem();
     bool breakOutOfEmptyMailBlockquotedParagraph();
     
index 65cbb11..4da4e33 100644 (file)
@@ -132,6 +132,12 @@ Frame& EditCommand::frame()
     return *document().frame();
 }
 
+const Frame& EditCommand::frame() const
+{
+    ASSERT(document().frame());
+    return *document().frame();
+}
+
 EditAction EditCommand::editingAction() const
 {
     return m_editingAction;
index 01a31a7..346f1ee 100644 (file)
@@ -66,7 +66,9 @@ protected:
     explicit EditCommand(Document&, EditAction = EditActionUnspecified);
     EditCommand(Document&, const VisibleSelection&, const VisibleSelection&);
 
+    const Frame& frame() const;
     Frame& frame();
+    const Document& document() const { return m_document; }
     Document& document() { return m_document; }
     CompositeEditCommand* parent() const { return m_parent; }
     void setStartingSelection(const VisibleSelection&);
index 0efb434..7ee880c 100644 (file)
 
 namespace WebCore {
 
-static bool dispatchBeforeInputEvent(Element& element, const AtomicString& inputType, const String& data = { })
+static bool dispatchBeforeInputEvent(Element& element, const AtomicString& inputType, const String& data = { }, const Vector<RefPtr<StaticRange>>& targetRanges = { })
 {
     auto* settings = element.document().settings();
     if (!settings || !settings->inputEventsEnabled())
         return true;
 
-    auto event = InputEvent::create(eventNames().beforeinputEvent, inputType, true, true, element.document().defaultView(), data, 0);
-    element.dispatchScopedEvent(event);
-
-    return !event->defaultPrevented();
+    return element.dispatchEvent(InputEvent::create(eventNames().beforeinputEvent, inputType, true, true, element.document().defaultView(), data, targetRanges, 0));
 }
 
-static void dispatchInputEvent(Element& element, const AtomicString& inputType, const String& data = { })
+static void dispatchInputEvent(Element& element, const AtomicString& inputType, const String& data = { }, const Vector<RefPtr<StaticRange>>& targetRanges = { })
 {
     auto* settings = element.document().settings();
     if (settings && settings->inputEventsEnabled())
-        element.dispatchScopedEvent(InputEvent::create(eventNames().inputEvent, inputType, true, false, element.document().defaultView(), data, 0));
+        element.dispatchScopedEvent(InputEvent::create(eventNames().inputEvent, inputType, true, false, element.document().defaultView(), data, targetRanges, 0));
     else
         element.dispatchInputEvent();
 }
@@ -1066,31 +1063,31 @@ static void notifyTextFromControls(Element* startRoot, Element* endRoot)
         endingTextControl->didEditInnerTextValue();
 }
 
-static bool dispatchBeforeInputEvents(RefPtr<Element> startRoot, RefPtr<Element> endRoot, const AtomicString& inputTypeName, const String& data = { })
+static bool dispatchBeforeInputEvents(RefPtr<Element> startRoot, RefPtr<Element> endRoot, const AtomicString& inputTypeName, const String& data = { }, const Vector<RefPtr<StaticRange>>& targetRanges = { })
 {
     bool continueWithDefaultBehavior = true;
     if (startRoot)
-        continueWithDefaultBehavior &= dispatchBeforeInputEvent(*startRoot, inputTypeName, data);
+        continueWithDefaultBehavior &= dispatchBeforeInputEvent(*startRoot, inputTypeName, data, targetRanges);
     if (endRoot && endRoot != startRoot)
-        continueWithDefaultBehavior &= dispatchBeforeInputEvent(*endRoot, inputTypeName, data);
+        continueWithDefaultBehavior &= dispatchBeforeInputEvent(*endRoot, inputTypeName, data, targetRanges);
     return continueWithDefaultBehavior;
 }
 
-static void dispatchInputEvents(RefPtr<Element> startRoot, RefPtr<Element> endRoot, const AtomicString& inputTypeName, const String& data = { })
+static void dispatchInputEvents(RefPtr<Element> startRoot, RefPtr<Element> endRoot, const AtomicString& inputTypeName, const String& data = { }, const Vector<RefPtr<StaticRange>>& targetRanges = { })
 {
     if (startRoot)
-        dispatchInputEvent(*startRoot, inputTypeName, data);
+        dispatchInputEvent(*startRoot, inputTypeName, data, targetRanges);
     if (endRoot && endRoot != startRoot)
-        dispatchInputEvent(*endRoot, inputTypeName, data);
+        dispatchInputEvent(*endRoot, inputTypeName, data, targetRanges);
 }
 
-bool Editor::willApplyEditing(CompositeEditCommand& command) const
+bool Editor::willApplyEditing(CompositeEditCommand& command, Vector<RefPtr<StaticRange>>&& targetRanges) const
 {
     auto* composition = command.composition();
     if (!composition)
         return true;
 
-    return dispatchBeforeInputEvents(composition->startingRootEditableElement(), composition->endingRootEditableElement(), command.inputEventTypeName(), command.inputEventData());
+    return dispatchBeforeInputEvents(composition->startingRootEditableElement(), composition->endingRootEditableElement(), command.inputEventTypeName(), command.inputEventData(), targetRanges);
 }
 
 void Editor::appliedEditing(PassRefPtr<CompositeEditCommand> cmd)
index ddf2b5e..d77f1cd 100644 (file)
@@ -68,6 +68,7 @@ class SharedBuffer;
 class Font;
 class SpellCheckRequest;
 class SpellChecker;
+class StaticRange;
 class StyleProperties;
 class Text;
 class TextCheckerClient;
@@ -199,7 +200,7 @@ public:
     void applyParagraphStyleToSelection(StyleProperties*, EditAction);
 
     // Returns whether or not we should proceed with editing.
-    bool willApplyEditing(CompositeEditCommand&) const;
+    bool willApplyEditing(CompositeEditCommand&, Vector<RefPtr<StaticRange>>&&) const;
     bool willUnapplyEditing(const EditCommandComposition&) const;
     bool willReapplyEditing(const EditCommandComposition&) const;
 
index e12865c..871c1dd 100644 (file)
@@ -33,6 +33,7 @@
 #include "Frame.h"
 #include "ReplaceSelectionCommand.h"
 #include "SetSelectionCommand.h"
+#include "StaticRange.h"
 #include "TextIterator.h"
 #include "markup.h"
 
@@ -73,4 +74,10 @@ String ReplaceRangeWithTextCommand::inputEventData() const
     return CompositeEditCommand::inputEventData();
 }
 
+Vector<RefPtr<StaticRange>> ReplaceRangeWithTextCommand::targetRanges() const
+{
+    RefPtr<StaticRange> range = StaticRange::createFromRange(*m_rangeToBeReplaced);
+    return { 1, range };
+}
+
 } // namespace WebCore
index e7b6c24..a4f2600 100644 (file)
@@ -41,6 +41,7 @@ private:
     ReplaceRangeWithTextCommand(RefPtr<Range> rangeToBeReplaced, const String& text);
     void doApply() override;
     String inputEventData() const final;
+    Vector<RefPtr<StaticRange>> targetRanges() const final;
 
     RefPtr<Range> m_rangeToBeReplaced;
     String m_text;
index f0b1518..e20593b 100644 (file)
@@ -33,6 +33,7 @@
 #include "Frame.h"
 #include "ReplaceSelectionCommand.h"
 #include "SetSelectionCommand.h"
+#include "StaticRange.h"
 #include "TextIterator.h"
 #include "markup.h"
 
@@ -119,6 +120,12 @@ String SpellingCorrectionCommand::inputEventData() const
     return CompositeEditCommand::inputEventData();
 }
 
+Vector<RefPtr<StaticRange>> SpellingCorrectionCommand::targetRanges() const
+{
+    RefPtr<StaticRange> range = StaticRange::createFromRange(*m_rangeToBeCorrected);
+    return { 1, range };
+}
+
 bool SpellingCorrectionCommand::shouldRetainAutocorrectionIndicator() const
 {
     return true;
index 4c57699..e55afa0 100644 (file)
@@ -43,6 +43,7 @@ private:
     bool shouldRetainAutocorrectionIndicator() const override;
 
     String inputEventData() const final;
+    Vector<RefPtr<StaticRange>> targetRanges() const final;
 
     RefPtr<Range> m_rangeToBeCorrected;
     VisibleSelection m_selectionToBeCorrected;
index 6aca94b..d05d4f9 100644 (file)
@@ -41,6 +41,7 @@
 #include "Logging.h"
 #include "MathMLElement.h"
 #include "RenderElement.h"
+#include "StaticRange.h"
 #include "TextIterator.h"
 #include "VisibleUnits.h"
 #include "htmlediting.h"
@@ -106,6 +107,22 @@ static inline EditAction editActionForTypingCommand(TypingCommand::ETypingComman
     }
 }
 
+static inline bool editActionIsDeleteByTyping(EditAction action)
+{
+    switch (action) {
+    case EditActionTypingDeleteSelection:
+    case EditActionTypingDeleteBackward:
+    case EditActionTypingDeleteWordBackward:
+    case EditActionTypingDeleteLineBackward:
+    case EditActionTypingDeleteForward:
+    case EditActionTypingDeleteWordForward:
+    case EditActionTypingDeleteLineForward:
+        return true;
+    default:
+        return false;
+    }
+}
+
 TypingCommand::TypingCommand(Document& document, ETypingCommand commandType, const String &textToInsert, Options options, TextGranularity granularity, TextCompositionType compositionType)
     : TextInsertionBaseCommand(document, editActionForTypingCommand(commandType, granularity))
     , m_commandType(commandType)
@@ -267,6 +284,11 @@ RefPtr<TypingCommand> TypingCommand::lastTypingCommandIfStillOpenForTyping(Frame
     return static_cast<TypingCommand*>(lastEditCommand.get());
 }
 
+bool TypingCommand::shouldDeferWillApplyCommandUntilAddingTypingCommand() const
+{
+    return !m_isHandlingInitialTypingCommand || editActionIsDeleteByTyping(editingAction());
+}
+
 void TypingCommand::closeTyping(Frame* frame)
 {
     if (RefPtr<TypingCommand> lastTypingCommand = lastTypingCommandIfStillOpenForTyping(*frame))
@@ -296,7 +318,7 @@ void TypingCommand::postTextStateChangeNotificationForDeletion(const VisibleSele
 
 bool TypingCommand::willApplyCommand()
 {
-    if (!m_isHandlingInitialTypingCommand) {
+    if (shouldDeferWillApplyCommandUntilAddingTypingCommand()) {
         // The TypingCommand will handle the willApplyCommand logic separately in TypingCommand::willAddTypingToOpenCommand.
         return true;
     }
@@ -413,14 +435,19 @@ void TypingCommand::markMisspellingsAfterTyping(ETypingCommand commandType)
     }
 }
 
-bool TypingCommand::willAddTypingToOpenCommand(ETypingCommand commandType, TextGranularity granularity, const String& text)
+bool TypingCommand::willAddTypingToOpenCommand(ETypingCommand commandType, TextGranularity granularity, const String& text, RefPtr<Range>&& range)
 {
-    if (m_isHandlingInitialTypingCommand)
-        return true;
-
     m_currentTextToInsert = text;
     m_currentTypingEditAction = editActionForTypingCommand(commandType, granularity);
-    return frame().editor().willApplyEditing(*this);
+
+    if (!shouldDeferWillApplyCommandUntilAddingTypingCommand())
+        return true;
+
+    if (!range || isEditingTextAreaOrTextInput())
+        return frame().editor().willApplyEditing(*this, CompositeEditCommand::targetRangesForBindings());
+
+    RefPtr<StaticRange> staticRange = StaticRange::createFromRange(*range);
+    return frame().editor().willApplyEditing(*this, { 1, staticRange });
 }
 
 void TypingCommand::typingAddedToOpenCommand(ETypingCommand commandTypeForAddedTyping)
@@ -562,9 +589,6 @@ bool TypingCommand::makeEditableRootEmpty()
 
 void TypingCommand::deleteKeyPressed(TextGranularity granularity, bool shouldAddToKillRing)
 {
-    if (!willAddTypingToOpenCommand(DeleteKey, granularity))
-        return;
-
     Frame& frame = this->frame();
 
     frame.editor().updateMarkersForWordsAffectedByEditing(false);
@@ -593,11 +617,15 @@ void TypingCommand::deleteKeyPressed(TextGranularity granularity, bool shouldAdd
 
         if (endingSelection().visibleStart().previous(CannotCrossEditingBoundary).isNull()) {
             // When the caret is at the start of the editable area in an empty list item, break out of the list item.
-            if (breakOutOfEmptyListItem()) {
-                typingAddedToOpenCommand(DeleteKey);
+            if (auto deleteListSelection = shouldBreakOutOfEmptyListItem()) {
+                if (willAddTypingToOpenCommand(DeleteKey, granularity, { }, Range::create(document(), deleteListSelection.value().start(), deleteListSelection.value().end()))) {
+                    breakOutOfEmptyListItem();
+                    typingAddedToOpenCommand(DeleteKey);
+                }
                 return;
             }
             // When there are no visible positions in the editing root, delete its entire contents.
+            // FIXME: Dispatch a `beforeinput` event here and bail if preventDefault() was invoked.
             if (endingSelection().visibleStart().next(CannotCrossEditingBoundary).isNull() && makeEditableRootEmpty()) {
                 typingAddedToOpenCommand(DeleteKey);
                 return;
@@ -660,6 +688,9 @@ void TypingCommand::deleteKeyPressed(TextGranularity granularity, bool shouldAdd
     if (selectionToDelete.isCaret() || !frame.selection().shouldDeleteSelection(selectionToDelete))
         return;
     
+    if (!willAddTypingToOpenCommand(DeleteKey, granularity, { }, selectionToDelete.firstRange()))
+        return;
+
     if (shouldAddToKillRing)
         frame.editor().addRangeToKillRing(*selectionToDelete.toNormalizedRange().get(), Editor::KillRingInsertionMode::PrependText);
 
@@ -678,9 +709,6 @@ void TypingCommand::deleteKeyPressed(TextGranularity granularity, bool shouldAdd
 
 void TypingCommand::forwardDeleteKeyPressed(TextGranularity granularity, bool shouldAddToKillRing)
 {
-    if (!willAddTypingToOpenCommand(ForwardDeleteKey, granularity))
-        return;
-
     Frame& frame = this->frame();
 
     frame.editor().updateMarkersForWordsAffectedByEditing(false);
@@ -764,7 +792,10 @@ void TypingCommand::forwardDeleteKeyPressed(TextGranularity granularity, bool sh
     
     if (selectionToDelete.isCaret() || !frame.selection().shouldDeleteSelection(selectionToDelete))
         return;
-        
+
+    if (!willAddTypingToOpenCommand(ForwardDeleteKey, granularity, { }, selectionToDelete.firstRange()))
+        return;
+
     // Post the accessibility notification before actually deleting the content while selectionToDelete is still valid
     postTextStateChangeNotificationForDeletion(selectionToDelete);
 
index 566170a..810aa49 100644 (file)
@@ -122,7 +122,7 @@ private:
     static void updateSelectionIfDifferentFromCurrentSelection(TypingCommand*, Frame*);
 
     void updatePreservesTypingStyle(ETypingCommand);
-    bool willAddTypingToOpenCommand(ETypingCommand, TextGranularity, const String& = emptyString());
+    bool willAddTypingToOpenCommand(ETypingCommand, TextGranularity, const String& = emptyString(), RefPtr<Range>&& = nullptr);
     void markMisspellingsAfterTyping(ETypingCommand);
     void typingAddedToOpenCommand(ETypingCommand);
     bool makeEditableRootEmpty();
@@ -136,6 +136,8 @@ private:
     bool willApplyCommand() final;
     void didApplyCommand() final;
 
+    bool shouldDeferWillApplyCommandUntilAddingTypingCommand() const;
+
     ETypingCommand m_commandType;
     EditAction m_currentTypingEditAction;
     String m_textToInsert;
index 10b5aef..eadb0fc 100644 (file)
@@ -1,3 +1,17 @@
+2016-10-21  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        Implement InputEvent.getTargetRanges() for the input events spec
+        https://bugs.webkit.org/show_bug.cgi?id=162947
+        <rdar://problem/28853079>
+
+        Reviewed by Darin Adler.
+
+        Boilerplate change to add a runtime guard for InputEvents-related IDL interfaces. See WebCore ChangeLog entry
+        for more details.
+
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::updatePreferences):
+
 2016-10-20  Carlos Garcia Campos  <cgarcia@igalia.com>
 
         [GTK] Configures but fails to link with ENABLE_OPENGL=OFF
index 1311f75..88634e0 100644 (file)
@@ -3224,6 +3224,7 @@ void WebPage::updatePreferences(const WebPreferencesStore& store)
 #endif
 
     settings.setInputEventsEnabled(store.getBoolValueForKey(WebPreferencesKey::inputEventsEnabledKey()));
+    RuntimeEnabledFeatures::sharedFeatures().setInputEventsEnabled(store.getBoolValueForKey(WebPreferencesKey::inputEventsEnabledKey()));
 
     RuntimeEnabledFeatures::sharedFeatures().setModernMediaControlsEnabled(store.getBoolValueForKey(WebPreferencesKey::modernMediaControlsEnabledKey()));