Keep positioned pseudos out of inline sizing

This commit is contained in:
SGavrl committed 2026-07-31 03:07:43 +00:00
1 parent 5c9f34fb34
commit 09bfe56589
2 files changed
+46 -1

No files matched your search

+32
View File
@@ -9435,6 +9435,38 @@ mod tests {
assert_eq!(pseudo.line_height, host.line_height);
}
#[test]
fn positioned_pseudo_does_not_wrap_shrink_to_fit_host_text() {
let tree = parse_html(
r#"<style>
html, body { margin:0 }
#host {
position:absolute; width:max-content;
padding:12px 24px; border:0;
font-size:14px; font-weight:600; color:transparent;
}
#host::after {
content:attr(text); position:absolute; inset:1px;
display:flex; align-items:center; justify-content:center;
color:black; background:white;
}
</style>
<button id="host" text="Learn more">Learn more</button>"#,
);
let laid = layout_dom(&tree, (500.0, 300.0));
let host = tree.get_element_by_id("host").unwrap();
let rect = laid.rects[&host];
assert!(
(120.0..=130.0).contains(&rect.width),
"max-content width must include the shaped inter-word advance: {rect:?}"
);
assert_eq!(
rect.height, 40.0,
"positioned generated content must not make the host label wrap"
);
}
#[test]
fn variable_font_properties_inherit_and_reset_through_elements_and_pseudos() {
let tree = parse_html(
+14 -1
View File
@@ -1568,7 +1568,20 @@ fn is_pure_text_ifc(
let Some(style) = styles.get(&id) else {
return false;
};
if style.before_pseudo.is_some() || style.after_pseudo.is_some() {
// Out-of-flow generated boxes neither contribute to nor interrupt the
// host's inline formatting context. Keeping a positioned decorative
// pseudo must not demote an otherwise text-only shrink-to-fit control to
// approximate per-word flex leaves: that path can disagree with shaped
// space advances and wrap text at its own max-content width.
let has_in_flow_pseudo = |pseudo: Option<&LayoutStyle>| {
pseudo.is_some_and(|pseudo| {
pseudo.display != Display::None
&& !matches!(pseudo.position, Some(taffy::Position::Absolute))
})
};
if has_in_flow_pseudo(style.before_pseudo.as_deref())
|| has_in_flow_pseudo(style.after_pseudo.as_deref())
{
return false;
}
// Only containers that lay their children out in normal flow (block, or