From 5390e058511b0fafa1c087d015a8b30830a6c88e Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Thu, 24 Feb 2022 11:56:03 +0000 Subject: [PATCH] LibWeb: Extract code for creating a Layout::Node based on display type We need to run the same logic for creating the ::before and ::after pseudo-elements, so this saves us from duplicating the code. --- Userland/Libraries/LibWeb/DOM/Element.cpp | 28 +++++++++++++---------- Userland/Libraries/LibWeb/DOM/Element.h | 2 ++ 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/Userland/Libraries/LibWeb/DOM/Element.cpp b/Userland/Libraries/LibWeb/DOM/Element.cpp index 4879c19fab..abcb382a6e 100644 --- a/Userland/Libraries/LibWeb/DOM/Element.cpp +++ b/Userland/Libraries/LibWeb/DOM/Element.cpp @@ -196,46 +196,50 @@ bool Element::has_class(const FlyString& class_name, CaseSensitivity case_sensit RefPtr Element::create_layout_node(NonnullRefPtr style) { - auto display = style->display(); - if (local_name() == "noscript" && document().is_scripting_enabled()) return nullptr; + auto display = style->display(); + return create_layout_node_for_display_type(document(), display, move(style), this); +} + +RefPtr Element::create_layout_node_for_display_type(DOM::Document& document, CSS::Display const& display, NonnullRefPtr style, Element* element) +{ if (display.is_table_inside()) - return adopt_ref(*new Layout::TableBox(document(), this, move(style))); + return adopt_ref(*new Layout::TableBox(document, element, move(style))); if (display.is_list_item()) - return adopt_ref(*new Layout::ListItemBox(document(), this, move(style))); + return adopt_ref(*new Layout::ListItemBox(document, element, move(style))); if (display.is_table_row()) - return adopt_ref(*new Layout::TableRowBox(document(), this, move(style))); + return adopt_ref(*new Layout::TableRowBox(document, element, move(style))); if (display.is_table_cell()) - return adopt_ref(*new Layout::TableCellBox(document(), this, move(style))); + return adopt_ref(*new Layout::TableCellBox(document, element, move(style))); if (display.is_table_row_group() || display.is_table_header_group() || display.is_table_footer_group()) - return adopt_ref(*new Layout::TableRowGroupBox(document(), this, move(style))); + return adopt_ref(*new Layout::TableRowGroupBox(document, element, move(style))); if (display.is_table_column() || display.is_table_column_group() || display.is_table_caption()) { // FIXME: This is just an incorrect placeholder until we improve table layout support. - return adopt_ref(*new Layout::BlockContainer(document(), this, move(style))); + return adopt_ref(*new Layout::BlockContainer(document, element, move(style))); } if (display.is_inline_outside()) { if (display.is_flow_root_inside()) { - auto block = adopt_ref(*new Layout::BlockContainer(document(), this, move(style))); + auto block = adopt_ref(*new Layout::BlockContainer(document, element, move(style))); block->set_inline(true); return block; } if (display.is_flow_inside()) - return adopt_ref(*new Layout::InlineNode(document(), this, move(style))); + return adopt_ref(*new Layout::InlineNode(document, element, move(style))); dbgln_if(LIBWEB_CSS_DEBUG, "FIXME: Support display: {}", display.to_string()); - return adopt_ref(*new Layout::InlineNode(document(), this, move(style))); + return adopt_ref(*new Layout::InlineNode(document, element, move(style))); } if (display.is_flow_inside() || display.is_flow_root_inside() || display.is_flex_inside()) - return adopt_ref(*new Layout::BlockContainer(document(), this, move(style))); + return adopt_ref(*new Layout::BlockContainer(document, element, move(style))); TODO(); } diff --git a/Userland/Libraries/LibWeb/DOM/Element.h b/Userland/Libraries/LibWeb/DOM/Element.h index 5009dfb2ed..080094341e 100644 --- a/Userland/Libraries/LibWeb/DOM/Element.h +++ b/Userland/Libraries/LibWeb/DOM/Element.h @@ -134,6 +134,8 @@ public: virtual void did_receive_focus() { } virtual void did_lose_focus() { } + static RefPtr create_layout_node_for_display_type(DOM::Document&, CSS::Display const&, NonnullRefPtr, Element*); + protected: virtual void children_changed() override;