aboutsummaryrefslogtreecommitdiffstats
path: root/components/layout_2020/table/construct.rs
diff options
context:
space:
mode:
authorOriol Brufau <obrufau@igalia.com>2024-03-21 12:48:39 +0100
committerGitHub <noreply@github.com>2024-03-21 11:48:39 +0000
commitecabdc2583f8e82f39600c2b5d1ca81a7219f235 (patch)
treed0758e1c528bc4e973fc98848a881542d7bdca73 /components/layout_2020/table/construct.rs
parentce0d4564694eb0d5d8baccd53377e387ea303e95 (diff)
downloadservo-ecabdc2583f8e82f39600c2b5d1ca81a7219f235.tar.gz
servo-ecabdc2583f8e82f39600c2b5d1ca81a7219f235.zip
Don't trim leading whitespace of anonymous table cells (#31803)
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`).
Diffstat (limited to 'components/layout_2020/table/construct.rs')
-rw-r--r--components/layout_2020/table/construct.rs27
1 files changed, 19 insertions, 8 deletions
diff --git a/components/layout_2020/table/construct.rs b/components/layout_2020/table/construct.rs
index 5e9b00ddbe4..ac689c951e1 100644
--- a/components/layout_2020/table/construct.rs
+++ b/components/layout_2020/table/construct.rs
@@ -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,
@@ -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;
}
@@ -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));
}
@@ -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;
}
@@ -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));
}