diff --git a/components/layout_thread/dom_wrapper.rs b/components/layout_thread/dom_wrapper.rs index f19e5e13b78..899c47b4747 100644 --- a/components/layout_thread/dom_wrapper.rs +++ b/components/layout_thread/dom_wrapper.rs @@ -686,21 +686,23 @@ impl<'le> ::selectors::Element for ServoLayoutElement<'le> { self.element.namespace() } - fn match_pseudo_element(&self, - _pseudo: &PseudoElement, - _context: &mut MatchingContext) - -> bool - { + fn match_pseudo_element( + &self, + _pseudo: &PseudoElement, + _context: &mut MatchingContext, + ) -> bool { false } - fn match_non_ts_pseudo_class(&self, - pseudo_class: &NonTSPseudoClass, - _: &mut MatchingContext, - _: &RelevantLinkStatus, - _: &mut F) - -> bool - where F: FnMut(&Self, ElementSelectorFlags), + fn match_non_ts_pseudo_class( + &self, + pseudo_class: &NonTSPseudoClass, + _: &mut MatchingContext, + _: &RelevantLinkStatus, + _: &mut F, + ) -> bool + where + F: FnMut(&Self, ElementSelectorFlags), { match *pseudo_class { // https://github.com/servo/servo/issues/8718 @@ -1176,11 +1178,11 @@ impl<'le> ::selectors::Element for ServoThreadSafeLayoutElement<'le> { self.element.get_namespace() } - fn match_pseudo_element(&self, - _pseudo: &PseudoElement, - _context: &mut MatchingContext) - -> bool - { + fn match_pseudo_element( + &self, + _pseudo: &PseudoElement, + _context: &mut MatchingContext + ) -> bool { false } @@ -1203,13 +1205,15 @@ impl<'le> ::selectors::Element for ServoThreadSafeLayoutElement<'le> { } } - fn match_non_ts_pseudo_class(&self, - _: &NonTSPseudoClass, - _: &mut MatchingContext, - _: &RelevantLinkStatus, - _: &mut F) - -> bool - where F: FnMut(&Self, ElementSelectorFlags), + fn match_non_ts_pseudo_class( + &self, + _: &NonTSPseudoClass, + _: &mut MatchingContext, + _: &RelevantLinkStatus, + _: &mut F, + ) -> bool + where + F: FnMut(&Self, ElementSelectorFlags), { // NB: This could maybe be implemented warn!("ServoThreadSafeLayoutElement::match_non_ts_pseudo_class called"); diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index 9045918d2f8..1d8c12f9a64 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -2528,11 +2528,11 @@ impl<'a> SelectorsElement for DomRoot { self.upcast::().GetParentElement() } - fn match_pseudo_element(&self, - _pseudo: &PseudoElement, - _context: &mut MatchingContext) - -> bool - { + fn match_pseudo_element( + &self, + _pseudo: &PseudoElement, + _context: &mut MatchingContext, + ) -> bool { false } @@ -2594,13 +2594,15 @@ impl<'a> SelectorsElement for DomRoot { self.namespace() } - fn match_non_ts_pseudo_class(&self, - pseudo_class: &NonTSPseudoClass, - _: &mut MatchingContext, - _: &RelevantLinkStatus, - _: &mut F) - -> bool - where F: FnMut(&Self, ElementSelectorFlags), + fn match_non_ts_pseudo_class( + &self, + pseudo_class: &NonTSPseudoClass, + _: &mut MatchingContext, + _: &RelevantLinkStatus, + _: &mut F, + ) -> bool + where + F: FnMut(&Self, ElementSelectorFlags), { match *pseudo_class { // https://github.com/servo/servo/issues/8718 diff --git a/components/selectors/context.rs b/components/selectors/context.rs index 22c886315fb..fa6d4428f56 100644 --- a/components/selectors/context.rs +++ b/components/selectors/context.rs @@ -5,6 +5,7 @@ use attr::CaseSensitivity; use bloom::BloomFilter; use nth_index_cache::NthIndexCache; +use parser::SelectorImpl; use tree::OpaqueElement; /// What kind of selector matching mode we should use. @@ -74,7 +75,10 @@ impl QuirksMode { /// Data associated with the matching process for a element. This context is /// used across many selectors for an element, so it's not appropriate for /// transient data that applies to only a single selector. -pub struct MatchingContext<'a> { +pub struct MatchingContext<'a, Impl> +where + Impl: SelectorImpl, +{ /// Input with the matching mode we should use when matching selectors. pub matching_mode: MatchingMode, /// Input with the bloom filter used to fast-reject selectors. @@ -107,9 +111,13 @@ pub struct MatchingContext<'a> { quirks_mode: QuirksMode, classes_and_ids_case_sensitivity: CaseSensitivity, + _impl: ::std::marker::PhantomData, } -impl<'a> MatchingContext<'a> { +impl<'a, Impl> MatchingContext<'a, Impl> +where + Impl: SelectorImpl, +{ /// Constructs a new `MatchingContext`. pub fn new( matching_mode: MatchingMode, @@ -144,6 +152,7 @@ impl<'a> MatchingContext<'a> { classes_and_ids_case_sensitivity: quirks_mode.classes_and_ids_case_sensitivity(), scope_element: None, nesting_level: 0, + _impl: ::std::marker::PhantomData, } } diff --git a/components/selectors/matching.rs b/components/selectors/matching.rs index 596fa8afe9f..e7ae0184c47 100644 --- a/components/selectors/matching.rs +++ b/components/selectors/matching.rs @@ -55,15 +55,15 @@ impl ElementSelectorFlags { } /// Holds per-compound-selector data. -struct LocalMatchingContext<'a, 'b: 'a> { - shared: &'a mut MatchingContext<'b>, +struct LocalMatchingContext<'a, 'b: 'a, Impl: SelectorImpl> { + shared: &'a mut MatchingContext<'b, Impl>, matches_hover_and_active_quirk: bool, } pub fn matches_selector_list( selector_list: &SelectorList, element: &E, - context: &mut MatchingContext, + context: &mut MatchingContext, ) -> bool where E: Element @@ -141,9 +141,13 @@ impl RelevantLinkStatus { /// If we found the relevant link for this element, record that in the /// overall matching context for the element as a whole and stop looking for /// addtional links. - fn examine_potential_link(&self, element: &E, context: &mut MatchingContext) - -> RelevantLinkStatus - where E: Element, + fn examine_potential_link( + &self, + element: &E, + context: &mut MatchingContext, + ) -> RelevantLinkStatus + where + E: Element, { // If a relevant link was previously found, we no longer want to look // for links. Only the nearest ancestor link is considered relevant. @@ -168,8 +172,13 @@ impl RelevantLinkStatus { /// matching. This is true only if the element is a link, an relevant link /// exists for the element, and the visited handling mode is set to accept /// relevant links as visited. - pub fn is_visited(&self, element: &E, context: &MatchingContext) -> bool - where E: Element, + pub fn is_visited( + &self, + element: &E, + context: &MatchingContext, + ) -> bool + where + E: Element, { if !element.is_link() { return false @@ -193,8 +202,13 @@ impl RelevantLinkStatus { /// as visited. If this is a relevant link, then is it unvisited if the /// visited handling mode is set to treat all links as unvisted (including /// relevant links). - pub fn is_unvisited(&self, element: &E, context: &MatchingContext) -> bool - where E: Element, + pub fn is_unvisited( + &self, + element: &E, + context: &MatchingContext + ) -> bool + where + E: Element, { if !element.is_link() { return false @@ -277,7 +291,7 @@ pub fn matches_selector( offset: usize, hashes: Option<&AncestorHashes>, element: &E, - context: &mut MatchingContext, + context: &mut MatchingContext, flags_setter: &mut F, ) -> bool where @@ -318,7 +332,7 @@ pub enum CompoundSelectorMatchingResult { pub fn matches_compound_selector( selector: &Selector, mut from_offset: usize, - context: &mut MatchingContext, + context: &mut MatchingContext, element: &E, ) -> CompoundSelectorMatchingResult where @@ -361,7 +375,7 @@ where pub fn matches_complex_selector( mut iter: SelectorIter, element: &E, - context: &mut MatchingContext, + context: &mut MatchingContext, flags_setter: &mut F, ) -> bool where @@ -410,7 +424,7 @@ where #[inline] fn matches_hover_and_active_quirk( selector_iter: &SelectorIter, - context: &MatchingContext, + context: &MatchingContext, rightmost: Rightmost, ) -> bool { if context.quirks_mode() != QuirksMode::Quirks { @@ -465,7 +479,7 @@ enum Rightmost { fn matches_complex_selector_internal( mut selector_iter: SelectorIter, element: &E, - context: &mut MatchingContext, + context: &mut MatchingContext, relevant_link: &mut RelevantLinkStatus, flags_setter: &mut F, rightmost: Rightmost, @@ -589,7 +603,7 @@ where fn matches_simple_selector( selector: &Component, element: &E, - context: &mut LocalMatchingContext, + context: &mut LocalMatchingContext, relevant_link: &RelevantLinkStatus, flags_setter: &mut F, ) -> bool @@ -761,7 +775,7 @@ fn select_name<'a, T>(is_html: bool, local_name: &'a T, local_name_lower: &'a T) #[inline] fn matches_generic_nth_child( element: &E, - context: &mut LocalMatchingContext, + context: &mut LocalMatchingContext, a: i32, b: i32, is_of_type: bool, diff --git a/components/selectors/tree.rs b/components/selectors/tree.rs index d99804c8675..ef353086032 100644 --- a/components/selectors/tree.rs +++ b/components/selectors/tree.rs @@ -67,17 +67,18 @@ pub trait Element: Sized + Clone + Debug { fn match_non_ts_pseudo_class( &self, pc: &::NonTSPseudoClass, - context: &mut MatchingContext, + context: &mut MatchingContext, relevant_link: &RelevantLinkStatus, flags_setter: &mut F, ) -> bool where F: FnMut(&Self, ElementSelectorFlags); - fn match_pseudo_element(&self, - pe: &::PseudoElement, - context: &mut MatchingContext) - -> bool; + fn match_pseudo_element( + &self, + pe: &::PseudoElement, + context: &mut MatchingContext, + ) -> bool; /// Whether this element is a `link`. fn is_link(&self) -> bool; diff --git a/components/style/gecko/wrapper.rs b/components/style/gecko/wrapper.rs index 908af2b6bd3..852436d3d06 100644 --- a/components/style/gecko/wrapper.rs +++ b/components/style/gecko/wrapper.rs @@ -1834,7 +1834,7 @@ impl<'le> ::selectors::Element for GeckoElement<'le> { fn match_non_ts_pseudo_class( &self, pseudo_class: &NonTSPseudoClass, - context: &mut MatchingContext, + context: &mut MatchingContext, relevant_link: &RelevantLinkStatus, flags_setter: &mut F, ) -> bool @@ -1975,7 +1975,7 @@ impl<'le> ::selectors::Element for GeckoElement<'le> { fn match_pseudo_element( &self, pseudo_element: &PseudoElement, - _context: &mut MatchingContext + _context: &mut MatchingContext, ) -> bool { // TODO(emilio): I believe we could assert we are a pseudo-element and // match the proper pseudo-element, given how we rulehash the stuff diff --git a/components/style/invalidation/element/element_wrapper.rs b/components/style/invalidation/element/element_wrapper.rs index 294f878cd20..5cedff38fa3 100644 --- a/components/style/invalidation/element/element_wrapper.rs +++ b/components/style/invalidation/element/element_wrapper.rs @@ -152,7 +152,7 @@ impl<'a, E> Element for ElementWrapper<'a, E> fn match_non_ts_pseudo_class( &self, pseudo_class: &NonTSPseudoClass, - context: &mut MatchingContext, + context: &mut MatchingContext, relevant_link: &RelevantLinkStatus, _setter: &mut F, ) -> bool @@ -258,7 +258,7 @@ impl<'a, E> Element for ElementWrapper<'a, E> fn match_pseudo_element( &self, pseudo_element: &PseudoElement, - context: &mut MatchingContext, + context: &mut MatchingContext, ) -> bool { self.element.match_pseudo_element(pseudo_element, context) } diff --git a/components/style/selector_map.rs b/components/style/selector_map.rs index 4d1ec302f15..da9180b9549 100644 --- a/components/style/selector_map.rs +++ b/components/style/selector_map.rs @@ -162,17 +162,20 @@ impl SelectorMap { /// /// Extract matching rules as per element's ID, classes, tag name, etc.. /// Sort the Rules at the end to maintain cascading order. - pub fn get_all_matching_rules(&self, - element: &E, - rule_hash_target: &E, - matching_rules_list: &mut V, - context: &mut MatchingContext, - quirks_mode: QuirksMode, - flags_setter: &mut F, - cascade_level: CascadeLevel) - where E: TElement, - V: VecLike, - F: FnMut(&E, ElementSelectorFlags), + pub fn get_all_matching_rules( + &self, + element: &E, + rule_hash_target: &E, + matching_rules_list: &mut V, + context: &mut MatchingContext, + quirks_mode: QuirksMode, + flags_setter: &mut F, + cascade_level: CascadeLevel, + ) + where + E: TElement, + V: VecLike, + F: FnMut(&E, ElementSelectorFlags), { if self.is_empty() { return @@ -223,15 +226,18 @@ impl SelectorMap { } /// Adds rules in `rules` that match `element` to the `matching_rules` list. - fn get_matching_rules(element: &E, - rules: &[Rule], - matching_rules: &mut V, - context: &mut MatchingContext, - flags_setter: &mut F, - cascade_level: CascadeLevel) - where E: TElement, - V: VecLike, - F: FnMut(&E, ElementSelectorFlags), + fn get_matching_rules( + element: &E, + rules: &[Rule], + matching_rules: &mut V, + context: &mut MatchingContext, + flags_setter: &mut F, + cascade_level: CascadeLevel, + ) + where + E: TElement, + V: VecLike, + F: FnMut(&E, ElementSelectorFlags), { for rule in rules { if matches_selector(&rule.selector, diff --git a/components/style/stylist.rs b/components/style/stylist.rs index 72445369d7c..2657e1dffdb 100644 --- a/components/style/stylist.rs +++ b/components/style/stylist.rs @@ -1198,7 +1198,7 @@ impl Stylist { animation_rules: AnimationRules, rule_inclusion: RuleInclusion, applicable_declarations: &mut V, - context: &mut MatchingContext, + context: &mut MatchingContext, flags_setter: &mut F, ) where