servo: Merge #18876 - style: Do not expose LocalMatchingContext (from emilio:die-localmatchingcontext-die); r=SimonSapin

This type is a lot of complexity related to a very specific thing such as the
hover and active quirk.

Instead of that, move `nesting_level` to `MatchingContext`, and simplify all
this computing whether the quirk applies upfront, for each complex selector we
test.

This is less error-prone, and also allows simplifying more stuff in a bit.

Also, this makes the hover and active quirk work in Servo with no extra effort.

Source-Repo: https://github.com/servo/servo
Source-Revision: a200fb4b9df4e7461b4238fe3a6d49881f438e25

--HG--
extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear
extra : subtree_revision : c0a047588e31497a14824809f41259847da86768
This commit is contained in:
Emilio Cobos Álvarez 2017-10-15 02:21:47 -05:00
Родитель c3bed650ca
Коммит 4484d6d979
8 изменённых файлов: 256 добавлений и 255 удалений

Просмотреть файл

@ -51,7 +51,7 @@ use script_layout_interface::{OpaqueStyleAndLayoutData, StyleData};
use script_layout_interface::wrapper_traits::{DangerousThreadSafeLayoutNode, GetLayoutData, LayoutNode}; use script_layout_interface::wrapper_traits::{DangerousThreadSafeLayoutNode, GetLayoutData, LayoutNode};
use script_layout_interface::wrapper_traits::{PseudoElementType, ThreadSafeLayoutElement, ThreadSafeLayoutNode}; use script_layout_interface::wrapper_traits::{PseudoElementType, ThreadSafeLayoutElement, ThreadSafeLayoutNode};
use selectors::attr::{AttrSelectorOperation, NamespaceConstraint, CaseSensitivity}; use selectors::attr::{AttrSelectorOperation, NamespaceConstraint, CaseSensitivity};
use selectors::matching::{ElementSelectorFlags, LocalMatchingContext, MatchingContext, RelevantLinkStatus}; use selectors::matching::{ElementSelectorFlags, MatchingContext, RelevantLinkStatus};
use selectors::matching::VisitedHandlingMode; use selectors::matching::VisitedHandlingMode;
use selectors::sink::Push; use selectors::sink::Push;
use servo_arc::{Arc, ArcBorrow}; use servo_arc::{Arc, ArcBorrow};
@ -720,7 +720,7 @@ impl<'le> ::selectors::Element for ServoLayoutElement<'le> {
fn match_non_ts_pseudo_class<F>(&self, fn match_non_ts_pseudo_class<F>(&self,
pseudo_class: &NonTSPseudoClass, pseudo_class: &NonTSPseudoClass,
_: &mut LocalMatchingContext<Self::Impl>, _: &mut MatchingContext,
_: &RelevantLinkStatus, _: &RelevantLinkStatus,
_: &mut F) _: &mut F)
-> bool -> bool
@ -1240,7 +1240,7 @@ impl<'le> ::selectors::Element for ServoThreadSafeLayoutElement<'le> {
fn match_non_ts_pseudo_class<F>(&self, fn match_non_ts_pseudo_class<F>(&self,
_: &NonTSPseudoClass, _: &NonTSPseudoClass,
_: &mut LocalMatchingContext<Self::Impl>, _: &mut MatchingContext,
_: &RelevantLinkStatus, _: &RelevantLinkStatus,
_: &mut F) _: &mut F)
-> bool -> bool

Просмотреть файл

@ -89,7 +89,7 @@ use script_layout_interface::message::ReflowGoal;
use script_thread::ScriptThread; use script_thread::ScriptThread;
use selectors::Element as SelectorsElement; use selectors::Element as SelectorsElement;
use selectors::attr::{AttrSelectorOperation, NamespaceConstraint, CaseSensitivity}; use selectors::attr::{AttrSelectorOperation, NamespaceConstraint, CaseSensitivity};
use selectors::matching::{ElementSelectorFlags, LocalMatchingContext, MatchingContext, RelevantLinkStatus}; use selectors::matching::{ElementSelectorFlags, MatchingContext, MatchingMode, RelevantLinkStatus};
use selectors::matching::{HAS_EDGE_CHILD_SELECTOR, HAS_SLOW_SELECTOR, HAS_SLOW_SELECTOR_LATER_SIBLINGS}; use selectors::matching::{HAS_EDGE_CHILD_SELECTOR, HAS_SLOW_SELECTOR, HAS_SLOW_SELECTOR_LATER_SIBLINGS};
use selectors::sink::Push; use selectors::sink::Push;
use servo_arc::Arc; use servo_arc::Arc;
@ -2583,7 +2583,7 @@ impl<'a> SelectorsElement for DomRoot<Element> {
fn match_non_ts_pseudo_class<F>(&self, fn match_non_ts_pseudo_class<F>(&self,
pseudo_class: &NonTSPseudoClass, pseudo_class: &NonTSPseudoClass,
_: &mut LocalMatchingContext<Self::Impl>, _: &mut MatchingContext,
_: &RelevantLinkStatus, _: &RelevantLinkStatus,
_: &mut F) _: &mut F)
-> bool -> bool

Просмотреть файл

@ -102,6 +102,9 @@ pub struct MatchingContext<'a> {
/// See https://drafts.csswg.org/selectors-4/#scope-pseudo /// See https://drafts.csswg.org/selectors-4/#scope-pseudo
pub scope_element: Option<OpaqueElement>, pub scope_element: Option<OpaqueElement>,
/// The current nesting level of selectors that we're matching.
pub nesting_level: usize,
quirks_mode: QuirksMode, quirks_mode: QuirksMode,
classes_and_ids_case_sensitivity: CaseSensitivity, classes_and_ids_case_sensitivity: CaseSensitivity,
} }
@ -140,6 +143,7 @@ impl<'a> MatchingContext<'a> {
relevant_link_found: false, relevant_link_found: false,
classes_and_ids_case_sensitivity: quirks_mode.classes_and_ids_case_sensitivity(), classes_and_ids_case_sensitivity: quirks_mode.classes_and_ids_case_sensitivity(),
scope_element: None, scope_element: None,
nesting_level: 0,
} }
} }

Просмотреть файл

@ -54,116 +54,19 @@ impl ElementSelectorFlags {
} }
} }
/// Holds per-selector data alongside a pointer to MatchingContext. /// Holds per-compound-selector data.
pub struct LocalMatchingContext<'a, 'b: 'a, Impl: SelectorImpl> { struct LocalMatchingContext<'a, 'b: 'a> {
/// Shared `MatchingContext`. shared: &'a mut MatchingContext<'b>,
pub shared: &'a mut MatchingContext<'b>, matches_hover_and_active_quirk: bool,
/// A reference to the base selector we're matching against.
pub selector: &'a Selector<Impl>,
/// The offset of the current compound selector being matched, kept up to
/// date by the callees when the iterator is advanced. This, in conjunction
/// with the selector reference above, allows callees to synthesize an
/// iterator for the current compound selector on-demand. This is necessary
/// because the primary iterator may already have been advanced partway
/// through the current compound selector, and the callee may need the whole
/// thing.
offset: usize,
/// The level of nesting for the selector being matched.
pub nesting_level: usize,
/// Holds a bool flag to see whether :active and :hover quirk should try to
/// match or not. This flag can only be true in the case PseudoElements are
/// encountered when matching mode is ForStatelessPseudoElement.
pub hover_active_quirk_disabled: bool,
} }
impl<'a, 'b, Impl> LocalMatchingContext<'a, 'b, Impl> pub fn matches_selector_list<E>(
where Impl: SelectorImpl selector_list: &SelectorList<E::Impl>,
{ element: &E,
/// Constructs a new `LocalMatchingContext`. context: &mut MatchingContext,
pub fn new(shared: &'a mut MatchingContext<'b>, ) -> bool
selector: &'a Selector<Impl>) -> Self { where
Self { E: Element
shared: shared,
selector: selector,
offset: 0,
nesting_level: 0,
// We flip this off once third sequence is reached.
hover_active_quirk_disabled: selector.has_pseudo_element(),
}
}
/// Updates offset of Selector to show new compound selector.
/// To be able to correctly re-synthesize main SelectorIter.
fn note_position(&mut self, selector_iter: &SelectorIter<Impl>) {
if let QuirksMode::Quirks = self.shared.quirks_mode() {
if self.selector.has_pseudo_element() && self.offset != 0 {
// This is the _second_ call to note_position,
// which means we've moved past the compound
// selector adjacent to the pseudo-element.
self.hover_active_quirk_disabled = false;
}
self.offset = self.selector.len() - selector_iter.selector_length();
}
}
/// Returns true if current compound selector matches :active and :hover quirk.
/// https://quirks.spec.whatwg.org/#the-active-and-hover-quirk
pub fn active_hover_quirk_matches(&self) -> bool {
if self.shared.quirks_mode() != QuirksMode::Quirks {
return false;
}
// Don't allow it in recursive selectors such as :not and :-moz-any.
if self.nesting_level != 0 {
return false;
}
if self.hover_active_quirk_disabled {
return false;
}
let mut iter = if self.offset == 0 {
self.selector.iter()
} else {
self.selector.iter_from(self.offset)
};
return iter.all(|simple| {
match *simple {
Component::LocalName(_) |
Component::AttributeInNoNamespaceExists { .. } |
Component::AttributeInNoNamespace { .. } |
Component::AttributeOther(_) |
Component::ID(_) |
Component::Class(_) |
Component::PseudoElement(_) |
Component::Negation(_) |
Component::FirstChild |
Component::LastChild |
Component::OnlyChild |
Component::Empty |
Component::NthChild(_, _) |
Component::NthLastChild(_, _) |
Component::NthOfType(_, _) |
Component::NthLastOfType(_, _) |
Component::FirstOfType |
Component::LastOfType |
Component::OnlyOfType => false,
Component::NonTSPseudoClass(ref pseudo_class) => {
Impl::is_active_or_hover(pseudo_class)
},
_ => true,
}
});
}
}
pub fn matches_selector_list<E>(selector_list: &SelectorList<E::Impl>,
element: &E,
context: &mut MatchingContext)
-> bool
where E: Element
{ {
selector_list.0.iter().any(|selector| { selector_list.0.iter().any(|selector| {
matches_selector(selector, matches_selector(selector,
@ -176,10 +79,9 @@ pub fn matches_selector_list<E>(selector_list: &SelectorList<E::Impl>,
} }
#[inline(always)] #[inline(always)]
fn may_match<E>(hashes: &AncestorHashes, fn may_match<E>(hashes: &AncestorHashes, bf: &BloomFilter) -> bool
bf: &BloomFilter) where
-> bool E: Element,
where E: Element,
{ {
// Check the first three hashes. Note that we can check for zero before // Check the first three hashes. Note that we can check for zero before
// masking off the high bits, since if any of the first three hashes is // masking off the high bits, since if any of the first three hashes is
@ -370,15 +272,17 @@ enum SelectorMatchingResult {
/// unncessary cache miss for cases when we can fast-reject with AncestorHashes /// unncessary cache miss for cases when we can fast-reject with AncestorHashes
/// (which the caller can store inline with the selector pointer). /// (which the caller can store inline with the selector pointer).
#[inline(always)] #[inline(always)]
pub fn matches_selector<E, F>(selector: &Selector<E::Impl>, pub fn matches_selector<E, F>(
offset: usize, selector: &Selector<E::Impl>,
hashes: Option<&AncestorHashes>, offset: usize,
element: &E, hashes: Option<&AncestorHashes>,
context: &mut MatchingContext, element: &E,
flags_setter: &mut F) context: &mut MatchingContext,
-> bool flags_setter: &mut F,
where E: Element, ) -> bool
F: FnMut(&E, ElementSelectorFlags), where
E: Element,
F: FnMut(&E, ElementSelectorFlags),
{ {
// Use the bloom filter to fast-reject. // Use the bloom filter to fast-reject.
if let Some(hashes) = hashes { if let Some(hashes) = hashes {
@ -389,13 +293,7 @@ pub fn matches_selector<E, F>(selector: &Selector<E::Impl>,
} }
} }
let mut local_context = LocalMatchingContext::new(context, selector); matches_complex_selector(selector.iter_from(offset), element, context, flags_setter)
let iter = if offset == 0 {
selector.iter()
} else {
selector.iter_from(offset)
};
matches_complex_selector(iter, element, &mut local_context, flags_setter)
} }
/// Whether a compound selector matched, and whether it was the rightmost /// Whether a compound selector matched, and whether it was the rightmost
@ -431,7 +329,11 @@ where
selector.combinator_at(from_offset); // This asserts. selector.combinator_at(from_offset); // This asserts.
} }
let mut local_context = LocalMatchingContext::new(context, selector); let mut local_context = LocalMatchingContext {
shared: context,
matches_hover_and_active_quirk: false,
};
for component in selector.iter_raw_parse_order_from(from_offset - 1) { for component in selector.iter_raw_parse_order_from(from_offset - 1) {
if matches!(*component, Component::Combinator(..)) { if matches!(*component, Component::Combinator(..)) {
return CompoundSelectorMatchingResult::Matched { return CompoundSelectorMatchingResult::Matched {
@ -457,27 +359,20 @@ where
} }
/// Matches a complex selector. /// Matches a complex selector.
pub fn matches_complex_selector<E, F>(mut iter: SelectorIter<E::Impl>, pub fn matches_complex_selector<E, F>(
element: &E, mut iter: SelectorIter<E::Impl>,
context: &mut LocalMatchingContext<E::Impl>, element: &E,
flags_setter: &mut F) context: &mut MatchingContext,
-> bool flags_setter: &mut F,
where E: Element, ) -> bool
F: FnMut(&E, ElementSelectorFlags), where
E: Element,
F: FnMut(&E, ElementSelectorFlags),
{ {
if cfg!(debug_assertions) {
if context.nesting_level == 0 &&
context.shared.matching_mode == MatchingMode::ForStatelessPseudoElement {
assert!(iter.clone().any(|c| {
matches!(*c, Component::PseudoElement(..))
}));
}
}
// If this is the special pseudo-element mode, consume the ::pseudo-element // If this is the special pseudo-element mode, consume the ::pseudo-element
// before proceeding, since the caller has already handled that part. // before proceeding, since the caller has already handled that part.
if context.nesting_level == 0 && if context.nesting_level == 0 &&
context.shared.matching_mode == MatchingMode::ForStatelessPseudoElement { context.matching_mode == MatchingMode::ForStatelessPseudoElement {
// Consume the pseudo. // Consume the pseudo.
let pseudo = iter.next().unwrap(); let pseudo = iter.next().unwrap();
debug_assert!(matches!(*pseudo, Component::PseudoElement(..)), debug_assert!(matches!(*pseudo, Component::PseudoElement(..)),
@ -491,41 +386,119 @@ pub fn matches_complex_selector<E, F>(mut iter: SelectorIter<E::Impl>,
return false; return false;
} }
// Advance to the non-pseudo-element part of the selector, and inform // Advance to the non-pseudo-element part of the selector, but let the
// the context. // context note that .
if iter.next_sequence().is_none() { if iter.next_sequence().is_none() {
return true; return true;
} }
context.note_position(&iter);
} }
match matches_complex_selector_internal(iter, let result = matches_complex_selector_internal(
element, iter,
context, element,
&mut RelevantLinkStatus::Looking, context,
flags_setter) { &mut RelevantLinkStatus::Looking,
flags_setter,
Rightmost::Yes,
);
match result {
SelectorMatchingResult::Matched => true, SelectorMatchingResult::Matched => true,
_ => false _ => false
} }
} }
fn matches_complex_selector_internal<E, F>(mut selector_iter: SelectorIter<E::Impl>, #[inline]
element: &E, fn matches_hover_and_active_quirk<Impl: SelectorImpl>(
context: &mut LocalMatchingContext<E::Impl>, selector_iter: &SelectorIter<Impl>,
relevant_link: &mut RelevantLinkStatus, context: &MatchingContext,
flags_setter: &mut F) rightmost: Rightmost,
-> SelectorMatchingResult ) -> bool {
where E: Element, if context.quirks_mode() != QuirksMode::Quirks {
F: FnMut(&E, ElementSelectorFlags), return false;
}
if context.nesting_level != 0 {
return false;
}
// This compound selector had a pseudo-element to the right that we
// intentionally skipped.
if matches!(rightmost, Rightmost::Yes) &&
context.matching_mode == MatchingMode::ForStatelessPseudoElement {
return false;
}
selector_iter.clone().all(|simple| {
match *simple {
Component::LocalName(_) |
Component::AttributeInNoNamespaceExists { .. } |
Component::AttributeInNoNamespace { .. } |
Component::AttributeOther(_) |
Component::ID(_) |
Component::Class(_) |
Component::PseudoElement(_) |
Component::Negation(_) |
Component::FirstChild |
Component::LastChild |
Component::OnlyChild |
Component::Empty |
Component::NthChild(_, _) |
Component::NthLastChild(_, _) |
Component::NthOfType(_, _) |
Component::NthLastOfType(_, _) |
Component::FirstOfType |
Component::LastOfType |
Component::OnlyOfType => false,
Component::NonTSPseudoClass(ref pseudo_class) => {
Impl::is_active_or_hover(pseudo_class)
},
_ => true,
}
})
}
enum Rightmost {
Yes,
No,
}
fn matches_complex_selector_internal<E, F>(
mut selector_iter: SelectorIter<E::Impl>,
element: &E,
context: &mut MatchingContext,
relevant_link: &mut RelevantLinkStatus,
flags_setter: &mut F,
rightmost: Rightmost,
) -> SelectorMatchingResult
where
E: Element,
F: FnMut(&E, ElementSelectorFlags),
{ {
*relevant_link = relevant_link.examine_potential_link(element, &mut context.shared); *relevant_link = relevant_link.examine_potential_link(element, context);
debug!("Matching complex selector {:?} for {:?}, relevant link {:?}", debug!("Matching complex selector {:?} for {:?}, relevant link {:?}",
selector_iter, element, relevant_link); selector_iter, element, relevant_link);
let matches_all_simple_selectors = selector_iter.all(|simple| {
matches_simple_selector(simple, element, context, &relevant_link, flags_setter) let matches_all_simple_selectors = {
}); let matches_hover_and_active_quirk =
matches_hover_and_active_quirk(&selector_iter, context, rightmost);
let mut local_context =
LocalMatchingContext {
shared: context,
matches_hover_and_active_quirk,
};
selector_iter.all(|simple| {
matches_simple_selector(
simple,
element,
&mut local_context,
&relevant_link,
flags_setter,
)
})
};
let combinator = selector_iter.next_sequence(); let combinator = selector_iter.next_sequence();
let siblings = combinator.map_or(false, |c| c.is_sibling()); let siblings = combinator.map_or(false, |c| c.is_sibling());
@ -567,13 +540,14 @@ fn matches_complex_selector_internal<E, F>(mut selector_iter: SelectorIter<E::Im
None => return candidate_not_found, None => return candidate_not_found,
Some(next_element) => next_element, Some(next_element) => next_element,
}; };
// Note in which compound selector are we currently. let result = matches_complex_selector_internal(
context.note_position(&selector_iter); selector_iter.clone(),
let result = matches_complex_selector_internal(selector_iter.clone(), &element,
&element, context,
context, relevant_link,
relevant_link, flags_setter,
flags_setter); Rightmost::No,
);
match (result, c) { match (result, c) {
// Return the status immediately. // Return the status immediately.
(SelectorMatchingResult::Matched, _) => return result, (SelectorMatchingResult::Matched, _) => return result,
@ -614,14 +588,15 @@ fn matches_complex_selector_internal<E, F>(mut selector_iter: SelectorIter<E::Im
/// Determines whether the given element matches the given single selector. /// Determines whether the given element matches the given single selector.
#[inline] #[inline]
fn matches_simple_selector<E, F>( fn matches_simple_selector<E, F>(
selector: &Component<E::Impl>, selector: &Component<E::Impl>,
element: &E, element: &E,
context: &mut LocalMatchingContext<E::Impl>, context: &mut LocalMatchingContext,
relevant_link: &RelevantLinkStatus, relevant_link: &RelevantLinkStatus,
flags_setter: &mut F) flags_setter: &mut F,
-> bool ) -> bool
where E: Element, where
F: FnMut(&E, ElementSelectorFlags), E: Element,
F: FnMut(&E, ElementSelectorFlags),
{ {
match *selector { match *selector {
Component::Combinator(_) => unreachable!(), Component::Combinator(_) => unreachable!(),
@ -705,7 +680,14 @@ fn matches_simple_selector<E, F>(
) )
} }
Component::NonTSPseudoClass(ref pc) => { Component::NonTSPseudoClass(ref pc) => {
element.match_non_ts_pseudo_class(pc, context, relevant_link, flags_setter) if context.matches_hover_and_active_quirk &&
context.shared.nesting_level == 0 &&
E::Impl::is_active_or_hover(pc) &&
!element.is_link() {
return false;
}
element.match_non_ts_pseudo_class(pc, &mut context.shared, relevant_link, flags_setter)
} }
Component::FirstChild => { Component::FirstChild => {
matches_first_child(element, flags_setter) matches_first_child(element, flags_setter)
@ -753,12 +735,17 @@ fn matches_simple_selector<E, F>(
matches_generic_nth_child(element, context, 0, 1, true, true, flags_setter) matches_generic_nth_child(element, context, 0, 1, true, true, flags_setter)
} }
Component::Negation(ref negated) => { Component::Negation(ref negated) => {
context.nesting_level += 1; context.shared.nesting_level += 1;
let result = !negated.iter().all(|ss| { let result = !negated.iter().all(|ss| {
matches_simple_selector(ss, element, context, matches_simple_selector(
relevant_link, flags_setter) ss,
element,
context,
relevant_link,
flags_setter,
)
}); });
context.nesting_level -= 1; context.shared.nesting_level -= 1;
result result
} }
} }
@ -773,16 +760,18 @@ fn select_name<'a, T>(is_html: bool, local_name: &'a T, local_name_lower: &'a T)
} }
#[inline] #[inline]
fn matches_generic_nth_child<E, F>(element: &E, fn matches_generic_nth_child<E, F>(
context: &mut LocalMatchingContext<E::Impl>, element: &E,
a: i32, context: &mut LocalMatchingContext,
b: i32, a: i32,
is_of_type: bool, b: i32,
is_from_end: bool, is_of_type: bool,
flags_setter: &mut F) is_from_end: bool,
-> bool flags_setter: &mut F,
where E: Element, ) -> bool
F: FnMut(&E, ElementSelectorFlags), where
E: Element,
F: FnMut(&E, ElementSelectorFlags),
{ {
if element.ignores_nth_child_selectors() { if element.ignores_nth_child_selectors() {
return false; return false;
@ -880,8 +869,9 @@ where
#[inline] #[inline]
fn matches_first_child<E, F>(element: &E, flags_setter: &mut F) -> bool fn matches_first_child<E, F>(element: &E, flags_setter: &mut F) -> bool
where E: Element, where
F: FnMut(&E, ElementSelectorFlags), E: Element,
F: FnMut(&E, ElementSelectorFlags),
{ {
flags_setter(element, HAS_EDGE_CHILD_SELECTOR); flags_setter(element, HAS_EDGE_CHILD_SELECTOR);
element.prev_sibling_element().is_none() element.prev_sibling_element().is_none()
@ -889,8 +879,9 @@ fn matches_first_child<E, F>(element: &E, flags_setter: &mut F) -> bool
#[inline] #[inline]
fn matches_last_child<E, F>(element: &E, flags_setter: &mut F) -> bool fn matches_last_child<E, F>(element: &E, flags_setter: &mut F) -> bool
where E: Element, where
F: FnMut(&E, ElementSelectorFlags), E: Element,
F: FnMut(&E, ElementSelectorFlags),
{ {
flags_setter(element, HAS_EDGE_CHILD_SELECTOR); flags_setter(element, HAS_EDGE_CHILD_SELECTOR);
element.next_sibling_element().is_none() element.next_sibling_element().is_none()

Просмотреть файл

@ -6,7 +6,7 @@
//! between layout and style. //! between layout and style.
use attr::{AttrSelectorOperation, NamespaceConstraint, CaseSensitivity}; use attr::{AttrSelectorOperation, NamespaceConstraint, CaseSensitivity};
use matching::{ElementSelectorFlags, LocalMatchingContext, MatchingContext, RelevantLinkStatus}; use matching::{ElementSelectorFlags, MatchingContext, RelevantLinkStatus};
use parser::SelectorImpl; use parser::SelectorImpl;
use servo_arc::NonZeroPtrMut; use servo_arc::NonZeroPtrMut;
use std::fmt::Debug; use std::fmt::Debug;
@ -64,12 +64,15 @@ pub trait Element: Sized + Clone + Debug {
operation: &AttrSelectorOperation<&<Self::Impl as SelectorImpl>::AttrValue>) operation: &AttrSelectorOperation<&<Self::Impl as SelectorImpl>::AttrValue>)
-> bool; -> bool;
fn match_non_ts_pseudo_class<F>(&self, fn match_non_ts_pseudo_class<F>(
pc: &<Self::Impl as SelectorImpl>::NonTSPseudoClass, &self,
context: &mut LocalMatchingContext<Self::Impl>, pc: &<Self::Impl as SelectorImpl>::NonTSPseudoClass,
relevant_link: &RelevantLinkStatus, context: &mut MatchingContext,
flags_setter: &mut F) -> bool relevant_link: &RelevantLinkStatus,
where F: FnMut(&Self, ElementSelectorFlags); flags_setter: &mut F,
) -> bool
where
F: FnMut(&Self, ElementSelectorFlags);
fn match_pseudo_element(&self, fn match_pseudo_element(&self,
pe: &<Self::Impl as SelectorImpl>::PseudoElement, pe: &<Self::Impl as SelectorImpl>::PseudoElement,

Просмотреть файл

@ -78,7 +78,7 @@ use rule_tree::CascadeLevel as ServoCascadeLevel;
use selector_parser::{AttrValue, ElementExt, PseudoClassStringArg}; use selector_parser::{AttrValue, ElementExt, PseudoClassStringArg};
use selectors::{Element, OpaqueElement}; use selectors::{Element, OpaqueElement};
use selectors::attr::{AttrSelectorOperation, AttrSelectorOperator, CaseSensitivity, NamespaceConstraint}; use selectors::attr::{AttrSelectorOperation, AttrSelectorOperator, CaseSensitivity, NamespaceConstraint};
use selectors::matching::{ElementSelectorFlags, LocalMatchingContext, MatchingContext}; use selectors::matching::{ElementSelectorFlags, MatchingContext};
use selectors::matching::{RelevantLinkStatus, VisitedHandlingMode}; use selectors::matching::{RelevantLinkStatus, VisitedHandlingMode};
use selectors::sink::Push; use selectors::sink::Push;
use servo_arc::{Arc, ArcBorrow, RawOffsetArc}; use servo_arc::{Arc, ArcBorrow, RawOffsetArc};
@ -1844,7 +1844,7 @@ impl<'le> ::selectors::Element for GeckoElement<'le> {
fn match_non_ts_pseudo_class<F>( fn match_non_ts_pseudo_class<F>(
&self, &self,
pseudo_class: &NonTSPseudoClass, pseudo_class: &NonTSPseudoClass,
context: &mut LocalMatchingContext<Self::Impl>, context: &mut MatchingContext,
relevant_link: &RelevantLinkStatus, relevant_link: &RelevantLinkStatus,
flags_setter: &mut F, flags_setter: &mut F,
) -> bool ) -> bool
@ -1899,20 +1899,14 @@ impl<'le> ::selectors::Element for GeckoElement<'le> {
NonTSPseudoClass::MozDirAttrRTL | NonTSPseudoClass::MozDirAttrRTL |
NonTSPseudoClass::MozDirAttrLikeAuto | NonTSPseudoClass::MozDirAttrLikeAuto |
NonTSPseudoClass::MozAutofill | NonTSPseudoClass::MozAutofill |
NonTSPseudoClass::Active |
NonTSPseudoClass::Hover |
NonTSPseudoClass::MozAutofillPreview => { NonTSPseudoClass::MozAutofillPreview => {
self.get_state().intersects(pseudo_class.state_flag()) self.get_state().intersects(pseudo_class.state_flag())
}, },
NonTSPseudoClass::AnyLink => self.is_link(), NonTSPseudoClass::AnyLink => self.is_link(),
NonTSPseudoClass::Link => relevant_link.is_unvisited(self, context.shared), NonTSPseudoClass::Link => relevant_link.is_unvisited(self, context),
NonTSPseudoClass::Visited => relevant_link.is_visited(self, context.shared), NonTSPseudoClass::Visited => relevant_link.is_visited(self, context),
NonTSPseudoClass::Active |
NonTSPseudoClass::Hover => {
if context.active_hover_quirk_matches() && !self.is_link() {
false
} else {
self.get_state().contains(pseudo_class.state_flag())
}
},
NonTSPseudoClass::MozFirstNode => { NonTSPseudoClass::MozFirstNode => {
flags_setter(self, HAS_EDGE_CHILD_SELECTOR); flags_setter(self, HAS_EDGE_CHILD_SELECTOR);
let mut elem = self.as_node(); let mut elem = self.as_node();

Просмотреть файл

@ -11,7 +11,7 @@ use element_state::ElementState;
use selector_parser::{NonTSPseudoClass, PseudoElement, SelectorImpl, Snapshot, SnapshotMap, AttrValue}; use selector_parser::{NonTSPseudoClass, PseudoElement, SelectorImpl, Snapshot, SnapshotMap, AttrValue};
use selectors::{Element, OpaqueElement}; use selectors::{Element, OpaqueElement};
use selectors::attr::{AttrSelectorOperation, CaseSensitivity, NamespaceConstraint}; use selectors::attr::{AttrSelectorOperation, CaseSensitivity, NamespaceConstraint};
use selectors::matching::{ElementSelectorFlags, LocalMatchingContext, MatchingContext}; use selectors::matching::{ElementSelectorFlags, MatchingContext};
use selectors::matching::RelevantLinkStatus; use selectors::matching::RelevantLinkStatus;
use std::cell::Cell; use std::cell::Cell;
use std::fmt; use std::fmt;
@ -149,13 +149,15 @@ impl<'a, E> Element for ElementWrapper<'a, E>
{ {
type Impl = SelectorImpl; type Impl = SelectorImpl;
fn match_non_ts_pseudo_class<F>(&self, fn match_non_ts_pseudo_class<F>(
pseudo_class: &NonTSPseudoClass, &self,
context: &mut LocalMatchingContext<Self::Impl>, pseudo_class: &NonTSPseudoClass,
relevant_link: &RelevantLinkStatus, context: &mut MatchingContext,
_setter: &mut F) relevant_link: &RelevantLinkStatus,
-> bool _setter: &mut F,
where F: FnMut(&Self, ElementSelectorFlags), ) -> bool
where
F: FnMut(&Self, ElementSelectorFlags),
{ {
// Some pseudo-classes need special handling to evaluate them against // Some pseudo-classes need special handling to evaluate them against
// the snapshot. // the snapshot.
@ -163,9 +165,12 @@ impl<'a, E> Element for ElementWrapper<'a, E>
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
NonTSPseudoClass::MozAny(ref selectors) => { NonTSPseudoClass::MozAny(ref selectors) => {
use selectors::matching::matches_complex_selector; use selectors::matching::matches_complex_selector;
return selectors.iter().any(|s| { context.nesting_level += 1;
let result = selectors.iter().any(|s| {
matches_complex_selector(s.iter(), self, context, _setter) matches_complex_selector(s.iter(), self, context, _setter)
}) });
context.nesting_level -= 1;
return result
} }
// :dir is implemented in terms of state flags, but which state flag // :dir is implemented in terms of state flags, but which state flag
@ -195,10 +200,10 @@ impl<'a, E> Element for ElementWrapper<'a, E>
// state directly. Instead, we use the `relevant_link` to determine if // state directly. Instead, we use the `relevant_link` to determine if
// they match. // they match.
NonTSPseudoClass::Link => { NonTSPseudoClass::Link => {
return relevant_link.is_unvisited(self, context.shared); return relevant_link.is_unvisited(self, context);
} }
NonTSPseudoClass::Visited => { NonTSPseudoClass::Visited => {
return relevant_link.is_visited(self, context.shared); return relevant_link.is_visited(self, context);
} }
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
@ -230,27 +235,31 @@ impl<'a, E> Element for ElementWrapper<'a, E>
let flag = pseudo_class.state_flag(); let flag = pseudo_class.state_flag();
if flag.is_empty() { if flag.is_empty() {
return self.element.match_non_ts_pseudo_class(pseudo_class, return self.element.match_non_ts_pseudo_class(
context, pseudo_class,
relevant_link, context,
&mut |_, _| {}) relevant_link,
&mut |_, _| {},
)
} }
match self.snapshot().and_then(|s| s.state()) { match self.snapshot().and_then(|s| s.state()) {
Some(snapshot_state) => snapshot_state.intersects(flag), Some(snapshot_state) => snapshot_state.intersects(flag),
None => { None => {
self.element.match_non_ts_pseudo_class(pseudo_class, self.element.match_non_ts_pseudo_class(
context, pseudo_class,
relevant_link, context,
&mut |_, _| {}) relevant_link,
&mut |_, _| {},
)
} }
} }
} }
fn match_pseudo_element(&self, fn match_pseudo_element(
pseudo_element: &PseudoElement, &self,
context: &mut MatchingContext) pseudo_element: &PseudoElement,
-> bool context: &mut MatchingContext,
{ ) -> bool {
self.element.match_pseudo_element(pseudo_element, context) self.element.match_pseudo_element(pseudo_element, context)
} }

Просмотреть файл

@ -2309,12 +2309,12 @@ impl Rule {
} }
/// Creates a new Rule. /// Creates a new Rule.
pub fn new(selector: Selector<SelectorImpl>, pub fn new(
hashes: AncestorHashes, selector: Selector<SelectorImpl>,
style_rule: Arc<Locked<StyleRule>>, hashes: AncestorHashes,
source_order: u32) style_rule: Arc<Locked<StyleRule>>,
-> Self source_order: u32,
{ ) -> Self {
Rule { Rule {
selector: selector, selector: selector,
hashes: hashes, hashes: hashes,