Generate ::before and ::after content from url() for layout2020

This commit is contained in:
Fernando Jiménez Moreno 2020-02-28 11:44:23 +01:00
parent 756cf66cd2
commit dc9a33f3a9
5 changed files with 46 additions and 6 deletions

View file

@ -271,10 +271,11 @@ where
})
}
/// https://www.w3.org/TR/CSS2/generate.html#propdef-content
fn generate_pseudo_element_content<'dom, Node>(
pseudo_element_style: &ComputedValues,
element: Node,
_context: &LayoutContext,
context: &LayoutContext,
) -> Vec<PseudoElementContentItem>
where
Node: NodeExt<'dom>,
@ -298,6 +299,13 @@ where
attr_val.map_or("".to_string(), |s| s.to_string()),
));
},
ContentItem::Url(image_url) => {
if let Some(replaced_content) =
ReplacedContent::from_image_url(element, context, image_url)
{
vec.push(PseudoElementContentItem::Replaced(replaced_content));
}
},
_ => (),
}
}

View file

@ -2,6 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use crate::context::LayoutContext;
use crate::dom_traversal::NodeExt;
use crate::fragments::{DebugId, Fragment, ImageFragment};
use crate::geom::flow_relative::{Rect, Vec2};
@ -10,9 +11,11 @@ use crate::sizing::ContentSizes;
use crate::style_ext::ComputedValuesExt;
use crate::ContainingBlock;
use net_traits::image::base::Image;
use net_traits::image_cache::{ImageOrMetadataAvailable, UsePlaceholder};
use servo_arc::Arc as ServoArc;
use std::sync::Arc;
use style::properties::ComputedValues;
use style::servo::url::ComputedUrl;
use style::values::computed::{Length, LengthOrAuto};
use style::values::CSSFloat;
use style::Zero;
@ -70,6 +73,39 @@ impl ReplacedContent {
None
}
pub fn from_image_url<'dom>(
element: impl NodeExt<'dom>,
context: &LayoutContext,
image_url: &ComputedUrl,
) -> Option<Self> {
if let ComputedUrl::Valid(image_url) = image_url {
let (image, width, height) = match context.get_or_request_image_or_meta(
element.as_opaque(),
image_url.clone(),
UsePlaceholder::No,
) {
Some(ImageOrMetadataAvailable::ImageAvailable(image, _)) => {
(Some(image.clone()), image.width as f32, image.height as f32)
},
Some(ImageOrMetadataAvailable::MetadataAvailable(metadata)) => {
(None, metadata.width as f32, metadata.height as f32)
},
None => return None,
};
return Some(Self {
kind: ReplacedContentKind::Image(image),
intrinsic: IntrinsicSizes {
width: Some(Length::new(width)),
height: Some(Length::new(height)),
// FIXME https://github.com/w3c/csswg-drafts/issues/4572
ratio: Some(width / height),
},
});
}
None
}
fn flow_relative_intrinsic_size(&self, style: &ComputedValues) -> Vec2<Option<Length>> {
let intrinsic_size = PhysicalSize::new(self.intrinsic.width, self.intrinsic.height);
Vec2::from_physical_size(&intrinsic_size, style.writing_mode)

View file

@ -134,7 +134,7 @@ impl Parse for Content {
let mut content = vec![];
let mut has_alt_content = false;
loop {
#[cfg(feature = "gecko")]
#[cfg(any(feature = "gecko", feature = "servo-layout-2020"))]
{
if let Ok(url) = input.try(|i| SpecifiedImageUrl::parse(context, i)) {
content.push(generics::ContentItem::Url(url));

View file

@ -1,2 +0,0 @@
[content-004.xht]
expected: FAIL

View file

@ -1,2 +0,0 @@
[pseudo-element-inline-box.html]
expected: FAIL