Skip to content

The headless browser for AI agents and web scraping

Correct content-box fixed table sizing

SGavrl68c81f319cd9
diff --git a/crates/obscura-render/src/dom.rs b/crates/obscura-render/src/dom.rs
index eca1c0f1..6d8c46d8 100644
--- a/crates/obscura-render/src/dom.rs
+++ b/crates/obscura-render/src/dom.rs
@@ -5465,12 +5465,19 @@ fn layout_dom_once(
continue;
}
let inline_outer_edges = table_inline_outer_edges(table_style);
+ let (horizontal_spacing, _) = table_spacing(table_style);
let mut used_outer = match table_style.width {
crate::Dimension::Px(width)
if table_style.box_sizing
== crate::BoxSizing::ContentBox =>
{
- width.max(0.0) + inline_outer_edges
+ // Border spacing lives inside a CSS table's
+ // content box. It is artificial Taffy
+ // padding in our grid model, but must not
+ // enlarge an authored content-box width.
+ width.max(0.0)
+ + (inline_outer_edges - horizontal_spacing * 2.0)
+ .max(0.0)
}
crate::Dimension::Px(width) => width.max(0.0),
crate::Dimension::Percent(_) => available_widths
@@ -5487,7 +5494,6 @@ fn layout_dom_once(
}),
_ => continue,
};
- let (horizontal_spacing, _) = table_spacing(table_style);
let interior_spacing =
horizontal_spacing * ncols.saturating_sub(1) as f32;
let target =
@@ -16453,6 +16459,24 @@ mod tests {
assert!((rect("second").width - 212.0).abs() < 0.1, "{:?}", rect("second"));
}
+ #[test]
+ fn fixed_content_box_table_keeps_border_spacing_inside_declared_width() {
+ let tree = parse_html(
+ r#"<style>
+ html,body { margin:0 }
+ table { box-sizing:content-box; table-layout:fixed; width:300px; border:4px solid black; border-spacing:10px 0 }
+ td { height:30px; padding:0; border:0 }
+ #first { width:50px }
+ </style>
+ <table id="table"><tr><td id="first"></td><td id="second"></td></tr></table>"#,
+ );
+ let laid = layout_dom(&tree, (800.0, 300.0));
+ let rect = |id: &str| laid.rects[&tree.get_element_by_id(id).unwrap()];
+ assert!((rect("table").width - 308.0).abs() < 0.1, "{:?}", rect("table"));
+ assert!((rect("first").width - 50.0).abs() < 0.1, "{:?}", rect("first"));
+ assert!((rect("second").width - 220.0).abs() < 0.1, "{:?}", rect("second"));
+ }
+
#[test]
fn fixed_percentage_table_resolves_tracks_against_final_used_width() {
let tree = parse_html(
diff --git a/render-repros/checks.json b/render-repros/checks.json
index 7e9e50ab..1a5d7336 100644
--- a/render-repros/checks.json
+++ b/render-repros/checks.json
@@ -276,7 +276,9 @@
{"name": "separate model charges outer spacing before first track", "color": "#862e9c", "x": 14, "y": 104, "width": 50, "height": 30},
{"name": "separate model removes border and all spacing from track space", "color": "#15aabf", "x": 74, "y": 104, "width": 212, "height": 30},
{"name": "later separate row cannot resize first track", "color": "#c2255c", "x": 14, "y": 134, "width": 50, "height": 30},
- {"name": "later separate row preserves remaining track", "color": "#fab005", "x": 74, "y": 134, "width": 212, "height": 30}
+ {"name": "later separate row preserves remaining track", "color": "#fab005", "x": 74, "y": 134, "width": 212, "height": 30},
+ {"name": "content-box table keeps spacing inside declared width", "color": "#5f3dc4", "x": 14, "y": 212, "width": 50, "height": 30},
+ {"name": "content-box remaining track excludes borders and spacing", "color": "#66a80f", "x": 74, "y": 212, "width": 220, "height": 30}
],
"table-row-geometry": [
{"name": "cell height remains a minimum below block content", "color": "#1971c2", "x": 0, "y": 0, "width": 40, "height": 30},
diff --git a/render-repros/fixed-table-layout.html b/render-repros/fixed-table-layout.html
index a447252b..983f8989 100644
--- a/render-repros/fixed-table-layout.html
+++ b/render-repros/fixed-table-layout.html
@@ -6,6 +6,7 @@
td { height: 30px; padding: 0; border: 0 }
.collapsed { border-collapse: collapse }
.separate { margin-top: 40px; border: 4px solid #212529; border-spacing: 10px 0 }
+ .content-box { box-sizing: content-box }
.first { width: 50px }
.long { color: transparent; white-space: nowrap }
</style>
@@ -17,3 +18,6 @@
<tr><td class="first" style="background:#862e9c"></td><td style="background:#15aabf"></td></tr>
<tr><td class="long" style="background:#c2255c">XXXXXXXXXXXXXXXXXXXXXXXX</td><td style="background:#fab005"></td></tr>
</table>
+<table class="separate content-box">
+ <tr><td class="first" style="background:#5f3dc4"></td><td style="background:#66a80f"></td></tr>
+</table>