servo: Merge #18934 - style: Make MatchingContext generic over SelectorImpl (from emilio:matching-context-generic); r=xidorn,heycam

This will help Xidorn implement tree pseudos, and in general makes sense,
allowing to put specific matching data in a selectors implementation.

Source-Repo: https://github.com/servo/servo
Source-Revision: 6268f482084179ed54e63028da038ae39c947359

--HG--
extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear
extra : subtree_revision : 2ed488ddfcbffb5b8779072c051a6d6057eee55b
This commit is contained in:
Emilio Cobos Álvarez 2017-10-19 05:43:51 -05:00
Родитель d7e6164f16
Коммит 24e9d2a703
9 изменённых файлов: 121 добавлений и 85 удалений

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

@ -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<Self::Impl>,
) -> bool {
false
}
fn match_non_ts_pseudo_class<F>(&self,
pseudo_class: &NonTSPseudoClass,
_: &mut MatchingContext,
_: &RelevantLinkStatus,
_: &mut F)
-> bool
where F: FnMut(&Self, ElementSelectorFlags),
fn match_non_ts_pseudo_class<F>(
&self,
pseudo_class: &NonTSPseudoClass,
_: &mut MatchingContext<Self::Impl>,
_: &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<Self::Impl>
) -> bool {
false
}
@ -1203,13 +1205,15 @@ impl<'le> ::selectors::Element for ServoThreadSafeLayoutElement<'le> {
}
}
fn match_non_ts_pseudo_class<F>(&self,
_: &NonTSPseudoClass,
_: &mut MatchingContext,
_: &RelevantLinkStatus,
_: &mut F)
-> bool
where F: FnMut(&Self, ElementSelectorFlags),
fn match_non_ts_pseudo_class<F>(
&self,
_: &NonTSPseudoClass,
_: &mut MatchingContext<Self::Impl>,
_: &RelevantLinkStatus,
_: &mut F,
) -> bool
where
F: FnMut(&Self, ElementSelectorFlags),
{
// NB: This could maybe be implemented
warn!("ServoThreadSafeLayoutElement::match_non_ts_pseudo_class called");

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

@ -2528,11 +2528,11 @@ impl<'a> SelectorsElement for DomRoot<Element> {
self.upcast::<Node>().GetParentElement()
}
fn match_pseudo_element(&self,
_pseudo: &PseudoElement,
_context: &mut MatchingContext)
-> bool
{
fn match_pseudo_element(
&self,
_pseudo: &PseudoElement,
_context: &mut MatchingContext<Self::Impl>,
) -> bool {
false
}
@ -2594,13 +2594,15 @@ impl<'a> SelectorsElement for DomRoot<Element> {
self.namespace()
}
fn match_non_ts_pseudo_class<F>(&self,
pseudo_class: &NonTSPseudoClass,
_: &mut MatchingContext,
_: &RelevantLinkStatus,
_: &mut F)
-> bool
where F: FnMut(&Self, ElementSelectorFlags),
fn match_non_ts_pseudo_class<F>(
&self,
pseudo_class: &NonTSPseudoClass,
_: &mut MatchingContext<Self::Impl>,
_: &RelevantLinkStatus,
_: &mut F,
) -> bool
where
F: FnMut(&Self, ElementSelectorFlags),
{
match *pseudo_class {
// https://github.com/servo/servo/issues/8718

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

@ -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>,
}
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,
}
}

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

