Bug 1369187: style: Add an API to fast-reject eager pseudos. r?bholley
Also, do nothing for now (we'll hook the Gecko pieces here when the time comes).
Let me know if you want to hold-off landing this.
MozReview-Commit-ID: 6PIhfp6sxk4
--- a/servo/components/style/dom.rs
+++ b/servo/components/style/dom.rs
@@ -377,16 +377,30 @@ pub trait TElement : Eq + PartialEq + De
/// XXX(emilio): It's a bit unfortunate we need to pass the current computed
/// values as an argument here, but otherwise Servo would crash due to
/// double borrows to return it.
fn existing_style_for_restyle_damage<'a>(&'a self,
current_computed_values: &'a ComputedValues,
pseudo: Option<&PseudoElement>)
-> Option<&'a PreExistingComputedValues>;
+ /// Whether a given element may generate a pseudo-element.
+ ///
+ /// This is useful to avoid computing, for example, pseudo styles for
+ /// `::-first-line` or `::-first-letter`, when we know it won't affect us.
+ ///
+ /// TODO(emilio, bz): actually implement the logic for it.
+ fn may_generate_pseudo(
+ &self,
+ _pseudo: &PseudoElement,
+ _primary_style: &ComputedValues,
+ ) -> bool {
+ true
+ }
+
/// Returns true if this element may have a descendant needing style processing.
///
/// Note that we cannot guarantee the existence of such an element, because
/// it may have been removed from the DOM between marking it for restyle and
/// the actual restyle traversal.
fn has_dirty_descendants(&self) -> bool;
/// Returns whether state or attributes that may change style have changed
@@ -439,17 +453,18 @@ pub trait TElement : Eq + PartialEq + De
unsafe fn unset_dirty_descendants(&self);
/// Similar to the dirty_descendants but for representing a descendant of
/// the element needs to be updated in animation-only traversal.
fn has_animation_only_dirty_descendants(&self) -> bool {
false
}
- /// Flag that this element has a descendant for animation-only restyle processing.
+ /// Flag that this element has a descendant for animation-only restyle
+ /// processing.
///
/// Only safe to call with exclusive access to the element.
unsafe fn set_animation_only_dirty_descendants(&self) {
}
/// Flag that this element has no descendant for animation-only restyle processing.
///
/// Only safe to call with exclusive access to the element.
--- a/servo/components/style/matching.rs
+++ b/servo/components/style/matching.rs
@@ -1101,16 +1101,20 @@ pub trait MatchMethods : TElement {
SelectorImpl::each_eagerly_cascaded_pseudo_element(|pseudo| {
// For pseudo-elements, we only try to match visited rules if there
// are also unvisited rules. (This matches Gecko's behavior.)
if visited_handling == VisitedHandlingMode::RelevantLinkVisited &&
!data.styles().pseudos.has(&pseudo) {
return
}
+ if !self.may_generate_pseudo(&pseudo, data.styles().primary.values()) {
+ return;
+ }
+
debug_assert!(applicable_declarations.is_empty());
// NB: We handle animation rules for ::before and ::after when
// traversing them.
stylist.push_applicable_declarations(self,
Some(&pseudo),
None,
None,
AnimationRules(None, None),