mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 00:57:45 +00:00
LibWeb: Implement document.elementFromPoint()
This function uses our existing hit testing code to determine the topmost element at the given coordinates relative to the viewport.
This commit is contained in:
parent
c732e03ea0
commit
69df94ec5c
5 changed files with 75 additions and 0 deletions
33
Tests/LibWeb/Text/input/DOM/Element-from-point.html
Normal file
33
Tests/LibWeb/Text/input/DOM/Element-from-point.html
Normal file
|
@ -0,0 +1,33 @@
|
|||
<!DOCTYPE html>
|
||||
<html id="root-element">
|
||||
<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>
|
||||
test(() => {
|
||||
println(`Negative coordinates return null: ${document.elementFromPoint(-1, -1) === null}`);
|
||||
println(`Coordinates outside the viewport return null: ${document.elementFromPoint(99999, 99999) === null}`);
|
||||
printElement(document.elementFromPoint(0, 0));
|
||||
printElement(document.elementFromPoint(500, 10));
|
||||
printElement(document.elementFromPoint(550, 60));
|
||||
});
|
||||
</script>
|
||||
</html>
|
Loading…
Add table
Add a link
Reference in a new issue