-
-
Notifications
You must be signed in to change notification settings - Fork 969
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
1 parent
a3472ae
commit 75c7dbc
Showing
12 changed files
with
225 additions
and
38 deletions.
There are no files selected for viewing
2 changes: 2 additions & 0 deletions
2
Tests/LibWeb/Text/expected/DOM/range-bounding-client-rect-with-nested-text.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Hello Ladybird Ladybird again World 6 | ||
4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
x [object DOMRectList] | ||
[object DOMRect] |
47 changes: 47 additions & 0 deletions
47
Tests/LibWeb/Text/input/DOM/range-bounding-client-rect-with-nested-text.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.