From 08b5d999f0842f194337b965155f2daf60aced91 Mon Sep 17 00:00:00 2001 From: CYBAI Date: Sat, 16 Dec 2017 16:39:37 -0600 Subject: [PATCH] servo: Merge #19583 - style: Move will-change outside of mako (from CYBAI:move-will-change-out-of-mako); r=emilio This is a sub-PR of #19015 r? emilio --- - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #19582 - [x] These changes do not require tests Source-Repo: https://github.com/servo/servo Source-Revision: 8aba41d951d63a09cc6c12cba7ed200ea4396544 --HG-- extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear extra : subtree_revision : 24b27ac8fd2e837f365610ecd737993588b6ea98 --- .../components/style/properties/gecko.mako.rs | 10 +-- .../style/properties/longhand/box.mako.rs | 64 +++---------------- servo/components/style/values/computed/box.rs | 3 +- servo/components/style/values/computed/mod.rs | 2 +- .../components/style/values/specified/box.rs | 47 ++++++++++++++ .../components/style/values/specified/mod.rs | 2 +- servo/components/style_derive/to_css.rs | 2 +- 7 files changed, 65 insertions(+), 65 deletions(-) diff --git a/servo/components/style/properties/gecko.mako.rs b/servo/components/style/properties/gecko.mako.rs index 5b46f784d99b..45fe22f3b6c4 100644 --- a/servo/components/style/properties/gecko.mako.rs +++ b/servo/components/style/properties/gecko.mako.rs @@ -3619,11 +3619,11 @@ fn static_assert() { if self.gecko.mWillChange.len() == 0 { T::Auto } else { - T::AnimateableFeatures( - self.gecko.mWillChange.iter().map(|gecko_atom| { - CustomIdent((gecko_atom.mRawPtr as *mut nsAtom).into()) - }).collect() - ) + let custom_idents: Vec = self.gecko.mWillChange.iter().map(|gecko_atom| { + CustomIdent((gecko_atom.mRawPtr as *mut nsAtom).into()) + }).collect(); + + T::AnimateableFeatures(custom_idents.into_boxed_slice()) } } diff --git a/servo/components/style/properties/longhand/box.mako.rs b/servo/components/style/properties/longhand/box.mako.rs index 2e1c1d271d70..694566ec62f1 100644 --- a/servo/components/style/properties/longhand/box.mako.rs +++ b/servo/components/style/properties/longhand/box.mako.rs @@ -881,62 +881,14 @@ ${helpers.single_keyword("-moz-orient", spec="Nonstandard (https://developer.mozilla.org/en-US/docs/Web/CSS/-moz-orient)", animation_value_type="discrete")} -<%helpers:longhand name="will-change" products="gecko" animation_value_type="discrete" - spec="https://drafts.csswg.org/css-will-change/#will-change"> - use std::fmt; - use style_traits::ToCss; - use values::CustomIdent; - - pub mod computed_value { - pub use super::SpecifiedValue as T; - } - - #[derive(Clone, Debug, MallocSizeOf, PartialEq, ToComputedValue)] - pub enum SpecifiedValue { - Auto, - AnimateableFeatures(Vec), - } - - impl ToCss for SpecifiedValue { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { - match *self { - SpecifiedValue::Auto => dest.write_str("auto"), - SpecifiedValue::AnimateableFeatures(ref features) => { - let (first, rest) = features.split_first().unwrap(); - first.to_css(dest)?; - for feature in rest { - dest.write_str(", ")?; - feature.to_css(dest)?; - } - Ok(()) - } - } - } - } - - #[inline] - pub fn get_initial_value() -> computed_value::T { - computed_value::T::Auto - } - - /// auto | # - pub fn parse<'i, 't>(_context: &ParserContext, input: &mut Parser<'i, 't>) - -> Result> { - if input.try(|input| input.expect_ident_matching("auto")).is_ok() { - Ok(computed_value::T::Auto) - } else { - input.parse_comma_separated(|i| { - let location = i.current_source_location(); - CustomIdent::from_ident(location, i.expect_ident()?, &[ - "will-change", - "none", - "all", - "auto", - ]) - }).map(SpecifiedValue::AnimateableFeatures) - } - } - +${helpers.predefined_type( + "will-change", + "WillChange", + "computed::WillChange::auto()", + products="gecko", + animation_value_type="discrete", + spec="https://drafts.csswg.org/css-will-change/#will-change" +)} ${helpers.predefined_type( "shape-image-threshold", "Opacity", "0.0", diff --git a/servo/components/style/values/computed/box.rs b/servo/components/style/values/computed/box.rs index e43fbd615695..989c96174f00 100644 --- a/servo/components/style/values/computed/box.rs +++ b/servo/components/style/values/computed/box.rs @@ -9,7 +9,8 @@ use values::computed::length::LengthOrPercentage; use values::generics::box_::AnimationIterationCount as GenericAnimationIterationCount; use values::generics::box_::VerticalAlign as GenericVerticalAlign; -pub use values::specified::box_::{AnimationName, OverflowClipBox, OverscrollBehavior, ScrollSnapType}; +pub use values::specified::box_::{AnimationName, OverflowClipBox, OverscrollBehavior}; +pub use values::specified::box_::{ScrollSnapType, WillChange}; /// A computed value for the `vertical-align` property. pub type VerticalAlign = GenericVerticalAlign; diff --git a/servo/components/style/values/computed/mod.rs b/servo/components/style/values/computed/mod.rs index b446aa6caa79..16fe42adc15b 100644 --- a/servo/components/style/values/computed/mod.rs +++ b/servo/components/style/values/computed/mod.rs @@ -41,7 +41,7 @@ pub use self::font::{FontFamily, FontLanguageOverride, FontVariantSettings, Font pub use self::font::{FontVariantLigatures, FontVariantNumeric, FontFeatureSettings}; pub use self::font::{MozScriptLevel, MozScriptMinSize, MozScriptSizeMultiplier, XTextZoom, XLang}; pub use self::box_::{AnimationIterationCount, AnimationName, OverscrollBehavior}; -pub use self::box_::{OverflowClipBox, ScrollSnapType, VerticalAlign}; +pub use self::box_::{OverflowClipBox, ScrollSnapType, VerticalAlign, WillChange}; pub use self::color::{Color, ColorPropertyValue, RGBAColor}; pub use self::effects::{BoxShadow, Filter, SimpleShadow}; pub use self::flex::FlexBasis; diff --git a/servo/components/style/values/specified/box.rs b/servo/components/style/values/specified/box.rs index 247eb7a16a9d..29f699d2c606 100644 --- a/servo/components/style/values/specified/box.rs +++ b/servo/components/style/values/specified/box.rs @@ -9,6 +9,7 @@ use cssparser::Parser; use parser::{Parse, ParserContext}; use std::fmt; use style_traits::{ParseError, ToCss}; +use values::CustomIdent; use values::KeyframesName; use values::generics::box_::AnimationIterationCount as GenericAnimationIterationCount; use values::generics::box_::VerticalAlign as GenericVerticalAlign; @@ -130,3 +131,49 @@ define_css_keyword_enum! { OverflowClipBox: "content-box" => ContentBox, } add_impls_for_keyword_enum!(OverflowClipBox); + +#[derive(Clone, Debug, MallocSizeOf, PartialEq, ToComputedValue, ToCss)] +/// Provides a rendering hint to the user agent, +/// stating what kinds of changes the author expects +/// to perform on the element +/// +/// +pub enum WillChange { + /// Expresses no particular intent + Auto, + #[css(comma, iterable)] + /// + AnimateableFeatures(Box<[CustomIdent]>), +} + +impl WillChange { + #[inline] + /// Get default value of `will-change` as `auto` + pub fn auto() -> WillChange { + WillChange::Auto + } +} + +impl Parse for WillChange { + /// auto | # + fn parse<'i, 't>( + _context: &ParserContext, + input: &mut Parser<'i, 't> + ) -> Result> { + if input.try(|input| input.expect_ident_matching("auto")).is_ok() { + return Ok(WillChange::Auto); + } + + let custom_idents = input.parse_comma_separated(|i| { + let location = i.current_source_location(); + CustomIdent::from_ident(location, i.expect_ident()?, &[ + "will-change", + "none", + "all", + "auto", + ]) + })?; + + Ok(WillChange::AnimateableFeatures(custom_idents.into_boxed_slice())) + } +} diff --git a/servo/components/style/values/specified/mod.rs b/servo/components/style/values/specified/mod.rs index 93fd4643015d..c16d12eb6c0c 100644 --- a/servo/components/style/values/specified/mod.rs +++ b/servo/components/style/values/specified/mod.rs @@ -35,7 +35,7 @@ pub use self::font::{FontFamily, FontLanguageOverride, FontVariantSettings, Font pub use self::font::{FontVariantLigatures, FontVariantNumeric, FontFeatureSettings}; pub use self::font::{MozScriptLevel, MozScriptMinSize, MozScriptSizeMultiplier, XTextZoom, XLang}; pub use self::box_::{AnimationIterationCount, AnimationName, OverscrollBehavior}; -pub use self::box_::{OverflowClipBox, ScrollSnapType, VerticalAlign}; +pub use self::box_::{OverflowClipBox, ScrollSnapType, VerticalAlign, WillChange}; pub use self::color::{Color, ColorPropertyValue, RGBAColor}; pub use self::effects::{BoxShadow, Filter, SimpleShadow}; pub use self::flex::FlexBasis; diff --git a/servo/components/style_derive/to_css.rs b/servo/components/style_derive/to_css.rs index 02a44617bdef..12fad8f0d346 100644 --- a/servo/components/style_derive/to_css.rs +++ b/servo/components/style_derive/to_css.rs @@ -27,7 +27,7 @@ pub fn derive(input: DeriveInput) -> Tokens { let mut expr = if !bindings.is_empty() { let mut expr = quote! {}; - if variant_attrs.function && variant_attrs.iterable { + if variant_attrs.iterable { assert_eq!(bindings.len(), 1); let binding = &bindings[0]; expr = quote! {