Skip to content

Commit

Permalink
Don't trim leading whitespace of anonymous table cells (#31803)
Browse files Browse the repository at this point in the history
A sequence of whitespace shouldn't generate an anonymous table row/cell,
but we can't just throw away the leading whitespace, because afterwards
we may encounter some other content, and then the leading whitespace
should appear in the cell (noticeable with e.g. `white-space: pre`).
  • Loading branch information
Loirooriol committed Mar 21, 2024
1 parent ce0d456 commit ecabdc2
Show file tree
Hide file tree
Showing 11 changed files with 19 additions and 29 deletions.
27 changes: 19 additions & 8 deletions components/layout_2020/table/construct.rs
Expand Up @@ -56,6 +56,19 @@ pub(crate) enum AnonymousTableContent<'dom, Node> {
},
}

impl<'dom, Node> AnonymousTableContent<'dom, Node> {
fn is_whitespace_only(&self) -> bool {
match self {
Self::Element { .. } => false,
Self::Text(_, ref text) => text.chars().all(char_is_whitespace),
}
}

fn contents_are_whitespace_only(contents: &[Self]) -> bool {
contents.iter().all(|content| content.is_whitespace_only())
}
}

impl Table {
pub(crate) fn construct<'dom>(
context: &LayoutContext,
Expand Down Expand Up @@ -627,7 +640,9 @@ where
}

fn finish_anonymous_row_if_needed(&mut self) {
if self.current_anonymous_row_content.is_empty() {
if AnonymousTableContent::contents_are_whitespace_only(&self.current_anonymous_row_content)
{
self.current_anonymous_row_content.clear();
return;
}

Expand Down Expand Up @@ -689,9 +704,6 @@ where
Node: NodeExt<'dom>,
{
fn handle_text(&mut self, info: &NodeAndStyleInfo<Node>, text: Cow<'dom, str>) {
if text.chars().all(char_is_whitespace) {
return;
}
self.current_anonymous_row_content
.push(AnonymousTableContent::Text(info.clone(), text));
}
Expand Down Expand Up @@ -897,7 +909,9 @@ where
}

fn finish_current_anonymous_cell_if_needed(&mut self) {
if self.current_anonymous_cell_content.is_empty() {
if AnonymousTableContent::contents_are_whitespace_only(&self.current_anonymous_cell_content)
{
self.current_anonymous_cell_content.clear();
return;
}

Expand Down Expand Up @@ -947,9 +961,6 @@ where
Node: NodeExt<'dom>,
{
fn handle_text(&mut self, info: &NodeAndStyleInfo<Node>, text: Cow<'dom, str>) {
if text.chars().all(char_is_whitespace) {
return;
}
self.current_anonymous_cell_content
.push(AnonymousTableContent::Text(info.clone(), text));
}
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

2 changes: 0 additions & 2 deletions tests/wpt/meta/css/css-tables/anonymous-table-ws-001.html.ini

This file was deleted.

3 changes: 0 additions & 3 deletions tests/wpt/meta/css/css-tables/table-model-fixup.html.ini
Expand Up @@ -14,8 +14,5 @@
[2.2. An anonymous table-row box must be generated around each sequence of consecutive children of a table-row-grouping box which are not table-row boxes. (3/3)]
expected: FAIL

[1.4. Anonymous inline boxes which contains only white space and are between two immediate siblings *each* of which is a table-non-root element, are treated as if they had display: none.]
expected: FAIL

[2.3 happens after 2.1. and 2.2. (1/2)]
expected: FAIL
2 changes: 0 additions & 2 deletions tests/wpt/meta/css/css-tables/whitespace-001.html.ini

This file was deleted.

0 comments on commit ecabdc2

Please sign in to comment.