From 292f899631f0faa43192e23748117987c8964c3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sun, 29 Apr 2018 03:02:21 +0200 Subject: [PATCH] style: Fix tidy issues and Servo build. --- Cargo.lock | 2 +- components/layout/display_list/builder.rs | 8 ++--- components/servo_arc/lib.rs | 2 +- .../style/properties/longhand/font.mako.rs | 2 +- components/style/servo/url.rs | 2 +- components/style/values/generics/image.rs | 2 ++ components/style/values/mod.rs | 4 +-- components/style/values/specified/box.rs | 2 +- components/style/values/specified/font.rs | 2 +- .../style_derive/specified_value_info.rs | 4 +-- components/style_traits/Cargo.toml | 5 +-- components/style_traits/lib.rs | 1 + .../style_traits/specified_value_info.rs | 7 ++++ tests/unit/style/properties/serialization.rs | 36 ------------------- tests/unit/style/rule_tree/bench.rs | 9 ++--- 15 files changed, 32 insertions(+), 56 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c6002808308..6e5c91f372a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -997,7 +997,6 @@ dependencies = [ "atomic_refcell 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "cssparser 0.23.2 (registry+https://github.com/rust-lang/crates.io-index)", "cstr 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", - "env_logger 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.39 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "malloc_size_of 0.0.1", @@ -3123,6 +3122,7 @@ dependencies = [ "serde 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)", "servo_arc 0.1.1", "servo_atoms 0.0.1", + "servo_url 0.0.1", "webrender_api 0.57.2 (git+https://github.com/servo/webrender)", ] diff --git a/components/layout/display_list/builder.rs b/components/layout/display_list/builder.rs index 141bbb52b80..65b12137c68 100644 --- a/components/layout/display_list/builder.rs +++ b/components/layout/display_list/builder.rs @@ -66,9 +66,9 @@ use style::servo::restyle_damage::ServoRestyleDamage; use style::values::{Either, RGBA}; use style::values::computed::Gradient; use style::values::computed::effects::SimpleShadow; -use style::values::computed::pointing::Cursor; use style::values::generics::background::BackgroundSize; use style::values::generics::image::{GradientKind, Image, PaintWorklet}; +use style::values::generics::pointing::Cursor; use style_traits::CSSPixel; use style_traits::ToCss; use style_traits::cursor::CursorKind; @@ -2952,11 +2952,11 @@ impl ComputedValuesCursorUtility for ComputedValues { fn get_cursor(&self, default_cursor: CursorKind) -> Option { match ( self.get_pointing().pointer_events, - self.get_pointing().cursor, + &self.get_pointing().cursor, ) { (PointerEvents::None, _) => None, - (PointerEvents::Auto, Cursor(CursorKind::Auto)) => Some(default_cursor), - (PointerEvents::Auto, Cursor(cursor)) => Some(cursor), + (PointerEvents::Auto, &Cursor { keyword: CursorKind::Auto, .. }) => Some(default_cursor), + (PointerEvents::Auto, &Cursor { keyword, .. }) => Some(keyword), } } } diff --git a/components/servo_arc/lib.rs b/components/servo_arc/lib.rs index b84ba879350..e2063c79a9c 100644 --- a/components/servo_arc/lib.rs +++ b/components/servo_arc/lib.rs @@ -925,7 +925,7 @@ impl Arc { /// /// ArcBorrow lets us deal with borrows of known-refcounted objects /// without needing to worry about how they're actually stored. -#[derive(Eq, Debug, PartialEq)] +#[derive(Debug, Eq, PartialEq)] pub struct ArcBorrow<'a, T: 'a>(&'a T); impl<'a, T> Copy for ArcBorrow<'a, T> {} diff --git a/components/style/properties/longhand/font.mako.rs b/components/style/properties/longhand/font.mako.rs index 112b4b4de54..7309aca8a38 100644 --- a/components/style/properties/longhand/font.mako.rs +++ b/components/style/properties/longhand/font.mako.rs @@ -450,7 +450,7 @@ ${helpers.predefined_type("-x-text-zoom", // a lot of code with `if product == gecko` conditionals, we have a // dummy system font module that does nothing - #[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, ToCss)] + #[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, SpecifiedValueInfo, ToCss)] #[cfg_attr(feature = "servo", derive(MallocSizeOf))] /// void enum for system font, can never exist pub enum SystemFont {} diff --git a/components/style/servo/url.rs b/components/style/servo/url.rs index b5eba690d36..c0867122ae3 100644 --- a/components/style/servo/url.rs +++ b/components/style/servo/url.rs @@ -23,7 +23,7 @@ use values::computed::{Context, ToComputedValue}; /// /// However, this approach is still not necessarily optimal: See /// -#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)] +#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize, SpecifiedValueInfo)] pub struct CssUrl { /// The original URI. This might be optional since we may insert computed /// values of images into the cascade directly, and we don't bother to diff --git a/components/style/values/generics/image.rs b/components/style/values/generics/image.rs index 5017559e00c..2da4d290039 100644 --- a/components/style/values/generics/image.rs +++ b/components/style/values/generics/image.rs @@ -145,6 +145,8 @@ pub struct PaintWorklet { pub arguments: Vec>, } +impl ::style_traits::SpecifiedValueInfo for PaintWorklet { } + impl ToCss for PaintWorklet { fn to_css(&self, dest: &mut CssWriter) -> fmt::Result where diff --git a/components/style/values/mod.rs b/components/style/values/mod.rs index a61b774bdbf..f02242e78d1 100644 --- a/components/style/values/mod.rs +++ b/components/style/values/mod.rs @@ -71,7 +71,7 @@ where /// Convenience void type to disable some properties and values through types. #[cfg_attr(feature = "servo", derive(Deserialize, MallocSizeOf, Serialize))] -#[derive(Clone, Copy, Debug, PartialEq, ToAnimatedValue, ToComputedValue, ToCss)] +#[derive(Clone, Copy, Debug, PartialEq, SpecifiedValueInfo, ToAnimatedValue, ToComputedValue, ToCss)] pub enum Impossible {} // FIXME(nox): This should be derived but the derive code cannot cope @@ -162,7 +162,7 @@ impl ToCss for CustomIdent { } /// -#[derive(Clone, Debug, MallocSizeOf, ToComputedValue, SpecifiedValueInfo)] +#[derive(Clone, Debug, MallocSizeOf, SpecifiedValueInfo, ToComputedValue)] pub enum KeyframesName { /// Ident(CustomIdent), diff --git a/components/style/values/specified/box.rs b/components/style/values/specified/box.rs index ab2872d26c3..f56d6afd430 100644 --- a/components/style/values/specified/box.rs +++ b/components/style/values/specified/box.rs @@ -522,7 +522,7 @@ pub fn assert_touch_action_matches() { } bitflags! { - #[derive(MallocSizeOf, ToComputedValue, SpecifiedValueInfo)] + #[derive(MallocSizeOf, SpecifiedValueInfo, ToComputedValue)] #[value_info(other_values = "none,strict,layout,style,paint")] /// Constants for contain: https://drafts.csswg.org/css-contain/#contain-property pub struct Contain: u8 { diff --git a/components/style/values/specified/font.rs b/components/style/values/specified/font.rs index 17ff3af6382..8ec4354ab7a 100644 --- a/components/style/values/specified/font.rs +++ b/components/style/values/specified/font.rs @@ -23,8 +23,8 @@ use values::computed::{Angle as ComputedAngle, Percentage as ComputedPercentage} use values::computed::{font as computed, Context, Length, NonNegativeLength, ToComputedValue}; use values::computed::font::{FamilyName, FontFamilyList, FontStyleAngle, SingleFontFamily}; use values::generics::NonNegative; -use values::generics::font::{self as generics, FeatureTagValue, FontSettings, FontTag}; use values::generics::font::{KeywordSize, VariationValue}; +use values::generics::font::{self as generics, FeatureTagValue, FontSettings, FontTag}; use values::specified::{AllowQuirks, Angle, Integer, LengthOrPercentage, NoCalcLength, Number, Percentage}; use values::specified::length::{FontBaseSize, AU_PER_PT, AU_PER_PX}; diff --git a/components/style_derive/specified_value_info.rs b/components/style_derive/specified_value_info.rs index 7168ec2509f..11ad7a0d1b4 100644 --- a/components/style_derive/specified_value_info.rs +++ b/components/style_derive/specified_value_info.rs @@ -4,7 +4,7 @@ use cg; use quote::Tokens; -use syn::{Data, DeriveInput, Fields, Ident,Type}; +use syn::{Data, DeriveInput, Fields, Ident, Type}; use to_css::{CssFieldAttrs, CssInputAttrs, CssVariantAttrs}; pub fn derive(mut input: DeriveInput) -> Tokens { @@ -101,7 +101,7 @@ pub fn derive(mut input: DeriveInput) -> Tokens { quote!() } else { let mut value_list = quote!(); - value_list.append_separated(values.iter(), quote!(,)); + value_list.append_separated(values.iter(), quote! { , }); quote! { _f(&[#value_list]); } }; diff --git a/components/style_traits/Cargo.toml b/components/style_traits/Cargo.toml index a2fafc6e978..67a6c851dce 100644 --- a/components/style_traits/Cargo.toml +++ b/components/style_traits/Cargo.toml @@ -10,7 +10,7 @@ name = "style_traits" path = "lib.rs" [features] -servo = ["serde", "servo_atoms", "cssparser/serde", "webrender_api"] +servo = ["serde", "servo_atoms", "cssparser/serde", "webrender_api", "servo_url"] gecko = [] [dependencies] @@ -24,4 +24,5 @@ selectors = { path = "../selectors" } serde = {version = "1.0", optional = true} webrender_api = {git = "https://github.com/servo/webrender", optional = true} servo_atoms = {path = "../atoms", optional = true} -servo_arc = {path = "../servo_arc" } +servo_arc = { path = "../servo_arc" } +servo_url = { path = "../url", optional = true } diff --git a/components/style_traits/lib.rs b/components/style_traits/lib.rs index 8d4e0846cc9..f232b157cf9 100644 --- a/components/style_traits/lib.rs +++ b/components/style_traits/lib.rs @@ -22,6 +22,7 @@ extern crate selectors; #[cfg(feature = "servo")] extern crate webrender_api; extern crate servo_arc; #[cfg(feature = "servo")] extern crate servo_atoms; +#[cfg(feature = "servo")] extern crate servo_url; #[cfg(feature = "servo")] pub use webrender_api::DevicePixel; diff --git a/components/style_traits/specified_value_info.rs b/components/style_traits/specified_value_info.rs index 122091fc8e9..28e1eef25e6 100644 --- a/components/style_traits/specified_value_info.rs +++ b/components/style_traits/specified_value_info.rs @@ -6,6 +6,7 @@ use servo_arc::Arc; use std::ops::Range; +use std::sync::Arc as StdArc; /// Type of value that a property supports. This is used by Gecko's /// devtools to make sense about value it parses, and types listed @@ -84,6 +85,11 @@ impl SpecifiedValueInfo for u32 {} impl SpecifiedValueInfo for str {} impl SpecifiedValueInfo for String {} +#[cfg(feature = "servo")] +impl SpecifiedValueInfo for ::servo_atoms::Atom {} +#[cfg(feature = "servo")] +impl SpecifiedValueInfo for ::servo_url::ServoUrl {} + impl SpecifiedValueInfo for Box { const SUPPORTED_TYPES: u8 = T::SUPPORTED_TYPES; fn collect_completion_keywords(f: KeywordsCollectFn) { @@ -111,6 +117,7 @@ macro_rules! impl_generic_specified_value_info { impl_generic_specified_value_info!(Option); impl_generic_specified_value_info!(Vec); impl_generic_specified_value_info!(Arc); +impl_generic_specified_value_info!(StdArc); impl_generic_specified_value_info!(Range); impl SpecifiedValueInfo for (T1, T2) diff --git a/tests/unit/style/properties/serialization.rs b/tests/unit/style/properties/serialization.rs index 369100aa686..e274d8a2a6a 100644 --- a/tests/unit/style/properties/serialization.rs +++ b/tests/unit/style/properties/serialization.rs @@ -487,42 +487,6 @@ mod shorthand_serialization { } } - mod outline { - use style::values::specified::outline::OutlineStyle; - use super::*; - - #[test] - fn outline_should_show_all_properties_when_set() { - let mut properties = Vec::new(); - - let width = BorderSideWidth::Length(Length::from_px(4f32)); - let style = OutlineStyle::Other(BorderStyle::Solid); - let color = RGBA::new(255, 0, 0, 255).into(); - - properties.push(PropertyDeclaration::OutlineWidth(width)); - properties.push(PropertyDeclaration::OutlineStyle(style)); - properties.push(PropertyDeclaration::OutlineColor(color)); - - let serialization = shorthand_properties_to_string(properties); - assert_eq!(serialization, "outline: 4px solid rgb(255, 0, 0);"); - } - - #[test] - fn outline_should_serialize_correctly_when_style_is_auto() { - let mut properties = Vec::new(); - - let width = BorderSideWidth::Length(Length::from_px(4f32)); - let style = OutlineStyle::Auto; - let color = RGBA::new(255, 0, 0, 255).into(); - properties.push(PropertyDeclaration::OutlineWidth(width)); - properties.push(PropertyDeclaration::OutlineStyle(style)); - properties.push(PropertyDeclaration::OutlineColor(color)); - - let serialization = shorthand_properties_to_string(properties); - assert_eq!(serialization, "outline: 4px auto rgb(255, 0, 0);"); - } - } - mod background { use super::*; diff --git a/tests/unit/style/rule_tree/bench.rs b/tests/unit/style/rule_tree/bench.rs index edc3b70daf4..54af9d39532 100644 --- a/tests/unit/style/rule_tree/bench.rs +++ b/tests/unit/style/rule_tree/bench.rs @@ -62,11 +62,12 @@ fn parse_rules(css: &str) -> Vec<(StyleSource, CascadeLevel)> { let rules = s.contents.rules.read_with(&guard); rules.0.iter().filter_map(|rule| { match *rule { - CssRule::Style(ref style_rule) => Some(style_rule), + CssRule::Style(ref style_rule) => Some(( + StyleSource::from_rule(style_rule.clone()), + CascadeLevel::UserNormal, + )), _ => None, } - }).cloned().map(StyleSource::Style).map(|s| { - (s, CascadeLevel::UserNormal) }).collect() } @@ -78,7 +79,7 @@ fn test_insertion_style_attribute(rule_tree: &RuleTree, rules: &[(StyleSource, C shared_lock: &SharedRwLock) -> StrongRuleNode { let mut rules = rules.to_vec(); - rules.push((StyleSource::Declarations(Arc::new(shared_lock.wrap(PropertyDeclarationBlock::with_one( + rules.push((StyleSource::from_declarations(Arc::new(shared_lock.wrap(PropertyDeclarationBlock::with_one( PropertyDeclaration::Display( longhands::display::SpecifiedValue::Block), Importance::Normal