selectors: Allow defining an implementation-dependent field in the matching context.

This commit is contained in:
Emilio Cobos Álvarez 2018-01-11 12:07:24 +01:00
parent 9b3fc43f5a
commit 1e27f2883b
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
6 changed files with 11 additions and 0 deletions

View file

@ -130,6 +130,9 @@ where
/// should match when matching_mode is ForStatelessPseudoElement. /// should match when matching_mode is ForStatelessPseudoElement.
pub pseudo_element_matching_fn: Option<&'a Fn(&Impl::PseudoElement) -> bool>, pub pseudo_element_matching_fn: Option<&'a Fn(&Impl::PseudoElement) -> bool>,
/// Extra implementation-dependent matching data.
pub extra_data: Option<Impl::ExtraMatchingData>,
quirks_mode: QuirksMode, quirks_mode: QuirksMode,
classes_and_ids_case_sensitivity: CaseSensitivity, classes_and_ids_case_sensitivity: CaseSensitivity,
_impl: ::std::marker::PhantomData<Impl>, _impl: ::std::marker::PhantomData<Impl>,
@ -173,6 +176,7 @@ where
scope_element: None, scope_element: None,
nesting_level: 0, nesting_level: 0,
pseudo_element_matching_fn: None, pseudo_element_matching_fn: None,
extra_data: None,
_impl: ::std::marker::PhantomData, _impl: ::std::marker::PhantomData,
} }
} }

View file

@ -84,6 +84,7 @@ macro_rules! with_all_bounds {
/// are parameterized on SelectorImpl. See /// are parameterized on SelectorImpl. See
/// <https://github.com/rust-lang/rust/issues/26925> /// <https://github.com/rust-lang/rust/issues/26925>
pub trait SelectorImpl: Clone + Sized + 'static { pub trait SelectorImpl: Clone + Sized + 'static {
type ExtraMatchingData: Sized + 'static;
type AttrValue: $($InSelector)*; type AttrValue: $($InSelector)*;
type Identifier: $($InSelector)* + PrecomputedHash; type Identifier: $($InSelector)* + PrecomputedHash;
type ClassName: $($InSelector)* + PrecomputedHash; type ClassName: $($InSelector)* + PrecomputedHash;
@ -2027,6 +2028,7 @@ pub mod tests {
} }
impl SelectorImpl for DummySelectorImpl { impl SelectorImpl for DummySelectorImpl {
type ExtraMatchingData = ();
type AttrValue = DummyAtom; type AttrValue = DummyAtom;
type Identifier = DummyAtom; type Identifier = DummyAtom;
type ClassName = DummyAtom; type ClassName = DummyAtom;

View file

@ -24,6 +24,7 @@ impl parser::PseudoElement for gecko_like_types::PseudoElement {
// Boilerplate // Boilerplate
impl SelectorImpl for Impl { impl SelectorImpl for Impl {
type ExtraMatchingData = u64;
type AttrValue = Atom; type AttrValue = Atom;
type Identifier = Atom; type Identifier = Atom;
type ClassName = Atom; type ClassName = Atom;

View file

@ -278,6 +278,7 @@ impl NonTSPseudoClass {
pub struct SelectorImpl; pub struct SelectorImpl;
impl ::selectors::SelectorImpl for SelectorImpl { impl ::selectors::SelectorImpl for SelectorImpl {
type ExtraMatchingData = ();
type AttrValue = Atom; type AttrValue = Atom;
type Identifier = Atom; type Identifier = Atom;
type ClassName = Atom; type ClassName = Atom;

View file

@ -26,6 +26,8 @@
#![deny(warnings)] #![deny(warnings)]
#![deny(missing_docs)] #![deny(missing_docs)]
#![cfg_attr(feature = "servo", feature(never_type))]
#![recursion_limit = "500"] // For define_css_keyword_enum! in -moz-appearance #![recursion_limit = "500"] // For define_css_keyword_enum! in -moz-appearance
extern crate app_units; extern crate app_units;

View file

@ -377,6 +377,7 @@ impl ::selectors::SelectorImpl for SelectorImpl {
type PseudoElement = PseudoElement; type PseudoElement = PseudoElement;
type NonTSPseudoClass = NonTSPseudoClass; type NonTSPseudoClass = NonTSPseudoClass;
type ExtraMatchingData = !;
type AttrValue = String; type AttrValue = String;
type Identifier = Atom; type Identifier = Atom;
type ClassName = Atom; type ClassName = Atom;