From 629a3ac61e5d6e031cc7fb2394f388c9ab0b0c33 Mon Sep 17 00:00:00 2001 From: Aliaksandr Kalenik Date: Mon, 21 Oct 2024 15:11:21 +0200 Subject: [PATCH] LibWeb: Add missing check if scrollable overflow defined for paintable With 6a549f62702e8b733dd4fc0caf1fa3e114243070 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. --- .../expected/query-scroll-size-of-inline-node.txt | 1 + .../Text/input/query-scroll-size-of-inline-node.html | 11 +++++++++++ Userland/Libraries/LibWeb/DOM/Element.cpp | 10 ++++++++-- 3 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 Tests/LibWeb/Text/expected/query-scroll-size-of-inline-node.txt create mode 100644 Tests/LibWeb/Text/input/query-scroll-size-of-inline-node.html diff --git a/Tests/LibWeb/Text/expected/query-scroll-size-of-inline-node.txt b/Tests/LibWeb/Text/expected/query-scroll-size-of-inline-node.txt new file mode 100644 index 00000000000..e6db6ac12bc --- /dev/null +++ b/Tests/LibWeb/Text/expected/query-scroll-size-of-inline-node.txt @@ -0,0 +1 @@ +Scroll Height: 0px, Scroll Width: 0px diff --git a/Tests/LibWeb/Text/input/query-scroll-size-of-inline-node.html b/Tests/LibWeb/Text/input/query-scroll-size-of-inline-node.html new file mode 100644 index 00000000000..bdba7060b2a --- /dev/null +++ b/Tests/LibWeb/Text/input/query-scroll-size-of-inline-node.html @@ -0,0 +1,11 @@ + + + + diff --git a/Userland/Libraries/LibWeb/DOM/Element.cpp b/Userland/Libraries/LibWeb/DOM/Element.cpp index 4b8e88abf3a..834442bdc32 100644 --- a/Userland/Libraries/LibWeb/DOM/Element.cpp +++ b/Userland/Libraries/LibWeb/DOM/Element.cpp @@ -1455,7 +1455,10 @@ int Element::scroll_width() const return 0; // 7. Return the width of the element’s 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 element’s 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