forked from WebKit/WebKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
https://bugs.webkit.org/show_bug.cgi?id=271117 Reviewed by Chris Dumez. Implement the spec change to avoid queuing a task to fire a selectionchange event when there is already a task scheduled to do that for the target: w3c/selection-api#172 Also update the relevant web platform tests: web-platform-tests/wpt#45145 * LayoutTests/fast/events/selectionchange-iframe-expected.txt: * LayoutTests/fast/events/selectionchange-user-initiated-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/selection/onselectionchange-on-distinct-text-controls-expected.txt: Added. * LayoutTests/imported/w3c/web-platform-tests/selection/onselectionchange-on-distinct-text-controls.html: Added. * LayoutTests/imported/w3c/web-platform-tests/selection/onselectionchange-on-document-expected.txt: Added. * LayoutTests/imported/w3c/web-platform-tests/selection/onselectionchange-on-document.html: Added. * LayoutTests/imported/w3c/web-platform-tests/selection/textcontrols/selectionchange.html: * Source/WebCore/editing/FrameSelection.cpp: (WebCore::FrameSelection::setSelectionWithoutUpdatingAppearance): * Source/WebCore/editing/FrameSelection.h: * Source/WebCore/html/HTMLTextFormControlElement.cpp: (WebCore::HTMLTextFormControlElement::HTMLTextFormControlElement): (WebCore::HTMLTextFormControlElement::scheduleSelectionChangeEvent): (WebCore::HTMLTextFormControlElement::scheduleSelectEvent): * Source/WebCore/html/HTMLTextFormControlElement.h: (WebCore::HTMLTextFormControlElement::hasScheduledSelectionChangeEvent const): (WebCore::HTMLTextFormControlElement::setHasScheduledSelectionChangeEvent): Canonical link: https://commits.webkit.org/276388@main
- Loading branch information
Showing
11 changed files
with
172 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
...w3c/web-platform-tests/selection/onselectionchange-on-distinct-text-controls-expected.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
|
||
PASS selectionchange event on each input element fires independently | ||
PASS selectionchange event on each textarea element fires independently | ||
|
48 changes: 48 additions & 0 deletions
48
...mported/w3c/web-platform-tests/selection/onselectionchange-on-distinct-text-controls.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<link rel="help" href="https://w3c.github.io/selection-api/#selectionchange-event"> | ||
<script src="../resources/testharness.js"></script> | ||
<script src="../resources/testharnessreport.js"></script> | ||
<body> | ||
<input id="input1" value="hello"> | ||
<input id="input2" value="world"> | ||
<textarea id="textarea1">hello</textarea> | ||
<textarea id="textarea2">world</textarea> | ||
<script> | ||
|
||
promise_test(() => { | ||
return (async function() { | ||
let selectionChangeCount1 = 0; | ||
let selectionChangeCount2 = 0; | ||
input1.addEventListener("selectionchange", () => ++selectionChangeCount1); | ||
input2.addEventListener("selectionchange", () => ++selectionChangeCount2); | ||
input1.setSelectionRange(1, 2); | ||
input1.setSelectionRange(2, 3); | ||
input2.setSelectionRange(1, 3); | ||
assert_equals(selectionChangeCount1, 0); | ||
assert_equals(selectionChangeCount2, 0); | ||
await new Promise((resolve) => setTimeout(resolve, 0)); | ||
assert_equals(selectionChangeCount1, 1); | ||
assert_equals(selectionChangeCount2, 1); | ||
})(); | ||
}, "selectionchange event on each input element fires independently"); | ||
|
||
promise_test(() => { | ||
return (async function() { | ||
let selectionChangeCount1 = 0; | ||
let selectionChangeCount2 = 0; | ||
textarea1.addEventListener("selectionchange", () => ++selectionChangeCount1); | ||
textarea2.addEventListener("selectionchange", () => ++selectionChangeCount2); | ||
textarea1.setSelectionRange(1, 2); | ||
textarea1.setSelectionRange(2, 3); | ||
textarea2.setSelectionRange(1, 3); | ||
assert_equals(selectionChangeCount1, 0); | ||
assert_equals(selectionChangeCount2, 0); | ||
await new Promise((resolve) => setTimeout(resolve, 0)); | ||
assert_equals(selectionChangeCount1, 1); | ||
assert_equals(selectionChangeCount2, 1); | ||
})(); | ||
}, "selectionchange event on each textarea element fires independently"); | ||
|
||
|
||
</script> |
8 changes: 8 additions & 0 deletions
8
...ests/imported/w3c/web-platform-tests/selection/onselectionchange-on-document-expected.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
|
||
|
||
PASS selectionchange event on document fires | ||
PASS selectionchange event on document fires once | ||
PASS task to fire selectionchange event gets queued each time selection is mutated | ||
PASS has scheduled selectionchange event is set to false at the beginning of a task to fire selectionchange event | ||
|
73 changes: 73 additions & 0 deletions
73
LayoutTests/imported/w3c/web-platform-tests/selection/onselectionchange-on-document.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<link rel="help" href="https://w3c.github.io/selection-api/#selectionchange-event"> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<body> | ||
<div id="container"><br><br></div> | ||
<script> | ||
|
||
promise_test(() => { | ||
return new Promise(resolve => { | ||
let didFireSelectionChangeEvent = false; | ||
document.addEventListener("selectionchange", () => { didFireSelectionChangeEvent = true; resolve(); }, {once: true}); | ||
getSelection().setPosition(container, 0); | ||
assert_false(didFireSelectionChangeEvent); | ||
}); | ||
}, "selectionchange event on document fires"); | ||
|
||
promise_test(() => { | ||
return (async function() { | ||
let selectionChangeCount = 0; | ||
document.addEventListener("selectionchange", () => ++selectionChangeCount); | ||
container.innerHTML = '<span><br></span><span><br></span>'; | ||
getSelection().setPosition(container, 0); | ||
assert_equals(selectionChangeCount, 0); | ||
getSelection().setPosition(container, 2); | ||
assert_equals(selectionChangeCount, 0); | ||
await new Promise((resolve) => setTimeout(resolve, 0)); | ||
assert_equals(selectionChangeCount, 1); | ||
})(); | ||
}, "selectionchange event on document fires once"); | ||
|
||
promise_test(() => { | ||
return (async function() { | ||
let selectionChangeCount = 0; | ||
document.addEventListener("selectionchange", () => ++selectionChangeCount); | ||
container.innerHTML = '<span><br></span><span><br></span>'; | ||
getSelection().setPosition(container, 0); | ||
assert_equals(selectionChangeCount, 0); | ||
getSelection().setPosition(container, 2); | ||
assert_equals(selectionChangeCount, 0); | ||
await new Promise((resolve) => setTimeout(resolve, 0)); | ||
assert_equals(selectionChangeCount, 1); | ||
getSelection().setPosition(container, 0); | ||
assert_equals(selectionChangeCount, 1); | ||
getSelection().setPosition(container, 2); | ||
assert_equals(selectionChangeCount, 1); | ||
await new Promise((resolve) => setTimeout(resolve, 0)); | ||
assert_equals(selectionChangeCount, 2); | ||
})(); | ||
}, "task to fire selectionchange event gets queued each time selection is mutated"); | ||
|
||
promise_test(() => { | ||
return (async function() { | ||
let selectionChangeCount = 0; | ||
document.addEventListener("selectionchange", () => { | ||
if (!selectionChangeCount) { | ||
getSelection().setPosition(container, 2); | ||
getSelection().setPosition(container, 0); | ||
} | ||
++selectionChangeCount; | ||
}); | ||
container.innerHTML = '<b><br></b><b><br></b>'; | ||
getSelection().setPosition(container, 0); | ||
assert_equals(selectionChangeCount, 0); | ||
await new Promise((resolve) => setTimeout(resolve, 0)); | ||
assert_equals(selectionChangeCount, 1); | ||
await new Promise((resolve) => setTimeout(resolve, 0)); | ||
assert_equals(selectionChangeCount, 2); | ||
})(); | ||
}, "has scheduled selectionchange event is set to false at the beginning of a task to fire selectionchange event"); | ||
|
||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters