Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust
Rust ai-agentsai-toolsbrowserbrowser-automationcloud-browserheadlessheadless-browserkitesurfplaywrightpuppeteerrustservoweb-crawlerweb-crawlingweb-scraperweb-scraping
Implement fixed table column allocation
ldm0d5ad7dce73fc
diff --git a/moli-layout/src/table.rs b/moli-layout/src/table.rsindex 66146ec74..d75a913fb 100644--- a/moli-layout/src/table.rs+++ b/moli-layout/src/table.rs@@ -14,17 +14,19 @@ use std::{fmt::Debug, hash::Hash};use style::Atom;use taffy::{AvailableSpace, DetailedGridInfo, Dimension, Display, GridAutoFlow, Layout,- LayoutGridContainer, LayoutInput, LayoutOutput, LayoutPartialTree, Line, NodeId, Point, Rect,- ResolveOrZero, RunMode, Size, SizingMode, SizingPurpose, Style, TraversePartialTree,- TraverseTree, compute_grid_layout, style_helpers,+ LayoutGridContainer, LayoutInput, LayoutOutput, LayoutPartialTree, Line, MaybeMath,+ MaybeResolve, NodeId, Point, Rect, ResolveOrZero, RunMode, Size, SizingMode, SizingPurpose,+ Style, TraversePartialTree, TraverseTree, compute_grid_layout, style_helpers,};use crate::{LayoutBoxId, LayoutBoxKind, LayoutWorld, style::resolve_stylo_calc_value};mod collapsed_borders;+mod columns;pub(crate) use collapsed_borders::CollapsedTableBorders;use collapsed_borders::{prepare_collapsed_table_borders, set_collapsed_border_geometry};+use columns::{TableColumnConstraint, distribute_fixed_columns, fixed_grid_min_inline_size};#[derive(Clone)]struct TableCell {@@ -61,7 +63,9 @@ struct TableContext {detailed: Option<DetailedGridInfo>,collapsed_borders: bool,column_count: usize,- fixed_track_min_width: f32,+ column_constraints: Vec<TableColumnConstraint>,+ fixed_layout: bool,+ inline_border_spacing: f32,}pub(crate) fn prepare_table_layout_trees<N>(world: &mut LayoutWorld<N>)@@ -91,6 +95,48 @@ where}world.boxes[root.index()].layout_children.extend(parts);prepare_collapsed_table_borders(world, root);+ apply_parent_facing_table_inline_constraints(world, root);+ }+}++/// Expose the table grid's minimum inline size to the parent formatting+/// context. The numeric Grid backend only sees the table after its parent has+/// resolved the child's used size, so returning an oversized LayoutOutput is+/// too late to influence that decision.+///+/// Blink performs the equivalent work through `ComputeGridInlineMinMax`+/// before `ComputeUsedInlineSizeForTableFragment`. Moli keeps the same+/// boundary explicit while adapting the table algorithm to Taffy's parent+/// sizing contract.+fn apply_parent_facing_table_inline_constraints<N>(world: &mut LayoutWorld<N>, root: LayoutBoxId)+where+ N: Copy + Debug + Eq + Hash,+{+ let context = build_table_context(world, root);+ let Some(min_border_box_size) = context.fixed_grid_min_border_box_size() else {+ return;+ };++ let style = &mut world.boxes[root.index()].style.taffy;+ let percentage_basis = None;+ let padding = style+ .padding+ .resolve_or_zero(percentage_basis, resolve_stylo_calc_value);+ let border = style+ .border+ .resolve_or_zero(percentage_basis, resolve_stylo_calc_value);+ let parent_inline_insets = padding.left + padding.right + border.left + border.right;+ let min_style_size = if style.box_sizing == taffy::BoxSizing::ContentBox {+ (min_border_box_size - parent_inline_insets).max(0.0)+ } else {+ min_border_box_size+ };++ let current = style.min_size.width;+ if current.is_auto() {+ style.min_size.width = Dimension::length(min_style_size);+ } else if current.tag() == taffy::CompactLength::LENGTH_TAG {+ style.min_size.width = Dimension::length(current.value().max(min_style_size));}}@@ -125,6 +171,7 @@ whereN: Copy + Debug + Eq + Hash,{let mut context = build_table_context(world, root);+ context.resolve_column_tracks(inputs);let mut output = {let mut wrapper = TableTreeWrapper {world,@@ -183,11 +230,6 @@ wherelet mut style = root_style.taffy.clone();style.display = Display::Grid;style.item_is_table = true;- // CSS table used width constrains the table grid border box (including- // outer border-spacing), even though ordinary `box-sizing` defaults to- // content-box. Feeding the wrapper to generic grid as content-box would- // add the two outer spacing gutters a second time.- style.box_sizing = taffy::BoxSizing::BorderBox;style.grid_auto_flow = GridAutoFlow::RowDense;style.grid_auto_columns.clear();style.grid_auto_rows.clear();@@ -212,11 +254,11 @@ where};if cell.row == 0 && cell.column_span == 1 {if cell.column >= column_tracks.len() {- column_tracks.resize(cell.column + 1, style_helpers::auto());+ column_tracks.resize(cell.column + 1, TableColumnConstraint::auto());}// An explicit <col>/<colgroup> width wins over the first-row// cell width in the fixed table algorithm.- if column_tracks[cell.column] == style_helpers::auto() {+ if column_tracks[cell.column].is_auto() {column_tracks[cell.column] =table_cell_width_track(&cell.style, root_style.table_layout_is_fixed());}@@ -232,14 +274,13 @@ where}collect_captions(world, root, &mut captions);max_columns = max_columns.max(column_tracks.len()).max(1);- column_tracks.resize(max_columns, style_helpers::auto());- let fixed_track_min_width = column_tracks+ column_tracks.resize(max_columns, TableColumnConstraint::auto());+ let fixed_layout = root_style.table_layout_is_fixed();+ style.grid_template_columns = column_tracks.iter()- .map(|track| track.min_sizing_function().into_raw())- .filter(|track| track.tag() == taffy::CompactLength::LENGTH_TAG)- .map(|track| track.value().max(0.0))- .sum();- style.grid_template_columns = column_tracks.into_iter().map(Into::into).collect();+ .copied()+ .map(|track| track.intrinsic_grid_track().into())+ .collect();style.grid_template_rows = if rows.is_empty() {vec![style_helpers::auto()]} else {@@ -269,7 +310,110 @@ wheredetailed: None,collapsed_borders: collapsed,column_count: max_columns,- fixed_track_min_width,+ column_constraints: column_tracks,+ fixed_layout,+ inline_border_spacing: spacing.width,+ }+}++impl TableContext {+ /// Resolve table column semantics before invoking the numeric Grid backend.+ /// Grid receives final lengths for a definite fixed-layout table and never+ /// participates in the table free-space distribution algorithm.+ fn resolve_column_tracks(&mut self, inputs: LayoutInput) {+ let Some(assignable_inline_size) = self.fixed_assignable_inline_size(inputs) else {+ return;+ };+ self.style.grid_template_columns =+ distribute_fixed_columns(assignable_inline_size, &self.column_constraints)+ .into_iter()+ .map(|size| {+ let track: taffy::TrackSizingFunction = style_helpers::length(size);+ track.into()+ })+ .collect();+ }++ fn fixed_assignable_inline_size(&self, inputs: LayoutInput) -> Option<f32> {+ if !self.fixed_layout {+ return None;+ }++ let percentage_basis = inputs.parent_size.width;+ let padding = self+ .style+ .padding+ .resolve_or_zero(percentage_basis, resolve_stylo_calc_value);+ let border = self+ .style+ .border+ .resolve_or_zero(percentage_basis, resolve_stylo_calc_value);+ let inline_insets = padding.left + padding.right + border.left + border.right;+ let to_border_box = |size: Option<f32>| {+ size.map(|size| {+ if self.style.box_sizing == taffy::BoxSizing::ContentBox {+ size + inline_insets+ } else {+ size.max(inline_insets)+ }+ })+ };+ let (preferred, min_size, max_size) = if inputs.sizing_mode == SizingMode::InherentSize {+ (+ to_border_box(+ self.style+ .size+ .width+ .maybe_resolve(percentage_basis, resolve_stylo_calc_value),+ ),+ to_border_box(+ self.style+ .min_size+ .width+ .maybe_resolve(percentage_basis, resolve_stylo_calc_value),+ ),+ to_border_box(+ self.style+ .max_size+ .width+ .maybe_resolve(percentage_basis, resolve_stylo_calc_value),+ ),+ )+ } else {+ (None, None, None)+ };+ let synthesized_border_box_size = preferred+ .maybe_clamp(min_size, max_size)+ .maybe_max(Some(inline_insets));+ let border_box_size = inputs+ .known_dimensions+ .width+ .or(synthesized_border_box_size)?;+ let internal_spacing =+ self.inline_border_spacing.max(0.0) * self.column_count.saturating_sub(1) as f32;++ Some((border_box_size - inline_insets - internal_spacing).max(0.0))+ }++ fn fixed_grid_min_border_box_size(&self) -> Option<f32> {+ if !self.fixed_layout {+ return None;+ }++ let padding = self+ .style+ .padding+ .resolve_or_zero(None, resolve_stylo_calc_value);+ let border = self+ .style+ .border+ .resolve_or_zero(None, resolve_stylo_calc_value);+ let inline_insets = padding.left + padding.right + border.left + border.right;+ let internal_spacing =+ self.inline_border_spacing.max(0.0) * self.column_count.saturating_sub(1) as f32;+ Some(+ fixed_grid_min_inline_size(&self.column_constraints) + inline_insets + internal_spacing,+ )}}@@ -289,7 +433,7 @@ fn collect_columns<N>(current: LayoutBoxId,group: Option<LayoutBoxId>,columns: &mut Vec<TableColumn>,- tracks: &mut Vec<taffy::TrackSizingFunction>,+ tracks: &mut Vec<TableColumnConstraint>,) whereN: Copy + Debug + Eq + Hash,{@@ -436,11 +580,11 @@ where.unwrap_or_default()}-fn dimension_track(dimension: Dimension) -> taffy::TrackSizingFunction {+fn dimension_track(dimension: Dimension) -> TableColumnConstraint {match dimension.tag() {- taffy::CompactLength::LENGTH_TAG => style_helpers::length(dimension.value()),- taffy::CompactLength::PERCENT_TAG => style_helpers::percent(dimension.value()),- _ => style_helpers::auto(),+ taffy::CompactLength::LENGTH_TAG => TableColumnConstraint::length(dimension.value()),+ taffy::CompactLength::PERCENT_TAG => TableColumnConstraint::percent(dimension.value(), 0.0),+ _ => TableColumnConstraint::auto(),}}@@ -458,24 +602,34 @@ fn minimum_dimension_track(dimension: Dimension) -> taffy::TrackSizingFunction {}}-fn table_cell_width_track(style: &Style<Atom>, fixed: bool) -> taffy::TrackSizingFunction {+fn table_cell_width_track(style: &Style<Atom>, fixed: bool) -> TableColumnConstraint {match style.size.width.tag() {taffy::CompactLength::LENGTH_TAG => {let padding = style.padding.resolve_or_zero(None, resolve_stylo_calc_value);let border = style.border.resolve_or_zero(None, resolve_stylo_calc_value);- let adjustment = if style.box_sizing == taffy::BoxSizing::ContentBox {- padding.left + padding.right + border.left + border.right+ let border_padding = padding.left + padding.right + border.left + border.right;+ let outer_width = if style.box_sizing == taffy::BoxSizing::ContentBox {+ style.size.width.value() + border_padding} else {- 0.0+ style.size.width.value().max(border_padding)};- style_helpers::length(style.size.width.value() + adjustment)+ TableColumnConstraint::length(outer_width)}taffy::CompactLength::PERCENT_TAG if fixed => {- style_helpers::percent(style.size.width.value())+ let border_padding = if style.box_sizing == taffy::BoxSizing::ContentBox {+ let padding = style+ .padding+ .resolve_or_zero(None, resolve_stylo_calc_value);+ let border = style.border.resolve_or_zero(None, resolve_stylo_calc_value);+ padding.left + padding.right + border.left + border.right+ } else {+ 0.0+ };+ TableColumnConstraint::percent(style.size.width.value(), border_padding)}- _ => style_helpers::auto(),+ _ => TableColumnConstraint::auto(),}}diff --git a/moli-layout/src/table/collapsed_borders.rs b/moli-layout/src/table/collapsed_borders.rsindex ff82480ea..23365a78e 100644--- a/moli-layout/src/table/collapsed_borders.rs+++ b/moli-layout/src/table/collapsed_borders.rs@@ -452,7 +452,6 @@ wherelet table_strut = borders.table_strut();set_layout_border(world, root, table_strut);- set_table_wrapper_width_contract(world, root, context.fixed_track_min_width);world.boxes[root.index()].collapsed_table_border_part = true;for cell in &context.cells {let strut = borders.cell_strut(cell);@@ -498,33 +497,6 @@ where};}-fn set_table_wrapper_width_contract<N>(- world: &mut LayoutWorld<N>,- root: LayoutBoxId,- fixed_track_min_width: f32,-) where- N: Copy + Debug + Eq + Hash,-{- let style = &mut world.boxes[root.index()].style.taffy;- // CSS table width constrains the grid border box, while a fixed-layout- // table must still grow enough to contain definite column tracks. This- // must be visible to the parent formatting context before it resolves the- // child's known dimensions; expanding LayoutOutput afterwards is too late.- style.box_sizing = taffy::BoxSizing::BorderBox;- let padding = style- .padding- .resolve_or_zero(None, resolve_stylo_calc_value);- let border = style.border.resolve_or_zero(None, resolve_stylo_calc_value);- let fixed_border_box_min =- fixed_track_min_width + padding.left + padding.right + border.left + border.right;- let current = style.min_size.width;- if current.is_auto() {- style.min_size.width = taffy::Dimension::length(fixed_border_box_min);- } else if current.tag() == taffy::CompactLength::LENGTH_TAG {- style.min_size.width = taffy::Dimension::length(current.value().max(fixed_border_box_min));- }-}-fn border_edge(style: &ResolvedLayoutStyle,side: PhysicalSide,diff --git a/moli-layout/src/table/columns.rs b/moli-layout/src/table/columns.rsnew file mode 100644index 000000000..e93d9d3c5--- /dev/null+++ b/moli-layout/src/table/columns.rs@@ -0,0 +1,347 @@+use taffy::{TrackSizingFunction, style_helpers};++/// A width constraint collected by the CSS table formatting context.+///+/// This remains independent of Grid track sizing. In fixed table layout the+/// constraints are synchronized against the table's assignable inline size+/// first, and only the resulting used lengths are handed to the Grid backend.+#[derive(Clone, Copy, Debug, Default, PartialEq)]+pub(super) struct TableColumnConstraint {+ /// Intrinsic floor accumulated from cells and column boxes.+ pub(super) min_inline_size: f32,+ /// Maximum/fixed measure. `is_constrained` distinguishes a declared width+ /// from an intrinsic maximum once automatic table sizing is implemented.+ pub(super) max_inline_size: Option<f32>,+ pub(super) percent: Option<f32>,+ pub(super) percent_border_padding: f32,+ pub(super) is_constrained: bool,+}++impl TableColumnConstraint {+ pub(super) const fn auto() -> Self {+ Self {+ min_inline_size: 0.0,+ max_inline_size: None,+ percent: None,+ percent_border_padding: 0.0,+ is_constrained: false,+ }+ }++ pub(super) fn length(value: f32) -> Self {+ Self {+ max_inline_size: Some(value.max(0.0)),+ is_constrained: true,+ ..Self::auto()+ }+ }++ pub(super) fn percent(ratio: f32, border_padding: f32) -> Self {+ Self {+ percent: Some(ratio.max(0.0)),+ percent_border_padding: border_padding.max(0.0),+ ..Self::auto()+ }+ }++ pub(super) fn is_auto(self) -> bool {+ self.max_inline_size.is_none() && self.percent.is_none()+ }++ /// Track used while the table has no definite assignable inline size, or+ /// by automatic table layout. It is deliberately never used to perform+ /// fixed-table free-space distribution.+ pub(super) fn intrinsic_grid_track(self) -> TrackSizingFunction {+ if let Some(percent) = self.percent {+ style_helpers::percent(percent)+ } else if self.is_constrained {+ style_helpers::length(self.max_inline_size.unwrap_or(0.0))+ } else {+ style_helpers::auto()+ }+ }++ fn resolved_percent(self, assignable_inline_size: f32) -> Option<f32> {+ self.percent.map(|ratio| {+ self.min_inline_size+ .max(ratio * assignable_inline_size + self.percent_border_padding)+ })+ }++ fn fixed_inline_size(self) -> Option<f32> {+ (self.is_constrained && self.percent.is_none())+ .then_some(self.max_inline_size.unwrap_or(0.0))+ }++ fn is_zero_inline_size_constrained(self) -> bool {+ self.fixed_inline_size() == Some(0.0)+ }++ fn receives_auto_distribution(self) -> bool {+ self.percent.is_none() && self.fixed_inline_size().is_none()+ }++ fn fixed_grid_min_inline_size(self) -> f32 {+ if let Some(fixed) = self.fixed_inline_size() {+ self.min_inline_size.max(fixed)+ } else {+ self.min_inline_size.max(self.percent_border_padding)+ }+ }+}++/// Minimum column extent used by fixed table layout before the authored table+/// inline size is applied. This is the fixed-layout subset of Blink's+/// `ComputeGridInlineMinMax`: definite columns contribute their declared+/// measure, while percentage and automatic columns contribute only their+/// intrinsic floor.+pub(super) fn fixed_grid_min_inline_size(constraints: &[TableColumnConstraint]) -> f32 {+ constraints+ .iter()+ .copied()+ .map(TableColumnConstraint::fixed_grid_min_inline_size)+ .sum()+}++/// Synchronize fixed-table column constraints with the assignable inline size.+///+/// This follows Blink's `SynchronizeAssignableTableInlineSizeAndColumnsFixed`:+/// non-zero fixed columns are assigned first, percentages second, and auto+/// columns receive the remainder. Fixed/percentage columns grow only when no+/// auto column exists, and over-constrained groups shrink proportionally.+/// Explicit zero-width columns stay zero unless every column is zero-width.+pub(super) fn distribute_fixed_columns(+ assignable_inline_size: f32,+ constraints: &[TableColumnConstraint],+) -> Vec<f32> {+ if constraints.is_empty() {+ return Vec::new();+ }++ let target = assignable_inline_size.max(0.0);+ let mut percent_count = 0usize;+ let mut auto_count = 0usize;+ let mut fixed_count = 0usize;+ let mut zero_fixed_count = 0usize;+ let mut total_percent = 0.0;+ let mut total_fixed = 0.0;++ for constraint in constraints.iter().copied() {+ if let Some(percent_size) = constraint.resolved_percent(target) {+ percent_count += 1;+ total_percent += percent_size;+ } else if let Some(fixed_size) = constraint.fixed_inline_size() {+ if fixed_size > 0.0 {+ fixed_count += 1;+ total_fixed += fixed_size;+ } else {+ zero_fixed_count += 1;+ }+ } else {+ auto_count += 1;+ }+ }++ let mut sizes = vec![0.0; constraints.len()];+ let mut assigned = 0.0;+ let mut last_assigned = None;++ if fixed_count > 0 {+ let target_fixed = (target - total_percent).max(0.0);+ let should_grow = total_fixed < target_fixed && auto_count == 0;+ let should_shrink = total_fixed > target;+ let scale = if should_grow || should_shrink {+ target_fixed / total_fixed+ } else {+ 1.0+ };++ for (index, constraint) in constraints.iter().copied().enumerate() {+ let Some(value) = constraint.fixed_inline_size() else {+ continue;+ };+ if value <= 0.0 {+ continue;+ }+ sizes[index] = value * scale;+ assigned += sizes[index];+ last_assigned = Some(index);+ }+ }++ if assigned >= target {+ absorb_rounding_remainder(&mut sizes, last_assigned, target, assigned);+ return sizes;+ }++ if percent_count > 0 {+ let available = target - assigned;+ let should_grow = total_percent < available && auto_count == 0;+ let should_shrink = total_percent > available;+ let scale = if should_grow || should_shrink {+ if total_percent > 0.0 {+ available / total_percent+ } else {+ 0.0+ }+ } else {+ 1.0+ };+ let equal_share = available / percent_count as f32;++ for (index, constraint) in constraints.iter().copied().enumerate() {+ let Some(percent_size) = constraint.resolved_percent(target) else {+ continue;+ };+ sizes[index] = if total_percent > 0.0 {+ percent_size * scale+ } else {+ equal_share+ };+ assigned += sizes[index];+ last_assigned = Some(index);+ }+ }++ let distribute_zero_fixed = zero_fixed_count == constraints.len();+ let recipient_count = if distribute_zero_fixed {+ zero_fixed_count+ } else {+ auto_count+ };+ if recipient_count > 0 {+ let share = (target - assigned) / recipient_count as f32;+ for (index, constraint) in constraints.iter().copied().enumerate() {+ let receives_remainder = constraint.receives_auto_distribution()+ || (distribute_zero_fixed && constraint.is_zero_inline_size_constrained());+ if !receives_remainder {+ continue;+ }+ sizes[index] = share;+ assigned += share;+ last_assigned = Some(index);+ }+ }++ absorb_rounding_remainder(&mut sizes, last_assigned, target, assigned);+ sizes+}++fn absorb_rounding_remainder(+ sizes: &mut [f32],+ last_assigned: Option<usize>,+ target: f32,+ assigned: f32,+) {+ if let Some(index) = last_assigned {+ sizes[index] = (sizes[index] + target - assigned).max(0.0);+ }+}++#[cfg(test)]+mod tests {+ use super::*;++ fn assert_sizes(actual_sizes: &[f32], expected: &[f32]) {+ assert_eq!(actual_sizes.len(), expected.len());+ for (index, (actual, expected)) in actual_sizes.iter().zip(expected).enumerate() {+ assert!(+ (actual - expected).abs() < 0.001,+ "column {index}: expected {expected}, got {actual}; all={actual_sizes:?}",+ );+ }+ }++ #[test]+ fn fixed_columns_assign_fixed_percent_then_auto() {+ let constraints = [+ TableColumnConstraint::length(80.0),+ TableColumnConstraint::percent(0.25, 0.0),+ TableColumnConstraint::auto(),+ TableColumnConstraint::auto(),+ ];++ assert_sizes(+ &distribute_fixed_columns(400.0, &constraints),+ &[80.0, 100.0, 110.0, 110.0],+ );+ }++ #[test]+ fn fixed_columns_grow_without_auto_columns() {+ let constraints = [+ TableColumnConstraint::length(50.0),+ TableColumnConstraint::length(100.0),+ TableColumnConstraint::percent(0.25, 0.0),+ ];++ assert_sizes(+ &distribute_fixed_columns(400.0, &constraints),+ &[100.0, 200.0, 100.0],+ );+ }++ #[test]+ fn fixed_columns_shrink_overconstrained_groups() {+ let constraints = [+ TableColumnConstraint::length(200.0),+ TableColumnConstraint::length(200.0),+ TableColumnConstraint::percent(0.5, 0.0),+ TableColumnConstraint::auto(),+ ];++ assert_sizes(+ &distribute_fixed_columns(300.0, &constraints),+ &[75.0, 75.0, 150.0, 0.0],+ );+ }++ #[test]+ fn fixed_columns_include_cell_border_padding_in_percent_measure() {+ let constraints = [+ TableColumnConstraint::percent(0.5, 20.0),+ TableColumnConstraint::auto(),+ ];++ assert_sizes(+ &distribute_fixed_columns(300.0, &constraints),+ &[170.0, 130.0],+ );+ }++ #[test]+ fn fixed_columns_only_grow_zero_lengths_when_all_are_zero() {+ assert_sizes(+ &distribute_fixed_columns(+ 100.0,+ &[+ TableColumnConstraint::length(0.0),+ TableColumnConstraint::auto(),+ ],+ ),+ &[0.0, 100.0],+ );+ assert_sizes(+ &distribute_fixed_columns(+ 100.0,+ &[+ TableColumnConstraint::length(0.0),+ TableColumnConstraint::length(0.0),+ ],+ ),+ &[50.0, 50.0],+ );+ }++ #[test]+ fn fixed_grid_min_uses_definite_tracks_and_percentage_insets() {+ assert_eq!(+ fixed_grid_min_inline_size(&[+ TableColumnConstraint::length(80.0),+ TableColumnConstraint::percent(0.5, 20.0),+ TableColumnConstraint::auto(),+ ]),+ 100.0,+ );+ }+}diff --git a/moli-renderer-v8/src/runtime/phase_one/mod.rs b/moli-renderer-v8/src/runtime/phase_one/mod.rsindex e2ea952e4..3b69615f1 100644--- a/moli-renderer-v8/src/runtime/phase_one/mod.rs+++ b/moli-renderer-v8/src/runtime/phase_one/mod.rs@@ -167,6 +167,24 @@ mod tests {}}+ fn rgb(red: u8, green: u8, blue: u8) -> moli_layout::PaintColor {+ moli_layout::PaintColor::new(+ f32::from(red) / 255.0,+ f32::from(green) / 255.0,+ f32::from(blue) / 255.0,+ 1.0,+ )+ }++ async fn render_test_snapshot(html: &'static str) -> moli_layout::PaintSnapshot {+ let mut page = parse_phase_one_html_into_page_vm_for_test(html).await;+ page.vm_mut().sync_live_document_style_sources();+ page.vm_mut()+ .screenshot_layout_snapshot(moli_layout::PaintViewport::new(800, 600, 1.0))+ .expect("test layout should succeed")+ .expect("test fixture should have a document element")+ }+fn glyph_min_x(snapshot: &moli_layout::PaintSnapshot, color: moli_layout::PaintColor) -> f32 {snapshot.fragments@@ -905,6 +923,208 @@ html,body{margin:0;padding:0}}));}+ #[test]+ fn fixed_table_layout_distributes_unresolved_columns_equally() {+ 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;width:300px;table-layout:fixed}+td{padding:0;border:0;height:10px}+#calc-cell{width:calc(50% - 20px);background:rgb(61,62,63)}+#remaining-cell{background:rgb(71,72,73)}+</style></head><body><table><tr><td id=calc-cell></td><td id=remaining-cell></td></tr></table></body></html>"#,+ )+ .await;++ assert_paint_rect(+ solid_paint_rect(&snapshot, rgb(61, 62, 63)),+ moli_layout::PaintRect::new(0.0, 0.0, 150.0, 10.0),+ );+ assert_paint_rect(+ solid_paint_rect(&snapshot, rgb(71, 72, 73)),+ moli_layout::PaintRect::new(150.0, 0.0, 150.0, 10.0),+ );+ }));+ }++ #[test]+ fn fixed_table_layout_grows_to_its_definite_column_minimum() {+ 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;width:300px;table-layout:fixed}+col{width:200px}td{padding:0;border:0;height:10px}+#first{background:rgb(81,82,83)}#second{background:rgb(91,92,93)}+#collapsed{border-collapse:collapse}+#collapsed-first{background:rgb(171,172,173)}#collapsed-second{background:rgb(181,182,183)}+</style></head><body>+<table><col><col><tr><td id=first></td><td id=second></td></tr></table>+<table id=collapsed><col><col><tr><td id=collapsed-first></td><td id=collapsed-second></td></tr></table>+</body></html>"#,+ )+ .await;++ assert_paint_rect(+ solid_paint_rect(&snapshot, rgb(81, 82, 83)),+ moli_layout::PaintRect::new(0.0, 0.0, 200.0, 10.0),+ );+ assert_paint_rect(+ solid_paint_rect(&snapshot, rgb(91, 92, 93)),+ moli_layout::PaintRect::new(200.0, 0.0, 200.0, 10.0),+ );+ assert_paint_rect(+ solid_paint_rect(&snapshot, rgb(171, 172, 173)),+ moli_layout::PaintRect::new(0.0, 10.0, 200.0, 10.0),+ );+ assert_paint_rect(+ solid_paint_rect(&snapshot, rgb(181, 182, 183)),+ moli_layout::PaintRect::new(200.0, 10.0, 200.0, 10.0),+ );+ }));+ }++ #[test]+ fn fixed_table_layout_grows_fixed_columns_when_no_auto_column_remains() {+ 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;width:400px;table-layout:fixed}+td{padding:0;border:0;height:10px}+#first{width:50px;background:rgb(101,102,103)}+#second{width:100px;background:rgb(111,112,113)}+#third{width:25%;background:rgb(121,122,123)}+</style></head><body><table><tr><td id=first></td><td id=second></td><td id=third></td></tr></table></body></html>"#,+ )+ .await;++ for (color, expected) in [+ (rgb(101, 102, 103), (0.0, 100.0)),+ (rgb(111, 112, 113), (100.0, 200.0)),+ (rgb(121, 122, 123), (300.0, 100.0)),+ ] {+ assert_paint_rect(+ solid_paint_rect(&snapshot, color),+ moli_layout::PaintRect::new(expected.0, 0.0, expected.1, 10.0),+ );+ }+ }));+ }++ #[test]+ fn fixed_table_layout_adds_content_box_padding_to_percent_cell_measure() {+ 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;width:300px;table-layout:fixed}+td{border:0;height:10px;padding-top:0;padding-bottom:0}+#first{box-sizing:content-box;width:50%;padding-left:10px;padding-right:10px;background:rgb(131,132,133)}+#second{padding-left:0;padding-right:0;background:rgb(141,142,143)}+</style></head><body><table><tr><td id=first></td><td id=second></td></tr></table></body></html>"#,+ )+ .await;++ assert_paint_rect(+ solid_paint_rect(&snapshot, rgb(131, 132, 133)),+ moli_layout::PaintRect::new(0.0, 0.0, 170.0, 10.0),+ );+ assert_paint_rect(+ solid_paint_rect(&snapshot, rgb(141, 142, 143)),+ moli_layout::PaintRect::new(170.0, 0.0, 130.0, 10.0),+ );+ }));+ }++ #[test]+ fn fixed_table_layout_clamps_border_box_cell_width_to_its_insets() {+ 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;width:100px;table-layout:fixed}+td{border:0;height:10px;padding-top:0;padding-bottom:0}+#first{box-sizing:border-box;width:10px;padding-left:20px;padding-right:20px;background:rgb(151,152,153)}+#second{padding-left:0;padding-right:0;background:rgb(161,162,163)}+</style></head><body><table><tr><td id=first></td><td id=second></td></tr></table></body></html>"#,+ )+ .await;++ assert_paint_rect(+ solid_paint_rect(&snapshot, rgb(151, 152, 153)),+ moli_layout::PaintRect::new(0.0, 0.0, 40.0, 10.0),+ );+ assert_paint_rect(+ solid_paint_rect(&snapshot, rgb(161, 162, 163)),+ moli_layout::PaintRect::new(40.0, 0.0, 60.0, 10.0),+ );+ }));+ }++ #[test]+ fn fixed_table_layout_preserves_native_and_explicit_box_sizing() {+ 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{position:absolute;left:0;border:4px solid black;border-spacing:0;width:100px;table-layout:fixed}+td{padding:0;border:0;height:10px}+#native{top:0}#content{top:30px;box-sizing:content-box}+#native-first{background:rgb(191,192,193)}#native-second{background:rgb(201,202,203)}+#content-first{background:rgb(211,212,213)}#content-second{background:rgb(221,222,223)}+</style></head><body>+<table id=native><tr><td id=native-first></td><td id=native-second></td></tr></table>+<table id=content><tr><td id=content-first></td><td id=content-second></td></tr></table>+</body></html>"#,+ )+ .await;++ for (color, expected) in [+ (rgb(191, 192, 193), (4.0, 4.0, 46.0)),+ (rgb(201, 202, 203), (50.0, 4.0, 46.0)),+ (rgb(211, 212, 213), (4.0, 34.0, 50.0)),+ (rgb(221, 222, 223), (54.0, 34.0, 50.0)),+ ] {+ assert_paint_rect(+ solid_paint_rect(&snapshot, color),+ moli_layout::PaintRect::new(expected.0, expected.1, expected.2, 10.0),+ );+ }+ }));+ }+#[test]fn layout_renderer_projects_current_blitz_taffy_parity_from_stylo() {let runtime = tokio::runtime::Builder::new_current_thread()@@ -993,35 +1213,25 @@ html,body{margin:0;padding:0});}- let mut replaced_table_page = parse_phase_one_html_into_page_vm_for_test(+ let mut replaced_page = parse_phase_one_html_into_page_vm_for_test(r#"<!doctype html><html><head><style>-html,body{margin:0;padding:0}table{border-spacing:0;width:300px;table-layout:fixed}td{padding:0;border:0;height:10px}-#calc-cell{width:calc(50% - 20px);background:rgb(61,62,63)}#remaining-cell{background:rgb(71,72,73)}+html,body{margin:0;padding:0}#image{display:block;width:120px;height:auto;aspect-ratio:0/1;background:rgb(81,82,83)}-</style></head><body><table><tr><td id=calc-cell></td><td id=remaining-cell></td></tr></table>-<svg id=image width=80 height=40 viewBox="0 0 80 40"></svg></body></html>"#,+</style></head><body><svg id=image width=80 height=40 viewBox="0 0 80 40"></svg></body></html>"#,).await;- replaced_table_page+ replaced_page.vm_mut().sync_live_document_style_sources();- let replaced_table = replaced_table_page+ let replaced = replaced_page.vm_mut().screenshot_layout_snapshot(moli_layout::PaintViewport::new(800, 600, 1.0))- .expect("table calc/replaced ratio layout should succeed")- .expect("table calc/replaced ratio fixture should have a document element");- for (color, expected) in [- (rgb(61, 62, 63), (0.0, 0.0, 150.0, 10.0)),- (rgb(71, 72, 73), (150.0, 0.0, 150.0, 10.0)),- (rgb(81, 82, 83), (0.0, 10.0, 120.0, 60.0)),- ] {- assert_paint_rect(- solid_paint_rect(&replaced_table, color),- moli_layout::PaintRect::new(- expected.0, expected.1, expected.2, expected.3,- ),- );- }+ .expect("replaced ratio layout should succeed")+ .expect("replaced ratio fixture should have a document element");+ assert_paint_rect(+ solid_paint_rect(&replaced, rgb(81, 82, 83)),+ moli_layout::PaintRect::new(0.0, 0.0, 120.0, 60.0),+ );}));}diff --git a/moli-renderer-v8/src/style_engine/ua/html.css b/moli-renderer-v8/src/style_engine/ua/html.cssindex f0c55c9bd..4b6dcd5e0 100644--- a/moli-renderer-v8/src/style_engine/ua/html.css+++ b/moli-renderer-v8/src/style_engine/ua/html.css@@ -76,6 +76,7 @@ figure {table {display: table;+ box-sizing: border-box;}thead {