Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't trim leading whitespace of anonymous table cells #31803

Merged
merged 1 commit into from Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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.