mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-22 09:19:03 +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:
@@ -0,0 +1,2 @@
|
||||
Hello Ladybird Ladybird again World 6
|
||||
4
|
||||
@@ -0,0 +1,2 @@
|
||||
x [object DOMRectList]
|
||||
[object DOMRect]
|
||||
@@ -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>
|
||||
19
Tests/LibWeb/Text/input/DOM/range-get-client-rects.html
Normal file
19
Tests/LibWeb/Text/input/DOM/range-get-client-rects.html
Normal file
@@ -0,0 +1,19 @@
|
||||
<!--refer to https://wpt.live/css/cssom-view/DOMRectList.html -->
|
||||
<body>
|
||||
<div id="x">x</div>
|
||||
<script src="../include.js"></script>
|
||||
<script>
|
||||
function print_class_string(object) {
|
||||
println({}.toString.call(object));
|
||||
}
|
||||
test(() => {
|
||||
const x = document.getElementById("x");
|
||||
const range = document.createRange();
|
||||
range.selectNodeContents(x);
|
||||
const domRectList = range.getClientRects();
|
||||
print_class_string(domRectList);
|
||||
print_class_string(domRectList.item(0));
|
||||
});
|
||||
</script>
|
||||
|
||||
</body>
|
||||
Reference in New Issue
Block a user