From 0bf39dc3d32b61cbf53830084363673654a79220 Mon Sep 17 00:00:00 2001 From: Jonathan Kew Date: Thu, 2 Feb 2023 13:35:51 +0000 Subject: [PATCH] style: Resolve to in ToResolvedValue for line-height This makes the serialization of the 'font' shorthand on computed style return the line-height as an absolute length rather than a number (font-size multiplier), which is consistent with what the line-height longhand already returns, and with other browsers. (See also https://github.com/w3c/csswg-drafts/issues/8385.) Differential Revision: https://phabricator.services.mozilla.com/D168542 --- components/style/values/computed/text.rs | 20 ++++++++++++++++++++ components/style/values/generics/text.rs | 1 - 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/components/style/values/computed/text.rs b/components/style/values/computed/text.rs index ff4d87fa93e..3db55672705 100644 --- a/components/style/values/computed/text.rs +++ b/components/style/values/computed/text.rs @@ -11,6 +11,7 @@ use crate::values::computed::{Context, NonNegativeLength, NonNegativeNumber, ToC use crate::values::generics::text::InitialLetter as GenericInitialLetter; use crate::values::generics::text::LineHeight as GenericLineHeight; use crate::values::generics::text::{GenericTextDecorationLength, Spacing}; +use crate::values::resolved::{Context as ResolvedContext, ToResolvedValue}; use crate::values::specified::text::{self as specified, TextOverflowSide}; use crate::values::specified::text::{TextEmphasisFillMode, TextEmphasisShapeKeyword}; use crate::values::{CSSFloat, CSSInteger}; @@ -113,6 +114,25 @@ impl ToComputedValue for specified::WordSpacing { /// A computed value for the `line-height` property. pub type LineHeight = GenericLineHeight; +impl ToResolvedValue for LineHeight { + type ResolvedValue = Self; + + fn to_resolved_value(self, context: &ResolvedContext) -> Self::ResolvedValue { + // Resolve to an absolute based on font size. + if let LineHeight::Number(num) = &self { + let size = context.style.get_font().clone_font_size().computed_size(); + LineHeight::Length(NonNegativeLength::new(size.px() * num.0)) + } else { + self + } + } + + #[inline] + fn from_resolved_value(value: Self::ResolvedValue) -> Self { + value + } +} + impl WordSpacing { /// Return the `normal` computed value, which is just zero. #[inline] diff --git a/components/style/values/generics/text.rs b/components/style/values/generics/text.rs index 0062f304701..9b59ff0dc3f 100644 --- a/components/style/values/generics/text.rs +++ b/components/style/values/generics/text.rs @@ -92,7 +92,6 @@ fn line_height_moz_block_height_enabled(context: &ParserContext) -> bool { ToAnimatedValue, ToCss, ToShmem, - ToResolvedValue, Parse, )] #[repr(C, u8)]