LibWeb: Add missing check if scrollable overflow defined for paintable

With 6a549f6270 we need to check if
optional scrollable overflow exists for paintable box, because it's not
computed for inline nodes.

Fixes crashing after navigating into direct messages screen on Discord.
This commit is contained in:
Aliaksandr Kalenik 2024-10-21 15:11:21 +02:00 committed by Alexander Kalenik
parent 27928cd28c
commit 629a3ac61e
Notes: github-actions[bot] 2024-10-21 13:58:16 +00:00
3 changed files with 20 additions and 2 deletions

View file

@ -0,0 +1 @@
Scroll Height: 0px, Scroll Width: 0px

View file

@ -0,0 +1,11 @@
<!DOCTYPE html>
<span id="empty-span"></span>
<script src="include.js"></script>
<script>
test(() => {
const hiddenDiv = document.getElementById('empty-span');
const scrollHeight = hiddenDiv.scrollHeight;
const scrollWidth = hiddenDiv.scrollWidth;
println(`Scroll Height: ${scrollHeight}px, Scroll Width: ${scrollWidth}px`);
});
</script>

View file

@ -1455,7 +1455,10 @@ int Element::scroll_width() const
return 0;
// 7. Return the width of the elements scrolling area.
return paintable_box()->scrollable_overflow_rect()->width().to_int();
if (auto scrollable_overflow_rect = paintable_box()->scrollable_overflow_rect(); scrollable_overflow_rect.has_value()) {
return scrollable_overflow_rect->width().to_int();
}
return 0;
}
// https://drafts.csswg.org/cssom-view/#dom-element-scrollheight
@ -1491,7 +1494,10 @@ int Element::scroll_height() const
return 0;
// 7. Return the height of the elements scrolling area.
return paintable_box()->scrollable_overflow_rect()->height().to_int();
if (auto scrollable_overflow_rect = paintable_box()->scrollable_overflow_rect(); scrollable_overflow_rect.has_value()) {
return scrollable_overflow_rect->height().to_int();
}
return 0;
}
// https://html.spec.whatwg.org/multipage/semantics-other.html#concept-element-disabled