1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 07:27:45 +00:00

LibWeb: Implement document.elementsFromPoint

This API seems to be used by WPT for sending synthetic input events.

Implementing the naive translation of elementFromPoint to the spec steps
for this algorithm turns 4 'tests had errors unexpectedly' and 3 'tests
had timeouts unexpectedly' into 1 pass and 7 'tests had unexpected
subtest results' on the infrastructure/ subdirectory of WPT.
This commit is contained in:
Andrew Kaster 2024-02-09 13:50:44 -07:00 committed by Andrew Kaster
parent e7daa02bf2
commit 6a0fe08604
5 changed files with 104 additions and 0 deletions

View file

@ -0,0 +1,46 @@
<!DOCTYPE html>
<style>
#large-box {
position: absolute;
top: 10px;
left: 500px;
width: 100px;
height: 100px;
background-color: magenta;
}
#small-box {
position: absolute;
top: 35px;
left: 525px;
width: 50px;
height: 50px;
background-color: yellow;
}
</style>
<script src="../include.js"></script>
<div id="large-box"></div><div id="small-box"></div>
<script>
function isEmptyArray(val) {
return Array.isArray(val) && val.length === 0;
}
test(() => {
println(`Negative coordinates return empty array: ${isEmptyArray(document.elementsFromPoint(-1, -1))}`);
println(`Coordinates outside the viewport return empty array: ${isEmptyArray(document.elementsFromPoint(99999, 99999))}`);
println("== Elements at (500, 10) ==")
for (let elem of document.elementsFromPoint(500, 10)) {
printElement(elem);
}
println("== FIXME: Elements at (550, 60) ==")
for (let elem of document.elementsFromPoint(550, 60)) {
printElement(elem);
}
// FIXME: 550, 60 is supposed to print the following, but the algorithm is wrong.
// <DIV id="small-box" >
// <DIV id="large-box" >
// <PRE id="out" >
// <BODY >
// <HTML >
});
</script>