mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
style: Reorder some variants
This doesn't make a difference, I was hoping it would allow us to remove the special-casey code we have here: https://searchfox.org/mozilla-central/rev/997a56b018662e2940c99bbaf57a6ac9d1aa5422/servo/components/selectors/matching.rs#610-632 But it doesn't. Still I think it doesn't hurt tho, shouldn't change behavior. Depends on D145485 Differential Revision: https://phabricator.services.mozilla.com/D145486
This commit is contained in:
parent
2939bf1a12
commit
2302d828a5
2 changed files with 70 additions and 69 deletions
|
@ -634,70 +634,13 @@ where
|
||||||
debug_assert!(context.shared.is_nested() || !context.shared.in_negation());
|
debug_assert!(context.shared.is_nested() || !context.shared.in_negation());
|
||||||
|
|
||||||
match *selector {
|
match *selector {
|
||||||
Component::Combinator(_) => unreachable!(),
|
|
||||||
Component::Part(ref parts) => {
|
|
||||||
let mut hosts = SmallVec::<[E; 4]>::new();
|
|
||||||
|
|
||||||
let mut host = match element.containing_shadow_host() {
|
|
||||||
Some(h) => h,
|
|
||||||
None => return false,
|
|
||||||
};
|
|
||||||
|
|
||||||
let current_host = context.shared.current_host;
|
|
||||||
if current_host != Some(host.opaque()) {
|
|
||||||
loop {
|
|
||||||
let outer_host = host.containing_shadow_host();
|
|
||||||
if outer_host.as_ref().map(|h| h.opaque()) == current_host {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
let outer_host = match outer_host {
|
|
||||||
Some(h) => h,
|
|
||||||
None => return false,
|
|
||||||
};
|
|
||||||
// TODO(emilio): if worth it, we could early return if
|
|
||||||
// host doesn't have the exportparts attribute.
|
|
||||||
hosts.push(host);
|
|
||||||
host = outer_host;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Translate the part into the right scope.
|
|
||||||
parts.iter().all(|part| {
|
|
||||||
let mut part = part.clone();
|
|
||||||
for host in hosts.iter().rev() {
|
|
||||||
part = match host.imported_part(&part) {
|
|
||||||
Some(p) => p,
|
|
||||||
None => return false,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
element.is_part(&part)
|
|
||||||
})
|
|
||||||
},
|
|
||||||
Component::Slotted(ref selector) => {
|
|
||||||
// <slots> are never flattened tree slottables.
|
|
||||||
!element.is_html_slot_element() &&
|
|
||||||
context.shared.nest(|context| {
|
|
||||||
matches_complex_selector(selector.iter(), element, context)
|
|
||||||
})
|
|
||||||
},
|
|
||||||
Component::PseudoElement(ref pseudo) => {
|
|
||||||
element.match_pseudo_element(pseudo, context.shared)
|
|
||||||
},
|
|
||||||
Component::LocalName(ref local_name) => matches_local_name(element, local_name),
|
|
||||||
Component::ExplicitUniversalType | Component::ExplicitAnyNamespace => true,
|
|
||||||
Component::Namespace(_, ref url) | Component::DefaultNamespace(ref url) => {
|
|
||||||
element.has_namespace(&url.borrow())
|
|
||||||
},
|
|
||||||
Component::ExplicitNoNamespace => {
|
|
||||||
let ns = crate::parser::namespace_empty_string::<E::Impl>();
|
|
||||||
element.has_namespace(&ns.borrow())
|
|
||||||
},
|
|
||||||
Component::ID(ref id) => {
|
Component::ID(ref id) => {
|
||||||
element.has_id(id, context.shared.classes_and_ids_case_sensitivity())
|
element.has_id(id, context.shared.classes_and_ids_case_sensitivity())
|
||||||
},
|
},
|
||||||
Component::Class(ref class) => {
|
Component::Class(ref class) => {
|
||||||
element.has_class(class, context.shared.classes_and_ids_case_sensitivity())
|
element.has_class(class, context.shared.classes_and_ids_case_sensitivity())
|
||||||
},
|
},
|
||||||
|
Component::LocalName(ref local_name) => matches_local_name(element, local_name),
|
||||||
Component::AttributeInNoNamespaceExists {
|
Component::AttributeInNoNamespaceExists {
|
||||||
ref local_name,
|
ref local_name,
|
||||||
ref local_name_lower,
|
ref local_name_lower,
|
||||||
|
@ -760,6 +703,62 @@ where
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
Component::Part(ref parts) => {
|
||||||
|
let mut hosts = SmallVec::<[E; 4]>::new();
|
||||||
|
|
||||||
|
let mut host = match element.containing_shadow_host() {
|
||||||
|
Some(h) => h,
|
||||||
|
None => return false,
|
||||||
|
};
|
||||||
|
|
||||||
|
let current_host = context.shared.current_host;
|
||||||
|
if current_host != Some(host.opaque()) {
|
||||||
|
loop {
|
||||||
|
let outer_host = host.containing_shadow_host();
|
||||||
|
if outer_host.as_ref().map(|h| h.opaque()) == current_host {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
let outer_host = match outer_host {
|
||||||
|
Some(h) => h,
|
||||||
|
None => return false,
|
||||||
|
};
|
||||||
|
// TODO(emilio): if worth it, we could early return if
|
||||||
|
// host doesn't have the exportparts attribute.
|
||||||
|
hosts.push(host);
|
||||||
|
host = outer_host;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Translate the part into the right scope.
|
||||||
|
parts.iter().all(|part| {
|
||||||
|
let mut part = part.clone();
|
||||||
|
for host in hosts.iter().rev() {
|
||||||
|
part = match host.imported_part(&part) {
|
||||||
|
Some(p) => p,
|
||||||
|
None => return false,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
element.is_part(&part)
|
||||||
|
})
|
||||||
|
},
|
||||||
|
Component::Slotted(ref selector) => {
|
||||||
|
// <slots> are never flattened tree slottables.
|
||||||
|
!element.is_html_slot_element() &&
|
||||||
|
context.shared.nest(|context| {
|
||||||
|
matches_complex_selector(selector.iter(), element, context)
|
||||||
|
})
|
||||||
|
},
|
||||||
|
Component::PseudoElement(ref pseudo) => {
|
||||||
|
element.match_pseudo_element(pseudo, context.shared)
|
||||||
|
},
|
||||||
|
Component::ExplicitUniversalType | Component::ExplicitAnyNamespace => true,
|
||||||
|
Component::Namespace(_, ref url) | Component::DefaultNamespace(ref url) => {
|
||||||
|
element.has_namespace(&url.borrow())
|
||||||
|
},
|
||||||
|
Component::ExplicitNoNamespace => {
|
||||||
|
let ns = crate::parser::namespace_empty_string::<E::Impl>();
|
||||||
|
element.has_namespace(&ns.borrow())
|
||||||
|
},
|
||||||
Component::NonTSPseudoClass(ref pc) => {
|
Component::NonTSPseudoClass(ref pc) => {
|
||||||
if let Some((ref rightmost, ref iter)) = context.quirks_data {
|
if let Some((ref rightmost, ref iter)) = context.quirks_data {
|
||||||
if pc.is_active_or_hover() && !element.is_link() && hover_and_active_quirk_applies(iter, context.shared, *rightmost) {
|
if pc.is_active_or_hover() && !element.is_link() && hover_and_active_quirk_applies(iter, context.shared, *rightmost) {
|
||||||
|
@ -833,6 +832,7 @@ where
|
||||||
}
|
}
|
||||||
true
|
true
|
||||||
}),
|
}),
|
||||||
|
Component::Combinator(_) => unreachable!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1030,17 +1030,6 @@ impl Combinator {
|
||||||
#[cfg_attr(feature = "shmem", derive(ToShmem))]
|
#[cfg_attr(feature = "shmem", derive(ToShmem))]
|
||||||
#[cfg_attr(feature = "shmem", shmem(no_bounds))]
|
#[cfg_attr(feature = "shmem", shmem(no_bounds))]
|
||||||
pub enum Component<Impl: SelectorImpl> {
|
pub enum Component<Impl: SelectorImpl> {
|
||||||
Combinator(Combinator),
|
|
||||||
|
|
||||||
ExplicitAnyNamespace,
|
|
||||||
ExplicitNoNamespace,
|
|
||||||
DefaultNamespace(#[cfg_attr(feature = "shmem", shmem(field_bound))] Impl::NamespaceUrl),
|
|
||||||
Namespace(
|
|
||||||
#[cfg_attr(feature = "shmem", shmem(field_bound))] Impl::NamespacePrefix,
|
|
||||||
#[cfg_attr(feature = "shmem", shmem(field_bound))] Impl::NamespaceUrl,
|
|
||||||
),
|
|
||||||
|
|
||||||
ExplicitUniversalType,
|
|
||||||
LocalName(LocalName<Impl>),
|
LocalName(LocalName<Impl>),
|
||||||
|
|
||||||
ID(#[cfg_attr(feature = "shmem", shmem(field_bound))] Impl::Identifier),
|
ID(#[cfg_attr(feature = "shmem", shmem(field_bound))] Impl::Identifier),
|
||||||
|
@ -1063,6 +1052,16 @@ pub enum Component<Impl: SelectorImpl> {
|
||||||
// Use a Box in the less common cases with more data to keep size_of::<Component>() small.
|
// Use a Box in the less common cases with more data to keep size_of::<Component>() small.
|
||||||
AttributeOther(Box<AttrSelectorWithOptionalNamespace<Impl>>),
|
AttributeOther(Box<AttrSelectorWithOptionalNamespace<Impl>>),
|
||||||
|
|
||||||
|
ExplicitUniversalType,
|
||||||
|
ExplicitAnyNamespace,
|
||||||
|
|
||||||
|
ExplicitNoNamespace,
|
||||||
|
DefaultNamespace(#[shmem(field_bound)] Impl::NamespaceUrl),
|
||||||
|
Namespace(
|
||||||
|
#[shmem(field_bound)] Impl::NamespacePrefix,
|
||||||
|
#[shmem(field_bound)] Impl::NamespaceUrl,
|
||||||
|
),
|
||||||
|
|
||||||
/// Pseudo-classes
|
/// Pseudo-classes
|
||||||
Negation(Box<[Selector<Impl>]>),
|
Negation(Box<[Selector<Impl>]>),
|
||||||
FirstChild,
|
FirstChild,
|
||||||
|
@ -1119,6 +1118,8 @@ pub enum Component<Impl: SelectorImpl> {
|
||||||
Is(Box<[Selector<Impl>]>),
|
Is(Box<[Selector<Impl>]>),
|
||||||
/// An implementation-dependent pseudo-element selector.
|
/// An implementation-dependent pseudo-element selector.
|
||||||
PseudoElement(#[cfg_attr(feature = "shmem", shmem(field_bound))] Impl::PseudoElement),
|
PseudoElement(#[cfg_attr(feature = "shmem", shmem(field_bound))] Impl::PseudoElement),
|
||||||
|
|
||||||
|
Combinator(Combinator),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Impl: SelectorImpl> Component<Impl> {
|
impl<Impl: SelectorImpl> Component<Impl> {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue