mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
Auto merge of #19805 - emilio:doc-state-fix, r=xidorn
style: Handle correctly document state invalidation inside negation. <!-- Reviewable:start --> This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/19805) <!-- Reviewable:end -->
This commit is contained in:
commit
3b07be5553
5 changed files with 50 additions and 4 deletions
|
@ -127,6 +127,9 @@ where
|
||||||
/// MatchingContext immutable again.
|
/// MatchingContext immutable again.
|
||||||
nesting_level: usize,
|
nesting_level: usize,
|
||||||
|
|
||||||
|
/// Whether we're inside a negation or not.
|
||||||
|
in_negation: bool,
|
||||||
|
|
||||||
/// An optional hook function for checking whether a pseudo-element
|
/// An optional hook function for checking whether a pseudo-element
|
||||||
/// 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>,
|
||||||
|
@ -176,6 +179,7 @@ where
|
||||||
classes_and_ids_case_sensitivity: quirks_mode.classes_and_ids_case_sensitivity(),
|
classes_and_ids_case_sensitivity: quirks_mode.classes_and_ids_case_sensitivity(),
|
||||||
scope_element: None,
|
scope_element: None,
|
||||||
nesting_level: 0,
|
nesting_level: 0,
|
||||||
|
in_negation: false,
|
||||||
pseudo_element_matching_fn: None,
|
pseudo_element_matching_fn: None,
|
||||||
extra_data: Default::default(),
|
extra_data: Default::default(),
|
||||||
_impl: ::std::marker::PhantomData,
|
_impl: ::std::marker::PhantomData,
|
||||||
|
@ -188,6 +192,12 @@ where
|
||||||
self.nesting_level != 0
|
self.nesting_level != 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Whether we're matching inside a :not(..) selector.
|
||||||
|
#[inline]
|
||||||
|
pub fn in_negation(&self) -> bool {
|
||||||
|
self.in_negation
|
||||||
|
}
|
||||||
|
|
||||||
/// The quirks mode of the document.
|
/// The quirks mode of the document.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn quirks_mode(&self) -> QuirksMode {
|
pub fn quirks_mode(&self) -> QuirksMode {
|
||||||
|
@ -212,6 +222,23 @@ where
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Runs F with a deeper nesting level, and marking ourselves in a negation,
|
||||||
|
/// for a :not(..) selector, for example.
|
||||||
|
#[inline]
|
||||||
|
pub fn nest_for_negation<F, R>(&mut self, f: F) -> R
|
||||||
|
where
|
||||||
|
F: FnOnce(&mut Self) -> R,
|
||||||
|
{
|
||||||
|
debug_assert!(
|
||||||
|
!self.in_negation,
|
||||||
|
"Someone messed up parsing?"
|
||||||
|
);
|
||||||
|
self.in_negation = true;
|
||||||
|
let result = self.nest(f);
|
||||||
|
self.in_negation = false;
|
||||||
|
result
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn visited_handling(&self) -> VisitedHandlingMode {
|
pub fn visited_handling(&self) -> VisitedHandlingMode {
|
||||||
self.visited_handling
|
self.visited_handling
|
||||||
|
|
|
@ -625,6 +625,8 @@ where
|
||||||
E: Element,
|
E: Element,
|
||||||
F: FnMut(&E, ElementSelectorFlags),
|
F: FnMut(&E, ElementSelectorFlags),
|
||||||
{
|
{
|
||||||
|
debug_assert!(context.shared.is_nested() || !context.shared.in_negation());
|
||||||
|
|
||||||
match *selector {
|
match *selector {
|
||||||
Component::Combinator(_) => unreachable!(),
|
Component::Combinator(_) => unreachable!(),
|
||||||
Component::Slotted(ref selector) => {
|
Component::Slotted(ref selector) => {
|
||||||
|
@ -777,7 +779,7 @@ where
|
||||||
matches_generic_nth_child(element, context, 0, 1, true, true, flags_setter)
|
matches_generic_nth_child(element, context, 0, 1, true, true, flags_setter)
|
||||||
}
|
}
|
||||||
Component::Negation(ref negated) => {
|
Component::Negation(ref negated) => {
|
||||||
context.shared.nest(|context| {
|
context.shared.nest_for_negation(|context| {
|
||||||
let mut local_context = LocalMatchingContext {
|
let mut local_context = LocalMatchingContext {
|
||||||
matches_hover_and_active_quirk: MatchesHoverAndActiveQuirk::No,
|
matches_hover_and_active_quirk: MatchesHoverAndActiveQuirk::No,
|
||||||
shared: context,
|
shared: context,
|
||||||
|
|
|
@ -1151,6 +1151,8 @@ extern "C" {
|
||||||
pub fn Servo_Element_IsDisplayNone ( element : RawGeckoElementBorrowed , ) -> bool ;
|
pub fn Servo_Element_IsDisplayNone ( element : RawGeckoElementBorrowed , ) -> bool ;
|
||||||
} extern "C" {
|
} extern "C" {
|
||||||
pub fn Servo_Element_IsPrimaryStyleReusedViaRuleNode ( element : RawGeckoElementBorrowed , ) -> bool ;
|
pub fn Servo_Element_IsPrimaryStyleReusedViaRuleNode ( element : RawGeckoElementBorrowed , ) -> bool ;
|
||||||
|
} extern "C" {
|
||||||
|
pub fn Servo_InvalidateStyleForDocStateChanges ( root : RawGeckoElementBorrowed , sets : * const nsTArray < RawServoStyleSetBorrowed > , aStatesChanged : u64 , ) ;
|
||||||
} extern "C" {
|
} extern "C" {
|
||||||
pub fn Servo_StyleSheet_FromUTF8Bytes ( loader : * mut Loader , gecko_stylesheet : * mut ServoStyleSheet , data : * const u8 , data_len : usize , parsing_mode : SheetParsingMode , extra_data : * mut RawGeckoURLExtraData , line_number_offset : u32 , quirks_mode : nsCompatibility , reusable_sheets : * mut LoaderReusableStyleSheets , ) -> RawServoStyleSheetContentsStrong ;
|
pub fn Servo_StyleSheet_FromUTF8Bytes ( loader : * mut Loader , gecko_stylesheet : * mut ServoStyleSheet , data : * const u8 , data_len : usize , parsing_mode : SheetParsingMode , extra_data : * mut RawGeckoURLExtraData , line_number_offset : u32 , quirks_mode : nsCompatibility , reusable_sheets : * mut LoaderReusableStyleSheets , ) -> RawServoStyleSheetContentsStrong ;
|
||||||
} extern "C" {
|
} extern "C" {
|
||||||
|
@ -1595,4 +1597,4 @@ extern "C" {
|
||||||
pub fn Gecko_IsInServoTraversal ( ) -> bool ;
|
pub fn Gecko_IsInServoTraversal ( ) -> bool ;
|
||||||
} extern "C" {
|
} extern "C" {
|
||||||
pub fn Gecko_IsMainThread ( ) -> bool ;
|
pub fn Gecko_IsMainThread ( ) -> bool ;
|
||||||
}
|
}
|
|
@ -2111,7 +2111,7 @@ impl<'le> ::selectors::Element for GeckoElement<'le> {
|
||||||
NonTSPseudoClass::MozWindowInactive => {
|
NonTSPseudoClass::MozWindowInactive => {
|
||||||
let state_bit = DocumentState::NS_DOCUMENT_STATE_WINDOW_INACTIVE;
|
let state_bit = DocumentState::NS_DOCUMENT_STATE_WINDOW_INACTIVE;
|
||||||
if context.extra_data.document_state.intersects(state_bit) {
|
if context.extra_data.document_state.intersects(state_bit) {
|
||||||
return true;
|
return !context.in_negation();
|
||||||
}
|
}
|
||||||
|
|
||||||
self.document_state().contains(state_bit)
|
self.document_state().contains(state_bit)
|
||||||
|
@ -2132,7 +2132,7 @@ impl<'le> ::selectors::Element for GeckoElement<'le> {
|
||||||
if context.extra_data.document_state.intersects(state_bit) {
|
if context.extra_data.document_state.intersects(state_bit) {
|
||||||
// NOTE(emilio): We could still return false for
|
// NOTE(emilio): We could still return false for
|
||||||
// Direction::Other(..), but we don't bother.
|
// Direction::Other(..), but we don't bother.
|
||||||
return true;
|
return !context.in_negation();
|
||||||
}
|
}
|
||||||
|
|
||||||
let doc_is_rtl = self.document_state().contains(state_bit);
|
let doc_is_rtl = self.document_state().contains(state_bit);
|
||||||
|
|
|
@ -39,6 +39,21 @@ fn main() {
|
||||||
for line in r.lines() {
|
for line in r.lines() {
|
||||||
let s = line.unwrap();
|
let s = line.unwrap();
|
||||||
for cap in matcher.captures_iter(&s) {
|
for cap in matcher.captures_iter(&s) {
|
||||||
|
// This causes a mismatch in old libclangs (the ones that are
|
||||||
|
// used in linux32 mozilla-central) because it generates:
|
||||||
|
//
|
||||||
|
// *const nsTArray<*const RawServoStyleSet>
|
||||||
|
//
|
||||||
|
// Instead of:
|
||||||
|
//
|
||||||
|
// *const nsTArray<RawServoStyleSetBorrowed>
|
||||||
|
//
|
||||||
|
// Which is not a problem, but would cause this to not compile.
|
||||||
|
//
|
||||||
|
// Skip this until libclang is updated there.
|
||||||
|
if &cap[1] == "InvalidateStyleForDocStateChanges" {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
w.write_all(format!(" [ Servo_{0}, bindings::Servo_{0} ];\n", &cap[1]).as_bytes()).unwrap();
|
w.write_all(format!(" [ Servo_{0}, bindings::Servo_{0} ];\n", &cap[1]).as_bytes()).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue