Bug 1374233 - Part 12: Implement ToAnimatedValue for LineHeight.

Besides, we replace its type with
GenericLineHeight<NonNegativeNumber, NonNegativeAu>.

MozReview-Commit-ID: GGOGXyUFJsJ
This commit is contained in:
Boris Chiou 2017-07-24 17:25:47 +08:00
parent ebedea5860
commit 6dd8b159d7
7 changed files with 42 additions and 37 deletions

View file

@ -449,8 +449,8 @@ pub fn line_height_from_style(style: &ComputedValues, metrics: &FontMetrics) ->
let font_size = style.get_font().font_size.0; let font_size = style.get_font().font_size.0;
match style.get_inheritedtext().line_height { match style.get_inheritedtext().line_height {
LineHeight::Normal => metrics.line_gap, LineHeight::Normal => metrics.line_gap,
LineHeight::Number(l) => font_size.scale_by(l), LineHeight::Number(l) => font_size.scale_by(l.0),
LineHeight::Length(l) => l LineHeight::Length(l) => l.0
} }
} }

View file

@ -4645,8 +4645,8 @@ fn static_assert() {
// FIXME: Align binary representations and ditch |match| for cast + static_asserts // FIXME: Align binary representations and ditch |match| for cast + static_asserts
let en = match v { let en = match v {
LineHeight::Normal => CoordDataValue::Normal, LineHeight::Normal => CoordDataValue::Normal,
LineHeight::Length(val) => CoordDataValue::Coord(val.0), LineHeight::Length(val) => CoordDataValue::Coord(val.value()),
LineHeight::Number(val) => CoordDataValue::Factor(val), LineHeight::Number(val) => CoordDataValue::Factor(val.0),
LineHeight::MozBlockHeight => LineHeight::MozBlockHeight =>
CoordDataValue::Enumerated(structs::NS_STYLE_LINE_HEIGHT_BLOCK_HEIGHT), CoordDataValue::Enumerated(structs::NS_STYLE_LINE_HEIGHT_BLOCK_HEIGHT),
}; };
@ -4657,8 +4657,8 @@ fn static_assert() {
use values::generics::text::LineHeight; use values::generics::text::LineHeight;
return match self.gecko.mLineHeight.as_value() { return match self.gecko.mLineHeight.as_value() {
CoordDataValue::Normal => LineHeight::Normal, CoordDataValue::Normal => LineHeight::Normal,
CoordDataValue::Coord(coord) => LineHeight::Length(Au(coord)), CoordDataValue::Coord(coord) => LineHeight::Length(Au(coord).into()),
CoordDataValue::Factor(n) => LineHeight::Number(n), CoordDataValue::Factor(n) => LineHeight::Number(n.into()),
CoordDataValue::Enumerated(val) if val == structs::NS_STYLE_LINE_HEIGHT_BLOCK_HEIGHT => CoordDataValue::Enumerated(val) if val == structs::NS_STYLE_LINE_HEIGHT_BLOCK_HEIGHT =>
LineHeight::MozBlockHeight, LineHeight::MozBlockHeight,
_ => panic!("this should not happen"), _ => panic!("this should not happen"),

View file

@ -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::border_spacing::computed_value::T as BorderSpacing;
use properties::longhands::font_weight::computed_value::T as FontWeight; use properties::longhands::font_weight::computed_value::T as FontWeight;
use properties::longhands::font_stretch::computed_value::T as FontStretch; 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::ComputedMatrix;
use properties::longhands::transform::computed_value::ComputedOperation as TransformOperation; use properties::longhands::transform::computed_value::ComputedOperation as TransformOperation;
use properties::longhands::transform::computed_value::T as TransformList; use properties::longhands::transform::computed_value::T as TransformList;

View file

@ -9,7 +9,7 @@
${helpers.predefined_type("line-height", ${helpers.predefined_type("line-height",
"LineHeight", "LineHeight",
"computed::LineHeight::normal()", "computed::LineHeight::normal()",
animation_value_type="ComputedValue", animation_value_type="LineHeight",
flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER", flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER",
spec="https://drafts.csswg.org/css2/visudet.html#propdef-line-height")} spec="https://drafts.csswg.org/css2/visudet.html#propdef-line-height")}

View file

@ -4,10 +4,10 @@
//! Computed types for text properties. //! Computed types for text properties.
use app_units::Au;
use properties::animated_properties::Animatable; use properties::animated_properties::Animatable;
use values::{CSSInteger, CSSFloat}; use values::{CSSInteger, CSSFloat};
use values::animated::ToAnimatedZero; use values::animated::ToAnimatedZero;
use values::computed::{NonNegativeAu, NonNegativeNumber};
use values::computed::length::{Length, LengthOrPercentage}; use values::computed::length::{Length, LengthOrPercentage};
use values::generics::text::InitialLetter as GenericInitialLetter; use values::generics::text::InitialLetter as GenericInitialLetter;
use values::generics::text::LineHeight as GenericLineHeight; use values::generics::text::LineHeight as GenericLineHeight;
@ -23,7 +23,7 @@ pub type LetterSpacing = Spacing<Length>;
pub type WordSpacing = Spacing<LengthOrPercentage>; pub type WordSpacing = Spacing<LengthOrPercentage>;
/// A computed value for the `line-height` property. /// A computed value for the `line-height` property.
pub type LineHeight = GenericLineHeight<CSSFloat, Au>; pub type LineHeight = GenericLineHeight<NonNegativeNumber, NonNegativeAu>;
impl Animatable for LineHeight { impl Animatable for LineHeight {
#[inline] #[inline]

View file

@ -104,7 +104,7 @@ where
/// A generic value for the `line-height` property. /// A generic value for the `line-height` property.
#[cfg_attr(feature = "servo", derive(HeapSizeOf))] #[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> { pub enum LineHeight<Number, LengthOrPercentage> {
/// `normal` /// `normal`
Normal, Normal,

View file

@ -14,8 +14,9 @@ use values::computed::text::LineHeight as ComputedLineHeight;
use values::generics::text::InitialLetter as GenericInitialLetter; use values::generics::text::InitialLetter as GenericInitialLetter;
use values::generics::text::LineHeight as GenericLineHeight; use values::generics::text::LineHeight as GenericLineHeight;
use values::generics::text::Spacing; 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::{FontRelativeLength, Length, LengthOrPercentage, NoCalcLength};
use values::specified::length::NonNegativeLengthOrPercentage;
/// A specified type for the `initial-letter` property. /// A specified type for the `initial-letter` property.
pub type InitialLetter = GenericInitialLetter<Number, Integer>; pub type InitialLetter = GenericInitialLetter<Number, Integer>;
@ -27,7 +28,7 @@ pub type LetterSpacing = Spacing<Length>;
pub type WordSpacing = Spacing<LengthOrPercentage>; pub type WordSpacing = Spacing<LengthOrPercentage>;
/// A specified value for the `line-height` property. /// A specified value for the `line-height` property.
pub type LineHeight = GenericLineHeight<Number, LengthOrPercentage>; pub type LineHeight = GenericLineHeight<NonNegativeNumber, NonNegativeLengthOrPercentage>;
impl Parse for InitialLetter { impl Parse for InitialLetter {
fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> { 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 { impl Parse for LineHeight {
fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> { 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)) return Ok(GenericLineHeight::Number(number))
} }
if let Ok(lop) = input.try(|i| LengthOrPercentage::parse_non_negative(context, i)) { if let Ok(nlop) = input.try(|i| NonNegativeLengthOrPercentage::parse(context, i)) {
return Ok(GenericLineHeight::Length(lop)) return Ok(GenericLineHeight::Length(nlop))
} }
let ident = input.expect_ident()?; let ident = input.expect_ident()?;
match ident { match ident {
@ -94,24 +95,29 @@ impl ToComputedValue for LineHeight {
GenericLineHeight::Number(number) => { GenericLineHeight::Number(number) => {
GenericLineHeight::Number(number.to_computed_value(context)) GenericLineHeight::Number(number.to_computed_value(context))
}, },
GenericLineHeight::Length(LengthOrPercentage::Length(ref length)) => { GenericLineHeight::Length(ref non_negative_lop) => {
GenericLineHeight::Length(context.maybe_zoom_text(length.to_computed_value(context).into()).0) let result = match non_negative_lop.0 {
}, LengthOrPercentage::Length(ref length) => {
GenericLineHeight::Length(LengthOrPercentage::Percentage(p)) => { context.maybe_zoom_text(length.to_computed_value(context).into())
let font_relative_length = },
Length::NoCalc(NoCalcLength::FontRelative(FontRelativeLength::Em(p.0))); LengthOrPercentage::Percentage(ref p) => {
GenericLineHeight::Length(font_relative_length.to_computed_value(context)) let font_relative_length =
}, Length::NoCalc(NoCalcLength::FontRelative(FontRelativeLength::Em(p.0)));
GenericLineHeight::Length(LengthOrPercentage::Calc(ref calc)) => { font_relative_length.to_computed_value(context).into()
let computed_calc = calc.to_computed_value_zoomed(context); }
let font_relative_length = LengthOrPercentage::Calc(ref calc) => {
Length::NoCalc(NoCalcLength::FontRelative(FontRelativeLength::Em(computed_calc.percentage()))); let computed_calc = calc.to_computed_value_zoomed(context);
let absolute_length = computed_calc.unclamped_length(); let font_relative_length =
let computed_length = computed_calc.clamping_mode.clamp( Length::NoCalc(NoCalcLength::FontRelative(
absolute_length + font_relative_length.to_computed_value(context) FontRelativeLength::Em(computed_calc.percentage())));
); let absolute_length = computed_calc.unclamped_length();
GenericLineHeight::Length(computed_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::MozBlockHeight
}, },
GenericLineHeight::Number(ref number) => { GenericLineHeight::Number(ref number) => {
GenericLineHeight::Number(Number::from_computed_value(number)) GenericLineHeight::Number(NonNegativeNumber::from_computed_value(number))
}, },
GenericLineHeight::Length(ref length) => { GenericLineHeight::Length(ref length) => {
GenericLineHeight::Length(LengthOrPercentage::Length( GenericLineHeight::Length(NoCalcLength::from_computed_value(&length.0).into())
NoCalcLength::from_computed_value(length)
))
} }
} }
} }