mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-29 20:29:18 +00:00
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.
This commit is contained in:
parent
a3472aef24
commit
75c7dbc5d2
Notes:
github-actions[bot]
2024-09-20 17:59:18 +00:00
Author: https://github.com/An-n-ya
Commit: 75c7dbc5d2
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1417
Reviewed-by: https://github.com/kalenikaliaksandr
12 changed files with 225 additions and 38 deletions
|
@ -0,0 +1,47 @@
|
|||
<!--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>
|
Loading…
Add table
Add a link
Reference in a new issue