mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
style: Resolve <number> to <length> 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
This commit is contained in:
parent
816a0f960b
commit
0bf39dc3d3
2 changed files with 20 additions and 1 deletions
|
@ -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<NonNegativeNumber, NonNegativeLength>;
|
||||
|
||||
impl ToResolvedValue for LineHeight {
|
||||
type ResolvedValue = Self;
|
||||
|
||||
fn to_resolved_value(self, context: &ResolvedContext) -> Self::ResolvedValue {
|
||||
// Resolve <number> to an absolute <length> 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]
|
||||
|
|
|
@ -92,7 +92,6 @@ fn line_height_moz_block_height_enabled(context: &ParserContext) -> bool {
|
|||
ToAnimatedValue,
|
||||
ToCss,
|
||||
ToShmem,
|
||||
ToResolvedValue,
|
||||
Parse,
|
||||
)]
|
||||
#[repr(C, u8)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue