mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
style: Move ANCHORS_RELATIVE_SELECTOR
out of nsINode flags
Move the flag to ComputedValueFlags, like `CONSIDERED_RELATIVE_SELECTOR`. Differential Revision: https://phabricator.services.mozilla.com/D180726
This commit is contained in:
parent
9321265b38
commit
ae5e0d49d8
7 changed files with 59 additions and 43 deletions
|
@ -99,6 +99,21 @@ impl QuirksMode {
|
|||
}
|
||||
}
|
||||
|
||||
/// Whether or not this matching considered relative selector.
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
pub enum RelativeSelectorMatchingState {
|
||||
/// Was not considered for any relative selector.
|
||||
None,
|
||||
/// Relative selector was considered for a match, but the element to be
|
||||
/// under matching would not anchor the relative selector. i.e. The
|
||||
/// relative selector was not part of the first compound selector (in match
|
||||
/// order).
|
||||
Considered,
|
||||
/// Same as above, but the relative selector was part of the first compound
|
||||
/// selector (in match order).
|
||||
ConsideredAnchor,
|
||||
}
|
||||
|
||||
/// 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.
|
||||
|
@ -146,7 +161,7 @@ where
|
|||
|
||||
/// The current element we're anchoring on for evaluating the relative selector.
|
||||
current_relative_selector_anchor: Option<OpaqueElement>,
|
||||
pub considered_relative_selector: bool,
|
||||
pub considered_relative_selector: RelativeSelectorMatchingState,
|
||||
|
||||
quirks_mode: QuirksMode,
|
||||
needs_selector_flags: NeedsSelectorFlags,
|
||||
|
@ -200,7 +215,7 @@ where
|
|||
pseudo_element_matching_fn: None,
|
||||
extra_data: Default::default(),
|
||||
current_relative_selector_anchor: None,
|
||||
considered_relative_selector: false,
|
||||
considered_relative_selector: RelativeSelectorMatchingState::None,
|
||||
_impl: ::std::marker::PhantomData,
|
||||
}
|
||||
}
|
||||
|
@ -329,12 +344,14 @@ where
|
|||
where
|
||||
F: FnOnce(&mut Self) -> R,
|
||||
{
|
||||
// TODO(dshin): Nesting should be rejected at parse time.
|
||||
let original_relative_selector_anchor = self.current_relative_selector_anchor.take();
|
||||
debug_assert!(
|
||||
self.current_relative_selector_anchor.is_none(),
|
||||
"Nesting should've been rejected at parse time"
|
||||
);
|
||||
self.current_relative_selector_anchor = Some(anchor);
|
||||
self.considered_relative_selector = RelativeSelectorMatchingState::Considered;
|
||||
let result = self.nest(f);
|
||||
self.current_relative_selector_anchor = original_relative_selector_anchor;
|
||||
self.considered_relative_selector = true;
|
||||
self.current_relative_selector_anchor = None;
|
||||
result
|
||||
}
|
||||
|
||||
|
|
|
@ -60,18 +60,13 @@ bitflags! {
|
|||
/// The element has an empty selector, so when a child is appended we
|
||||
/// might need to restyle the parent completely.
|
||||
const HAS_EMPTY_SELECTOR = 1 << 4;
|
||||
|
||||
/// This element has a relative selector that anchors to it, or may do so
|
||||
/// if its descendants or its later siblings change.
|
||||
const ANCHORS_RELATIVE_SELECTOR = 1 << 5;
|
||||
}
|
||||
}
|
||||
|
||||
impl ElementSelectorFlags {
|
||||
/// Returns the subset of flags that apply to the element.
|
||||
pub fn for_self(self) -> ElementSelectorFlags {
|
||||
self & (ElementSelectorFlags::HAS_EMPTY_SELECTOR |
|
||||
ElementSelectorFlags::ANCHORS_RELATIVE_SELECTOR)
|
||||
self & ElementSelectorFlags::HAS_EMPTY_SELECTOR
|
||||
}
|
||||
|
||||
/// Returns the subset of flags that apply to the parent.
|
||||
|
@ -370,12 +365,10 @@ fn matches_relative_selectors<E: Element>(
|
|||
element: &E,
|
||||
context: &mut MatchingContext<E::Impl>,
|
||||
) -> bool {
|
||||
if context.needs_selector_flags() {
|
||||
// If we've considered anchoring `:has()` selector while trying to match this element,
|
||||
// mark it as such, as it has implications on style sharing (See style sharing
|
||||
// code for further information).
|
||||
element.apply_selector_flags(ElementSelectorFlags::ANCHORS_RELATIVE_SELECTOR);
|
||||
}
|
||||
// If we've considered anchoring `:has()` selector while trying to match this element,
|
||||
// mark it as such, as it has implications on style sharing (See style sharing
|
||||
// code for further information).
|
||||
context.considered_relative_selector = RelativeSelectorMatchingState::ConsideredAnchor;
|
||||
for RelativeSelector {
|
||||
match_hint,
|
||||
selector,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue