From a6d1307aa4eaa9aee34829879d9ba711174cce4d Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 19 Mar 2023 20:35:42 +0100 Subject: [PATCH] LibWeb: Don't crash on HTML input element with `display: inline` This would previously assert in InlineFormattingContext because we had an outwardly inline box that wasn't inwardly flow. Fix this by converting text-based input boxes to inline-blocks. This is an ad-hoc solution, and there might be a much better way to solve it. --- .../expected/input-element-with-display-inline.txt | 9 +++++++++ .../input/input-element-with-display-inline.html | 10 ++++++++++ Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp | 7 ++++++- 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 Tests/LibWeb/Layout/expected/input-element-with-display-inline.txt create mode 100644 Tests/LibWeb/Layout/input/input-element-with-display-inline.html diff --git a/Tests/LibWeb/Layout/expected/input-element-with-display-inline.txt b/Tests/LibWeb/Layout/expected/input-element-with-display-inline.txt new file mode 100644 index 0000000000..64f9d6b032 --- /dev/null +++ b/Tests/LibWeb/Layout/expected/input-element-with-display-inline.txt @@ -0,0 +1,9 @@ +Viewport <#document> at (0,0) content-size 800x600 children: not-inline + BlockContainer at (1,1) content-size 798x45.835937 children: not-inline + BlockContainer at (10,10) content-size 780x27.835937 children: inline + line 0 width: 202, height: 27.835937, bottom: 27.835937, baseline: 25.835937 + frag 0 from BlockContainer start: 0, length: 0, rect: [11,11 200x25.835937] + BlockContainer at (11,11) content-size 200x25.835937 inline-block children: not-inline + BlockContainer <#shadow-root> at (11,11) content-size 0x0 children: not-inline + BlockContainer
at (14,13) content-size 194x21.835937 children: inline + TextNode <#text> diff --git a/Tests/LibWeb/Layout/input/input-element-with-display-inline.html b/Tests/LibWeb/Layout/input/input-element-with-display-inline.html new file mode 100644 index 0000000000..f7e8ae1d9c --- /dev/null +++ b/Tests/LibWeb/Layout/input/input-element-with-display-inline.html @@ -0,0 +1,10 @@ + \ No newline at end of file diff --git a/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp index 1cbb2757b6..bd5a85474b 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp @@ -71,7 +71,12 @@ JS::GCPtr HTMLInputElement::create_layout_node(NonnullRefPtr(document(), *this, move(style)); - return heap().allocate_without_realm(document(), this, move(style)); + // AD-HOC: We rewrite `display: inline` to `display: inline-block`. + // This is required for the internal shadow tree to work correctly in layout. + if (style->display().is_inline_outside() && style->display().is_flow_inside()) + style->set_property(CSS::PropertyID::Display, CSS::IdentifierStyleValue::create(CSS::ValueID::InlineBlock)); + + return Element::create_layout_node_for_display_type(document(), style->display(), style, this); } void HTMLInputElement::set_checked(bool checked, ChangeSource change_source)