mirror of
https://github.com/servo/servo.git
synced 2025-08-08 15:05:35 +01:00
Derive the most trivial ToCss implementations 🌋
For now, all variants get serialised as the space-separated serialisations of their fields. Unit variants are not supported.
This commit is contained in:
parent
6d6f03974d
commit
c4f1d647a0
18 changed files with 113 additions and 263 deletions
|
@ -1074,8 +1074,6 @@
|
|||
predefined_type=length_type,
|
||||
logical=logical,
|
||||
**kwargs)">
|
||||
use std::fmt;
|
||||
use style_traits::ToCss;
|
||||
% if not logical:
|
||||
use values::specified::AllowQuirks;
|
||||
% endif
|
||||
|
@ -1085,8 +1083,8 @@
|
|||
pub type T = ::values::computed::${length_type};
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, HasViewportPercentage, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
#[derive(Clone, Debug, HasViewportPercentage, PartialEq, ToCss)]
|
||||
pub struct SpecifiedValue(pub ${length_type});
|
||||
|
||||
% if length_type == "MozLength":
|
||||
|
@ -1131,12 +1129,6 @@
|
|||
ret.map(SpecifiedValue)
|
||||
}
|
||||
|
||||
impl ToCss for SpecifiedValue {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
self.0.to_css(dest)
|
||||
}
|
||||
}
|
||||
|
||||
impl ToComputedValue for SpecifiedValue {
|
||||
type ComputedValue = computed_value::T;
|
||||
#[inline]
|
||||
|
|
|
@ -222,8 +222,8 @@ ${helpers.predefined_type("border-image-outset", "LengthOrNumberRect",
|
|||
pub mod computed_value {
|
||||
pub use super::RepeatKeyword;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
#[derive(Debug, Clone, PartialEq, ToCss)]
|
||||
pub struct T(pub RepeatKeyword, pub RepeatKeyword);
|
||||
}
|
||||
|
||||
|
@ -238,14 +238,6 @@ ${helpers.predefined_type("border-image-outset", "LengthOrNumberRect",
|
|||
"round" => Round,
|
||||
"space" => Space);
|
||||
|
||||
|
||||
impl ToCss for computed_value::T {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
try!(self.0.to_css(dest));
|
||||
try!(dest.write_str(" "));
|
||||
self.1.to_css(dest)
|
||||
}
|
||||
}
|
||||
impl ToCss for SpecifiedValue {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
try!(self.0.to_css(dest));
|
||||
|
|
|
@ -13,8 +13,6 @@
|
|||
ignored_when_colors_disabled="True"
|
||||
spec="https://drafts.csswg.org/css-color/#color">
|
||||
use cssparser::RGBA;
|
||||
use std::fmt;
|
||||
use style_traits::ToCss;
|
||||
use values::specified::{AllowQuirks, Color, CSSColor};
|
||||
|
||||
impl ToComputedValue for SpecifiedValue {
|
||||
|
@ -31,17 +29,11 @@
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Debug)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
#[derive(Clone, Debug, PartialEq, ToCss)]
|
||||
pub struct SpecifiedValue(pub CSSColor);
|
||||
no_viewport_percentage!(SpecifiedValue);
|
||||
|
||||
impl ToCss for SpecifiedValue {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
self.0.to_css(dest)
|
||||
}
|
||||
}
|
||||
|
||||
pub mod computed_value {
|
||||
use cssparser;
|
||||
pub type T = cssparser::RGBA;
|
||||
|
@ -91,6 +83,9 @@
|
|||
%>
|
||||
use gecko_bindings::bindings::Gecko_GetLookAndFeelSystemColor;
|
||||
use gecko_bindings::structs::root::mozilla::LookAndFeel_ColorID;
|
||||
use std::fmt;
|
||||
use style_traits::ToCss;
|
||||
|
||||
pub type SystemColor = LookAndFeel_ColorID;
|
||||
|
||||
impl ToCss for SystemColor {
|
||||
|
|
|
@ -2149,18 +2149,15 @@ ${helpers.single_keyword("-moz-math-variant",
|
|||
internal="True" disable_when_testing="True">
|
||||
use app_units::Au;
|
||||
use gecko_bindings::structs::NS_MATHML_DEFAULT_SCRIPT_MIN_SIZE_PT;
|
||||
use std::fmt;
|
||||
use style_traits::ToCss;
|
||||
use values::specified::length::{AU_PER_PT, FontBaseSize, NoCalcLength};
|
||||
|
||||
#[derive(Clone, Debug, HasViewportPercentage, PartialEq)]
|
||||
#[derive(Clone, Debug, HasViewportPercentage, PartialEq, ToCss)]
|
||||
pub struct SpecifiedValue(pub NoCalcLength);
|
||||
|
||||
pub mod computed_value {
|
||||
pub type T = super::Au;
|
||||
}
|
||||
|
||||
|
||||
impl ToComputedValue for SpecifiedValue {
|
||||
type ComputedValue = computed_value::T;
|
||||
|
||||
|
@ -2185,12 +2182,6 @@ ${helpers.single_keyword("-moz-math-variant",
|
|||
}
|
||||
}
|
||||
|
||||
impl ToCss for SpecifiedValue {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
self.0.to_css(dest)
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_initial_value() -> computed_value::T {
|
||||
Au((NS_MATHML_DEFAULT_SCRIPT_MIN_SIZE_PT as f32 * AU_PER_PT) as i32)
|
||||
|
|
|
@ -31,8 +31,8 @@ ${helpers.single_keyword("caption-side", "top bottom",
|
|||
use app_units::Au;
|
||||
use properties::animated_properties::Animatable;
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, ToCss)]
|
||||
pub struct T {
|
||||
pub horizontal: Au,
|
||||
pub vertical: Au,
|
||||
|
@ -92,14 +92,6 @@ ${helpers.single_keyword("caption-side", "top bottom",
|
|||
}
|
||||
}
|
||||
|
||||
impl ToCss for computed_value::T {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
try!(self.horizontal.to_css(dest));
|
||||
try!(dest.write_str(" "));
|
||||
self.vertical.to_css(dest)
|
||||
}
|
||||
}
|
||||
|
||||
impl ToComputedValue for SpecifiedValue {
|
||||
type ComputedValue = computed_value::T;
|
||||
|
||||
|
|
|
@ -443,8 +443,8 @@ ${helpers.predefined_type("word-spacing",
|
|||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub struct T(pub SmallVec<[TextShadow; 1]>);
|
||||
|
||||
#[derive(Clone, PartialEq, Debug)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
#[derive(Clone, PartialEq, Debug, ToCss)]
|
||||
pub struct TextShadow {
|
||||
pub offset_x: Au,
|
||||
pub offset_y: Au,
|
||||
|
@ -468,18 +468,6 @@ ${helpers.predefined_type("word-spacing",
|
|||
}
|
||||
}
|
||||
|
||||
impl ToCss for computed_value::TextShadow {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
self.offset_x.to_css(dest)?;
|
||||
dest.write_str(" ")?;
|
||||
self.offset_y.to_css(dest)?;
|
||||
dest.write_str(" ")?;
|
||||
self.blur_radius.to_css(dest)?;
|
||||
dest.write_str(" ")?;
|
||||
self.color.to_css(dest)
|
||||
}
|
||||
}
|
||||
|
||||
impl ToCss for SpecifiedValue {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
let mut iter = self.0.iter();
|
||||
|
@ -767,7 +755,6 @@ ${helpers.predefined_type("word-spacing",
|
|||
|
||||
<%helpers:longhand name="text-emphasis-position" animation_value_type="none" products="gecko"
|
||||
spec="https://drafts.csswg.org/css-text-decor/#propdef-text-emphasis-position">
|
||||
use std::fmt;
|
||||
use values::computed::ComputedValueAsSpecified;
|
||||
use style_traits::ToCss;
|
||||
|
||||
|
@ -778,8 +765,8 @@ ${helpers.predefined_type("word-spacing",
|
|||
"right" => Right,
|
||||
"left" => Left);
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
#[derive(Debug, Clone, PartialEq, ToCss)]
|
||||
pub struct SpecifiedValue(pub HorizontalWritingModeValue, pub VerticalWritingModeValue);
|
||||
|
||||
pub mod computed_value {
|
||||
|
@ -804,15 +791,6 @@ ${helpers.predefined_type("word-spacing",
|
|||
}
|
||||
}
|
||||
|
||||
impl ToCss for SpecifiedValue {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
let SpecifiedValue(horizontal, vertical) = *self;
|
||||
try!(horizontal.to_css(dest));
|
||||
try!(dest.write_char(' '));
|
||||
vertical.to_css(dest)
|
||||
}
|
||||
}
|
||||
|
||||
% if product == "gecko":
|
||||
impl SpecifiedValue {
|
||||
pub fn from_gecko_keyword(kw: u32) -> Self {
|
||||
|
|
|
@ -114,17 +114,15 @@ ${helpers.single_keyword("list-style-position", "outside inside", animation_valu
|
|||
<%helpers:longhand name="list-style-image" animation_value_type="none"
|
||||
boxed="${product == 'gecko'}"
|
||||
spec="https://drafts.csswg.org/css-lists/#propdef-list-style-image">
|
||||
use std::fmt;
|
||||
use values::computed::ComputedValueAsSpecified;
|
||||
use values::specified::UrlOrNone;
|
||||
pub use self::computed_value::T as SpecifiedValue;
|
||||
use style_traits::ToCss;
|
||||
|
||||
pub mod computed_value {
|
||||
use values::specified::UrlOrNone;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
#[derive(Debug, Clone, PartialEq, ToCss)]
|
||||
pub struct T(pub UrlOrNone);
|
||||
}
|
||||
|
||||
|
@ -132,12 +130,6 @@ ${helpers.single_keyword("list-style-position", "outside inside", animation_valu
|
|||
impl ComputedValueAsSpecified for SpecifiedValue {}
|
||||
no_viewport_percentage!(SpecifiedValue);
|
||||
|
||||
impl ToCss for SpecifiedValue {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
self.0.to_css(dest)
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_initial_value() -> computed_value::T {
|
||||
computed_value::T(Either::Second(None_))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue