Skip to content

armgit / moli

Public Imported from GitHub
0

Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust

Ignore table-part decorations in used geometry

ldm07391608b7bea
diff --git a/moli-layout/src/table.rs b/moli-layout/src/table.rs
index 899c6a7ee..02939f7b5 100644
--- a/moli-layout/src/table.rs
+++ b/moli-layout/src/table.rs
@@ -803,15 +803,7 @@ fn apply_structural_layout<N>(
for row in &context.rows {
let y = row_starts.get(row.index).copied().unwrap_or(origin.y);
let height = detailed.rows.sizes.get(row.index).copied().unwrap_or(0.0);
- set_structural_rect(
- world,
- row.id,
- origin.x,
- y,
- content_width,
- height,
- grid_size.width,
- );
+ set_table_part_layout(world, row.id, origin.x, y, content_width, height);
}
let mut groups = context
.rows
@@ -832,15 +824,7 @@ fn apply_structural_layout<N>(
let y = row_starts.get(start).copied().unwrap_or(origin.y);
let height =
track_range_extent(&detailed.rows.sizes, &detailed.rows.gutters, start, end);
- set_structural_rect(
- world,
- group,
- origin.x,
- y,
- content_width,
- height,
- grid_size.width,
- );
+ set_table_part_layout(world, group, origin.x, y, content_width, height);
}
}
for column in &context.columns {
@@ -851,15 +835,7 @@ fn apply_structural_layout<N>(
column.start,
column.start.saturating_add(column.span),
);
- set_structural_rect(
- world,
- column.id,
- x,
- origin.y,
- width,
- content_height,
- grid_size.width,
- );
+ set_table_part_layout(world, column.id, x, origin.y, width, content_height);
}
let mut column_groups = context
.columns
@@ -887,15 +863,7 @@ fn apply_structural_layout<N>(
start,
end,
);
- set_structural_rect(
- world,
- group,
- x,
- origin.y,
- width,
- content_height,
- grid_size.width,
- );
+ set_table_part_layout(world, group, x, origin.y, width, content_height);
}
}
@@ -930,32 +898,29 @@ fn track_range_extent(sizes: &[f32], gutters: &[f32], start: usize, end: usize)
.sum::<f32>()
}
-fn set_structural_rect<N>(
+fn set_table_part_layout<N>(
world: &mut LayoutWorld<N>,
id: LayoutBoxId,
x: f32,
y: f32,
width: f32,
height: f32,
- parent_width: f32,
) where
N: Copy + Debug + Eq + Hash,
{
- let style = &world.boxes[id.index()].style.taffy;
- let padding = style
- .padding
- .resolve_or_zero(Some(parent_width), resolve_stylo_calc_value);
- let border = style
- .border
- .resolve_or_zero(Some(parent_width), resolve_stylo_calc_value);
+ // Internal table parts expose the grid's structural geometry, not an
+ // ordinary CSS box model. Their margin and padding are ignored. Borders
+ // are ignored in the separated model and represented by the table-owned
+ // conflict grid in the collapsed model; keep the authored style intact
+ // while publishing zero used decoration edges to generic paint.
world.boxes[id.index()].unrounded_layout = Layout {
order: 0,
location: Point { x, y },
size: Size { width, height },
content_size: Size { width, height },
scrollbar_size: Size::ZERO,
- border,
- padding,
+ border: Rect::ZERO,
+ padding: Rect::ZERO,
margin: Rect::ZERO,
};
}
diff --git a/moli-layout/src/table/collapsed_borders.rs b/moli-layout/src/table/collapsed_borders.rs
index 23365a78e..744176d2e 100644
--- a/moli-layout/src/table/collapsed_borders.rs
+++ b/moli-layout/src/table/collapsed_borders.rs
@@ -466,7 +466,6 @@ where
.chain(context.columns.iter().map(|column| column.id))
.chain(context.columns.iter().filter_map(|column| column.group))
{
- set_layout_border(world, part, PaintEdgeSizes::default());
world.boxes[part.index()].collapsed_table_border_part = true;
}
world.boxes[root.index()].collapsed_table_borders = Some(borders);
diff --git a/moli-layout/tests/phase4_layout_contract.rs b/moli-layout/tests/phase4_layout_contract.rs
index 2e8288ebf..1d28ef865 100644
--- a/moli-layout/tests/phase4_layout_contract.rs
+++ b/moli-layout/tests/phase4_layout_contract.rs
@@ -316,6 +316,81 @@ fn table_caption_tracks_rows_cells_and_common_spans_share_one_wrapper_geometry()
assert_close(span.width, 300.0);
}
+#[test]
+fn separated_table_parts_ignore_authored_border_padding_and_margin() {
+ use LayoutElementCategory::Table;
+ use LayoutTableRole::{BodyGroup, Cell, Row, Table as Root};
+
+ let source = Source(vec![
+ Node::element("root", "div", LayoutElementCategory::Generic, None, vec![1]),
+ Node::element("table", "table", Table(Root), None, vec![2]),
+ Node::element("body", "tbody", Table(BodyGroup), None, vec![3]),
+ Node::element("row", "tr", Table(Row), None, vec![4]),
+ Node::element("cell", "td", Table(Cell), None, Vec::new()).with_metadata(
+ LayoutElementMetadata {
+ table: Some(LayoutTableData::default()),
+ ..LayoutElementMetadata::default()
+ },
+ ),
+ ]);
+ let table = PaintColor::new(0.11, 0.12, 0.13, 1.0);
+ let group = PaintColor::new(0.21, 0.22, 0.23, 1.0);
+ let row = PaintColor::new(0.31, 0.32, 0.33, 1.0);
+ let cell = PaintColor::new(0.41, 0.42, 0.43, 1.0);
+ let structural_style = |display, color| {
+ style(display, color).tap_taffy(|taffy| {
+ taffy.border = Rect {
+ left: taffy::LengthPercentage::length(20.0),
+ right: taffy::LengthPercentage::length(20.0),
+ top: taffy::LengthPercentage::length(20.0),
+ bottom: taffy::LengthPercentage::length(20.0),
+ };
+ taffy.padding = Rect {
+ left: taffy::LengthPercentage::length(12.0),
+ right: taffy::LengthPercentage::length(12.0),
+ top: taffy::LengthPercentage::length(12.0),
+ bottom: taffy::LengthPercentage::length(12.0),
+ };
+ taffy.margin = Rect {
+ left: taffy::LengthPercentageAuto::length(9.0),
+ right: taffy::LengthPercentageAuto::length(9.0),
+ top: taffy::LengthPercentageAuto::length(9.0),
+ bottom: taffy::LengthPercentageAuto::length(9.0),
+ };
+ })
+ };
+ let mut styles = Styles::default();
+ styles.primary.insert(
+ 0,
+ sized(LayoutDisplay::Block, 200.0, 100.0, PaintColor::TRANSPARENT),
+ );
+ styles
+ .primary
+ .insert(1, sized(LayoutDisplay::Table, 50.0, 20.0, table));
+ styles
+ .primary
+ .insert(2, structural_style(LayoutDisplay::TableRowGroup, group));
+ styles
+ .primary
+ .insert(3, structural_style(LayoutDisplay::TableRow, row));
+ styles
+ .primary
+ .insert(4, sized(LayoutDisplay::TableCell, 50.0, 20.0, cell));
+
+ let snapshot = render(&source, &mut styles, 200, 100);
+ for color in [table, group, row, cell] {
+ assert_eq!(rect(&snapshot, color), PaintRect::new(0.0, 0.0, 50.0, 20.0));
+ }
+ assert!(
+ snapshot
+ .fragments
+ .iter()
+ .all(|fragment| !matches!(fragment, PaintFragment::Border { .. })),
+ "table structural borders must not reach generic paint: {:?}",
+ snapshot.fragments
+ );
+}
+
#[test]
fn table_sections_use_visual_header_body_footer_order() {
use LayoutElementCategory::Table;
diff --git a/moli-renderer-v8/src/runtime/phase_one/mod.rs b/moli-renderer-v8/src/runtime/phase_one/mod.rs
index e57c5f83c..4a4b408fb 100644
--- a/moli-renderer-v8/src/runtime/phase_one/mod.rs
+++ b/moli-renderer-v8/src/runtime/phase_one/mod.rs
@@ -1428,6 +1428,53 @@ td{width:10px;height:10px;padding:0;border:0;font-size:0}
}));
}
+ #[test]
+ fn layout_renderer_ignores_separated_table_part_border_padding_and_margin() {
+ let runtime = tokio::runtime::Builder::new_current_thread()
+ .enable_all()
+ .build()
+ .expect("current-thread runtime should build");
+
+ runtime.block_on(tokio::task::LocalSet::new().run_until(async move {
+ let snapshot = render_test_snapshot(
+ r#"<!doctype html><html><head><style>
+html,body{margin:0;padding:0}
+table{border-spacing:0;background:rgb(81,41,141)}
+colgroup{border:20px solid rgb(203,13,23);padding:12px;margin:9px}
+col{border:20px solid rgb(204,14,24);padding:12px;margin:9px}
+tbody{border:20px solid rgb(201,11,21);padding:12px;margin:9px;background:rgb(82,42,142)}
+tr{border:20px solid rgb(202,12,22);padding:12px;margin:9px;background:rgb(83,43,143)}
+td{box-sizing:border-box;width:50px;height:20px;padding:0;background:rgb(84,44,144)}
+</style></head><body><table><colgroup><col></colgroup><tbody><tr><td></td></tr></tbody></table></body></html>"#,
+ )
+ .await;
+
+ assert_paint_rect(
+ solid_paint_rect(&snapshot, rgb(84, 44, 144)),
+ moli_layout::PaintRect::new(0.0, 0.0, 50.0, 20.0),
+ );
+ for ignored in [
+ rgb(201, 11, 21),
+ rgb(202, 12, 22),
+ rgb(203, 13, 23),
+ rgb(204, 14, 24),
+ ] {
+ assert!(
+ snapshot.fragments.iter().all(|fragment| !matches!(
+ fragment,
+ moli_layout::PaintFragment::Border { colors, .. }
+ if colors.top == ignored
+ || colors.right == ignored
+ || colors.bottom == ignored
+ || colors.left == ignored
+ )),
+ "separated table-part border reached paint: {ignored:?}; fragments={:?}",
+ snapshot.fragments
+ );
+ }
+ }));
+ }
+
#[test]
fn layout_renderer_computes_phase_four_special_formatting_geometry_from_native_dom_and_stylo() {
let runtime = tokio::runtime::Builder::new_current_thread()