style: Use more CascadeData and less Stylist for XBL stuff.

Just some more uses of Stylist in XBL that can be converted right away.

I'm trying to make XBL not use a Stylist, slowly...
This commit is contained in:
Emilio Cobos Álvarez 2018-02-12 11:19:46 +01:00
parent 4913d9c900
commit 1bb6ce2c88
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
3 changed files with 23 additions and 35 deletions

View file

@ -31,7 +31,7 @@ use std::fmt;
use std::fmt::Debug; use std::fmt::Debug;
use std::hash::Hash; use std::hash::Hash;
use std::ops::Deref; use std::ops::Deref;
use stylist::{CascadeData, Stylist}; use stylist::CascadeData;
use traversal_flags::TraversalFlags; use traversal_flags::TraversalFlags;
/// An opaque handle to a node, which, unlike UnsafeNode, cannot be transformed /// An opaque handle to a node, which, unlike UnsafeNode, cannot be transformed
@ -751,10 +751,10 @@ pub trait TElement
/// Implements Gecko's `nsBindingManager::WalkRules`. /// Implements Gecko's `nsBindingManager::WalkRules`.
/// ///
/// Returns whether to cut off the inheritance. /// Returns whether to cut off the inheritance.
fn each_xbl_stylist<'a, F>(&self, _: F) -> bool fn each_xbl_cascade_data<'a, F>(&self, _: F) -> bool
where where
Self: 'a, Self: 'a,
F: FnMut(AtomicRef<'a, Stylist>), F: FnMut(AtomicRef<'a, CascadeData>, QuirksMode),
{ {
false false
} }
@ -768,24 +768,11 @@ pub trait TElement
Self: 'a, Self: 'a,
F: FnMut(AtomicRef<'a, CascadeData>, QuirksMode), F: FnMut(AtomicRef<'a, CascadeData>, QuirksMode),
{ {
let cut_off_inheritance = self.each_xbl_stylist(|stylist| { let cut_off_inheritance = self.each_xbl_cascade_data(&mut f);
let quirks_mode = stylist.quirks_mode();
f(
AtomicRef::map(stylist, |stylist| stylist.author_cascade_data()),
quirks_mode,
)
});
let mut current = self.assigned_slot(); let mut current = self.assigned_slot();
while let Some(slot) = current { while let Some(slot) = current {
slot.each_xbl_stylist(|stylist| { slot.each_xbl_cascade_data(&mut f);
let quirks_mode = stylist.quirks_mode();
f(
AtomicRef::map(stylist, |stylist| stylist.author_cascade_data()),
quirks_mode,
)
});
current = slot.assigned_slot(); current = slot.assigned_slot();
} }
@ -794,8 +781,9 @@ pub trait TElement
/// Gets the current existing CSS transitions, by |property, end value| pairs in a FnvHashMap. /// Gets the current existing CSS transitions, by |property, end value| pairs in a FnvHashMap.
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
fn get_css_transitions_info(&self) fn get_css_transitions_info(
-> FnvHashMap<LonghandId, Arc<AnimationValue>>; &self,
) -> FnvHashMap<LonghandId, Arc<AnimationValue>>;
/// Does a rough (and cheap) check for whether or not transitions might need to be updated that /// Does a rough (and cheap) check for whether or not transitions might need to be updated that
/// will quickly return false for the common case of no transitions specified or running. If /// will quickly return false for the common case of no transitions specified or running. If

View file

@ -86,7 +86,7 @@ use std::mem;
use std::ops::DerefMut; use std::ops::DerefMut;
use std::ptr; use std::ptr;
use string_cache::{Atom, Namespace, WeakAtom, WeakNamespace}; use string_cache::{Atom, Namespace, WeakAtom, WeakNamespace};
use stylist::Stylist; use stylist::CascadeData;
/// A simple wrapper over `nsIDocument`. /// A simple wrapper over `nsIDocument`.
#[derive(Clone, Copy)] #[derive(Clone, Copy)]
@ -429,12 +429,12 @@ impl<'lb> GeckoXBLBinding<'lb> {
} }
} }
fn each_xbl_stylist<F>(&self, f: &mut F) fn each_xbl_cascade_data<F>(&self, f: &mut F)
where where
F: FnMut(AtomicRef<'lb, Stylist>), F: FnMut(AtomicRef<'lb, CascadeData>, QuirksMode),
{ {
if let Some(base) = self.base_binding() { if let Some(base) = self.base_binding() {
base.each_xbl_stylist(f); base.each_xbl_cascade_data(f);
} }
let raw_data = unsafe { let raw_data = unsafe {
@ -443,7 +443,8 @@ impl<'lb> GeckoXBLBinding<'lb> {
if let Some(raw_data) = raw_data { if let Some(raw_data) = raw_data {
let data = PerDocumentStyleData::from_ffi(&*raw_data).borrow(); let data = PerDocumentStyleData::from_ffi(&*raw_data).borrow();
f(AtomicRef::map(data, |d| &d.stylist)); let quirks_mode = data.stylist.quirks_mode();
f(AtomicRef::map(data, |d| d.stylist.author_cascade_data()), quirks_mode);
} }
} }
} }
@ -1374,10 +1375,10 @@ impl<'le> TElement for GeckoElement<'le> {
self.may_have_animations() && unsafe { Gecko_ElementHasCSSTransitions(self.0) } self.may_have_animations() && unsafe { Gecko_ElementHasCSSTransitions(self.0) }
} }
fn each_xbl_stylist<'a, F>(&self, mut f: F) -> bool fn each_xbl_cascade_data<'a, F>(&self, mut f: F) -> bool
where where
'le: 'a, 'le: 'a,
F: FnMut(AtomicRef<'a, Stylist>), F: FnMut(AtomicRef<'a, CascadeData>, QuirksMode),
{ {
// Walk the binding scope chain, starting with the binding attached to // Walk the binding scope chain, starting with the binding attached to
// our content, up till we run out of scopes or we get cut off. // our content, up till we run out of scopes or we get cut off.
@ -1388,7 +1389,7 @@ impl<'le> TElement for GeckoElement<'le> {
while let Some(element) = current { while let Some(element) = current {
if let Some(binding) = element.get_xbl_binding() { if let Some(binding) = element.get_xbl_binding() {
binding.each_xbl_stylist(&mut f); binding.each_xbl_cascade_data(&mut f);
// If we're not looking at our original element, allow the // If we're not looking at our original element, allow the
// binding to cut off style inheritance. // binding to cut off style inheritance.
@ -1416,8 +1417,7 @@ impl<'le> TElement for GeckoElement<'le> {
fn xbl_binding_anonymous_content(&self) -> Option<GeckoNode<'le>> { fn xbl_binding_anonymous_content(&self) -> Option<GeckoNode<'le>> {
self.get_xbl_binding_with_content() self.get_xbl_binding_with_content()
.map(|b| unsafe { b.anon_content().as_ref() }.unwrap()) .map(|b| unsafe { GeckoNode::from_content(&*b.anon_content()) })
.map(GeckoNode::from_content)
} }
fn get_css_transitions_info( fn get_css_transitions_info(

View file

@ -1268,8 +1268,8 @@ impl Stylist {
} }
for slot in slots.iter().rev() { for slot in slots.iter().rev() {
slot.each_xbl_stylist(|stylist| { slot.each_xbl_cascade_data(|cascade_data, _quirks_mode| {
if let Some(map) = stylist.cascade_data.author.slotted_rules(pseudo_element) { if let Some(map) = cascade_data.slotted_rules(pseudo_element) {
map.get_all_matching_rules( map.get_all_matching_rules(
element, element,
rule_hash_target, rule_hash_target,
@ -1287,8 +1287,8 @@ impl Stylist {
// even for getDefaultComputedStyle! // even for getDefaultComputedStyle!
// //
// Also, this doesn't account for the author_styles_enabled stuff. // Also, this doesn't account for the author_styles_enabled stuff.
let cut_off_inheritance = element.each_xbl_stylist(|stylist| { let cut_off_inheritance = element.each_xbl_cascade_data(|cascade_data, quirks_mode| {
if let Some(map) = stylist.cascade_data.author.normal_rules(pseudo_element) { if let Some(map) = cascade_data.normal_rules(pseudo_element) {
// NOTE(emilio): This is needed because the XBL stylist may // NOTE(emilio): This is needed because the XBL stylist may
// think it has a different quirks mode than the document. // think it has a different quirks mode than the document.
// //
@ -1299,7 +1299,7 @@ impl Stylist {
context.matching_mode(), context.matching_mode(),
context.bloom_filter, context.bloom_filter,
context.nth_index_cache.as_mut().map(|s| &mut **s), context.nth_index_cache.as_mut().map(|s| &mut **s),
stylist.quirks_mode, quirks_mode,
); );
matching_context.pseudo_element_matching_fn = context.pseudo_element_matching_fn; matching_context.pseudo_element_matching_fn = context.pseudo_element_matching_fn;