Skip to content

Commit 64c353f

Browse files
martinfalisseawesomekling
authored andcommitted
LibWeb: Parse border-collapse property for HTML table
1 parent 25f612f commit 64c353f

File tree

7 files changed

+22
-3
lines changed

7 files changed

+22
-3
lines changed

Userland/Libraries/LibWeb/CSS/ComputedValues.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ class InitialValues {
7272
static CSS::GridTrackPlacement grid_row_start() { return CSS::GridTrackPlacement::make_auto(); }
7373
static CSS::Size column_gap() { return CSS::Size::make_auto(); }
7474
static CSS::Size row_gap() { return CSS::Size::make_auto(); }
75+
static CSS::BorderCollapse border_collapse() { return CSS::BorderCollapse::Separate; }
7576
};
7677

7778
struct BackgroundLayerData {
@@ -192,6 +193,7 @@ class ComputedValues {
192193
CSS::GridTrackPlacement const& grid_row_start() const { return m_noninherited.grid_row_start; }
193194
CSS::Size const& column_gap() const { return m_noninherited.column_gap; }
194195
CSS::Size const& row_gap() const { return m_noninherited.row_gap; }
196+
CSS::BorderCollapse border_collapse() const { return m_noninherited.border_collapse; }
195197

196198
CSS::LengthBox const& inset() const { return m_noninherited.inset; }
197199
const CSS::LengthBox& margin() const { return m_noninherited.margin; }
@@ -316,6 +318,7 @@ class ComputedValues {
316318
CSS::GridTrackPlacement grid_row_start { InitialValues::grid_row_start() };
317319
CSS::Size column_gap { InitialValues::column_gap() };
318320
CSS::Size row_gap { InitialValues::row_gap() };
321+
CSS::BorderCollapse border_collapse { InitialValues::border_collapse() };
319322
} m_noninherited;
320323
};
321324

@@ -396,6 +399,7 @@ class MutableComputedValues final : public ComputedValues {
396399
void set_grid_row_start(CSS::GridTrackPlacement value) { m_noninherited.grid_row_start = value; }
397400
void set_column_gap(CSS::Size const& column_gap) { m_noninherited.column_gap = column_gap; }
398401
void set_row_gap(CSS::Size const& row_gap) { m_noninherited.row_gap = row_gap; }
402+
void set_border_collapse(CSS::BorderCollapse const& border_collapse) { m_noninherited.border_collapse = border_collapse; }
399403

400404
void set_fill(Color value) { m_inherited.fill = value; }
401405
void set_stroke(Color value) { m_inherited.stroke = value; }

Userland/Libraries/LibWeb/CSS/Enums.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@
6060
"content-box",
6161
"padding-box"
6262
],
63+
"border-collapse": [
64+
"separate",
65+
"collapse"
66+
],
6367
"box-sizing": [
6468
"border-box",
6569
"content-box"

Userland/Libraries/LibWeb/CSS/Properties.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,8 @@
266266
"border-collapse": {
267267
"inherited": true,
268268
"initial": "separate",
269-
"valid-identifiers": [
270-
"collapse",
271-
"separate"
269+
"valid-types": [
270+
"border-collapse"
272271
]
273272
},
274273
"border-left-color": {

Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,8 @@ RefPtr<StyleValue> ResolvedCSSStyleDeclaration::style_value_for_property(Layout:
202202
return IdentifierStyleValue::create(to_value_id(layout_node.computed_values().border_bottom().line_style));
203203
case CSS::PropertyID::BorderBottomWidth:
204204
return LengthStyleValue::create(Length::make_px(layout_node.computed_values().border_bottom().width));
205+
case CSS::PropertyID::BorderCollapse:
206+
return IdentifierStyleValue::create(to_value_id(layout_node.computed_values().border_collapse()));
205207
case CSS::PropertyID::BorderLeft: {
206208
auto border = layout_node.computed_values().border_left();
207209
auto width = LengthStyleValue::create(Length::make_px(border.width));

Userland/Libraries/LibWeb/CSS/StyleProperties.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,4 +737,10 @@ CSS::GridTrackPlacement StyleProperties::grid_row_start() const
737737
return value->as_grid_track_placement().grid_track_placement();
738738
}
739739

740+
Optional<CSS::BorderCollapse> StyleProperties::border_collapse() const
741+
{
742+
auto value = property(CSS::PropertyID::BorderCollapse);
743+
return value_id_to_border_collapse(value->to_identifier());
744+
}
745+
740746
}

Userland/Libraries/LibWeb/CSS/StyleProperties.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ class StyleProperties : public RefCounted<StyleProperties> {
9090
CSS::GridTrackPlacement grid_column_start() const;
9191
CSS::GridTrackPlacement grid_row_end() const;
9292
CSS::GridTrackPlacement grid_row_start() const;
93+
Optional<CSS::BorderCollapse> border_collapse() const;
9394

9495
Vector<CSS::Transformation> transformations() const;
9596
CSS::TransformOrigin transform_origin() const;

Userland/Libraries/LibWeb/Layout/Node.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,9 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& computed_style)
605605

606606
computed_values.set_column_gap(computed_style.size_value(CSS::PropertyID::ColumnGap));
607607
computed_values.set_row_gap(computed_style.size_value(CSS::PropertyID::RowGap));
608+
609+
if (auto border_collapse = computed_style.border_collapse(); border_collapse.has_value())
610+
computed_values.set_border_collapse(border_collapse.value());
608611
}
609612

610613
bool Node::is_root_element() const

0 commit comments

Comments
 (0)