Forráskód Böngészése

LibWeb: Make `display: foo` box constructors take the Element by pointer

This means we can instantiate them for pseudo-elements, which don't have
an associated Element. They all pass it to their parent as a
`Layout::Node*` and handle a lack of `layout_node()` already so this
won't affect any functionality.
Sam Atkins 3 éve
szülő
commit
7bb721bea2

+ 4 - 4
Userland/Libraries/LibWeb/DOM/Element.cpp

@@ -205,7 +205,7 @@ RefPtr<Layout::Node> Element::create_layout_node(NonnullRefPtr<CSS::StylePropert
         return adopt_ref(*new Layout::TableBox(document(), this, move(style)));
 
     if (display.is_list_item())
-        return adopt_ref(*new Layout::ListItemBox(document(), *this, move(style)));
+        return adopt_ref(*new Layout::ListItemBox(document(), this, move(style)));
 
     if (display.is_table_row())
         return adopt_ref(*new Layout::TableRowBox(document(), this, move(style)));
@@ -214,7 +214,7 @@ RefPtr<Layout::Node> Element::create_layout_node(NonnullRefPtr<CSS::StylePropert
         return adopt_ref(*new Layout::TableCellBox(document(), this, 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(), this, 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.
@@ -228,10 +228,10 @@ RefPtr<Layout::Node> Element::create_layout_node(NonnullRefPtr<CSS::StylePropert
             return block;
         }
         if (display.is_flow_inside())
-            return adopt_ref(*new Layout::InlineNode(document(), *this, move(style)));
+            return adopt_ref(*new Layout::InlineNode(document(), this, 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(), this, move(style)));
     }
 
     if (display.is_flow_inside() || display.is_flow_root_inside() || display.is_flex_inside())

+ 2 - 2
Userland/Libraries/LibWeb/Layout/InlineNode.cpp

@@ -17,8 +17,8 @@
 
 namespace Web::Layout {
 
-InlineNode::InlineNode(DOM::Document& document, DOM::Element& element, NonnullRefPtr<CSS::StyleProperties> style)
-    : Layout::NodeWithStyleAndBoxModelMetrics(document, &element, move(style))
+InlineNode::InlineNode(DOM::Document& document, DOM::Element* element, NonnullRefPtr<CSS::StyleProperties> style)
+    : Layout::NodeWithStyleAndBoxModelMetrics(document, element, move(style))
 {
     set_inline(true);
 }

+ 1 - 1
Userland/Libraries/LibWeb/Layout/InlineNode.h

@@ -12,7 +12,7 @@ namespace Web::Layout {
 
 class InlineNode : public NodeWithStyleAndBoxModelMetrics {
 public:
-    InlineNode(DOM::Document&, DOM::Element&, NonnullRefPtr<CSS::StyleProperties>);
+    InlineNode(DOM::Document&, DOM::Element*, NonnullRefPtr<CSS::StyleProperties>);
     virtual ~InlineNode() override;
 
     virtual void paint(PaintContext&, PaintPhase) override;

+ 2 - 2
Userland/Libraries/LibWeb/Layout/ListItemBox.cpp

@@ -10,8 +10,8 @@
 
 namespace Web::Layout {
 
-ListItemBox::ListItemBox(DOM::Document& document, DOM::Element& element, NonnullRefPtr<CSS::StyleProperties> style)
-    : Layout::BlockContainer(document, &element, move(style))
+ListItemBox::ListItemBox(DOM::Document& document, DOM::Element* element, NonnullRefPtr<CSS::StyleProperties> style)
+    : Layout::BlockContainer(document, element, move(style))
 {
 }
 

+ 1 - 1
Userland/Libraries/LibWeb/Layout/ListItemBox.h

@@ -13,7 +13,7 @@ namespace Web::Layout {
 
 class ListItemBox final : public BlockContainer {
 public:
-    ListItemBox(DOM::Document&, DOM::Element&, NonnullRefPtr<CSS::StyleProperties>);
+    ListItemBox(DOM::Document&, DOM::Element*, NonnullRefPtr<CSS::StyleProperties>);
     virtual ~ListItemBox() override;
 
     DOM::Element& dom_node() { return static_cast<DOM::Element&>(*BlockContainer::dom_node()); }

+ 2 - 2
Userland/Libraries/LibWeb/Layout/TableRowGroupBox.cpp

@@ -11,8 +11,8 @@
 
 namespace Web::Layout {
 
-TableRowGroupBox::TableRowGroupBox(DOM::Document& document, DOM::Element& element, NonnullRefPtr<CSS::StyleProperties> style)
-    : Layout::BlockContainer(document, &element, move(style))
+TableRowGroupBox::TableRowGroupBox(DOM::Document& document, DOM::Element* element, NonnullRefPtr<CSS::StyleProperties> style)
+    : Layout::BlockContainer(document, element, move(style))
 {
 }
 

+ 1 - 1
Userland/Libraries/LibWeb/Layout/TableRowGroupBox.h

@@ -12,7 +12,7 @@ namespace Web::Layout {
 
 class TableRowGroupBox final : public BlockContainer {
 public:
-    TableRowGroupBox(DOM::Document&, DOM::Element&, NonnullRefPtr<CSS::StyleProperties>);
+    TableRowGroupBox(DOM::Document&, DOM::Element*, NonnullRefPtr<CSS::StyleProperties>);
     virtual ~TableRowGroupBox() override;
 
     size_t column_count() const;