Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust
Rust ai-agentsai-toolsbrowserbrowser-automationcloud-browserheadlessheadless-browserkitesurfplaywrightpuppeteerrustservoweb-crawlerweb-crawlingweb-scraperweb-scraping
fix(layout): ignore ratios on internal table boxes
ldm0be6393b694ec
diff --git a/moli-layout/src/world.rs b/moli-layout/src/world.rsindex fef4eadc2..24a37f24a 100644--- a/moli-layout/src/world.rs+++ b/moli-layout/src/world.rs@@ -77,6 +77,28 @@ impl LayoutBoxKind {matches!(self, Self::Text)}+ /// Whether this box is one of CSS Display's internal table boxes.+ ///+ /// A table wrapper and its caption are deliberately excluded. Properties+ /// such as `aspect-ratio` apply to those boxes, but not to row groups,+ /// rows, columns, or cells. Anonymous repair boxes obey the same used-value+ /// boundary as their source-backed counterparts.+ pub(crate) const fn is_internal_table_box(self) -> bool {+ matches!(+ self,+ Self::TableRowGroup+ | Self::TableHeaderGroup+ | Self::TableFooterGroup+ | Self::TableColumnGroup+ | Self::TableColumn+ | Self::TableRow+ | Self::TableCell+ | Self::AnonymousTableRowGroup+ | Self::AnonymousTableRow+ | Self::AnonymousTableCell+ )+ }+pub(crate) const fn debug_name(self) -> &'static str {match self {Self::PrincipalBlock => "principal-block",@@ -553,6 +575,9 @@ impl<N> LayoutBox<N> {/// Resolve the used ratio at the layout-node boundary, after both authored/// style and natural replaced-element sizing are available.pub(crate) fn resolved_aspect_ratio(&self) -> Option<taffy::ResolvedAspectRatio> {+ if self.kind.is_internal_table_box() {+ return None;+ }let natural_ratio = self.replaced_context.and_then(|context| context.inherent_ratio());@@ -1061,9 +1086,18 @@ whereelement_semantics: Option<LayoutElementSemantics>,anonymous_reason: Option<LayoutAnonymousReason>,kind: LayoutBoxKind,- style: ResolvedLayoutStyle,+ mut style: ResolvedLayoutStyle,text: Option<Arc<str>>,) -> LayoutBox<N> {+ if kind.is_internal_table_box() {+ // Keep the authored/computed value in `preferred_aspect_ratio`.+ // Only the numeric backend projection is suppressed: CSS Sizing+ // excludes internal table boxes from `aspect-ratio`, and the table+ // formatter supplies their used track and cell sizes. Chromium+ // represents the same boundary with its table-cell constraint+ // space before generic block-size resolution.+ style.taffy.aspect_ratio = None;+ }let capability_diagnostics =default_capability_diagnostics(kind, element_semantics.as_ref(), &style);LayoutBox {diff --git a/moli-renderer-v8/src/runtime/page_vm/tests/preferred_aspect_ratio.rs b/moli-renderer-v8/src/runtime/page_vm/tests/preferred_aspect_ratio.rsindex f4b2098b6..b28a20690 100644--- a/moli-renderer-v8/src/runtime/page_vm/tests/preferred_aspect_ratio.rs+++ b/moli-renderer-v8/src/runtime/page_vm/tests/preferred_aspect_ratio.rs@@ -89,3 +89,68 @@ document.body.innerHTML = `.await.expect("preferred aspect-ratio fixture should run");}++/// Regression for WPT css/css-sizing/aspect-ratio/table-element-001.html.+#[tokio::test(flavor = "current_thread")]+async fn screenshot_keeps_preferred_ratios_out_of_internal_table_box_sizing() {+ run_page_vm_async_test(async move {+ let loader =+ crate::network::ResourceRequestClient::new(&FetchConfig::default()).expect("loader");+ let mut page_vm = test_page_vm_with_loader_and_document_url(+ &loader,+ Vec::new(),+ Url::parse("https://example.com/internal-table-box-aspect-ratio.html")?,+ );+ page_vm.vm_mut().eval(+ r#"+document.head.innerHTML = `<style>+html,body{margin:0;background:white}+table{border-collapse:collapse}+th,td{padding:0}+</style>`;+document.body.innerHTML = `+<table id=internal>+ <tr id=row>+ <th id=cell style="background:green;width:100px;aspect-ratio:1/1"></th>+ <td id=empty-a style="background:red;height:50px;aspect-ratio:4/1"></td>+ <td id=empty-b style="background:red;height:50px;min-width:min-content;aspect-ratio:4/1"></td>+ </tr>+</table>+<table id=wrapper style="background:green;width:100px;aspect-ratio:2/1"></table>`;+'installed'+"#,+ )?;+ page_vm.vm_mut().sync_live_document_style_sources();+ let snapshot = page_vm+ .vm_mut()+ .screenshot_layout_snapshot(moli_layout::PaintViewport::new(220, 120, 1.0))?+ .expect("internal-table-box aspect-ratio fixture must retain a layout root");++ let geometry = page_vm.vm_mut().eval(+ r#"JSON.stringify(Object.fromEntries(['internal','row','cell','empty-a','empty-b','wrapper'].map(id=>{const element=document.getElementById(id);const rect=element.getBoundingClientRect();return [id,{rect:[rect.x,rect.y,rect.width,rect.height],ratio:getComputedStyle(element).aspectRatio}]})))"#,+ )?;+ assert_eq!(+ serde_json::from_str::<serde_json::Value>(&geometry)?,+ serde_json::json!({+ "internal": {"rect": [0, 0, 100, 50], "ratio": "auto"},+ "row": {"rect": [0, 0, 100, 50], "ratio": "auto"},+ "cell": {"rect": [0, 0, 100, 50], "ratio": "1 / 1"},+ "empty-a": {"rect": [100, 0, 0, 50], "ratio": "4 / 1"},+ "empty-b": {"rect": [100, 0, 0, 50], "ratio": "4 / 1"},+ "wrapper": {"rect": [0, 50, 100, 50], "ratio": "2 / 1"},+ }),+ "internal table boxes must retain computed ratios without consuming them as used sizes, while the table wrapper still consumes its ratio",+ );++ let raster = moli_paint::raster_snapshot(&snapshot)?;+ let pixel = |x: u32, y: u32| -> [u8; 4] {+ let offset = ((y * raster.width + x) * 4) as usize;+ raster.rgba[offset..offset + 4].try_into().unwrap()+ };+ assert_eq!(pixel(99, 99), [0, 128, 0, 255]);+ assert_eq!(pixel(100, 99), [255, 255, 255, 255]);+ Ok::<_, anyhow::Error>(())+ })+ .await+ .expect("internal-table-box aspect-ratio fixture should run");+}