ladybird/Tests/LibWeb/Text/input/DOM/range-bounding-client-rect-with-nested-text.html
Annya 75c7dbc5d2 LibWeb: Implement Range's extension method
This patch implements `Range::getClientRects` and
`Range::getBoundingClientRect`. Since the rects returned by invoking
getClientRects can be accessed without adding them to the Selection,
`ViewportPaintable::recompute_selection_states` has been updated to
accept a Range as a parameter, rather than acquiring it through the
Document's Selection.

With this change, the following tests now pass:

- wpt[css/cssom-view/range-bounding-client-rect-with-nested-text.html]
- wpt[css/cssom-view/DOMRectList.html]

Note: The test
"css/cssom-view/range-bounding-client-rect-with-display-contents.html"
still fails due to an issue with Element::getClientRects, which will
be addressed in a future commit.
2024-09-20 19:58:20 +02:00

47 lines
1.3 KiB
HTML

<!--refer to https://wpt.live/css/cssom-view/range-bounding-client-rect-with-nested-text.html -->
<!DOCTYPE html>
<meta charset="utf-8">
<title>All the rectangles for the text nodes must included in getClientRects</title>
<script src="../include.js"></script>
<style>
.nullDims {
width: 0;
height: 0;
}
.nullDims > div {
position: absolute;
left: 10px;
}
</style>
<div id="container">
<div class="nullDims">
<div id="first" style="top: 10px">Hello</div>
</div>
<div class="nullDims">
<div id="second" style="top: 40px">Ladybird</div>
</div>
<div class="nullDims">
<div id="third" style="top: 70px">Ladybird again</div>
</div>
<div class="nullDims">
<div id="last" style="top: 100px">World</div>
</div>
</div>
<script>
test(function () {
const first = document.getElementById("first");
const last = document.getElementById("last");
const range = document.createRange();
range.setStart(first.firstChild, 0);
range.setEnd(last.firstChild, 3);
const selection = window.getSelection();
selection.removeAllRanges();
selection.addRange(range);
let rects = Array.from(range.getClientRects());
println(rects.length);
rects = rects.filter(({ width, height }) => width > 0 && height > 0);
println(rects.length);
})
</script>