浏览代码

LibWeb: Allow anonymous table, table-row and table-cell layout nodes

Andreas Kling 4 年之前
父节点
当前提交
d3046a2649

+ 3 - 3
Libraries/LibWeb/DOM/Element.cpp

@@ -135,11 +135,11 @@ RefPtr<Layout::Node> Element::create_layout_node()
     if (display == CSS::Display::ListItem)
         return adopt(*new Layout::ListItemBox(document(), *this, move(style)));
     if (display == CSS::Display::Table)
-        return adopt(*new Layout::TableBox(document(), *this, move(style)));
+        return adopt(*new Layout::TableBox(document(), this, move(style)));
     if (display == CSS::Display::TableRow)
-        return adopt(*new Layout::TableRowBox(document(), *this, move(style)));
+        return adopt(*new Layout::TableRowBox(document(), this, move(style)));
     if (display == CSS::Display::TableCell)
-        return adopt(*new Layout::TableCellBox(document(), *this, move(style)));
+        return adopt(*new Layout::TableCellBox(document(), this, move(style)));
     if (display == CSS::Display::TableRowGroup || display == CSS::Display::TableHeaderGroup || display == CSS::Display::TableFooterGroup)
         return adopt(*new Layout::TableRowGroupBox(document(), *this, move(style)));
     if (display == CSS::Display::InlineBlock) {

+ 7 - 2
Libraries/LibWeb/Layout/TableBox.cpp

@@ -29,8 +29,13 @@
 
 namespace Web::Layout {
 
-TableBox::TableBox(DOM::Document& document, DOM::Element& element, NonnullRefPtr<CSS::StyleProperties> style)
-    : Layout::BlockBox(document, &element, move(style))
+TableBox::TableBox(DOM::Document& document, DOM::Element* element, NonnullRefPtr<CSS::StyleProperties> style)
+    : Layout::BlockBox(document, element, move(style))
+{
+}
+
+TableBox::TableBox(DOM::Document& document, DOM::Element* element, CSS::ComputedValues computed_values)
+    : Layout::BlockBox(document, element, move(computed_values))
 {
 }
 

+ 2 - 1
Libraries/LibWeb/Layout/TableBox.h

@@ -32,7 +32,8 @@ namespace Web::Layout {
 
 class TableBox final : public Layout::BlockBox {
 public:
-    TableBox(DOM::Document&, DOM::Element&, NonnullRefPtr<CSS::StyleProperties>);
+    TableBox(DOM::Document&, DOM::Element*, NonnullRefPtr<CSS::StyleProperties>);
+    TableBox(DOM::Document&, DOM::Element*, CSS::ComputedValues);
     virtual ~TableBox() override;
 };
 

+ 9 - 3
Libraries/LibWeb/Layout/TableCellBox.cpp

@@ -30,8 +30,13 @@
 
 namespace Web::Layout {
 
-TableCellBox::TableCellBox(DOM::Document& document, DOM::Element& element, NonnullRefPtr<CSS::StyleProperties> style)
-    : Layout::BlockBox(document, &element, move(style))
+TableCellBox::TableCellBox(DOM::Document& document, DOM::Element* element, NonnullRefPtr<CSS::StyleProperties> style)
+    : Layout::BlockBox(document, element, move(style))
+{
+}
+
+TableCellBox::TableCellBox(DOM::Document& document, DOM::Element* element, CSS::ComputedValues computed_values)
+    : Layout::BlockBox(document, element, move(computed_values))
 {
 }
 
@@ -41,7 +46,8 @@ TableCellBox::~TableCellBox()
 
 size_t TableCellBox::colspan() const
 {
-    ASSERT(dom_node());
+    if (!dom_node())
+        return 0;
     return downcast<DOM::Element>(*dom_node()).attribute(HTML::AttributeNames::colspan).to_uint().value_or(1);
 }
 

+ 2 - 1
Libraries/LibWeb/Layout/TableCellBox.h

@@ -32,7 +32,8 @@ namespace Web::Layout {
 
 class TableCellBox final : public BlockBox {
 public:
-    TableCellBox(DOM::Document&, DOM::Element&, NonnullRefPtr<CSS::StyleProperties>);
+    TableCellBox(DOM::Document&, DOM::Element*, NonnullRefPtr<CSS::StyleProperties>);
+    TableCellBox(DOM::Document&, DOM::Element*, CSS::ComputedValues);
     virtual ~TableCellBox() override;
 
     TableCellBox* next_cell() { return next_sibling_of_type<TableCellBox>(); }

+ 7 - 2
Libraries/LibWeb/Layout/TableRowBox.cpp

@@ -29,8 +29,13 @@
 
 namespace Web::Layout {
 
-TableRowBox::TableRowBox(DOM::Document& document, DOM::Element& element, NonnullRefPtr<CSS::StyleProperties> style)
-    : Box(document, &element, move(style))
+TableRowBox::TableRowBox(DOM::Document& document, DOM::Element* element, NonnullRefPtr<CSS::StyleProperties> style)
+    : Box(document, element, move(style))
+{
+}
+
+TableRowBox::TableRowBox(DOM::Document& document, DOM::Element* element, CSS::ComputedValues computed_values)
+    : Box(document, element, move(computed_values))
 {
 }
 

+ 2 - 1
Libraries/LibWeb/Layout/TableRowBox.h

@@ -32,7 +32,8 @@ namespace Web::Layout {
 
 class TableRowBox final : public Box {
 public:
-    TableRowBox(DOM::Document&, DOM::Element&, NonnullRefPtr<CSS::StyleProperties>);
+    TableRowBox(DOM::Document&, DOM::Element*, NonnullRefPtr<CSS::StyleProperties>);
+    TableRowBox(DOM::Document&, DOM::Element*, CSS::ComputedValues);
     virtual ~TableRowBox() override;
 };