From 87efab93fb21fc267cbd42b21d75468972109e13 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Mon, 11 Sep 2017 20:04:12 -0500 Subject: [PATCH] servo: Merge #18447 - Remove most uses of ComputedValueAsSpecified (from servo:kill-cvas); r=emilio Source-Repo: https://github.com/servo/servo Source-Revision: 5cc2b4f705e420b156899ed55072ccc11d0e50c0 --HG-- extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear extra : subtree_revision : 1e210928eef95f3c02c404694e55f84625e13bee --- servo/components/style/counter_style/mod.rs | 4 ++-- servo/components/style/gecko/url.rs | 1 + servo/components/style/macros.rs | 2 +- .../style/properties/longhand/counters.mako.rs | 7 ++----- .../properties/longhand/inherited_box.mako.rs | 7 ++----- .../properties/longhand/inherited_svg.mako.rs | 8 ++------ .../style/properties/longhand/list.mako.rs | 12 +++--------- .../style/properties/longhand/pointing.mako.rs | 9 +++------ .../style/properties/longhand/text.mako.rs | 4 +--- .../style/properties/longhand/ui.mako.rs | 6 +----- servo/components/style/values/computed/mod.rs | 15 ++++++++++----- servo/components/style/values/generics/mod.rs | 2 +- servo/components/style/values/specified/mod.rs | 11 +---------- 13 files changed, 30 insertions(+), 58 deletions(-) diff --git a/servo/components/style/counter_style/mod.rs b/servo/components/style/counter_style/mod.rs index 094f14a1cdcf..6bdd22d8e07a 100644 --- a/servo/components/style/counter_style/mod.rs +++ b/servo/components/style/counter_style/mod.rs @@ -342,7 +342,7 @@ impl ToCss for System { } /// https://drafts.csswg.org/css-counter-styles/#typedef-symbol -#[derive(Clone, Debug, Eq, PartialEq)] +#[derive(Clone, Debug, Eq, PartialEq, ToComputedValue)] pub enum Symbol { /// String(String), @@ -489,7 +489,7 @@ impl Parse for Fallback { } /// https://drafts.csswg.org/css-counter-styles/#descdef-counter-style-symbols -#[derive(Clone, Debug, Eq, PartialEq)] +#[derive(Clone, Debug, Eq, PartialEq, ToComputedValue)] pub struct Symbols(pub Vec); impl Parse for Symbols { diff --git a/servo/components/style/gecko/url.rs b/servo/components/style/gecko/url.rs index b206ad761e71..0c2348fbaa25 100644 --- a/servo/components/style/gecko/url.rs +++ b/servo/components/style/gecko/url.rs @@ -30,6 +30,7 @@ pub struct SpecifiedUrl { /// a property with this specified url value. pub image_value: Option>, } +trivial_to_computed_value!(SpecifiedUrl); impl SpecifiedUrl { /// Try to parse a URL from a string value that is a valid CSS token for a diff --git a/servo/components/style/macros.rs b/servo/components/style/macros.rs index aeec5516fda1..e2791e6f09fb 100644 --- a/servo/components/style/macros.rs +++ b/servo/components/style/macros.rs @@ -5,7 +5,7 @@ //! Various macro helpers. macro_rules! trivial_to_computed_value { - ($name: ident) => { + ($name:ty) => { impl $crate::values::computed::ToComputedValue for $name { type ComputedValue = $name; diff --git a/servo/components/style/properties/longhand/counters.mako.rs b/servo/components/style/properties/longhand/counters.mako.rs index 190351895c7e..16aca0ff60f9 100644 --- a/servo/components/style/properties/longhand/counters.mako.rs +++ b/servo/components/style/properties/longhand/counters.mako.rs @@ -8,7 +8,6 @@ <%helpers:longhand name="content" boxed="True" animation_value_type="discrete" spec="https://drafts.csswg.org/css-content/#propdef-content"> - use values::computed::ComputedValueAsSpecified; #[cfg(feature = "gecko")] use values::generics::CounterStyleOrNone; #[cfg(feature = "gecko")] @@ -22,8 +21,6 @@ pub use self::computed_value::T as SpecifiedValue; pub use self::computed_value::ContentItem; - impl ComputedValueAsSpecified for SpecifiedValue {} - pub mod computed_value { use cssparser; use std::fmt; @@ -39,8 +36,8 @@ #[cfg(feature = "gecko")] use values::specified::Attr; - #[derive(Clone, Debug, Eq, PartialEq)] #[cfg_attr(feature = "servo", derive(HeapSizeOf))] + #[derive(Clone, Debug, Eq, PartialEq, ToComputedValue)] pub enum ContentItem { /// Literal string content. String(String), @@ -100,8 +97,8 @@ } } - #[derive(Clone, Debug, Eq, PartialEq)] #[cfg_attr(feature = "servo", derive(HeapSizeOf))] + #[derive(Clone, Debug, Eq, PartialEq, ToComputedValue)] pub enum T { Normal, None, diff --git a/servo/components/style/properties/longhand/inherited_box.mako.rs b/servo/components/style/properties/longhand/inherited_box.mako.rs index 16779dfbf03d..23a621309f27 100644 --- a/servo/components/style/properties/longhand/inherited_box.mako.rs +++ b/servo/components/style/properties/longhand/inherited_box.mako.rs @@ -256,17 +256,14 @@ ${helpers.single_keyword("image-rendering", spec="Nonstandard (internal layout use only)"> use std::fmt; use style_traits::ToCss; - use values::computed::ComputedValueAsSpecified; - - #[derive(Clone, Copy, Debug, Eq, PartialEq)] - #[cfg_attr(feature = "servo", derive(HeapSizeOf, Deserialize, Serialize))] + #[cfg_attr(feature = "servo", derive(Deserialize, HeapSizeOf, Serialize))] + #[derive(Clone, Copy, Debug, Eq, PartialEq, ToComputedValue)] pub struct SpecifiedValue(pub bool); pub mod computed_value { pub type T = super::SpecifiedValue; } - impl ComputedValueAsSpecified for SpecifiedValue {} pub fn get_initial_value() -> computed_value::T { SpecifiedValue(false) diff --git a/servo/components/style/properties/longhand/inherited_svg.mako.rs b/servo/components/style/properties/longhand/inherited_svg.mako.rs index 3d3b82541fc1..7ab122146190 100644 --- a/servo/components/style/properties/longhand/inherited_svg.mako.rs +++ b/servo/components/style/properties/longhand/inherited_svg.mako.rs @@ -136,8 +136,6 @@ ${helpers.predefined_type("marker-end", "UrlOrNone", "Either::Second(None_)", animation_value_type="discrete" products="gecko" spec="https://www.w3.org/TR/SVG2/painting.html#PaintOrder"> - - use values::computed::ComputedValueAsSpecified; use std::fmt; use style_traits::ToCss; @@ -164,8 +162,8 @@ ${helpers.predefined_type("marker-end", "UrlOrNone", "Either::Second(None_)", /// /// Higher priority values, i.e. the values specified first, /// will be painted first (and may be covered by paintings of lower priority) - #[derive(Clone, Copy, Debug, PartialEq)] #[cfg_attr(feature = "servo", derive(HeapSizeOf))] + #[derive(Clone, Copy, Debug, PartialEq, ToComputedValue)] pub struct SpecifiedValue(pub u8); pub mod computed_value { @@ -258,10 +256,8 @@ ${helpers.predefined_type("marker-end", "UrlOrNone", "Either::Second(None_)", Ok(()) } } - - - impl ComputedValueAsSpecified for SpecifiedValue { } + <%helpers:vector_longhand name="-moz-context-properties" animation_value_type="none" products="gecko" diff --git a/servo/components/style/properties/longhand/list.mako.rs b/servo/components/style/properties/longhand/list.mako.rs index 2540922ca2ef..10d81fc4691c 100644 --- a/servo/components/style/properties/longhand/list.mako.rs +++ b/servo/components/style/properties/longhand/list.mako.rs @@ -33,7 +33,6 @@ ${helpers.single_keyword("list-style-position", "outside inside", animation_valu <%helpers:longhand name="list-style-type" animation_value_type="discrete" boxed="True" spec="https://drafts.csswg.org/css-lists/#propdef-list-style-type"> use values::CustomIdent; - use values::computed::ComputedValueAsSpecified; use values::generics::CounterStyleOrNone; pub use self::computed_value::T as SpecifiedValue; @@ -42,15 +41,13 @@ ${helpers.single_keyword("list-style-position", "outside inside", animation_valu use values::generics::CounterStyleOrNone; /// | | none - #[derive(Clone, Debug, Eq, PartialEq, ToCss)] + #[derive(Clone, Debug, Eq, PartialEq, ToComputedValue, ToCss)] pub enum T { CounterStyle(CounterStyleOrNone), String(String), } } - impl ComputedValueAsSpecified for SpecifiedValue {} - #[cfg(feature = "gecko")] impl SpecifiedValue { /// Convert from gecko keyword to list-style-type. @@ -144,18 +141,15 @@ ${helpers.single_keyword("list-style-position", "outside inside", animation_valu use cssparser::serialize_string; use std::fmt; use style_traits::ToCss; - use values::computed::ComputedValueAsSpecified; pub use self::computed_value::T as SpecifiedValue; pub mod computed_value { - #[derive(Clone, Debug, PartialEq)] #[cfg_attr(feature = "servo", derive(HeapSizeOf))] - pub struct T(pub Vec<(String,String)>); + #[derive(Clone, Debug, PartialEq, ToComputedValue)] + pub struct T(pub Vec<(String, String)>); } - impl ComputedValueAsSpecified for SpecifiedValue {} - impl ToCss for SpecifiedValue { fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { if self.0.is_empty() { diff --git a/servo/components/style/properties/longhand/pointing.mako.rs b/servo/components/style/properties/longhand/pointing.mako.rs index 121e5193b4c7..0965640482ef 100644 --- a/servo/components/style/properties/longhand/pointing.mako.rs +++ b/servo/components/style/properties/longhand/pointing.mako.rs @@ -9,12 +9,9 @@ <%helpers:longhand name="cursor" boxed="${product == 'gecko'}" animation_value_type="discrete" spec="https://drafts.csswg.org/css-ui/#cursor"> pub use self::computed_value::T as SpecifiedValue; - use values::computed::ComputedValueAsSpecified; #[cfg(feature = "gecko")] use values::specified::url::SpecifiedUrl; - impl ComputedValueAsSpecified for SpecifiedValue {} - pub mod computed_value { #[cfg(feature = "gecko")] use std::fmt; @@ -25,7 +22,7 @@ use values::specified::url::SpecifiedUrl; #[cfg_attr(feature = "servo", derive(HeapSizeOf))] - #[derive(Clone, Copy, Debug, PartialEq, ToCss)] + #[derive(Clone, Copy, Debug, PartialEq, ToComputedValue, ToCss)] pub enum Keyword { Auto, Cursor(Cursor), @@ -35,14 +32,14 @@ pub type T = Keyword; #[cfg(feature = "gecko")] - #[derive(Clone, Debug, PartialEq)] + #[derive(Clone, Debug, PartialEq, ToComputedValue)] pub struct Image { pub url: SpecifiedUrl, pub hotspot: Option<(f32, f32)>, } #[cfg(feature = "gecko")] - #[derive(Clone, Debug, PartialEq)] + #[derive(Clone, Debug, PartialEq, ToComputedValue)] pub struct T { pub images: Vec, pub keyword: Keyword, diff --git a/servo/components/style/properties/longhand/text.mako.rs b/servo/components/style/properties/longhand/text.mako.rs index 0bb640e02e23..78d98d637918 100644 --- a/servo/components/style/properties/longhand/text.mako.rs +++ b/servo/components/style/properties/longhand/text.mako.rs @@ -146,12 +146,10 @@ ${helpers.single_keyword("unicode-bidi", spec="https://drafts.csswg.org/css-text-decor/#propdef-text-decoration-line"> use std::fmt; use style_traits::ToCss; - use values::computed::ComputedValueAsSpecified; - - impl ComputedValueAsSpecified for SpecifiedValue {} bitflags! { #[cfg_attr(feature = "servo", derive(HeapSizeOf))] + #[derive(ToComputedValue)] pub flags SpecifiedValue: u8 { const NONE = 0, const UNDERLINE = 0x01, diff --git a/servo/components/style/properties/longhand/ui.mako.rs b/servo/components/style/properties/longhand/ui.mako.rs index c33f41a654e0..2e3f52d12be0 100644 --- a/servo/components/style/properties/longhand/ui.mako.rs +++ b/servo/components/style/properties/longhand/ui.mako.rs @@ -49,12 +49,10 @@ ${helpers.single_keyword("-moz-window-shadow", "none default menu tooltip sheet" spec="None (Nonstandard Firefox-only property)"> use std::fmt; use style_traits::ToCss; - use values::computed::ComputedValueAsSpecified; - pub mod computed_value { - #[derive(Clone, Copy, Debug, PartialEq)] #[cfg_attr(feature = "servo", derive(HeapSizeOf))] + #[derive(Clone, Copy, Debug, PartialEq, ToComputedValue)] pub struct T(pub bool); } @@ -76,8 +74,6 @@ ${helpers.single_keyword("-moz-window-shadow", "none default menu tooltip sheet" computed_value::T(false) } - impl ComputedValueAsSpecified for SpecifiedValue {} - pub fn parse<'i, 't>(_context: &ParserContext, input: &mut Parser<'i, 't>) -> Result> { match input.expect_integer()? { diff --git a/servo/components/style/values/computed/mod.rs b/servo/components/style/values/computed/mod.rs index 53a7fbe74c45..339417ff2e7f 100644 --- a/servo/components/style/values/computed/mod.rs +++ b/servo/components/style/values/computed/mod.rs @@ -4,7 +4,7 @@ //! Computed values. -use Atom; +use {Atom, Namespace}; use context::QuirksMode; use euclid::Size2D; use font_metrics::FontMetricsProvider; @@ -19,6 +19,7 @@ use std::fmt; #[cfg(feature = "servo")] use std::sync::Arc; use style_traits::ToCss; +use style_traits::cursor::Cursor; use super::{CSSFloat, CSSInteger}; use super::generics::{GreaterThanOrEqualToOne, NonNegative}; use super::generics::grid::{GridLine as GenericGridLine, TrackBreadth as GenericTrackBreadth}; @@ -332,13 +333,17 @@ impl ToComputedValue for T } } -trivial_to_computed_value!(Atom); +trivial_to_computed_value!(()); +trivial_to_computed_value!(bool); +trivial_to_computed_value!(f32); +trivial_to_computed_value!(i32); trivial_to_computed_value!(u8); trivial_to_computed_value!(u16); -trivial_to_computed_value!(bool); -trivial_to_computed_value!(i32); -trivial_to_computed_value!(f32); +trivial_to_computed_value!(Atom); trivial_to_computed_value!(BorderStyle); +trivial_to_computed_value!(Cursor); +trivial_to_computed_value!(Namespace); +trivial_to_computed_value!(String); /// A `` value. pub type Number = CSSFloat; diff --git a/servo/components/style/values/generics/mod.rs b/servo/components/style/values/generics/mod.rs index ba39c19bd6ab..0f419da0383d 100644 --- a/servo/components/style/values/generics/mod.rs +++ b/servo/components/style/values/generics/mod.rs @@ -71,7 +71,7 @@ impl SymbolsType { /// /// Since wherever is used, 'none' is a valid value as /// well, we combine them into one type to make code simpler. -#[derive(Clone, Debug, Eq, PartialEq, ToCss)] +#[derive(Clone, Debug, Eq, PartialEq, ToComputedValue, ToCss)] pub enum CounterStyleOrNone { /// `none` None, diff --git a/servo/components/style/values/specified/mod.rs b/servo/components/style/values/specified/mod.rs index 7c91096bb8be..2b08912f73ef 100644 --- a/servo/components/style/values/specified/mod.rs +++ b/servo/components/style/values/specified/mod.rs @@ -21,7 +21,6 @@ use super::computed::{Context, ToComputedValue}; use super::generics::{GreaterThanOrEqualToOne, NonNegative}; use super::generics::grid::{GridLine as GenericGridLine, TrackBreadth as GenericTrackBreadth}; use super::generics::grid::{TrackSize as GenericTrackSize, TrackList as GenericTrackList}; -use values::computed::ComputedValueAsSpecified; use values::specified::calc::CalcNode; pub use properties::animated_properties::TransitionProperty; @@ -84,8 +83,6 @@ pub mod url { use cssparser::Parser; use parser::{Parse, ParserContext}; use style_traits::ParseError; -#[cfg(feature = "gecko")] -use values::computed::ComputedValueAsSpecified; #[cfg(feature = "servo")] pub use ::servo::url::*; @@ -100,10 +97,6 @@ impl Parse for SpecifiedUrl { } impl Eq for SpecifiedUrl {} - -#[cfg(feature = "gecko")] -impl ComputedValueAsSpecified for SpecifiedUrl {} - } /// Parse an `` value, handling `calc()` correctly. @@ -681,8 +674,8 @@ pub type NamespaceId = (); /// An attr(...) rule /// /// `[namespace? `|`]? ident` -#[derive(Clone, Debug, Eq, PartialEq)] #[cfg_attr(feature = "servo", derive(HeapSizeOf))] +#[derive(Clone, Debug, Eq, PartialEq, ToComputedValue)] pub struct Attr { /// Optional namespace pub namespace: Option<(Namespace, NamespaceId)>, @@ -777,5 +770,3 @@ impl ToCss for Attr { dest.write_str(")") } } - -impl ComputedValueAsSpecified for Attr {}