Skip to content

The headless browser for AI agents and web scraping

fix(render): inherit font shorthand on native controls

SGavrl4e82527d00cb
diff --git a/crates/obscura-render/src/style.rs b/crates/obscura-render/src/style.rs
index 9cef7cc8..fd670531 100644
--- a/crates/obscura-render/src/style.rs
+++ b/crates/obscura-render/src/style.rs
@@ -7224,6 +7224,22 @@ pub(crate) fn line_height_expression_is_length(value: &str) -> bool {
/// the required size so modern design-system declarations reach the size,
/// line-height, weight, style, and family fields that affect our layout.
fn apply_font_shorthand(style: &mut LayoutStyle, value: &str) {
+ let value = value.trim();
+ if value.eq_ignore_ascii_case("inherit") || value.eq_ignore_ascii_case("unset") {
+ // All modeled font longhands are inherited. Clear earlier declarations,
+ // including native-control UA defaults, before the top-down pass.
+ style.font_size = None;
+ style.font_size_raw = None;
+ style.font_size_expression = None;
+ style.font_family = None;
+ style.font_weight = None;
+ style.font_style_italic = None;
+ style.font_optical_sizing = None;
+ style.font_variation_settings = None;
+ style.line_height = None;
+ style.line_height_expression = None;
+ return;
+ }
let tokens = split_ws_paren(value);
let Some((size_index, size, attached_line_height)) =
tokens.iter().enumerate().find_map(|(index, token)| {
diff --git a/crates/obscura-render/tests/layout_test.rs b/crates/obscura-render/tests/layout_test.rs
index c40f2bbd..647db96d 100644
--- a/crates/obscura-render/tests/layout_test.rs
+++ b/crates/obscura-render/tests/layout_test.rs
@@ -4485,6 +4485,28 @@ fn grid_replaced_classification_keeps_controls_stretched_and_media_natural() {
assert_eq!(auto_button.x + auto_button.width, auto_button_grid.x + auto_button_grid.width);
}
+#[test]
+fn inherited_font_shorthand_overrides_native_control_typography() {
+ let tree = parse_html(r#"
+ <style>
+ body { font:700 20px/30px Arial }
+ input { display:block; border:0; padding:0 }
+ </style>
+ <input id="inherit" style="font:inherit">
+ <input id="unset" style="font:unset">
+ "#);
+ let layout = layout_dom(&tree, (800.0, 600.0));
+ for name in ["inherit", "unset"] {
+ let node = tree.get_element_by_id(name).unwrap();
+ let style = &layout.styles[&node];
+ assert_eq!(style.font_size, Some(20.0), "{name}");
+ assert_eq!(style.line_height, Some(obscura_render::LineHeight::Px(30.0)), "{name}");
+ assert_eq!(style.font_weight.as_deref(), Some("700"), "{name}");
+ assert_eq!(style.font_family.as_deref(), Some("arial"), "{name}");
+ assert_eq!(layout.rects[&node].height, 30.0, "{name}");
+ }
+}
+
#[test]
fn grid_ordinary_aspect_ratio_preserves_normal_alignment_provenance() {
let tree = parse_html(