mirror of
https://github.com/servo/servo.git
synced 2025-10-17 16:59:27 +01:00
Auto merge of #17209 - servo:derive-all-the-things, r=emilio
Introduce more generics and more deriving <!-- Reviewable:start --> This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/17209) <!-- Reviewable:end -->
This commit is contained in:
commit
738483742c
20 changed files with 153 additions and 323 deletions
|
@ -7,8 +7,6 @@
|
|||
use app_units::Au;
|
||||
use cssparser::Parser;
|
||||
use parser::{Parse, ParserContext};
|
||||
use std::fmt;
|
||||
use style_traits::ToCss;
|
||||
use values::computed::{Context, ToComputedValue};
|
||||
use values::generics::border::BorderCornerRadius as GenericBorderCornerRadius;
|
||||
use values::generics::border::BorderImageSideWidth as GenericBorderImageSideWidth;
|
||||
|
@ -20,7 +18,7 @@ use values::specified::length::{Length, LengthOrPercentage};
|
|||
|
||||
/// A specified value for a single side of the `border-width` property.
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
#[derive(Clone, Debug, HasViewportPercentage, PartialEq)]
|
||||
#[derive(Clone, Debug, HasViewportPercentage, PartialEq, ToCss)]
|
||||
pub enum BorderSideWidth {
|
||||
/// `thin`
|
||||
Thin,
|
||||
|
@ -73,17 +71,6 @@ impl Parse for BorderSideWidth {
|
|||
}
|
||||
}
|
||||
|
||||
impl ToCss for BorderSideWidth {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
match *self {
|
||||
BorderSideWidth::Thin => dest.write_str("thin"),
|
||||
BorderSideWidth::Medium => dest.write_str("medium"),
|
||||
BorderSideWidth::Thick => dest.write_str("thick"),
|
||||
BorderSideWidth::Length(ref length) => length.to_css(dest)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ToComputedValue for BorderSideWidth {
|
||||
type ComputedValue = Au;
|
||||
|
||||
|
|
|
@ -894,9 +894,9 @@ impl LengthOrPercentage {
|
|||
}
|
||||
|
||||
/// Either a `<length>`, a `<percentage>`, or the `auto` keyword.
|
||||
#[derive(Clone, Debug, HasViewportPercentage, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
#[allow(missing_docs)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
#[derive(Clone, Debug, HasViewportPercentage, PartialEq, ToCss)]
|
||||
pub enum LengthOrPercentageOrAuto {
|
||||
Length(NoCalcLength),
|
||||
Percentage(Percentage),
|
||||
|
@ -918,17 +918,6 @@ impl From<Percentage> for LengthOrPercentageOrAuto {
|
|||
}
|
||||
}
|
||||
|
||||
impl ToCss for LengthOrPercentageOrAuto {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
match *self {
|
||||
LengthOrPercentageOrAuto::Length(ref length) => length.to_css(dest),
|
||||
LengthOrPercentageOrAuto::Percentage(percentage) => percentage.to_css(dest),
|
||||
LengthOrPercentageOrAuto::Auto => dest.write_str("auto"),
|
||||
LengthOrPercentageOrAuto::Calc(ref calc) => calc.to_css(dest),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl LengthOrPercentageOrAuto {
|
||||
fn parse_internal(context: &ParserContext,
|
||||
input: &mut Parser,
|
||||
|
@ -1012,8 +1001,8 @@ impl LengthOrPercentageOrAuto {
|
|||
}
|
||||
|
||||
/// Either a `<length>`, a `<percentage>`, or the `none` keyword.
|
||||
#[derive(Clone, Debug, HasViewportPercentage, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
#[derive(Clone, Debug, HasViewportPercentage, PartialEq, ToCss)]
|
||||
#[allow(missing_docs)]
|
||||
pub enum LengthOrPercentageOrNone {
|
||||
Length(NoCalcLength),
|
||||
|
@ -1022,16 +1011,6 @@ pub enum LengthOrPercentageOrNone {
|
|||
None,
|
||||
}
|
||||
|
||||
impl ToCss for LengthOrPercentageOrNone {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
match *self {
|
||||
LengthOrPercentageOrNone::Length(ref length) => length.to_css(dest),
|
||||
LengthOrPercentageOrNone::Percentage(ref percentage) => percentage.to_css(dest),
|
||||
LengthOrPercentageOrNone::Calc(ref calc) => calc.to_css(dest),
|
||||
LengthOrPercentageOrNone::None => dest.write_str("none"),
|
||||
}
|
||||
}
|
||||
}
|
||||
impl LengthOrPercentageOrNone {
|
||||
fn parse_internal(context: &ParserContext,
|
||||
input: &mut Parser,
|
||||
|
@ -1099,8 +1078,8 @@ pub type LengthOrAuto = Either<Length, Auto>;
|
|||
|
||||
/// Either a `<length>` or a `<percentage>` or the `auto` keyword or the
|
||||
/// `content` keyword.
|
||||
#[derive(Clone, Debug, HasViewportPercentage, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
#[derive(Clone, Debug, HasViewportPercentage, PartialEq, ToCss)]
|
||||
pub enum LengthOrPercentageOrAutoOrContent {
|
||||
/// A `<length>`.
|
||||
Length(NoCalcLength),
|
||||
|
@ -1156,18 +1135,6 @@ impl LengthOrPercentageOrAutoOrContent {
|
|||
}
|
||||
}
|
||||
|
||||
impl ToCss for LengthOrPercentageOrAutoOrContent {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
match *self {
|
||||
LengthOrPercentageOrAutoOrContent::Length(ref len) => len.to_css(dest),
|
||||
LengthOrPercentageOrAutoOrContent::Percentage(perc) => perc.to_css(dest),
|
||||
LengthOrPercentageOrAutoOrContent::Auto => dest.write_str("auto"),
|
||||
LengthOrPercentageOrAutoOrContent::Content => dest.write_str("content"),
|
||||
LengthOrPercentageOrAutoOrContent::Calc(ref calc) => calc.to_css(dest),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Either a `<length>` or a `<number>`.
|
||||
pub type LengthOrNumber = Either<Length, Number>;
|
||||
|
||||
|
|
|
@ -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| {
|
||||
|
|
|
@ -7,8 +7,6 @@
|
|||
use cssparser::Parser;
|
||||
use euclid::Point2D;
|
||||
use parser::{Parse, ParserContext};
|
||||
use std::fmt;
|
||||
use style_traits::ToCss;
|
||||
use values::computed::{LengthOrPercentage as ComputedLengthOrPercentage, Context, ToComputedValue};
|
||||
use values::computed::transform::TimingFunction as ComputedTimingFunction;
|
||||
use values::generics::transform::{StepPosition, TimingFunction as GenericTimingFunction};
|
||||
|
@ -22,7 +20,7 @@ pub type TransformOrigin = GenericTransformOrigin<OriginComponent<X>, OriginComp
|
|||
|
||||
/// The specified value of a component of a CSS `<transform-origin>`.
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
#[derive(Clone, Debug, HasViewportPercentage, PartialEq)]
|
||||
#[derive(Clone, Debug, HasViewportPercentage, PartialEq, ToCss)]
|
||||
pub enum OriginComponent<S> {
|
||||
/// `center`
|
||||
Center,
|
||||
|
@ -99,20 +97,6 @@ impl<S> Parse for OriginComponent<S>
|
|||
}
|
||||
}
|
||||
|
||||
impl<S: ToCss> ToCss for OriginComponent<S>
|
||||
where S: ToCss,
|
||||
{
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result
|
||||
where W: fmt::Write,
|
||||
{
|
||||
match *self {
|
||||
OriginComponent::Center => dest.write_str("center"),
|
||||
OriginComponent::Length(ref lop) => lop.to_css(dest),
|
||||
OriginComponent::Side(ref keyword) => keyword.to_css(dest),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<S> ToComputedValue for OriginComponent<S>
|
||||
where S: Side,
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue