From cb1a951477165f147ceff4eed35ea1b2ea664779 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Thu, 11 Jan 2018 12:37:47 +0100 Subject: [PATCH] style: Allow storing a DocumentState for invalidation. --- components/style/gecko/selector_parser.rs | 9 ++++++++- components/style/gecko/wrapper.rs | 23 ++++++++++++++++++----- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/components/style/gecko/selector_parser.rs b/components/style/gecko/selector_parser.rs index 417e5caec99..d4656f0c7fb 100644 --- a/components/style/gecko/selector_parser.rs +++ b/components/style/gecko/selector_parser.rs @@ -277,8 +277,15 @@ impl NonTSPseudoClass { #[derive(Clone, Debug, Eq, PartialEq)] pub struct SelectorImpl; +/// A struct holding the members necessary to invalidate document state +/// selectors. +pub struct InvalidationMatchingData { + /// The document state that has changed, which makes it always match. + pub document_state: DocumentState, +} + impl ::selectors::SelectorImpl for SelectorImpl { - type ExtraMatchingData = (); + type ExtraMatchingData = InvalidationMatchingData; type AttrValue = Atom; type Identifier = Atom; type ClassName = Atom; diff --git a/components/style/gecko/wrapper.rs b/components/style/gecko/wrapper.rs index 56ad17e6009..4de36a327d4 100644 --- a/components/style/gecko/wrapper.rs +++ b/components/style/gecko/wrapper.rs @@ -2110,8 +2110,14 @@ impl<'le> ::selectors::Element for GeckoElement<'le> { self.get_document_theme() == DocumentTheme::Doc_Theme_Dark } NonTSPseudoClass::MozWindowInactive => { - self.document_state() - .contains(DocumentState::NS_DOCUMENT_STATE_WINDOW_INACTIVE) + let state_bit = DocumentState::NS_DOCUMENT_STATE_WINDOW_INACTIVE; + if let Some(ref invalidation_data) = context.extra_data { + if invalidation_data.document_state.intersects(state_bit) { + return true; + } + } + + self.document_state().contains(state_bit) } NonTSPseudoClass::MozPlaceholder => false, NonTSPseudoClass::MozAny(ref sels) => { @@ -2126,9 +2132,16 @@ impl<'le> ::selectors::Element for GeckoElement<'le> { self.match_element_lang(None, lang_arg) } NonTSPseudoClass::MozLocaleDir(ref dir) => { - let doc_is_rtl = - self.document_state() - .contains(DocumentState::NS_DOCUMENT_STATE_RTL_LOCALE); + let state_bit = DocumentState::NS_DOCUMENT_STATE_RTL_LOCALE; + if let Some(ref invalidation_data) = context.extra_data { + // NOTE(emilio): We could still return false for + // Direction::Other(..), but we don't bother. + if invalidation_data.document_state.intersects(state_bit) { + return true; + } + } + + let doc_is_rtl = self.document_state().contains(state_bit); match **dir { Direction::Ltr => !doc_is_rtl,