Skip to content

armgit / moli

Public Imported from GitHub
0

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

fix(layout): stabilize table layout and cache measurements

ldm0b1c012951cfc
diff --git a/moli-benchmark/wpt-cross-current/error-cases.txt b/moli-benchmark/wpt-cross-current/error-cases.txt
index 06ac418c6..3c9277d54 100644
--- a/moli-benchmark/wpt-cross-current/error-cases.txt
+++ b/moli-benchmark/wpt-cross-current/error-cases.txt
@@ -7,3 +7,4 @@ infrastructure/expected-fail/user-prompt.html?type=confirm
infrastructure/expected-fail/user-prompt.html?type=confirm&wait
infrastructure/expected-fail/user-prompt.html?type=prompt
infrastructure/expected-fail/user-prompt.html?type=prompt&wait
+shadow-dom/declarative/gethtml.html
diff --git a/moli-benchmark/wpt-cross-current/failed-cases.txt b/moli-benchmark/wpt-cross-current/failed-cases.txt
index ad095e4ec..35bfa441c 100644
--- a/moli-benchmark/wpt-cross-current/failed-cases.txt
+++ b/moli-benchmark/wpt-cross-current/failed-cases.txt
@@ -22,6 +22,7 @@ content-security-policy/inheritance/location-reload.html
content-security-policy/inside-worker/dedicatedworker-report-only.html
content-security-policy/inside-worker/dedicatedworker-worker-src.html
content-security-policy/inside-worker/serviceworker-report-only.https.sub.html
+content-security-policy/navigation/javascript-url-navigation-evaluated-to-string-inherits-csp.html
content-security-policy/navigation/to-javascript-parent-initiated-parent-csp.html
content-security-policy/object-src/object-src-url-blocked.html
content-security-policy/resource-hints/prefetch-allowed-by-default.html
@@ -51,7 +52,6 @@ css/css-cascade/all-prop-revert-layer-noop.html?include=2
css/css-cascade/all-prop-revert-layer-noop.html?include=4
css/css-cascade/all-prop-revert-layer-noop.html?include=5
css/css-cascade/all-prop-revert-noop.html?include=2
-css/css-cascade/all-prop-revert-noop.html?include=4
css/css-cascade/all-prop-revert-noop.html?include=5
css/css-cascade/import-conditions.html
css/css-cascade/layer-counter-style-override.html
@@ -342,10 +342,6 @@ css/css-flexbox/flexbox_rtl-direction.html
css/css-flexbox/flexbox_rtl-flow-reverse.html
css/css-flexbox/flexbox_rtl-flow.html
css/css-flexbox/flexbox_rtl-order.html
-css/css-flexbox/flexbox_stf-table-caption.html
-css/css-flexbox/flexbox_stf-table-cell.html
-css/css-flexbox/flexbox_stf-table-row-group.html
-css/css-flexbox/flexbox_stf-table-row.html
css/css-flexbox/flexbox_stf-table-singleline-2.html
css/css-flexbox/flexbox_visibility-collapse-line-wrapping.html
css/css-flexbox/flexbox_visibility-collapse.html
@@ -428,11 +424,8 @@ css/css-flexbox/svg-root-as-flex-item-003.html
css/css-flexbox/svg-root-as-flex-item-004.html
css/css-flexbox/svg-root-as-flex-item-005.html
css/css-flexbox/table-as-item-fixed-min-width-3.html
-css/css-flexbox/table-as-item-flex-cross-size.html
css/css-flexbox/table-as-item-large-intrinsic-size.html
-css/css-flexbox/table-as-item-stretch-cross-size-2.html
css/css-flexbox/table-as-item-stretch-cross-size-5.html
-css/css-flexbox/table-as-item-stretch-cross-size.html
css/css-font-loading/font-face-reject.html
css/css-font-loading/fontface-descriptor-updates-2.html
css/css-font-loading/fontface-load-in-modal-dialog.html
@@ -521,6 +514,7 @@ css/css-grid/abspos/positioned-grid-descendants-001.html
css/css-grid/abspos/positioned-grid-descendants-002.html
css/css-grid/abspos/positioned-grid-descendants-004.html
css/css-grid/abspos/positioned-grid-descendants-007.html
+css/css-grid/abspos/positioned-grid-descendants-015.html
css/css-grid/abspos/positioned-grid-items-020.html
css/css-grid/abspos/positioned-grid-items-021.html
css/css-grid/abspos/positioned-grid-items-024.html
@@ -807,8 +801,6 @@ css/css-grid/alignment/self-baseline/grid-self-baseline-vertical-rl-006.html
css/css-grid/alignment/self-baseline/grid-self-baseline-vertical-rl-007.html
css/css-grid/computed-grid-column.html
css/css-grid/firefox-bug-1881495.html
-css/css-grid/grid-definition/fr-unit-with-percentage.html
-css/css-grid/grid-definition/fr-unit.html
css/css-grid/grid-definition/grid-auto-repeat-aspect-ratio-001.html
css/css-grid/grid-definition/grid-auto-repeat-aspect-ratio-002.html
css/css-grid/grid-definition/grid-auto-repeat-max-size-002.html
@@ -1471,8 +1463,6 @@ css/css-grid/grid-lanes/track-sizing/row-track-sizing-003.html
css/css-grid/grid-lanes/track-sizing/row-track-sizing-004.html
css/css-grid/grid-lanes/track-sizing/row-track-sizing-005.html
css/css-grid/grid-layout-properties.html
-css/css-grid/grid-model/display-grid.html
-css/css-grid/grid-model/display-inline-grid.html
css/css-grid/grid-model/grid-areas-overflowing-grid-container-001.html
css/css-grid/grid-model/grid-areas-overflowing-grid-container-002.html
css/css-grid/grid-model/grid-areas-overflowing-grid-container-003.html
@@ -3530,6 +3520,7 @@ service-workers/service-worker/static-router-invalid-rules.https.html
service-workers/service-worker/static-router-main-resource.https.html
service-workers/service-worker/static-router-no-fetch-handler.https.html
service-workers/service-worker/static-router-request-destination.https.html
+service-workers/service-worker/static-router-subresource.https.html
service-workers/service-worker/synced-state.https.html
service-workers/service-worker/unregister-then-register-new-script.https.html
service-workers/service-worker/unregister-then-register.https.html
@@ -3753,7 +3744,6 @@ webrtc-priority/RTCPeerConnection-ondatachannel.html
webrtc-priority/RTCRtpParameters-encodings.html
webusb/usb-supported-by-permissions-policy.html
workers/WorkerNavigator_platform.htm
-workers/modules/dedicated-worker-import-csp.html
workers/semantics/encodings/003.html
workers/semantics/encodings/004.html
workers/semantics/structured-clone/dedicated.html
@@ -3786,5 +3776,4 @@ xhr/setrequestheader-bogus-name.htm
xhr/setrequestheader-bogus-value.htm
xhr/status-async.htm
xhr/status-basic.htm
-xhr/xmlhttprequest-timeout-worker-overridesexpires.html?timeout set to expired value before load fires
xml/xml-prolog-accepted-versions.html
diff --git a/moli-benchmark/wpt-cross-current/harness-stalled-cases.txt b/moli-benchmark/wpt-cross-current/harness-stalled-cases.txt
index 5bd1f6821..81d61b039 100644
--- a/moli-benchmark/wpt-cross-current/harness-stalled-cases.txt
+++ b/moli-benchmark/wpt-cross-current/harness-stalled-cases.txt
@@ -31,7 +31,6 @@ html/semantics/embedded-content/the-img-element/decode/image-decode-iframe.html
html/semantics/embedded-content/the-object-element/object-events.html
html/semantics/forms/form-submission-target/rel-base-target.html
html/semantics/links/links-created-by-a-and-area-elements/target_blank_implicit_noopener_base.html
-navigation-api/navigate-event/intercept-cross-origin.html
navigation-api/navigate-event/navigate-history-back-noop.html
payment-method-basic-card/apply_the_modifiers.html
payment-method-basic-card/steps_for_selecting_the_payment_handler.html
diff --git a/moli-benchmark/wpt-cross-current/passed-cases.txt b/moli-benchmark/wpt-cross-current/passed-cases.txt
index 23c036d47..e5e3e04cb 100644
--- a/moli-benchmark/wpt-cross-current/passed-cases.txt
+++ b/moli-benchmark/wpt-cross-current/passed-cases.txt
@@ -35,7 +35,6 @@ compression/compression-constructor-error.any.js?moli-wpt-any=window
compression/compression-including-empty-chunk.any.js?moli-wpt-any=dedicatedworker
compression/compression-including-empty-chunk.any.js?moli-wpt-any=window
compression/compression-large-flush-output.any.js?moli-wpt-any=dedicatedworker
-compression/compression-large-flush-output.any.js?moli-wpt-any=window
compression/compression-multiple-chunks.any.js?moli-wpt-any=dedicatedworker
compression/compression-multiple-chunks.any.js?moli-wpt-any=window
compression/compression-output-length.any.js?moli-wpt-any=dedicatedworker
@@ -114,7 +113,6 @@ content-security-policy/media-src/media-src-blocked-data-url.html
content-security-policy/meta/meta-img-src.html
content-security-policy/meta/meta-modified.html
content-security-policy/meta/sandbox-iframe.html
-content-security-policy/navigation/javascript-url-navigation-evaluated-to-string-inherits-csp.html
content-security-policy/navigation/to-javascript-parent-initiated-check-csp-order.html
content-security-policy/navigation/to-javascript-parent-initiated-child-csp.html
content-security-policy/navigation/to-javascript-url-frame-src.html
@@ -1143,6 +1141,10 @@ css/css-flexbox/flexbox_stf-abspos.html
css/css-flexbox/flexbox_stf-fixpos.html
css/css-flexbox/flexbox_stf-float.html
css/css-flexbox/flexbox_stf-inline-block.html
+css/css-flexbox/flexbox_stf-table-caption.html
+css/css-flexbox/flexbox_stf-table-cell.html
+css/css-flexbox/flexbox_stf-table-row-group.html
+css/css-flexbox/flexbox_stf-table-row.html
css/css-flexbox/flexbox_stf-table-singleline.html
css/css-flexbox/flexbox_stf-table.html
css/css-flexbox/flexbox_table-fixed-layout.html
@@ -1436,6 +1438,7 @@ css/css-flexbox/table-as-item-change-cell.html
css/css-flexbox/table-as-item-cross-size.html
css/css-flexbox/table-as-item-fixed-min-width-2.html
css/css-flexbox/table-as-item-fixed-min-width.html
+css/css-flexbox/table-as-item-flex-cross-size.html
css/css-flexbox/table-as-item-inflexible-in-column-1.html
css/css-flexbox/table-as-item-inflexible-in-column-2.html
css/css-flexbox/table-as-item-inflexible-in-row-1.html
@@ -1447,8 +1450,10 @@ css/css-flexbox/table-as-item-percent-width-cell-001.html
css/css-flexbox/table-as-item-specified-height.html
css/css-flexbox/table-as-item-specified-width-vertical.html
css/css-flexbox/table-as-item-specified-width.html
+css/css-flexbox/table-as-item-stretch-cross-size-2.html
css/css-flexbox/table-as-item-stretch-cross-size-3.html
css/css-flexbox/table-as-item-stretch-cross-size-4.html
+css/css-flexbox/table-as-item-stretch-cross-size.html
css/css-flexbox/table-as-item-wide-content.html
css/css-flexbox/table-item-flex-percentage-min-width.html
css/css-flexbox/table-item-flex-percentage-width.html
@@ -1548,7 +1553,6 @@ css/css-grid/abspos/positioned-grid-descendants-011.html
css/css-grid/abspos/positioned-grid-descendants-012.html
css/css-grid/abspos/positioned-grid-descendants-013.html
css/css-grid/abspos/positioned-grid-descendants-014.html
-css/css-grid/abspos/positioned-grid-descendants-015.html
css/css-grid/abspos/positioned-grid-descendants-016.html
css/css-grid/abspos/positioned-grid-descendants-017.html
css/css-grid/abspos/positioned-grid-items-001.html
@@ -1734,6 +1738,8 @@ css/css-grid/grid-definition/flex-factor-sum-less-than-1-001.html
css/css-grid/grid-definition/flex-item-grid-container-auto-repeat-001.html
css/css-grid/grid-definition/flex-item-grid-container-auto-repeat-002.html
css/css-grid/grid-definition/flex-item-grid-container-percentage-rows-001.html
+css/css-grid/grid-definition/fr-unit-with-percentage.html
+css/css-grid/grid-definition/fr-unit.html
css/css-grid/grid-definition/grid-auto-explicit-rows-001.html
css/css-grid/grid-definition/grid-auto-fill-columns-001.html
css/css-grid/grid-definition/grid-auto-fill-rows-001.html
@@ -1954,6 +1960,8 @@ css/css-grid/grid-lanes/track-sizing/auto-repeat/row-auto-repeat-006.html
css/css-grid/grid-lanes/track-sizing/dynamic-grid-track-direction.html
css/css-grid/grid-model/column-property-should-not-apply-on-grid-container-001.html
css/css-grid/grid-model/compute-intrinsic-widths-scrollbar-001.html
+css/css-grid/grid-model/display-grid.html
+css/css-grid/grid-model/display-inline-grid.html
css/css-grid/grid-model/fixed-width-intrinsic-width-should-exclude-scrollbar-001.html
css/css-grid/grid-model/grid-areas-overflowing-grid-container-004.html
css/css-grid/grid-model/grid-areas-overflowing-grid-container-005.html
@@ -5165,6 +5173,7 @@ hr-time/navigation-start-post-before-unload.html
hr-time/performance-tojson.html
hr-time/timeOrigin.html
hr-time/timing-attack.html
+html/browsers/browsing-the-web/history-traversal/api-availability.html
html/browsers/browsing-the-web/history-traversal/event-order/after-load-hash-twice.html
html/browsers/browsing-the-web/history-traversal/event-order/after-load-hash.html
html/browsers/browsing-the-web/history-traversal/event-order/after-load-pushState.html
@@ -7586,7 +7595,6 @@ shadow-dom/declarative/declarative-shadow-dom-slot-assignment.html
shadow-dom/declarative/declarative-shadow-dom-write-to-iframe.html
shadow-dom/declarative/declarative-with-disabled-shadow.html
shadow-dom/declarative/gethtml-ordering.html
-shadow-dom/declarative/gethtml.html
shadow-dom/declarative/innerhtml-before-closing-tag.html
shadow-dom/declarative/innerhtml-on-ordinary-template.html
shadow-dom/declarative/move-template-before-closing-tag.html
@@ -8620,6 +8628,7 @@ workers/interfaces/WorkerUtils/navigator/005.html
workers/interfaces/WorkerUtils/navigator/006.html
workers/interfaces/WorkerUtils/navigator/007.html
workers/interfaces/WorkerUtils/navigator/language.html
+workers/modules/dedicated-worker-import-csp.html
workers/modules/dedicated-worker-import-data-url-cross-origin.html
workers/modules/dedicated-worker-import-failure.html
workers/modules/dedicated-worker-import-meta.html
@@ -8723,6 +8732,7 @@ xhr/status-error.htm
xhr/sync-xhr-and-window-onload.html
xhr/template-element.html
xhr/thrown-error-in-events.html
+xhr/timeout-cors-async.htm
xhr/timeout-sync.htm
xhr/xmlhttprequest-basic.htm
xhr/xmlhttprequest-eventtarget.htm
@@ -8754,6 +8764,7 @@ xhr/xmlhttprequest-timeout-worker-aborted.html?only open()ed, not aborted
xhr/xmlhttprequest-timeout-worker-overrides.html?timeout disabled after initially set
xhr/xmlhttprequest-timeout-worker-overrides.html?timeout enabled after initially disabled
xhr/xmlhttprequest-timeout-worker-overrides.html?timeout overrides load after a delay
+xhr/xmlhttprequest-timeout-worker-overridesexpires.html?timeout set to expired value before load fires
xhr/xmlhttprequest-timeout-worker-overridesexpires.html?timeout set to expiring value after load fires
xhr/xmlhttprequest-timeout-worker-overridesexpires.html?timeout set to non-expiring value after timeout fires
xhr/xmlhttprequest-timeout-worker-simple.html?load fires normally
diff --git a/moli-benchmark/wpt-cross-current/timeout-cases.txt b/moli-benchmark/wpt-cross-current/timeout-cases.txt
index 10001c6f8..fd430de4b 100644
--- a/moli-benchmark/wpt-cross-current/timeout-cases.txt
+++ b/moli-benchmark/wpt-cross-current/timeout-cases.txt
@@ -1,6 +1,7 @@
IndexedDB/idbfactory-databases-opaque-origin.html
IndexedDB/idbfactory-deleteDatabase-opaque-origin.html
IndexedDB/idbfactory-open-opaque-origin.html
+compression/compression-large-flush-output.any.js?moli-wpt-any=window
conformance-checkers/html-svg/struct-dom-01-b-isvalid.html
conformance-checkers/html-svg/struct-svg-02-f-isvalid.html
content-security-policy/embedded-enforcement/change-csp-attribute-and-history-navigation.html
@@ -29,6 +30,7 @@ content-security-policy/xslt/document-function-blocked.html
content-security-policy/xslt/xsltprocessor-include-blocked.html
cookiestore/serviceworker_cookieStore_cross_origin.https.sub.html
css/css-cascade/all-prop-initial-xml.html
+css/css-cascade/all-prop-revert-noop.html?include=4
css/css-flexbox/inline-flex-column-image-load.html
css/css-values/dynamic-viewport-units-rule-cache.html
css/css-variables/variable-animation-from-to.html
@@ -60,7 +62,6 @@ fetch/api/policies/referrer-origin-service-worker.https.html
fetch/api/policies/referrer-origin-when-cross-origin-service-worker.https.html
fetch/api/policies/referrer-unsafe-url-service-worker.https.html
focus/nested-focus-within-iframe-focus-event.html
-html/browsers/browsing-the-web/history-traversal/api-availability.html
html/browsers/browsing-the-web/history-traversal/browsing_context_name_cross_origin.html
html/browsers/browsing-the-web/history-traversal/pageswap/pageswap-push-navigation.html
html/browsers/browsing-the-web/history-traversal/pageswap/pageswap-reload-navigation.html
@@ -201,6 +202,7 @@ navigation-api/navigate-event/defer/tentative/defer-with-multiple-handlers-and-s
navigation-api/navigate-event/defer/tentative/defer-with-multiple-handlers.html
navigation-api/navigate-event/defer/tentative/defer-with-single-handler-reject.html
navigation-api/navigate-event/defer/tentative/defer-with-single-handler.html
+navigation-api/navigate-event/intercept-cross-origin.html
navigation-api/navigate-event/navigate-form-requestSubmit.html
navigation-api/navigate-event/navigation-back-cross-document-preventDefault.html
navigation-api/navigate-event/navigation-traverseTo-navigates-top-and-same-doc-child-and-cross-doc-child.html
@@ -268,7 +270,6 @@ service-workers/service-worker/registration-service-worker-attributes.https.html
service-workers/service-worker/resource-timing-fetch-variants.https.html
service-workers/service-worker/secure-context.https.html
service-workers/service-worker/skip-waiting-without-client.https.html
-service-workers/service-worker/static-router-subresource.https.html
service-workers/service-worker/unregister-immediately-before-installed.https.html
service-workers/service-worker/unregister-immediately-during-extendable-events.https.html
streams/transferable/deserialize-error.window.js?moli-wpt-script=window
diff --git a/moli-layout/src/style.rs b/moli-layout/src/style.rs
index 115ff2432..478e3bb4f 100644
--- a/moli-layout/src/style.rs
+++ b/moli-layout/src/style.rs
@@ -1598,6 +1598,8 @@ impl ResolvedLayoutStyle {
pub fn force_layout_display(&mut self, display: LayoutDisplay) {
self.display = display;
self.taffy.display = taffy_display(display);
+ self.taffy.item_is_table =
+ matches!(display, LayoutDisplay::Table | LayoutDisplay::InlineTable);
}
/// Returns the computed CSS font size sampled for this pass.
@@ -2027,6 +2029,7 @@ impl ResolvedLayoutStyle {
computed: parent.computed.clone(),
taffy: Style {
display: taffy_display(display),
+ item_is_table: matches!(display, LayoutDisplay::Table | LayoutDisplay::InlineTable),
..Style::default()
},
preferred_aspect_ratio: PreferredAspectRatio::Auto,
diff --git a/moli-layout/src/table.rs b/moli-layout/src/table.rs
index 948d44d77..38174831c 100644
--- a/moli-layout/src/table.rs
+++ b/moli-layout/src/table.rs
@@ -26,10 +26,12 @@ use crate::{
};
mod block;
+mod cache;
mod collapsed_borders;
mod columns;
mod rows;
+pub(crate) use cache::TableMeasureCache;
pub(crate) use collapsed_borders::CollapsedTableBorders;
use collapsed_borders::{prepare_collapsed_table_borders, set_collapsed_border_geometry};
use columns::{
@@ -56,6 +58,15 @@ struct TableRow {
group: Option<LayoutBoxId>,
index: usize,
grid_index: usize,
+ start_cell_index: usize,
+ cell_count: usize,
+ section_end: usize,
+}
+
+impl TableRow {
+ fn cells(&self) -> std::ops::Range<usize> {
+ self.start_cell_index..self.start_cell_index + self.cell_count
+ }
}
#[derive(Clone, Copy)]
@@ -140,6 +151,8 @@ struct TableContext {
sections: Vec<rows::SectionConstraint>,
section_boxes: Vec<LayoutBoxId>,
section_tracks: Vec<std::ops::Range<usize>>,
+ measured_baselines: (Option<f32>, Option<f32>),
+ caption_inline_min: f32,
layout_mode: TableLayoutMode,
inline_border_spacing: f32,
block_border_spacing: f32,
@@ -289,7 +302,7 @@ where
let display = world.boxes[parent.index()].style.display();
display.is_flex_container() || display.is_grid_container()
});
- if allocated_wrapper && !context.captions.is_empty() {
+ if allocated_wrapper && !context.captions.is_empty() && context.writing_mode.is_horizontal() {
let mut space = grid_inputs.constraint_space(context.writing_mode);
if let Some(block_size) = space.known_size.block_size {
// Flex/Grid allocate the complete wrapper. Caption space must not
@@ -302,7 +315,53 @@ where
context.writing_mode,
RunMode::ComputeSize,
);
- space.known_size.block_size = Some((block_size - captions).max(0.0));
+ let style = &world.boxes[root.index()].style.taffy;
+ let basis = space.margin_padding_percentage_basis();
+ let decorations = style
+ .padding
+ .resolve_or_zero(basis, resolve_stylo_calc_value)
+ + style
+ .border
+ .resolve_or_zero(basis, resolve_stylo_calc_value);
+ let adjustment = if style.box_sizing == taffy::BoxSizing::ContentBox {
+ context
+ .writing_mode
+ .to_logical(decorations.sum_axes())
+ .block_size
+ } else {
+ 0.0
+ };
+ let resolve = |dimension: Dimension| {
+ dimension
+ .maybe_resolve(
+ space.percentage_resolution_size.block_size,
+ resolve_stylo_calc_value,
+ )
+ .map(|size| size + adjustment)
+ };
+ // The preferred table height describes the grid, excluding its
+ // captions. A parent may pass that authored size as a known size
+ // before it has measured the complete wrapper.
+ let mut grid_minimum =
+ resolve(context.writing_mode.to_logical(style.size).block_size).unwrap_or(0.0);
+ if let Some(parent) = world.boxes[root.index()].layout_parent {
+ let parent_style = &world.boxes[parent.index()].style;
+ let main_axis = if matches!(
+ parent_style.taffy.flex_direction,
+ taffy::FlexDirection::Row | taffy::FlexDirection::RowReverse
+ ) {
+ parent_style.writing_mode().inline_axis()
+ } else {
+ parent_style.writing_mode().block_axis()
+ };
+ if parent_style.display().is_flex_container()
+ && main_axis == context.writing_mode.block_axis()
+ && style.flex_shrink == 0.0
+ {
+ grid_minimum = grid_minimum.max(resolve(style.flex_basis).unwrap_or(0.0));
+ }
+ }
+ space.known_size.block_size = Some((block_size - captions).max(grid_minimum));
grid_inputs = space.into_layout_input();
}
}
@@ -314,6 +373,13 @@ where
};
compute_grid_layout(&mut wrapper, NodeId::from(0usize), grid_inputs)
};
+ if context.writing_mode.is_horizontal() && inputs.axis != RequestedAxis::Horizontal {
+ // Fixed Grid tracks can return without measuring child baselines.
+ // Use the row pass, including the absence of a baseline in a table
+ // with no rows; final cell layout may refine it below.
+ output.first_baselines.y = context.measured_baselines.0;
+ output.last_baselines.y = context.measured_baselines.1;
+ }
{
let caption_parent_writing_mode = world.boxes[root.index()].style.writing_mode();
@@ -426,6 +492,7 @@ where
section_boxes.push(section);
}
}
+ index_row_sections(&mut rows);
place_table_cells(&mut cells, &rows, &mut max_columns);
max_columns = max_columns.max(column_tracks.len()).max(1);
column_tracks.resize(max_columns, TableColumnConstraint::auto());
@@ -439,7 +506,9 @@ where
end: style_helpers::span(cell.row_span as u16),
};
clear_table_cell_inline_sizing(&mut cell.style, writing_mode);
- block::clear_cell_block_sizing(&mut cell.style, writing_mode);
+ if writing_mode.is_horizontal() {
+ block::clear_cell_block_sizing(&mut cell.style, writing_mode);
+ }
}
let placeholder_track: taffy::TrackSizingFunction = style_helpers::auto();
style.grid_template_columns =
@@ -464,6 +533,14 @@ where
bottom: style_helpers::length(padding.bottom + spacing.height),
};
}
+ let section_tracks = if writing_mode.is_horizontal() {
+ Vec::new()
+ } else {
+ sections
+ .iter()
+ .map(|section| section.rows.clone())
+ .collect()
+ };
TableContext {
style,
cells,
@@ -477,7 +554,9 @@ where
column_sizes: Vec::new(),
sections,
section_boxes,
- section_tracks: Vec::new(),
+ section_tracks,
+ measured_baselines: (None, None),
+ caption_inline_min: 0.0,
layout_mode,
inline_border_spacing: spacing.width,
block_border_spacing: spacing.height,
@@ -498,7 +577,11 @@ impl TableContext {
}
let mut cell_constraints = vec![None; self.column_count];
let mut cell_spans = Vec::new();
- for cell in self.cells.iter().filter(|cell| cell.row == 0) {
+ let first_row_cells = self
+ .rows
+ .first()
+ .map_or(&[][..], |row| &self.cells[row.cells()]);
+ for cell in first_row_cells {
let constraint = authored_table_cell_inline_constraint(
&world.boxes[cell.id.index()].style.taffy,
self.writing_mode,
@@ -521,12 +604,45 @@ impl TableContext {
where
N: Copy + Debug + Eq + Hash,
{
+ for &caption in &self.captions {
+ let style = &world.boxes[caption.index()].style.taffy;
+ let margin = style.margin.resolve_or_zero(None, resolve_stylo_calc_value);
+ let output = world.compute_child_size(
+ caption.to_taffy(),
+ LayoutInput {
+ known_dimensions: Size::NONE,
+ definite_dimensions: Size::NONE,
+ parent_size: Size::NONE,
+ parent_writing_mode: self.writing_mode,
+ available_space: self.writing_mode.to_physical(LogicalSize {
+ inline_size: AvailableSpace::MinContent,
+ block_size: AvailableSpace::MaxContent,
+ }),
+ sizing_mode: SizingMode::InherentSize,
+ sizing_purpose: SizingPurpose::IntrinsicContribution,
+ run_mode: RunMode::ComputeSize,
+ axis: RequestedAxis::from(self.writing_mode.inline_axis()),
+ block_auto_behavior: AutoSizeBehavior::FitContent,
+ vertical_margins_are_collapsible: Line::FALSE,
+ },
+ );
+ // Captions belong to the wrapper, but their minimum outer width
+ // also constrains its grid, including anonymous tables.
+ self.caption_inline_min = self.caption_inline_min.max(
+ self.writing_mode.to_logical(output.size).inline_size
+ + physical_inline_sum(self.writing_mode, margin),
+ );
+ }
let mut cell_constraints = vec![None; self.column_count];
let mut cell_spans = Vec::new();
- for cell in &self.cells {
- if self.layout_mode.is_fixed() && cell.row != 0 {
- continue;
- }
+ let measured_cells = if self.layout_mode.is_fixed() {
+ self.rows
+ .first()
+ .map_or(&[][..], |row| &self.cells[row.cells()])
+ } else {
+ &self.cells
+ };
+ for cell in measured_cells {
let constraint =
table_cell_inline_constraint(world, cell.id, self.writing_mode, self.layout_mode);
collect_cell_constraint(cell, constraint, &mut cell_constraints, &mut cell_spans);
@@ -558,11 +674,13 @@ impl TableContext {
let internal_spacing =
self.inline_border_spacing.max(0.0) * self.column_count.saturating_sub(1) as f32;
let undistributable_space = inline_insets + internal_spacing;
- let grid_min_max = compute_grid_inline_min_max(
+ let mut grid_min_max = compute_grid_inline_min_max(
&self.column_constraints,
undistributable_space,
self.layout_mode,
);
+ grid_min_max.min = grid_min_max.min.max(self.caption_inline_min);
+ grid_min_max.max = grid_min_max.max.max(self.caption_inline_min);
let preferred_inline_size = self.writing_mode.to_logical(self.style.size).inline_size;
let intrinsic_inline_sizes = TableIntrinsicInlineSizes::from_grid(
grid_min_max,
@@ -695,7 +813,7 @@ impl TableContext {
if let Some(min_size) = min_size {
used = used.max(min_size);
}
- used.max(inline_insets)
+ used.max(inline_insets).max(self.caption_inline_min)
}
fn fixed_grid_min_border_box_size(&self) -> Option<f32> {
@@ -783,12 +901,7 @@ fn collect_rows<N>(
}
LayoutBoxKind::TableRow | LayoutBoxKind::AnonymousTableRow => {
let row_index = rows.len();
- rows.push(TableRow {
- id: current,
- group,
- index: row_index,
- grid_index: row_index,
- });
+ let start_cell_index = cells.len();
for cell in world.boxes[current.index()].children.iter().copied() {
if !matches!(
world.boxes[cell.index()].kind,
@@ -822,11 +935,34 @@ fn collect_rows<N>(
block_layout: None,
});
}
+ rows.push(TableRow {
+ id: current,
+ group,
+ index: row_index,
+ grid_index: row_index,
+ start_cell_index,
+ cell_count: cells.len() - start_cell_index,
+ section_end: 0,
+ });
}
_ => {}
}
}
+/// Cache the end of each contiguous placement group in one reverse pass.
+/// Consecutive ungrouped rows share a boundary, just as grouped rows do.
+fn index_row_sections(rows: &mut [TableRow]) {
+ let mut next_group = None;
+ let mut section_end = rows.len();
+ for row in rows.iter_mut().rev() {
+ if next_group != Some(row.group) {
+ section_end = row.index + 1;
+ next_group = Some(row.group);
+ }
+ row.section_end = section_end;
+ }
+}
+
fn place_table_cells(cells: &mut [TableCell], rows: &[TableRow], max_columns: &mut usize) {
let mut occupied_until = Vec::<usize>::new();
let mut active_group = None;
@@ -836,13 +972,9 @@ fn place_table_cells(cells: &mut [TableCell], rows: &[TableRow], max_columns: &m
occupied_until.clear();
active_group = Some(row.group);
}
- let section_end = rows
- .iter()
- .skip(row.index + 1)
- .find(|candidate| candidate.group != row.group)
- .map_or(rows.len(), |candidate| candidate.index);
+ let section_end = row.section_end;
let mut cursor = 0usize;
- for cell in cells.iter_mut().filter(|cell| cell.row == row.index) {
+ for cell in &mut cells[row.cells()] {
let span = cell.column_span.max(1);
loop {
let end = cursor.saturating_add(span);
@@ -1631,6 +1763,8 @@ mod tests {
Some(80.0),
));
world.boxes[root.index()].children = vec![caption, group];
+ world.boxes[caption.index()].parent = Some(root);
+ world.boxes[group.index()].parent = Some(root);
let mut cells = Vec::new();
for height in [10.0, 30.0] {
let row = world.allocate(make_box(
@@ -1645,9 +1779,14 @@ mod tests {
));
world.boxes[group.index()].children.push(row);
world.boxes[row.index()].children.push(cell);
+ world.boxes[row.index()].parent = Some(group);
+ world.boxes[cell.index()].parent = Some(row);
cells.push(cell);
}
- prepare_table_layout_trees(&mut world);
+ let mut prepared = crate::taffy_tree::prepare_world_layout(
+ &mut world,
+ crate::PaintViewport::new(800, 600, 1.0),
+ );
let inputs = LayoutInput {
known_dimensions: Size {
width: Some(200.0),
@@ -1684,6 +1823,16 @@ mod tests {
for id in cells.iter().chain([&caption, &group]) {
assert_eq!(world.boxes[id.index()].unrounded_layout.size, Size::ZERO);
}
+ assert_eq!(cold.first_baselines.y, Some(40.0));
+ assert_eq!(cold, world.compute_child_layout(root.to_taffy(), inputs));
+ assert_eq!(
+ world.boxes[root.index()]
+ .table_measure_cache
+ .as_ref()
+ .unwrap()
+ .computations,
+ 1
+ );
let final_layout = world.compute_child_layout(
root.to_taffy(),
LayoutInput {
@@ -1693,7 +1842,7 @@ mod tests {
);
let warm = world.compute_child_layout(root.to_taffy(), inputs);
assert_eq!(cold.size, final_layout.size);
- assert_eq!(cold.size, warm.size);
+ assert_eq!(cold, warm);
assert_eq!(
world.boxes[group.index()].unrounded_layout.size.height,
80.0
@@ -1706,6 +1855,196 @@ mod tests {
world.boxes[cells[1].index()].unrounded_layout.size.height,
60.0
);
+ world.boxes[group.index()].style.taffy.size.height = Dimension::length(120.0);
+ prepared.invalidate_scrollbar_feedback(&mut world, &[group], false);
+ let changed = world.compute_child_layout(root.to_taffy(), inputs);
+ assert_eq!(changed.size.height, 140.0);
+ assert_eq!(changed.first_baselines.y, Some(50.0));
+ assert_eq!(
+ world.boxes[root.index()]
+ .table_measure_cache
+ .as_ref()
+ .unwrap()
+ .computations,
+ 2
+ );
+ }
+
+ #[test]
+ fn indexed_placement_clips_spans_at_group_boundaries_including_ungrouped_rows() {
+ let a = LayoutBoxId::from_index(20);
+ let b = LayoutBoxId::from_index(21);
+ let groups = [Some(a), Some(a), Some(a), None, None, Some(b), None];
+ let counts = [1, 1, 0, 1, 1, 1, 1];
+ let spans = [(2, 0), (1, 99), (1, 0), (1, 1), (1, 99), (1, 0)];
+ let mut rows = Vec::new();
+ let mut cells = Vec::new();
+ for (index, (&group, &cell_count)) in groups.iter().zip(&counts).enumerate() {
+ rows.push(TableRow {
+ id: LayoutBoxId::from_index(index),
+ group,
+ index,
+ grid_index: index,
+ start_cell_index: cells.len(),
+ cell_count,
+ section_end: 0,
+ });
+ for _ in 0..cell_count {
+ let (column_span, row_span) = spans[cells.len()];
+ cells.push(TableCell {
+ id: LayoutBoxId::from_index(30 + cells.len()),
+ style: Style::default(),
+ row: index,
+ column: 0,
+ row_span,
+ column_span,
+ block_layout: None,
+ });
+ }
+ }
+ index_row_sections(&mut rows);
+ assert_eq!(
+ rows.iter().map(|row| row.section_end).collect::<Vec<_>>(),
+ [3, 3, 3, 5, 5, 6, 7]
+ );
+ let mut columns = 0;
+ place_table_cells(&mut cells, &rows, &mut columns);
+ assert_eq!(columns, 3);
+ assert_eq!(
+ cells
+ .iter()
+ .map(|cell| (cell.column, cell.row_span))
+ .collect::<Vec<_>>(),
+ [(0, 3), (2, 2), (0, 2), (1, 1), (0, 1), (0, 1)]
+ );
+ }
+
+ #[test]
+ fn nested_table_measurements_reuse_baselines_with_bounded_work() {
+ use crate::{LayoutDisplay, PaintColor, ResolvedLayoutStyle};
+
+ let make_box = |kind, display, height| {
+ LayoutWorld::<usize>::new_box(
+ None,
+ None,
+ None,
+ "nested-table-cache".into(),
+ None,
+ None,
+ None,
+ kind,
+ ResolvedLayoutStyle::synthetic(
+ display,
+ Style {
+ size: Size {
+ width: Dimension::length(100.0),
+ height,
+ },
+ ..Style::default()
+ },
+ PaintColor::TRANSPARENT,
+ ),
+ None,
+ )
+ };
+ for depth in [2, 4, 8, 16] {
+ let mut world = LayoutWorld::new(
+ make_box(
+ LayoutBoxKind::TableWrapper,
+ LayoutDisplay::Table,
+ Dimension::auto(),
+ ),
+ false,
+ );
+ let root = world.root();
+ let mut table = root;
+ for level in 0..depth {
+ let row = world.allocate(make_box(
+ LayoutBoxKind::TableRow,
+ LayoutDisplay::TableRow,
+ Dimension::auto(),
+ ));
+ let cell = world.allocate(make_box(
+ LayoutBoxKind::TableCell,
+ LayoutDisplay::TableCell,
+ Dimension::auto(),
+ ));
+ let nested = level + 1 < depth;
+ let child = world.allocate(make_box(
+ if nested {
+ LayoutBoxKind::TableWrapper
+ } else {
+ LayoutBoxKind::PrincipalBlock
+ },
+ if nested {
+ LayoutDisplay::Table
+ } else {
+ LayoutDisplay::Block
+ },
+ if nested {
+ Dimension::auto()
+ } else {
+ Dimension::length(10.0)
+ },
+ ));
+ for (parent, child) in [(table, row), (row, cell), (cell, child)] {
+ world.boxes[parent.index()].children.push(child);
+ world.boxes[child.index()].parent = Some(parent);
+ }
+ table = child;
+ }
+ crate::taffy_tree::prepare_world_layout(
+ &mut world,
+ crate::PaintViewport::new(800, 600, 1.0),
+ );
+ let inputs = LayoutInput {
+ run_mode: RunMode::ComputeSize,
+ known_dimensions: Size {
+ width: Some(100.0),
+ height: None,
+ },
+ ..LayoutInput::HIDDEN
+ };
+ let cold = world.compute_child_layout(root.to_taffy(), inputs);
+ assert_eq!(
+ cold.size,
+ Size {
+ width: 100.0,
+ height: 10.0
+ }
+ );
+ assert_eq!(cold.first_baselines.y, Some(10.0));
+ let computations = |world: &LayoutWorld<usize>| {
+ world
+ .boxes
+ .iter()
+ .filter_map(|b| b.table_measure_cache.as_ref())
+ .map(|c| c.computations)
+ .sum::<usize>()
+ };
+ let measured = computations(&world);
+ assert_eq!(
+ world
+ .boxes
+ .iter()
+ .filter(|b| b.table_measure_cache.is_some())
+ .count(),
+ depth
+ );
+ assert!(
+ measured <= depth * 8,
+ "depth={depth}, table measurements={measured}"
+ );
+ assert_eq!(cold, world.compute_child_layout(root.to_taffy(), inputs));
+ assert_eq!(
+ computations(&world),
+ measured,
+ "warm measurement must reuse the complete result"
+ );
+ eprintln!(
+ "nested tables: depth={depth}, cold measurements={measured}, warm measurements=0"
+ );
+ }
}
#[test]
diff --git a/moli-layout/src/table/block.rs b/moli-layout/src/table/block.rs
index b62eb7592..7bbf3b6a0 100644
--- a/moli-layout/src/table/block.rs
+++ b/moli-layout/src/table/block.rs
@@ -95,6 +95,12 @@ impl TableContext {
N: Copy + Debug + Eq + Hash,
{
let mode = self.writing_mode;
+ // The Grid backend still places table tracks on physical axes. Keep
+ // the existing vertical-table path until that boundary is converted;
+ // logical block constraints must not become physical row heights.
+ if !mode.is_horizontal() {
+ return inputs;
+ }
// Inline-only intrinsic probes do not need a second cell measurement.
if inputs.run_mode == RunMode::ComputeSize
&& inputs.axis == RequestedAxis::from(mode.inline_axis())
@@ -158,16 +164,26 @@ impl TableContext {
})
.collect();
let mut spans = Vec::new();
+ let cell_percentage_basis = self.column_sizes.iter().sum::<f32>()
+ + self.inline_border_spacing * self.column_count.saturating_sub(1) as f32;
+ // The first cell pass uses the table content box, including outer
+ // spacing. The final pass uses the row width. Their padding can
+ // differ without shrinking the row's first-pass minimum.
+ let measurement_percentage_basis = cell_percentage_basis + 2.0 * self.inline_border_spacing;
+ let mut fallback_descents = vec![None::<f32>; rows.len()];
for index in 0..self.cells.len() {
let cell = &self.cells[index];
let authored_style = &world.boxes[cell.id.index()].style.taffy;
let dimension = mode.to_logical(authored_style.size).block_size;
let cell_padding = authored_style
.padding
- .resolve_or_zero(space.known_size.inline_size, resolve_stylo_calc_value);
+ .resolve_or_zero(Some(measurement_percentage_basis), resolve_stylo_calc_value);
+ let final_padding = authored_style
+ .padding
+ .resolve_or_zero(Some(cell_percentage_basis), resolve_stylo_calc_value);
let cell_border = authored_style
.border
- .resolve_or_zero(space.known_size.inline_size, resolve_stylo_calc_value);
+ .resolve_or_zero(Some(cell_percentage_basis), resolve_stylo_calc_value);
let cell_insets = block_sum(mode, cell_padding) + block_sum(mode, cell_border);
let css_size = outer_fixed_size(dimension, cell_insets, authored_style.box_sizing);
let cell_percent = percent(dimension);
@@ -204,8 +220,7 @@ impl TableContext {
block_auto_behavior: AutoSizeBehavior::FitContent,
vertical_margins_are_collapsible: Line::FALSE,
};
- // Percentage padding is relative to the table, not the cell's
- // Grid area. Freeze that basis across both measurement and layout.
+ // Freeze the measurement basis while determining the row minimum.
self.cells[index].style.padding = cell_padding.map(style_helpers::length);
let restricted = !preferred.is_auto() || fixed(dimension).is_some();
let cell_id = self.cells[index].id;
@@ -218,6 +233,7 @@ impl TableContext {
let output = wrapper.with_grid_cell_style(index, |world, cell| {
world.compute_child_layout(cell.to_taffy(), measure_inputs)
});
+ self.cells[index].style.padding = final_padding.map(style_helpers::length);
for (id, style) in restored {
world.boxes[id.index()].style.taffy = style;
world.cache_clear(id.to_taffy());
@@ -234,6 +250,11 @@ impl TableContext {
} else {
cell_padding.left + cell_border.left
};
+ fallback_descents[cell.row] = Some(
+ fallback_descents[cell.row]
+ .unwrap_or(f32::INFINITY)
+ .min(end_inset),
+ );
let baseline = (baseline_aligned && !world.boxes[cell.id.index()].children.is_empty())
.then(|| baseline.unwrap_or((natural - end_inset).max(0.0)));
cell.block_layout = Some(CellBlockLayout {
@@ -362,6 +383,37 @@ impl TableContext {
.max(0.0),
);
}
+ let mut position = padding.top + border.top
+ - if explicit_spacing {
+ self.block_border_spacing
+ } else {
+ 0.0
+ };
+ let starts: Vec<_> = tracks
+ .iter()
+ .map(|&size| {
+ let start = position;
+ position += size
+ + if explicit_spacing {
+ 0.0
+ } else {
+ self.block_border_spacing
+ };
+ start
+ })
+ .collect();
+ let baseline = |index: usize| {
+ starts[self.rows[index].grid_index]
+ + rows[index].ascent.unwrap_or_else(|| {
+ fallback_descents[index]
+ .map_or(0.0, |descent| (rows[index].size - descent).max(0.0))
+ })
+ };
+ self.measured_baselines = if rows.is_empty() {
+ (None, None)
+ } else {
+ (Some(baseline(0)), Some(baseline(rows.len() - 1)))
+ };
self.style.grid_template_rows = tracks
.into_iter()
.map(|size| {
@@ -449,7 +501,16 @@ where
.taffy
.padding
.resolve_or_zero(inputs.parent_size.width, resolve_stylo_calc_value);
- output.first_baselines.y = Some(if inputs.run_mode == RunMode::PerformLayout {
+ output.first_baselines.y = Some(if !layout.definite {
+ let border = world.boxes[cell.index()]
+ .style
+ .taffy
+ .border
+ .resolve_or_zero(inputs.parent_size.width, resolve_stylo_calc_value);
+ // The natural border box includes empty block children whose
+ // overflow content size can be zero (for example an empty group).
+ (output.size.height - padding.bottom - border.bottom).max(0.0)
+ } else if inputs.run_mode == RunMode::PerformLayout {
(output.content_size.height - padding.bottom).max(0.0)
} else {
layout.baseline.unwrap_or(0.0)
diff --git a/moli-layout/src/table/cache.rs b/moli-layout/src/table/cache.rs
new file mode 100644
index 000000000..d767423e3
--- /dev/null
+++ b/moli-layout/src/table/cache.rs
@@ -0,0 +1,137 @@
+//! Pass-local table measurements, including baselines and content bounds.
+
+use taffy::{LayoutInput, LayoutOutput};
+
+const CAPACITY: usize = 8;
+
+/// Exact constraint matches avoid reusing a used size as a guarantee of
+/// percentage definiteness. Allocated only for measured tables, with a fixed
+/// entry limit independent of document size and the number of probes.
+#[derive(Debug, Default)]
+pub(crate) struct TableMeasureCache {
+ entries: Vec<(LayoutInput, LayoutOutput)>,
+ #[cfg(test)]
+ pub(super) computations: usize,
+}
+
+impl TableMeasureCache {
+ pub(crate) fn get(&mut self, inputs: LayoutInput) -> Option<LayoutOutput> {
+ let index = self.entries.iter().position(|(key, _)| *key == inputs)?;
+ let entry = self.entries.remove(index);
+ self.entries.push(entry);
+ Some(entry.1)
+ }
+
+ pub(crate) fn store(&mut self, inputs: LayoutInput, output: LayoutOutput) {
+ if let Some(index) = self.entries.iter().position(|(key, _)| *key == inputs) {
+ self.entries.remove(index);
+ } else if self.entries.len() == CAPACITY {
+ self.entries.remove(0);
+ }
+ self.entries.push((inputs, output));
+ #[cfg(test)]
+ {
+ self.computations += 1;
+ }
+ }
+
+ pub(crate) fn clear(&mut self) {
+ self.entries.clear();
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use taffy::{AvailableSpace, Point, RunMode, Size, SizingPurpose, WritingMode};
+
+ fn inputs(width: f32) -> LayoutInput {
+ LayoutInput {
+ run_mode: RunMode::ComputeSize,
+ known_dimensions: Size {
+ width: Some(width),
+ height: Some(100.0),
+ },
+ ..LayoutInput::HIDDEN
+ }
+ }
+
+ #[test]
+ fn measured_baselines_survive_reuse_but_not_different_constraints() {
+ let mut cache = TableMeasureCache::default();
+ let input = inputs(80.0);
+ let output = LayoutOutput::from_sizes_and_baseline_sets(
+ Size {
+ width: 80.0,
+ height: 100.0,
+ },
+ Size {
+ width: 80.0,
+ height: 120.0,
+ },
+ Point {
+ x: None,
+ y: Some(15.0),
+ },
+ Point {
+ x: None,
+ y: Some(85.0),
+ },
+ );
+ cache.store(input, output);
+ assert_eq!(cache.get(input), Some(output));
+ for changed in [
+ LayoutInput {
+ definite_dimensions: input.known_dimensions,
+ ..input
+ },
+ LayoutInput {
+ parent_size: input.known_dimensions,
+ ..input
+ },
+ LayoutInput {
+ parent_writing_mode: WritingMode::VerticalRl,
+ ..input
+ },
+ LayoutInput {
+ available_space: Size {
+ width: AvailableSpace::MinContent,
+ height: AvailableSpace::MaxContent,
+ },
+ ..input
+ },
+ LayoutInput {
+ sizing_purpose: SizingPurpose::IntrinsicContribution,
+ ..input
+ },
+ LayoutInput {
+ run_mode: RunMode::PerformLayout,
+ ..input
+ },
+ ] {
+ assert!(
+ cache.get(changed).is_none(),
+ "constraints must match: {changed:?}"
+ );
+ }
+ cache.clear();
+ assert!(cache.get(input).is_none());
+ }
+
+ #[test]
+ fn measurements_are_bounded_and_recently_used_entries_survive_eviction() {
+ let mut cache = TableMeasureCache::default();
+ for index in 0..CAPACITY {
+ cache.store(inputs(index as f32), LayoutOutput::HIDDEN);
+ }
+ assert!(cache.get(inputs(0.0)).is_some());
+ cache.store(inputs(CAPACITY as f32), LayoutOutput::HIDDEN);
+ assert_eq!(cache.entries.len(), CAPACITY);
+ assert!(cache.get(inputs(0.0)).is_some());
+ assert!(cache.get(inputs(1.0)).is_none());
+ for index in 0..100 {
+ cache.store(inputs(index as f32), LayoutOutput::HIDDEN);
+ assert!(cache.entries.len() <= CAPACITY);
+ }
+ }
+}
diff --git a/moli-layout/src/taffy_tree.rs b/moli-layout/src/taffy_tree.rs
index a56fb6e71..73026a17a 100644
--- a/moli-layout/src/taffy_tree.rs
+++ b/moli-layout/src/taffy_tree.rs
@@ -109,7 +109,7 @@ impl PreparedWorldLayout {
}
self.feedback_invalidation_marks[id.index()] = true;
invalidated.push(id);
- world.boxes[id.index()].cache.clear();
+ world.boxes[id.index()].clear_layout_caches();
if let Some(parent) = world.boxes[id.index()].layout_parent {
self.feedback_invalidation_worklist.push(parent);
}
@@ -135,7 +135,7 @@ where
N: Copy + Debug + Eq + Hash,
{
for layout_box in &mut world.boxes {
- layout_box.cache.clear();
+ layout_box.clear_layout_caches();
layout_box.unrounded_layout = Layout::with_order(0);
layout_box.final_layout = Layout::with_order(0);
layout_box.layout_parent = None;
@@ -1662,6 +1662,28 @@ where
if self.should_hide(node_id, inputs) {
return compute_hidden_layout(self, node_id);
}
+ let style = &self.boxes[LayoutBoxId::from_taffy(node_id).index()].style;
+ if inputs.run_mode == RunMode::ComputeSize
+ && style.taffy.item_is_table
+ && inputs.axis != taffy::RequestedAxis::from(style.writing_mode().inline_axis())
+ {
+ // The compact intrinsic-size cache drops baselines. Table
+ // measurement needs the complete result, without final fragments.
+ let id = LayoutBoxId::from_taffy(node_id);
+ if let Some(output) = self.boxes[id.index()]
+ .table_measure_cache
+ .as_mut()
+ .and_then(|cache| cache.get(inputs))
+ {
+ return output;
+ }
+ let output = self.compute_child_layout_uncached(node_id, inputs, None);
+ self.boxes[id.index()]
+ .table_measure_cache
+ .get_or_insert_with(Default::default)
+ .store(inputs, output);
+ return output;
+ }
compute_cached_layout(self, node_id, inputs, |world, node_id, inputs| {
world.compute_child_layout_uncached(node_id, inputs, None)
})
@@ -1701,9 +1723,7 @@ where
if self.is_viewport_taffy_node(node_id) {
self.viewport_layout.cache.clear();
} else {
- self.boxes[LayoutBoxId::from_taffy(node_id).index()]
- .cache
- .clear();
+ self.boxes[LayoutBoxId::from_taffy(node_id).index()].clear_layout_caches();
}
}
}
diff --git a/moli-layout/src/world.rs b/moli-layout/src/world.rs
index 24a37f24a..24da5a9ef 100644
--- a/moli-layout/src/world.rs
+++ b/moli-layout/src/world.rs
@@ -280,6 +280,7 @@ pub struct LayoutBox<N> {
/// object. It is frozen with the rest of the layout tree for CSSOM reads.
pub(crate) resolved_grid_tracks: Option<LayoutResolvedGridTracks>,
pub(crate) cache: Cache,
+ pub(crate) table_measure_cache: Option<Box<crate::table::TableMeasureCache>>,
pub(crate) unrounded_layout: Layout,
pub(crate) final_layout: Layout,
}
@@ -503,6 +504,13 @@ impl Default for ViewportLayoutState {
}
impl<N> LayoutBox<N> {
+ pub(crate) fn clear_layout_caches(&mut self) {
+ self.cache.clear();
+ if let Some(cache) = &mut self.table_measure_cache {
+ cache.clear();
+ }
+ }
+
pub fn kind(&self) -> LayoutBoxKind {
self.kind
}
@@ -1133,6 +1141,7 @@ where
inline_formatting_context: false,
resolved_grid_tracks: None,
cache: Cache::new(),
+ table_measure_cache: None,
unrounded_layout: Layout::with_order(0),
final_layout: Layout::with_order(0),
}
diff --git a/moli-renderer-v8/tests/fixtures/table-row-heights.chromium.json b/moli-renderer-v8/tests/fixtures/table-row-heights.chromium.json
index 28d2a5e73..d9817fc72 100644
--- a/moli-renderer-v8/tests/fixtures/table-row-heights.chromium.json
+++ b/moli-renderer-v8/tests/fixtures/table-row-heights.chromium.json
@@ -58,7 +58,15 @@
{"name": "percent-scroll-cell", "rects": [[0, 0, 240, 103], [0, 0, 200, 100], [0, 0, 200, 100], [0, 0, 200, 100], [0, 0, 200, 100], [0, 0, 200, 100], [0, 0, 200, 200], [0, 100, 240, 3]]},
{"name": "percent-baseline", "rects": [[0, 0, 240, 103], [0, 0, 200, 100], [0, 0, 200, 100], [0, 0, 200, 100], [0, 0, 100, 100], [0, 0, 10, 50], [100, 0, 100, 100], [100, 30, 10, 20], [0, 100, 240, 3]]},
{"name": "cell-padding", "rects": [[0, 0, 240, 103], [0, 0, 200, 100], [0, 0, 200, 100], [0, 0, 200, 100], [0, 0, 100, 100], [10, 45, 80, 10], [100, 0, 100, 100], [110, 80, 80, 10], [0, 100, 240, 3]]},
- {"name": "rtl", "rects": [[0, 0, 240, 83], [0, 0, 200, 80], [0, 0, 200, 80], [0, 0, 200, 20], [0, 0, 200, 20], [190, 5, 10, 10], [0, 20, 200, 60], [0, 20, 200, 60], [190, 35, 10, 30], [0, 80, 240, 3]]}
+ {"name": "rtl", "rects": [[0, 0, 240, 83], [0, 0, 200, 80], [0, 0, 200, 80], [0, 0, 200, 20], [0, 0, 200, 20], [190, 5, 10, 10], [0, 20, 200, 60], [0, 20, 200, 60], [190, 35, 10, 30], [0, 80, 240, 3]]},
+ {"name": "percentage-padding-spacing", "rects": [[0, 0, 240, 81], [0, 0, 200, 78], [15, 15, 170, 48], [15, 15, 170, 48], [15, 15, 170, 48], [32, 34, 10, 10], [0, 78, 240, 3]]},
+ {"name": "caption-inflexible-row", "rects": [[0, 0, 100, 100], [0, 0, 100, 30]]},
+ {"name": "caption-inflexible-column", "rects": [[0, 0, 100, 100], [0, 0, 100, 30]]},
+ {"name": "caption-no-grow", "rects": [[0, 0, 200, 100], [0, 0, 200, 10], [0, 10, 200, 90], [0, 10, 200, 90], [0, 10, 200, 90]]},
+ {"name": "nested-anonymous-baseline", "rects": [[0, 0, 40, 40], [0, 0, 40, 20], [0, 0, 20, 20], [0, 0, 20, 20], [20, 10, 20, 10], [20, 10, 20, 10], [0, 20, 40, 20], [0, 30, 20, 10], [0, 30, 20, 10], [20, 20, 20, 20], [20, 20, 20, 20]]},
+ {"name": "nested-table-baselines", "rects": [[0, 0, 40, 40], [0, 0, 40, 20], [0, 0, 20, 20], [0, 0, 20, 10], [0, 10, 20, 10], [20, 0, 20, 20], [20, 0, 20, 10], [20, 10, 20, 10], [0, 20, 40, 20], [0, 20, 20, 20], [0, 20, 20, 10], [0, 30, 20, 10], [20, 20, 20, 20], [20, 20, 20, 10], [20, 30, 20, 10]]},
+ {"name": "anonymous-caption-minimum", "rects": [[0, 0, 120, 50], [0, 0, 100, 10], [0, 0, 20, 10], [0, 10, 100, 40], [0, 10, 100, 40]]},
+ {"name": "nested-empty-group", "rects": [[0, 0, 40, 40], [0, 0, 40, 20], [0, 4, 0, 16], [20, 0, 20, 20], [20, 0, 20, 20], [0, 20, 40, 20], [0, 20, 20, 20], [0, 20, 20, 20], [20, 20, 20, 20], [20, 20, 20, 20]]}
],
[
{"name": "thead-fixed", "rects": [[0, 0, 240, 99], [0, 0, 160, 96], [0, 0, 160, 96], [0, 0, 160, 24], [0, 0, 160, 24], [0, 7, 10, 10], [0, 24, 160, 72], [0, 24, 160, 72], [0, 45, 10, 30], [0, 96, 240, 3]]},
@@ -116,7 +124,15 @@
{"name": "percent-scroll-cell", "rects": [[0, 0, 240, 103], [0, 0, 160, 100], [0, 0, 160, 100], [0, 0, 160, 100], [0, 0, 160, 100], [0, 0, 160, 100], [0, 0, 160, 200], [0, 100, 240, 3]]},
{"name": "percent-baseline", "rects": [[0, 0, 240, 103], [0, 0, 160, 100], [0, 0, 160, 100], [0, 0, 160, 100], [0, 0, 80, 100], [0, 0, 10, 50], [80, 0, 80, 100], [80, 30, 10, 20], [0, 100, 240, 3]]},
{"name": "cell-padding", "rects": [[0, 0, 240, 99], [0, 0, 160, 96], [0, 0, 160, 96], [0, 0, 160, 96], [0, 0, 80, 96], [10, 43, 60, 10], [80, 0, 80, 96], [88, 78, 64, 10], [0, 96, 240, 3]]},
- {"name": "rtl", "rects": [[0, 0, 240, 99], [0, 0, 160, 96], [0, 0, 160, 96], [0, 0, 160, 24], [0, 0, 160, 24], [150, 7, 10, 10], [0, 24, 160, 72], [0, 24, 160, 72], [150, 45, 10, 30], [0, 96, 240, 3]]}
+ {"name": "rtl", "rects": [[0, 0, 240, 99], [0, 0, 160, 96], [0, 0, 160, 96], [0, 0, 160, 24], [0, 0, 160, 24], [150, 7, 10, 10], [0, 24, 160, 72], [0, 24, 160, 72], [150, 45, 10, 30], [0, 96, 240, 3]]},
+ {"name": "percentage-padding-spacing", "rects": [[0, 0, 240, 129], [0, 0, 160, 126], [15, 15, 130, 96], [15, 15, 130, 96], [15, 15, 130, 96], [28, 58, 10, 10], [0, 126, 240, 3]]},
+ {"name": "caption-inflexible-row", "rects": [[0, 0, 100, 100], [0, 0, 100, 30]]},
+ {"name": "caption-inflexible-column", "rects": [[0, 0, 100, 100], [0, 0, 100, 30]]},
+ {"name": "caption-no-grow", "rects": [[0, 0, 160, 106], [0, 0, 160, 10], [0, 10, 160, 96], [0, 10, 160, 96], [0, 10, 160, 96]]},
+ {"name": "nested-anonymous-baseline", "rects": [[0, 0, 40, 40], [0, 0, 40, 20], [0, 0, 20, 20], [0, 0, 20, 20], [20, 10, 20, 10], [20, 10, 20, 10], [0, 20, 40, 20], [0, 30, 20, 10], [0, 30, 20, 10], [20, 20, 20, 20], [20, 20, 20, 20]]},
+ {"name": "nested-table-baselines", "rects": [[0, 0, 40, 40], [0, 0, 40, 20], [0, 0, 20, 20], [0, 0, 20, 10], [0, 10, 20, 10], [20, 0, 20, 20], [20, 0, 20, 10], [20, 10, 20, 10], [0, 20, 40, 20], [0, 20, 20, 20], [0, 20, 20, 10], [0, 30, 20, 10], [20, 20, 20, 20], [20, 20, 20, 10], [20, 30, 20, 10]]},
+ {"name": "anonymous-caption-minimum", "rects": [[0, 0, 120, 50], [0, 0, 100, 10], [0, 0, 20, 10], [0, 10, 100, 40], [0, 10, 100, 40]]},
+ {"name": "nested-empty-group", "rects": [[0, 0, 40, 40], [0, 0, 40, 20], [0, 4, 0, 16], [20, 0, 20, 20], [20, 0, 20, 20], [0, 20, 40, 20], [0, 20, 20, 20], [0, 20, 20, 20], [20, 20, 20, 20], [20, 20, 20, 20]]}
],
[
{"name": "thead-fixed", "rects": [[0, 0, 240, 43], [0, 0, 200, 40], [0, 0, 200, 40], [0, 0, 200, 10], [0, 0, 200, 10], [0, 0, 10, 10], [0, 10, 200, 30], [0, 10, 200, 30], [0, 10, 10, 30], [0, 40, 240, 3]]},
@@ -174,7 +190,15 @@
{"name": "percent-scroll-cell", "rects": [[0, 0, 240, 103], [0, 0, 200, 100], [0, 0, 200, 100], [0, 0, 200, 100], [0, 0, 200, 100], [0, 0, 200, 100], [0, 0, 200, 200], [0, 100, 240, 3]]},
{"name": "percent-baseline", "rects": [[0, 0, 240, 103], [0, 0, 200, 100], [0, 0, 200, 100], [0, 0, 200, 100], [0, 0, 100, 100], [0, 0, 10, 50], [100, 0, 100, 100], [100, 30, 10, 20], [0, 100, 240, 3]]},
{"name": "cell-padding", "rects": [[0, 0, 240, 63], [0, 0, 200, 60], [0, 0, 200, 60], [0, 0, 200, 60], [0, 0, 100, 60], [10, 25, 80, 10], [100, 0, 100, 60], [110, 40, 80, 10], [0, 60, 240, 3]]},
- {"name": "rtl", "rects": [[0, 0, 240, 43], [0, 0, 200, 40], [0, 0, 200, 40], [0, 0, 200, 10], [0, 0, 200, 10], [190, 0, 10, 10], [0, 10, 200, 30], [0, 10, 200, 30], [190, 10, 10, 30], [0, 40, 240, 3]]}
+ {"name": "rtl", "rects": [[0, 0, 240, 43], [0, 0, 200, 40], [0, 0, 200, 40], [0, 0, 200, 10], [0, 0, 200, 10], [190, 0, 10, 10], [0, 10, 200, 30], [0, 10, 200, 30], [190, 10, 10, 30], [0, 40, 240, 3]]},
+ {"name": "percentage-padding-spacing", "rects": [[0, 0, 240, 81], [0, 0, 200, 78], [15, 15, 170, 48], [15, 15, 170, 48], [15, 15, 170, 48], [32, 34, 10, 10], [0, 78, 240, 3]]},
+ {"name": "caption-inflexible-row", "rects": [[0, 0, 100, 100], [0, 0, 100, 30]]},
+ {"name": "caption-inflexible-column", "rects": [[0, 0, 100, 100], [0, 0, 100, 30]]},
+ {"name": "caption-no-grow", "rects": [[0, 0, 200, 100], [0, 0, 200, 10], [0, 10, 200, 90], [0, 10, 200, 90], [0, 10, 200, 90]]},
+ {"name": "nested-anonymous-baseline", "rects": [[0, 0, 40, 40], [0, 0, 40, 20], [0, 0, 20, 20], [0, 0, 20, 20], [20, 10, 20, 10], [20, 10, 20, 10], [0, 20, 40, 20], [0, 30, 20, 10], [0, 30, 20, 10], [20, 20, 20, 20], [20, 20, 20, 20]]},
+ {"name": "nested-table-baselines", "rects": [[0, 0, 40, 40], [0, 0, 40, 20], [0, 0, 20, 20], [0, 0, 20, 10], [0, 10, 20, 10], [20, 0, 20, 20], [20, 0, 20, 10], [20, 10, 20, 10], [0, 20, 40, 20], [0, 20, 20, 20], [0, 20, 20, 10], [0, 30, 20, 10], [20, 20, 20, 20], [20, 20, 20, 10], [20, 30, 20, 10]]},
+ {"name": "anonymous-caption-minimum", "rects": [[0, 0, 120, 50], [0, 0, 100, 10], [0, 0, 20, 10], [0, 10, 100, 40], [0, 10, 100, 40]]},
+ {"name": "nested-empty-group", "rects": [[0, 0, 40, 40], [0, 0, 40, 20], [0, 4, 0, 16], [20, 0, 20, 20], [20, 0, 20, 20], [0, 20, 40, 20], [0, 20, 20, 20], [0, 20, 20, 20], [20, 20, 20, 20], [20, 20, 20, 20]]}
]
]
}
diff --git a/moli-renderer-v8/tests/fixtures/table-row-heights.html b/moli-renderer-v8/tests/fixtures/table-row-heights.html
index 9da6afafd..02b6e9def 100644
--- a/moli-renderer-v8/tests/fixtures/table-row-heights.html
+++ b/moli-renderer-v8/tests/fixtures/table-row-heights.html
@@ -23,6 +23,16 @@ function add(name, contents, tableStyle='', ownerStyle='', wrapperStyle='') {
document.body.append(owner);
cases.push({name, owner});
}
+function addMarkup(name, markup, ownerStyle='') {
+ const owner = document.createElement('div');
+ owner.className = 'case';
+ owner.style.fontSize = '0';
+ owner.style.lineHeight = '0';
+ owner.style.cssText += ownerStyle;
+ owner.innerHTML = markup;
+ document.body.append(owner);
+ cases.push({name, owner});
+}
function buildTableRowHeightCases() {
for (const tag of ['thead','tbody','tfoot']) {
add(`${tag}-fixed`, `<${tag} height="80">${row(10)}${row(30)}</${tag}>`);
@@ -76,6 +86,18 @@ function buildTableRowHeightCases() {
add('percent-baseline', '<tbody><tr><td style="height:100px;vertical-align:baseline"><div style="height:50%;width:10px"></div></td><td style="vertical-align:baseline"><div style="height:20px;width:10px"></div></td></tr></tbody>');
add('cell-padding', '<tbody style="height:100px"><tr><td style="height:40px;padding:10px;box-sizing:content-box"><div style="height:10px"></div></td><td style="padding:5%;vertical-align:bottom"><div style="height:10px"></div></td></tr></tbody>');
add('rtl', `<tbody style="height:80px">${row(10)}${row(30)}</tbody>`, 'direction:rtl');
+ add('percentage-padding-spacing', '<tbody><tr><td style="padding:10%"><div style="height:10px;width:10px"></div></td></tr></tbody>', 'border-spacing:10px;border:5px solid;box-sizing:border-box');
+ for (const direction of ['row', 'column']) {
+ addMarkup(`caption-inflexible-${direction}`, `<div style="display:table;box-sizing:content-box;border:10px solid;width:80px;height:50px;flex:0 0 ${direction==='row'?80:50}px"><div style="display:table-caption;height:10px;border:10px solid"></div></div>`, `display:flex;flex-direction:${direction};align-items:flex-start`);
+ }
+ addMarkup('caption-no-grow', '<table style="height:90px"><caption style="height:10px"></caption><tbody><tr><td></td></tr></tbody></table>', 'display:flex;flex-direction:column;align-items:flex-start');
+ addMarkup('nested-anonymous-baseline', '<div style="display:table"><div style="display:table-row"><div style="display:table-cell;vertical-align:baseline"><span style="display:inline-block;width:20px;height:20px"></span></div><div style="display:table-row"><span style="display:inline-block;width:20px;height:10px"></span></div></div><div style="display:table-row"><div style="display:table-row-group"><span style="display:inline-block;width:20px;height:10px"></span></div><div style="display:table-cell;vertical-align:baseline"><span style="display:inline-block;width:20px;height:20px"></span></div></div></div>');
+ const twoLines = '<span style="display:inline-block;width:20px;height:10px"></span>'.repeat(2);
+ // Absolute positioning measures the same nested table before final layout;
+ // a size-only cache hit must not replace its first baseline with its bottom.
+ addMarkup('nested-table-baselines', '<div style="position:absolute;width:40px">' + ['table', 'inline-table'].map(display => `<div style="display:table-row"><div style="display:table-cell;width:20px">${twoLines}</div><span style="display:${display};width:20px">${twoLines}</span></div>`).join('') + '</div>', 'position:relative');
+ addMarkup('anonymous-caption-minimum', '<div style="width:120px"><div style="display:table-cell"><span style="display:inline-block;width:20px;height:10px"></span></div><div style="display:table-caption;caption-side:bottom"><span style="display:inline-block;width:100px;height:40px"></span></div></div>');
+ addMarkup('nested-empty-group', '<div style="display:table"><div style="display:table-row"><div style="display:table-row-group;height:16px;width:16px"></div><div style="display:table-cell"><span style="display:inline-block;width:20px;height:20px"></span></div></div><div style="display:table-row"><div style="display:table-cell"><span style="display:inline-block;width:20px;height:20px"></span></div><div style="display:table-cell"><span style="display:inline-block;width:20px;height:20px"></span></div></div></div>');
for (const {owner} of cases) {
for (const el of owner.querySelectorAll('table,thead,tbody,tfoot,tr,td,th,caption')) {
el.dataset.originalHeight = el.style.height;
@@ -85,7 +107,8 @@ function buildTableRowHeightCases() {
function setTableRowHeightPhase(phase) {
for (const {owner} of cases) {
owner.style.height = phase===1 ? '320px' : '240px';
- owner.querySelector('table').style.width = phase===1 ? '160px' : '200px';
+ const table = owner.querySelector('table');
+ if (table) table.style.width = phase===1 ? '160px' : '200px';
for (const el of owner.querySelectorAll('thead,tbody,tfoot')) {
if (phase===1) el.style.height = '96px';
else if (phase===2) { el.style.height = 'auto'; el.removeAttribute('height'); }