aboutsummaryrefslogtreecommitdiffstats
path: root/components
diff options
context:
space:
mode:
Diffstat (limited to 'components')
-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));
}