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 parent strut participation in inline layout
ldm08e1447161ef9
diff --git a/moli-layout/src/inline.rs b/moli-layout/src/inline.rsindex 5fd3c179c..be704e990 100644--- a/moli-layout/src/inline.rs+++ b/moli-layout/src/inline.rs@@ -572,7 +572,11 @@ pub(crate) fn build_inline_line_placements(uses_internal_atomic_baseline: false,intrinsic_baseline_adjustment: 0.0,vertical_align: glyph_run.style().brush.vertical_align,- contributes_to_line: paint,+ // Parley may expose an empty root-style run next to+ // float/out-of-flow placeholders. It carries the font+ // style but no glyph geometry and is not in-flow line+ // content by itself.+ contributes_to_line: paint && style_index.is_some(),alignment_parent_strut: None,glyph_key: if paint {style_index.map(|index| (run.index(), index))@@ -611,26 +615,18 @@ pub(crate) fn build_inline_line_placements(}}).collect::<Vec<_>>();- let has_shifted_baseline_content = geometries.iter().any(|geometry| {- geometry.contributes_to_line- && geometry.vertical_align.kind == LayoutInlineAlignment::Baseline- && geometry.vertical_align.baseline_shift != 0.0- });- let has_baseline_atomic_content = geometries.iter().any(|geometry| {- geometry.contributes_to_line- && geometry.glyph_key.is_none()- && geometry.vertical_align.kind == LayoutInlineAlignment::Baseline- });- let uses_parent_strut = context.parent_strut.is_some()+ // Every CSS line starts with the IFC owner's zero-width font strut.+ // Reconstruct it explicitly whenever this sidecar owns in-flow+ // vertical geometry. Float and out-of-flow placeholders do not create+ // a normal-flow line contribution and retain Parley's raw position.+ let reconstructs_parent_strut = context.parent_strut.is_some()&& geometries.iter().any(|geometry| {- geometry.vertical_align.kind != LayoutInlineAlignment::Baseline- || (geometry.glyph_key.is_some()- && !has_shifted_baseline_content- && !has_baseline_atomic_content)+ geometry.contributes_to_line+ || geometry.vertical_align.kind != LayoutInlineAlignment::Baseline});let root_parent_x_height = context.parent_strut- .filter(|_| uses_parent_strut)+ .filter(|_| reconstructs_parent_strut).map(|strut| strut.x_height).or_else(|| {line.items().find_map(|item| match item {@@ -673,7 +669,8 @@ pub(crate) fn build_inline_line_placements(&& geometry.vertical_align.kind == LayoutInlineAlignment::Baseline&& geometry.vertical_align.baseline_shift == 0.0});- let reconstructs_parent_baseline = consumes_internal_atomic_baseline || uses_parent_strut;+ let reconstructs_parent_baseline =+ consumes_internal_atomic_baseline || reconstructs_parent_strut;let baseline_ascent = reconstructs_parent_baseline.then(|| {geometries@@ -687,7 +684,7 @@ pub(crate) fn build_inline_line_placements(.fold(context.parent_strut- .filter(|_| uses_parent_strut)+ .filter(|_| reconstructs_parent_strut).map(|strut| strut.line_ascent),|maximum, ascent| {Some(maximum.map_or(ascent, |maximum| maximum.max(ascent)))@@ -714,7 +711,7 @@ pub(crate) fn build_inline_line_placements(let parent_baseline = parley_parent_baseline + parent_baseline_adjustment;let (parent_text_top, parent_text_bottom) = context.parent_strut- .filter(|_| uses_parent_strut)+ .filter(|_| reconstructs_parent_strut).map(|strut| {(parent_baseline - strut.text_ascent,@@ -736,15 +733,15 @@ pub(crate) fn build_inline_line_placements(// First position baseline-, text-edge-, and middle-aligned content.// Top/bottom depend on the resulting aligned subtree and are resolved// in the second pass, matching the ordering used by browser IFCs.- let (mut min_y, mut max_y) = context.parent_strut.filter(|_| uses_parent_strut).map_or(- (raw_top, raw_bottom),- |strut| {+ let (mut min_y, mut max_y) = context+ .parent_strut+ .filter(|_| reconstructs_parent_strut)+ .map_or((raw_top, raw_bottom), |strut| {(parent_baseline - strut.line_ascent,parent_baseline + strut.line_descent,)- },- );+ });let mut item_offsets = base_offsets;for (item_index, geometry) in geometries.iter().enumerate() {if matches!(diff --git a/moli-layout/src/stylo_to_parley.rs b/moli-layout/src/stylo_to_parley.rsindex d6d281c2f..589482f94 100644--- a/moli-layout/src/stylo_to_parley.rs+++ b/moli-layout/src/stylo_to_parley.rs@@ -95,7 +95,7 @@ pub(crate) fn text_style(let inherited_text = computed.get_inherited_text();let font_size = font.font_size.used_size.0.px();let line_height = match font.line_height {- style::values::computed::font::LineHeight::Normal => LineHeight::FontSizeRelative(1.2),+ style::values::computed::font::LineHeight::Normal => LineHeight::MetricsRelative(1.0),style::values::computed::font::LineHeight::Number(number) => {LineHeight::FontSizeRelative(number.0)}diff --git a/moli-layout/tests/box_builder_contract.rs b/moli-layout/tests/box_builder_contract.rsindex a59e1d340..a1f07009d 100644--- a/moli-layout/tests/box_builder_contract.rs+++ b/moli-layout/tests/box_builder_contract.rs@@ -2048,6 +2048,9 @@ fn nested_inline_baseline_shift_expands_the_line_once_for_text_and_atomic_contenStyle::default(),PaintColor::new(0.0, 1.0, 0.0, 1.0),)+ // Synthetic styles do not run CSS inheritance; mirror the+ // structural inline's inherited parent font metrics explicitly.+ .with_text_metrics(20.0, 20.0).with_inline_baseline_shift(baseline_shift),);styles.primary.insert(@@ -2100,9 +2103,80 @@ fn nested_inline_baseline_shift_expands_the_line_once_for_text_and_atomic_contenlet baseline_after = solid_rect(&baseline, red);let raised_after = solid_rect(&raised, red);- assert!((raised_atomic.y - baseline_atomic.y).abs() < 0.01);+ assert!(+ (raised_atomic.y - baseline_atomic.y).abs() < 0.01,+ "baseline={baseline_atomic:?}, raised={raised_atomic:?}"+ );assert_eq!(raised_inline, baseline_inline);- assert!((raised_after.y - baseline_after.y - 10.0).abs() < 0.01);+ assert!(+ (raised_after.y - baseline_after.y - 10.0).abs() < 0.01,+ "baseline={baseline_after:?}, raised={raised_after:?}"+ );+}++#[test]+fn baseline_atomic_inline_keeps_the_parent_strut_descent_in_the_line_box() {+ let source = TestSource {+ root: 0,+ nodes: vec![+ TestNode::element("root", vec![1, 2]),+ TestNode::element("atomic", Vec::new()),+ TestNode::element("after", Vec::new()),+ ],+ };+ let atomic_color = PaintColor::new(0.0, 0.0, 1.0, 1.0);+ let after_color = PaintColor::new(1.0, 0.0, 0.0, 1.0);+ let mut styles = TestStyles::default();+ styles.primary.insert(+ 0,+ ResolvedLayoutStyle::synthetic(+ LayoutDisplay::Block,+ Style {+ size: Size {+ width: length(100.0),+ height: Dimension::auto(),+ },+ ..Style::default()+ },+ PaintColor::TRANSPARENT,+ )+ .with_text_metrics(14.0, 16.0),+ );+ styles.primary.insert(+ 1,+ colored_box(LayoutDisplay::InlineBlock, 48.0, 48.0, atomic_color),+ );+ styles+ .primary+ .insert(2, colored_box(LayoutDisplay::Block, 10.0, 5.0, after_color));++ let snapshot = build_screenshot_snapshot(+ &source,+ &mut styles,+ &mut DocumentLayoutServices::new(),+ ScreenshotLayoutRequest::new(PaintViewport::new(100, 100, 1.0)),+ )+ .unwrap();+ let rect_for = |color| {+ snapshot+ .fragments+ .iter()+ .find_map(|fragment| {+ fragment+ .solid_fill_in_surface()+ .filter(|(_, actual)| *actual == color)+ .map(|(rect, _)| rect)+ })+ .expect("colored fixture box")+ };+ let atomic = rect_for(atomic_color);+ let after = rect_for(after_color);++ assert!(+ after.y > atomic.y + atomic.height,+ "the parent font descent must remain below a baseline-aligned atomic inline: \+ atomic={atomic:?}, after={after:?}"+ );}#[test]diff --git a/moli-layout/tests/phase4_layout_contract.rs b/moli-layout/tests/phase4_layout_contract.rsindex 0ab8d52eb..754d9e42e 100644--- a/moli-layout/tests/phase4_layout_contract.rs+++ b/moli-layout/tests/phase4_layout_contract.rs@@ -417,9 +417,11 @@ fn float_descendant_of_structural_inline_rounds_with_its_ifc_owner() {2,sized(LayoutDisplay::Block, 60.0, 20.0, BLUE).with_float(Float::Left, Clear::None),);- styles- .primary- .insert(3, sized(LayoutDisplay::Inline, 55.0, 14.0, GREEN));+ styles.primary.insert(+ 3,+ sized(LayoutDisplay::Inline, 55.0, 14.0, GREEN)+ .with_inline_alignment(moli_layout::LayoutInlineAlignment::Top),+ );let snapshot = render(&source, &mut styles, 200, 40);let floated = rect(&snapshot, BLUE);@@ -484,9 +486,11 @@ fn block_content_alignment_moves_the_inline_float_fragment_group() {styles.primary.insert(2, sized(LayoutDisplay::Block, 10.0, 5.0, RED));- styles- .primary- .insert(3, sized(LayoutDisplay::InlineBlock, 20.0, 10.0, GREEN));+ styles.primary.insert(+ 3,+ sized(LayoutDisplay::InlineBlock, 20.0, 10.0, GREEN)+ .with_inline_alignment(moli_layout::LayoutInlineAlignment::Top),+ );let snapshot = render(&source, &mut styles, 200, 100);let floated = rect(&snapshot, BLUE);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 f211a5946..20af19ebb 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@@ -2385,6 +2385,60 @@ getComputedStyle(document.getElementById('inline-gradient')).getPropertyValue('-.expect("background-clip:text screenshot fixture should run");}+#[tokio::test(flavor = "current_thread")]+async fn baseline_atomic_inline_keeps_parent_font_descent_in_flex_header() {+ 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/baseline-atomic-strut.html")?,+ );+ page_vm.vm_mut().eval(+ r#"+document.head.innerHTML = `<style>+html,body{margin:0}+#bar{display:flex;align-items:center;box-sizing:border-box;width:200px;height:60px;padding:6px}+#header{display:flex;align-items:center}+#wrapper{display:block;font:14px/normal Arial,sans-serif}+#atomic{display:inline-block;width:48px;height:48px;background:blue}+</style>`;+document.body.innerHTML = `<div id=bar><header id=header><div id=wrapper><span id=atomic></span></div></header></div>`;+'installed'+"#,+ )?;+ page_vm+ .vm_mut()+ .prime_document_lifecycle_processing_and_record_stylesheet_network_results();++ let geometry = page_vm.vm_mut().eval(+ r#"JSON.stringify(Object.fromEntries(['bar','header','wrapper','atomic'].map(id=>{const r=document.getElementById(id).getBoundingClientRect();return [id,[r.x,r.y,r.width,r.height]]})))"#,+ )?;+ let geometry: serde_json::Value = serde_json::from_str(&geometry)?;+ for (id, expected) in [+ ("bar", [0.0, 0.0, 200.0, 60.0]),+ ("header", [6.0, 5.0, 48.0, 51.0]),+ ("wrapper", [6.0, 5.0, 48.0, 51.0]),+ ("atomic", [6.0, 5.0, 48.0, 48.0]),+ ] {+ let actual = geometry[id]+ .as_array()+ .unwrap_or_else(|| panic!("missing geometry for {id}: {geometry}"));+ for (index, expected) in expected.into_iter().enumerate() {+ let actual = actual[index].as_f64().expect("numeric geometry") as f32;+ assert!(+ (actual - expected).abs() <= 0.05,+ "{id}[{index}]: expected {expected}, got {actual}; geometry={geometry}"+ );+ }+ }+ Ok::<_, anyhow::Error>(())+ })+ .await+ .expect("baseline atomic strut fixture should run");+}+#[tokio::test(flavor = "current_thread")]async fn rounded_flex_max_content_width_does_not_rewrap_its_text() {run_page_vm_async_test(async move {