Skip to content

Commit f0a772e

Browse files
Jon4t4nAtkinsSJ
authored andcommitted
LibWeb: Improve table colspan and rowspan spec alignment
This patch improves the spec alignment [1] for the table `colspan` and `rowspan` attributes by: - Handling min and max for `colspan`. - Handling max for `rowspan`. [1] https://html.spec.whatwg.org/multipage/tables.html#algorithm-for-processing-rows
1 parent 04bc9b1 commit f0a772e

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

Userland/Libraries/LibWeb/HTML/HTMLTableCellElement.cpp

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,19 +95,45 @@ void HTMLTableCellElement::apply_presentational_hints(CSS::StyleProperties& styl
9595
apply_border_style(CSS::PropertyID::BorderBottomStyle, CSS::PropertyID::BorderBottomWidth, CSS::PropertyID::BorderBottomColor);
9696
}
9797

98+
// This implements step 8 in the spec here:
99+
// https://html.spec.whatwg.org/multipage/tables.html#algorithm-for-processing-rows
98100
unsigned int HTMLTableCellElement::col_span() const
99101
{
100-
return Web::HTML::parse_non_negative_integer(attribute(HTML::AttributeNames::colspan)).value_or(1);
102+
auto optional_value = Web::HTML::parse_non_negative_integer(attribute(HTML::AttributeNames::colspan));
103+
104+
// If parsing that value failed, or returned zero, or if the attribute is absent, then let colspan be 1, instead.
105+
if (!optional_value.has_value() || optional_value.value() == 0) {
106+
return 1;
107+
}
108+
109+
auto value = optional_value.value();
110+
111+
// If colspan is greater than 1000, let it be 1000 instead.
112+
if (value > 1000) {
113+
return 1000;
114+
}
115+
116+
return value;
101117
}
102118

103119
WebIDL::ExceptionOr<void> HTMLTableCellElement::set_col_span(unsigned int value)
104120
{
105121
return set_attribute(HTML::AttributeNames::colspan, DeprecatedString::number(value));
106122
}
107123

124+
// This implements step 9 in the spec here:
125+
// https://html.spec.whatwg.org/multipage/tables.html#algorithm-for-processing-rows
108126
unsigned int HTMLTableCellElement::row_span() const
109127
{
110-
return Web::HTML::parse_non_negative_integer(attribute(HTML::AttributeNames::rowspan)).value_or(1);
128+
// If parsing that value failed or if the attribute is absent, then let rowspan be 1, instead.
129+
auto value = Web::HTML::parse_non_negative_integer(attribute(HTML::AttributeNames::rowspan)).value_or(1);
130+
131+
// If rowspan is greater than 65534, let it be 65534 instead.
132+
if (value > 65534) {
133+
return 65534;
134+
}
135+
136+
return value;
111137
}
112138

113139
WebIDL::ExceptionOr<void> HTMLTableCellElement::set_row_span(unsigned int value)

0 commit comments

Comments
 (0)