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(style): extend table dimension presentation hints
ldm0b73d663a4659
diff --git a/moli-renderer-v8/src/runtime/page_vm/tests/rendering_update.rs b/moli-renderer-v8/src/runtime/page_vm/tests/rendering_update.rsindex 5dac9456c..584c56581 100644--- a/moli-renderer-v8/src/runtime/page_vm/tests/rendering_update.rs+++ b/moli-renderer-v8/src/runtime/page_vm/tests/rendering_update.rs@@ -2818,6 +2818,50 @@ async fn screenshot_preserves_table_cell_dimension_hints_and_avatar_columns() {.expect("table-cell dimension hints should preserve avatar alignment");}+#[tokio::test(flavor = "current_thread")]+async fn screenshot_recascades_table_part_dimension_hints() {+ run_page_vm_async_test(async move {+ let loader = crate::network::ResourceRequestClient::new(&FetchConfig::default())?;+ let mut page = test_page_vm_with_loader_and_document_url(+ &loader,+ Vec::new(),+ Url::parse("https://example.com/table-part-dimensions.html")?,+ );+ page.vm_mut()+ .set_layout_policy(moli_page_types::LayoutPolicy::OnDemand);+ let fixture = include_str!("../../../../tests/fixtures/table-part-dimensions.html");+ page.vm_mut().eval(&format!(+ "document.open();document.write({});document.close()",+ serde_json::to_string(fixture)?,+ ))?;+ page.vm_mut()+ .prime_document_lifecycle_processing_and_record_stylesheet_network_results();++ for phase in 0..4 {+ page.vm_mut()+ .eval(&format!("setTablePartDimensionPhase({phase})"))?;+ page.vm_mut()+ .screenshot_layout_snapshot(moli_layout::PaintViewport::new(800, 600, 1.0))?+ .expect("table-part dimension fixture must retain a layout root");+ let checks: serde_json::Value = serde_json::from_str(+ &page+ .vm_mut()+ .eval("JSON.stringify(collectTablePartDimensionChecks())")?,+ )?;+ let checks = checks.as_array().expect("table-part dimension checks");+ assert_eq!(checks.len(), 71);+ let failures: Vec<_> = checks+ .iter()+ .filter(|check| check["actual"] != check["expected"])+ .collect();+ assert!(failures.is_empty(), "phase {phase}: {failures:#?}");+ }+ Ok::<_, anyhow::Error>(())+ })+ .await+ .expect("table-part dimensions should recascade and resize tables");+}+#[tokio::test(flavor = "current_thread")]async fn screenshot_recascades_nearest_table_cell_presentation_style() {run_page_vm_async_test(async move {diff --git a/moli-renderer-v8/tests/fixtures/table-part-dimensions.html b/moli-renderer-v8/tests/fixtures/table-part-dimensions.htmlnew file mode 100644index 000000000..0288c465e--- /dev/null+++ b/moli-renderer-v8/tests/fixtures/table-part-dimensions.html@@ -0,0 +1,144 @@+<!doctype html>+<meta charset="utf-8">+<style>+ html, body { margin: 0; padding: 0; font: 0/0 sans-serif; }+ table { border-spacing: 0; }+ td { padding: 0; }+ .dimension-owner { position: absolute; width: 200px; height: 120px; }+ .dimension { display: block; padding: 0; border: 0; margin: 0; }+ .author-dimension { width: 80px; height: 40px; }+</style>+<body>+<script>+ // All four phases were checked against Chrome/147.0.7709.0.+ // Block display isolates the hint's cascade/zero semantics from table layout's+ // minimum content sizes. The native tables below test the resulting geometry.+ // Blink's HTMLTableColElement also inherits height from HTMLTablePartElement.+ const dimensions = [+ {tag:'table', fixed:[48,32], percentage:[50,60], zero:[200,0], mutated:[96,64]},+ {tag:'col', fixed:[48,32], percentage:[50,60], zero:[0,0], mutated:[96,64]},+ {tag:'colgroup', fixed:[48,32], percentage:[50,60], zero:[0,0], mutated:[96,64]},+ {tag:'thead', fixed:[200,32], percentage:[200,60], zero:[200,0], mutated:[200,64]},+ {tag:'tbody', fixed:[200,32], percentage:[200,60], zero:[200,0], mutated:[200,64]},+ {tag:'tfoot', fixed:[200,32], percentage:[200,60], zero:[200,0], mutated:[200,64]},+ {tag:'tr', fixed:[200,32], percentage:[200,60], zero:[200,0], mutated:[200,64]},+ ];+ const cases = [+ {id:'fixed', width:'48', height:'32'},+ {id:'percentage', width:'25%', height:'50%'},+ {id:'zero', width:'0', height:'0'},+ {id:'zero-percent', width:'0%', height:'0%'},+ {id:'missing'},+ {id:'relative', width:'10*', height:'10*'},+ {id:'namespaced', width:'48', height:'32', namespace:'urn:dimension-test'},+ {id:'author', width:'48', height:'32', className:'author-dimension'},+ {id:'inline-auto', width:'48', height:'32', style:'width:auto;height:auto'},+ ];+ const checks = [];+ const mutations = [];+ const cssHeightReferences = [];+ for (const dimension of dimensions) {+ for (const test of cases) {+ const owner = document.createElement('div');+ owner.className = 'dimension-owner';+ const element = document.createElement(dimension.tag);+ element.className = `dimension ${test.className || ''}`;+ element.style.cssText = test.style || '';+ for (const name of ['width','height']) {+ if (test[name] !== undefined) element.setAttributeNS(test.namespace || null, name, test[name]);+ }+ const content = document.createElement('div');+ content.style.cssText = 'width:10px;height:8px';+ element.append(content);+ owner.append(element);+ document.body.append(owner);+ const expected = test.id === 'author' ? [80,40]+ : (dimension[test.id === 'zero-percent' ? 'zero' : test.id] || [200,8]);+ checks.push({id:`${dimension.tag}-${test.id}`, element,+ expected: test.id === 'fixed'+ ? [expected, dimension.mutated, [200,8], dimension.zero]+ : [expected, expected, expected, expected]});+ if (test.id === 'fixed' || test.id === 'author') {+ mutations.push({element, names:['width','height']});+ }+ }+ }++ // Table/row heights size real rows; zero preserves the content minimum.+ // Moli's table formatter currently ignores CSS row-group heights too, so+ // compare those native groups with authored CSS. The block cases above+ // independently verify the hint values, including percentages and zero.+ for (const tag of ['table','thead','tbody','tfoot','tr']) {+ const table = document.createElement('table');+ table.style.width = '200px';+ const section = document.createElement(['thead','tbody','tfoot'].includes(tag) ? tag : 'tbody');+ const row = document.createElement('tr');+ row.innerHTML = '<td><div style="width:10px;height:8px"></div></td>';+ section.append(row);+ table.append(section);+ const element = tag === 'table' ? table : tag === 'tr' ? row : section;+ element.setAttribute('height','32');+ document.body.append(table);+ const check = {id:`native-${tag}`, element:row,+ expected:[[200,32],[200,64],[200,8],[200,8]]};+ if (element === section) {+ const reference = table.cloneNode(true);+ const referenceGroup = reference.querySelector(tag);+ referenceGroup.removeAttribute('height');+ referenceGroup.style.height = '32px';+ document.body.append(reference);+ check.reference = reference.rows[0];+ cssHeightReferences.push(referenceGroup);+ }+ checks.push(check);+ mutations.push({element, names:['height']});+ }++ // Exercise spanning col/colgroup boxes and a group with explicit columns.+ // In fixed layout, the latter's width does not override its children's widths.+ // Removing the hint redistributes space; width=0 retains a zero-width column.+ for (const variant of ['col','colgroup','colgroup-children']) {+ const table = document.createElement('table');+ table.style.cssText = 'width:240px;table-layout:fixed';+ table.innerHTML = variant === 'col'+ ? '<colgroup><col span="2" width="48"><col></colgroup>'+ : variant === 'colgroup'+ ? '<colgroup span="2" width="48"></colgroup><colgroup><col></colgroup>'+ : '<colgroup width="48"><col><col></colgroup><colgroup><col></colgroup>';+ const element = table.querySelector(variant === 'col' ? 'col' : 'colgroup');+ const body = document.createElement('tbody');+ body.innerHTML = '<tr style="height:8px"><td></td><td></td><td></td></tr>';+ table.append(body);+ document.body.append(table);+ checks.push({id:`native-${variant}`, cells:Array.from(table.rows[0].cells),+ expected:variant === 'colgroup-children'+ ? [[80,80,80],[80,80,80],[80,80,80],[80,80,80]]+ : [[48,48,144],[96,96,48],[80,80,80],[0,0,240]]});+ mutations.push({element, names:['width']});+ }++ let dimensionPhase = 0;+ function setTablePartDimensionPhase(phase) {+ dimensionPhase = phase;+ for (const {element, names} of mutations) {+ for (const name of names) {+ if (phase === 1) element.setAttribute(name, name === 'width' ? '96' : '64');+ else if (phase === 2) element.removeAttribute(name);+ else if (phase === 3) element.setAttribute(name, '0');+ }+ }+ for (const element of cssHeightReferences) {+ element.style.height = ['32px','64px','auto','0px'][phase];+ }+ }+ function collectTablePartDimensionChecks() {+ return checks.map(check => {+ const rect = check.element && check.element.getBoundingClientRect();+ const reference = check.reference && check.reference.getBoundingClientRect();+ return {id:check.id,+ actual:check.cells ? check.cells.map(cell => cell.getBoundingClientRect().width)+ : [rect.width,rect.height],+ expected:reference ? [reference.width,reference.height] : check.expected[dimensionPhase]};+ });+ }+</script>diff --git a/moli-selector/src/stylo/presentation.rs b/moli-selector/src/stylo/presentation.rsindex 7497e4bea..6c31c571c 100644--- a/moli-selector/src/stylo/presentation.rs+++ b/moli-selector/src/stylo/presentation.rs@@ -179,13 +179,16 @@ fn append_html_table_presentation_declarations() {let native = element.element();let local_name = native.local_name();- // Table-cell dimensions are presentation hints, just like table width.+ let is_cell = matches!(local_name, "td" | "th");+ let is_column = matches!(local_name, "col" | "colgroup");+ // Table dimensions are presentation hints, including column-group widths.// Keep them in the cascade so author CSS can override them and the table// algorithm receives the same constraints as an authored CSS length.- if matches!(local_name, "table" | "td" | "th")+ // Table/cell widths ignore zero; column widths preserve it.+ if (local_name == "table" || is_cell || is_column)&& let Some(width) = native.attribute_ns("", "width")- .and_then(|value| parse_html_dimension(value, true, false))+ .and_then(|value| parse_html_dimension(value, true, is_column)){use style::values::generics::length::Size;block.push(@@ -194,6 +197,20 @@ fn append_html_table_presentation_declarations();}+ // Only cell heights ignore zero. Blink also maps height on col/colgroup+ // through HTMLTablePartElement, observable when their display is changed.+ if (matches!(local_name, "table" | "thead" | "tbody" | "tfoot" | "tr") || is_cell || is_column)+ && let Some(height) = native+ .attribute_ns("", "height")+ .and_then(|value| parse_html_dimension(value, true, !is_cell))+ {+ use style::values::generics::length::Size;+ block.push(+ PropertyDeclaration::Height(Size::LengthPercentage(NonNegative(height))),+ Importance::Normal,+ );+ }+if local_name == "table" {if let Some(spacing) = native.attribute("cellspacing")@@ -232,17 +249,7 @@ fn append_html_table_presentation_declarations(append_html_table_part_alignment_declarations(element, block);}- if matches!(local_name, "td" | "th") {- if let Some(height) = native- .attribute_ns("", "height")- .and_then(|value| parse_html_dimension(value, true, false))- {- use style::values::generics::length::Size;- block.push(- PropertyDeclaration::Height(Size::LengthPercentage(NonNegative(height))),- Importance::Normal,- );- }+ if is_cell {append_html_table_cell_padding_declarations(element, block);}}