mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
Use generics for initial-letter
The former version used ComputedValueAsSpecified, which means we were storing specified numbers and integers in the computed value.
This commit is contained in:
parent
f388c0ab1e
commit
7d09ce0495
7 changed files with 83 additions and 82 deletions
|
@ -3898,18 +3898,18 @@ fn static_assert() {
|
|||
}
|
||||
|
||||
pub fn set_initial_letter(&mut self, v: longhands::initial_letter::computed_value::T) {
|
||||
use properties::longhands::initial_letter::computed_value::T;
|
||||
use values::generics::text::InitialLetter;
|
||||
match v {
|
||||
T::Normal => {
|
||||
InitialLetter::Normal => {
|
||||
self.gecko.mInitialLetterSize = 0.;
|
||||
self.gecko.mInitialLetterSink = 0;
|
||||
},
|
||||
T::Specified(size, sink) => {
|
||||
self.gecko.mInitialLetterSize = size.get();
|
||||
InitialLetter::Specified(size, sink) => {
|
||||
self.gecko.mInitialLetterSize = size;
|
||||
if let Some(sink) = sink {
|
||||
self.gecko.mInitialLetterSink = sink.value();
|
||||
self.gecko.mInitialLetterSink = sink;
|
||||
} else {
|
||||
self.gecko.mInitialLetterSink = size.get().floor() as i32;
|
||||
self.gecko.mInitialLetterSink = size.floor() as i32;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -287,72 +287,11 @@ ${helpers.predefined_type(
|
|||
ignored_when_colors_disabled=True,
|
||||
spec="https://drafts.csswg.org/css-text-decor/#propdef-text-decoration-color")}
|
||||
|
||||
<%helpers:longhand name="initial-letter"
|
||||
animation_value_type="none"
|
||||
products="gecko"
|
||||
spec="https://drafts.csswg.org/css-inline/#sizing-drop-initials">
|
||||
use std::fmt;
|
||||
use style_traits::ToCss;
|
||||
use values::computed::ComputedValueAsSpecified;
|
||||
use values::specified::{Number, Integer};
|
||||
|
||||
impl ComputedValueAsSpecified for SpecifiedValue {}
|
||||
no_viewport_percentage!(SpecifiedValue);
|
||||
|
||||
#[derive(PartialEq, Clone, Debug)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub enum SpecifiedValue {
|
||||
Normal,
|
||||
Specified(Number, Option<Integer>)
|
||||
}
|
||||
|
||||
pub mod computed_value {
|
||||
pub use super::SpecifiedValue as T;
|
||||
}
|
||||
|
||||
impl ToCss for SpecifiedValue {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
match *self {
|
||||
SpecifiedValue::Normal => try!(dest.write_str("normal")),
|
||||
SpecifiedValue::Specified(size, sink) => {
|
||||
try!(size.to_css(dest));
|
||||
if let Some(sink) = sink {
|
||||
try!(dest.write_str(" "));
|
||||
try!(sink.to_css(dest));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_initial_value() -> computed_value::T {
|
||||
computed_value::T::Normal
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_initial_specified_value() -> SpecifiedValue {
|
||||
SpecifiedValue::Normal
|
||||
}
|
||||
|
||||
/// normal | <number> <integer>?
|
||||
pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
|
||||
if input.try(|input| input.expect_ident_matching("normal")).is_ok() {
|
||||
return Ok(SpecifiedValue::Normal);
|
||||
}
|
||||
|
||||
let size = try!(Number::parse_at_least_one(context, input));
|
||||
|
||||
match input.try(|input| Integer::parse(context, input)) {
|
||||
Ok(number) => {
|
||||
if number.value() < 1 {
|
||||
return Err(());
|
||||
}
|
||||
Ok(SpecifiedValue::Specified(size, Some(number)))
|
||||
}
|
||||
Err(()) => Ok(SpecifiedValue::Specified(size, None)),
|
||||
}
|
||||
}
|
||||
</%helpers:longhand>
|
||||
${helpers.predefined_type(
|
||||
"initial-letter",
|
||||
"InitialLetter",
|
||||
"computed::InitialLetter::normal()",
|
||||
initial_specified_value="specified::InitialLetter::normal()",
|
||||
animation_value_type="none",
|
||||
products="gecko",
|
||||
spec="https://drafts.csswg.org/css-inline/#sizing-drop-initials")}
|
||||
|
|
|
@ -41,7 +41,7 @@ pub use self::length::{CalcLengthOrPercentage, Length, LengthOrNumber, LengthOrP
|
|||
pub use self::length::{LengthOrPercentageOrAutoOrContent, LengthOrPercentageOrNone, LengthOrNone};
|
||||
pub use self::length::{MaxLength, MozLength};
|
||||
pub use self::position::Position;
|
||||
pub use self::text::{LetterSpacing, LineHeight, WordSpacing};
|
||||
pub use self::text::{InitialLetter, LetterSpacing, LineHeight, WordSpacing};
|
||||
pub use self::transform::{TimingFunction, TransformOrigin};
|
||||
|
||||
pub mod background;
|
||||
|
|
|
@ -6,9 +6,14 @@
|
|||
|
||||
use app_units::Au;
|
||||
use properties::animated_properties::Animatable;
|
||||
use values::CSSFloat;
|
||||
use values::{CSSInteger, CSSFloat};
|
||||
use values::computed::length::{Length, LengthOrPercentage};
|
||||
use values::generics::text::{LineHeight as GenericLineHeight, Spacing};
|
||||
use values::generics::text::InitialLetter as GenericInitialLetter;
|
||||
use values::generics::text::LineHeight as GenericLineHeight;
|
||||
use values::generics::text::Spacing;
|
||||
|
||||
/// A computed value for the `initial-letter` property.
|
||||
pub type InitialLetter = GenericInitialLetter<CSSFloat, CSSInteger>;
|
||||
|
||||
/// A computed value for the `letter-spacing` property.
|
||||
pub type LetterSpacing = Spacing<Length>;
|
||||
|
|
|
@ -11,7 +11,48 @@ use properties::animated_properties::Animatable;
|
|||
use std::fmt;
|
||||
use style_traits::ToCss;
|
||||
|
||||
/// A generic spacing value for the `letter-spacing` and `word-spacing` properties.alloc
|
||||
/// A generic value for the `initial-letter` property.
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
#[derive(Clone, Copy, Debug, HasViewportPercentage, PartialEq, ToComputedValue)]
|
||||
pub enum InitialLetter<Number, Integer> {
|
||||
/// `normal`
|
||||
Normal,
|
||||
/// `<number> <integer>?`
|
||||
Specified(Number, Option<Integer>),
|
||||
}
|
||||
|
||||
impl<N, I> InitialLetter<N, I> {
|
||||
/// Returns `normal`.
|
||||
#[inline]
|
||||
pub fn normal() -> Self {
|
||||
InitialLetter::Normal
|
||||
}
|
||||
}
|
||||
|
||||
impl<N, I> ToCss for InitialLetter<N, I>
|
||||
where
|
||||
N: ToCss,
|
||||
I: ToCss,
|
||||
{
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result
|
||||
where
|
||||
W: fmt::Write,
|
||||
{
|
||||
match *self {
|
||||
InitialLetter::Normal => dest.write_str("normal"),
|
||||
InitialLetter::Specified(ref size, ref sink) => {
|
||||
size.to_css(dest)?;
|
||||
if let Some(ref sink) = *sink {
|
||||
dest.write_str(" ")?;
|
||||
sink.to_css(dest)?;
|
||||
}
|
||||
Ok(())
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A generic spacing value for the `letter-spacing` and `word-spacing` properties.
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
#[derive(Clone, Copy, Debug, HasViewportPercentage, PartialEq, ToComputedValue)]
|
||||
pub enum Spacing<Value> {
|
||||
|
|
|
@ -45,7 +45,7 @@ pub use self::length::{Percentage, LengthOrNone, LengthOrNumber, LengthOrPercent
|
|||
pub use self::length::{LengthOrPercentageOrNone, LengthOrPercentageOrAutoOrContent, NoCalcLength};
|
||||
pub use self::length::{MaxLength, MozLength};
|
||||
pub use self::position::{Position, PositionComponent};
|
||||
pub use self::text::{LetterSpacing, LineHeight, WordSpacing};
|
||||
pub use self::text::{InitialLetter, LetterSpacing, LineHeight, WordSpacing};
|
||||
pub use self::transform::{TimingFunction, TransformOrigin};
|
||||
pub use super::generics::grid::GridLine;
|
||||
|
||||
|
|
|
@ -9,10 +9,15 @@ use parser::{Parse, ParserContext};
|
|||
use std::ascii::AsciiExt;
|
||||
use values::computed::{Context, ToComputedValue};
|
||||
use values::computed::text::LineHeight as ComputedLineHeight;
|
||||
use values::generics::text::{LineHeight as GenericLineHeight, Spacing};
|
||||
use values::specified::{AllowQuirks, Number};
|
||||
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::length::{FontRelativeLength, Length, LengthOrPercentage, NoCalcLength};
|
||||
|
||||
/// A specified type for the `initial-letter` property.
|
||||
pub type InitialLetter = GenericInitialLetter<Number, Integer>;
|
||||
|
||||
/// A specified value for the `letter-spacing` property.
|
||||
pub type LetterSpacing = Spacing<Length>;
|
||||
|
||||
|
@ -22,6 +27,17 @@ pub type WordSpacing = Spacing<LengthOrPercentage>;
|
|||
/// A specified value for the `line-height` property.
|
||||
pub type LineHeight = GenericLineHeight<Number, LengthOrPercentage>;
|
||||
|
||||
impl Parse for InitialLetter {
|
||||
fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
|
||||
if input.try(|i| i.expect_ident_matching("normal")).is_ok() {
|
||||
return Ok(GenericInitialLetter::Normal);
|
||||
}
|
||||
let size = Number::parse_at_least_one(context, input)?;
|
||||
let sink = input.try(|i| Integer::parse_positive(context, i)).ok();
|
||||
Ok(GenericInitialLetter::Specified(size, sink))
|
||||
}
|
||||
}
|
||||
|
||||
impl Parse for LetterSpacing {
|
||||
fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
|
||||
Spacing::parse_with(context, input, |c, i| {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue