Revert "Backport several style changes from Gecko (5) (#30099)" (#30104)

This reverts commit 8e15389cae.
This commit is contained in:
Oriol Brufau 2023-08-16 08:24:42 +02:00 committed by GitHub
parent 8e15389cae
commit d6ae8dc112
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
152 changed files with 4622 additions and 5862 deletions

View file

@ -28,7 +28,6 @@ log = "0.4"
phf = "0.10"
precomputed-hash = "0.1"
servo_arc = { version = "0.2", path = "../servo_arc" }
size_of_test = { path = "../size_of_test" }
smallvec = "1.0"
to_shmem = { version = "0.0.0", path = "../to_shmem", optional = true }
to_shmem_derive = { version = "0.0.0", path = "../to_shmem_derive", optional = true }

View file

@ -68,14 +68,6 @@ impl VisitedHandlingMode {
}
}
/// Whether we need to set selector invalidation flags on elements for this
/// match request.
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum NeedsSelectorFlags {
No,
Yes,
}
/// Which quirks mode is this document in.
///
/// See: https://quirks.spec.whatwg.org/
@ -148,7 +140,6 @@ where
pub extra_data: Impl::ExtraMatchingData,
quirks_mode: QuirksMode,
needs_selector_flags: NeedsSelectorFlags,
classes_and_ids_case_sensitivity: CaseSensitivity,
_impl: ::std::marker::PhantomData<Impl>,
}
@ -163,7 +154,6 @@ where
bloom_filter: Option<&'a BloomFilter>,
nth_index_cache: Option<&'a mut NthIndexCache>,
quirks_mode: QuirksMode,
needs_selector_flags: NeedsSelectorFlags,
) -> Self {
Self::new_for_visited(
matching_mode,
@ -171,7 +161,6 @@ where
nth_index_cache,
VisitedHandlingMode::AllLinksUnvisited,
quirks_mode,
needs_selector_flags,
)
}
@ -182,7 +171,6 @@ where
nth_index_cache: Option<&'a mut NthIndexCache>,
visited_handling: VisitedHandlingMode,
quirks_mode: QuirksMode,
needs_selector_flags: NeedsSelectorFlags,
) -> Self {
Self {
matching_mode,
@ -191,7 +179,6 @@ where
nth_index_cache,
quirks_mode,
classes_and_ids_case_sensitivity: quirks_mode.classes_and_ids_case_sensitivity(),
needs_selector_flags,
scope_element: None,
current_host: None,
nesting_level: 0,
@ -226,12 +213,6 @@ where
self.matching_mode
}
/// Whether we need to set selector flags.
#[inline]
pub fn needs_selector_flags(&self) -> bool {
self.needs_selector_flags == NeedsSelectorFlags::Yes
}
/// The case-sensitivity for class and ID selectors
#[inline]
pub fn classes_and_ids_case_sensitivity(&self) -> CaseSensitivity {

View file

@ -5,9 +5,6 @@
// Make |cargo bench| work.
#![cfg_attr(feature = "bench", feature(test))]
#[macro_use]
extern crate size_of_test;
pub mod attr;
pub mod bloom;
mod builder;

View file

@ -78,7 +78,8 @@ where
// This is pretty much any(..) but manually inlined because the compiler
// refuses to do so from querySelector / querySelectorAll.
for selector in &selector_list.0 {
let matches = matches_selector(selector, 0, None, element, context);
let matches = matches_selector(selector, 0, None, element, context, &mut |_, _| {});
if matches {
return true;
}
@ -183,15 +184,17 @@ enum MatchesHoverAndActiveQuirk {
/// unncessary cache miss for cases when we can fast-reject with AncestorHashes
/// (which the caller can store inline with the selector pointer).
#[inline(always)]
pub fn matches_selector<E>(
pub fn matches_selector<E, F>(
selector: &Selector<E::Impl>,
offset: usize,
hashes: Option<&AncestorHashes>,
element: &E,
context: &mut MatchingContext<E::Impl>,
flags_setter: &mut F,
) -> bool
where
E: Element,
F: FnMut(&E, ElementSelectorFlags),
{
// Use the bloom filter to fast-reject.
if let Some(hashes) = hashes {
@ -202,7 +205,7 @@ where
}
}
matches_complex_selector(selector.iter_from(offset), element, context)
matches_complex_selector(selector.iter_from(offset), element, context, flags_setter)
}
/// Whether a compound selector matched, and whether it was the rightmost
@ -274,7 +277,7 @@ where
);
for component in iter {
if !matches_simple_selector(component, element, &mut local_context) {
if !matches_simple_selector(component, element, &mut local_context, &mut |_, _| {}) {
return CompoundSelectorMatchingResult::NotMatched;
}
}
@ -290,13 +293,15 @@ where
/// Matches a complex selector.
#[inline(always)]
pub fn matches_complex_selector<E>(
pub fn matches_complex_selector<E, F>(
mut iter: SelectorIter<E::Impl>,
element: &E,
context: &mut MatchingContext<E::Impl>,
flags_setter: &mut F,
) -> bool
where
E: Element,
F: FnMut(&E, ElementSelectorFlags),
{
// If this is the special pseudo-element mode, consume the ::pseudo-element
// before proceeding, since the caller has already handled that part.
@ -329,7 +334,7 @@ where
}
let result =
matches_complex_selector_internal(iter, element, context, Rightmost::Yes);
matches_complex_selector_internal(iter, element, context, flags_setter, Rightmost::Yes);
matches!(result, SelectorMatchingResult::Matched)
}
@ -453,14 +458,16 @@ where
}
}
fn matches_complex_selector_internal<E>(
fn matches_complex_selector_internal<E, F>(
mut selector_iter: SelectorIter<E::Impl>,
element: &E,
context: &mut MatchingContext<E::Impl>,
flags_setter: &mut F,
rightmost: Rightmost,
) -> SelectorMatchingResult
where
E: Element,
F: FnMut(&E, ElementSelectorFlags),
{
debug!(
"Matching complex selector {:?} for {:?}",
@ -471,16 +478,16 @@ where
&mut selector_iter,
element,
context,
flags_setter,
rightmost,
);
let combinator = selector_iter.next_sequence();
if combinator.map_or(false, |c| c.is_sibling()) {
if context.needs_selector_flags() {
element.apply_selector_flags(
ElementSelectorFlags::HAS_SLOW_SELECTOR_LATER_SIBLINGS
);
}
flags_setter(
element,
ElementSelectorFlags::HAS_SLOW_SELECTOR_LATER_SIBLINGS,
);
}
if !matches_compound_selector {
@ -525,6 +532,7 @@ where
selector_iter.clone(),
&element,
context,
flags_setter,
Rightmost::No,
)
});
@ -587,14 +595,16 @@ where
/// Determines whether the given element matches the given compound selector.
#[inline]
fn matches_compound_selector<E>(
fn matches_compound_selector<E, F>(
selector_iter: &mut SelectorIter<E::Impl>,
element: &E,
context: &mut MatchingContext<E::Impl>,
flags_setter: &mut F,
rightmost: Rightmost,
) -> bool
where
E: Element,
F: FnMut(&E, ElementSelectorFlags),
{
let matches_hover_and_active_quirk =
matches_hover_and_active_quirk(&selector_iter, context, rightmost);
@ -633,17 +643,19 @@ where
};
iter::once(selector)
.chain(selector_iter)
.all(|simple| matches_simple_selector(simple, element, &mut local_context))
.all(|simple| matches_simple_selector(simple, element, &mut local_context, flags_setter))
}
/// Determines whether the given element matches the given single selector.
fn matches_simple_selector<E>(
fn matches_simple_selector<E, F>(
selector: &Component<E::Impl>,
element: &E,
context: &mut LocalMatchingContext<E::Impl>,
flags_setter: &mut F,
) -> bool
where
E: Element,
F: FnMut(&E, ElementSelectorFlags),
{
debug_assert!(context.shared.is_nested() || !context.shared.in_negation());
@ -691,7 +703,7 @@ where
// <slots> are never flattened tree slottables.
!element.is_html_slot_element() &&
context.shared.nest(|context| {
matches_complex_selector(selector.iter(), element, context)
matches_complex_selector(selector.iter(), element, context, flags_setter)
})
},
Component::PseudoElement(ref pseudo) => {
@ -783,18 +795,16 @@ where
return false;
}
element.match_non_ts_pseudo_class(pc, &mut context.shared)
element.match_non_ts_pseudo_class(pc, &mut context.shared, flags_setter)
},
Component::FirstChild => matches_first_child(element, context.shared),
Component::LastChild => matches_last_child(element, context.shared),
Component::FirstChild => matches_first_child(element, flags_setter),
Component::LastChild => matches_last_child(element, flags_setter),
Component::OnlyChild => {
matches_first_child(element, context.shared) && matches_last_child(element, context.shared)
matches_first_child(element, flags_setter) && matches_last_child(element, flags_setter)
},
Component::Root => element.is_root(),
Component::Empty => {
if context.shared.needs_selector_flags() {
element.apply_selector_flags(ElementSelectorFlags::HAS_EMPTY_SELECTOR);
}
flags_setter(element, ElementSelectorFlags::HAS_EMPTY_SELECTOR);
element.is_empty()
},
Component::Host(ref selector) => {
@ -804,7 +814,7 @@ where
.map_or(false, |host| host == element.opaque()) &&
selector.as_ref().map_or(true, |selector| {
context.shared.nest(|context| {
matches_complex_selector(selector.iter(), element, context)
matches_complex_selector(selector.iter(), element, context, flags_setter)
})
})
},
@ -813,30 +823,30 @@ where
None => element.is_root(),
},
Component::NthChild(a, b) => {
matches_generic_nth_child(element, context.shared, a, b, false, false)
matches_generic_nth_child(element, context, a, b, false, false, flags_setter)
},
Component::NthLastChild(a, b) => {
matches_generic_nth_child(element, context.shared, a, b, false, true)
matches_generic_nth_child(element, context, a, b, false, true, flags_setter)
},
Component::NthOfType(a, b) => {
matches_generic_nth_child(element, context.shared, a, b, true, false)
matches_generic_nth_child(element, context, a, b, true, false, flags_setter)
},
Component::NthLastOfType(a, b) => {
matches_generic_nth_child(element, context.shared, a, b, true, true)
matches_generic_nth_child(element, context, a, b, true, true, flags_setter)
},
Component::FirstOfType => {
matches_generic_nth_child(element, context.shared, 0, 1, true, false)
matches_generic_nth_child(element, context, 0, 1, true, false, flags_setter)
},
Component::LastOfType => {
matches_generic_nth_child(element, context.shared, 0, 1, true, true)
matches_generic_nth_child(element, context, 0, 1, true, true, flags_setter)
},
Component::OnlyOfType => {
matches_generic_nth_child(element, context.shared, 0, 1, true, false) &&
matches_generic_nth_child(element, context.shared, 0, 1, true, true)
matches_generic_nth_child(element, context, 0, 1, true, false, flags_setter) &&
matches_generic_nth_child(element, context, 0, 1, true, true, flags_setter)
},
Component::Is(ref list) | Component::Where(ref list) => context.shared.nest(|context| {
for selector in &**list {
if matches_complex_selector(selector.iter(), element, context) {
if matches_complex_selector(selector.iter(), element, context, flags_setter) {
return true;
}
}
@ -844,7 +854,7 @@ where
}),
Component::Negation(ref list) => context.shared.nest_for_negation(|context| {
for selector in &**list {
if matches_complex_selector(selector.iter(), element, context) {
if matches_complex_selector(selector.iter(), element, context, flags_setter) {
return false;
}
}
@ -863,31 +873,35 @@ fn select_name<'a, T>(is_html: bool, local_name: &'a T, local_name_lower: &'a T)
}
#[inline]
fn matches_generic_nth_child<E>(
fn matches_generic_nth_child<E, F>(
element: &E,
context: &mut MatchingContext<E::Impl>,
context: &mut LocalMatchingContext<E::Impl>,
a: i32,
b: i32,
is_of_type: bool,
is_from_end: bool,
flags_setter: &mut F,
) -> bool
where
E: Element,
F: FnMut(&E, ElementSelectorFlags),
{
if element.ignores_nth_child_selectors() {
return false;
}
if context.needs_selector_flags() {
element.apply_selector_flags(if is_from_end {
flags_setter(
element,
if is_from_end {
ElementSelectorFlags::HAS_SLOW_SELECTOR
} else {
ElementSelectorFlags::HAS_SLOW_SELECTOR_LATER_SIBLINGS
});
}
},
);
// Grab a reference to the appropriate cache.
let mut cache = context
.shared
.nth_index_cache
.as_mut()
.map(|c| c.get(is_of_type, is_from_end));
@ -978,23 +992,21 @@ where
}
#[inline]
fn matches_first_child<E>(element: &E, context: &MatchingContext<E::Impl>) -> bool
fn matches_first_child<E, F>(element: &E, flags_setter: &mut F) -> bool
where
E: Element,
F: FnMut(&E, ElementSelectorFlags),
{
if context.needs_selector_flags() {
element.apply_selector_flags(ElementSelectorFlags::HAS_EDGE_CHILD_SELECTOR);
}
flags_setter(element, ElementSelectorFlags::HAS_EDGE_CHILD_SELECTOR);
element.prev_sibling_element().is_none()
}
#[inline]
fn matches_last_child<E>(element: &E, context: &MatchingContext<E::Impl>) -> bool
fn matches_last_child<E, F>(element: &E, flags_setter: &mut F) -> bool
where
E: Element,
F: FnMut(&E, ElementSelectorFlags),
{
if context.needs_selector_flags() {
element.apply_selector_flags(ElementSelectorFlags::HAS_EDGE_CHILD_SELECTOR);
}
flags_setter(element, ElementSelectorFlags::HAS_EDGE_CHILD_SELECTOR);
element.next_sibling_element().is_none()
}

View file

@ -160,8 +160,6 @@ impl SelectorParsingState {
pub type SelectorParseError<'i> = ParseError<'i, SelectorParseErrorKind<'i>>;
size_of_test!(SelectorParseError, 48);
#[derive(Clone, Debug, PartialEq)]
pub enum SelectorParseErrorKind<'i> {
NoQualifiedNameInAttributeSelector(Token<'i>),
@ -186,8 +184,6 @@ pub enum SelectorParseErrorKind<'i> {
ClassNeedsIdent(Token<'i>),
}
size_of_test!(SelectorParseErrorKind, 40);
macro_rules! with_all_bounds {
(
[ $( $InSelector: tt )* ]

View file

@ -1 +0,0 @@
disable_all_formatting = true

View file

@ -77,11 +77,14 @@ pub trait Element: Sized + Clone + Debug {
operation: &AttrSelectorOperation<&<Self::Impl as SelectorImpl>::AttrValue>,
) -> bool;
fn match_non_ts_pseudo_class(
fn match_non_ts_pseudo_class<F>(
&self,
pc: &<Self::Impl as SelectorImpl>::NonTSPseudoClass,
context: &mut MatchingContext<Self::Impl>,
) -> bool;
flags_setter: &mut F,
) -> bool
where
F: FnMut(&Self, ElementSelectorFlags);
fn match_pseudo_element(
&self,
@ -89,30 +92,6 @@ pub trait Element: Sized + Clone + Debug {
context: &mut MatchingContext<Self::Impl>,
) -> bool;
/// Sets selector flags, which indicate what kinds of selectors may have
/// matched on this element and therefore what kind of work may need to
/// be performed when DOM state changes.
///
/// You probably don't want to use this directly and want to use
/// apply_selector_flags, since that sets flags on the parent as needed.
fn set_selector_flags(&self, flags: ElementSelectorFlags);
fn apply_selector_flags(&self, flags: ElementSelectorFlags) {
// Handle flags that apply to the element.
let self_flags = flags.for_self();
if !self_flags.is_empty() {
self.set_selector_flags(self_flags);
}
// Handle flags that apply to the parent.
let parent_flags = flags.for_parent();
if !parent_flags.is_empty() {
if let Some(p) = self.parent_element() {
p.set_selector_flags(parent_flags);
}
}
}
/// Whether this element is a `link`.
fn is_link(&self) -> bool;