diff --git a/components/style/font_face.rs b/components/style/font_face.rs index 38de34a3705..96a13416f34 100644 --- a/components/style/font_face.rs +++ b/components/style/font_face.rs @@ -48,24 +48,16 @@ impl OneOrMoreSeparated for Source { /// `url()` function. /// /// -#[derive(Clone, Debug, Eq, PartialEq)] #[cfg_attr(feature = "servo", derive(Deserialize, Serialize))] +#[derive(Clone, Debug, Eq, PartialEq, ToCss)] pub struct UrlSource { /// The specified url. pub url: SpecifiedUrl, /// The format hints specified with the `format()` function. + #[css(skip)] pub format_hints: Vec, } -impl ToCss for UrlSource { - fn to_css(&self, dest: &mut CssWriter) -> fmt::Result - where - W: Write, - { - self.url.to_css(dest) - } -} - /// A font-display value for a @font-face rule. /// The font-display descriptor determines how a font face is displayed based /// on whether and when it is downloaded and ready to use. diff --git a/components/style/gecko/url.rs b/components/style/gecko/url.rs index 7e0ce29f12b..323c6ebb9b3 100644 --- a/components/style/gecko/url.rs +++ b/components/style/gecko/url.rs @@ -12,12 +12,12 @@ use gecko_bindings::sugar::refptr::RefPtr; use malloc_size_of::{MallocSizeOf, MallocSizeOfOps}; use parser::ParserContext; use servo_arc::{Arc, RawOffsetArc}; -use std::fmt::{self, Write}; use std::mem; -use style_traits::{CssWriter, ToCss, ParseError}; +use style_traits::ParseError; /// A specified url() value for gecko. Gecko does not eagerly resolve SpecifiedUrls. -#[derive(Clone, Debug, PartialEq)] +#[css(function = "url")] +#[derive(Clone, Debug, PartialEq, ToCss)] pub struct SpecifiedUrl { /// The URL in unresolved string form. /// @@ -26,10 +26,12 @@ pub struct SpecifiedUrl { serialization: Arc, /// The URL extra data. + #[css(skip)] pub extra_data: RefPtr, /// Cache ImageValue, if any, so that we can reuse it while rematching a /// a property with this specified url value. + #[css(skip)] pub image_value: Option>, } trivial_to_computed_value!(SpecifiedUrl); @@ -133,17 +135,6 @@ impl SpecifiedUrl { } } -impl ToCss for SpecifiedUrl { - fn to_css(&self, dest: &mut CssWriter) -> fmt::Result - where - W: Write, - { - dest.write_str("url(")?; - self.serialization.to_css(dest)?; - dest.write_str(")") - } -} - impl MallocSizeOf for SpecifiedUrl { fn size_of(&self, _ops: &mut MallocSizeOfOps) -> usize { use gecko_bindings::bindings::Gecko_ImageValue_SizeOfIncludingThis; diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index 2462d21a715..283e8dd1fec 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -1707,59 +1707,35 @@ impl PropertyId { /// A declaration using a CSS-wide keyword. #[cfg_attr(feature = "gecko", derive(MallocSizeOf))] -#[derive(Clone, PartialEq)] +#[derive(Clone, PartialEq, ToCss)] pub struct WideKeywordDeclaration { + #[css(skip)] id: LonghandId, keyword: CSSWideKeyword, } -impl ToCss for WideKeywordDeclaration { - fn to_css(&self, dest: &mut CssWriter) -> fmt::Result - where - W: fmt::Write, - { - self.keyword.to_css(dest) - } -} - /// An unparsed declaration that contains `var()` functions. #[cfg_attr(feature = "gecko", derive(MallocSizeOf))] -#[derive(Clone, PartialEq)] +#[derive(Clone, PartialEq, ToCss)] pub struct VariableDeclaration { + #[css(skip)] id: LonghandId, #[cfg_attr(feature = "gecko", ignore_malloc_size_of = "XXX: how to handle this?")] value: Arc, } -impl ToCss for VariableDeclaration { - fn to_css(&self, dest: &mut CssWriter) -> fmt::Result - where - W: fmt::Write, - { - self.value.to_css(dest) - } -} - /// A custom property declaration with the property name and the declared value. #[cfg_attr(feature = "gecko", derive(MallocSizeOf))] -#[derive(Clone, PartialEq)] +#[derive(Clone, PartialEq, ToCss)] pub struct CustomDeclaration { /// The name of the custom property. + #[css(skip)] pub name: ::custom_properties::Name, /// The value of the custom property. #[cfg_attr(feature = "gecko", ignore_malloc_size_of = "XXX: how to handle this?")] pub value: DeclaredValueOwned>, } -impl ToCss for CustomDeclaration { - fn to_css(&self, dest: &mut CssWriter) -> fmt::Result - where - W: fmt::Write, - { - self.value.to_css(dest) - } -} - impl fmt::Debug for PropertyDeclaration { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { self.id().to_css(&mut CssWriter::new(f))?; diff --git a/components/style/values/computed/font.rs b/components/style/values/computed/font.rs index b8d2873a113..83d3369c3ea 100644 --- a/components/style/values/computed/font.rs +++ b/components/style/values/computed/font.rs @@ -40,13 +40,14 @@ pub use values::specified::font::{XTextZoom, XLang, MozScriptSizeMultiplier, Fon #[cfg_attr(feature = "servo", derive(Deserialize, Serialize))] pub struct FontWeight(pub u16); -#[derive(Animate, ComputeSquaredDistance, MallocSizeOf, ToAnimatedZero)] -#[derive(Clone, Copy, Debug, PartialEq)] +#[derive(Animate, Clone, ComputeSquaredDistance, Copy, Debug, MallocSizeOf)] +#[derive(PartialEq, ToAnimatedZero, ToCss)] /// The computed value of font-size pub struct FontSize { /// The size. pub size: NonNegativeLength, /// If derived from a keyword, the keyword and additional transformations applied to it + #[css(skip)] pub keyword_info: Option, } @@ -159,12 +160,6 @@ impl FontSize { } } -impl ToCss for FontSize { - fn to_css(&self, dest: &mut CssWriter) -> fmt::Result where W: fmt::Write { - self.size.to_css(dest) - } -} - /// XXXManishearth it might be better to /// animate this as computed, however this complicates /// clamping and might not be the right thing to do. diff --git a/components/style/values/generics/font.rs b/components/style/values/generics/font.rs index f052d7d2876..c498a3cfaef 100644 --- a/components/style/values/generics/font.rs +++ b/components/style/values/generics/font.rs @@ -162,14 +162,16 @@ impl Parse for FontTag { } #[derive(Animate, Clone, ComputeSquaredDistance, Copy, Debug, MallocSizeOf)] -#[derive(PartialEq, ToAnimatedValue, ToAnimatedZero)] +#[derive(PartialEq, ToAnimatedValue, ToAnimatedZero, ToCss)] /// Additional information for keyword-derived font sizes. pub struct KeywordInfo { /// The keyword used pub kw: KeywordSize, /// A factor to be multiplied by the computed size of the keyword + #[css(skip)] pub factor: f32, /// An additional Au offset to add to the kw*factor in the case of calcs + #[css(skip)] pub offset: Length, } diff --git a/components/style/values/specified/font.rs b/components/style/values/specified/font.rs index cb2b2b63519..8b2cf9737b9 100644 --- a/components/style/values/specified/font.rs +++ b/components/style/values/specified/font.rs @@ -118,7 +118,7 @@ impl ToComputedValue for FontWeight { } } -#[derive(Clone, Debug, MallocSizeOf, PartialEq)] +#[derive(Clone, Debug, MallocSizeOf, PartialEq, ToCss)] /// A specified font-size value pub enum FontSize { /// A length; e.g. 10px. @@ -142,21 +142,6 @@ pub enum FontSize { System(SystemFont) } -impl ToCss for FontSize { - fn to_css(&self, dest: &mut CssWriter) -> fmt::Result - where - W: Write, - { - match *self { - FontSize::Length(ref lop) => lop.to_css(dest), - FontSize::Keyword(info) => info.kw.to_css(dest), - FontSize::Smaller => dest.write_str("smaller"), - FontSize::Larger => dest.write_str("larger"), - FontSize::System(sys) => sys.to_css(dest), - } - } -} - impl From for FontSize { fn from(other: LengthOrPercentage) -> Self { FontSize::Length(other) @@ -2015,9 +2000,9 @@ impl Parse for VariationValue { } -#[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq, ToComputedValue)] +#[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq, ToComputedValue, ToCss)] /// text-zoom. Enable if true, disable if false -pub struct XTextZoom(pub bool); +pub struct XTextZoom(#[css(skip)] pub bool); impl Parse for XTextZoom { fn parse<'i, 't>(_: &ParserContext, input: &mut Parser<'i, 't>) -> Result> { @@ -2026,18 +2011,9 @@ impl Parse for XTextZoom { } } -impl ToCss for XTextZoom { - fn to_css(&self, _: &mut CssWriter) -> fmt::Result - where - W: Write, - { - Ok(()) - } -} - -#[derive(Clone, Debug, MallocSizeOf, PartialEq, ToComputedValue)] +#[derive(Clone, Debug, MallocSizeOf, PartialEq, ToComputedValue, ToCss)] /// Internal property that reflects the lang attribute -pub struct XLang(pub Atom); +pub struct XLang(#[css(skip)] pub Atom); impl XLang { #[inline] @@ -2057,15 +2033,6 @@ impl Parse for XLang { } } -impl ToCss for XLang { - fn to_css(&self, _: &mut CssWriter) -> fmt::Result - where - W: Write, - { - Ok(()) - } -} - #[cfg_attr(feature = "gecko", derive(MallocSizeOf))] #[derive(Clone, Copy, Debug, PartialEq, ToCss)] /// Specifies the minimum font size allowed due to changes in scriptlevel. diff --git a/components/style/values/specified/table.rs b/components/style/values/specified/table.rs index 89f9941633d..1ca24533144 100644 --- a/components/style/values/specified/table.rs +++ b/components/style/values/specified/table.rs @@ -6,12 +6,11 @@ use cssparser::Parser; use parser::{Parse, ParserContext}; -use std::fmt; -use style_traits::{CssWriter, ToCss, StyleParseErrorKind, ParseError}; +use style_traits::{StyleParseErrorKind, ParseError}; -#[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq, ToComputedValue)] +#[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq, ToComputedValue, ToCss)] /// span. for `` pres attr -pub struct XSpan(pub i32); +pub struct XSpan(#[css(skip)] pub i32); impl Parse for XSpan { // never parse it, only set via presentation attribute @@ -19,9 +18,3 @@ impl Parse for XSpan { Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError)) } } - -impl ToCss for XSpan { - fn to_css(&self, _: &mut CssWriter) -> fmt::Result where W: fmt::Write { - Ok(()) - } -} diff --git a/components/style_derive/to_css.rs b/components/style_derive/to_css.rs index 8864696fb9d..5d9654de350 100644 --- a/components/style_derive/to_css.rs +++ b/components/style_derive/to_css.rs @@ -53,6 +53,9 @@ pub fn derive(input: syn::DeriveInput) -> Tokens { } else { for binding in bindings { let attrs = cg::parse_field_attrs::(&binding.ast()); + if attrs.skip { + continue; + } if !attrs.ignore_bound { where_clause.add_trait_bound(&binding.ast().ty); } @@ -152,4 +155,5 @@ pub struct CssVariantAttrs { #[derive(Default, FromField)] struct CssFieldAttrs { ignore_bound: bool, + skip: bool, } diff --git a/components/style_traits/values.rs b/components/style_traits/values.rs index 0c3dcc8851b..188fccc9691 100644 --- a/components/style_traits/values.rs +++ b/components/style_traits/values.rs @@ -26,10 +26,12 @@ use std::fmt::{self, Write}; /// serialised like unit variants and its fields are surrounded by parentheses; /// * if `#[css(iterable)]` is found on a function variant, that variant needs /// to have a single member, and that member needs to be iterable. The -/// iterable will be serialized as the arguments for the function. +/// iterable will be serialized as the arguments for the function; /// * if `#[css(dimension)]` is found on a variant, that variant needs /// to have a single member. The variant would be serialized as a CSS -/// dimension token, like: . +/// dimension token, like: ; +/// * if `#[css(skip)]` is found on a field, the `ToCss` call for that field +/// is skipped; /// * finally, one can put `#[css(derive_debug)]` on the whole type, to /// implement `Debug` by a single call to `ToCss::to_css`. pub trait ToCss {