@ -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<E>(
selector_list: &SelectorList<E::Impl>,
element: &E,
context: &mut MatchingContext,
context: &mut MatchingContext<E::Impl>,
) -> 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<E>(&self, element: &E, context: &mut MatchingContext)
-> RelevantLinkStatus
where E: Element,
fn examine_potential_link<E>(
&self,
element: &E,
context: &mut MatchingContext<E::Impl>,
) -> 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<E>(&self, element: &E, context: &MatchingContext) -> bool
where E: Element,
pub fn is_visited<E>(
&self,
element: &E,
context: &MatchingContext<E::Impl>,
) -> 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<E>(&self, element: &E, context: &MatchingContext) -> bool
where E: Element,
pub fn is_unvisited<E>(
&self,
element: &E,
context: &MatchingContext<E::Impl>
) -> bool
where
E: Element,
{
if !element.is_link() {
return false
@ -277,7 +291,7 @@ pub fn matches_selector<E, F>(
offset: usize,
hashes: Option<&AncestorHashes>,
element: &E,
context: &mut MatchingContext,
context: &mut MatchingContext<E::Impl>,
flags_setter: &mut F,
) -> bool
where
@ -318,7 +332,7 @@ pub enum CompoundSelectorMatchingResult {
pub fn matches_compound_selector<E>(
selector: &Selector<E::Impl>,
mut from_offset: usize,
context: &mut MatchingContext,
context: &mut MatchingContext<E::Impl>,
element: &E,
) -> CompoundSelectorMatchingResult
where
@ -361,7 +375,7 @@ where
pub fn matches_complex_selector<E, F>(
mut iter: SelectorIter<E::Impl>,
element: &E,
context: &mut MatchingContext,
context: &mut MatchingContext<E::Impl>,
flags_setter: &mut F,
) -> bool
where
@ -410,7 +424,7 @@ where
#[inline]
fn matches_hover_and_active_quirk<Impl: SelectorImpl>(
selector_iter: &SelectorIter<Impl>,
context: &MatchingContext,
context: &MatchingContext<Impl>,
rightmost: Rightmost,
) -> bool {
if context.quirks_mode() != QuirksMode::Quirks {
@ -465,7 +479,7 @@ enum Rightmost {
fn matches_complex_selector_internal<E, F>(
mut selector_iter: SelectorIter<E::Impl>,
element: &E,
context: &mut MatchingContext,
context: &mut MatchingContext<E::Impl>,
relevant_link: &mut RelevantLinkStatus,
flags_setter: &mut F,
rightmost: Rightmost,
@ -589,7 +603,7 @@ where
fn matches_simple_selector<E, F>(
selector: &Component<E::Impl>,
element: &E,
context: &mut LocalMatchingContext,
context: &mut LocalMatchingContext<E::Impl>,
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<E, F>(
element: &E,
context: &mut LocalMatchingContext,
context: &mut LocalMatchingContext<E::Impl>,
a: i32,
b: i32,
is_of_type: bool,

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

@ -67,17 +67,18 @@ pub trait Element: Sized + Clone + Debug {
fn match_non_ts_pseudo_class<F>(
&self,
pc: &<Self::Impl as SelectorImpl>::NonTSPseudoClass,
context: &mut MatchingContext,
context: &mut MatchingContext<Self::Impl>,
relevant_link: &RelevantLinkStatus,
flags_setter: &mut F,
) -> bool
where
F: FnMut(&Self, ElementSelectorFlags);
fn match_pseudo_element(&self,
pe: &<Self::Impl as SelectorImpl>::PseudoElement,
context: &mut MatchingContext)
-> bool;
fn match_pseudo_element(
&self,
pe: &<Self::Impl as SelectorImpl>::PseudoElement,
context: &mut MatchingContext<Self::Impl>,
) -> bool;
/// Whether this element is a `link`.
fn is_link(&self) -> bool;

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

@ -1834,7 +1834,7 @@ impl<'le> ::selectors::Element for GeckoElement<'le> {
fn match_non_ts_pseudo_class<F>(
&self,
pseudo_class: &NonTSPseudoClass,
context: &mut MatchingContext,
context: &mut MatchingContext<Self::Impl>,
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<Self::Impl>,
) -> 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

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

@ -152,7 +152,7 @@ impl<'a, E> Element for ElementWrapper<'a, E>
fn match_non_ts_pseudo_class<F>(
&self,
pseudo_class: &NonTSPseudoClass,
context: &mut MatchingContext,
context: &mut MatchingContext<Self::Impl>,
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<Self::Impl>,
) -> bool {
self.element.match_pseudo_element(pseudo_element, context)
}

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

@ -162,17 +162,20 @@ impl SelectorMap<Rule> {
///
/// 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<E, V, F>(&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<ApplicableDeclarationBlock>,
F: FnMut(&E, ElementSelectorFlags),
pub fn get_all_matching_rules<E, V, F>(
&self,
element: &E,
rule_hash_target: &E,
matching_rules_list: &mut V,
context: &mut MatchingContext<E::Impl>,
quirks_mode: QuirksMode,
flags_setter: &mut F,
cascade_level: CascadeLevel,
)
where
E: TElement,
V: VecLike<ApplicableDeclarationBlock>,
F: FnMut(&E, ElementSelectorFlags),
{
if self.is_empty() {
return
@ -223,15 +226,18 @@ impl SelectorMap<Rule> {
}
/// Adds rules in `rules` that match `element` to the `matching_rules` list.
fn get_matching_rules<E, V, F>(element: &E,
rules: &[Rule],
matching_rules: &mut V,
context: &mut MatchingContext,
flags_setter: &mut F,
cascade_level: CascadeLevel)
where E: TElement,
V: VecLike<ApplicableDeclarationBlock>,
F: FnMut(&E, ElementSelectorFlags),
fn get_matching_rules<E, V, F>(
element: &E,
rules: &[Rule],
matching_rules: &mut V,
context: &mut MatchingContext<E::Impl>,
flags_setter: &mut F,
cascade_level: CascadeLevel,
)
where
E: TElement,
V: VecLike<ApplicableDeclarationBlock>,
F: FnMut(&E, ElementSelectorFlags),
{
for rule in rules {
if matches_selector(&rule.selector,

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

@ -1198,7 +1198,7 @@ impl Stylist {
animation_rules: AnimationRules,
rule_inclusion: RuleInclusion,
applicable_declarations: &mut V,
context: &mut MatchingContext,
context: &mut MatchingContext<E::Impl>,
flags_setter: &mut F,
)
where