1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 13:28:11 +00:00

LibWeb: Account for scroll offset in hit-testing

The hit-testing position is now shifted by the scroll offsets before
performing any checks for containment. This is implemented by assigning
each PaintableBox/InlinePaintable an offset corresponding to the scroll
frame in which it is contained. The non-scroll-adjusted position is
still passed down when recursing to children because the assigned
offset accumulated for nested scroll frames.

With this change, hit testing works in the Inspector.
Fixes https://github.com/SerenityOS/serenity/issues/22068
This commit is contained in:
Aliaksandr Kalenik 2024-01-29 06:28:17 +01:00 committed by Andreas Kling
parent beb1c85b6b
commit 556679fedd
7 changed files with 81 additions and 10 deletions

View file

@ -0,0 +1,49 @@
<script src="../include.js"></script>
<style type="text/css">
#container {
border: 1px solid black;
height: 200px;
overflow: scroll;
}
p {
margin: 0;
}
p:hover {
background-color: yellow;
}
</style>
<body>
<div id=container>
<p id="line-1">Line 1</p>
<p id="line-2">Line 2</p>
<p id="line-3">Line 3</p>
<p id="line-4">Line 4</p>
<p id="line-5">Line 5</p>
<p id="line-6">Line 6</p>
<p id="line-7">Line 7</p>
<span id="line-8">Line 8</span>
<p id="line-9">Line 9</p>
<p id="line-10">Line 10</p>
<p id="line-11">Line 11</p>
<p id="line-12">Line 12</p>
<p id="line-13">Line 13</p>
<p id="line-14">Line 14</p>
<p id="line-15">Line 15</p>
<p id="line-16">Line 16</p>
<p id="line-17">Line 17</p>
<p id="line-18">Line 18</p>
<p id="line-19">Line 19</p>
<p id="line-20">Line 20</p>
</div>
</body>
<script>
const scrollContainer = document.getElementById("container");
scrollContainer.scrollTop = 100;
test(() => {
printElement(internals.hitTest(10, 10).node.parentNode);
printElement(internals.hitTest(10, 30).node.parentNode);
});
</script>