style: Use precomputation for the -servo-details-content pseudo-element

This commit is contained in:
Emilio Cobos Álvarez 2016-04-23 01:58:51 +02:00
parent b6402a81d0
commit 3563ecb770
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
4 changed files with 42 additions and 32 deletions

View file

@ -707,10 +707,6 @@ pub trait ThreadSafeLayoutNode : Clone + Copy + Sized + PartialEq {
})
}
// TODO(emilio): Since the ::-details-* pseudos are internal, just affecting
// one element, and only changing `display` property when the element `open`
// attribute changes, this should be eligible for not being cascaded
// eagerly, reading the display property from layout instead.
#[inline]
fn get_details_summary_pseudo(&self) -> Option<Self> {
if self.is_element() &&
@ -729,18 +725,29 @@ pub trait ThreadSafeLayoutNode : Clone + Copy + Sized + PartialEq {
#[inline]
fn get_details_content_pseudo(&self) -> Option<Self> {
if self.is_element() &&
self.as_element().get_local_name() == &atom!("details") &&
self.as_element().get_namespace() == &ns!(html) {
if !self.is_element() {
return None;
}
let element = self.as_element();
if element.get_local_name() != &atom!("details") ||
element.get_namespace() != &ns!(html) {
return None;
}
self.borrow_layout_data().unwrap()
.style_data.per_pseudo
.style_data
.precomputed
.non_eagerly_cascaded_pseudo_elements
.get(&PseudoElement::DetailsContent)
.map(|style| {
self.with_pseudo(PseudoElementType::DetailsContent(style.get_box().display))
})
let display = if element.get_attr(&ns!(), &atom!("open")).is_some() {
style.get_box().display
} else {
None
}
display::T::none
};
self.with_pseudo(PseudoElementType::DetailsContent(display))
})
}
/// Borrows the layout data immutably. Fails on a conflicting borrow.
@ -763,11 +770,19 @@ pub trait ThreadSafeLayoutNode : Clone + Copy + Sized + PartialEq {
fn style(&self) -> Ref<Arc<ServoComputedValues>> {
Ref::map(self.borrow_layout_data().unwrap(), |data| {
let style = match self.get_pseudo_element_type() {
PseudoElementType::Before(_) => data.style_data.per_pseudo.get(&PseudoElement::Before),
PseudoElementType::After(_) => data.style_data.per_pseudo.get(&PseudoElement::After),
PseudoElementType::DetailsSummary(_) => data.style_data.per_pseudo.get(&PseudoElement::DetailsSummary),
PseudoElementType::DetailsContent(_) => data.style_data.per_pseudo.get(&PseudoElement::DetailsContent),
PseudoElementType::Normal => data.style_data.style.as_ref(),
PseudoElementType::Before(_)
=> data.style_data.per_pseudo.get(&PseudoElement::Before),
PseudoElementType::After(_)
=> data.style_data.per_pseudo.get(&PseudoElement::After),
PseudoElementType::DetailsSummary(_)
=> data.style_data.per_pseudo.get(&PseudoElement::DetailsSummary),
PseudoElementType::DetailsContent(_)
=> data.style_data
.precomputed
.non_eagerly_cascaded_pseudo_elements
.get(&PseudoElement::DetailsContent),
PseudoElementType::Normal
=> data.style_data.style.as_ref(),
};
style.unwrap()
})

View file

@ -159,15 +159,14 @@ impl SelectorImpl for ServoSelectorImpl {
impl SelectorImplExt for ServoSelectorImpl {
type ComputedValues = ServoComputedValues;
// TODO: Making details-summary not eagerly cascaded shouldn't be difficult
#[inline]
fn is_eagerly_cascaded_pseudo_element(pseudo: &PseudoElement) -> bool {
match *pseudo {
PseudoElement::Before |
PseudoElement::After |
PseudoElement::Selection |
PseudoElement::DetailsContent |
PseudoElement::DetailsSummary => true,
PseudoElement::DetailsContent => false,
}
}

View file

@ -90,7 +90,7 @@ pub struct PrecomputedStyleData<Impl: SelectorImpl, Computed: ComputedValues> {
/// are eagerly computed once, and then just looked up in the table,
/// since they only appear in rules of the form *|*::pseudo-element
pub non_eagerly_cascaded_pseudo_elements: HashMap<Impl::PseudoElement,
Computed,
Arc<Computed>,
BuildHasherDefault<::fnv::FnvHasher>>,
}
@ -277,7 +277,7 @@ impl<Impl: SelectorImplExt> Stylist<Impl> {
&declarations, false,
None, None,
box StdoutErrorReporter);
precomputed.non_eagerly_cascaded_pseudo_elements.insert(pseudo, computed);
precomputed.non_eagerly_cascaded_pseudo_elements.insert(pseudo, Arc::new(computed));
}
})
}
@ -287,7 +287,7 @@ impl<Impl: SelectorImplExt> Stylist<Impl> {
}
pub fn get_non_eagerly_cascaded_pseudo_element_style(&self,
pseudo: &Impl::PseudoElement) -> Option<Impl::ComputedValues> {
pseudo: &Impl::PseudoElement) -> Option<Arc<Impl::ComputedValues>> {
debug_assert!(!Impl::is_eagerly_cascaded_pseudo_element(pseudo));
self.precomputed
.non_eagerly_cascaded_pseudo_elements

View file

@ -51,15 +51,11 @@ details::-servo-details-summary {
details[open]::-servo-details-summary {
list-style: disclosure-open;
}
details::-servo-details-content {
*|*::-servo-details-content {
margin-left: 40px;
overflow: hidden;
display: none;
}
details[open]::-servo-details-content {
display: block;
}
/*
* Until servo supports svg properly, make sure to at least prevent svg
* children from being layed out and rendered like usual html.