diff --git a/Cargo.lock b/Cargo.lock index b0cb400e9cfe..f279d729d17d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -162,7 +162,7 @@ dependencies = [ name = "baldrdash" version = "0.1.0" dependencies = [ - "bindgen 0.43.0 (registry+https://github.com/rust-lang/crates.io-index)", + "bindgen 0.43.2 (registry+https://github.com/rust-lang/crates.io-index)", "cranelift-codegen 0.28.0 (registry+https://github.com/rust-lang/crates.io-index)", "cranelift-wasm 0.28.0 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -215,7 +215,7 @@ dependencies = [ [[package]] name = "bindgen" -version = "0.43.0" +version = "0.43.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1291,7 +1291,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" name = "js" version = "0.1.4" dependencies = [ - "bindgen 0.43.0 (registry+https://github.com/rust-lang/crates.io-index)", + "bindgen 0.43.2 (registry+https://github.com/rust-lang/crates.io-index)", "cmake 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", "glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2496,7 +2496,7 @@ dependencies = [ "app_units 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "arrayvec 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "atomic_refcell 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "bindgen 0.43.0 (registry+https://github.com/rust-lang/crates.io-index)", + "bindgen 0.43.2 (registry+https://github.com/rust-lang/crates.io-index)", "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)", "cssparser 0.25.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3290,7 +3290,7 @@ dependencies = [ "checksum base64 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "621fc7ecb8008f86d7fb9b95356cd692ce9514b80a86d85b397f32a22da7b9e2" "checksum binary-space-partition 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "88ceb0d16c4fd0e42876e298d7d3ce3780dd9ebdcbe4199816a32c77e08597ff" "checksum bincode 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bda13183df33055cbb84b847becce220d392df502ebe7a4a78d7021771ed94d0" -"checksum bindgen 0.43.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b41df015ccbc22b038641bd84d0aeeff01e0a4c0714ed35ed0e9a3dd8ad8d732" +"checksum bindgen 0.43.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6d52d263eacd15d26cbcf215d254b410bd58212aaa2d3c453a04b2d3b3adcf41" "checksum binjs_meta 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "430239e4551e42b80fa5d92322ac80ea38c9dda56e5d5582e057e2288352b71a" "checksum bit-set 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6f1efcc46c18245a69c38fcc5cc650f16d3a59d034f3106e9ed63748f695730a" "checksum bit-vec 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4440d5cb623bb7390ae27fec0bb6c61111969860f8e3ae198bfa0663645e67cf" diff --git a/layout/style/ServoBindings.toml b/layout/style/ServoBindings.toml index 9aa023165773..cc739cd5460b 100644 --- a/layout/style/ServoBindings.toml +++ b/layout/style/ServoBindings.toml @@ -56,10 +56,7 @@ hide-types = [ "nsINode_ErrorResult", "nsDOMAttributeMap_ErrorResult", # End of JS::Value related types - # This is generated by cbindgen, and we map it to its original rust type. - # Note: This could also avoid some rust-bindgen issues on complex template - # structs. i.e. We may use incorrect template parameters for nested structs. - # https://github.com/rust-lang-nursery/rust-bindgen/issues/1429 + # https://github.com/rust-lang/rust-bindgen/issues/1503 "mozilla::StyleTimingFunction.*", ] bitfield-enums = [ @@ -416,6 +413,7 @@ cbindgen-types = [ { gecko = "StyleOverflowAnchor", servo = "values::computed::OverflowAnchor" }, { gecko = "StyleLengthPercentage", servo = "values::computed::LengthPercentage" }, { gecko = "StyleNonNegativeLengthPercentage", servo = "values::computed::NonNegativeLengthPercentage" }, + { gecko = "StyleGenericLengthPercentageOrAuto", servo = "values::generics::length::LengthPercentageOrAuto" }, { gecko = "StyleLengthPercentageOrAuto", servo = "values::computed::LengthPercentageOrAuto" }, { gecko = "StyleRect", servo = "values::generics::rect::Rect" }, { gecko = "StyleIntersectionObserverRootMargin", servo = "values::specified::gecko::IntersectionObserverRootMargin" }, diff --git a/layout/style/nsStyleCoord.h b/layout/style/nsStyleCoord.h index cd3d70007e27..e066f039876e 100644 --- a/layout/style/nsStyleCoord.h +++ b/layout/style/nsStyleCoord.h @@ -99,16 +99,20 @@ nscoord LengthPercentage::ResolveWith(T aPercentageGetter) const { return Resolve(aPercentageGetter()); } -const LengthPercentage& LengthPercentageOrAuto::AsLengthPercentage() const { +template <> +inline const LengthPercentage& LengthPercentageOrAuto::AsLengthPercentage() + const { MOZ_ASSERT(IsLengthPercentage()); return length_percentage._0; } -bool LengthPercentageOrAuto::ConvertsToLength() const { +template <> +inline bool LengthPercentageOrAuto::ConvertsToLength() const { return IsLengthPercentage() && AsLengthPercentage().ConvertsToLength(); } -bool LengthPercentageOrAuto::HasPercent() const { +template <> +inline bool LengthPercentageOrAuto::HasPercent() const { return IsLengthPercentage() && AsLengthPercentage().HasPercent(); } diff --git a/layout/style/nsStyleStruct.h b/layout/style/nsStyleStruct.h index f76543d7226a..68bb5daa2f38 100644 --- a/layout/style/nsStyleStruct.h +++ b/layout/style/nsStyleStruct.h @@ -2041,7 +2041,7 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleDisplay { float mShapeImageThreshold = 0.0f; // The margin around a shape-outside: . - mozilla::LengthPercentage mShapeMargin; + mozilla::NonNegativeLengthPercentage mShapeMargin; mozilla::StyleShapeSource mShapeOutside; diff --git a/servo/components/style/cbindgen.toml b/servo/components/style/cbindgen.toml index d76a57c95411..4c0b631d31d5 100644 --- a/servo/components/style/cbindgen.toml +++ b/servo/components/style/cbindgen.toml @@ -99,7 +99,7 @@ item_types = ["enums", "structs", "typedefs"] template inline nscoord ResolveWith(T aPercentageGetter) const; """ -"LengthPercentageOrAuto" = """ +"GenericLengthPercentageOrAuto" = """ inline const StyleLengthPercentage& AsLengthPercentage() const; inline bool HasPercent() const; inline bool ConvertsToLength() const; diff --git a/servo/components/style/gecko/conversions.rs b/servo/components/style/gecko/conversions.rs index 0f6ac89c9f2f..ccaa16c844cd 100644 --- a/servo/components/style/gecko/conversions.rs +++ b/servo/components/style/gecko/conversions.rs @@ -27,6 +27,7 @@ use crate::values::computed::{LengthPercentageOrAuto, NonNegativeLengthPercentag use crate::values::generics::box_::VerticalAlign; use crate::values::generics::grid::{TrackListValue, TrackSize}; use crate::values::generics::image::{CompatMode, GradientItem, Image as GenericImage}; +use crate::values::generics::length::LengthPercentageOrAuto as GenericLengthPercentageOrAuto; use crate::values::generics::rect::Rect; use crate::values::generics::NonNegative; use app_units::Au; @@ -62,19 +63,19 @@ impl From for LengthPercentage { } } -impl LengthPercentageOrAuto { +impl NonNegativeLengthPercentageOrAuto { /// Convert this value in an appropriate `nsStyleCoord::CalcValue`. pub fn to_calc_value(&self) -> Option { match *self { - LengthPercentageOrAuto::LengthPercentage(len) => Some(From::from(len)), - LengthPercentageOrAuto::Auto => None, + GenericLengthPercentageOrAuto::LengthPercentage(ref len) => Some(From::from(len.0)), + GenericLengthPercentageOrAuto::Auto => None, } } } impl From for LengthPercentageOrAuto { fn from(other: nsStyleCoord_CalcValue) -> LengthPercentageOrAuto { - LengthPercentageOrAuto::LengthPercentage(LengthPercentage::from(other)) + GenericLengthPercentageOrAuto::LengthPercentage(LengthPercentage::from(other)) } } @@ -82,7 +83,7 @@ impl From for LengthPercentageOrAuto { // disappear as we move more stuff to cbindgen. impl From for NonNegativeLengthPercentageOrAuto { fn from(other: nsStyleCoord_CalcValue) -> Self { - NonNegative(LengthPercentageOrAuto::LengthPercentage( + GenericLengthPercentageOrAuto::LengthPercentage(NonNegative( LengthPercentage::with_clamping_mode( Au(other.mLength).into(), if other.mHasPercent { diff --git a/servo/components/style/gecko/values.rs b/servo/components/style/gecko/values.rs index 42177bf08587..ac3495a7504d 100644 --- a/servo/components/style/gecko/values.rs +++ b/servo/components/style/gecko/values.rs @@ -14,15 +14,15 @@ use crate::media_queries::Device; use crate::values::computed::basic_shape::ShapeRadius as ComputedShapeRadius; use crate::values::computed::FlexBasis as ComputedFlexBasis; use crate::values::computed::{Angle, ExtremumLength, Length, LengthPercentage}; -use crate::values::computed::{LengthPercentageOrAuto, Percentage}; -use crate::values::computed::{LengthPercentageOrNone, Number, NumberOrPercentage}; use crate::values::computed::{MaxLength as ComputedMaxLength, MozLength as ComputedMozLength}; +use crate::values::computed::{NonNegativeLengthPercentage, Percentage}; +use crate::values::computed::{Number, NumberOrPercentage}; use crate::values::generics::basic_shape::ShapeRadius; use crate::values::generics::box_::Perspective; use crate::values::generics::flex::FlexBasis; use crate::values::generics::gecko::ScrollSnapPoint; use crate::values::generics::grid::{TrackBreadth, TrackKeyword}; -use crate::values::generics::length::{MaxLength, MozLength}; +use crate::values::generics::length::{LengthPercentageOrAuto, MaxLength, MozLength}; use crate::values::generics::{CounterStyleOrNone, NonNegative}; use crate::values::{Auto, Either, None_, Normal}; use crate::Atom; @@ -183,7 +183,10 @@ impl GeckoStyleCoordConvertible for Length { } } -impl GeckoStyleCoordConvertible for LengthPercentageOrAuto { +impl GeckoStyleCoordConvertible for LengthPercentageOrAuto +where + LengthPercentage: GeckoStyleCoordConvertible, +{ fn to_gecko_style_coord(&self, coord: &mut T) { match *self { LengthPercentageOrAuto::Auto => coord.set_value(CoordDataValue::Auto), @@ -200,23 +203,6 @@ impl GeckoStyleCoordConvertible for LengthPercentageOrAuto { } } -impl GeckoStyleCoordConvertible for LengthPercentageOrNone { - fn to_gecko_style_coord(&self, coord: &mut T) { - match *self { - LengthPercentageOrNone::None => coord.set_value(CoordDataValue::None), - LengthPercentageOrNone::LengthPercentage(ref lp) => lp.to_gecko_style_coord(coord), - } - } - - fn from_gecko_style_coord(coord: &T) -> Option { - match coord.as_value() { - CoordDataValue::None => Some(LengthPercentageOrNone::None), - _ => LengthPercentage::from_gecko_style_coord(coord) - .map(LengthPercentageOrNone::LengthPercentage), - } - } -} - impl GeckoStyleCoordConvertible for TrackBreadth { fn to_gecko_style_coord(&self, coord: &mut T) { match *self { @@ -367,34 +353,40 @@ impl GeckoStyleCoordConvertible for ExtremumLength { impl GeckoStyleCoordConvertible for ComputedMozLength { fn to_gecko_style_coord(&self, coord: &mut T) { match *self { - MozLength::LengthPercentageOrAuto(ref lpoa) => lpoa.to_gecko_style_coord(coord), + MozLength::LengthPercentage(ref lpoa) => lpoa.to_gecko_style_coord(coord), + MozLength::Auto => coord.set_value(CoordDataValue::Auto), MozLength::ExtremumLength(ref e) => e.to_gecko_style_coord(coord), } } fn from_gecko_style_coord(coord: &T) -> Option { - LengthPercentageOrAuto::from_gecko_style_coord(coord) - .map(MozLength::LengthPercentageOrAuto) - .or_else(|| { - ExtremumLength::from_gecko_style_coord(coord).map(MozLength::ExtremumLength) - }) + if let CoordDataValue::Auto = coord.as_value() { + return Some(MozLength::Auto); + } + if let Some(lp) = NonNegativeLengthPercentage::from_gecko_style_coord(coord) { + return Some(MozLength::LengthPercentage(lp)); + } + ExtremumLength::from_gecko_style_coord(coord).map(MozLength::ExtremumLength) } } impl GeckoStyleCoordConvertible for ComputedMaxLength { fn to_gecko_style_coord(&self, coord: &mut T) { match *self { - MaxLength::LengthPercentageOrNone(ref lpon) => lpon.to_gecko_style_coord(coord), + MaxLength::LengthPercentage(ref lpon) => lpon.to_gecko_style_coord(coord), + MaxLength::None => coord.set_value(CoordDataValue::None), MaxLength::ExtremumLength(ref e) => e.to_gecko_style_coord(coord), } } fn from_gecko_style_coord(coord: &T) -> Option { - LengthPercentageOrNone::from_gecko_style_coord(coord) - .map(MaxLength::LengthPercentageOrNone) - .or_else(|| { - ExtremumLength::from_gecko_style_coord(coord).map(MaxLength::ExtremumLength) - }) + if let CoordDataValue::None = coord.as_value() { + return Some(MaxLength::None); + } + if let Some(lp) = NonNegativeLengthPercentage::from_gecko_style_coord(coord) { + return Some(MaxLength::LengthPercentage(lp)); + } + ExtremumLength::from_gecko_style_coord(coord).map(MaxLength::ExtremumLength) } } diff --git a/servo/components/style/properties/gecko.mako.rs b/servo/components/style/properties/gecko.mako.rs index 798e39adb273..297357446a27 100644 --- a/servo/components/style/properties/gecko.mako.rs +++ b/servo/components/style/properties/gecko.mako.rs @@ -1390,7 +1390,6 @@ impl Clone for ${style_struct.gecko_struct_name} { "LengthOrNormal": impl_style_coord, "LengthPercentage": impl_simple, "LengthPercentageOrAuto": impl_style_coord, - "LengthPercentageOrNone": impl_style_coord, "MaxLength": impl_style_coord, "MozLength": impl_style_coord, "MozScriptMinSize": impl_absolute_length, @@ -3831,11 +3830,11 @@ fn static_assert() { BackgroundSize::Explicit { width: explicit_width, height: explicit_height } => { let mut w_type = nsStyleImageLayers_Size_DimensionType::eAuto; let mut h_type = nsStyleImageLayers_Size_DimensionType::eAuto; - if let Some(w) = explicit_width.0.to_calc_value() { + if let Some(w) = explicit_width.to_calc_value() { width = w; w_type = nsStyleImageLayers_Size_DimensionType::eLengthPercentage; } - if let Some(h) = explicit_height.0.to_calc_value() { + if let Some(h) = explicit_height.to_calc_value() { height = h; h_type = nsStyleImageLayers_Size_DimensionType::eLengthPercentage; } diff --git a/servo/components/style/properties/longhands/position.mako.rs b/servo/components/style/properties/longhands/position.mako.rs index cc5515dbac72..2a0f86d056a9 100644 --- a/servo/components/style/properties/longhands/position.mako.rs +++ b/servo/components/style/properties/longhands/position.mako.rs @@ -13,7 +13,7 @@ ${helpers.predefined_type( side, "LengthPercentageOrAuto", - "computed::LengthPercentageOrAuto::Auto", + "computed::LengthPercentageOrAuto::auto()", spec="https://www.w3.org/TR/CSS2/visuren.html#propdef-%s" % side, flags="GETCS_NEEDS_LAYOUT_FLUSH", animation_value_type="ComputedValue", @@ -27,7 +27,7 @@ ${helpers.predefined_type( "inset-%s" % side, "LengthPercentageOrAuto", - "computed::LengthPercentageOrAuto::Auto", + "computed::LengthPercentageOrAuto::auto()", spec="https://drafts.csswg.org/css-logical-props/#propdef-inset-%s" % side, flags="GETCS_NEEDS_LAYOUT_FLUSH", alias="offset-%s:layout.css.offset-logical-properties.enabled" % side, @@ -270,24 +270,12 @@ ${helpers.predefined_type( animation_value_type="MozLength", servo_restyle_damage="reflow", )} - ${helpers.predefined_type( - "max-%s" % size, - "MaxLength", - "computed::MaxLength::none()", - logical=logical, - logical_group="max-size", - allow_quirks=not logical, - spec=spec % size, - animation_value_type="MaxLength", - servo_restyle_damage="reflow", - )} % else: // servo versions (no keyword support) ${helpers.predefined_type( size, - "LengthPercentageOrAuto", - "computed::LengthPercentageOrAuto::Auto", - "parse_non_negative", + "NonNegativeLengthPercentageOrAuto", + "computed::NonNegativeLengthPercentageOrAuto::auto()", spec=spec % size, logical_group="size", allow_quirks=not logical, @@ -296,9 +284,8 @@ ${helpers.predefined_type( )} ${helpers.predefined_type( "min-%s" % size, - "LengthPercentage", - "computed::LengthPercentage::zero()", - "parse_non_negative", + "NonNegativeLengthPercentage", + "computed::NonNegativeLengthPercentage::zero()", spec=spec % ("min-%s" % size), logical_group="min-size", animation_value_type="ComputedValue", @@ -306,19 +293,18 @@ ${helpers.predefined_type( allow_quirks=not logical, servo_restyle_damage="reflow", )} - ${helpers.predefined_type( - "max-%s" % size, - "LengthPercentageOrNone", - "computed::LengthPercentageOrNone::None", - "parse_non_negative", - spec=spec % ("max-%s" % size), - logical_group="max-size", - animation_value_type="ComputedValue", - logical=logical, - allow_quirks=not logical, - servo_restyle_damage="reflow", - )} % endif + ${helpers.predefined_type( + "max-%s" % size, + "MaxLength", + "computed::MaxLength::none()", + logical=logical, + logical_group="max-size", + allow_quirks=not logical, + spec=spec % size, + animation_value_type="MaxLength", + servo_restyle_damage="reflow", + )} % endfor ${helpers.single_keyword( diff --git a/servo/components/style/properties/properties.mako.rs b/servo/components/style/properties/properties.mako.rs index 439db6d927e5..23ca997a1324 100644 --- a/servo/components/style/properties/properties.mako.rs +++ b/servo/components/style/properties/properties.mako.rs @@ -3016,7 +3016,7 @@ impl ComputedValuesInner { /// Get the logical computed inline size. #[inline] - pub fn content_inline_size(&self) -> computed::LengthPercentageOrAuto { + pub fn content_inline_size(&self) -> computed::NonNegativeLengthPercentageOrAuto { let position_style = self.get_position(); if self.writing_mode.is_vertical() { position_style.height @@ -3027,35 +3027,35 @@ impl ComputedValuesInner { /// Get the logical computed block size. #[inline] - pub fn content_block_size(&self) -> computed::LengthPercentageOrAuto { + pub fn content_block_size(&self) -> computed::NonNegativeLengthPercentageOrAuto { let position_style = self.get_position(); if self.writing_mode.is_vertical() { position_style.width } else { position_style.height } } /// Get the logical computed min inline size. #[inline] - pub fn min_inline_size(&self) -> computed::LengthPercentage { + pub fn min_inline_size(&self) -> computed::NonNegativeLengthPercentage { let position_style = self.get_position(); if self.writing_mode.is_vertical() { position_style.min_height } else { position_style.min_width } } /// Get the logical computed min block size. #[inline] - pub fn min_block_size(&self) -> computed::LengthPercentage { + pub fn min_block_size(&self) -> computed::NonNegativeLengthPercentage { let position_style = self.get_position(); if self.writing_mode.is_vertical() { position_style.min_width } else { position_style.min_height } } /// Get the logical computed max inline size. #[inline] - pub fn max_inline_size(&self) -> computed::LengthPercentageOrNone { + pub fn max_inline_size(&self) -> computed::MaxLength { let position_style = self.get_position(); if self.writing_mode.is_vertical() { position_style.max_height } else { position_style.max_width } } /// Get the logical computed max block size. #[inline] - pub fn max_block_size(&self) -> computed::LengthPercentageOrNone { + pub fn max_block_size(&self) -> computed::MaxLength { let position_style = self.get_position(); if self.writing_mode.is_vertical() { position_style.max_width } else { position_style.max_height } } diff --git a/servo/components/style/stylesheets/viewport_rule.rs b/servo/components/style/stylesheets/viewport_rule.rs index 862399e065c1..8325216519da 100644 --- a/servo/components/style/stylesheets/viewport_rule.rs +++ b/servo/components/style/stylesheets/viewport_rule.rs @@ -11,16 +11,17 @@ use crate::context::QuirksMode; use crate::error_reporting::ContextualParseError; use crate::font_metrics::get_metrics_provider_for_product; use crate::media_queries::Device; -use crate::parser::ParserContext; +use crate::parser::{Parse, ParserContext}; use crate::properties::StyleBuilder; use crate::rule_cache::RuleCacheConditions; use crate::shared_lock::{SharedRwLockReadGuard, StylesheetGuards, ToCssWithGuard}; use crate::str::CssStringWriter; use crate::stylesheets::{Origin, StylesheetInDocument}; use crate::values::computed::{Context, ToComputedValue}; -use crate::values::specified::{ - self, LengthPercentageOrAuto, NoCalcLength, ViewportPercentageLength, -}; +use crate::values::generics::length::LengthPercentageOrAuto; +use crate::values::generics::NonNegative; +use crate::values::specified::{self, NoCalcLength}; +use crate::values::specified::{NonNegativeLengthPercentageOrAuto, ViewportPercentageLength}; use app_units::Au; use cssparser::CowRcStr; use cssparser::{parse_important, AtRuleParser, DeclarationListParser, DeclarationParser, Parser}; @@ -151,7 +152,7 @@ trait FromMeta: Sized { #[cfg_attr(feature = "servo", derive(MallocSizeOf))] #[derive(Clone, Debug, PartialEq, ToCss)] pub enum ViewportLength { - Specified(LengthPercentageOrAuto), + Specified(NonNegativeLengthPercentageOrAuto), ExtendToZoom, } @@ -159,9 +160,9 @@ impl FromMeta for ViewportLength { fn from_meta(value: &str) -> Option { macro_rules! specified { ($value:expr) => { - ViewportLength::Specified(LengthPercentageOrAuto::LengthPercentage( + ViewportLength::Specified(LengthPercentageOrAuto::LengthPercentage(NonNegative( specified::LengthPercentage::Length($value), - )) + ))) }; } @@ -188,7 +189,7 @@ impl ViewportLength { ) -> Result> { // we explicitly do not accept 'extend-to-zoom', since it is a UA // internal value for viewport translation - LengthPercentageOrAuto::parse_non_negative(context, input).map(ViewportLength::Specified) + NonNegativeLengthPercentageOrAuto::parse(context, input).map(ViewportLength::Specified) } } diff --git a/servo/components/style/values/animated/length.rs b/servo/components/style/values/animated/length.rs index dd678f5c3954..73957618ceaa 100644 --- a/servo/components/style/values/animated/length.rs +++ b/servo/components/style/values/animated/length.rs @@ -4,10 +4,8 @@ //! Animation implementation for various length-related types. -use super::{Animate, Procedure, ToAnimatedValue}; +use super::{Animate, Procedure}; use crate::values::computed::length::LengthPercentage; -use crate::values::computed::MaxLength as ComputedMaxLength; -use crate::values::computed::MozLength as ComputedMozLength; use crate::values::computed::Percentage; /// @@ -38,51 +36,3 @@ impl Animate for LengthPercentage { )) } } - -// FIXME(emilio): These should use NonNegative<> instead. -impl ToAnimatedValue for ComputedMaxLength { - type AnimatedValue = Self; - - #[inline] - fn to_animated_value(self) -> Self { - self - } - - #[inline] - fn from_animated_value(animated: Self::AnimatedValue) -> Self { - use crate::values::computed::LengthPercentageOrNone; - use crate::values::generics::length::MaxLength as GenericMaxLength; - match animated { - GenericMaxLength::LengthPercentageOrNone(lpn) => { - let result = match lpn { - LengthPercentageOrNone::LengthPercentage(len) => { - LengthPercentageOrNone::LengthPercentage(len.clamp_to_non_negative()) - }, - LengthPercentageOrNone::None => lpn, - }; - GenericMaxLength::LengthPercentageOrNone(result) - }, - _ => animated, - } - } -} - -impl ToAnimatedValue for ComputedMozLength { - type AnimatedValue = Self; - - #[inline] - fn to_animated_value(self) -> Self { - self - } - - #[inline] - fn from_animated_value(animated: Self::AnimatedValue) -> Self { - use crate::values::generics::length::MozLength as GenericMozLength; - match animated { - GenericMozLength::LengthPercentageOrAuto(lpa) => { - GenericMozLength::LengthPercentageOrAuto(lpa.clamp_to_non_negative()) - }, - _ => animated, - } - } -} diff --git a/servo/components/style/values/computed/background.rs b/servo/components/style/values/computed/background.rs index 08f10c9c1eca..dc23915a74bd 100644 --- a/servo/components/style/values/computed/background.rs +++ b/servo/components/style/values/computed/background.rs @@ -4,20 +4,21 @@ //! Computed types for CSS values related to backgrounds. -use crate::values::computed::length::NonNegativeLengthPercentageOrAuto; +use crate::values::computed::length::NonNegativeLengthPercentage; use crate::values::generics::background::BackgroundSize as GenericBackgroundSize; +use crate::values::generics::length::LengthPercentageOrAuto; pub use crate::values::specified::background::BackgroundRepeat; /// A computed value for the `background-size` property. -pub type BackgroundSize = GenericBackgroundSize; +pub type BackgroundSize = GenericBackgroundSize; impl BackgroundSize { /// Returns `auto auto`. pub fn auto() -> Self { GenericBackgroundSize::Explicit { - width: NonNegativeLengthPercentageOrAuto::auto(), - height: NonNegativeLengthPercentageOrAuto::auto(), + width: LengthPercentageOrAuto::auto(), + height: LengthPercentageOrAuto::auto(), } } } diff --git a/servo/components/style/values/computed/length.rs b/servo/components/style/values/computed/length.rs index c779594202bf..313b4151d2bd 100644 --- a/servo/components/style/values/computed/length.rs +++ b/servo/components/style/values/computed/length.rs @@ -7,13 +7,15 @@ use super::{Context, Number, Percentage, ToComputedValue}; use crate::values::animated::ToAnimatedValue; use crate::values::distance::{ComputeSquaredDistance, SquaredDistance}; -use crate::values::generics::length::MaxLength as GenericMaxLength; -use crate::values::generics::length::MozLength as GenericMozLength; +use crate::values::generics::length as generics; +use crate::values::generics::length::{ + MaxLength as GenericMaxLength, MozLength as GenericMozLength, +}; use crate::values::generics::transform::IsZeroLength; use crate::values::generics::NonNegative; use crate::values::specified::length::ViewportPercentageLength; use crate::values::specified::length::{AbsoluteLength, FontBaseSize, FontRelativeLength}; -use crate::values::{specified, Auto, CSSFloat, Either, IsAuto, Normal}; +use crate::values::{specified, Auto, CSSFloat, Either, Normal}; use app_units::Au; use ordered_float::NotNan; use std::fmt::{self, Write}; @@ -452,151 +454,61 @@ impl IsZeroLength for LengthPercentage { } } -#[allow(missing_docs)] -#[css(derive_debug)] -#[derive( - Animate, Clone, ComputeSquaredDistance, Copy, MallocSizeOf, PartialEq, ToAnimatedZero, ToCss, -)] -#[repr(C, u8)] -pub enum LengthPercentageOrAuto { - LengthPercentage(LengthPercentage), - Auto, -} +/// Some boilerplate to share between negative and non-negative +/// length-percentage or auto. +macro_rules! computed_length_percentage_or_auto { + ($inner:ty) => { + /// Returns the `0` value. + #[inline] + pub fn zero() -> Self { + generics::LengthPercentageOrAuto::LengthPercentage(<$inner>::zero()) + } -impl LengthPercentageOrAuto { - /// Returns the `0` value. - #[inline] - pub fn zero() -> Self { - LengthPercentageOrAuto::LengthPercentage(LengthPercentage::zero()) - } -} + /// Returns the used value. + #[inline] + pub fn to_used_value(&self, percentage_basis: Au) -> Option { + match *self { + generics::GenericLengthPercentageOrAuto::Auto => None, + generics::GenericLengthPercentageOrAuto::LengthPercentage(ref lp) => { + Some(lp.to_used_value(percentage_basis)) + } + } + } -/// A wrapper of LengthPercentageOrAuto, whose value must be >= 0. -pub type NonNegativeLengthPercentageOrAuto = NonNegative; - -impl IsAuto for NonNegativeLengthPercentageOrAuto { - #[inline] - fn is_auto(&self) -> bool { - *self == Self::auto() - } -} - -impl NonNegativeLengthPercentageOrAuto { - /// `auto` - #[inline] - pub fn auto() -> Self { - NonNegative(LengthPercentageOrAuto::Auto) - } -} - -impl ToAnimatedValue for NonNegativeLengthPercentageOrAuto { - type AnimatedValue = LengthPercentageOrAuto; - - #[inline] - fn to_animated_value(self) -> Self::AnimatedValue { - self.0 - } - - #[inline] - fn from_animated_value(animated: Self::AnimatedValue) -> Self { - NonNegative(animated.clamp_to_non_negative()) - } -} - -impl LengthPercentageOrAuto { - /// Returns true if the computed value is absolute 0 or 0%. - #[inline] - pub fn is_definitely_zero(&self) -> bool { - use self::LengthPercentageOrAuto::*; - match *self { - LengthPercentage(ref l) => l.is_definitely_zero(), - Auto => false, + /// Returns true if the computed value is absolute 0 or 0%. + #[inline] + pub fn is_definitely_zero(&self) -> bool { + use values::generics::length::LengthPercentageOrAuto::*; + match *self { + LengthPercentage(ref l) => l.is_definitely_zero(), + Auto => false, + } } } +} +/// A computed type for ` | auto`. +pub type LengthPercentageOrAuto = generics::GenericLengthPercentageOrAuto; + +impl LengthPercentageOrAuto { /// Clamps the value to a non-negative value. pub fn clamp_to_non_negative(self) -> Self { - use self::LengthPercentageOrAuto::*; + use values::generics::length::LengthPercentageOrAuto::*; match self { LengthPercentage(l) => LengthPercentage(l.clamp_to_non_negative()), Auto => Auto, } } + + computed_length_percentage_or_auto!(LengthPercentage); } -impl ToComputedValue for specified::LengthPercentageOrAuto { - type ComputedValue = LengthPercentageOrAuto; +/// A wrapper of LengthPercentageOrAuto, whose value must be >= 0. +pub type NonNegativeLengthPercentageOrAuto = + generics::LengthPercentageOrAuto; - #[inline] - fn to_computed_value(&self, context: &Context) -> LengthPercentageOrAuto { - match *self { - specified::LengthPercentageOrAuto::LengthPercentage(ref value) => { - LengthPercentageOrAuto::LengthPercentage(value.to_computed_value(context)) - }, - specified::LengthPercentageOrAuto::Auto => LengthPercentageOrAuto::Auto, - } - } - - #[inline] - fn from_computed_value(computed: &LengthPercentageOrAuto) -> Self { - match *computed { - LengthPercentageOrAuto::Auto => specified::LengthPercentageOrAuto::Auto, - LengthPercentageOrAuto::LengthPercentage(ref value) => { - specified::LengthPercentageOrAuto::LengthPercentage( - ToComputedValue::from_computed_value(value), - ) - }, - } - } -} - -#[allow(missing_docs)] -#[css(derive_debug)] -#[derive( - Animate, Clone, ComputeSquaredDistance, Copy, MallocSizeOf, PartialEq, ToAnimatedZero, ToCss, -)] -pub enum LengthPercentageOrNone { - LengthPercentage(LengthPercentage), - None, -} - -impl LengthPercentageOrNone { - /// Returns the used value. - pub fn to_used_value(&self, containing_length: Au) -> Option { - match *self { - LengthPercentageOrNone::None => None, - LengthPercentageOrNone::LengthPercentage(ref lp) => { - Some(lp.to_used_value(containing_length)) - }, - } - } -} - -// FIXME(emilio): Derive this. -impl ToComputedValue for specified::LengthPercentageOrNone { - type ComputedValue = LengthPercentageOrNone; - - #[inline] - fn to_computed_value(&self, context: &Context) -> LengthPercentageOrNone { - match *self { - specified::LengthPercentageOrNone::LengthPercentage(ref value) => { - LengthPercentageOrNone::LengthPercentage(value.to_computed_value(context)) - }, - specified::LengthPercentageOrNone::None => LengthPercentageOrNone::None, - } - } - - #[inline] - fn from_computed_value(computed: &LengthPercentageOrNone) -> Self { - match *computed { - LengthPercentageOrNone::None => specified::LengthPercentageOrNone::None, - LengthPercentageOrNone::LengthPercentage(value) => { - specified::LengthPercentageOrNone::LengthPercentage( - ToComputedValue::from_computed_value(&value), - ) - }, - } - } +impl NonNegativeLengthPercentageOrAuto { + computed_length_percentage_or_auto!(NonNegativeLengthPercentage); } /// A wrapper of LengthPercentage, whose value must be >= 0. @@ -630,13 +542,6 @@ impl From for NonNegativeLengthPercentage { } } -impl From for LengthPercentage { - #[inline] - fn from(lp: NonNegativeLengthPercentage) -> LengthPercentage { - lp.0 - } -} - // TODO(emilio): This is a really generic impl which is only needed to implement // Animated and co for Spacing<>. Get rid of this, probably? impl From for LengthPercentage { @@ -650,7 +555,7 @@ impl NonNegativeLengthPercentage { /// Get zero value. #[inline] pub fn zero() -> Self { - NonNegative::(LengthPercentage::zero()) + NonNegative(LengthPercentage::zero()) } /// Returns true if the computed value is absolute 0 or 0%. @@ -662,7 +567,26 @@ impl NonNegativeLengthPercentage { /// Returns the used value. #[inline] pub fn to_used_value(&self, containing_length: Au) -> Au { - self.0.to_used_value(containing_length) + let resolved = self.0.to_used_value(containing_length); + ::std::cmp::max(resolved, Au(0)) + } + + /// Convert the computed value into used value. + #[inline] + pub fn maybe_to_used_value(&self, containing_length: Option) -> Option { + let resolved = self.0.maybe_to_used_value(containing_length)?; + Some(::std::cmp::max(resolved, Au(0))) + } +} + +#[cfg(feature = "servo")] +impl MaxLength { + /// Convert the computed value into used value. + pub fn to_used_value(&self, percentage_basis: Au) -> Option { + match *self { + GenericMaxLength::None => None, + GenericMaxLength::LengthPercentage(ref lp) => Some(lp.to_used_value(percentage_basis)), + } } } @@ -881,6 +805,8 @@ pub type NonNegativeLengthPercentageOrNormal = Either; - -impl MozLength { - /// Returns the `auto` value. - #[inline] - pub fn auto() -> Self { - GenericMozLength::LengthPercentageOrAuto(LengthPercentageOrAuto::Auto) - } -} +pub type MozLength = GenericMozLength; /// A computed value for `max-width` or `min-height` property. -pub type MaxLength = GenericMaxLength; - -impl MaxLength { - /// Returns the `none` value. - #[inline] - pub fn none() -> Self { - GenericMaxLength::LengthPercentageOrNone(LengthPercentageOrNone::None) - } -} +pub type MaxLength = GenericMaxLength; diff --git a/servo/components/style/values/computed/mod.rs b/servo/components/style/values/computed/mod.rs index 02ccf01e25e8..ab8edd2b746a 100644 --- a/servo/components/style/values/computed/mod.rs +++ b/servo/components/style/values/computed/mod.rs @@ -62,7 +62,7 @@ pub use self::gecko::ScrollSnapPoint; pub use self::image::{Gradient, GradientItem, Image, ImageLayer, LineDirection, MozImageRect}; pub use self::length::{CSSPixelLength, ExtremumLength, NonNegativeLength}; pub use self::length::{Length, LengthOrNumber, LengthPercentage}; -pub use self::length::{LengthPercentageOrAuto, LengthPercentageOrNone, MaxLength, MozLength}; +pub use self::length::{LengthPercentageOrAuto, MaxLength, MozLength}; pub use self::length::{NonNegativeLengthPercentage, NonNegativeLengthPercentageOrAuto}; #[cfg(feature = "gecko")] pub use self::list::ListStyleType; diff --git a/servo/components/style/values/generics/background.rs b/servo/components/style/values/generics/background.rs index 4a7ee4b9b95e..d739329e4fcf 100644 --- a/servo/components/style/values/generics/background.rs +++ b/servo/components/style/values/generics/background.rs @@ -4,7 +4,7 @@ //! Generic types for CSS values related to backgrounds. -use crate::values::IsAuto; +use crate::values::generics::length::LengthPercentageOrAuto; use std::fmt::{self, Write}; use style_traits::{CssWriter, ToCss}; @@ -22,13 +22,13 @@ use style_traits::{CssWriter, ToCss}; ToAnimatedZero, ToComputedValue, )] -pub enum BackgroundSize { +pub enum BackgroundSize { /// ` ` Explicit { /// Explicit width. - width: LengthPercentageOrAuto, + width: LengthPercentageOrAuto, /// Explicit height. - height: LengthPercentageOrAuto, + height: LengthPercentageOrAuto, }, /// `cover` #[animation(error)] @@ -38,9 +38,9 @@ pub enum BackgroundSize { Contain, } -impl ToCss for BackgroundSize +impl ToCss for BackgroundSize where - LengthPercentageOrAuto: ToCss + IsAuto, + LengthPercentage: ToCss, { fn to_css(&self, dest: &mut CssWriter) -> fmt::Result where diff --git a/servo/components/style/values/generics/length.rs b/servo/components/style/values/generics/length.rs index 006739462aa7..61be27e4fd2d 100644 --- a/servo/components/style/values/generics/length.rs +++ b/servo/components/style/values/generics/length.rs @@ -4,7 +4,75 @@ //! Generic types for CSS values related to length. +use crate::parser::{Parse, ParserContext}; use crate::values::computed::ExtremumLength; +use cssparser::Parser; +use style_traits::ParseError; + +/// A ` | auto` value. +#[allow(missing_docs)] +#[derive( + Animate, + Clone, + ComputeSquaredDistance, + Copy, + Debug, + MallocSizeOf, + PartialEq, + SpecifiedValueInfo, + ToAnimatedValue, + ToAnimatedZero, + ToComputedValue, + ToCss, +)] +#[repr(C, u8)] +pub enum GenericLengthPercentageOrAuto { + LengthPercentage(LengthPercent), + Auto, +} + +pub use self::GenericLengthPercentageOrAuto as LengthPercentageOrAuto; + +impl LengthPercentageOrAuto { + /// `auto` value. + #[inline] + pub fn auto() -> Self { + LengthPercentageOrAuto::Auto + } + + /// Whether this is the `auto` value. + #[inline] + pub fn is_auto(&self) -> bool { + matches!(*self, LengthPercentageOrAuto::Auto) + } + + /// A helper function to parse this with quirks or not and so forth. + pub fn parse_with<'i, 't>( + context: &ParserContext, + input: &mut Parser<'i, 't>, + parser: impl FnOnce( + &ParserContext, + &mut Parser<'i, 't>, + ) -> Result>, + ) -> Result> { + if input.try(|i| i.expect_ident_matching("auto")).is_ok() { + return Ok(LengthPercentageOrAuto::Auto); + } + + Ok(LengthPercentageOrAuto::LengthPercentage(parser( + context, input, + )?)) + } +} + +impl Parse for LengthPercentageOrAuto { + fn parse<'i, 't>( + context: &ParserContext, + input: &mut Parser<'i, 't>, + ) -> Result> { + Self::parse_with(context, input, LengthPercentage::parse) + } +} /// A generic value for the `width`, `height`, `min-width`, or `min-height` property. /// @@ -13,25 +81,35 @@ use crate::values::computed::ExtremumLength; /// /// Note that it only accepts non-negative values. #[allow(missing_docs)] -#[cfg_attr(feature = "servo", derive(MallocSizeOf))] #[derive( Animate, Clone, ComputeSquaredDistance, Copy, Debug, + MallocSizeOf, PartialEq, SpecifiedValueInfo, + ToAnimatedValue, ToAnimatedZero, ToComputedValue, ToCss, )] -pub enum MozLength { - LengthPercentageOrAuto(LengthPercentageOrAuto), +pub enum MozLength { + LengthPercentage(LengthPercentage), + Auto, #[animation(error)] ExtremumLength(ExtremumLength), } +impl MozLength { + /// `auto` value. + #[inline] + pub fn auto() -> Self { + MozLength::Auto + } +} + /// A generic value for the `max-width` or `max-height` property. #[allow(missing_docs)] #[cfg_attr(feature = "servo", derive(MallocSizeOf))] @@ -43,12 +121,23 @@ pub enum MozLength { Debug, PartialEq, SpecifiedValueInfo, + ToAnimatedValue, ToAnimatedZero, ToComputedValue, ToCss, )] -pub enum MaxLength { - LengthPercentageOrNone(LengthPercentageOrNone), +pub enum MaxLength { + LengthPercentage(LengthPercentage), + None, + #[cfg(feature = "gecko")] #[animation(error)] ExtremumLength(ExtremumLength), } + +impl MaxLength { + /// `none` value. + #[inline] + pub fn none() -> Self { + MaxLength::None + } +} diff --git a/servo/components/style/values/specified/background.rs b/servo/components/style/values/specified/background.rs index 47c66feaef63..b53669abfa8f 100644 --- a/servo/components/style/values/specified/background.rs +++ b/servo/components/style/values/specified/background.rs @@ -6,14 +6,16 @@ use crate::parser::{Parse, ParserContext}; use crate::values::generics::background::BackgroundSize as GenericBackgroundSize; -use crate::values::specified::length::NonNegativeLengthPercentageOrAuto; +use crate::values::specified::length::{ + NonNegativeLengthPercentage, NonNegativeLengthPercentageOrAuto, +}; use cssparser::Parser; use selectors::parser::SelectorParseErrorKind; use std::fmt::{self, Write}; use style_traits::{CssWriter, ParseError, ToCss}; /// A specified value for the `background-size` property. -pub type BackgroundSize = GenericBackgroundSize; +pub type BackgroundSize = GenericBackgroundSize; impl Parse for BackgroundSize { fn parse<'i, 't>( diff --git a/servo/components/style/values/specified/gecko.rs b/servo/components/style/values/specified/gecko.rs index 8259430bf202..42ca5e3e2bf9 100644 --- a/servo/components/style/values/specified/gecko.rs +++ b/servo/components/style/values/specified/gecko.rs @@ -5,8 +5,8 @@ //! Specified types for legacy Gecko-only properties. use crate::parser::{Parse, ParserContext}; -use crate::values::computed::{self, LengthPercentage}; use crate::values::computed::length::CSSPixelLength; +use crate::values::computed::{self, LengthPercentage}; use crate::values::generics::gecko::ScrollSnapPoint as GenericScrollSnapPoint; use crate::values::generics::rect::Rect; use crate::values::specified::length::LengthPercentage as SpecifiedLengthPercentage; @@ -28,8 +28,8 @@ impl Parse for ScrollSnapPoint { } input.expect_function_matching("repeat")?; // FIXME(emilio): This won't clamp properly when animating. - let length = - input.parse_nested_block(|i| SpecifiedLengthPercentage::parse_non_negative(context, i))?; + let length = input + .parse_nested_block(|i| SpecifiedLengthPercentage::parse_non_negative(context, i))?; Ok(GenericScrollSnapPoint::Repeat(length)) } } @@ -49,9 +49,9 @@ fn parse_pixel_or_percent<'i, 't>( _ => Err(()), } }, - Token::Percentage { unit_value, .. } => Ok( - LengthPercentage::new_percent(computed::Percentage(unit_value)) - ), + Token::Percentage { unit_value, .. } => Ok(LengthPercentage::new_percent( + computed::Percentage(unit_value), + )), _ => Err(()), }; value.map_err(|()| location.new_custom_error(StyleParseErrorKind::UnspecifiedError)) diff --git a/servo/components/style/values/specified/length.rs b/servo/components/style/values/specified/length.rs index e83abebc37ca..9da179900787 100644 --- a/servo/components/style/values/specified/length.rs +++ b/servo/components/style/values/specified/length.rs @@ -10,12 +10,14 @@ use super::{AllowQuirks, Number, Percentage, ToComputedValue}; use crate::font_metrics::FontMetricsQueryResult; use crate::parser::{Parse, ParserContext}; use crate::values::computed::{self, CSSPixelLength, Context, ExtremumLength}; -use crate::values::generics::length::MaxLength as GenericMaxLength; -use crate::values::generics::length::MozLength as GenericMozLength; +use crate::values::generics::length as generics; +use crate::values::generics::length::{ + MaxLength as GenericMaxLength, MozLength as GenericMozLength, +}; use crate::values::generics::transform::IsZeroLength; use crate::values::generics::NonNegative; use crate::values::specified::calc::CalcNode; -use crate::values::{Auto, CSSFloat, Either, IsAuto, Normal}; +use crate::values::{Auto, CSSFloat, Either, Normal}; use app_units::Au; use cssparser::{Parser, Token}; use euclid::Size2D; @@ -785,6 +787,16 @@ impl From for LengthPercentage { } } +impl Parse for LengthPercentage { + #[inline] + fn parse<'i, 't>( + context: &ParserContext, + input: &mut Parser<'i, 't>, + ) -> Result> { + Self::parse_quirky(context, input, AllowQuirks::No) + } +} + impl LengthPercentage { #[inline] /// Returns a `zero` length. @@ -844,12 +856,26 @@ impl LengthPercentage { Ok(LengthPercentage::Calc(Box::new(calc))) } + /// Parses allowing the unitless length quirk. + /// + #[inline] + pub fn parse_quirky<'i, 't>( + context: &ParserContext, + input: &mut Parser<'i, 't>, + allow_quirks: AllowQuirks, + ) -> Result> { + Self::parse_internal(context, input, AllowedNumericType::All, allow_quirks) + } + /// Parse a non-negative length. + /// + /// FIXME(emilio): This should be not public and we should use + /// NonNegativeLengthPercentage instead. #[inline] pub fn parse_non_negative<'i, 't>( context: &ParserContext, input: &mut Parser<'i, 't>, - ) -> Result> { + ) -> Result> { Self::parse_non_negative_quirky(context, input, AllowQuirks::No) } @@ -859,7 +885,7 @@ impl LengthPercentage { context: &ParserContext, input: &mut Parser<'i, 't>, allow_quirks: AllowQuirks, - ) -> Result> { + ) -> Result> { Self::parse_internal( context, input, @@ -869,29 +895,6 @@ impl LengthPercentage { } } -impl Parse for LengthPercentage { - #[inline] - fn parse<'i, 't>( - context: &ParserContext, - input: &mut Parser<'i, 't>, - ) -> Result> { - Self::parse_quirky(context, input, AllowQuirks::No) - } -} - -impl LengthPercentage { - /// Parses a length or a percentage, allowing the unitless length quirk. - /// - #[inline] - pub fn parse_quirky<'i, 't>( - context: &ParserContext, - input: &mut Parser<'i, 't>, - allow_quirks: AllowQuirks, - ) -> Result> { - Self::parse_internal(context, input, AllowedNumericType::All, allow_quirks) - } -} - impl IsZeroLength for LengthPercentage { #[inline] fn is_zero_length(&self) -> bool { @@ -903,189 +906,64 @@ impl IsZeroLength for LengthPercentage { } } -/// Either a ``, a ``, or the `auto` keyword. -#[allow(missing_docs)] -#[derive(Clone, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToCss)] -pub enum LengthPercentageOrAuto { - LengthPercentage(LengthPercentage), - Auto, -} +/// A specified type for ` | auto`. +pub type LengthPercentageOrAuto = generics::LengthPercentageOrAuto; impl LengthPercentageOrAuto { - fn parse_internal<'i, 't>( - context: &ParserContext, - input: &mut Parser<'i, 't>, - num_context: AllowedNumericType, - allow_quirks: AllowQuirks, - ) -> Result> { - if input.try(|i| i.expect_ident_matching("auto")).is_ok() { - return Ok(LengthPercentageOrAuto::Auto); - } - - Ok(LengthPercentageOrAuto::LengthPercentage( - LengthPercentage::parse_internal(context, input, num_context, allow_quirks)?, - )) - } - - /// Parse a non-negative length, percentage, or auto. - #[inline] - pub fn parse_non_negative<'i, 't>( - context: &ParserContext, - input: &mut Parser<'i, 't>, - ) -> Result> { - Self::parse_non_negative_quirky(context, input, AllowQuirks::No) - } - - /// Parse a non-negative length, percentage, or auto. - #[inline] - pub fn parse_non_negative_quirky<'i, 't>( - context: &ParserContext, - input: &mut Parser<'i, 't>, - allow_quirks: AllowQuirks, - ) -> Result> { - Self::parse_internal( - context, - input, - AllowedNumericType::NonNegative, - allow_quirks, - ) - } - - /// Returns the `auto` value. - pub fn auto() -> Self { - LengthPercentageOrAuto::Auto - } - /// Returns a value representing a `0` length. pub fn zero() -> Self { - LengthPercentageOrAuto::LengthPercentage(LengthPercentage::zero()) + generics::LengthPercentageOrAuto::LengthPercentage(LengthPercentage::zero()) } /// Returns a value representing `0%`. #[inline] pub fn zero_percent() -> Self { - LengthPercentageOrAuto::LengthPercentage(LengthPercentage::zero_percent()) + generics::LengthPercentageOrAuto::LengthPercentage(LengthPercentage::zero_percent()) } - /// Parses, with quirks. + /// Parses a length or a percentage, allowing the unitless length quirk. + /// #[inline] pub fn parse_quirky<'i, 't>( context: &ParserContext, input: &mut Parser<'i, 't>, allow_quirks: AllowQuirks, ) -> Result> { - Self::parse_internal(context, input, AllowedNumericType::All, allow_quirks) - } -} - -impl Parse for LengthPercentageOrAuto { - #[inline] - fn parse<'i, 't>( - context: &ParserContext, - input: &mut Parser<'i, 't>, - ) -> Result> { - Self::parse_quirky(context, input, AllowQuirks::No) + Self::parse_with(context, input, |context, input| { + LengthPercentage::parse_quirky(context, input, allow_quirks) + }) } } /// A wrapper of LengthPercentageOrAuto, whose value must be >= 0. -pub type NonNegativeLengthPercentageOrAuto = NonNegative; - -impl IsAuto for NonNegativeLengthPercentageOrAuto { - #[inline] - fn is_auto(&self) -> bool { - *self == Self::auto() - } -} +pub type NonNegativeLengthPercentageOrAuto = + generics::LengthPercentageOrAuto; impl NonNegativeLengthPercentageOrAuto { - /// 0 - #[inline] + /// Returns a value representing a `0` length. pub fn zero() -> Self { - NonNegative(LengthPercentageOrAuto::zero()) + generics::LengthPercentageOrAuto::LengthPercentage(NonNegativeLengthPercentage::zero()) } - /// 0% + /// Returns a value representing `0%`. #[inline] pub fn zero_percent() -> Self { - NonNegative(LengthPercentageOrAuto::zero_percent()) - } - - /// `auto` - #[inline] - pub fn auto() -> Self { - NonNegative(LengthPercentageOrAuto::Auto) - } -} - -impl Parse for NonNegativeLengthPercentageOrAuto { - #[inline] - fn parse<'i, 't>( - context: &ParserContext, - input: &mut Parser<'i, 't>, - ) -> Result> { - Ok(NonNegative(LengthPercentageOrAuto::parse_non_negative( - context, input, - )?)) - } -} - -/// Either a ``, a ``, or the `none` keyword. -#[derive(Clone, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToCss)] -#[allow(missing_docs)] -pub enum LengthPercentageOrNone { - LengthPercentage(LengthPercentage), - None, -} - -impl LengthPercentageOrNone { - fn parse_internal<'i, 't>( - context: &ParserContext, - input: &mut Parser<'i, 't>, - num_context: AllowedNumericType, - allow_quirks: AllowQuirks, - ) -> Result> { - if input.try(|i| i.expect_ident_matching("none")).is_ok() { - return Ok(LengthPercentageOrNone::None); - } - - Ok(LengthPercentageOrNone::LengthPercentage( - LengthPercentage::parse_internal(context, input, num_context, allow_quirks)?, - )) - } - - /// Parse a non-negative LengthPercentageOrNone. - #[inline] - pub fn parse_non_negative<'i, 't>( - context: &ParserContext, - input: &mut Parser<'i, 't>, - ) -> Result> { - Self::parse_non_negative_quirky(context, input, AllowQuirks::No) - } - - /// Parse a non-negative LengthPercentageOrNone, with quirks. - #[inline] - pub fn parse_non_negative_quirky<'i, 't>( - context: &ParserContext, - input: &mut Parser<'i, 't>, - allow_quirks: AllowQuirks, - ) -> Result> { - Self::parse_internal( - context, - input, - AllowedNumericType::NonNegative, - allow_quirks, + generics::LengthPercentageOrAuto::LengthPercentage( + NonNegativeLengthPercentage::zero_percent(), ) } -} -impl Parse for LengthPercentageOrNone { + /// Parses a non-negative length-percentage, allowing the unitless length + /// quirk. #[inline] - fn parse<'i, 't>( + pub fn parse_quirky<'i, 't>( context: &ParserContext, input: &mut Parser<'i, 't>, + allow_quirks: AllowQuirks, ) -> Result> { - Self::parse_internal(context, input, AllowedNumericType::All, AllowQuirks::No) + Self::parse_with(context, input, |context, input| { + NonNegativeLengthPercentage::parse_quirky(context, input, allow_quirks) + }) } } @@ -1101,7 +979,7 @@ pub type NonNegativeLengthPercentageOrNormal = Either for NonNegativeLengthPercentage { #[inline] fn from(len: NoCalcLength) -> Self { - NonNegative::(LengthPercentage::from(len)) + NonNegative(LengthPercentage::from(len)) } } @@ -1111,7 +989,7 @@ impl Parse for NonNegativeLengthPercentage { context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - LengthPercentage::parse_non_negative(context, input).map(NonNegative::) + Self::parse_quirky(context, input, AllowQuirks::No) } } @@ -1119,7 +997,13 @@ impl NonNegativeLengthPercentage { #[inline] /// Returns a `zero` length. pub fn zero() -> Self { - NonNegative::(LengthPercentage::zero()) + NonNegative(LengthPercentage::zero()) + } + + #[inline] + /// Returns a `0%` value. + pub fn zero_percent() -> Self { + NonNegative(LengthPercentage::zero_percent()) } /// Parses a length or a percentage, allowing the unitless length quirk. @@ -1130,8 +1014,7 @@ impl NonNegativeLengthPercentage { input: &mut Parser<'i, 't>, allow_quirks: AllowQuirks, ) -> Result> { - LengthPercentage::parse_non_negative_quirky(context, input, allow_quirks) - .map(NonNegative::) + LengthPercentage::parse_non_negative_quirky(context, input, allow_quirks).map(NonNegative) } } @@ -1168,7 +1051,7 @@ impl LengthOrNumber { } /// A specified value for `min-width`, `min-height`, `width` or `height` property. -pub type MozLength = GenericMozLength; +pub type MozLength = GenericMozLength; impl Parse for MozLength { fn parse<'i, 't>( @@ -1190,26 +1073,23 @@ impl MozLength { return Ok(GenericMozLength::ExtremumLength(l)); } - let length = - LengthPercentageOrAuto::parse_non_negative_quirky(context, input, allow_quirks)?; - Ok(GenericMozLength::LengthPercentageOrAuto(length)) - } + if input.try(|i| i.expect_ident_matching("auto")).is_ok() { + return Ok(GenericMozLength::Auto); + } - /// Returns `auto`. - #[inline] - pub fn auto() -> Self { - GenericMozLength::LengthPercentageOrAuto(LengthPercentageOrAuto::auto()) + let length = NonNegativeLengthPercentage::parse_quirky(context, input, allow_quirks)?; + Ok(GenericMozLength::LengthPercentage(length)) } /// Returns `0%`. #[inline] pub fn zero_percent() -> Self { - GenericMozLength::LengthPercentageOrAuto(LengthPercentageOrAuto::zero_percent()) + GenericMozLength::LengthPercentage(NonNegativeLengthPercentage::zero_percent()) } } /// A specified value for `max-width` or `max-height` property. -pub type MaxLength = GenericMaxLength; +pub type MaxLength = GenericMaxLength; impl Parse for MaxLength { fn parse<'i, 't>( @@ -1227,12 +1107,18 @@ impl MaxLength { input: &mut Parser<'i, 't>, allow_quirks: AllowQuirks, ) -> Result> { - if let Ok(l) = input.try(ExtremumLength::parse) { - return Ok(GenericMaxLength::ExtremumLength(l)); + #[cfg(feature = "gecko")] + { + if let Ok(l) = input.try(ExtremumLength::parse) { + return Ok(GenericMaxLength::ExtremumLength(l)); + } } - let length = - LengthPercentageOrNone::parse_non_negative_quirky(context, input, allow_quirks)?; - Ok(GenericMaxLength::LengthPercentageOrNone(length)) + if input.try(|i| i.expect_ident_matching("none")).is_ok() { + return Ok(GenericMaxLength::None); + } + + let length = NonNegativeLengthPercentage::parse_quirky(context, input, allow_quirks)?; + Ok(GenericMaxLength::LengthPercentage(length)) } } diff --git a/servo/components/style/values/specified/mod.rs b/servo/components/style/values/specified/mod.rs index 2cb267045ac7..b37d2554c34a 100644 --- a/servo/components/style/values/specified/mod.rs +++ b/servo/components/style/values/specified/mod.rs @@ -59,7 +59,7 @@ pub use self::image::{GradientItem, GradientKind, Image, ImageLayer, MozImageRec pub use self::length::{AbsoluteLength, CalcLengthPercentage, CharacterWidth}; pub use self::length::{FontRelativeLength, Length, LengthOrNumber}; pub use self::length::{LengthPercentage, LengthPercentageOrAuto}; -pub use self::length::{LengthPercentageOrNone, MaxLength, MozLength}; +pub use self::length::{MaxLength, MozLength}; pub use self::length::{NoCalcLength, ViewportPercentageLength}; pub use self::length::{NonNegativeLengthPercentage, NonNegativeLengthPercentageOrAuto}; #[cfg(feature = "gecko")] diff --git a/servo/ports/geckolib/glue.rs b/servo/ports/geckolib/glue.rs index 8cef5cda4f57..7693c32f3bcc 100644 --- a/servo/ports/geckolib/glue.rs +++ b/servo/ports/geckolib/glue.rs @@ -4436,8 +4436,9 @@ pub extern "C" fn Servo_DeclarationBlock_SetPixelValue( use style::properties::{LonghandId, PropertyDeclaration}; use style::values::generics::length::MozLength; use style::values::generics::NonNegative; + use style::values::generics::length::LengthPercentageOrAuto; use style::values::specified::length::NonNegativeLengthPercentage; - use style::values::specified::length::{LengthPercentage, LengthPercentageOrAuto}; + use style::values::specified::length::{LengthPercentage}; use style::values::specified::length::{NoCalcLength, NonNegativeLength}; use style::values::specified::{BorderCornerRadius, BorderSideWidth}; @@ -4446,8 +4447,8 @@ pub extern "C" fn Servo_DeclarationBlock_SetPixelValue( let lp = LengthPercentage::Length(nocalc); let lp_or_auto = LengthPercentageOrAuto::LengthPercentage(lp.clone()); let prop = match_wrap_declared! { long, - Height => MozLength::LengthPercentageOrAuto(lp_or_auto), - Width => MozLength::LengthPercentageOrAuto(lp_or_auto), + Height => MozLength::LengthPercentage(NonNegative(lp)), + Width => MozLength::LengthPercentage(NonNegative(lp)), BorderTopWidth => BorderSideWidth::Length(nocalc.into()), BorderRightWidth => BorderSideWidth::Length(nocalc.into()), BorderBottomWidth => BorderSideWidth::Length(nocalc.into()), @@ -4495,10 +4496,11 @@ pub extern "C" fn Servo_DeclarationBlock_SetLengthValue( ) { use style::properties::longhands::_moz_script_min_size::SpecifiedValue as MozScriptMinSize; use style::properties::{LonghandId, PropertyDeclaration}; + use style::values::generics::NonNegative; use style::values::generics::length::MozLength; use style::values::specified::length::NoCalcLength; use style::values::specified::length::{AbsoluteLength, FontRelativeLength}; - use style::values::specified::length::{LengthPercentage, LengthPercentageOrAuto}; + use style::values::specified::length::LengthPercentage; let long = get_longhand_from_id!(property); let nocalc = match unit { @@ -4523,9 +4525,7 @@ pub extern "C" fn Servo_DeclarationBlock_SetLengthValue( }; let prop = match_wrap_declared! { long, - Width => MozLength::LengthPercentageOrAuto(LengthPercentageOrAuto::LengthPercentage( - LengthPercentage::Length(nocalc) - )), + Width => MozLength::LengthPercentage(NonNegative(LengthPercentage::Length(nocalc))), FontSize => LengthPercentage::from(nocalc).into(), MozScriptMinSize => MozScriptMinSize(nocalc), }; @@ -4564,16 +4564,18 @@ pub extern "C" fn Servo_DeclarationBlock_SetPercentValue( ) { use style::properties::{LonghandId, PropertyDeclaration}; use style::values::computed::Percentage; - use style::values::generics::length::MozLength; - use style::values::specified::length::{LengthPercentage, LengthPercentageOrAuto}; + use style::values::generics::NonNegative; + use style::values::generics::length::{MozLength, LengthPercentageOrAuto}; + use style::values::specified::length::LengthPercentage; let long = get_longhand_from_id!(property); let pc = Percentage(value); - let lp_or_auto = LengthPercentageOrAuto::LengthPercentage(LengthPercentage::Percentage(pc)); + let lp = LengthPercentage::Percentage(pc); + let lp_or_auto = LengthPercentageOrAuto::LengthPercentage(lp.clone()); let prop = match_wrap_declared! { long, - Height => MozLength::LengthPercentageOrAuto(lp_or_auto), - Width => MozLength::LengthPercentageOrAuto(lp_or_auto), + Height => MozLength::LengthPercentage(NonNegative(lp)), + Width => MozLength::LengthPercentage(NonNegative(lp)), MarginTop => lp_or_auto, MarginRight => lp_or_auto, MarginBottom => lp_or_auto, @@ -4591,7 +4593,7 @@ pub extern "C" fn Servo_DeclarationBlock_SetAutoValue( property: nsCSSPropertyID, ) { use style::properties::{LonghandId, PropertyDeclaration}; - use style::values::specified::{LengthPercentageOrAuto, MozLength}; + use style::values::generics::length::{LengthPercentageOrAuto, MozLength}; let long = get_longhand_from_id!(property); let auto = LengthPercentageOrAuto::Auto; diff --git a/third_party/rust/bindgen/.cargo-checksum.json b/third_party/rust/bindgen/.cargo-checksum.json index 6022f4aa9a86..52c8500e8532 100644 --- a/third_party/rust/bindgen/.cargo-checksum.json +++ b/third_party/rust/bindgen/.cargo-checksum.json @@ -1 +1 @@ -{"files":{"Cargo.toml":"d6ee9689e1d4ece0423949f53cfd91c6c1f53e9246e559e3c6e9093d691a4229","LICENSE":"c23953d9deb0a3312dbeaf6c128a657f3591acee45067612fa68405eaa4525db","README.md":"630d1a1d123c131bad0fec23173e263ba8ecc064b5cd8446d4cab7ffd197db45","build.rs":"032a1c51963894a421b0535f9227796d88768ac5f665a81d2edced69dc6d106a","src/callbacks.rs":"9d41b7848cea37e8741fa7bc947ba58a83647824b1a0bbe7ff75012c412eab13","src/clang.rs":"b25f8d455e3cd89d416a4c5e55d828db9691f4def82109c1dd12457e5ca2c13c","src/codegen/bitfield_unit.rs":"88b0604322dc449fc9284850eadc1f5d14b42fa747d4258bae0b6b9535f52dfd","src/codegen/bitfield_unit_tests.rs":"2073ac6a36e0bc9afaef5b1207966817c8fb7a1a9f6368c3b1b8f79822efbfba","src/codegen/error.rs":"2613af1d833377fd4a70719f4a09951d9d45dc9227827b9a2a938a1bcaaea2dd","src/codegen/helpers.rs":"2c890c96a1a6b72ada63593cb544f005476fb176d7181553713e83710dc8eefd","src/codegen/impl_debug.rs":"43b977b8d16073d021977ce57f3c22eb5b1083493905ae19a171e2271939f574","src/codegen/impl_partialeq.rs":"671dd0eac712bf8281e11a7b3e545a443c6e9e2c8ee7fbebeb03c76667ca206b","src/codegen/mod.rs":"a1bfb972bed101b735d3ac19fa1080bd3a8d4e38e11b4adf34ca413982e2fe5e","src/codegen/struct_layout.rs":"b77f03dfbbed408a5fa6e693560aea8dc902fe7d10d847ce39122e6961078515","src/extra_assertions.rs":"449549c4a7a50c3f0b06332452b2fb6c9b23f31ca8e5e1656fe6c7f21e8ef7fa","src/features.rs":"be74e03d4f00582fa8970439da52057b04204b450193833953ed84772933bd46","src/ir/analysis/derive_copy.rs":"b7e12cdc74937909529e4cefe9f43b3ee0a5590f07392b73481811ac9fddedd2","src/ir/analysis/derive_debug.rs":"cf9346ecb3afd4e94094a2723e4d76c76c55f42a13dc1d5ec6564d25d3a46cf4","src/ir/analysis/derive_default.rs":"87332eccd5accbfbf7fad2e1511be4f8945b0538ae3e0628c8af17d16068691f","src/ir/analysis/derive_hash.rs":"521ea1dbe221755042a95e8e8dcb594e427e54be2eb869c61ebbdb27fec5aa77","src/ir/analysis/derive_partialeq_or_partialord.rs":"3c5d051f69401fe50b56143143eca3e71674d6a87d0013c31745b75d0f3d584f","src/ir/analysis/has_destructor.rs":"d9aaaceba580b48eb0df4e5537b34b417c51ccdfeb8f6b72484f3bf4992317fe","src/ir/analysis/has_float.rs":"5f7ee1b834978817041d884fee4648b31ecb66c62aafb8e7a9a17e5ac434bfe5","src/ir/analysis/has_type_param_in_array.rs":"abf74468b923c015aaf67599e50857267516010472819a79ca494fe02dd6ac93","src/ir/analysis/has_vtable.rs":"37765e954ef792e369a58ccfe1d827a00fe9bce680466da1d6523671b94b6c92","src/ir/analysis/mod.rs":"ea5ace45c77e855674bb565ba0fef556f60e3293b0ddcf11d3a5a6ec15ab0648","src/ir/analysis/sizedness.rs":"4f788bff0ceb0e008d70145510340ab636e5203787316f0be41f789ce9b2f73d","src/ir/analysis/template_params.rs":"6554dd1240142ec0e7299e678b696725f5cba99243d1c3d1cbf58d4764082fd6","src/ir/annotations.rs":"ef106afcbe6084c18bd13a37ee3c1cdc9596bfb055db8c773d81f8f15fec3208","src/ir/comment.rs":"1b068d5834da7360aec4cb80d9c55219cedbb2ae8b9727a39ec7d156c88fe0b5","src/ir/comp.rs":"7b22f3ff19ca45a6fbfe7ea015109d43f4ddf65b33b47b1c37829fcb87cdff9b","src/ir/context.rs":"7fde495a0b97f332a2018a6ee7b1cbac46e8dee68f2a3956a2a95e26e970c266","src/ir/derive.rs":"19601e76528d6cce8e04a66572e75da4e9efdecc4d60a983fc68c11958e9f3ec","src/ir/dot.rs":"d01f1621ab67e368d854a82bd6bb0b8dd52f3c2c733de8eaf81aece9543818cb","src/ir/enum_ty.rs":"9cc242d6b3c1866665594e8b306860ee39c0ea42d22198d46b7fded473fe3e84","src/ir/function.rs":"44603a952b5f5f3074f4f9b4995e88b28906e22830865533469f42071af61aa9","src/ir/int.rs":"07e0c7dbd2dd977177fae3acd2a14adf271c6cf9ff4b57cddc11d50734fd4801","src/ir/item.rs":"0ec5cec91551e01069451265fcf755cb54608bc2dfa770e770769eef0f2ba080","src/ir/item_kind.rs":"dbeae8c4fd0e5c9485d325aea040e056a1f2cd6d43fc927dee8fe1c0c59a7197","src/ir/layout.rs":"e722edffcd34914b534813da5af6fe8ba69927a54e0ec88ae1733f5ddf0e50b1","src/ir/mod.rs":"2eae90f207fad2e45957ec9287064992a419e3fc916aba84faff2ea25cbeb5ee","src/ir/module.rs":"c4d90bf38fe3672e01923734ccbdb7951ea929949d5f413a9c2aee12395a5094","src/ir/objc.rs":"828a890acdc8b10c44e69e2ed4a4f5d8c0e734606d3a8cc71658dcf43a49acf4","src/ir/template.rs":"c0f8570b927dfd6a421fc4ce3094ec837a3ed936445225dbfac961e8e0842ae5","src/ir/traversal.rs":"ea751379a5aec02f93f8d2c61e18232776b1f000dbeae64b9a7195ba21a19dd6","src/ir/ty.rs":"a7e72e4fb85a1328f17a5428c7bc7f1c51326299833f82252770bebf99d1a9a1","src/ir/var.rs":"5c0caaa505faef18e334c6198b3634b6f390d14cf9da629226cd78617fd3594b","src/lib.rs":"b94a374ef78f6b6cd2b0676efcd67a16800730b28374155b54387a55774aed6e","src/log_stubs.rs":"6dfdd908b7c6453da416cf232893768f9480e551ca4add0858ef88bf71ee6ceb","src/main.rs":"e519053bcdde6bc88f60f955246a02d53b3db1cc5ccd1612e6675b790b7460b0","src/options.rs":"a4b4028542d6292363fc97621c704bf1b4e7eb149e9cb86b52e30aad0be13b99","src/parse.rs":"be7d13cc84fae79ec7b3aa9e77063fa475a48d74a854423e2c72d75006a25202","src/regex_set.rs":"c417889726b5e3325f9375551bf23fd54c9b40020151c364741ea6126ede386b","src/time.rs":"3b763e6fee51d0eb01228dfe28bc28a9f692aff73b2a7b90a030902e0238fca6"},"package":"b41df015ccbc22b038641bd84d0aeeff01e0a4c0714ed35ed0e9a3dd8ad8d732"} \ No newline at end of file +{"files":{"Cargo.toml":"e0559de35f6564bbfc4779f43d9104d604befb7ff7de5baf591379c285544d3c","LICENSE":"c23953d9deb0a3312dbeaf6c128a657f3591acee45067612fa68405eaa4525db","README.md":"630d1a1d123c131bad0fec23173e263ba8ecc064b5cd8446d4cab7ffd197db45","build.rs":"032a1c51963894a421b0535f9227796d88768ac5f665a81d2edced69dc6d106a","src/callbacks.rs":"936198c967ca4205ab043ce2264d8188d0716ad7c294cebdaacde2b486224450","src/clang.rs":"b25f8d455e3cd89d416a4c5e55d828db9691f4def82109c1dd12457e5ca2c13c","src/codegen/bitfield_unit.rs":"88b0604322dc449fc9284850eadc1f5d14b42fa747d4258bae0b6b9535f52dfd","src/codegen/bitfield_unit_tests.rs":"2073ac6a36e0bc9afaef5b1207966817c8fb7a1a9f6368c3b1b8f79822efbfba","src/codegen/error.rs":"2613af1d833377fd4a70719f4a09951d9d45dc9227827b9a2a938a1bcaaea2dd","src/codegen/helpers.rs":"2c890c96a1a6b72ada63593cb544f005476fb176d7181553713e83710dc8eefd","src/codegen/impl_debug.rs":"43b977b8d16073d021977ce57f3c22eb5b1083493905ae19a171e2271939f574","src/codegen/impl_partialeq.rs":"671dd0eac712bf8281e11a7b3e545a443c6e9e2c8ee7fbebeb03c76667ca206b","src/codegen/mod.rs":"57a6c0dc52af70b08f54e744b629df67c5528a8d63ccb9485cc1af91d02dadc0","src/codegen/struct_layout.rs":"b77f03dfbbed408a5fa6e693560aea8dc902fe7d10d847ce39122e6961078515","src/extra_assertions.rs":"449549c4a7a50c3f0b06332452b2fb6c9b23f31ca8e5e1656fe6c7f21e8ef7fa","src/features.rs":"be74e03d4f00582fa8970439da52057b04204b450193833953ed84772933bd46","src/ir/analysis/derive_copy.rs":"b7e12cdc74937909529e4cefe9f43b3ee0a5590f07392b73481811ac9fddedd2","src/ir/analysis/derive_debug.rs":"cf9346ecb3afd4e94094a2723e4d76c76c55f42a13dc1d5ec6564d25d3a46cf4","src/ir/analysis/derive_default.rs":"87332eccd5accbfbf7fad2e1511be4f8945b0538ae3e0628c8af17d16068691f","src/ir/analysis/derive_hash.rs":"521ea1dbe221755042a95e8e8dcb594e427e54be2eb869c61ebbdb27fec5aa77","src/ir/analysis/derive_partialeq_or_partialord.rs":"3c5d051f69401fe50b56143143eca3e71674d6a87d0013c31745b75d0f3d584f","src/ir/analysis/has_destructor.rs":"d9aaaceba580b48eb0df4e5537b34b417c51ccdfeb8f6b72484f3bf4992317fe","src/ir/analysis/has_float.rs":"5f7ee1b834978817041d884fee4648b31ecb66c62aafb8e7a9a17e5ac434bfe5","src/ir/analysis/has_type_param_in_array.rs":"abf74468b923c015aaf67599e50857267516010472819a79ca494fe02dd6ac93","src/ir/analysis/has_vtable.rs":"37765e954ef792e369a58ccfe1d827a00fe9bce680466da1d6523671b94b6c92","src/ir/analysis/mod.rs":"ea5ace45c77e855674bb565ba0fef556f60e3293b0ddcf11d3a5a6ec15ab0648","src/ir/analysis/sizedness.rs":"4f788bff0ceb0e008d70145510340ab636e5203787316f0be41f789ce9b2f73d","src/ir/analysis/template_params.rs":"6554dd1240142ec0e7299e678b696725f5cba99243d1c3d1cbf58d4764082fd6","src/ir/annotations.rs":"ef106afcbe6084c18bd13a37ee3c1cdc9596bfb055db8c773d81f8f15fec3208","src/ir/comment.rs":"1b068d5834da7360aec4cb80d9c55219cedbb2ae8b9727a39ec7d156c88fe0b5","src/ir/comp.rs":"7b22f3ff19ca45a6fbfe7ea015109d43f4ddf65b33b47b1c37829fcb87cdff9b","src/ir/context.rs":"925ba08ad614c40b0578be524206a662aec53f959d47d3b2cc84389718fc485b","src/ir/derive.rs":"19601e76528d6cce8e04a66572e75da4e9efdecc4d60a983fc68c11958e9f3ec","src/ir/dot.rs":"d01f1621ab67e368d854a82bd6bb0b8dd52f3c2c733de8eaf81aece9543818cb","src/ir/enum_ty.rs":"9cc242d6b3c1866665594e8b306860ee39c0ea42d22198d46b7fded473fe3e84","src/ir/function.rs":"c497a6e07e95dc65be73f12396e344929973243d5cf7808a97c5309b0b090ef8","src/ir/int.rs":"07e0c7dbd2dd977177fae3acd2a14adf271c6cf9ff4b57cddc11d50734fd4801","src/ir/item.rs":"d626a0054df8254a504b44019dc531a933ec1bd3961b1465a602f0d767e0ad4e","src/ir/item_kind.rs":"dbeae8c4fd0e5c9485d325aea040e056a1f2cd6d43fc927dee8fe1c0c59a7197","src/ir/layout.rs":"e722edffcd34914b534813da5af6fe8ba69927a54e0ec88ae1733f5ddf0e50b1","src/ir/mod.rs":"2eae90f207fad2e45957ec9287064992a419e3fc916aba84faff2ea25cbeb5ee","src/ir/module.rs":"c4d90bf38fe3672e01923734ccbdb7951ea929949d5f413a9c2aee12395a5094","src/ir/objc.rs":"828a890acdc8b10c44e69e2ed4a4f5d8c0e734606d3a8cc71658dcf43a49acf4","src/ir/template.rs":"c0f8570b927dfd6a421fc4ce3094ec837a3ed936445225dbfac961e8e0842ae5","src/ir/traversal.rs":"ea751379a5aec02f93f8d2c61e18232776b1f000dbeae64b9a7195ba21a19dd6","src/ir/ty.rs":"1068a7e4916d69b5034a76c47b67e6257db906cc16dad6d8af4bdb39ad52cd84","src/ir/var.rs":"5c0caaa505faef18e334c6198b3634b6f390d14cf9da629226cd78617fd3594b","src/lib.rs":"994d8495557cadc8c4a748e2643b35c6850f2c7130e35c8abf4ae02b83cfeff7","src/log_stubs.rs":"6dfdd908b7c6453da416cf232893768f9480e551ca4add0858ef88bf71ee6ceb","src/main.rs":"e519053bcdde6bc88f60f955246a02d53b3db1cc5ccd1612e6675b790b7460b0","src/options.rs":"a4b4028542d6292363fc97621c704bf1b4e7eb149e9cb86b52e30aad0be13b99","src/parse.rs":"be7d13cc84fae79ec7b3aa9e77063fa475a48d74a854423e2c72d75006a25202","src/regex_set.rs":"c417889726b5e3325f9375551bf23fd54c9b40020151c364741ea6126ede386b","src/time.rs":"3b763e6fee51d0eb01228dfe28bc28a9f692aff73b2a7b90a030902e0238fca6"},"package":"6d52d263eacd15d26cbcf215d254b410bd58212aaa2d3c453a04b2d3b3adcf41"} \ No newline at end of file diff --git a/third_party/rust/bindgen/Cargo.toml b/third_party/rust/bindgen/Cargo.toml index 2d0e17e1291e..65c223c8197b 100644 --- a/third_party/rust/bindgen/Cargo.toml +++ b/third_party/rust/bindgen/Cargo.toml @@ -12,7 +12,7 @@ [package] name = "bindgen" -version = "0.43.0" +version = "0.43.2" authors = ["Jyun-Yan You ", "Emilio Cobos Álvarez ", "Nick Fitzgerald ", "The Servo project developers"] build = "build.rs" include = ["LICENSE", "README.md", "Cargo.toml", "build.rs", "src/*.rs", "src/**/*.rs"] @@ -49,7 +49,7 @@ features = ["runtime", "clang_6_0"] version = "2" [dependencies.env_logger] -version = "0.5" +version = "0.6" optional = true [dependencies.lazy_static] diff --git a/third_party/rust/bindgen/src/callbacks.rs b/third_party/rust/bindgen/src/callbacks.rs index 71b98fc90b6b..26f773383902 100644 --- a/third_party/rust/bindgen/src/callbacks.rs +++ b/third_party/rust/bindgen/src/callbacks.rs @@ -55,4 +55,9 @@ pub trait ParseCallbacks: fmt::Debug + UnwindSafe { ) -> Option { None } + + /// Allows to rename an item, replacing `_original_item_name`. + fn item_name(&self, _original_item_name: &str) -> Option { + None + } } diff --git a/third_party/rust/bindgen/src/codegen/mod.rs b/third_party/rust/bindgen/src/codegen/mod.rs index 8cc55a0e1b3f..34b5b4d9ba14 100644 --- a/third_party/rust/bindgen/src/codegen/mod.rs +++ b/third_party/rust/bindgen/src/codegen/mod.rs @@ -666,6 +666,7 @@ impl CodeGenerator for Type { .through_type_refs() .resolve(ctx); let name = item.canonical_name(ctx); + let path = item.canonical_path(ctx); { let through_type_aliases = inner.into_resolver() @@ -678,7 +679,7 @@ impl CodeGenerator for Type { // typedef struct foo { ... } foo; // // here, and also other more complex cases like #946. - if through_type_aliases.canonical_name(ctx) == name { + if through_type_aliases.canonical_path(ctx) == path { return; } } @@ -1044,6 +1045,7 @@ impl<'a> FieldCodegen<'a> for FieldData { let field_item = self.ty().into_resolver().through_type_refs().resolve(ctx); let field_ty = field_item.expect_type(); let mut ty = self.ty().to_rust_ty_or_opaque(ctx, &()); + ty.append_implicit_template_params(ctx, field_item); // NB: If supported, we use proper `union` types. let ty = if parent.is_union() && !parent.can_be_rust_union(ctx) { @@ -1071,7 +1073,6 @@ impl<'a> FieldCodegen<'a> for FieldData { } } } else { - ty.append_implicit_template_params(ctx, field_item); ty }; @@ -3377,12 +3378,6 @@ impl CodeGenerator for Function { attributes.push(attributes::doc(comment)); } - if let Some(mangled) = mangled_name { - attributes.push(attributes::link_name(mangled)); - } else if name != canonical_name { - attributes.push(attributes::link_name(name)); - } - // Handle overloaded functions by giving each overload its own unique // suffix. let times_seen = result.overload_number(&canonical_name); @@ -3390,6 +3385,14 @@ impl CodeGenerator for Function { write!(&mut canonical_name, "{}", times_seen).unwrap(); } + if let Some(mangled) = mangled_name { + if canonical_name != mangled { + attributes.push(attributes::link_name(mangled)); + } + } else if name != canonical_name { + attributes.push(attributes::link_name(name)); + } + let abi = match signature.abi() { Abi::ThisCall if !ctx.options().rust_features().thiscall_abi => { warn!("Skipping function with thiscall ABI that isn't supported by the configured Rust target"); diff --git a/third_party/rust/bindgen/src/ir/context.rs b/third_party/rust/bindgen/src/ir/context.rs index bdf38428122e..c0f92464b091 100644 --- a/third_party/rust/bindgen/src/ir/context.rs +++ b/third_party/rust/bindgen/src/ir/context.rs @@ -2160,16 +2160,21 @@ If you encounter an error missing from this list, please file an issue or a PR!" ::clang_sys::CXCursor_Namespace, "Be a nice person" ); + + let mut module_name = None; + let spelling = cursor.spelling(); + if !spelling.is_empty() + { + module_name = Some(spelling) + } + let tokens = match cursor.tokens() { Some(tokens) => tokens, - None => return (None, ModuleKind::Normal), + None => return (module_name, ModuleKind::Normal), }; - let mut iter = tokens.iter(); let mut kind = ModuleKind::Normal; let mut found_namespace_keyword = false; - let mut module_name = None; - while let Some(token) = iter.next() { match &*token.spelling { "inline" => { @@ -2195,7 +2200,9 @@ If you encounter an error missing from this list, please file an issue or a PR!" break; } name if found_namespace_keyword => { - module_name = Some(name.to_owned()); + if module_name.is_none() { + module_name = Some(name.to_owned()); + } break; } _ => { diff --git a/third_party/rust/bindgen/src/ir/function.rs b/third_party/rust/bindgen/src/ir/function.rs index 3f2c8254723f..883203e9a1ea 100644 --- a/third_party/rust/bindgen/src/ir/function.rs +++ b/third_party/rust/bindgen/src/ir/function.rs @@ -562,11 +562,7 @@ impl ClangSubItemParser for Function { name.push_str("_destructor"); } - let mut mangled_name = cursor_mangling(context, &cursor); - if mangled_name.as_ref() == Some(&name) { - mangled_name = None; - } - + let mangled_name = cursor_mangling(context, &cursor); let comment = cursor.raw_comment(); let function = Self::new(name, mangled_name, sig, comment, kind, linkage); diff --git a/third_party/rust/bindgen/src/ir/item.rs b/third_party/rust/bindgen/src/ir/item.rs index 5f0ccc0bc222..380313e75380 100644 --- a/third_party/rust/bindgen/src/ir/item.rs +++ b/third_party/rust/bindgen/src/ir/item.rs @@ -875,6 +875,11 @@ impl Item { let name = names.join("_"); + let name = ctx + .parse_callbacks() + .and_then(|callbacks| callbacks.item_name(&name)) + .unwrap_or(name); + ctx.rust_mangle(&name).into_owned() } @@ -1314,7 +1319,8 @@ impl ClangItemParser for Item { CXCursor_UsingDeclaration | CXCursor_UsingDirective | CXCursor_StaticAssert | - CXCursor_InclusionDirective => { + CXCursor_InclusionDirective | + CXCursor_FunctionTemplate => { debug!( "Unhandled cursor kind {:?}: {:?}", cursor.kind(), diff --git a/third_party/rust/bindgen/src/ir/ty.rs b/third_party/rust/bindgen/src/ir/ty.rs index 75d5960d1401..922146ea8d24 100644 --- a/third_party/rust/bindgen/src/ir/ty.rs +++ b/third_party/rust/bindgen/src/ir/ty.rs @@ -1184,6 +1184,9 @@ impl Type { name = interface.rust_name(); TypeKind::ObjCInterface(interface) } + CXType_Dependent => { + return Err(ParseError::Continue); + } _ => { error!( "unsupported type: kind = {:?}; ty = {:?}; at {:?}", diff --git a/third_party/rust/bindgen/src/lib.rs b/third_party/rust/bindgen/src/lib.rs index 039bd39a2170..ffe4e80dccda 100644 --- a/third_party/rust/bindgen/src/lib.rs +++ b/third_party/rust/bindgen/src/lib.rs @@ -431,7 +431,7 @@ impl Builder { //Temporary placeholder for below 4 options let mut options: Vec = Vec::new(); if self.options.codegen_config.functions() { - options.push("function".into()); + options.push("functions".into()); } if self.options.codegen_config.types() { options.push("types".into()); @@ -2053,7 +2053,7 @@ fn commandline_flag_unit_test_function() { "--rust-target", "--no-derive-default", "--generate", - "function,types,vars,methods,constructors,destructors", + "functions,types,vars,methods,constructors,destructors", ].iter() .map(|&x| x.into()) .collect::>(); @@ -2074,7 +2074,7 @@ fn commandline_flag_unit_test_function() { "input_header", "--no-derive-default", "--generate", - "function,types,vars,methods,constructors,destructors", + "functions,types,vars,methods,constructors,destructors", "--whitelist-type", "Distinct_Type", "--whitelist-function",