LibWeb: Add null check for get_client_rects() on non paintable elements

This commit is contained in:
Cnidarias 2024-04-16 21:43:33 +02:00 committed by Alexander Kalenik
parent c186ab96ac
commit 1a1e5aaf54
Notes: sideshowbarker 2024-07-17 06:40:35 +09:00
3 changed files with 13 additions and 7 deletions

View file

@ -1 +1,3 @@
{"x":0,"y":0,"width":0,"height":0,"top":0,"right":0,"bottom":0,"left":0}
{"x":0,"y":0,"width":0,"height":0,"top":0,"right":0,"bottom":0,"left":0}

View file

@ -3,10 +3,14 @@
#box { display: none; }
</style>
<div id="box"></div>
<br id="br"/>
<script src="include.js"></script>
<script>
test(() => {
const rect = document.getElementById("box").getBoundingClientRect();
println(JSON.stringify(rect));
const br_rect = document.getElementById("br").getBoundingClientRect();
println(JSON.stringify(br_rect));
});
</script>

View file

@ -884,16 +884,16 @@ JS::NonnullGCPtr<Geometry::DOMRectList> Element::get_client_rects() const
const_cast<Document&>(document()).update_paint_and_hit_testing_properties_if_needed();
Gfx::AffineTransform transform;
if (auto const* paintable_box = this->paintable_box())
transform = Gfx::extract_2d_affine_transform(paintable_box->transform());
CSSPixelPoint scroll_offset;
for (auto const* containing_block = paintable()->containing_block(); containing_block; containing_block = containing_block->containing_block()) {
transform = Gfx::extract_2d_affine_transform(containing_block->transform()).multiply(transform);
scroll_offset.translate_by(containing_block->scroll_offset());
}
auto const* paintable = this->paintable();
if (auto const* paintable_box = this->paintable_box()) {
transform = Gfx::extract_2d_affine_transform(paintable_box->transform());
for (auto const* containing_block = paintable->containing_block(); containing_block; containing_block = containing_block->containing_block()) {
transform = Gfx::extract_2d_affine_transform(containing_block->transform()).multiply(transform);
scroll_offset.translate_by(containing_block->scroll_offset());
}
auto absolute_rect = paintable_box->absolute_border_box_rect();
auto transformed_rect = transform.map(absolute_rect.translated(-paintable_box->transform_origin()).to_type<float>())
.to_type<CSSPixels>()