diff --git a/components/layout/display_list/builder.rs b/components/layout/display_list/builder.rs index 17f946f7187..2c0f6d612e1 100644 --- a/components/layout/display_list/builder.rs +++ b/components/layout/display_list/builder.rs @@ -60,10 +60,10 @@ use style::logical_geometry::{LogicalMargin, LogicalPoint, LogicalRect}; use style::properties::{style_structs, ComputedValues}; use style::servo::restyle_damage::ServoRestyleDamage; use style::values::computed::effects::SimpleShadow; -use style::values::computed::image::{Image, ImageLayer}; +use style::values::computed::image::Image; use style::values::computed::{ClipRectOrAuto, Gradient, LengthOrAuto}; use style::values::generics::background::BackgroundSize; -use style::values::generics::image::{GradientKind, PaintWorklet}; +use style::values::generics::image::PaintWorklet; use style::values::specified::ui::CursorKind; use style::values::RGBA; use style_traits::ToCss; @@ -732,12 +732,8 @@ impl Fragment { // http://www.w3.org/TR/CSS21/colors.html#background let background = style.get_background(); for (i, background_image) in background.background_image.0.iter().enumerate().rev() { - let background_image = match *background_image { - ImageLayer::None => continue, - ImageLayer::Image(ref image) => image, - }; - match *background_image { + Image::None => {}, Image::Gradient(ref gradient) => { self.build_display_list_for_background_gradient( state, @@ -975,15 +971,15 @@ impl Fragment { display_list_section, ); - let display_item = match gradient.kind { - GradientKind::Linear(angle_or_corner) => { - let (gradient, stops) = gradient::linear( - style, - placement.tile_size, - &gradient.items[..], - angle_or_corner, - gradient.repeating, - ); + let display_item = match gradient { + Gradient::Linear { + ref direction, + ref items, + ref repeating, + compat_mode: _, + } => { + let (gradient, stops) = + gradient::linear(style, placement.tile_size, items, *direction, *repeating); let item = webrender_api::GradientDisplayItem { gradient, bounds: placement.bounds.to_f32_px(), @@ -993,14 +989,20 @@ impl Fragment { }; DisplayItem::Gradient(CommonDisplayItem::with_data(base, item, stops)) }, - GradientKind::Radial(ref shape, ref center) => { + Gradient::Radial { + ref shape, + ref position, + ref items, + ref repeating, + compat_mode: _, + } => { let (gradient, stops) = gradient::radial( style, placement.tile_size, - &gradient.items[..], + items, shape, - center, - gradient.repeating, + position, + *repeating, ); let item = webrender_api::RadialGradientDisplayItem { gradient, @@ -1011,6 +1013,7 @@ impl Fragment { }; DisplayItem::RadialGradient(CommonDisplayItem::with_data(base, item, stops)) }, + Gradient::Conic { .. } => unimplemented!(), }; state.add_display_item(display_item); }); @@ -1122,22 +1125,20 @@ impl Fragment { let border_radius = border::radii(bounds, border_style_struct); let border_widths = border.to_physical(style.writing_mode); - if let ImageLayer::Image(ref image) = border_style_struct.border_image_source { - if self - .build_display_list_for_border_image( - state, - style, - base.clone(), - bounds, - image, - border_widths, - ) - .is_some() - { - return; - } - // Fallback to rendering a solid border. + if self + .build_display_list_for_border_image( + state, + style, + base.clone(), + bounds, + &border_style_struct.border_image_source, + border_widths, + ) + .is_some() + { + return; } + if border_widths == SideOffsets2D::zero() { return; } @@ -1224,30 +1225,37 @@ impl Fragment { height = image.height; NinePatchBorderSource::Image(image.key?) }, - Image::Gradient(ref gradient) => match gradient.kind { - GradientKind::Linear(angle_or_corner) => { - let (wr_gradient, linear_stops) = gradient::linear( - style, - border_image_area, - &gradient.items[..], - angle_or_corner, - gradient.repeating, - ); + Image::Gradient(ref gradient) => match **gradient { + Gradient::Linear { + ref direction, + ref items, + ref repeating, + compat_mode: _, + } => { + let (wr_gradient, linear_stops) = + gradient::linear(style, border_image_area, items, *direction, *repeating); stops = linear_stops; NinePatchBorderSource::Gradient(wr_gradient) }, - GradientKind::Radial(ref shape, ref center) => { + Gradient::Radial { + ref shape, + ref position, + ref items, + ref repeating, + compat_mode: _, + } => { let (wr_gradient, radial_stops) = gradient::radial( style, border_image_area, - &gradient.items[..], + items, shape, - center, - gradient.repeating, + position, + *repeating, ); stops = radial_stops; NinePatchBorderSource::RadialGradient(wr_gradient) }, + Gradient::Conic { .. } => unimplemented!(), }, _ => return None, }; diff --git a/components/layout/display_list/gradient.rs b/components/layout/display_list/gradient.rs index e683bbb963c..b816bca753f 100644 --- a/components/layout/display_list/gradient.rs +++ b/components/layout/display_list/gradient.rs @@ -7,8 +7,8 @@ use app_units::Au; use euclid::default::{Point2D, Size2D, Vector2D}; use style::properties::ComputedValues; use style::values::computed::image::{EndingShape, LineDirection}; -use style::values::computed::{Angle, GradientItem, LengthPercentage, Percentage, Position}; -use style::values::generics::image::{Circle, ColorStop, Ellipse, ShapeExtent}; +use style::values::computed::{Angle, Color, LengthPercentage, Percentage, Position}; +use style::values::generics::image::{Circle, ColorStop, Ellipse, GradientItem, ShapeExtent}; use webrender_api::{ExtendMode, Gradient, GradientBuilder, GradientStop, RadialGradient}; /// A helper data structure for gradients. @@ -78,7 +78,7 @@ fn ellipse_size_keyword( fn convert_gradient_stops( style: &ComputedValues, - gradient_items: &[GradientItem], + gradient_items: &[GradientItem], total_length: Au, ) -> GradientBuilder { // Determine the position of each stop per CSS-IMAGES § 3.4. @@ -237,7 +237,7 @@ fn position_to_offset(position: &LengthPercentage, total_length: Au) -> f32 { pub fn linear( style: &ComputedValues, size: Size2D, - stops: &[GradientItem], + stops: &[GradientItem], direction: LineDirection, repeating: bool, ) -> (Gradient, Vec) { @@ -303,7 +303,7 @@ pub fn linear( pub fn radial( style: &ComputedValues, size: Size2D, - stops: &[GradientItem], + stops: &[GradientItem], shape: &EndingShape, center: &Position, repeating: bool, diff --git a/components/layout_2020/display_list/gradient.rs b/components/layout_2020/display_list/gradient.rs index f1e5c1a3c1a..09f5be610c2 100644 --- a/components/layout_2020/display_list/gradient.rs +++ b/components/layout_2020/display_list/gradient.rs @@ -4,9 +4,8 @@ use style::properties::ComputedValues; use style::values::computed::image::{EndingShape, Gradient, LineDirection}; -use style::values::computed::{GradientItem, Length, Position}; -use style::values::generics::image::GenericGradientKind as Kind; -use style::values::generics::image::{Circle, ColorStop, Ellipse, ShapeExtent}; +use style::values::computed::{Color, Length, LengthPercentage, Position}; +use style::values::generics::image::{Circle, ColorStop, Ellipse, GradientItem, ShapeExtent}; use webrender_api::{self as wr, units}; pub(super) fn build( @@ -15,36 +14,51 @@ pub(super) fn build( layer: &super::background::BackgroundLayer, builder: &mut super::DisplayListBuilder, ) { - let extend_mode = if gradient.repeating { - wr::ExtendMode::Repeat - } else { - wr::ExtendMode::Clamp - }; - match &gradient.kind { - Kind::Linear(line_direction) => build_linear( + match gradient { + Gradient::Linear { + ref items, + ref direction, + ref repeating, + compat_mode: _, + } => build_linear( style, - &gradient.items, - line_direction, - extend_mode, + items, + direction, + if *repeating { + wr::ExtendMode::Repeat + } else { + wr::ExtendMode::Clamp + }, &layer, builder, ), - Kind::Radial(ending_shape, center) => build_radial( + Gradient::Radial { + ref shape, + ref position, + ref items, + ref repeating, + compat_mode: _, + } => build_radial( style, - &gradient.items, - ending_shape, - center, - extend_mode, + items, + shape, + position, + if *repeating { + wr::ExtendMode::Repeat + } else { + wr::ExtendMode::Clamp + }, &layer, builder, ), + Gradient::Conic { .. } => unimplemented!(), } } /// https://drafts.csswg.org/css-images-3/#linear-gradients pub(super) fn build_linear( style: &ComputedValues, - items: &[GradientItem], + items: &[GradientItem], line_direction: &LineDirection, extend_mode: wr::ExtendMode, layer: &super::background::BackgroundLayer, @@ -144,7 +158,7 @@ pub(super) fn build_linear( /// https://drafts.csswg.org/css-images-3/#radial-gradients pub(super) fn build_radial( style: &ComputedValues, - items: &[GradientItem], + items: &[GradientItem], shape: &EndingShape, center: &Position, extend_mode: wr::ExtendMode, @@ -244,7 +258,7 @@ pub(super) fn build_radial( /// https://drafts.csswg.org/css-images-4/#color-stop-fixup fn fixup_stops( style: &ComputedValues, - items: &[GradientItem], + items: &[GradientItem], gradient_line_length: Length, ) -> Vec { // Remove color transititon hints, which are not supported yet. diff --git a/components/layout_2020/display_list/mod.rs b/components/layout_2020/display_list/mod.rs index dccee5ea71a..af0797d30b6 100644 --- a/components/layout_2020/display_list/mod.rs +++ b/components/layout_2020/display_list/mod.rs @@ -333,7 +333,7 @@ impl<'a> BuilderForBoxFragment<'a> { } fn build_background(&mut self, builder: &mut DisplayListBuilder) { - use style::values::computed::image::{Image, ImageLayer}; + use style::values::computed::image::Image; let b = self.fragment.style.get_background(); let background_color = self.fragment.style.resolve_color(b.background_color); if background_color.alpha > 0 { @@ -345,85 +345,80 @@ impl<'a> BuilderForBoxFragment<'a> { builder.wr.push_rect(&common, rgba(background_color)) } // Reverse because the property is top layer first, we want to paint bottom layer first. - for (index, layer) in b.background_image.0.iter().enumerate().rev() { - match layer { - ImageLayer::None => {}, - ImageLayer::Image(image) => match image { - Image::Gradient(gradient) => { - let intrinsic = IntrinsicSizes { - width: None, - height: None, - ratio: None, - }; - if let Some(layer) = - &background::layout_layer(self, builder, index, intrinsic) - { - gradient::build(&self.fragment.style, gradient, layer, builder) - } - }, - Image::Url(image_url) => { - // FIXME: images won’t always have in intrinsic width or height - // when support for SVG is added. - // Or a WebRender `ImageKey`, for that matter. - let (width, height, key) = match image_url.url() { - Some(url) => { - match builder.context.get_webrender_image_for_url( - self.fragment.tag, - url.clone(), - UsePlaceholder::No, - ) { - Some(WebRenderImageInfo { - width, - height, - key: Some(key), - }) => (width, height, key), - _ => continue, - } - }, - None => continue, - }; - - // FIXME: https://drafts.csswg.org/css-images-4/#the-image-resolution - let dppx = 1.0; - - let intrinsic = IntrinsicSizes { - width: Some(Length::new(width as f32 / dppx)), - height: Some(Length::new(height as f32 / dppx)), - // FIXME https://github.com/w3c/csswg-drafts/issues/4572 - ratio: Some(width as f32 / height as f32), - }; - - if let Some(layer) = - background::layout_layer(self, builder, index, intrinsic) - { - let image_rendering = - image_rendering(self.fragment.style.clone_image_rendering()); - if layer.repeat { - builder.wr.push_repeating_image( - &layer.common, - layer.bounds, - layer.tile_size, - layer.tile_spacing, - image_rendering, - wr::AlphaType::PremultipliedAlpha, - key, - wr::ColorF::WHITE, - ) - } else { - builder.wr.push_image( - &layer.common, - layer.bounds, - image_rendering, - wr::AlphaType::PremultipliedAlpha, - key, - wr::ColorF::WHITE, - ) - } - } - }, - // Gecko-only value, represented as a (boxed) empty enum on non-Gecko. - Image::Rect(rect) => match **rect {}, + for (index, image) in b.background_image.0.iter().enumerate().rev() { + match image { + Image::None => {}, + Image::Gradient(ref gradient) => { + let intrinsic = IntrinsicSizes { + width: None, + height: None, + ratio: None, + }; + if let Some(layer) = &background::layout_layer(self, builder, index, intrinsic) + { + gradient::build(&self.fragment.style, &gradient, layer, builder) + } }, + Image::Url(ref image_url) => { + // FIXME: images won’t always have in intrinsic width or height + // when support for SVG is added. + // Or a WebRender `ImageKey`, for that matter. + let (width, height, key) = match image_url.url() { + Some(url) => { + match builder.context.get_webrender_image_for_url( + self.fragment.tag, + url.clone(), + UsePlaceholder::No, + ) { + Some(WebRenderImageInfo { + width, + height, + key: Some(key), + }) => (width, height, key), + _ => continue, + } + }, + None => continue, + }; + + // FIXME: https://drafts.csswg.org/css-images-4/#the-image-resolution + let dppx = 1.0; + + let intrinsic = IntrinsicSizes { + width: Some(Length::new(width as f32 / dppx)), + height: Some(Length::new(height as f32 / dppx)), + // FIXME https://github.com/w3c/csswg-drafts/issues/4572 + ratio: Some(width as f32 / height as f32), + }; + + if let Some(layer) = background::layout_layer(self, builder, index, intrinsic) { + let image_rendering = + image_rendering(self.fragment.style.clone_image_rendering()); + if layer.repeat { + builder.wr.push_repeating_image( + &layer.common, + layer.bounds, + layer.tile_size, + layer.tile_spacing, + image_rendering, + wr::AlphaType::PremultipliedAlpha, + key, + wr::ColorF::WHITE, + ) + } else { + builder.wr.push_image( + &layer.common, + layer.bounds, + image_rendering, + wr::AlphaType::PremultipliedAlpha, + key, + wr::ColorF::WHITE, + ) + } + } + }, + // Gecko-only value, represented as a (boxed) empty enum on non-Gecko. + Image::Rect(ref rect) => match **rect {}, } } } diff --git a/components/layout_thread/dom_wrapper.rs b/components/layout_thread/dom_wrapper.rs index 064ceb5148e..1ec4c92fcf0 100644 --- a/components/layout_thread/dom_wrapper.rs +++ b/components/layout_thread/dom_wrapper.rs @@ -914,10 +914,6 @@ impl<'le> ::selectors::Element for ServoLayoutElement<'le> { false } - fn exported_part(&self, _: &Atom) -> Option { - None - } - fn imported_part(&self, _: &Atom) -> Option { None } @@ -1441,11 +1437,6 @@ impl<'le> ::selectors::Element for ServoThreadSafeLayoutElement<'le> { false } - fn exported_part(&self, _: &Atom) -> Option { - debug!("ServoThreadSafeLayoutElement::exported_part called"); - None - } - fn imported_part(&self, _: &Atom) -> Option { debug!("ServoThreadSafeLayoutElement::imported_part called"); None diff --git a/components/layout_thread_2020/dom_wrapper.rs b/components/layout_thread_2020/dom_wrapper.rs index 92a9f3f005b..7b1da3454a0 100644 --- a/components/layout_thread_2020/dom_wrapper.rs +++ b/components/layout_thread_2020/dom_wrapper.rs @@ -922,10 +922,6 @@ impl<'le> ::selectors::Element for ServoLayoutElement<'le> { false } - fn exported_part(&self, _: &Atom) -> Option { - None - } - fn imported_part(&self, _: &Atom) -> Option { None } @@ -1447,11 +1443,6 @@ impl<'le> ::selectors::Element for ServoThreadSafeLayoutElement<'le> { false } - fn exported_part(&self, _: &Atom) -> Option { - debug!("ServoThreadSafeLayoutElement::exported_part called"); - None - } - fn imported_part(&self, _: &Atom) -> Option { debug!("ServoThreadSafeLayoutElement::imported_part called"); None diff --git a/components/script/dom/cssrulelist.rs b/components/script/dom/cssrulelist.rs index 18a41857923..812434fd180 100644 --- a/components/script/dom/cssrulelist.rs +++ b/components/script/dom/cssrulelist.rs @@ -17,7 +17,9 @@ use crate::stylesheet_loader::StylesheetLoader; use dom_struct::dom_struct; use servo_arc::Arc; use style::shared_lock::Locked; -use style::stylesheets::{CssRules, CssRulesHelpers, KeyframesRule, RulesMutateError}; +use style::stylesheets::{ + AllowImportRules, CssRules, CssRulesHelpers, KeyframesRule, RulesMutateError, +}; #[allow(unsafe_code)] unsafe_no_jsmanaged_fields!(RulesSource); @@ -116,6 +118,7 @@ impl CSSRuleList { index, nested, Some(&loader), + AllowImportRules::Yes, ) })?; diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index 2fd6780cab0..baccc4e65aa 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -682,10 +682,7 @@ impl<'dom> LayoutElementHelpers<'dom> for LayoutDom<'dom, Element> { hints.push(from_declaration( shared_lock, PropertyDeclaration::BackgroundImage(background_image::SpecifiedValue( - vec![specified::ImageLayer::Image(specified::Image::for_cascade( - url.into(), - ))] - .into(), + vec![specified::Image::for_cascade(url.into())].into(), )), )); } @@ -3164,10 +3161,6 @@ impl<'a> SelectorsElement for DomRoot { false } - fn exported_part(&self, _: &Atom) -> Option { - None - } - fn imported_part(&self, _: &Atom) -> Option { None } diff --git a/components/script/dom/htmlstyleelement.rs b/components/script/dom/htmlstyleelement.rs index afa99d8d86b..6d10b0838f7 100644 --- a/components/script/dom/htmlstyleelement.rs +++ b/components/script/dom/htmlstyleelement.rs @@ -26,7 +26,7 @@ use servo_arc::Arc; use std::cell::Cell; use style::media_queries::MediaList; use style::parser::ParserContext as CssParserContext; -use style::stylesheets::{CssRuleType, Origin, Stylesheet}; +use style::stylesheets::{AllowImportRules, CssRuleType, Origin, Stylesheet}; use style_traits::ParsingMode; #[dom_struct] @@ -119,6 +119,7 @@ impl HTMLStyleElement { css_error_reporter, doc.quirks_mode(), self.line_number as u32, + AllowImportRules::Yes, ); let sheet = Arc::new(sheet); diff --git a/components/style/encoding_support.rs b/components/style/encoding_support.rs index 5544487179f..1ba92953bb9 100644 --- a/components/style/encoding_support.rs +++ b/components/style/encoding_support.rs @@ -10,7 +10,7 @@ use crate::context::QuirksMode; use crate::error_reporting::ParseErrorReporter; use crate::media_queries::MediaList; use crate::shared_lock::SharedRwLock; -use crate::stylesheets::{Origin, Stylesheet, StylesheetLoader, UrlExtraData}; +use crate::stylesheets::{AllowImportRules, Origin, Stylesheet, StylesheetLoader, UrlExtraData}; use cssparser::{stylesheet_encoding, EncodingSupport}; use servo_arc::Arc; use std::borrow::Cow; @@ -78,6 +78,7 @@ impl Stylesheet { error_reporter, quirks_mode, 0, + AllowImportRules::Yes, ) } @@ -100,6 +101,7 @@ impl Stylesheet { stylesheet_loader, error_reporter, 0, + AllowImportRules::Yes, ) } } diff --git a/components/style/values/computed/mod.rs b/components/style/values/computed/mod.rs index 2a7a200dc95..841cc3df22a 100644 --- a/components/style/values/computed/mod.rs +++ b/components/style/values/computed/mod.rs @@ -21,8 +21,6 @@ use crate::media_queries::Device; use crate::properties; use crate::properties::{ComputedValues, LonghandId, StyleBuilder}; use crate::rule_cache::RuleCacheConditions; -#[cfg(feature = "servo")] -use crate::Prefix; use crate::{ArcSlice, Atom}; use euclid::default::Size2D; use servo_arc::Arc; @@ -501,7 +499,9 @@ trivial_to_computed_value!(u32); trivial_to_computed_value!(usize); trivial_to_computed_value!(Atom); #[cfg(feature = "servo")] -trivial_to_computed_value!(Prefix); +trivial_to_computed_value!(html5ever::Namespace); +#[cfg(feature = "servo")] +trivial_to_computed_value!(html5ever::Prefix); trivial_to_computed_value!(String); trivial_to_computed_value!(Box); trivial_to_computed_value!(crate::OwnedStr); diff --git a/components/style/values/resolved/mod.rs b/components/style/values/resolved/mod.rs index 633bcd47997..45cc5cbd8cf 100644 --- a/components/style/values/resolved/mod.rs +++ b/components/style/values/resolved/mod.rs @@ -79,6 +79,8 @@ trivial_to_resolved_value!(computed::url::ComputedUrl); #[cfg(feature = "gecko")] trivial_to_resolved_value!(computed::url::ComputedImageUrl); #[cfg(feature = "servo")] +trivial_to_resolved_value!(html5ever::Namespace); +#[cfg(feature = "servo")] trivial_to_resolved_value!(html5ever::Prefix); trivial_to_resolved_value!(computed::LengthPercentage); trivial_to_resolved_value!(style_traits::values::specified::AllowedNumericType); diff --git a/components/style/values/specified/image.rs b/components/style/values/specified/image.rs index 1de62bb613d..59250c45a6f 100644 --- a/components/style/values/specified/image.rs +++ b/components/style/values/specified/image.rs @@ -52,6 +52,16 @@ pub type Gradient = generic::Gradient< type LengthPercentageItemList = crate::OwnedSlice>; +#[cfg(feature = "gecko")] +fn conic_gradients_enabled() -> bool { + static_prefs::pref!("layout.css.conic-gradient.enabled") +} + +#[cfg(feature = "servo")] +fn conic_gradients_enabled() -> bool { + false +} + impl SpecifiedValueInfo for Gradient { const SUPPORTED_TYPES: u8 = CssType::GRADIENT; @@ -73,7 +83,7 @@ impl SpecifiedValueInfo for Gradient { "-webkit-gradient", ]); - if static_prefs::pref!("layout.css.conic-gradient.enabled") { + if conic_gradients_enabled() { f(&["conic-gradient", "repeating-conic-gradient"]); } } @@ -240,10 +250,10 @@ impl Parse for Gradient { "-moz-repeating-radial-gradient" => { (Shape::Radial, true, GradientCompatMode::Moz) }, - "conic-gradient" if static_prefs::pref!("layout.css.conic-gradient.enabled") => { + "conic-gradient" if conic_gradients_enabled() => { (Shape::Conic, false, GradientCompatMode::Modern) }, - "repeating-conic-gradient" if static_prefs::pref!("layout.css.conic-gradient.enabled") => { + "repeating-conic-gradient" if conic_gradients_enabled() => { (Shape::Conic, true, GradientCompatMode::Modern) }, "-webkit-gradient" => {