diff --git a/components/selectors/build.rs b/components/selectors/build.rs index a7c58c64a869..1521ce66f2d7 100644 --- a/components/selectors/build.rs +++ b/components/selectors/build.rs @@ -14,8 +14,7 @@ fn main() { .join("ascii_case_insensitive_html_attributes.rs"); let mut file = BufWriter::new(File::create(&path).unwrap()); - write!(&mut file, "{{ static SET: ::phf::Set<&'static str> = ", - ).unwrap(); + write!(&mut file, "{{ static SET: ::phf::Set<&'static str> = ").unwrap(); let mut set = phf_codegen::Set::new(); for name in ASCII_CASE_INSENSITIVE_HTML_ATTRIBUTES.split_whitespace() { set.entry(name); diff --git a/components/selectors/lib.rs b/components/selectors/lib.rs index 49d769d25005..ecf18fe02efd 100644 --- a/components/selectors/lib.rs +++ b/components/selectors/lib.rs @@ -7,9 +7,9 @@ #[macro_use] extern crate bitflags; #[macro_use] extern crate cssparser; +extern crate fnv; #[macro_use] extern crate log; #[macro_use] extern crate matches; -extern crate fnv; extern crate phf; extern crate precomputed_hash; extern crate servo_arc; diff --git a/components/selectors/parser.rs b/components/selectors/parser.rs index 9fbd711ab785..c1136213c597 100644 --- a/components/selectors/parser.rs +++ b/components/selectors/parser.rs @@ -9,7 +9,8 @@ use builder::{SelectorBuilder, SpecificityAndFlags}; use context::QuirksMode; use cssparser::{ParseError, ParseErrorKind, BasicParseError, BasicParseErrorKind}; use cssparser::{SourceLocation, CowRcStr, Delimiter}; -use cssparser::{Token, Parser as CssParser, parse_nth, ToCss, serialize_identifier, CssStringWriter}; +use cssparser::{Token, Parser as CssParser, ToCss, CssStringWriter}; +use cssparser::{parse_nth, serialize_identifier}; use precomputed_hash::PrecomputedHash; use servo_arc::ThinArc; use sink::Push; @@ -1300,7 +1301,8 @@ impl Selector { { let selector = parse_selector(parser, input)?; if selector.has_pseudo_element() { - return Err(input.new_custom_error(SelectorParseErrorKind::PseudoElementInComplexSelector)) + let e = SelectorParseErrorKind::PseudoElementInComplexSelector; + return Err(input.new_custom_error(e)) } Ok(selector) } @@ -1428,9 +1430,8 @@ where Ok(OptionalQName::Some(namespace, Some(local_name.clone()))) } Ok(t) if in_attr_selector => { - Err(location.new_custom_error( - SelectorParseErrorKind::InvalidQualNameInAttr(t.clone()) - )) + let e = SelectorParseErrorKind::InvalidQualNameInAttr(t.clone()); + Err(location.new_custom_error(e)) } Ok(t) => { Err(location.new_custom_error( @@ -1694,7 +1695,8 @@ where }, Some(SimpleSelectorParseResult::PseudoElement(_)) | Some(SimpleSelectorParseResult::SlottedPseudo(_)) => { - return Err(input.new_custom_error(SelectorParseErrorKind::NonSimpleSelectorInNegation)); + let e = SelectorParseErrorKind::NonSimpleSelectorInNegation; + return Err(input.new_custom_error(e)); } } } @@ -1759,10 +1761,10 @@ where match input.next_including_whitespace() { Ok(&Token::Colon) => {}, Ok(&Token::WhiteSpace(_)) | Err(_) => break, - Ok(t) => - return Err(location.new_custom_error( - SelectorParseErrorKind::PseudoElementExpectedColon(t.clone()) - )), + Ok(t) => { + let e = SelectorParseErrorKind::PseudoElementExpectedColon(t.clone()); + return Err(location.new_custom_error(e)); + }, } let location = input.current_source_location(); @@ -1903,9 +1905,10 @@ where let class = Component::Class(class.as_ref().into()); Ok(Some(SimpleSelectorParseResult::SimpleSelector(class))) } - ref t => Err(location.new_custom_error( - SelectorParseErrorKind::ClassNeedsIdent(t.clone()) - )), + ref t => { + let e = SelectorParseErrorKind::ClassNeedsIdent(t.clone()); + Err(location.new_custom_error(e)) + }, } } Ok(Token::SquareBracketBlock) => { @@ -1921,33 +1924,32 @@ where let (name, is_functional) = match next_token { Token::Ident(name) => (name, false), Token::Function(name) => (name, true), - t => return Err(input.new_custom_error( - SelectorParseErrorKind::PseudoElementExpectedIdent(t) - )), + t => { + let e = SelectorParseErrorKind::PseudoElementExpectedIdent(t); + return Err(input.new_custom_error(e)); + }, }; let is_pseudo_element = !is_single_colon || P::pseudo_element_allows_single_colon(&name); if is_pseudo_element { let parse_result = if is_functional { if P::parse_slotted(parser) && name.eq_ignore_ascii_case("slotted") { - SimpleSelectorParseResult::SlottedPseudo( - input.parse_nested_block(|input| { - parse_inner_compound_selector( - parser, - input, - ) - })? - ) + let selector = input.parse_nested_block(|input| { + parse_inner_compound_selector( + parser, + input, + ) + })?; + SimpleSelectorParseResult::SlottedPseudo(selector) } else { - SimpleSelectorParseResult::PseudoElement( - input.parse_nested_block(|input| { - P::parse_functional_pseudo_element( - parser, - name, - input, - ) - })? - ) + let selector = input.parse_nested_block(|input| { + P::parse_functional_pseudo_element( + parser, + name, + input, + ) + })?; + SimpleSelectorParseResult::PseudoElement(selector) } } else { SimpleSelectorParseResult::PseudoElement( @@ -2158,7 +2160,10 @@ pub mod tests { parser: &mut CssParser<'i, 't>, ) -> Result> { match_ignore_ascii_case! { &name, - "lang" => return Ok(PseudoClass::Lang(parser.expect_ident_or_string()?.as_ref().to_owned())), + "lang" => { + let lang = parser.expect_ident_or_string()?.as_ref().to_owned(); + return Ok(PseudoClass::Lang(lang)); + }, _ => {} } Err(parser.new_custom_error(SelectorParseErrorKind::UnsupportedPseudoClassOrElement(name))) diff --git a/components/style/custom_properties.rs b/components/style/custom_properties.rs index 833d8d2b023c..7823b938309a 100644 --- a/components/style/custom_properties.rs +++ b/components/style/custom_properties.rs @@ -366,25 +366,24 @@ fn parse_declaration_value_block<'i, 't>( token.serialization_type() } Token::BadUrl(u) => { - return Err(input.new_custom_error(StyleParseErrorKind::BadUrlInDeclarationValueBlock(u))) + let e = StyleParseErrorKind::BadUrlInDeclarationValueBlock(u); + return Err(input.new_custom_error(e)) } Token::BadString(s) => { - return Err(input.new_custom_error(StyleParseErrorKind::BadStringInDeclarationValueBlock(s))) + let e = StyleParseErrorKind::BadStringInDeclarationValueBlock(s); + return Err(input.new_custom_error(e)) } Token::CloseParenthesis => { - return Err(input.new_custom_error( - StyleParseErrorKind::UnbalancedCloseParenthesisInDeclarationValueBlock - )) + let e = StyleParseErrorKind::UnbalancedCloseParenthesisInDeclarationValueBlock; + return Err(input.new_custom_error(e)) } Token::CloseSquareBracket => { - return Err(input.new_custom_error( - StyleParseErrorKind::UnbalancedCloseSquareBracketInDeclarationValueBlock - )) + let e = StyleParseErrorKind::UnbalancedCloseSquareBracketInDeclarationValueBlock; + return Err(input.new_custom_error(e)) } Token::CloseCurlyBracket => { - return Err(input.new_custom_error( - StyleParseErrorKind::UnbalancedCloseCurlyBracketInDeclarationValueBlock - )) + let e = StyleParseErrorKind::UnbalancedCloseCurlyBracketInDeclarationValueBlock; + return Err(input.new_custom_error(e)) } Token::Function(ref name) => { if name.eq_ignore_ascii_case("var") { diff --git a/components/style/font_face.rs b/components/style/font_face.rs index 885a4f39f5cc..dceea4df775b 100644 --- a/components/style/font_face.rs +++ b/components/style/font_face.rs @@ -12,8 +12,9 @@ use computed_values::{font_stretch, font_style, font_weight}; use cssparser::{AtRuleParser, DeclarationListParser, DeclarationParser, Parser}; use cssparser::{SourceLocation, CowRcStr}; +#[cfg(feature = "gecko")] +use cssparser::UnicodeRange; use error_reporting::{ContextualParseError, ParseErrorReporter}; -#[cfg(feature = "gecko")] use cssparser::UnicodeRange; use parser::{ParserContext, ParserErrorContext, Parse}; #[cfg(feature = "gecko")] use properties::longhands::font_language_override; diff --git a/components/style/gecko/arc_types.rs b/components/style/gecko/arc_types.rs index 4a11375797db..6a77c4c67135 100644 --- a/components/style/gecko/arc_types.rs +++ b/components/style/gecko/arc_types.rs @@ -8,13 +8,25 @@ #![allow(non_snake_case, missing_docs)] -use gecko_bindings::bindings::{RawServoCounterStyleRule, RawServoFontFeatureValuesRule, RawServoImportRule}; -use gecko_bindings::bindings::{RawServoKeyframe, RawServoKeyframesRule, RawServoSupportsRule}; -use gecko_bindings::bindings::{RawServoMediaRule, RawServoNamespaceRule, RawServoPageRule}; -use gecko_bindings::bindings::{RawServoRuleNode, RawServoRuleNodeStrong, RawServoDocumentRule}; +use gecko_bindings::bindings::RawServoCounterStyleRule; +use gecko_bindings::bindings::RawServoDocumentRule; +use gecko_bindings::bindings::RawServoFontFeatureValuesRule; +use gecko_bindings::bindings::RawServoImportRule; +use gecko_bindings::bindings::RawServoKeyframe; +use gecko_bindings::bindings::RawServoKeyframesRule; +use gecko_bindings::bindings::RawServoMediaRule; +use gecko_bindings::bindings::RawServoNamespaceRule; +use gecko_bindings::bindings::RawServoPageRule; +use gecko_bindings::bindings::RawServoRuleNode; +use gecko_bindings::bindings::RawServoRuleNodeStrong; +use gecko_bindings::bindings::RawServoSupportsRule; use gecko_bindings::bindings::ServoCssRules; -use gecko_bindings::structs::{RawServoAnimationValue, RawServoDeclarationBlock, RawServoFontFaceRule}; -use gecko_bindings::structs::{RawServoMediaList, RawServoStyleRule, RawServoStyleSheetContents}; +use gecko_bindings::structs::RawServoAnimationValue; +use gecko_bindings::structs::RawServoDeclarationBlock; +use gecko_bindings::structs::RawServoFontFaceRule; +use gecko_bindings::structs::RawServoMediaList; +use gecko_bindings::structs::RawServoStyleRule; +use gecko_bindings::structs::RawServoStyleSheetContents; use gecko_bindings::sugar::ownership::{HasArcFFI, HasFFI, Strong}; use media_queries::MediaList; use properties::{ComputedValues, PropertyDeclarationBlock}; @@ -24,8 +36,8 @@ use servo_arc::{Arc, ArcBorrow}; use shared_lock::Locked; use std::{mem, ptr}; use stylesheets::{CssRules, CounterStyleRule, FontFaceRule, FontFeatureValuesRule}; -use stylesheets::{ImportRule, KeyframesRule, MediaRule, StylesheetContents, StyleRule}; -use stylesheets::{NamespaceRule, PageRule, SupportsRule, DocumentRule}; +use stylesheets::{DocumentRule, ImportRule, KeyframesRule, MediaRule, NamespaceRule, PageRule}; +use stylesheets::{StylesheetContents, StyleRule, SupportsRule}; use stylesheets::keyframes_rule::Keyframe; macro_rules! impl_arc_ffi { diff --git a/components/style/gecko/conversions.rs b/components/style/gecko/conversions.rs index fa9f10f67dba..6900cc9e2c1d 100644 --- a/components/style/gecko/conversions.rs +++ b/components/style/gecko/conversions.rs @@ -10,15 +10,15 @@ use app_units::Au; use gecko::values::{convert_rgba_to_nscolor, GeckoStyleCoordConvertible}; -use gecko_bindings::bindings::{Gecko_CreateGradient, Gecko_SetGradientImageValue, Gecko_SetLayerImageImageValue}; -use gecko_bindings::bindings::{Gecko_InitializeImageCropRect, Gecko_SetImageElement}; +use gecko_bindings::bindings; use gecko_bindings::structs::{self, nsCSSUnit, nsStyleCoord_CalcValue}; use gecko_bindings::structs::{nsStyleImage, nsresult, SheetType}; use gecko_bindings::sugar::ns_style_coord::{CoordDataValue, CoordData, CoordDataMut}; use std::f32::consts::PI; use stylesheets::{Origin, RulesMutateError}; use values::computed::{Angle, CalcLengthOrPercentage, Gradient, Image}; -use values::computed::{Integer, LengthOrPercentage, LengthOrPercentageOrAuto, Percentage, TextAlign}; +use values::computed::{Integer, LengthOrPercentage, LengthOrPercentageOrAuto}; +use values::computed::{Percentage, TextAlign}; use values::computed::url::ComputedImageUrl; use values::generics::box_::VerticalAlign; use values::generics::grid::{TrackListValue, TrackSize}; @@ -156,13 +156,13 @@ impl nsStyleImage { }, GenericImage::Url(ref url) => { unsafe { - Gecko_SetLayerImageImageValue(self, url.image_value.get()); + bindings::Gecko_SetLayerImageImageValue(self, url.image_value.get()); } }, GenericImage::Rect(ref image_rect) => { unsafe { - Gecko_SetLayerImageImageValue(self, image_rect.url.image_value.get()); - Gecko_InitializeImageCropRect(self); + bindings::Gecko_SetLayerImageImageValue(self, image_rect.url.image_value.get()); + bindings::Gecko_InitializeImageCropRect(self); // Set CropRect let ref mut rect = *self.mCropRect.mPtr; @@ -174,18 +174,18 @@ impl nsStyleImage { } GenericImage::Element(ref element) => { unsafe { - Gecko_SetImageElement(self, element.as_ptr()); + bindings::Gecko_SetImageElement(self, element.as_ptr()); } } } } fn set_gradient(&mut self, gradient: Gradient) { - use gecko_bindings::structs::{NS_STYLE_GRADIENT_SHAPE_CIRCULAR, NS_STYLE_GRADIENT_SHAPE_ELLIPTICAL}; - use gecko_bindings::structs::{NS_STYLE_GRADIENT_SHAPE_LINEAR, NS_STYLE_GRADIENT_SIZE_CLOSEST_CORNER}; - use gecko_bindings::structs::{NS_STYLE_GRADIENT_SIZE_CLOSEST_SIDE, NS_STYLE_GRADIENT_SIZE_EXPLICIT_SIZE}; - use gecko_bindings::structs::{NS_STYLE_GRADIENT_SIZE_FARTHEST_CORNER, NS_STYLE_GRADIENT_SIZE_FARTHEST_SIDE}; - use gecko_bindings::structs::nsStyleCoord; + use self::structs::NS_STYLE_GRADIENT_SIZE_CLOSEST_CORNER as CLOSEST_CORNER; + use self::structs::NS_STYLE_GRADIENT_SIZE_CLOSEST_SIDE as CLOSEST_SIDE; + use self::structs::NS_STYLE_GRADIENT_SIZE_FARTHEST_CORNER as FARTHEST_CORNER; + use self::structs::NS_STYLE_GRADIENT_SIZE_FARTHEST_SIDE as FARTHEST_SIDE; + use self::structs::nsStyleCoord; use values::computed::image::LineDirection; use values::generics::image::{Circle, Ellipse, EndingShape, GradientKind, ShapeExtent}; use values::specified::position::{X, Y}; @@ -199,8 +199,8 @@ impl nsStyleImage { let gecko_gradient = match gradient.kind { GradientKind::Linear(direction) => { let gecko_gradient = unsafe { - Gecko_CreateGradient(NS_STYLE_GRADIENT_SHAPE_LINEAR as u8, - NS_STYLE_GRADIENT_SIZE_FARTHEST_CORNER as u8, + bindings::Gecko_CreateGradient(structs::NS_STYLE_GRADIENT_SHAPE_LINEAR as u8, + structs::NS_STYLE_GRADIENT_SIZE_FARTHEST_CORNER as u8, gradient.repeating, gradient.compat_mode != CompatMode::Modern, gradient.compat_mode == CompatMode::Moz, @@ -279,12 +279,12 @@ impl nsStyleImage { GradientKind::Radial(shape, position, angle) => { let keyword_to_gecko_size = |keyword| { match keyword { - ShapeExtent::ClosestSide => NS_STYLE_GRADIENT_SIZE_CLOSEST_SIDE, - ShapeExtent::FarthestSide => NS_STYLE_GRADIENT_SIZE_FARTHEST_SIDE, - ShapeExtent::ClosestCorner => NS_STYLE_GRADIENT_SIZE_CLOSEST_CORNER, - ShapeExtent::FarthestCorner => NS_STYLE_GRADIENT_SIZE_FARTHEST_CORNER, - ShapeExtent::Contain => NS_STYLE_GRADIENT_SIZE_CLOSEST_SIDE, - ShapeExtent::Cover => NS_STYLE_GRADIENT_SIZE_FARTHEST_CORNER, + ShapeExtent::ClosestSide => CLOSEST_SIDE, + ShapeExtent::FarthestSide => FARTHEST_SIDE, + ShapeExtent::ClosestCorner => CLOSEST_CORNER, + ShapeExtent::FarthestCorner => FARTHEST_CORNER, + ShapeExtent::Contain => CLOSEST_SIDE, + ShapeExtent::Cover => FARTHEST_CORNER, } }; let (gecko_shape, gecko_size) = match shape { @@ -293,23 +293,23 @@ impl nsStyleImage { Circle::Extent(extent) => { keyword_to_gecko_size(extent) }, - _ => NS_STYLE_GRADIENT_SIZE_EXPLICIT_SIZE, + _ => structs::NS_STYLE_GRADIENT_SIZE_EXPLICIT_SIZE, }; - (NS_STYLE_GRADIENT_SHAPE_CIRCULAR as u8, size as u8) + (structs::NS_STYLE_GRADIENT_SHAPE_CIRCULAR as u8, size as u8) }, EndingShape::Ellipse(ref ellipse) => { let size = match *ellipse { Ellipse::Extent(extent) => { keyword_to_gecko_size(extent) }, - _ => NS_STYLE_GRADIENT_SIZE_EXPLICIT_SIZE, + _ => structs::NS_STYLE_GRADIENT_SIZE_EXPLICIT_SIZE, }; - (NS_STYLE_GRADIENT_SHAPE_ELLIPTICAL as u8, size as u8) + (structs::NS_STYLE_GRADIENT_SHAPE_ELLIPTICAL as u8, size as u8) } }; let gecko_gradient = unsafe { - Gecko_CreateGradient(gecko_shape, + bindings::Gecko_CreateGradient(gecko_shape, gecko_size, gradient.repeating, gradient.compat_mode == CompatMode::Moz, @@ -375,13 +375,12 @@ impl nsStyleImage { } unsafe { - Gecko_SetGradientImageValue(self, gecko_gradient); + bindings::Gecko_SetGradientImageValue(self, gecko_gradient); } } /// Converts into Image. pub unsafe fn into_image(self: &nsStyleImage) -> Option { - use gecko_bindings::bindings::Gecko_GetImageElement; use gecko_bindings::structs::nsStyleImageType; use values::computed::{NumberOrPercentage, MozImageRect}; @@ -413,7 +412,7 @@ impl nsStyleImage { }, nsStyleImageType::eStyleImageType_Element => { use gecko_string_cache::Atom; - let atom = Gecko_GetImageElement(self); + let atom = bindings::Gecko_GetImageElement(self); Some(GenericImage::Element(Atom::from_raw(atom))) }, _ => panic!("Unexpected image type") @@ -421,32 +420,31 @@ impl nsStyleImage { } unsafe fn get_image_url(self: &nsStyleImage) -> ComputedImageUrl { - use gecko_bindings::bindings::Gecko_GetURLValue; - let url_value = Gecko_GetURLValue(self); + let url_value = bindings::Gecko_GetURLValue(self); ComputedImageUrl::from_url_value_data(url_value.as_ref().unwrap()) .expect("Could not convert to ComputedUrl") } unsafe fn get_gradient(self: &nsStyleImage) -> Box { use gecko::values::convert_nscolor_to_rgba; - use gecko_bindings::bindings::Gecko_GetGradientImageValue; - use gecko_bindings::structs::{NS_STYLE_GRADIENT_SHAPE_CIRCULAR, NS_STYLE_GRADIENT_SHAPE_ELLIPTICAL}; - use gecko_bindings::structs::{NS_STYLE_GRADIENT_SHAPE_LINEAR, NS_STYLE_GRADIENT_SIZE_CLOSEST_CORNER}; - use gecko_bindings::structs::{NS_STYLE_GRADIENT_SIZE_CLOSEST_SIDE, NS_STYLE_GRADIENT_SIZE_EXPLICIT_SIZE}; - use gecko_bindings::structs::{NS_STYLE_GRADIENT_SIZE_FARTHEST_CORNER, NS_STYLE_GRADIENT_SIZE_FARTHEST_SIDE}; + use self::structs::NS_STYLE_GRADIENT_SIZE_CLOSEST_CORNER as CLOSEST_CORNER; + use self::structs::NS_STYLE_GRADIENT_SIZE_CLOSEST_SIDE as CLOSEST_SIDE; + use self::structs::NS_STYLE_GRADIENT_SIZE_FARTHEST_CORNER as FARTHEST_CORNER; + use self::structs::NS_STYLE_GRADIENT_SIZE_FARTHEST_SIDE as FARTHEST_SIDE; use values::computed::{Length, LengthOrPercentage}; use values::computed::image::LineDirection; use values::computed::position::Position; - use values::generics::image::{ColorStop, CompatMode, Circle, Ellipse, EndingShape, GradientKind, ShapeExtent}; + use values::generics::image::{ColorStop, CompatMode, Circle, Ellipse}; + use values::generics::image::{EndingShape, GradientKind, ShapeExtent}; use values::specified::position::{X, Y}; - let gecko_gradient = Gecko_GetGradientImageValue(self).as_ref().unwrap(); + let gecko_gradient = bindings::Gecko_GetGradientImageValue(self).as_ref().unwrap(); let angle = Angle::from_gecko_style_coord(&gecko_gradient.mAngle); let horizontal_style = LengthOrPercentage::from_gecko_style_coord(&gecko_gradient.mBgPosX); let vertical_style = LengthOrPercentage::from_gecko_style_coord(&gecko_gradient.mBgPosY); let kind = match gecko_gradient.mShape as u32 { - NS_STYLE_GRADIENT_SHAPE_LINEAR => { + structs::NS_STYLE_GRADIENT_SHAPE_LINEAR => { let line_direction = match (angle, horizontal_style, vertical_style) { (Some(a), None, None) => LineDirection::Angle(a), (None, Some(horizontal), Some(vertical)) => { @@ -495,10 +493,10 @@ impl nsStyleImage { _ => { let gecko_size_to_keyword = |gecko_size| { match gecko_size { - NS_STYLE_GRADIENT_SIZE_CLOSEST_SIDE => ShapeExtent::ClosestSide, - NS_STYLE_GRADIENT_SIZE_FARTHEST_SIDE => ShapeExtent::FarthestSide, - NS_STYLE_GRADIENT_SIZE_CLOSEST_CORNER => ShapeExtent::ClosestCorner, - NS_STYLE_GRADIENT_SIZE_FARTHEST_CORNER => ShapeExtent::FarthestCorner, + CLOSEST_SIDE => ShapeExtent::ClosestSide, + FARTHEST_SIDE => ShapeExtent::FarthestSide, + CLOSEST_CORNER => ShapeExtent::ClosestCorner, + FARTHEST_CORNER => ShapeExtent::FarthestCorner, // FIXME: We should support ShapeExtent::Contain and ShapeExtent::Cover. // But we can't choose those yet since Gecko does not support both values. // https://bugzilla.mozilla.org/show_bug.cgi?id=1217664 @@ -507,9 +505,9 @@ impl nsStyleImage { }; let shape = match gecko_gradient.mShape as u32 { - NS_STYLE_GRADIENT_SHAPE_CIRCULAR => { + structs::NS_STYLE_GRADIENT_SHAPE_CIRCULAR => { let circle = match gecko_gradient.mSize as u32 { - NS_STYLE_GRADIENT_SIZE_EXPLICIT_SIZE => { + structs::NS_STYLE_GRADIENT_SIZE_EXPLICIT_SIZE => { let radius = Length::from_gecko_style_coord(&gecko_gradient.mRadiusX) .expect("mRadiusX could not convert to Length"); debug_assert_eq!(radius, @@ -520,9 +518,9 @@ impl nsStyleImage { }; EndingShape::Circle(circle) }, - NS_STYLE_GRADIENT_SHAPE_ELLIPTICAL => { + structs::NS_STYLE_GRADIENT_SHAPE_ELLIPTICAL => { let length_percentage_keyword = match gecko_gradient.mSize as u32 { - NS_STYLE_GRADIENT_SIZE_EXPLICIT_SIZE => { + structs::NS_STYLE_GRADIENT_SIZE_EXPLICIT_SIZE => { match (LengthOrPercentage::from_gecko_style_coord(&gecko_gradient.mRadiusX), LengthOrPercentage::from_gecko_style_coord(&gecko_gradient.mRadiusY)) { (Some(x), Some(y)) => Ellipse::Radii(x, y), diff --git a/components/style/gecko/data.rs b/components/style/gecko/data.rs index 52812d668443..e1afa8f53aa2 100644 --- a/components/style/gecko/data.rs +++ b/components/style/gecko/data.rs @@ -7,8 +7,8 @@ use atomic_refcell::{AtomicRef, AtomicRefCell, AtomicRefMut}; use dom::TElement; use gecko_bindings::bindings::{self, RawServoStyleSet}; -use gecko_bindings::structs::{RawGeckoPresContextOwned, ServoStyleSetSizes, ServoStyleSheet}; -use gecko_bindings::structs::{StyleSheetInfo, ServoStyleSheetInner, nsIDocument, self}; +use gecko_bindings::structs::{self, RawGeckoPresContextOwned, ServoStyleSetSizes, ServoStyleSheet}; +use gecko_bindings::structs::{StyleSheetInfo, ServoStyleSheetInner, nsIDocument}; use gecko_bindings::sugar::ownership::{HasArcFFI, HasBoxFFI, HasFFI, HasSimpleFFI}; use invalidation::media_queries::{MediaListKey, ToMediaListKey}; use malloc_size_of::MallocSizeOfOps; diff --git a/components/style/gecko/media_queries.rs b/components/style/gecko/media_queries.rs index bb5fbdde044d..e8dcb0179eb2 100644 --- a/components/style/gecko/media_queries.rs +++ b/components/style/gecko/media_queries.rs @@ -14,8 +14,9 @@ use gecko::values::{convert_nscolor_to_rgba, convert_rgba_to_nscolor}; use gecko_bindings::bindings; use gecko_bindings::structs; use gecko_bindings::structs::{nsCSSKeyword, nsCSSProps_KTableEntry, nsCSSValue, nsCSSUnit}; -use gecko_bindings::structs::{nsMediaFeature, nsMediaFeature_ValueType, nsMediaFeature_RangeType}; -use gecko_bindings::structs::{nsPresContext, RawGeckoPresContextOwned}; +use gecko_bindings::structs::{nsMediaFeature, nsMediaFeature_RangeType}; +use gecko_bindings::structs::{nsMediaFeature_ValueType, nsPresContext}; +use gecko_bindings::structs::RawGeckoPresContextOwned; use media_queries::MediaType; use parser::{Parse, ParserContext}; use properties::ComputedValues; diff --git a/components/style/gecko/selector_parser.rs b/components/style/gecko/selector_parser.rs index 41f33269d7d4..7a1988ad51eb 100644 --- a/components/style/gecko/selector_parser.rs +++ b/components/style/gecko/selector_parser.rs @@ -4,7 +4,8 @@ //! Gecko-specific bits for selector-parsing. -use cssparser::{BasicParseError, BasicParseErrorKind, Parser, ToCss, Token, CowRcStr, SourceLocation}; +use cssparser::{BasicParseError, BasicParseErrorKind, Parser}; +use cssparser::{ToCss, Token, CowRcStr, SourceLocation}; use element_state::{DocumentState, ElementState}; use gecko_bindings::structs; use gecko_bindings::structs::RawServoSelectorList; diff --git a/components/style/gecko/snapshot.rs b/components/style/gecko/snapshot.rs index f51d031a5270..51b4b4b64ed0 100644 --- a/components/style/gecko/snapshot.rs +++ b/components/style/gecko/snapshot.rs @@ -15,7 +15,8 @@ use gecko_bindings::structs::ServoElementSnapshot; use gecko_bindings::structs::ServoElementSnapshotFlags as Flags; use gecko_bindings::structs::ServoElementSnapshotTable; use invalidation::element::element_wrapper::ElementSnapshot; -use selectors::attr::{AttrSelectorOperation, AttrSelectorOperator, CaseSensitivity, NamespaceConstraint}; +use selectors::attr::{AttrSelectorOperation, AttrSelectorOperator}; +use selectors::attr::{CaseSensitivity, NamespaceConstraint}; use string_cache::{Atom, Namespace}; /// A snapshot of a Gecko element. diff --git a/components/style/gecko/wrapper.rs b/components/style/gecko/wrapper.rs index 6902093be7db..864b5a9eb1a7 100644 --- a/components/style/gecko/wrapper.rs +++ b/components/style/gecko/wrapper.rs @@ -29,7 +29,6 @@ use gecko::global_style_data::GLOBAL_STYLE_DATA; use gecko::selector_parser::{SelectorImpl, NonTSPseudoClass, PseudoElement}; use gecko::snapshot_helpers; use gecko_bindings::bindings; -use gecko_bindings::bindings::{Gecko_ConstructStyleChildrenIterator, Gecko_DestroyStyleChildrenIterator}; use gecko_bindings::bindings::{Gecko_ElementState, Gecko_GetDocumentLWTheme}; use gecko_bindings::bindings::{Gecko_GetLastChild, Gecko_GetNextStyleChild}; use gecko_bindings::bindings::{Gecko_SetNodeFlags, Gecko_UnsetNodeFlags}; @@ -73,7 +72,8 @@ use properties::style_structs::Font; use rule_tree::CascadeLevel as ServoCascadeLevel; use selector_parser::{AttrValue, Direction, PseudoClassStringArg}; use selectors::{Element, OpaqueElement}; -use selectors::attr::{AttrSelectorOperation, AttrSelectorOperator, CaseSensitivity, NamespaceConstraint}; +use selectors::attr::{AttrSelectorOperation, AttrSelectorOperator}; +use selectors::attr::{CaseSensitivity, NamespaceConstraint}; use selectors::matching::{ElementSelectorFlags, MatchingContext}; use selectors::matching::VisitedHandlingMode; use selectors::sink::Push; @@ -454,7 +454,7 @@ impl<'a> Drop for GeckoChildrenIterator<'a> { fn drop(&mut self) { if let GeckoChildrenIterator::GeckoIterator(ref mut it) = *self { unsafe { - Gecko_DestroyStyleChildrenIterator(it); + bindings::Gecko_DestroyStyleChildrenIterator(it); } } } @@ -1046,7 +1046,7 @@ impl<'le> TElement for GeckoElement<'le> { self.may_have_anonymous_children() { unsafe { let mut iter: structs::StyleChildrenIterator = ::std::mem::zeroed(); - Gecko_ConstructStyleChildrenIterator(self.0, &mut iter); + bindings::Gecko_ConstructStyleChildrenIterator(self.0, &mut iter); return LayoutIterator(GeckoChildrenIterator::GeckoIterator(iter)); } } diff --git a/components/style/gecko_bindings/sugar/ns_style_coord.rs b/components/style/gecko_bindings/sugar/ns_style_coord.rs index d08ad0e8669f..d974e9393020 100644 --- a/components/style/gecko_bindings/sugar/ns_style_coord.rs +++ b/components/style/gecko_bindings/sugar/ns_style_coord.rs @@ -4,9 +4,9 @@ //! Rust helpers for Gecko's `nsStyleCoord`. -use gecko_bindings::bindings::{Gecko_ResetStyleCoord, Gecko_SetStyleCoordCalcValue, Gecko_AddRefCalcArbitraryThread}; -use gecko_bindings::structs::{nsStyleCoord_Calc, nsStyleUnit, nsStyleUnion, nsStyleCoord, nsStyleSides, nsStyleCorners}; -use gecko_bindings::structs::{nsStyleCoord_CalcValue, nscoord}; +use gecko_bindings::bindings; +use gecko_bindings::structs::{nsStyleCoord, nsStyleCoord_Calc, nsStyleCoord_CalcValue}; +use gecko_bindings::structs::{nsStyleCorners, nsStyleUnit, nsStyleUnion, nsStyleSides, nscoord}; use std::mem; impl nsStyleCoord { @@ -257,7 +257,7 @@ pub unsafe trait CoordDataMut : CoordData { unsafe { if self.unit() == nsStyleUnit::eStyleUnit_Calc { let (unit, union) = self.values_mut(); - Gecko_ResetStyleCoord(unit, union); + bindings::Gecko_ResetStyleCoord(unit, union); } } } @@ -368,7 +368,7 @@ pub unsafe trait CoordDataMut : CoordData { } Calc(calc) => { // Gecko_SetStyleCoordCalcValue changes the unit internally - Gecko_SetStyleCoordCalcValue(unit, union, calc); + bindings::Gecko_SetStyleCoordCalcValue(unit, union, calc); } } } @@ -388,7 +388,7 @@ pub unsafe trait CoordDataMut : CoordData { fn addref_if_calc(&mut self) { unsafe { if self.unit() == nsStyleUnit::eStyleUnit_Calc { - Gecko_AddRefCalcArbitraryThread(self.as_calc_mut()); + bindings::Gecko_AddRefCalcArbitraryThread(self.as_calc_mut()); } } } diff --git a/components/style/gecko_bindings/sugar/ns_timing_function.rs b/components/style/gecko_bindings/sugar/ns_timing_function.rs index ea07af54b3f5..189ba55da2c4 100644 --- a/components/style/gecko_bindings/sugar/ns_timing_function.rs +++ b/components/style/gecko_bindings/sugar/ns_timing_function.rs @@ -6,7 +6,8 @@ use gecko_bindings::structs::{nsTimingFunction, nsTimingFunction_Type}; use std::mem; use values::computed::ToComputedValue; use values::computed::transform::TimingFunction as ComputedTimingFunction; -use values::generics::transform::{StepPosition, TimingFunction as GenericTimingFunction, TimingKeyword}; +use values::generics::transform::{StepPosition, TimingKeyword}; +use values::generics::transform::TimingFunction as GenericTimingFunction; use values::specified::transform::TimingFunction; impl nsTimingFunction { diff --git a/components/style/invalidation/element/element_wrapper.rs b/components/style/invalidation/element/element_wrapper.rs index 29da4d7cb2fd..8ba737895836 100644 --- a/components/style/invalidation/element/element_wrapper.rs +++ b/components/style/invalidation/element/element_wrapper.rs @@ -8,7 +8,8 @@ use {Atom, CaseSensitivityExt, LocalName, Namespace, WeakAtom}; use dom::TElement; use element_state::ElementState; -use selector_parser::{NonTSPseudoClass, PseudoElement, SelectorImpl, Snapshot, SnapshotMap, AttrValue}; +use selector_parser::{AttrValue, NonTSPseudoClass, PseudoElement, SelectorImpl}; +use selector_parser::{Snapshot, SnapshotMap}; use selectors::{Element, OpaqueElement}; use selectors::attr::{AttrSelectorOperation, CaseSensitivity, NamespaceConstraint}; use selectors::matching::{ElementSelectorFlags, MatchingContext}; diff --git a/components/style/lib.rs b/components/style/lib.rs index 49acbe35f139..2f4cb786d24b 100644 --- a/components/style/lib.rs +++ b/components/style/lib.rs @@ -39,9 +39,9 @@ extern crate fallible; extern crate fnv; #[cfg(feature = "gecko")] #[macro_use] pub mod gecko_string_cache; extern crate hashglobe; +#[cfg(feature = "servo")] #[macro_use] extern crate html5ever; extern crate itertools; extern crate itoa; -#[cfg(feature = "servo")] #[macro_use] extern crate html5ever; #[macro_use] extern crate lazy_static; #[macro_use] diff --git a/components/style/stylesheets/document_rule.rs b/components/style/stylesheets/document_rule.rs index 920e3045cdaa..70f347d0fd94 100644 --- a/components/style/stylesheets/document_rule.rs +++ b/components/style/stylesheets/document_rule.rs @@ -12,7 +12,8 @@ use malloc_size_of::{MallocSizeOfOps, MallocUnconditionalShallowSizeOf}; use media_queries::Device; use parser::{Parse, ParserContext}; use servo_arc::Arc; -use shared_lock::{DeepCloneParams, DeepCloneWithLock, Locked, SharedRwLock, SharedRwLockReadGuard, ToCssWithGuard}; +use shared_lock::{DeepCloneParams, DeepCloneWithLock, Locked}; +use shared_lock::{SharedRwLock, SharedRwLockReadGuard, ToCssWithGuard}; use std::fmt::{self, Write}; use str::CssStringWriter; use style_traits::{CssWriter, ParseError, StyleParseErrorKind, ToCss}; diff --git a/components/style/stylesheets/font_feature_values_rule.rs b/components/style/stylesheets/font_feature_values_rule.rs index eb799793f791..512b95064a60 100644 --- a/components/style/stylesheets/font_feature_values_rule.rs +++ b/components/style/stylesheets/font_feature_values_rule.rs @@ -7,8 +7,9 @@ //! [font-feature-values]: https://drafts.csswg.org/css-fonts-3/#at-font-feature-values-rule use Atom; -use cssparser::{AtRuleParser, AtRuleType, BasicParseErrorKind, DeclarationListParser, DeclarationParser, Parser}; -use cssparser::{CowRcStr, RuleListParser, SourceLocation, QualifiedRuleParser, Token}; +use cssparser::{AtRuleParser, AtRuleType, BasicParseErrorKind, CowRcStr}; +use cssparser::{DeclarationListParser, DeclarationParser, Parser}; +use cssparser::{QualifiedRuleParser, RuleListParser, SourceLocation, Token}; use error_reporting::{ContextualParseError, ParseErrorReporter}; #[cfg(feature = "gecko")] use gecko_bindings::bindings::Gecko_AppendFeatureValueHashEntry; diff --git a/components/style/stylesheets/import_rule.rs b/components/style/stylesheets/import_rule.rs index 6b3c28621e50..d8e5c63c73ae 100644 --- a/components/style/stylesheets/import_rule.rs +++ b/components/style/stylesheets/import_rule.rs @@ -8,7 +8,8 @@ use cssparser::SourceLocation; use media_queries::MediaList; -use shared_lock::{DeepCloneWithLock, DeepCloneParams, SharedRwLock, SharedRwLockReadGuard, ToCssWithGuard}; +use shared_lock::{DeepCloneWithLock, DeepCloneParams}; +use shared_lock::{SharedRwLock, SharedRwLockReadGuard, ToCssWithGuard}; use std::fmt::{self, Write}; use str::CssStringWriter; use style_traits::{CssWriter, ToCss}; diff --git a/components/style/stylesheets/keyframes_rule.rs b/components/style/stylesheets/keyframes_rule.rs index 302ac36e46b4..e28741aaf5d0 100644 --- a/components/style/stylesheets/keyframes_rule.rs +++ b/components/style/stylesheets/keyframes_rule.rs @@ -8,12 +8,14 @@ use cssparser::{AtRuleParser, Parser, QualifiedRuleParser, RuleListParser, Parse use cssparser::{DeclarationListParser, DeclarationParser, parse_one_rule, SourceLocation, Token}; use error_reporting::{NullReporter, ContextualParseError, ParseErrorReporter}; use parser::{ParserContext, ParserErrorContext}; -use properties::{DeclarationSource, Importance, PropertyDeclaration, PropertyDeclarationBlock, PropertyId}; -use properties::{PropertyDeclarationId, LonghandId, SourcePropertyDeclaration}; +use properties::{DeclarationSource, Importance, PropertyDeclaration}; +use properties::{LonghandId, PropertyDeclarationBlock, PropertyId}; +use properties::{PropertyDeclarationId, SourcePropertyDeclaration}; use properties::LonghandIdSet; use properties::longhands::transition_timing_function::single_value::SpecifiedValue as SpecifiedTimingFunction; use servo_arc::Arc; -use shared_lock::{DeepCloneParams, DeepCloneWithLock, SharedRwLock, SharedRwLockReadGuard, Locked, ToCssWithGuard}; +use shared_lock::{DeepCloneParams, DeepCloneWithLock, SharedRwLock, SharedRwLockReadGuard}; +use shared_lock::{Locked, ToCssWithGuard}; use std::fmt::{self, Write}; use str::CssStringWriter; use style_traits::{CssWriter, ParseError, ParsingMode, StyleParseErrorKind, ToCss}; diff --git a/components/style/stylesheets/media_rule.rs b/components/style/stylesheets/media_rule.rs index 20aa4329693d..f19d28c2461e 100644 --- a/components/style/stylesheets/media_rule.rs +++ b/components/style/stylesheets/media_rule.rs @@ -11,7 +11,8 @@ use cssparser::SourceLocation; use malloc_size_of::{MallocSizeOfOps, MallocUnconditionalShallowSizeOf}; use media_queries::MediaList; use servo_arc::Arc; -use shared_lock::{DeepCloneParams, DeepCloneWithLock, Locked, SharedRwLock, SharedRwLockReadGuard, ToCssWithGuard}; +use shared_lock::{DeepCloneParams, DeepCloneWithLock, Locked}; +use shared_lock::{SharedRwLock, SharedRwLockReadGuard, ToCssWithGuard}; use std::fmt::{self, Write}; use str::CssStringWriter; use style_traits::{CssWriter, ToCss}; diff --git a/components/style/stylesheets/mod.rs b/components/style/stylesheets/mod.rs index da999548dfc6..8f69b5420b5e 100644 --- a/components/style/stylesheets/mod.rs +++ b/components/style/stylesheets/mod.rs @@ -29,7 +29,8 @@ use error_reporting::NullReporter; use malloc_size_of::{MallocSizeOfOps, MallocUnconditionalShallowSizeOf}; use parser::{ParserContext, ParserErrorContext}; use servo_arc::Arc; -use shared_lock::{DeepCloneParams, DeepCloneWithLock, Locked, SharedRwLock, SharedRwLockReadGuard, ToCssWithGuard}; +use shared_lock::{DeepCloneParams, DeepCloneWithLock, Locked}; +use shared_lock::{SharedRwLock, SharedRwLockReadGuard, ToCssWithGuard}; use std::fmt; use str::CssStringWriter; use style_traits::ParsingMode; @@ -47,7 +48,8 @@ pub use self::origin::{Origin, OriginSet, OriginSetIterator, PerOrigin, PerOrigi pub use self::page_rule::PageRule; pub use self::rule_parser::{State, TopLevelRuleParser}; pub use self::rule_list::{CssRules, CssRulesHelpers}; -pub use self::rules_iterator::{AllRules, EffectiveRules, NestedRuleIterationCondition, RulesIterator}; +pub use self::rules_iterator::{AllRules, EffectiveRules}; +pub use self::rules_iterator::{NestedRuleIterationCondition, RulesIterator}; pub use self::stylesheet::{Namespaces, Stylesheet, DocumentStyleSheet}; pub use self::stylesheet::{StylesheetContents, StylesheetInDocument, UserAgentStylesheets}; pub use self::style_rule::StyleRule; diff --git a/components/style/stylesheets/page_rule.rs b/components/style/stylesheets/page_rule.rs index 7b72f3e60c3a..732231ca0cef 100644 --- a/components/style/stylesheets/page_rule.rs +++ b/components/style/stylesheets/page_rule.rs @@ -11,7 +11,8 @@ use cssparser::SourceLocation; use malloc_size_of::{MallocSizeOf, MallocSizeOfOps, MallocUnconditionalShallowSizeOf}; use properties::PropertyDeclarationBlock; use servo_arc::Arc; -use shared_lock::{DeepCloneParams, DeepCloneWithLock, Locked, SharedRwLock, SharedRwLockReadGuard, ToCssWithGuard}; +use shared_lock::{DeepCloneParams, DeepCloneWithLock, Locked}; +use shared_lock::{SharedRwLock, SharedRwLockReadGuard, ToCssWithGuard}; use std::fmt::{self, Write}; use str::CssStringWriter; diff --git a/components/style/stylesheets/style_rule.rs b/components/style/stylesheets/style_rule.rs index 4a4ab3d58ed2..fc6738df58dd 100644 --- a/components/style/stylesheets/style_rule.rs +++ b/components/style/stylesheets/style_rule.rs @@ -6,12 +6,15 @@ use cssparser::SourceLocation; #[cfg(feature = "gecko")] -use malloc_size_of::{MallocShallowSizeOf, MallocSizeOf, MallocSizeOfOps, MallocUnconditionalShallowSizeOf}; +use malloc_size_of::{MallocShallowSizeOf, MallocSizeOf, MallocSizeOfOps}; +#[cfg(feature = "gecko")] +use malloc_size_of::MallocUnconditionalShallowSizeOf; use properties::PropertyDeclarationBlock; use selector_parser::SelectorImpl; use selectors::SelectorList; use servo_arc::Arc; -use shared_lock::{DeepCloneParams, DeepCloneWithLock, Locked, SharedRwLock, SharedRwLockReadGuard, ToCssWithGuard}; +use shared_lock::{DeepCloneParams, DeepCloneWithLock, Locked}; +use shared_lock::{SharedRwLock, SharedRwLockReadGuard, ToCssWithGuard}; use std::fmt::{self, Write}; use str::CssStringWriter; diff --git a/components/style/stylesheets/stylesheet.rs b/components/style/stylesheets/stylesheet.rs index f54a8a3b1832..811d01fab1e3 100644 --- a/components/style/stylesheets/stylesheet.rs +++ b/components/style/stylesheets/stylesheet.rs @@ -22,7 +22,8 @@ use style_traits::ParsingMode; use stylesheets::{CssRule, CssRules, Origin, UrlExtraData}; use stylesheets::loader::StylesheetLoader; use stylesheets::rule_parser::{State, TopLevelRuleParser}; -use stylesheets::rules_iterator::{EffectiveRules, EffectiveRulesIterator, NestedRuleIterationCondition, RulesIterator}; +use stylesheets::rules_iterator::{EffectiveRules, EffectiveRulesIterator}; +use stylesheets::rules_iterator::{NestedRuleIterationCondition, RulesIterator}; /// This structure holds the user-agent and user stylesheets. pub struct UserAgentStylesheets { diff --git a/components/style/stylesheets/supports_rule.rs b/components/style/stylesheets/supports_rule.rs index cdb0cd43818e..0a4240147c95 100644 --- a/components/style/stylesheets/supports_rule.rs +++ b/components/style/stylesheets/supports_rule.rs @@ -4,15 +4,17 @@ //! [@supports rules](https://drafts.csswg.org/css-conditional-3/#at-supports) -use cssparser::{Delimiter, parse_important, Parser, SourceLocation, Token}; +use cssparser::{Delimiter, Parser, SourceLocation, Token}; use cssparser::{ParseError as CssParseError, ParserInput}; +use cssparser::parse_important; #[cfg(feature = "gecko")] use malloc_size_of::{MallocSizeOfOps, MallocUnconditionalShallowSizeOf}; use parser::ParserContext; use properties::{PropertyId, PropertyDeclaration, SourcePropertyDeclaration}; use selectors::parser::SelectorParseErrorKind; use servo_arc::Arc; -use shared_lock::{DeepCloneParams, DeepCloneWithLock, Locked, SharedRwLock, SharedRwLockReadGuard, ToCssWithGuard}; +use shared_lock::{DeepCloneParams, DeepCloneWithLock, Locked}; +use shared_lock::{SharedRwLock, SharedRwLockReadGuard, ToCssWithGuard}; use std::ffi::{CStr, CString}; use std::fmt::{self, Write}; use std::str; diff --git a/components/style/traversal.rs b/components/style/traversal.rs index 8944752f6428..f8e68aa021d9 100644 --- a/components/style/traversal.rs +++ b/components/style/traversal.rs @@ -259,10 +259,9 @@ pub trait DomTraversal : Sync { parent_data: &ElementData, is_initial_style: bool, ) -> bool { - debug_assert!(parent.has_current_styles_for_traversal( - parent_data, - context.shared.traversal_flags, - )); + debug_assert!( + parent.has_current_styles_for_traversal(parent_data, context.shared.traversal_flags) + ); // If the parent computed display:none, we don't style the subtree. if parent_data.styles.is_display_none() { diff --git a/components/style/values/computed/angle.rs b/components/style/values/computed/angle.rs index fdeda7749bda..ff7c1af6e134 100644 --- a/components/style/values/computed/angle.rs +++ b/components/style/values/computed/angle.rs @@ -15,8 +15,8 @@ use values::distance::{ComputeSquaredDistance, SquaredDistance}; /// A computed angle. #[animate(fallback = "Self::animate_fallback")] #[cfg_attr(feature = "servo", derive(Deserialize, Serialize))] -#[derive(Animate, Clone, Copy, Debug, MallocSizeOf, PartialEq, ToCss)] -#[derive(PartialOrd, ToAnimatedZero)] +#[derive(Animate, Clone, Copy, Debug, MallocSizeOf)] +#[derive(PartialEq, PartialOrd, ToAnimatedZero, ToCss)] pub enum Angle { /// An angle with degree unit. #[css(dimension)] diff --git a/components/style/values/computed/background.rs b/components/style/values/computed/background.rs index daaa9a732e6c..2c9700b94b5b 100644 --- a/components/style/values/computed/background.rs +++ b/components/style/values/computed/background.rs @@ -12,7 +12,8 @@ use values::animated::{ToAnimatedValue, ToAnimatedZero}; use values::computed::{Context, ToComputedValue}; use values::computed::length::LengthOrPercentageOrAuto; use values::generics::background::BackgroundSize as GenericBackgroundSize; -use values::specified::background::{BackgroundRepeat as SpecifiedBackgroundRepeat, BackgroundRepeatKeyword}; +use values::specified::background::BackgroundRepeat as SpecifiedBackgroundRepeat; +use values::specified::background::BackgroundRepeatKeyword; /// A computed value for the `background-size` property. pub type BackgroundSize = GenericBackgroundSize; diff --git a/components/style/values/computed/basic_shape.rs b/components/style/values/computed/basic_shape.rs index 13dea6fc99a8..6646f281f746 100644 --- a/components/style/values/computed/basic_shape.rs +++ b/components/style/values/computed/basic_shape.rs @@ -11,31 +11,28 @@ use std::fmt::{self, Write}; use style_traits::{CssWriter, ToCss}; use values::computed::{LengthOrPercentage, Image}; use values::computed::url::ComputedUrl; -use values::generics::basic_shape::{BasicShape as GenericBasicShape}; -use values::generics::basic_shape::{Circle as GenericCircle, ClippingShape as GenericClippingShape}; -use values::generics::basic_shape::{Ellipse as GenericEllipse, FloatAreaShape as GenericFloatAreaShape}; -use values::generics::basic_shape::{InsetRect as GenericInsetRect, ShapeRadius as GenericShapeRadius}; +use values::generics::basic_shape as generic; /// A computed clipping shape. -pub type ClippingShape = GenericClippingShape; +pub type ClippingShape = generic::ClippingShape; /// A computed float area shape. -pub type FloatAreaShape = GenericFloatAreaShape; +pub type FloatAreaShape = generic::FloatAreaShape; /// A computed basic shape. -pub type BasicShape = GenericBasicShape; +pub type BasicShape = generic::BasicShape; /// The computed value of `inset()` -pub type InsetRect = GenericInsetRect; +pub type InsetRect = generic::InsetRect; /// A computed circle. -pub type Circle = GenericCircle; +pub type Circle = generic::Circle; /// A computed ellipse. -pub type Ellipse = GenericEllipse; +pub type Ellipse = generic::Ellipse; /// The computed value of `ShapeRadius` -pub type ShapeRadius = GenericShapeRadius; +pub type ShapeRadius = generic::ShapeRadius; impl ToCss for Circle { fn to_css(&self, dest: &mut CssWriter) -> fmt::Result diff --git a/components/style/values/computed/image.rs b/components/style/values/computed/image.rs index 7535ccf6dd46..15eed79287a1 100644 --- a/components/style/values/computed/image.rs +++ b/components/style/values/computed/image.rs @@ -18,10 +18,7 @@ use values::computed::{Length, LengthOrPercentage, NumberOrPercentage, ToCompute use values::computed::Percentage; use values::computed::position::Position; use values::computed::url::ComputedImageUrl; -use values::generics::image::{CompatMode, ColorStop as GenericColorStop, EndingShape as GenericEndingShape}; -use values::generics::image::{Gradient as GenericGradient, GradientItem as GenericGradientItem}; -use values::generics::image::{Image as GenericImage, GradientKind as GenericGradientKind}; -use values::generics::image::{LineDirection as GenericLineDirection, MozImageRect as GenericMozImageRect}; +use values::generics::image::{self as generic, CompatMode}; use values::specified::image::LineDirection as SpecifiedLineDirection; use values::specified::position::{X, Y}; @@ -30,11 +27,11 @@ pub type ImageLayer = Either; /// Computed values for an image according to CSS-IMAGES. /// -pub type Image = GenericImage; +pub type Image = generic::Image; /// Computed values for a CSS gradient. /// -pub type Gradient = GenericGradient< +pub type Gradient = generic::Gradient< LineDirection, Length, LengthOrPercentage, @@ -44,7 +41,7 @@ pub type Gradient = GenericGradient< >; /// A computed gradient kind. -pub type GradientKind = GenericGradientKind< +pub type GradientKind = generic::GradientKind< LineDirection, Length, LengthOrPercentage, @@ -69,18 +66,18 @@ pub enum LineDirection { } /// A computed radial gradient ending shape. -pub type EndingShape = GenericEndingShape; +pub type EndingShape = generic::EndingShape; /// A computed gradient item. -pub type GradientItem = GenericGradientItem; +pub type GradientItem = generic::GradientItem; /// A computed color stop. -pub type ColorStop = GenericColorStop; +pub type ColorStop = generic::ColorStop; /// Computed values for `-moz-image-rect(...)`. -pub type MozImageRect = GenericMozImageRect; +pub type MozImageRect = generic::MozImageRect; -impl GenericLineDirection for LineDirection { +impl generic::LineDirection for LineDirection { fn points_downwards(&self, compat_mode: CompatMode) -> bool { match *self { LineDirection::Angle(angle) => angle.radians() == PI, diff --git a/components/style/values/computed/text.rs b/components/style/values/computed/text.rs index 597fbbd588de..1af6cdd3a78e 100644 --- a/components/style/values/computed/text.rs +++ b/components/style/values/computed/text.rs @@ -15,7 +15,8 @@ use values::generics::text::InitialLetter as GenericInitialLetter; use values::generics::text::LineHeight as GenericLineHeight; use values::generics::text::MozTabSize as GenericMozTabSize; use values::generics::text::Spacing; -use values::specified::text::{TextDecorationLine, TextEmphasisFillMode, TextEmphasisShapeKeyword, TextOverflowSide}; +use values::specified::text::{TextDecorationLine, TextEmphasisFillMode}; +use values::specified::text::{TextEmphasisShapeKeyword, TextOverflowSide}; pub use values::specified::TextAlignKeyword as TextAlign; pub use values::specified::TextEmphasisPosition; diff --git a/components/style/values/computed/transform.rs b/components/style/values/computed/transform.rs index a320224d4e0f..13ae19d7824d 100644 --- a/components/style/values/computed/transform.rs +++ b/components/style/values/computed/transform.rs @@ -9,18 +9,12 @@ use num_traits::Zero; use super::CSSFloat; use values::animated::ToAnimatedZero; use values::computed::{Angle, Integer, Length, LengthOrPercentage, Number, Percentage}; -use values::generics::transform::{self, Matrix as GenericMatrix, Matrix3D as GenericMatrix3D}; -use values::generics::transform::{Transform as GenericTransform, TransformOperation as GenericTransformOperation}; -use values::generics::transform::Rotate as GenericRotate; -use values::generics::transform::Scale as GenericScale; -use values::generics::transform::TimingFunction as GenericTimingFunction; -use values::generics::transform::TransformOrigin as GenericTransformOrigin; -use values::generics::transform::Translate as GenericTranslate; +use values::generics::transform as generic; pub use values::generics::transform::TransformStyle; /// A single operation in a computed CSS `transform` -pub type TransformOperation = GenericTransformOperation< +pub type TransformOperation = generic::TransformOperation< Angle, Number, Length, @@ -28,13 +22,13 @@ pub type TransformOperation = GenericTransformOperation< LengthOrPercentage, >; /// A computed CSS `transform` -pub type Transform = GenericTransform; +pub type Transform = generic::Transform; /// The computed value of a CSS `` -pub type TransformOrigin = GenericTransformOrigin; +pub type TransformOrigin = generic::TransformOrigin; /// A computed timing function. -pub type TimingFunction = GenericTimingFunction; +pub type TimingFunction = generic::TimingFunction; /// A vector to represent the direction vector (rotate axis) for Rotate3D. pub type DirectionVector = Vector3D; @@ -52,9 +46,9 @@ impl TransformOrigin { } /// computed value of matrix3d() -pub type Matrix3D = GenericMatrix3D; +pub type Matrix3D = generic::Matrix3D; /// computed value of matrix() -pub type Matrix = GenericMatrix; +pub type Matrix = generic::Matrix; // we rustfmt_skip here because we want the matrices to look like // matrices instead of being split across lines @@ -133,19 +127,19 @@ impl TransformOperation { /// Must be called on a Translate function pub fn to_translate_3d(&self) -> Self { match *self { - GenericTransformOperation::Translate3D(..) => self.clone(), - GenericTransformOperation::TranslateX(ref x) | - GenericTransformOperation::Translate(ref x, None) => { - GenericTransformOperation::Translate3D(x.clone(), LengthOrPercentage::zero(), Length::zero()) + generic::TransformOperation::Translate3D(..) => self.clone(), + generic::TransformOperation::TranslateX(ref x) | + generic::TransformOperation::Translate(ref x, None) => { + generic::TransformOperation::Translate3D(x.clone(), LengthOrPercentage::zero(), Length::zero()) }, - GenericTransformOperation::Translate(ref x, Some(ref y)) => { - GenericTransformOperation::Translate3D(x.clone(), y.clone(), Length::zero()) + generic::TransformOperation::Translate(ref x, Some(ref y)) => { + generic::TransformOperation::Translate3D(x.clone(), y.clone(), Length::zero()) }, - GenericTransformOperation::TranslateY(ref y) => { - GenericTransformOperation::Translate3D(LengthOrPercentage::zero(), y.clone(), Length::zero()) + generic::TransformOperation::TranslateY(ref y) => { + generic::TransformOperation::Translate3D(LengthOrPercentage::zero(), y.clone(), Length::zero()) }, - GenericTransformOperation::TranslateZ(ref z) => { - GenericTransformOperation::Translate3D( + generic::TransformOperation::TranslateZ(ref z) => { + generic::TransformOperation::Translate3D( LengthOrPercentage::zero(), LengthOrPercentage::zero(), z.clone(), @@ -159,12 +153,12 @@ impl TransformOperation { /// Must be called on a Scale function pub fn to_scale_3d(&self) -> Self { match *self { - GenericTransformOperation::Scale3D(..) => self.clone(), - GenericTransformOperation::Scale(s, None) => GenericTransformOperation::Scale3D(s, s, 1.), - GenericTransformOperation::Scale(x, Some(y)) => GenericTransformOperation::Scale3D(x, y, 1.), - GenericTransformOperation::ScaleX(x) => GenericTransformOperation::Scale3D(x, 1., 1.), - GenericTransformOperation::ScaleY(y) => GenericTransformOperation::Scale3D(1., y, 1.), - GenericTransformOperation::ScaleZ(z) => GenericTransformOperation::Scale3D(1., 1., z), + generic::TransformOperation::Scale3D(..) => self.clone(), + generic::TransformOperation::Scale(s, None) => generic::TransformOperation::Scale3D(s, s, 1.), + generic::TransformOperation::Scale(x, Some(y)) => generic::TransformOperation::Scale3D(x, y, 1.), + generic::TransformOperation::ScaleX(x) => generic::TransformOperation::Scale3D(x, 1., 1.), + generic::TransformOperation::ScaleY(y) => generic::TransformOperation::Scale3D(1., y, 1.), + generic::TransformOperation::ScaleZ(z) => generic::TransformOperation::Scale3D(1., 1., z), _ => unreachable!(), } } @@ -176,56 +170,58 @@ impl TransformOperation { impl ToAnimatedZero for TransformOperation { fn to_animated_zero(&self) -> Result { match *self { - GenericTransformOperation::Matrix3D(..) => Ok(GenericTransformOperation::Matrix3D(Matrix3D::identity())), - GenericTransformOperation::Matrix(..) => Ok(GenericTransformOperation::Matrix(Matrix::identity())), - GenericTransformOperation::Skew(sx, sy) => { - Ok(GenericTransformOperation::Skew( + generic::TransformOperation::Matrix3D(..) => + Ok(generic::TransformOperation::Matrix3D(Matrix3D::identity())), + generic::TransformOperation::Matrix(..) => + Ok(generic::TransformOperation::Matrix(Matrix::identity())), + generic::TransformOperation::Skew(sx, sy) => { + Ok(generic::TransformOperation::Skew( sx.to_animated_zero()?, sy.to_animated_zero()?, )) }, - GenericTransformOperation::SkewX(s) => Ok(GenericTransformOperation::SkewX(s.to_animated_zero()?)), - GenericTransformOperation::SkewY(s) => Ok(GenericTransformOperation::SkewY(s.to_animated_zero()?)), - GenericTransformOperation::Translate3D(ref tx, ref ty, ref tz) => { - Ok(GenericTransformOperation::Translate3D( + generic::TransformOperation::SkewX(s) => Ok(generic::TransformOperation::SkewX(s.to_animated_zero()?)), + generic::TransformOperation::SkewY(s) => Ok(generic::TransformOperation::SkewY(s.to_animated_zero()?)), + generic::TransformOperation::Translate3D(ref tx, ref ty, ref tz) => { + Ok(generic::TransformOperation::Translate3D( tx.to_animated_zero()?, ty.to_animated_zero()?, tz.to_animated_zero()?, )) }, - GenericTransformOperation::Translate(ref tx, ref ty) => { - Ok(GenericTransformOperation::Translate( + generic::TransformOperation::Translate(ref tx, ref ty) => { + Ok(generic::TransformOperation::Translate( tx.to_animated_zero()?, ty.to_animated_zero()?, )) }, - GenericTransformOperation::TranslateX(ref t) => { - Ok(GenericTransformOperation::TranslateX(t.to_animated_zero()?)) + generic::TransformOperation::TranslateX(ref t) => { + Ok(generic::TransformOperation::TranslateX(t.to_animated_zero()?)) }, - GenericTransformOperation::TranslateY(ref t) => { - Ok(GenericTransformOperation::TranslateY(t.to_animated_zero()?)) + generic::TransformOperation::TranslateY(ref t) => { + Ok(generic::TransformOperation::TranslateY(t.to_animated_zero()?)) }, - GenericTransformOperation::TranslateZ(ref t) => { - Ok(GenericTransformOperation::TranslateZ(t.to_animated_zero()?)) + generic::TransformOperation::TranslateZ(ref t) => { + Ok(generic::TransformOperation::TranslateZ(t.to_animated_zero()?)) }, - GenericTransformOperation::Scale3D(..) => Ok(GenericTransformOperation::Scale3D(1.0, 1.0, 1.0)), - GenericTransformOperation::Scale(_, _) => Ok(GenericTransformOperation::Scale(1.0, Some(1.0))), - GenericTransformOperation::ScaleX(..) => Ok(GenericTransformOperation::ScaleX(1.0)), - GenericTransformOperation::ScaleY(..) => Ok(GenericTransformOperation::ScaleY(1.0)), - GenericTransformOperation::ScaleZ(..) => Ok(GenericTransformOperation::ScaleZ(1.0)), - GenericTransformOperation::Rotate3D(x, y, z, a) => { - let (x, y, z, _) = transform::get_normalized_vector_and_angle(x, y, z, a); - Ok(GenericTransformOperation::Rotate3D(x, y, z, Angle::zero())) + generic::TransformOperation::Scale3D(..) => Ok(generic::TransformOperation::Scale3D(1.0, 1.0, 1.0)), + generic::TransformOperation::Scale(_, _) => Ok(generic::TransformOperation::Scale(1.0, Some(1.0))), + generic::TransformOperation::ScaleX(..) => Ok(generic::TransformOperation::ScaleX(1.0)), + generic::TransformOperation::ScaleY(..) => Ok(generic::TransformOperation::ScaleY(1.0)), + generic::TransformOperation::ScaleZ(..) => Ok(generic::TransformOperation::ScaleZ(1.0)), + generic::TransformOperation::Rotate3D(x, y, z, a) => { + let (x, y, z, _) = generic::get_normalized_vector_and_angle(x, y, z, a); + Ok(generic::TransformOperation::Rotate3D(x, y, z, Angle::zero())) }, - GenericTransformOperation::RotateX(_) => Ok(GenericTransformOperation::RotateX(Angle::zero())), - GenericTransformOperation::RotateY(_) => Ok(GenericTransformOperation::RotateY(Angle::zero())), - GenericTransformOperation::RotateZ(_) => Ok(GenericTransformOperation::RotateZ(Angle::zero())), - GenericTransformOperation::Rotate(_) => Ok(GenericTransformOperation::Rotate(Angle::zero())), - GenericTransformOperation::Perspective(..) | - GenericTransformOperation::AccumulateMatrix { + generic::TransformOperation::RotateX(_) => Ok(generic::TransformOperation::RotateX(Angle::zero())), + generic::TransformOperation::RotateY(_) => Ok(generic::TransformOperation::RotateY(Angle::zero())), + generic::TransformOperation::RotateZ(_) => Ok(generic::TransformOperation::RotateZ(Angle::zero())), + generic::TransformOperation::Rotate(_) => Ok(generic::TransformOperation::Rotate(Angle::zero())), + generic::TransformOperation::Perspective(..) | + generic::TransformOperation::AccumulateMatrix { .. } | - GenericTransformOperation::InterpolateMatrix { + generic::TransformOperation::InterpolateMatrix { .. } => { // Perspective: We convert a perspective function into an equivalent @@ -236,7 +232,7 @@ impl ToAnimatedZero for TransformOperation { // // Therefore, we use an identity matrix to represent the identity transform list. // http://dev.w3.org/csswg/css-transforms/#identity-transform-function - Ok(GenericTransformOperation::Matrix3D(Matrix3D::identity())) + Ok(generic::TransformOperation::Matrix3D(Matrix3D::identity())) }, } } @@ -246,7 +242,7 @@ impl ToAnimatedZero for TransformOperation { impl ToAnimatedZero for Transform { #[inline] fn to_animated_zero(&self) -> Result { - Ok(GenericTransform(self.0 + Ok(generic::Transform(self.0 .iter() .map(|op| op.to_animated_zero()) .collect::, _>>()?)) @@ -254,74 +250,75 @@ impl ToAnimatedZero for Transform { } /// A computed CSS `rotate` -pub type Rotate = GenericRotate; +pub type Rotate = generic::Rotate; impl Rotate { /// Convert TransformOperation to Rotate. pub fn to_transform_operation(&self) -> Option { match *self { - GenericRotate::None => None, - GenericRotate::Rotate(angle) => Some(GenericTransformOperation::Rotate(angle)), - GenericRotate::Rotate3D(rx, ry, rz, angle) => Some(GenericTransformOperation::Rotate3D(rx, ry, rz, angle)), + generic::Rotate::None => None, + generic::Rotate::Rotate(angle) => Some(generic::TransformOperation::Rotate(angle)), + generic::Rotate::Rotate3D(rx, ry, rz, angle) => + Some(generic::TransformOperation::Rotate3D(rx, ry, rz, angle)), } } /// Convert Rotate to TransformOperation. pub fn from_transform_operation(operation: &TransformOperation) -> Rotate { match *operation { - GenericTransformOperation::Rotate(angle) => GenericRotate::Rotate(angle), - GenericTransformOperation::Rotate3D(rx, ry, rz, angle) => - GenericRotate::Rotate3D(rx, ry, rz, angle), + generic::TransformOperation::Rotate(angle) => generic::Rotate::Rotate(angle), + generic::TransformOperation::Rotate3D(rx, ry, rz, angle) => + generic::Rotate::Rotate3D(rx, ry, rz, angle), _ => unreachable!("Found unexpected value for rotate property"), } } } /// A computed CSS `translate` -pub type Translate = GenericTranslate; +pub type Translate = generic::Translate; impl Translate { /// Convert TransformOperation to Translate. pub fn to_transform_operation(&self) -> Option { match *self { - GenericTranslate::None => None, - GenericTranslate::TranslateX(tx) => Some(GenericTransformOperation::TranslateX(tx)), - GenericTranslate::Translate(tx, ty) => Some(GenericTransformOperation::Translate(tx, Some(ty))), - GenericTranslate::Translate3D(tx, ty, tz) => Some(GenericTransformOperation::Translate3D(tx, ty, tz)), + generic::Translate::None => None, + generic::Translate::TranslateX(tx) => Some(generic::TransformOperation::TranslateX(tx)), + generic::Translate::Translate(tx, ty) => Some(generic::TransformOperation::Translate(tx, Some(ty))), + generic::Translate::Translate3D(tx, ty, tz) => Some(generic::TransformOperation::Translate3D(tx, ty, tz)), } } /// Convert Translate to TransformOperation. pub fn from_transform_operation(operation: &TransformOperation) -> Translate { match *operation { - GenericTransformOperation::TranslateX(tx) => GenericTranslate::TranslateX(tx), - GenericTransformOperation::Translate(tx, Some(ty)) => GenericTranslate::Translate(tx, ty), - GenericTransformOperation::Translate3D(tx, ty, tz) => GenericTranslate::Translate3D(tx, ty, tz), + generic::TransformOperation::TranslateX(tx) => generic::Translate::TranslateX(tx), + generic::TransformOperation::Translate(tx, Some(ty)) => generic::Translate::Translate(tx, ty), + generic::TransformOperation::Translate3D(tx, ty, tz) => generic::Translate::Translate3D(tx, ty, tz), _ => unreachable!("Found unexpected value for translate"), } } } /// A computed CSS `scale` -pub type Scale = GenericScale; +pub type Scale = generic::Scale; impl Scale { /// Convert TransformOperation to Scale. pub fn to_transform_operation(&self) -> Option { match *self { - GenericScale::None => None, - GenericScale::ScaleX(sx) => Some(GenericTransformOperation::ScaleX(sx)), - GenericScale::Scale(sx, sy) => Some(GenericTransformOperation::Scale(sx, Some(sy))), - GenericScale::Scale3D(sx, sy, sz) => Some(GenericTransformOperation::Scale3D(sx, sy, sz)), + generic::Scale::None => None, + generic::Scale::ScaleX(sx) => Some(generic::TransformOperation::ScaleX(sx)), + generic::Scale::Scale(sx, sy) => Some(generic::TransformOperation::Scale(sx, Some(sy))), + generic::Scale::Scale3D(sx, sy, sz) => Some(generic::TransformOperation::Scale3D(sx, sy, sz)), } } /// Convert Scale to TransformOperation. pub fn from_transform_operation(operation: &TransformOperation) -> Scale { match *operation { - GenericTransformOperation::ScaleX(sx) => GenericScale::ScaleX(sx), - GenericTransformOperation::Scale(sx, Some(sy)) => GenericScale::Scale(sx, sy), - GenericTransformOperation::Scale3D(sx, sy, sz) => GenericScale::Scale3D(sx, sy, sz), + generic::TransformOperation::ScaleX(sx) => generic::Scale::ScaleX(sx), + generic::TransformOperation::Scale(sx, Some(sy)) => generic::Scale::Scale(sx, sy), + generic::TransformOperation::Scale3D(sx, sy, sz) => generic::Scale::Scale3D(sx, sy, sz), _ => unreachable!("Found unexpected value for scale"), } } diff --git a/components/style/values/generics/basic_shape.rs b/components/style/values/generics/basic_shape.rs index 8c798b468ae9..96756772a9f6 100644 --- a/components/style/values/generics/basic_shape.rs +++ b/components/style/values/generics/basic_shape.rs @@ -210,10 +210,9 @@ where return Err(()); } self.coordinates.iter().zip(other.coordinates.iter()).map(|(this, other)| { - Ok( - this.0.compute_squared_distance(&other.0)? + - this.1.compute_squared_distance(&other.1)?, - ) + let d1 = this.0.compute_squared_distance(&other.0)?; + let d2 = this.1.compute_squared_distance(&other.1)?; + Ok(d1 + d2) }).sum() } } diff --git a/components/style/values/generics/transform.rs b/components/style/values/generics/transform.rs index b80bc8b14f45..8dd2238a1a11 100644 --- a/components/style/values/generics/transform.rs +++ b/components/style/values/generics/transform.rs @@ -586,8 +586,8 @@ pub fn get_normalized_vector_and_angle( } } -#[derive(Clone, ComputeSquaredDistance, Copy, Debug, MallocSizeOf, PartialEq)] -#[derive(ToAnimatedZero, ToComputedValue, ToCss)] +#[derive(Clone, ComputeSquaredDistance, Copy, Debug, MallocSizeOf)] +#[derive(PartialEq, ToAnimatedZero, ToComputedValue, ToCss)] /// A value of the `Rotate` property /// /// @@ -616,8 +616,8 @@ pub enum Scale { Scale3D(Number, Number, Number), } -#[derive(ComputeSquaredDistance, ToAnimatedZero, ToComputedValue)] -#[derive(Clone, Debug, MallocSizeOf, PartialEq, ToCss)] +#[derive(Clone, ComputeSquaredDistance, Debug, MallocSizeOf, PartialEq)] +#[derive(ToAnimatedZero, ToComputedValue, ToCss)] /// A value of the `Translate` property /// /// diff --git a/components/style/values/specified/basic_shape.rs b/components/style/values/specified/basic_shape.rs index 6830c3a6b1aa..e0fa3322a372 100644 --- a/components/style/values/specified/basic_shape.rs +++ b/components/style/values/specified/basic_shape.rs @@ -13,42 +13,39 @@ use std::borrow::Cow; use std::fmt::{self, Write}; use style_traits::{CssWriter, ParseError, StyleParseErrorKind, ToCss}; use values::computed::Percentage; -use values::generics::basic_shape::{Circle as GenericCircle}; -use values::generics::basic_shape::{ClippingShape as GenericClippingShape, Ellipse as GenericEllipse}; -use values::generics::basic_shape::{FillRule, BasicShape as GenericBasicShape}; -use values::generics::basic_shape::{FloatAreaShape as GenericFloatAreaShape, InsetRect as GenericInsetRect}; -use values::generics::basic_shape::{GeometryBox, ShapeBox, ShapeSource}; -use values::generics::basic_shape::{Polygon as GenericPolygon, ShapeRadius as GenericShapeRadius}; +use values::generics::basic_shape as generic; +use values::generics::basic_shape::{FillRule, GeometryBox, ShapeBox, ShapeSource}; use values::generics::rect::Rect; use values::specified::LengthOrPercentage; use values::specified::border::BorderRadius; use values::specified::image::Image; -use values::specified::position::{HorizontalPosition, Position, PositionComponent, Side, VerticalPosition}; +use values::specified::position::{HorizontalPosition, Position, PositionComponent}; +use values::specified::position::{Side, VerticalPosition}; use values::specified::url::SpecifiedUrl; /// A specified clipping shape. -pub type ClippingShape = GenericClippingShape; +pub type ClippingShape = generic::ClippingShape; /// A specified float area shape. -pub type FloatAreaShape = GenericFloatAreaShape; +pub type FloatAreaShape = generic::FloatAreaShape; /// A specified basic shape. -pub type BasicShape = GenericBasicShape; +pub type BasicShape = generic::BasicShape; /// The specified value of `inset()` -pub type InsetRect = GenericInsetRect; +pub type InsetRect = generic::InsetRect; /// A specified circle. -pub type Circle = GenericCircle; +pub type Circle = generic::Circle; /// A specified ellipse. -pub type Ellipse = GenericEllipse; +pub type Ellipse = generic::Ellipse; /// The specified value of `ShapeRadius` -pub type ShapeRadius = GenericShapeRadius; +pub type ShapeRadius = generic::ShapeRadius; /// The specified value of `Polygon` -pub type Polygon = GenericPolygon; +pub type Polygon = generic::Polygon; impl Parse for ShapeSource where @@ -110,10 +107,10 @@ impl Parse for BasicShape { let function = input.expect_function()?.clone(); input.parse_nested_block(move |i| { (match_ignore_ascii_case! { &function, - "inset" => return InsetRect::parse_function_arguments(context, i).map(GenericBasicShape::Inset), - "circle" => return Circle::parse_function_arguments(context, i).map(GenericBasicShape::Circle), - "ellipse" => return Ellipse::parse_function_arguments(context, i).map(GenericBasicShape::Ellipse), - "polygon" => return Polygon::parse_function_arguments(context, i).map(GenericBasicShape::Polygon), + "inset" => return InsetRect::parse_function_arguments(context, i).map(generic::BasicShape::Inset), + "circle" => return Circle::parse_function_arguments(context, i).map(generic::BasicShape::Circle), + "ellipse" => return Ellipse::parse_function_arguments(context, i).map(generic::BasicShape::Ellipse), + "polygon" => return Polygon::parse_function_arguments(context, i).map(generic::BasicShape::Polygon), _ => Err(()) }).map_err(|()| location.new_custom_error(StyleParseErrorKind::UnexpectedFunction(function.clone()))) }) @@ -139,7 +136,7 @@ impl InsetRect { } else { None }; - Ok(GenericInsetRect { + Ok(generic::InsetRect { rect: rect, round: round, }) @@ -166,7 +163,7 @@ impl Circle { Position::center() }; - Ok(GenericCircle { radius, position }) + Ok(generic::Circle { radius, position }) } } @@ -176,7 +173,7 @@ impl ToCss for Circle { W: Write, { dest.write_str("circle(")?; - if GenericShapeRadius::ClosestSide != self.radius { + if generic::ShapeRadius::ClosestSide != self.radius { self.radius.to_css(dest)?; dest.write_str(" ")?; } @@ -208,7 +205,7 @@ impl Ellipse { Position::center() }; - Ok(GenericEllipse { + Ok(generic::Ellipse { semiaxis_x: a, semiaxis_y: b, position: position, @@ -239,12 +236,12 @@ impl Parse for ShapeRadius { fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result> { if let Ok(lop) = input.try(|i| LengthOrPercentage::parse_non_negative(context, i)) { - return Ok(GenericShapeRadius::Length(lop)) + return Ok(generic::ShapeRadius::Length(lop)) } try_match_ident_ignore_ascii_case! { input, - "closest-side" => Ok(GenericShapeRadius::ClosestSide), - "farthest-side" => Ok(GenericShapeRadius::FarthestSide), + "closest-side" => Ok(generic::ShapeRadius::ClosestSide), + "farthest-side" => Ok(generic::ShapeRadius::FarthestSide), } } } diff --git a/components/style/values/specified/grid.rs b/components/style/values/specified/grid.rs index 5f85499087da..f13140ed4d2f 100644 --- a/components/style/values/specified/grid.rs +++ b/components/style/values/specified/grid.rs @@ -11,8 +11,9 @@ use std::mem; use style_traits::{ParseError, StyleParseErrorKind}; use values::{CSSFloat, CustomIdent}; use values::computed::{self, Context, ToComputedValue}; -use values::generics::grid::{GridTemplateComponent, RepeatCount, TrackBreadth, TrackKeyword, TrackRepeat}; -use values::generics::grid::{LineNameList, TrackSize, TrackList, TrackListType, TrackListValue}; +use values::generics::grid::{GridTemplateComponent, RepeatCount, TrackBreadth}; +use values::generics::grid::{TrackKeyword, TrackRepeat, LineNameList, TrackSize}; +use values::generics::grid::{TrackList, TrackListType, TrackListValue}; use values::specified::{LengthOrPercentage, Integer}; /// Parse a single flexible length. @@ -175,7 +176,8 @@ impl Parse for TrackList { let mut names = vec![]; let mut values = vec![]; - let mut list_type = TrackListType::Explicit; // assume it's the simplest case + // assume it's the simplest case. + let mut list_type = TrackListType::Explicit; // holds value. It can only be only one in a TrackList. let mut auto_repeat = None; // if there is any the list will be of type TrackListType::Auto(idx) diff --git a/components/style/values/specified/image.rs b/components/style/values/specified/image.rs index 9bf565ac6352..d959f27262b2 100644 --- a/components/style/values/specified/image.rs +++ b/components/style/values/specified/image.rs @@ -21,11 +21,7 @@ use style_traits::{CssWriter, ParseError, StyleParseErrorKind, ToCss}; use values::{Either, None_}; #[cfg(feature = "gecko")] use values::computed::{Context, Position as ComputedPosition, ToComputedValue}; -use values::generics::image::{Circle, CompatMode, Ellipse, ColorStop as GenericColorStop}; -use values::generics::image::{EndingShape as GenericEndingShape, Gradient as GenericGradient}; -use values::generics::image::{GradientItem as GenericGradientItem, GradientKind as GenericGradientKind}; -use values::generics::image::{Image as GenericImage, LineDirection as GenericsLineDirection}; -use values::generics::image::{MozImageRect as GenericMozImageRect, ShapeExtent}; +use values::generics::image::{self as generic, Circle, CompatMode, Ellipse, ShapeExtent}; use values::generics::image::PaintWorklet; use values::generics::position::Position as GenericPosition; use values::specified::{Angle, Color, Length, LengthOrPercentage}; @@ -38,12 +34,12 @@ pub type ImageLayer = Either; /// Specified values for an image according to CSS-IMAGES. /// -pub type Image = GenericImage; +pub type Image = generic::Image; /// Specified values for a CSS gradient. /// #[cfg(not(feature = "gecko"))] -pub type Gradient = GenericGradient< +pub type Gradient = generic::Gradient< LineDirection, Length, LengthOrPercentage, @@ -55,7 +51,7 @@ pub type Gradient = GenericGradient< /// Specified values for a CSS gradient. /// #[cfg(feature = "gecko")] -pub type Gradient = GenericGradient< +pub type Gradient = generic::Gradient< LineDirection, Length, LengthOrPercentage, @@ -66,7 +62,7 @@ pub type Gradient = GenericGradient< /// A specified gradient kind. #[cfg(not(feature = "gecko"))] -pub type GradientKind = GenericGradientKind< +pub type GradientKind = generic::GradientKind< LineDirection, Length, LengthOrPercentage, @@ -76,7 +72,7 @@ pub type GradientKind = GenericGradientKind< /// A specified gradient kind. #[cfg(feature = "gecko")] -pub type GradientKind = GenericGradientKind< +pub type GradientKind = generic::GradientKind< LineDirection, Length, LengthOrPercentage, @@ -114,36 +110,36 @@ pub enum GradientPosition { } /// A specified ending shape. -pub type EndingShape = GenericEndingShape; +pub type EndingShape = generic::EndingShape; /// A specified gradient item. -pub type GradientItem = GenericGradientItem; +pub type GradientItem = generic::GradientItem; /// A computed color stop. -pub type ColorStop = GenericColorStop; +pub type ColorStop = generic::ColorStop; /// Specified values for `moz-image-rect` /// -moz-image-rect(, top, right, bottom, left); -pub type MozImageRect = GenericMozImageRect; +pub type MozImageRect = generic::MozImageRect; impl Parse for Image { fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result> { if let Ok(url) = input.try(|input| SpecifiedImageUrl::parse(context, input)) { - return Ok(GenericImage::Url(url)); + return Ok(generic::Image::Url(url)); } if let Ok(gradient) = input.try(|i| Gradient::parse(context, i)) { - return Ok(GenericImage::Gradient(Box::new(gradient))); + return Ok(generic::Image::Gradient(Box::new(gradient))); } #[cfg(feature = "servo")] { if let Ok(paint_worklet) = input.try(|i| PaintWorklet::parse(context, i)) { - return Ok(GenericImage::PaintWorklet(paint_worklet)); + return Ok(generic::Image::PaintWorklet(paint_worklet)); } } if let Ok(image_rect) = input.try(|input| MozImageRect::parse(context, input)) { - return Ok(GenericImage::Rect(Box::new(image_rect))); + return Ok(generic::Image::Rect(Box::new(image_rect))); } - Ok(GenericImage::Element(Image::parse_element(input)?)) + Ok(generic::Image::Element(Image::parse_element(input)?)) } } @@ -153,7 +149,7 @@ impl Image { #[cfg(feature = "servo")] pub fn for_cascade(url: ServoUrl) -> Self { use values::CssUrl; - GenericImage::Url(CssUrl::for_cascade(url)) + generic::Image::Url(CssUrl::for_cascade(url)) } /// Parses a `-moz-element(# )`. @@ -220,7 +216,9 @@ impl Parse for Gradient { Some((Shape::Radial, true, CompatMode::Moz)) }, "-webkit-gradient" => { - return input.parse_nested_block(|i| Self::parse_webkit_gradient_argument(context, i)); + return input.parse_nested_block(|i| { + Self::parse_webkit_gradient_argument(context, i) + }); }, _ => None, }; @@ -406,7 +404,7 @@ impl Gradient { let second = Point::parse(context, input)?; let direction = LineDirection::from_points(first, second); - let kind = GenericGradientKind::Linear(direction); + let kind = generic::GradientKind::Linear(direction); (kind, false) }, @@ -425,22 +423,27 @@ impl Gradient { (true, first_point, first_radius) }; - let shape = GenericEndingShape::Circle(Circle::Radius(Length::from_px(radius.value))); + let rad = Circle::Radius(Length::from_px(radius.value)); + let shape = generic::EndingShape::Circle(rad); let position: Position = point.into(); #[cfg(feature = "gecko")] { - let kind = GenericGradientKind::Radial(shape, GradientPosition::Modern(position), None); + let pos = GradientPosition::Modern(position); + let kind = generic::GradientKind::Radial(shape, pos, None); (kind, reverse_stops) } #[cfg(not(feature = "gecko"))] { - let kind = GenericGradientKind::Radial(shape, position, None); + let kind = generic::GradientKind::Radial(shape, position, None); (kind, reverse_stops) } }, - _ => return Err(input.new_custom_error(SelectorParseErrorKind::UnexpectedIdent(ident.clone()))), + _ => { + let e = SelectorParseErrorKind::UnexpectedIdent(ident.clone()); + return Err(input.new_custom_error(e)); + }, }; let mut items = input.try(|i| { @@ -459,7 +462,11 @@ impl Gradient { }, "from" => Percentage::zero(), "to" => Percentage::hundred(), - _ => return Err(i.new_custom_error(StyleParseErrorKind::UnexpectedFunction(function.clone()))), + _ => { + return Err(i.new_custom_error( + StyleParseErrorKind::UnexpectedFunction(function.clone()) + )) + }, }; let color = Color::parse(context, i)?; if color == Color::CurrentColor { @@ -470,7 +477,7 @@ impl Gradient { if reverse_stops { p.reverse(); } - Ok(GenericGradientItem::ColorStop(GenericColorStop { + Ok(generic::GradientItem::ColorStop(generic::ColorStop { color: color, position: Some(p.into()), })) @@ -479,11 +486,11 @@ impl Gradient { if items.is_empty() { items = vec![ - GenericGradientItem::ColorStop(GenericColorStop { + generic::GradientItem::ColorStop(generic::ColorStop { color: Color::transparent().into(), position: Some(Percentage::zero().into()), }), - GenericGradientItem::ColorStop(GenericColorStop { + generic::GradientItem::ColorStop(generic::ColorStop { color: Color::transparent().into(), position: Some(Percentage::hundred().into()), }), @@ -494,7 +501,7 @@ impl Gradient { } else { items.sort_by(|a, b| { match (a, b) { - (&GenericGradientItem::ColorStop(ref a), &GenericGradientItem::ColorStop(ref b)) => { + (&generic::GradientItem::ColorStop(ref a), &generic::GradientItem::ColorStop(ref b)) => { match (&a.position, &b.position) { (&Some(LengthOrPercentage::Percentage(a)), &Some(LengthOrPercentage::Percentage(b))) => { return a.0.partial_cmp(&b.0).unwrap_or(Ordering::Equal); @@ -512,7 +519,7 @@ impl Gradient { }) } - Ok(GenericGradient { + Ok(generic::Gradient { kind: kind, items: items, repeating: false, @@ -538,7 +545,7 @@ impl GradientKind { _ => LineDirection::Vertical(Y::Top), } }; - Ok(GenericGradientKind::Linear(direction)) + Ok(generic::GradientKind::Linear(direction)) } fn parse_radial<'i, 't>( @@ -598,7 +605,7 @@ impl GradientKind { } let shape = shape.unwrap_or({ - GenericEndingShape::Ellipse(Ellipse::Extent(ShapeExtent::FarthestCorner)) + generic::EndingShape::Ellipse(Ellipse::Extent(ShapeExtent::FarthestCorner)) }); #[cfg(feature = "gecko")] @@ -609,23 +616,23 @@ impl GradientKind { *compat_mode = CompatMode::Modern; } let position = moz_position.unwrap_or(LegacyPosition::center()); - return Ok(GenericGradientKind::Radial(shape, GradientPosition::Legacy(position), angle)); + return Ok(generic::GradientKind::Radial(shape, GradientPosition::Legacy(position), angle)); } } let position = position.unwrap_or(Position::center()); #[cfg(feature = "gecko")] { - return Ok(GenericGradientKind::Radial(shape, GradientPosition::Modern(position), angle)); + return Ok(generic::GradientKind::Radial(shape, GradientPosition::Modern(position), angle)); } #[cfg(not(feature = "gecko"))] { - return Ok(GenericGradientKind::Radial(shape, position, angle)); + return Ok(generic::GradientKind::Radial(shape, position, angle)); } } } -impl GenericsLineDirection for LineDirection { +impl generic::LineDirection for LineDirection { fn points_downwards(&self, compat_mode: CompatMode) -> bool { match *self { LineDirection::Angle(ref angle) => angle.radians() == PI, @@ -803,25 +810,25 @@ impl EndingShape { ) -> Result> { if let Ok(extent) = input.try(|i| ShapeExtent::parse_with_compat_mode(i, compat_mode)) { if input.try(|i| i.expect_ident_matching("circle")).is_ok() { - return Ok(GenericEndingShape::Circle(Circle::Extent(extent))); + return Ok(generic::EndingShape::Circle(Circle::Extent(extent))); } let _ = input.try(|i| i.expect_ident_matching("ellipse")); - return Ok(GenericEndingShape::Ellipse(Ellipse::Extent(extent))); + return Ok(generic::EndingShape::Ellipse(Ellipse::Extent(extent))); } if input.try(|i| i.expect_ident_matching("circle")).is_ok() { if let Ok(extent) = input.try(|i| ShapeExtent::parse_with_compat_mode(i, compat_mode)) { - return Ok(GenericEndingShape::Circle(Circle::Extent(extent))); + return Ok(generic::EndingShape::Circle(Circle::Extent(extent))); } if compat_mode == CompatMode::Modern { if let Ok(length) = input.try(|i| Length::parse(context, i)) { - return Ok(GenericEndingShape::Circle(Circle::Radius(length))); + return Ok(generic::EndingShape::Circle(Circle::Radius(length))); } } - return Ok(GenericEndingShape::Circle(Circle::Extent(ShapeExtent::FarthestCorner))); + return Ok(generic::EndingShape::Circle(Circle::Extent(ShapeExtent::FarthestCorner))); } if input.try(|i| i.expect_ident_matching("ellipse")).is_ok() { if let Ok(extent) = input.try(|i| ShapeExtent::parse_with_compat_mode(i, compat_mode)) { - return Ok(GenericEndingShape::Ellipse(Ellipse::Extent(extent))); + return Ok(generic::EndingShape::Ellipse(Ellipse::Extent(extent))); } if compat_mode == CompatMode::Modern { let pair: Result<_, ParseError> = input.try(|i| { @@ -830,10 +837,10 @@ impl EndingShape { Ok((x, y)) }); if let Ok((x, y)) = pair { - return Ok(GenericEndingShape::Ellipse(Ellipse::Radii(x, y))); + return Ok(generic::EndingShape::Ellipse(Ellipse::Radii(x, y))); } } - return Ok(GenericEndingShape::Ellipse(Ellipse::Extent(ShapeExtent::FarthestCorner))); + return Ok(generic::EndingShape::Ellipse(Ellipse::Extent(ShapeExtent::FarthestCorner))); } // -moz- prefixed radial gradient doesn't allow EndingShape's Length or LengthOrPercentage // to come before shape keyword. Otherwise it conflicts with . @@ -843,7 +850,7 @@ impl EndingShape { if compat_mode == CompatMode::Modern { let _ = input.try(|i| i.expect_ident_matching("ellipse")); } - return Ok(GenericEndingShape::Ellipse(Ellipse::Radii(length.into(), y))); + return Ok(generic::EndingShape::Ellipse(Ellipse::Radii(length.into(), y))); } if compat_mode == CompatMode::Modern { let y = input.try(|i| { @@ -851,12 +858,12 @@ impl EndingShape { LengthOrPercentage::parse(context, i) }); if let Ok(y) = y { - return Ok(GenericEndingShape::Ellipse(Ellipse::Radii(length.into(), y))); + return Ok(generic::EndingShape::Ellipse(Ellipse::Radii(length.into(), y))); } let _ = input.try(|i| i.expect_ident_matching("circle")); } - return Ok(GenericEndingShape::Circle(Circle::Radius(length))); + return Ok(generic::EndingShape::Circle(Circle::Radius(length))); } } input.try(|i| { @@ -872,7 +879,7 @@ impl EndingShape { } LengthOrPercentage::parse(context, i)? }; - Ok(GenericEndingShape::Ellipse(Ellipse::Radii(x.into(), y))) + Ok(generic::EndingShape::Ellipse(Ellipse::Radii(x.into(), y))) }) } } @@ -903,11 +910,11 @@ impl GradientItem { if seen_stop { if let Ok(hint) = input.try(|i| LengthOrPercentage::parse(context, i)) { seen_stop = false; - return Ok(GenericGradientItem::InterpolationHint(hint)); + return Ok(generic::GradientItem::InterpolationHint(hint)); } } seen_stop = true; - ColorStop::parse(context, input).map(GenericGradientItem::ColorStop) + ColorStop::parse(context, input).map(generic::GradientItem::ColorStop) })?; if !seen_stop || items.len() < 2 { return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError)); diff --git a/components/style/values/specified/mod.rs b/components/style/values/specified/mod.rs index 85a25fa6e046..3fcfedd4415b 100644 --- a/components/style/values/specified/mod.rs +++ b/components/style/values/specified/mod.rs @@ -26,12 +26,13 @@ use values::specified::calc::CalcNode; pub use properties::animated_properties::TransitionProperty; pub use self::angle::Angle; #[cfg(feature = "gecko")] -pub use self::align::{AlignContent, JustifyContent, AlignItems, ContentDistribution, SelfAlignment, JustifyItems}; +pub use self::align::{AlignContent, AlignItems, AlignSelf, ContentDistribution}; #[cfg(feature = "gecko")] -pub use self::align::{AlignSelf, JustifySelf}; +pub use self::align::{SelfAlignment, JustifyContent, JustifyItems, JustifySelf}; pub use self::background::{BackgroundRepeat, BackgroundSize}; pub use self::border::{BorderCornerRadius, BorderImageSlice, BorderImageWidth}; -pub use self::border::{BorderImageRepeat, BorderImageSideWidth, BorderRadius, BorderSideWidth, BorderSpacing}; +pub use self::border::{BorderImageRepeat, BorderImageSideWidth}; +pub use self::border::{BorderRadius, BorderSideWidth, BorderSpacing}; pub use self::column::ColumnCount; pub use self::font::{FontSize, FontSizeAdjust, FontSynthesis, FontWeight, FontVariantAlternates}; pub use self::font::{FontFamily, FontLanguageOverride, FontVariationSettings, FontVariantEastAsian}; diff --git a/components/style/values/specified/transform.rs b/components/style/values/specified/transform.rs index 445429614cf0..06374994f65f 100644 --- a/components/style/values/specified/transform.rs +++ b/components/style/values/specified/transform.rs @@ -11,20 +11,15 @@ use style_traits::{ParseError, StyleParseErrorKind}; use values::computed::{Context, LengthOrPercentage as ComputedLengthOrPercentage}; use values::computed::{Percentage as ComputedPercentage, ToComputedValue}; use values::computed::transform::TimingFunction as ComputedTimingFunction; -use values::generics::transform::{Matrix3D, Transform as GenericTransform}; -use values::generics::transform::{StepPosition, TimingFunction as GenericTimingFunction, Matrix}; -use values::generics::transform::{TimingKeyword, TransformOrigin as GenericTransformOrigin}; -use values::generics::transform::Rotate as GenericRotate; -use values::generics::transform::Scale as GenericScale; -use values::generics::transform::TransformOperation as GenericTransformOperation; -use values::generics::transform::Translate as GenericTranslate; +use values::generics::transform as generic; +use values::generics::transform::{Matrix, Matrix3D, StepPosition, TimingKeyword}; use values::specified::{self, Angle, Number, Length, Integer, LengthOrPercentage}; use values::specified::position::{Side, X, Y}; pub use values::generics::transform::TransformStyle; /// A single operation in a specified CSS `transform` -pub type TransformOperation = GenericTransformOperation< +pub type TransformOperation = generic::TransformOperation< Angle, Number, Length, @@ -33,10 +28,10 @@ pub type TransformOperation = GenericTransformOperation< >; /// A specified CSS `transform` -pub type Transform = GenericTransform; +pub type Transform = generic::Transform; /// The specified value of a CSS `` -pub type TransformOrigin = GenericTransformOrigin, OriginComponent, Length>; +pub type TransformOrigin = generic::TransformOrigin, OriginComponent, Length>; impl Transform { /// Internal parse function for deciding if we wish to accept prefixed values or not @@ -53,10 +48,10 @@ impl Transform { .try(|input| input.expect_ident_matching("none")) .is_ok() { - return Ok(GenericTransform(Vec::new())); + return Ok(generic::Transform(Vec::new())); } - Ok(GenericTransform(Space::parse(input, |input| { + Ok(generic::Transform(Space::parse(input, |input| { let function = input.expect_function()?.clone(); input.parse_nested_block(|input| { let location = input.current_source_location(); @@ -75,7 +70,7 @@ impl Transform { let e = Number::parse(context, input)?; input.expect_comma()?; let f = Number::parse(context, input)?; - Ok(GenericTransformOperation::Matrix(Matrix { a, b, c, d, e, f })) + Ok(generic::TransformOperation::Matrix(Matrix { a, b, c, d, e, f })) }, "matrix3d" => { let m11 = Number::parse(context, input)?; @@ -110,7 +105,7 @@ impl Transform { let m43 = Number::parse(context, input)?; input.expect_comma()?; let m44 = Number::parse(context, input)?; - Ok(GenericTransformOperation::Matrix3D(Matrix3D { + Ok(generic::TransformOperation::Matrix3D(Matrix3D { m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34, @@ -121,22 +116,22 @@ impl Transform { let sx = specified::LengthOrPercentage::parse(context, input)?; if input.try(|input| input.expect_comma()).is_ok() { let sy = specified::LengthOrPercentage::parse(context, input)?; - Ok(GenericTransformOperation::Translate(sx, Some(sy))) + Ok(generic::TransformOperation::Translate(sx, Some(sy))) } else { - Ok(GenericTransformOperation::Translate(sx, None)) + Ok(generic::TransformOperation::Translate(sx, None)) } }, "translatex" => { let tx = specified::LengthOrPercentage::parse(context, input)?; - Ok(GenericTransformOperation::TranslateX(tx)) + Ok(generic::TransformOperation::TranslateX(tx)) }, "translatey" => { let ty = specified::LengthOrPercentage::parse(context, input)?; - Ok(GenericTransformOperation::TranslateY(ty)) + Ok(generic::TransformOperation::TranslateY(ty)) }, "translatez" => { let tz = specified::Length::parse(context, input)?; - Ok(GenericTransformOperation::TranslateZ(tz)) + Ok(generic::TransformOperation::TranslateZ(tz)) }, "translate3d" => { let tx = specified::LengthOrPercentage::parse(context, input)?; @@ -144,28 +139,28 @@ impl Transform { let ty = specified::LengthOrPercentage::parse(context, input)?; input.expect_comma()?; let tz = specified::Length::parse(context, input)?; - Ok(GenericTransformOperation::Translate3D(tx, ty, tz)) + Ok(generic::TransformOperation::Translate3D(tx, ty, tz)) }, "scale" => { let sx = Number::parse(context, input)?; if input.try(|input| input.expect_comma()).is_ok() { let sy = Number::parse(context, input)?; - Ok(GenericTransformOperation::Scale(sx, Some(sy))) + Ok(generic::TransformOperation::Scale(sx, Some(sy))) } else { - Ok(GenericTransformOperation::Scale(sx, None)) + Ok(generic::TransformOperation::Scale(sx, None)) } }, "scalex" => { let sx = Number::parse(context, input)?; - Ok(GenericTransformOperation::ScaleX(sx)) + Ok(generic::TransformOperation::ScaleX(sx)) }, "scaley" => { let sy = Number::parse(context, input)?; - Ok(GenericTransformOperation::ScaleY(sy)) + Ok(generic::TransformOperation::ScaleY(sy)) }, "scalez" => { let sz = Number::parse(context, input)?; - Ok(GenericTransformOperation::ScaleZ(sz)) + Ok(generic::TransformOperation::ScaleZ(sz)) }, "scale3d" => { let sx = Number::parse(context, input)?; @@ -173,23 +168,23 @@ impl Transform { let sy = Number::parse(context, input)?; input.expect_comma()?; let sz = Number::parse(context, input)?; - Ok(GenericTransformOperation::Scale3D(sx, sy, sz)) + Ok(generic::TransformOperation::Scale3D(sx, sy, sz)) }, "rotate" => { let theta = specified::Angle::parse_with_unitless(context, input)?; - Ok(GenericTransformOperation::Rotate(theta)) + Ok(generic::TransformOperation::Rotate(theta)) }, "rotatex" => { let theta = specified::Angle::parse_with_unitless(context, input)?; - Ok(GenericTransformOperation::RotateX(theta)) + Ok(generic::TransformOperation::RotateX(theta)) }, "rotatey" => { let theta = specified::Angle::parse_with_unitless(context, input)?; - Ok(GenericTransformOperation::RotateY(theta)) + Ok(generic::TransformOperation::RotateY(theta)) }, "rotatez" => { let theta = specified::Angle::parse_with_unitless(context, input)?; - Ok(GenericTransformOperation::RotateZ(theta)) + Ok(generic::TransformOperation::RotateZ(theta)) }, "rotate3d" => { let ax = Number::parse(context, input)?; @@ -200,28 +195,28 @@ impl Transform { input.expect_comma()?; let theta = specified::Angle::parse_with_unitless(context, input)?; // TODO(gw): Check that the axis can be normalized. - Ok(GenericTransformOperation::Rotate3D(ax, ay, az, theta)) + Ok(generic::TransformOperation::Rotate3D(ax, ay, az, theta)) }, "skew" => { let ax = specified::Angle::parse_with_unitless(context, input)?; if input.try(|input| input.expect_comma()).is_ok() { let ay = specified::Angle::parse_with_unitless(context, input)?; - Ok(GenericTransformOperation::Skew(ax, Some(ay))) + Ok(generic::TransformOperation::Skew(ax, Some(ay))) } else { - Ok(GenericTransformOperation::Skew(ax, None)) + Ok(generic::TransformOperation::Skew(ax, None)) } }, "skewx" => { let theta = specified::Angle::parse_with_unitless(context, input)?; - Ok(GenericTransformOperation::SkewX(theta)) + Ok(generic::TransformOperation::SkewX(theta)) }, "skewy" => { let theta = specified::Angle::parse_with_unitless(context, input)?; - Ok(GenericTransformOperation::SkewY(theta)) + Ok(generic::TransformOperation::SkewY(theta)) }, "perspective" => { let d = specified::Length::parse_non_negative(context, input)?; - Ok(GenericTransformOperation::Perspective(d)) + Ok(generic::TransformOperation::Perspective(d)) }, _ => Err(()), }; @@ -253,7 +248,7 @@ pub enum OriginComponent { } /// A specified timing function. -pub type TimingFunction = GenericTimingFunction; +pub type TimingFunction = generic::TimingFunction; impl Parse for TransformOrigin { fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result> { @@ -367,7 +362,7 @@ fn allow_frames_timing() -> bool { impl Parse for TimingFunction { fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result> { if let Ok(keyword) = input.try(TimingKeyword::parse) { - return Ok(GenericTimingFunction::Keyword(keyword)); + return Ok(generic::TimingFunction::Keyword(keyword)); } if let Ok(ident) = input.try(|i| i.expect_ident_cloned()) { let position = @@ -376,7 +371,7 @@ impl Parse for TimingFunction { "step-end" => StepPosition::End, _ => return Err(input.new_custom_error(SelectorParseErrorKind::UnexpectedIdent(ident.clone()))), }; - return Ok(GenericTimingFunction::Steps(Integer::new(1), position)); + return Ok(generic::TimingFunction::Steps(Integer::new(1), position)); } let location = input.current_source_location(); let function = input.expect_function()?.clone(); @@ -395,7 +390,7 @@ impl Parse for TimingFunction { return Err(i.new_custom_error(StyleParseErrorKind::UnspecifiedError)); } - Ok(GenericTimingFunction::CubicBezier { x1, y1, x2, y2 }) + Ok(generic::TimingFunction::CubicBezier { x1, y1, x2, y2 }) }, "steps" => { let steps = Integer::parse_positive(context, i)?; @@ -403,12 +398,12 @@ impl Parse for TimingFunction { i.expect_comma()?; StepPosition::parse(i) }).unwrap_or(StepPosition::End); - Ok(GenericTimingFunction::Steps(steps, position)) + Ok(generic::TimingFunction::Steps(steps, position)) }, "frames" => { if allow_frames_timing() { let frames = Integer::parse_with_minimum(context, i, 2)?; - Ok(GenericTimingFunction::Frames(frames)) + Ok(generic::TimingFunction::Frames(frames)) } else { Err(()) } @@ -425,25 +420,25 @@ impl ToComputedValue for TimingFunction { #[inline] fn to_computed_value(&self, context: &Context) -> Self::ComputedValue { match *self { - GenericTimingFunction::Keyword(keyword) => GenericTimingFunction::Keyword(keyword), - GenericTimingFunction::CubicBezier { + generic::TimingFunction::Keyword(keyword) => generic::TimingFunction::Keyword(keyword), + generic::TimingFunction::CubicBezier { x1, y1, x2, y2, } => { - GenericTimingFunction::CubicBezier { + generic::TimingFunction::CubicBezier { x1: x1.to_computed_value(context), y1: y1.to_computed_value(context), x2: x2.to_computed_value(context), y2: y2.to_computed_value(context), } }, - GenericTimingFunction::Steps(steps, position) => { - GenericTimingFunction::Steps(steps.to_computed_value(context) as u32, position) + generic::TimingFunction::Steps(steps, position) => { + generic::TimingFunction::Steps(steps.to_computed_value(context) as u32, position) }, - GenericTimingFunction::Frames(frames) => { - GenericTimingFunction::Frames(frames.to_computed_value(context) as u32) + generic::TimingFunction::Frames(frames) => { + generic::TimingFunction::Frames(frames.to_computed_value(context) as u32) }, } } @@ -451,32 +446,32 @@ impl ToComputedValue for TimingFunction { #[inline] fn from_computed_value(computed: &Self::ComputedValue) -> Self { match *computed { - GenericTimingFunction::Keyword(keyword) => GenericTimingFunction::Keyword(keyword), - GenericTimingFunction::CubicBezier { + generic::TimingFunction::Keyword(keyword) => generic::TimingFunction::Keyword(keyword), + generic::TimingFunction::CubicBezier { ref x1, ref y1, ref x2, ref y2, } => { - GenericTimingFunction::CubicBezier { + generic::TimingFunction::CubicBezier { x1: Number::from_computed_value(x1), y1: Number::from_computed_value(y1), x2: Number::from_computed_value(x2), y2: Number::from_computed_value(y2), } }, - GenericTimingFunction::Steps(steps, position) => { - GenericTimingFunction::Steps(Integer::from_computed_value(&(steps as i32)), position) + generic::TimingFunction::Steps(steps, position) => { + generic::TimingFunction::Steps(Integer::from_computed_value(&(steps as i32)), position) }, - GenericTimingFunction::Frames(frames) => { - GenericTimingFunction::Frames(Integer::from_computed_value(&(frames as i32))) + generic::TimingFunction::Frames(frames) => { + generic::TimingFunction::Frames(Integer::from_computed_value(&(frames as i32))) }, } } } /// A specified CSS `rotate` -pub type Rotate = GenericRotate; +pub type Rotate = generic::Rotate; impl Parse for Rotate { fn parse<'i, 't>( @@ -484,7 +479,7 @@ impl Parse for Rotate { input: &mut Parser<'i, 't> ) -> Result> { if input.try(|i| i.expect_ident_matching("none")).is_ok() { - return Ok(GenericRotate::None); + return Ok(generic::Rotate::None); } if let Ok(rx) = input.try(|i| Number::parse(context, i)) { @@ -492,17 +487,17 @@ impl Parse for Rotate { let ry = Number::parse(context, input)?; let rz = Number::parse(context, input)?; let angle = specified::Angle::parse(context, input)?; - return Ok(GenericRotate::Rotate3D(rx, ry, rz, angle)); + return Ok(generic::Rotate::Rotate3D(rx, ry, rz, angle)); } // 'rotate: ' let angle = specified::Angle::parse(context, input)?; - Ok(GenericRotate::Rotate(angle)) + Ok(generic::Rotate::Rotate(angle)) } } /// A specified CSS `translate` -pub type Translate = GenericTranslate; +pub type Translate = generic::Translate; impl Parse for Translate { fn parse<'i, 't>( @@ -510,27 +505,27 @@ impl Parse for Translate { input: &mut Parser<'i, 't> ) -> Result> { if input.try(|i| i.expect_ident_matching("none")).is_ok() { - return Ok(GenericTranslate::None); + return Ok(generic::Translate::None); } let tx = specified::LengthOrPercentage::parse(context, input)?; if let Ok(ty) = input.try(|i| specified::LengthOrPercentage::parse(context, i)) { if let Ok(tz) = input.try(|i| specified::Length::parse(context, i)) { // 'translate: ' - return Ok(GenericTranslate::Translate3D(tx, ty, tz)); + return Ok(generic::Translate::Translate3D(tx, ty, tz)); } // translate: ' - return Ok(GenericTranslate::Translate(tx, ty)); + return Ok(generic::Translate::Translate(tx, ty)); } // 'translate: ' - Ok(GenericTranslate::TranslateX(tx)) + Ok(generic::Translate::TranslateX(tx)) } } /// A specified CSS `scale` -pub type Scale = GenericScale; +pub type Scale = generic::Scale; impl Parse for Scale { fn parse<'i, 't>( @@ -538,21 +533,21 @@ impl Parse for Scale { input: &mut Parser<'i, 't> ) -> Result> { if input.try(|i| i.expect_ident_matching("none")).is_ok() { - return Ok(GenericScale::None); + return Ok(generic::Scale::None); } let sx = Number::parse(context, input)?; if let Ok(sy) = input.try(|i| Number::parse(context, i)) { if let Ok(sz) = input.try(|i| Number::parse(context, i)) { // 'scale: ' - return Ok(GenericScale::Scale3D(sx, sy, sz)); + return Ok(generic::Scale::Scale3D(sx, sy, sz)); } // 'scale: ' - return Ok(GenericScale::Scale(sx, sy)); + return Ok(generic::Scale::Scale(sx, sy)); } // 'scale: ' - Ok(GenericScale::ScaleX(sx)) + Ok(generic::Scale::ScaleX(sx)) } }