Introduce #[css(skip)]

This commit is contained in:
Anthony Ramine 2018-03-05 15:37:36 +01:00
parent 7931df716d
commit ca45695db1
8 changed files with 31 additions and 96 deletions

View file

@ -48,24 +48,16 @@ impl OneOrMoreSeparated for Source {
/// `url()` function.
///
/// <https://drafts.csswg.org/css-fonts/#src-desc>
#[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<String>,
}
impl ToCss for UrlSource {
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> 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.

View file

@ -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<String>,
/// The URL extra data.
#[css(skip)]
pub extra_data: RefPtr<URLExtraData>,
/// 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<RefPtr<ImageValue>>,
}
trivial_to_computed_value!(SpecifiedUrl);
@ -133,17 +135,6 @@ impl SpecifiedUrl {
}
}
impl ToCss for SpecifiedUrl {
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> 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;

View file

@ -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<W>(&self, dest: &mut CssWriter<W>) -> 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<UnparsedValue>,
}
impl ToCss for VariableDeclaration {
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> 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<Arc<::custom_properties::SpecifiedValue>>,
}
impl ToCss for CustomDeclaration {
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> 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))?;

View file

@ -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<KeywordInfo>,
}
@ -159,12 +160,6 @@ impl FontSize {
}
}
impl ToCss for FontSize {
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> 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.

View file

@ -2015,9 +2015,9 @@ impl Parse for VariationValue<Number> {
}
#[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<XTextZoom, ParseError<'i>> {
@ -2026,18 +2026,9 @@ impl Parse for XTextZoom {
}
}
impl ToCss for XTextZoom {
fn to_css<W>(&self, _: &mut CssWriter<W>) -> 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 +2048,6 @@ impl Parse for XLang {
}
}
impl ToCss for XLang {
fn to_css<W>(&self, _: &mut CssWriter<W>) -> 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.

View file

@ -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 `<col span>` 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<W>(&self, _: &mut CssWriter<W>) -> fmt::Result where W: fmt::Write {
Ok(())
}
}

View file

@ -53,6 +53,9 @@ pub fn derive(input: syn::DeriveInput) -> Tokens {
} else {
for binding in bindings {
let attrs = cg::parse_field_attrs::<CssFieldAttrs>(&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,
}

View file

@ -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: <member><identifier>.
/// dimension token, like: <member><identifier>;
/// * 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 {