Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate ::before and ::after content for layout_2020 #25817

Merged
merged 5 commits into from Feb 25, 2020

Generate ::before and ::after content from attr() for layout 2020

  • Loading branch information
ferjm committed Feb 25, 2020
commit 5b2d6c81b27dec9abfab5540f8562e2d5314b87c

Some generated files are not rendered by default. Learn more.

@@ -21,6 +21,7 @@ euclid = "0.20"
fnv = "1.0"
gfx = {path = "../gfx"}
gfx_traits = {path = "../gfx_traits"}
html5ever = "0.25"
ipc-channel = "0.14"
libc = "0.2"
msg = {path = "../msg"}
@@ -9,8 +9,11 @@ use crate::replaced::ReplacedContent;
use crate::style_ext::{Display, DisplayGeneratingBox, DisplayInside, DisplayOutside};
use crate::wrapper::GetRawData;
use atomic_refcell::{AtomicRefCell, AtomicRefMut};
use html5ever::LocalName;
use net_traits::image::base::Image as NetImage;
use script_layout_interface::wrapper_traits::{LayoutNode, ThreadSafeLayoutNode};
use script_layout_interface::wrapper_traits::{
LayoutNode, ThreadSafeLayoutElement, ThreadSafeLayoutNode,
};
use servo_arc::Arc as ServoArc;
use std::marker::PhantomData as marker;
use std::sync::Arc;
@@ -253,24 +256,23 @@ fn pseudo_element_style<'dom, Node>(
where
Node: NodeExt<'dom>,
{
if let Some(pseudo_element) = match which {
match which {
WhichPseudoElement::Before => element.to_threadsafe().get_before_pseudo(),
WhichPseudoElement::After => element.to_threadsafe().get_after_pseudo(),
} {
}
.and_then(|pseudo_element| {
let style = pseudo_element.style(context.shared_context());
if style.ineffective_content_property() {
None
} else {
Some(style)
}
} else {
None
}
})
}

fn generate_pseudo_element_content<'dom, Node>(
pseudo_element_style: &ComputedValues,
_element: Node,
element: Node,
_context: &LayoutContext,
) -> Vec<PseudoElementContentItem>
where
@@ -282,14 +284,25 @@ where
for item in items.iter() {
match item {
ContentItem::String(s) => {
vec.push(PseudoElementContentItem::Text(s.to_string()))
vec.push(PseudoElementContentItem::Text(s.to_string()));
},
ContentItem::Attr(attr) => {
let element = element
.to_threadsafe()
.as_element()
.expect("Expected an element");
let attr_val = element
.get_attr(&attr.namespace_url, &LocalName::from(&*attr.attribute));
vec.push(PseudoElementContentItem::Text(
attr_val.map_or("".to_string(), |s| s.to_string()),
));
},
_ => unimplemented!(),
_ => (),
}
}
vec
},
_ => vec![],
Content::Normal | Content::None => unreachable!(),
}
}

@@ -8,7 +8,7 @@
use crate::computed_values::list_style_type::T as ListStyleType;
#[cfg(feature = "gecko")]
use crate::values::generics::CounterStyle;
#[cfg(feature = "gecko")]
This conversation was marked as resolved by SimonSapin

This comment has been minimized.

Copy link
@SimonSapin

SimonSapin Feb 20, 2020

Member

This and other cfgs changed here should probably be something like #[cfg(any(feature = "gecko", feature = "servo-layout-2020"))], since layout 2013 still doesn’t support this.

#[cfg(any(feature = "gecko", feature = "servo-layout-2020"))]
use crate::values::specified::Attr;
use crate::values::CustomIdent;
use std::ops::Deref;
@@ -212,7 +212,7 @@ pub enum GenericContentItem<ImageUrl> {
#[cfg(feature = "gecko")]
MozAltContent,
/// `attr([namespace? `|`]? ident)`
#[cfg(feature = "gecko")]
#[cfg(any(feature = "gecko", feature = "servo-layout-2020"))]
Attr(Attr),
/// `url(url)`
Url(ImageUrl),
@@ -12,7 +12,7 @@ use crate::values::generics::counters::CounterPair;
#[cfg(feature = "gecko")]
use crate::values::generics::CounterStyle;
use crate::values::specified::url::SpecifiedImageUrl;
#[cfg(feature = "gecko")]
#[cfg(any(feature = "gecko", feature = "servo-layout-2020"))]
use crate::values::specified::Attr;
use crate::values::specified::Integer;
use crate::values::CustomIdent;
@@ -163,7 +163,7 @@ impl Parse for Content {
let style = Content::parse_counter_style(context, input);
Ok(generics::ContentItem::Counters(name, separator, style))
}),
#[cfg(feature = "gecko")]
#[cfg(any(feature = "gecko", feature = "servo-layout-2020"))]
"attr" => input.parse_nested_block(|input| {
Ok(generics::ContentItem::Attr(Attr::parse_function(context, input)?))
}),
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.