Truly independent web browser
LibWeb: Resolve a unitless line-height without a box
sideshowbarker1c716280bfb1
diff --git a/Libraries/LibWeb/Rust/src/css/resolved_value.rs b/Libraries/LibWeb/Rust/src/css/resolved_value.rsindex 89d3ef5a052..62e6056ca71 100644--- a/Libraries/LibWeb/Rust/src/css/resolved_value.rs+++ b/Libraries/LibWeb/Rust/src/css/resolved_value.rs@@ -1128,6 +1128,29 @@ pub unsafe extern "C" fn rust_resolved_value_of_style(style_value_for_shadow(SHADOW_TYPE_TEXT, shadows, current)}property_id::BACKDROP_FILTER | property_id::FILTER => resolve_filter_style_value(&computed(), current),+ // https://drafts.csswg.org/cssom/#resolved-value+ // line-height: The resolved value is normal if the computed value is normal, or the used value otherwise.+ // NB: Without a box, the used value of a number is that number times the computed font size.+ property_id::LINE_HEIGHT => {+ let line_height = computed();+ match &*line_height {+ StyleValueData::Number { value } => {+ // SAFETY: The caller passes a context its callback accepts, and the call hands over one strong+ // reference.+ let font_size = unsafe {+ StyleValueArc::from_raw((query.computed_value)(+ query.computed_value_context,+ property_id::FONT_SIZE,+ ))+ };+ match absolute_length_px(&font_size) {+ Some(font_size) => length_value(value * font_size),+ None => line_height,+ }+ }+ _ => line_height,+ }+ }property_id::TOUCH_ACTION => resolve_touch_action_style_value(&computed()),property_id::TRANSFORM_ORIGIN => style_value_for_transform_origin(handle_value(&transform.transform_origin_x).expect("transform-origin has an x offset"),diff --git a/Tests/LibWeb/Text/expected/css/computed-style-without-layout-box.txt b/Tests/LibWeb/Text/expected/css/computed-style-without-layout-box.txtindex 9d602524b07..f954adfb4ec 100644--- a/Tests/LibWeb/Text/expected/css/computed-style-without-layout-box.txt+++ b/Tests/LibWeb/Text/expected/css/computed-style-without-layout-box.txt@@ -1,6 +1,6 @@contents display: contentscontents color: rgb(10, 20, 30)-contents line-height: 1.5+contents line-height: 24pxcontents margins: 1px 2px 9px 4pxcontents margin shorthand: 1px 2px 9px 4pxcontents logical margin: 9pxdiff --git a/Tests/LibWeb/Text/expected/css/line-height-resolved-value-without-a-box.txt b/Tests/LibWeb/Text/expected/css/line-height-resolved-value-without-a-box.txtnew file mode 100644index 00000000000..3191fa97a9e--- /dev/null+++ b/Tests/LibWeb/Text/expected/css/line-height-resolved-value-without-a-box.txt@@ -0,0 +1,6 @@+rendered: 34px+inside-display-none: 34px+display-none: 34px+length: 24px+percentage: 30px+normal: normaldiff --git a/Tests/LibWeb/Text/input/css/line-height-resolved-value-without-a-box.html b/Tests/LibWeb/Text/input/css/line-height-resolved-value-without-a-box.htmlnew file mode 100644index 00000000000..e993537b41c--- /dev/null+++ b/Tests/LibWeb/Text/input/css/line-height-resolved-value-without-a-box.html@@ -0,0 +1,18 @@+<!DOCTYPE html>+<script src="../include.js"></script>+<style>+ .wrapper { font-size: 20px; line-height: 1.7; }+</style>+<div class="wrapper"><div id="rendered">rendered</div></div>+<div class="wrapper" style="display: none"><div id="inside-display-none">inside display: none</div></div>+<div class="wrapper"><div id="display-none" style="display: none">display: none</div></div>+<div class="wrapper" style="display: none"><div id="length" style="line-height: 24px">length</div></div>+<div class="wrapper" style="display: none"><div id="percentage" style="line-height: 150%">percentage</div></div>+<div class="wrapper" style="display: none"><div id="normal" style="line-height: normal">normal</div></div>+<script>+ test(() => {+ // A unitless line-height resolves to pixels whether or not the element is rendered, and normal stays normal.+ for (const id of ["rendered", "inside-display-none", "display-none", "length", "percentage", "normal"])+ println(`${id}: ${getComputedStyle(document.getElementById(id)).lineHeight}`);+ });+</script>