Automatic update from web-platform-tests [Reference Target] Use relatedTarget for event propagation Replace the reference target handling in GetShadowRootParent with an approach that uses Event's existing relatedTarget concept, per discussion at [1]. The way this will work is that for CommandEvent, ToggleEvent, SubmitEvent, and InterestEvent, instead of an internal source/submitter, the events will use relatedTarget. The getters for these no longer need individual retargeting since relatedTarget gets retargeted as part of event dispatch. When relatedTarget is non-null for one of these event types, we'll dispatch it as a composed event. The result is that when the source/submitter is in a parent shadow because of reference target, we'll bubble the event into that shadow (but no further, due to the way relatedTarget already affects event dispatch). [1] https://github.com/whatwg/html/pull/10995#issuecomment-4572681552 Bug: 346835896 Change-Id: I6cb5cde907a3db8492795adb13e971bbd92f5ca5 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7902895 Commit-Queue: Dan Clark <daniec@microsoft.com> Reviewed-by: Mason Freed <masonf@chromium.org> Cr-Commit-Position: refs/heads/main@{#1650570} -- wpt-commits: 9911aea5c6a42d47b89c88d43e91ce04d4f1099f wpt-pr: 60816
70 lines
2.7 KiB
HTML
70 lines
2.7 KiB
HTML
<!DOCTYPE html>
|
|
<meta charset="utf-8" />
|
|
<link rel="author" title="Keith Cirkel" href="mailto:keithamus@github.com" >
|
|
<link rel="author" title="Luke Warlow" href="mailto:lwarlow@igalia.com" >
|
|
<link
|
|
rel="help"
|
|
href="https://open-ui.org/components/interest-invokers.explainer/"
|
|
/>
|
|
<script src="/resources/testharness.js"></script>
|
|
<script src="/resources/testharnessreport.js"></script>
|
|
<script src="/resources/testdriver.js"></script>
|
|
<script src="/resources/testdriver-actions.js"></script>
|
|
<script src="/resources/testdriver-vendor.js"></script>
|
|
<script src="resources/invoker-utils.js"></script>
|
|
|
|
<body>
|
|
<script>
|
|
test((t) => {
|
|
const host = document.createElement("div");
|
|
t.add_cleanup(() => host.remove());
|
|
document.body.append(host);
|
|
const shadow = host.attachShadow({ mode: "closed" });
|
|
const slot = shadow.appendChild(document.createElement("slot"));
|
|
let childEvent = null;
|
|
let childEventTarget = null;
|
|
let childEventSource = null;
|
|
slot.addEventListener("interest", (e) => {
|
|
childEvent = e;
|
|
childEventTarget = e.target;
|
|
childEventSource = e.source;
|
|
}, { once: true });
|
|
host.addEventListener("interest", (e) => {
|
|
assert_unreached("host should not receive interest event");
|
|
}, { once: true });
|
|
const event = new InterestEvent("interest", {
|
|
bubbles: true,
|
|
source: slot,
|
|
composed: true,
|
|
});
|
|
slot.dispatchEvent(event);
|
|
assert_true(childEvent instanceof InterestEvent, "slot saw interest event");
|
|
assert_equals(childEventTarget, slot, "target is child inside shadow boundary");
|
|
assert_equals(childEventSource, slot, "source is child inside shadow boundary");
|
|
}, "InterestEvent doesn't propagate across shadow boundary when retargeted source == currentTarget");
|
|
|
|
promise_test(async (t) => {
|
|
const host = document.createElement("div");
|
|
t.add_cleanup(() => host.remove());
|
|
document.body.append(host);
|
|
const shadow = host.attachShadow({ mode: "open" });
|
|
const button = shadow.appendChild(document.createElement("button"));
|
|
const interestee = host.appendChild(document.createElement("div"));
|
|
button.interestForElement = interestee;
|
|
button.style = "interest-delay: 0s";
|
|
let event = null;
|
|
let eventTarget = null;
|
|
let eventSource = null;
|
|
interestee.addEventListener("interest", (e) => {
|
|
event = e;
|
|
eventTarget = e.target;
|
|
eventSource = e.source;
|
|
},{ once: true });
|
|
await hoverOver(button);
|
|
assert_true(!!event,"InterestEvent gets fired");
|
|
assert_true(event instanceof InterestEvent);
|
|
assert_equals(eventTarget, interestee, "target is interestee");
|
|
assert_equals(eventSource, host, "interestee is host");
|
|
}, "cross shadow InterestEvent retargets interestee to host element");
|
|
</script>
|