diff options
-rw-r--r-- | components/layout/text.rs | 4 | ||||
-rw-r--r-- | components/style/properties/gecko.mako.rs | 8 | ||||
-rw-r--r-- | components/style/properties/helpers/animated_properties.mako.rs | 1 | ||||
-rw-r--r-- | components/style/properties/longhand/inherited_text.mako.rs | 2 | ||||
-rw-r--r-- | components/style/values/computed/text.rs | 4 | ||||
-rw-r--r-- | components/style/values/generics/text.rs | 2 | ||||
-rw-r--r-- | components/style/values/specified/text.rs | 58 |
7 files changed, 42 insertions, 37 deletions
diff --git a/components/layout/text.rs b/components/layout/text.rs index da779ecb240..f1c7d40515d 100644 --- a/components/layout/text.rs +++ b/components/layout/text.rs @@ -449,8 +449,8 @@ pub fn line_height_from_style(style: &ComputedValues, metrics: &FontMetrics) -> let font_size = style.get_font().font_size.0; match style.get_inheritedtext().line_height { LineHeight::Normal => metrics.line_gap, - LineHeight::Number(l) => font_size.scale_by(l), - LineHeight::Length(l) => l + LineHeight::Number(l) => font_size.scale_by(l.0), + LineHeight::Length(l) => l.0 } } diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index 5443c6c96f4..5f292cd40e3 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -4645,8 +4645,8 @@ fn static_assert() { // FIXME: Align binary representations and ditch |match| for cast + static_asserts let en = match v { LineHeight::Normal => CoordDataValue::Normal, - LineHeight::Length(val) => CoordDataValue::Coord(val.0), - LineHeight::Number(val) => CoordDataValue::Factor(val), + LineHeight::Length(val) => CoordDataValue::Coord(val.value()), + LineHeight::Number(val) => CoordDataValue::Factor(val.0), LineHeight::MozBlockHeight => CoordDataValue::Enumerated(structs::NS_STYLE_LINE_HEIGHT_BLOCK_HEIGHT), }; @@ -4657,8 +4657,8 @@ fn static_assert() { use values::generics::text::LineHeight; return match self.gecko.mLineHeight.as_value() { CoordDataValue::Normal => LineHeight::Normal, - CoordDataValue::Coord(coord) => LineHeight::Length(Au(coord)), - CoordDataValue::Factor(n) => LineHeight::Number(n), + CoordDataValue::Coord(coord) => LineHeight::Length(Au(coord).into()), + CoordDataValue::Factor(n) => LineHeight::Number(n.into()), CoordDataValue::Enumerated(val) if val == structs::NS_STYLE_LINE_HEIGHT_BLOCK_HEIGHT => LineHeight::MozBlockHeight, _ => panic!("this should not happen"), diff --git a/components/style/properties/helpers/animated_properties.mako.rs b/components/style/properties/helpers/animated_properties.mako.rs index 710f1dc7802..7b932fc5449 100644 --- a/components/style/properties/helpers/animated_properties.mako.rs +++ b/components/style/properties/helpers/animated_properties.mako.rs @@ -20,6 +20,7 @@ use properties::longhands::background_size::computed_value::T as BackgroundSizeL use properties::longhands::border_spacing::computed_value::T as BorderSpacing; use properties::longhands::font_weight::computed_value::T as FontWeight; use properties::longhands::font_stretch::computed_value::T as FontStretch; +use properties::longhands::line_height::computed_value::T as LineHeight; use properties::longhands::transform::computed_value::ComputedMatrix; use properties::longhands::transform::computed_value::ComputedOperation as TransformOperation; use properties::longhands::transform::computed_value::T as TransformList; diff --git a/components/style/properties/longhand/inherited_text.mako.rs b/components/style/properties/longhand/inherited_text.mako.rs index b31c5ec22c7..8384671de0e 100644 --- a/components/style/properties/longhand/inherited_text.mako.rs +++ b/components/style/properties/longhand/inherited_text.mako.rs @@ -9,7 +9,7 @@ ${helpers.predefined_type("line-height", "LineHeight", "computed::LineHeight::normal()", - animation_value_type="ComputedValue", + animation_value_type="LineHeight", flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER", spec="https://drafts.csswg.org/css2/visudet.html#propdef-line-height")} diff --git a/components/style/values/computed/text.rs b/components/style/values/computed/text.rs index c6902515c2a..7376616ba5e 100644 --- a/components/style/values/computed/text.rs +++ b/components/style/values/computed/text.rs @@ -4,10 +4,10 @@ //! Computed types for text properties. -use app_units::Au; use properties::animated_properties::Animatable; use values::{CSSInteger, CSSFloat}; use values::animated::ToAnimatedZero; +use values::computed::{NonNegativeAu, NonNegativeNumber}; use values::computed::length::{Length, LengthOrPercentage}; use values::generics::text::InitialLetter as GenericInitialLetter; use values::generics::text::LineHeight as GenericLineHeight; @@ -23,7 +23,7 @@ pub type LetterSpacing = Spacing<Length>; pub type WordSpacing = Spacing<LengthOrPercentage>; /// A computed value for the `line-height` property. -pub type LineHeight = GenericLineHeight<CSSFloat, Au>; +pub type LineHeight = GenericLineHeight<NonNegativeNumber, NonNegativeAu>; impl Animatable for LineHeight { #[inline] diff --git a/components/style/values/generics/text.rs b/components/style/values/generics/text.rs index 995752ce70f..94be4a6db8c 100644 --- a/components/style/values/generics/text.rs +++ b/components/style/values/generics/text.rs @@ -104,7 +104,7 @@ where /// A generic value for the `line-height` property. #[cfg_attr(feature = "servo", derive(HeapSizeOf))] -#[derive(Clone, Copy, Debug, HasViewportPercentage, PartialEq, ToCss)] +#[derive(Clone, Copy, Debug, HasViewportPercentage, PartialEq, ToAnimatedValue, ToCss)] pub enum LineHeight<Number, LengthOrPercentage> { /// `normal` Normal, diff --git a/components/style/values/specified/text.rs b/components/style/values/specified/text.rs index 2316d12eaeb..8341d6236f1 100644 --- a/components/style/values/specified/text.rs +++ b/components/style/values/specified/text.rs @@ -14,8 +14,9 @@ use values::computed::text::LineHeight as ComputedLineHeight; use values::generics::text::InitialLetter as GenericInitialLetter; use values::generics::text::LineHeight as GenericLineHeight; use values::generics::text::Spacing; -use values::specified::{AllowQuirks, Integer, Number}; +use values::specified::{AllowQuirks, Integer, NonNegativeNumber, Number}; use values::specified::length::{FontRelativeLength, Length, LengthOrPercentage, NoCalcLength}; +use values::specified::length::NonNegativeLengthOrPercentage; /// A specified type for the `initial-letter` property. pub type InitialLetter = GenericInitialLetter<Number, Integer>; @@ -27,7 +28,7 @@ pub type LetterSpacing = Spacing<Length>; pub type WordSpacing = Spacing<LengthOrPercentage>; /// A specified value for the `line-height` property. -pub type LineHeight = GenericLineHeight<Number, LengthOrPercentage>; +pub type LineHeight = GenericLineHeight<NonNegativeNumber, NonNegativeLengthOrPercentage>; impl Parse for InitialLetter { fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> { @@ -58,11 +59,11 @@ impl Parse for WordSpacing { impl Parse for LineHeight { fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> { - if let Ok(number) = input.try(|i| Number::parse_non_negative(context, i)) { + if let Ok(number) = input.try(|i| NonNegativeNumber::parse(context, i)) { return Ok(GenericLineHeight::Number(number)) } - if let Ok(lop) = input.try(|i| LengthOrPercentage::parse_non_negative(context, i)) { - return Ok(GenericLineHeight::Length(lop)) + if let Ok(nlop) = input.try(|i| NonNegativeLengthOrPercentage::parse(context, i)) { + return Ok(GenericLineHeight::Length(nlop)) } let ident = input.expect_ident()?; match ident { @@ -94,24 +95,29 @@ impl ToComputedValue for LineHeight { GenericLineHeight::Number(number) => { GenericLineHeight::Number(number.to_computed_value(context)) }, - GenericLineHeight::Length(LengthOrPercentage::Length(ref length)) => { - GenericLineHeight::Length(context.maybe_zoom_text(length.to_computed_value(context).into()).0) - }, - GenericLineHeight::Length(LengthOrPercentage::Percentage(p)) => { - let font_relative_length = - Length::NoCalc(NoCalcLength::FontRelative(FontRelativeLength::Em(p.0))); - GenericLineHeight::Length(font_relative_length.to_computed_value(context)) - }, - GenericLineHeight::Length(LengthOrPercentage::Calc(ref calc)) => { - let computed_calc = calc.to_computed_value_zoomed(context); - let font_relative_length = - Length::NoCalc(NoCalcLength::FontRelative(FontRelativeLength::Em(computed_calc.percentage()))); - let absolute_length = computed_calc.unclamped_length(); - let computed_length = computed_calc.clamping_mode.clamp( - absolute_length + font_relative_length.to_computed_value(context) - ); - GenericLineHeight::Length(computed_length) - }, + GenericLineHeight::Length(ref non_negative_lop) => { + let result = match non_negative_lop.0 { + LengthOrPercentage::Length(ref length) => { + context.maybe_zoom_text(length.to_computed_value(context).into()) + }, + LengthOrPercentage::Percentage(ref p) => { + let font_relative_length = + Length::NoCalc(NoCalcLength::FontRelative(FontRelativeLength::Em(p.0))); + font_relative_length.to_computed_value(context).into() + } + LengthOrPercentage::Calc(ref calc) => { + let computed_calc = calc.to_computed_value_zoomed(context); + let font_relative_length = + Length::NoCalc(NoCalcLength::FontRelative( + FontRelativeLength::Em(computed_calc.percentage()))); + let absolute_length = computed_calc.unclamped_length(); + computed_calc.clamping_mode.clamp( + absolute_length + font_relative_length.to_computed_value(context) + ).into() + } + }; + GenericLineHeight::Length(result) + } } } @@ -126,12 +132,10 @@ impl ToComputedValue for LineHeight { GenericLineHeight::MozBlockHeight }, GenericLineHeight::Number(ref number) => { - GenericLineHeight::Number(Number::from_computed_value(number)) + GenericLineHeight::Number(NonNegativeNumber::from_computed_value(number)) }, GenericLineHeight::Length(ref length) => { - GenericLineHeight::Length(LengthOrPercentage::Length( - NoCalcLength::from_computed_value(length) - )) + GenericLineHeight::Length(NoCalcLength::from_computed_value(&length.0).into()) } } } |