diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2018-04-03 18:12:13 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-03 18:12:13 -0400 |
commit | d744e35d38ce84f7209eb1fc41d2d9f38545d0de (patch) | |
tree | 4358de73814b0ab509fd896482f26ca45b99ebad | |
parent | d0a9fdb92b1476bc42603b495a01bd10da18d978 (diff) | |
parent | cc838f54e5042668259ddd9235d8af34230a9fd8 (diff) | |
download | servo-d744e35d38ce84f7209eb1fc41d2d9f38545d0de.tar.gz servo-d744e35d38ce84f7209eb1fc41d2d9f38545d0de.zip |
Auto merge of #20482 - brainlessdeveloper:list-style-image-computed, r=emilio
Implement a URL-generic type for ListStyleImage
<!-- Please describe your changes on the following line: -->
This should fix the following two "expected to fail" tests described in https://github.com/servo/servo/issues/18015:
- getComputedStyle(elem) for url() listStyleImage uses the resolved URL
and elem.style uses the original URL
- getComputedStyle(elem) for url() listStyle uses the resolved URL
and elem.style uses the original URL
I updated the test failure expectations by removing the corresponding `.ini` file.
---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #18015 (github issue number if applicable).
<!-- Either: -->
- [x] There are tests for these changes OR
- [ ] These changes do not require tests because _____
<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->
<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/20482)
<!-- Reviewable:end -->
26 files changed, 157 insertions, 124 deletions
diff --git a/components/layout/construct.rs b/components/layout/construct.rs index 3849e43ad51..291e8941e7d 100644 --- a/components/layout/construct.rs +++ b/components/layout/construct.rs @@ -52,11 +52,10 @@ use style::context::SharedStyleContext; use style::dom::TElement; use style::logical_geometry::Direction; use style::properties::ComputedValues; -use style::properties::longhands::list_style_image; use style::selector_parser::{PseudoElement, RestyleDamage}; use style::servo::restyle_damage::ServoRestyleDamage; -use style::values::Either; use style::values::computed::counters::ContentItem; +use style::values::generics::url::UrlOrNone as ImageUrlOrNone; use table::TableFlow; use table_caption::TableCaptionFlow; use table_cell::TableCellFlow; @@ -1278,13 +1277,13 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode> -> ConstructionResult { let flotation = FloatKind::from_property(flotation); let marker_fragments = match node.style(self.style_context()).get_list().list_style_image { - list_style_image::computed_value::T(Either::First(ref url_value)) => { + ImageUrlOrNone::Url(ref url_value) => { let image_info = Box::new(ImageFragmentInfo::new( url_value.url().map(|u| u.clone()), node, &self.layout_context )); vec![Fragment::new(node, SpecificFragmentInfo::Image(image_info), self.layout_context)] } - list_style_image::computed_value::T(Either::Second(_none)) => { + ImageUrlOrNone::None => { match ListStyleTypeContent::from_list_style_type(node.style(self.style_context()) .get_list() .list_style_type) { diff --git a/components/style/gecko/conversions.rs b/components/style/gecko/conversions.rs index 43a4b8dc91a..fa9f10f67db 100644 --- a/components/style/gecko/conversions.rs +++ b/components/style/gecko/conversions.rs @@ -17,8 +17,9 @@ 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, ComputedImageUrl, Gradient, Image}; +use values::computed::{Angle, CalcLengthOrPercentage, Gradient, Image}; use values::computed::{Integer, LengthOrPercentage, LengthOrPercentageOrAuto, Percentage, TextAlign}; +use values::computed::url::ComputedImageUrl; use values::generics::box_::VerticalAlign; use values::generics::grid::{TrackListValue, TrackSize}; use values::generics::image::{CompatMode, Image as GenericImage, GradientItem}; @@ -593,11 +594,11 @@ pub mod basic_shape { use gecko_bindings::structs::{nsStyleCoord, nsStyleCorners}; use gecko_bindings::sugar::ns_style_coord::{CoordDataMut, CoordDataValue}; use std::borrow::Borrow; - use values::computed::ComputedUrl; use values::computed::basic_shape::{BasicShape, ClippingShape, FloatAreaShape, ShapeRadius}; use values::computed::border::{BorderCornerRadius, BorderRadius}; use values::computed::length::LengthOrPercentage; use values::computed::position; + use values::computed::url::ComputedUrl; use values::generics::basic_shape::{BasicShape as GenericBasicShape, InsetRect, Polygon}; use values::generics::basic_shape::{Circle, Ellipse, FillRule}; use values::generics::basic_shape::{GeometryBox, ShapeBox, ShapeSource}; diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index 10b090fb39f..9139b2387bf 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -66,6 +66,7 @@ use values::generics::column::ColumnCount; use values::generics::position::ZIndex; use values::generics::text::MozTabSize; use values::generics::transform::TransformStyle; +use values::generics::url::UrlOrNone; use computed_values::border_style; pub mod style_structs { @@ -937,10 +938,10 @@ def set_gecko_property(ffi_name, expr): #[allow(non_snake_case)] pub fn set_${ident}(&mut self, v: longhands::${ident}::computed_value::T) { match v { - Either::First(url) => { + UrlOrNone::Url(ref url) => { self.gecko.${gecko_ffi_name}.set_move(url.url_value.clone()) } - Either::Second(_none) => { + UrlOrNone::None => { unsafe { self.gecko.${gecko_ffi_name}.clear(); } @@ -961,15 +962,14 @@ def set_gecko_property(ffi_name, expr): #[allow(non_snake_case)] pub fn clone_${ident}(&self) -> longhands::${ident}::computed_value::T { use values::specified::url::SpecifiedUrl; - use values::None_; if self.gecko.${gecko_ffi_name}.mRawPtr.is_null() { - Either::Second(None_) + UrlOrNone::none() } else { unsafe { let ref gecko_url_value = *self.gecko.${gecko_ffi_name}.mRawPtr; - Either::First(SpecifiedUrl::from_url_value_data(&gecko_url_value._base) - .expect("${gecko_ffi_name} could not convert to SpecifiedUrl")) + UrlOrNone::Url(SpecifiedUrl::from_url_value_data(&gecko_url_value._base) + .expect("${gecko_ffi_name} could not convert to SpecifiedUrl")) } } } @@ -1469,7 +1469,7 @@ impl Clone for ${style_struct.gecko_struct_name} { "SVGWidth": impl_svg_length, "Transform": impl_transform, "TransformOrigin": impl_transform_origin, - "UrlOrNone": impl_css_url, + "url::UrlOrNone": impl_css_url, } def longhand_method(longhand): @@ -4061,14 +4061,13 @@ fn static_assert() { skip_longhands="list-style-image list-style-type quotes -moz-image-region"> pub fn set_list_style_image(&mut self, image: longhands::list_style_image::computed_value::T) { - use values::Either; match image { - longhands::list_style_image::computed_value::T(Either::Second(_none)) => { + UrlOrNone::None => { unsafe { Gecko_SetListStyleImageNone(&mut self.gecko); } } - longhands::list_style_image::computed_value::T(Either::First(ref url)) => { + UrlOrNone::Url(ref url) => { unsafe { Gecko_SetListStyleImageImageValue(&mut self.gecko, url.image_value.get()); } @@ -4090,20 +4089,16 @@ fn static_assert() { pub fn clone_list_style_image(&self) -> longhands::list_style_image::computed_value::T { use values::specified::url::SpecifiedImageUrl; - use values::{Either, None_}; - longhands::list_style_image::computed_value::T( - match self.gecko.mListStyleImage.mRawPtr.is_null() { - true => Either::Second(None_), - false => { - unsafe { - let ref gecko_image_request = *self.gecko.mListStyleImage.mRawPtr; - Either::First(SpecifiedImageUrl::from_image_request(gecko_image_request) - .expect("mListStyleImage could not convert to SpecifiedImageUrl")) - } - } - } - ) + if self.gecko.mListStyleImage.mRawPtr.is_null() { + return UrlOrNone::None; + } + + unsafe { + let ref gecko_image_request = *self.gecko.mListStyleImage.mRawPtr; + UrlOrNone::Url(SpecifiedImageUrl::from_image_request(gecko_image_request) + .expect("mListStyleImage could not convert to SpecifiedImageUrl")) + } } pub fn set_list_style_type(&mut self, v: longhands::list_style_type::computed_value::T, device: &Device) { diff --git a/components/style/properties/helpers/animated_properties.mako.rs b/components/style/properties/helpers/animated_properties.mako.rs index 570658c5301..bb6931cdde3 100644 --- a/components/style/properties/helpers/animated_properties.mako.rs +++ b/components/style/properties/helpers/animated_properties.mako.rs @@ -36,7 +36,7 @@ use values::animated::color::RGBA as AnimatedRGBA; use values::animated::effects::Filter as AnimatedFilter; use values::animated::effects::FilterList as AnimatedFilterList; use values::computed::{Angle, CalcLengthOrPercentage}; -use values::computed::{ClipRect, Context, ComputedUrl}; +use values::computed::{ClipRect, Context}; use values::computed::{Length, LengthOrPercentage, LengthOrPercentageOrAuto}; use values::computed::{LengthOrPercentageOrNone, MaxLength}; use values::computed::{NonNegativeNumber, Number, NumberOrPercentage, Percentage}; @@ -48,6 +48,7 @@ use values::computed::transform::Transform as ComputedTransform; use values::computed::transform::Rotate as ComputedRotate; use values::computed::transform::Translate as ComputedTranslate; use values::computed::transform::Scale as ComputedScale; +use values::computed::url::ComputedUrl; use values::generics::transform::{self, Rotate, Translate, Scale, Transform, TransformOperation}; use values::distance::{ComputeSquaredDistance, SquaredDistance}; use values::generics::font::{FontSettings as GenericFontSettings, FontTag, VariationValue}; diff --git a/components/style/properties/longhand/box.mako.rs b/components/style/properties/longhand/box.mako.rs index e606f081c6c..ddd0bd67baf 100644 --- a/components/style/properties/longhand/box.mako.rs +++ b/components/style/properties/longhand/box.mako.rs @@ -613,7 +613,7 @@ ${helpers.single_keyword("-moz-appearance", spec="Nonstandard (https://developer.mozilla.org/en-US/docs/Web/CSS/-moz-appearance)", animation_value_type="discrete")} -${helpers.predefined_type("-moz-binding", "UrlOrNone", "Either::Second(None_)", +${helpers.predefined_type("-moz-binding", "url::UrlOrNone", "computed::url::UrlOrNone::none()", products="gecko", animation_value_type="none", gecko_ffi_name="mBinding", diff --git a/components/style/properties/longhand/inherited_svg.mako.rs b/components/style/properties/longhand/inherited_svg.mako.rs index a3ab5c3754e..063a4418181 100644 --- a/components/style/properties/longhand/inherited_svg.mako.rs +++ b/components/style/properties/longhand/inherited_svg.mako.rs @@ -112,17 +112,17 @@ ${helpers.single_keyword("clip-rule", "nonzero evenodd", animation_value_type="discrete", spec="https://www.w3.org/TR/SVG11/masking.html#ClipRuleProperty")} -${helpers.predefined_type("marker-start", "UrlOrNone", "Either::Second(None_)", +${helpers.predefined_type("marker-start", "url::UrlOrNone", "computed::url::UrlOrNone::none()", products="gecko", animation_value_type="discrete", spec="https://www.w3.org/TR/SVG2/painting.html#VertexMarkerProperties")} -${helpers.predefined_type("marker-mid", "UrlOrNone", "Either::Second(None_)", +${helpers.predefined_type("marker-mid", "url::UrlOrNone", "computed::url::UrlOrNone::none()", products="gecko", animation_value_type="discrete", spec="https://www.w3.org/TR/SVG2/painting.html#VertexMarkerProperties")} -${helpers.predefined_type("marker-end", "UrlOrNone", "Either::Second(None_)", +${helpers.predefined_type("marker-end", "url::UrlOrNone", "computed::url::UrlOrNone::none()", products="gecko", animation_value_type="discrete", spec="https://www.w3.org/TR/SVG2/painting.html#VertexMarkerProperties")} diff --git a/components/style/properties/longhand/list.mako.rs b/components/style/properties/longhand/list.mako.rs index c478dc6f98c..5ed1ea44831 100644 --- a/components/style/properties/longhand/list.mako.rs +++ b/components/style/properties/longhand/list.mako.rs @@ -41,9 +41,9 @@ ${helpers.single_keyword("list-style-position", "outside inside", animation_valu % endif ${helpers.predefined_type("list-style-image", - "ListStyleImage", - initial_value="specified::ListStyleImage::none()", - initial_specified_value="specified::ListStyleImage::none()", + "url::ImageUrlOrNone", + initial_value="computed::url::ImageUrlOrNone::none()", + initial_specified_value="specified::url::ImageUrlOrNone::none()", animation_value_type="discrete", spec="https://drafts.csswg.org/css-lists/#propdef-list-style-image", servo_restyle_damage="rebuild_and_reflow")} diff --git a/components/style/properties/shorthand/inherited_svg.mako.rs b/components/style/properties/shorthand/inherited_svg.mako.rs index 0984e879369..09c533a708b 100644 --- a/components/style/properties/shorthand/inherited_svg.mako.rs +++ b/components/style/properties/shorthand/inherited_svg.mako.rs @@ -7,7 +7,7 @@ <%helpers:shorthand name="marker" products="gecko" sub_properties="marker-start marker-end marker-mid" spec="https://www.w3.org/TR/SVG2/painting.html#MarkerShorthand"> - use values::specified::UrlOrNone; + use values::specified::url::UrlOrNone; pub fn parse_value<'i, 't>( context: &ParserContext, diff --git a/components/style/properties/shorthand/list.mako.rs b/components/style/properties/shorthand/list.mako.rs index d7b723adf62..67e141f5ac6 100644 --- a/components/style/properties/shorthand/list.mako.rs +++ b/components/style/properties/shorthand/list.mako.rs @@ -9,7 +9,7 @@ derive_serialize="True" spec="https://drafts.csswg.org/css-lists/#propdef-list-style"> use properties::longhands::{list_style_image, list_style_position, list_style_type}; - use values::{Either, None_}; + use values::specified::url::ImageUrlOrNone; pub fn parse_value<'i, 't>( context: &ParserContext, @@ -76,7 +76,7 @@ (true, 2, None, None) => { Ok(expanded! { list_style_position: position, - list_style_image: list_style_image::SpecifiedValue(Either::Second(None_)), + list_style_image: ImageUrlOrNone::none(), list_style_type: list_style_type_none(), }) } @@ -90,14 +90,14 @@ (true, 1, Some(list_style_type), None) => { Ok(expanded! { list_style_position: position, - list_style_image: list_style_image::SpecifiedValue(Either::Second(None_)), + list_style_image: ImageUrlOrNone::none(), list_style_type: list_style_type, }) } (true, 1, None, None) => { Ok(expanded! { list_style_position: position, - list_style_image: list_style_image::SpecifiedValue(Either::Second(None_)), + list_style_image: ImageUrlOrNone::none(), list_style_type: list_style_type_none(), }) } diff --git a/components/style/values/animated/mod.rs b/components/style/values/animated/mod.rs index 9e0653d8a00..55ec1c626cf 100644 --- a/components/style/values/animated/mod.rs +++ b/components/style/values/animated/mod.rs @@ -13,10 +13,10 @@ use euclid::{Point2D, Size2D}; use smallvec::SmallVec; use values::computed::Angle as ComputedAngle; use values::computed::BorderCornerRadius as ComputedBorderCornerRadius; -#[cfg(feature = "servo")] -use values::computed::ComputedUrl; use values::computed::MaxLength as ComputedMaxLength; use values::computed::MozLength as ComputedMozLength; +#[cfg(feature = "servo")] +use values::computed::url::ComputedUrl; use values::specified::url::SpecifiedUrl; pub mod color; diff --git a/components/style/values/computed/basic_shape.rs b/components/style/values/computed/basic_shape.rs index 17c39741c81..13dea6fc99a 100644 --- a/components/style/values/computed/basic_shape.rs +++ b/components/style/values/computed/basic_shape.rs @@ -9,7 +9,8 @@ use std::fmt::{self, Write}; use style_traits::{CssWriter, ToCss}; -use values::computed::{LengthOrPercentage, ComputedUrl, Image}; +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}; diff --git a/components/style/values/computed/image.rs b/components/style/values/computed/image.rs index e0b3e3bbd91..7535ccf6dd4 100644 --- a/components/style/values/computed/image.rs +++ b/components/style/values/computed/image.rs @@ -12,11 +12,12 @@ use std::f32::consts::PI; use std::fmt::{self, Write}; use style_traits::{CssWriter, ToCss}; use values::{Either, None_}; -use values::computed::{Angle, ComputedImageUrl, Context}; +use values::computed::{Angle, Context}; use values::computed::{Length, LengthOrPercentage, NumberOrPercentage, ToComputedValue}; #[cfg(feature = "gecko")] 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}; diff --git a/components/style/values/computed/length.rs b/components/style/values/computed/length.rs index 4dc85a71f0f..9bff238dc48 100644 --- a/components/style/values/computed/length.rs +++ b/components/style/values/computed/length.rs @@ -21,7 +21,8 @@ use values::specified::length::{AbsoluteLength, FontBaseSize, FontRelativeLength use values::specified::length::ViewportPercentageLength; pub use super::image::Image; -pub use values::specified::{Angle, BorderStyle, Time, UrlOrNone}; +pub use values::specified::url::UrlOrNone; +pub use values::specified::{Angle, BorderStyle, Time}; impl ToComputedValue for specified::NoCalcLength { type ComputedValue = CSSPixelLength; diff --git a/components/style/values/computed/list.rs b/components/style/values/computed/list.rs index 2e5584c69d9..3521c59eb58 100644 --- a/components/style/values/computed/list.rs +++ b/components/style/values/computed/list.rs @@ -4,7 +4,7 @@ //! `list` computed values. -pub use values::specified::list::{ListStyleImage, Quotes}; +pub use values::specified::list::Quotes; #[cfg(feature = "gecko")] pub use values::specified::list::ListStyleType; diff --git a/components/style/values/computed/mod.rs b/components/style/values/computed/mod.rs index 9dba026d117..2e763f97c41 100644 --- a/components/style/values/computed/mod.rs +++ b/components/style/values/computed/mod.rs @@ -62,7 +62,7 @@ pub use self::length::{CalcLengthOrPercentage, Length, LengthOrNumber, LengthOrP pub use self::length::{LengthOrPercentageOrAuto, LengthOrPercentageOrNone, MaxLength, MozLength}; pub use self::length::{CSSPixelLength, ExtremumLength, NonNegativeLength}; pub use self::length::{NonNegativeLengthOrPercentage, NonNegativeLengthOrPercentageOrAuto}; -pub use self::list::{ListStyleImage, Quotes}; +pub use self::list::Quotes; #[cfg(feature = "gecko")] pub use self::list::ListStyleType; pub use self::outline::OutlineStyle; @@ -81,7 +81,6 @@ pub use self::time::Time; pub use self::transform::{Rotate, Scale, TimingFunction, Transform, TransformOperation}; pub use self::transform::{TransformOrigin, TransformStyle, Translate}; pub use self::ui::MozForceBrokenImageIcon; -pub use self::url::{ComputedUrl, ComputedImageUrl}; #[cfg(feature = "gecko")] pub mod align; @@ -114,14 +113,7 @@ pub mod text; pub mod time; pub mod transform; pub mod ui; - -/// Common handling for the computed value CSS url() values. -pub mod url { -#[cfg(feature = "servo")] -pub use ::servo::url::{ComputedUrl, ComputedImageUrl}; -#[cfg(feature = "gecko")] -pub use ::gecko::url::{ComputedUrl, ComputedImageUrl}; -} +pub mod url; /// A `Context` is all the data a specified value could ever need to compute /// itself and be transformed to a computed value. @@ -639,9 +631,3 @@ impl ClipRectOrAuto { } } } - -/// <url> | <none> -pub type UrlOrNone = Either<ComputedUrl, None_>; - -/// <url> | <none> for image -pub type ImageUrlOrNone = Either<ComputedImageUrl, None_>; diff --git a/components/style/values/computed/svg.rs b/components/style/values/computed/svg.rs index b43312ec67c..7e26de6f042 100644 --- a/components/style/values/computed/svg.rs +++ b/components/style/values/computed/svg.rs @@ -6,9 +6,10 @@ use app_units::Au; use values::RGBA; -use values::computed::{ComputedUrl, LengthOrPercentage, NonNegativeLength}; +use values::computed::{LengthOrPercentage, NonNegativeLength}; use values::computed::{NonNegativeNumber, NonNegativeLengthOrPercentage, Number}; use values::computed::Opacity; +use values::computed::url::ComputedUrl; use values::generics::svg as generic; pub use values::specified::SVGPaintOrder; diff --git a/components/style/values/computed/url.rs b/components/style/values/computed/url.rs new file mode 100644 index 00000000000..f3fc11dbd1f --- /dev/null +++ b/components/style/values/computed/url.rs @@ -0,0 +1,18 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//! Common handling for the computed value CSS url() values. + +use values::generics::url::UrlOrNone as GenericUrlOrNone; + +#[cfg(feature = "servo")] +pub use ::servo::url::{ComputedUrl, ComputedImageUrl}; +#[cfg(feature = "gecko")] +pub use ::gecko::url::{ComputedUrl, ComputedImageUrl}; + +/// Computed <url> | <none> +pub type UrlOrNone = GenericUrlOrNone<ComputedUrl>; + +/// Computed image <url> | <none> +pub type ImageUrlOrNone = GenericUrlOrNone<ComputedImageUrl>; diff --git a/components/style/values/generics/mod.rs b/components/style/values/generics/mod.rs index 8af481687d4..c66fb1629ec 100644 --- a/components/style/values/generics/mod.rs +++ b/components/style/values/generics/mod.rs @@ -32,6 +32,7 @@ pub mod size; pub mod svg; pub mod text; pub mod transform; +pub mod url; // https://drafts.csswg.org/css-counter-styles/#typedef-symbols-type #[allow(missing_docs)] diff --git a/components/style/values/generics/url.rs b/components/style/values/generics/url.rs new file mode 100644 index 00000000000..2aabc23846b --- /dev/null +++ b/components/style/values/generics/url.rs @@ -0,0 +1,39 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//! Generic types for url properties. + +use cssparser::Parser; +use parser::{Parse, ParserContext}; +use style_traits::ParseError; + +/// An image url or none, used for example in list-style-image +#[derive(Animate, Clone, ComputeSquaredDistance, Debug, MallocSizeOf)] +#[derive(PartialEq, ToAnimatedValue, ToAnimatedZero, ToComputedValue, ToCss)] +pub enum UrlOrNone<Url> { + /// `none` + None, + /// `A URL` + Url(Url), +} + +impl<Url> UrlOrNone<Url> { + /// Initial "none" value for properties such as `list-style-image` + pub fn none() -> Self { + UrlOrNone::None + } +} + +impl<Url> Parse for UrlOrNone<Url> where Url: Parse { + fn parse<'i, 't>( + context: &ParserContext, + input: &mut Parser<'i, 't>, + ) -> Result<UrlOrNone<Url>, ParseError<'i>> { + if let Ok(url) = input.try(|input| Url::parse(context, input)) { + return Ok(UrlOrNone::Url(url)); + } + input.expect_ident_matching("none")?; + Ok(UrlOrNone::None) + } +} diff --git a/components/style/values/specified/list.rs b/components/style/values/specified/list.rs index f2bc6068790..d047c4526dd 100644 --- a/components/style/values/specified/list.rs +++ b/components/style/values/specified/list.rs @@ -8,12 +8,10 @@ use cssparser::{Parser, Token}; use parser::{Parse, ParserContext}; use std::fmt::{self, Write}; use style_traits::{CssWriter, ParseError, StyleParseErrorKind, ToCss}; -use values::{Either, None_}; #[cfg(feature = "gecko")] use values::CustomIdent; #[cfg(feature = "gecko")] use values::generics::CounterStyleOrNone; -use values::specified::ImageUrlOrNone; /// Specified and computed `list-style-type` property. #[cfg(feature = "gecko")] @@ -73,31 +71,6 @@ impl Parse for ListStyleType { } } -/// Specified and computed `list-style-image` property. -#[derive(Clone, Debug, MallocSizeOf, PartialEq, ToCss)] -pub struct ListStyleImage(pub ImageUrlOrNone); - -// FIXME(nox): This is wrong, there are different types for specified -// and computed URLs in Servo. -trivial_to_computed_value!(ListStyleImage); - -impl ListStyleImage { - /// Initial specified value for `list-style-image`. - #[inline] - pub fn none() -> ListStyleImage { - ListStyleImage(Either::Second(None_)) - } -} - -impl Parse for ListStyleImage { - fn parse<'i, 't>( - context: &ParserContext, - input: &mut Parser<'i, 't>, - ) -> Result<ListStyleImage, ParseError<'i>> { - ImageUrlOrNone::parse(context, input).map(ListStyleImage) - } -} - /// Specified and computed `quote` property. /// /// FIXME(emilio): It's a shame that this allocates all the time it's computed, diff --git a/components/style/values/specified/mod.rs b/components/style/values/specified/mod.rs index 82ed1f824a3..728f88f23e7 100644 --- a/components/style/values/specified/mod.rs +++ b/components/style/values/specified/mod.rs @@ -11,12 +11,11 @@ use context::QuirksMode; use cssparser::{Parser, Token, serialize_identifier}; use num_traits::One; use parser::{ParserContext, Parse}; -use self::url::{SpecifiedImageUrl, SpecifiedUrl}; use std::f32; use std::fmt::{self, Write}; use style_traits::{CssWriter, ParseError, StyleParseErrorKind, ToCss}; use style_traits::values::specified::AllowedNumericType; -use super::{Auto, CSSFloat, CSSInteger, Either, None_}; +use super::{Auto, CSSFloat, CSSInteger, Either}; use super::computed::{Context, ToComputedValue}; use super::generics::{GreaterThanOrEqualToOne, NonNegative}; use super::generics::grid::{GridLine as GenericGridLine, TrackBreadth as GenericTrackBreadth}; @@ -56,7 +55,7 @@ pub use self::length::{LengthOrPercentage, LengthOrPercentageOrAuto}; pub use self::length::{LengthOrPercentageOrNone, MaxLength, MozLength}; pub use self::length::{NoCalcLength, ViewportPercentageLength}; pub use self::length::{NonNegativeLengthOrPercentage, NonNegativeLengthOrPercentageOrAuto}; -pub use self::list::{ListStyleImage, Quotes}; +pub use self::list::Quotes; #[cfg(feature = "gecko")] pub use self::list::ListStyleType; pub use self::outline::OutlineStyle; @@ -114,14 +113,7 @@ pub mod text; pub mod time; pub mod transform; pub mod ui; - -/// Common handling for the specified value CSS url() values. -pub mod url { -#[cfg(feature = "servo")] -pub use ::servo::url::{SpecifiedUrl, SpecifiedImageUrl}; -#[cfg(feature = "gecko")] -pub use ::gecko::url::{SpecifiedUrl, SpecifiedImageUrl}; -} +pub mod url; /// Parse a `<number>` value, with a given clamping mode. fn parse_number_with_clamping_mode<'i, 't>( @@ -519,12 +511,6 @@ impl Parse for PositiveInteger { } } -#[allow(missing_docs)] -pub type UrlOrNone = Either<SpecifiedUrl, None_>; - -/// The specified value of a `<url>` for image or `none`. -pub type ImageUrlOrNone = Either<SpecifiedImageUrl, None_>; - /// The specified value of a grid `<track-breadth>` pub type TrackBreadth = GenericTrackBreadth<LengthOrPercentage>; diff --git a/components/style/values/specified/svg.rs b/components/style/values/specified/svg.rs index 23abf340763..fb8140fe5b9 100644 --- a/components/style/values/specified/svg.rs +++ b/components/style/values/specified/svg.rs @@ -12,8 +12,9 @@ use style_traits::{StyleParseErrorKind, ToCss}; use values::CustomIdent; use values::generics::svg as generic; use values::specified::{LengthOrPercentage, NonNegativeLengthOrPercentage, NonNegativeNumber}; -use values::specified::{Number, Opacity, SpecifiedUrl}; +use values::specified::{Number, Opacity}; use values::specified::color::RGBAColor; +use values::specified::url::SpecifiedUrl; /// Specified SVG Paint value pub type SVGPaint = generic::SVGPaint<RGBAColor, SpecifiedUrl>; diff --git a/components/style/values/specified/url.rs b/components/style/values/specified/url.rs new file mode 100644 index 00000000000..56c7fc7171f --- /dev/null +++ b/components/style/values/specified/url.rs @@ -0,0 +1,18 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//! Common handling for the specified value CSS url() values. + +use values::generics::url::UrlOrNone as GenericUrlOrNone; + +#[cfg(feature = "servo")] +pub use ::servo::url::{SpecifiedUrl, SpecifiedImageUrl}; +#[cfg(feature = "gecko")] +pub use ::gecko::url::{SpecifiedUrl, SpecifiedImageUrl}; + +/// Specified <url> | <none> +pub type UrlOrNone = GenericUrlOrNone<SpecifiedUrl>; + +/// Specified image <url> | <none> +pub type ImageUrlOrNone = GenericUrlOrNone<SpecifiedImageUrl>; diff --git a/tests/unit/style/properties/serialization.rs b/tests/unit/style/properties/serialization.rs index bc2bbc70b93..7416ec9d679 100644 --- a/tests/unit/style/properties/serialization.rs +++ b/tests/unit/style/properties/serialization.rs @@ -493,10 +493,9 @@ mod shorthand_serialization { } mod list_style { - use style::properties::longhands::list_style_image::SpecifiedValue as ListStyleImage; use style::properties::longhands::list_style_position::SpecifiedValue as ListStylePosition; use style::properties::longhands::list_style_type::SpecifiedValue as ListStyleType; - use style::values::Either; + use style::values::generics::url::UrlOrNone as ImageUrlOrNone; use super::*; #[test] @@ -504,8 +503,7 @@ mod shorthand_serialization { let mut properties = Vec::new(); let position = ListStylePosition::Inside; - let image = - ListStyleImage(Either::First(SpecifiedUrl::new_for_testing("http://servo/test.png"))); + let image = ImageUrlOrNone::Url(SpecifiedUrl::new_for_testing("http://servo/test.png")); let style_type = ListStyleType::Disc; properties.push(PropertyDeclaration::ListStylePosition(position)); diff --git a/tests/wpt/mozilla/meta/css/get-computed-style-for-url.html.ini b/tests/wpt/mozilla/meta/css/get-computed-style-for-url.html.ini deleted file mode 100644 index 4b9fd22e1df..00000000000 --- a/tests/wpt/mozilla/meta/css/get-computed-style-for-url.html.ini +++ /dev/null @@ -1,10 +0,0 @@ -[get-computed-style-for-url.html] - type: testharness - [getComputedStyle(elem) for url() listStyle uses the resolved URL and elem.style uses the original URL] - expected: FAIL - bug: https://github.com/servo/servo/issues/18015 - - [getComputedStyle(elem) for url() listStyleImage uses the resolved URL and elem.style uses the original URL] - expected: FAIL - bug: https://github.com/servo/servo/issues/18015 - diff --git a/tests/wpt/mozilla/tests/css/get-computed-style-for-url.html b/tests/wpt/mozilla/tests/css/get-computed-style-for-url.html index 06ec9dc5571..d590e40aa9e 100644 --- a/tests/wpt/mozilla/tests/css/get-computed-style-for-url.html +++ b/tests/wpt/mozilla/tests/css/get-computed-style-for-url.html @@ -40,6 +40,29 @@ }, `getComputedStyle(elem) for url() ${property} uses the resolved URL and elem.style uses the original URL`); } + function testNoneForProperty(property) { + test(function() { + var elem = document.createElement("div"); + elem.style[property] = "none"; + container.appendChild(elem); + + assert_equals( + getComputedStyle(elem)[computedPropertyName[property] || property], + "none" + ); + assert_equals( + elem.style[computedPropertyName[property] || property], + "none" + ); + }, `getComputedStyle(elem) and elem.style for url() ${property} correctly return "none"`); + } + + testNoneForProperty("background"); + testNoneForProperty("backgroundImage"); + testNoneForProperty("borderImage"); + testNoneForProperty("listStyle"); + testNoneForProperty("listStyleImage"); + testUrlsForProperty("backgroundImage", "test.jpg"); testUrlsForProperty("background", "test.jpg", "no-repeat"); testUrlsForProperty("borderImage", "test.jpg", "30 round"); |