mirror of
https://github.com/servo/servo.git
synced 2025-08-08 06:55:31 +01:00
Don't expose any AtomicRefCell directly from style traits
This lets us experiment with how we store this data on the DOM side.
This commit is contained in:
parent
4c61baee30
commit
516e8e0aa6
9 changed files with 67 additions and 42 deletions
|
@ -22,7 +22,7 @@ use crate::shared_lock::Locked;
|
|||
use crate::stylist::CascadeData;
|
||||
use crate::traversal_flags::TraversalFlags;
|
||||
use crate::{Atom, LocalName, Namespace, WeakAtom};
|
||||
use atomic_refcell::{AtomicRef, AtomicRefCell, AtomicRefMut};
|
||||
use atomic_refcell::{AtomicRef, AtomicRefMut};
|
||||
use selectors::matching::{ElementSelectorFlags, QuirksMode, VisitedHandlingMode};
|
||||
use selectors::sink::Push;
|
||||
use selectors::Element as SelectorsElement;
|
||||
|
@ -689,18 +689,14 @@ pub trait TElement:
|
|||
/// Unsafe following the same reasoning as ensure_data.
|
||||
unsafe fn clear_data(&self);
|
||||
|
||||
/// Gets a reference to the ElementData container.
|
||||
fn get_data(&self) -> Option<&AtomicRefCell<ElementData>>;
|
||||
/// Whether there is an ElementData container.
|
||||
fn has_data(&self) -> bool;
|
||||
|
||||
/// Immutably borrows the ElementData.
|
||||
fn borrow_data(&self) -> Option<AtomicRef<ElementData>> {
|
||||
self.get_data().map(|x| x.borrow())
|
||||
}
|
||||
fn borrow_data(&self) -> Option<AtomicRef<ElementData>>;
|
||||
|
||||
/// Mutably borrows the ElementData.
|
||||
fn mutate_data(&self) -> Option<AtomicRefMut<ElementData>> {
|
||||
self.get_data().map(|x| x.borrow_mut())
|
||||
}
|
||||
fn mutate_data(&self) -> Option<AtomicRefMut<ElementData>>;
|
||||
|
||||
/// Whether we should skip any root- or item-based display property
|
||||
/// blockification on this element. (This function exists so that Gecko
|
||||
|
|
|
@ -557,6 +557,11 @@ impl<'le> fmt::Debug for GeckoElement<'le> {
|
|||
}
|
||||
|
||||
impl<'le> GeckoElement<'le> {
|
||||
#[inline(always)]
|
||||
fn get_data(&self) -> Option<&AtomicRefCell<ElementData>> {
|
||||
unsafe { self.0.mServoData.get().as_ref() }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn attrs(&self) -> &[structs::AttrArray_InternalAttr] {
|
||||
unsafe {
|
||||
|
@ -1299,7 +1304,7 @@ impl<'le> TElement for GeckoElement<'le> {
|
|||
}
|
||||
|
||||
unsafe fn set_handled_snapshot(&self) {
|
||||
debug_assert!(self.get_data().is_some());
|
||||
debug_assert!(self.has_data());
|
||||
self.set_flags(ELEMENT_HANDLED_SNAPSHOT as u32)
|
||||
}
|
||||
|
||||
|
@ -1309,7 +1314,7 @@ impl<'le> TElement for GeckoElement<'le> {
|
|||
}
|
||||
|
||||
unsafe fn set_dirty_descendants(&self) {
|
||||
debug_assert!(self.get_data().is_some());
|
||||
debug_assert!(self.has_data());
|
||||
debug!("Setting dirty descendants: {:?}", self);
|
||||
self.set_flags(ELEMENT_HAS_DIRTY_DESCENDANTS_FOR_SERVO as u32)
|
||||
}
|
||||
|
@ -1378,13 +1383,23 @@ impl<'le> TElement for GeckoElement<'le> {
|
|||
panic!("Atomic child count not implemented in Gecko");
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn get_data(&self) -> Option<&AtomicRefCell<ElementData>> {
|
||||
unsafe { self.0.mServoData.get().as_ref() }
|
||||
/// Whether there is an ElementData container.
|
||||
fn has_data(&self) -> bool {
|
||||
self.get_data().is_some()
|
||||
}
|
||||
|
||||
/// Immutably borrows the ElementData.
|
||||
fn borrow_data(&self) -> Option<AtomicRef<ElementData>> {
|
||||
self.get_data().map(|x| x.borrow())
|
||||
}
|
||||
|
||||
/// Mutably borrows the ElementData.
|
||||
fn mutate_data(&self) -> Option<AtomicRefMut<ElementData>> {
|
||||
self.get_data().map(|x| x.borrow_mut())
|
||||
}
|
||||
|
||||
unsafe fn ensure_data(&self) -> AtomicRefMut<ElementData> {
|
||||
if self.get_data().is_none() {
|
||||
if !self.has_data() {
|
||||
debug!("Creating ElementData for {:?}", self);
|
||||
let ptr = Box::into_raw(Box::new(AtomicRefCell::new(ElementData::default())));
|
||||
self.0.mServoData.set(ptr);
|
||||
|
|
|
@ -90,7 +90,7 @@ pub fn invalidated_descendants<E>(element: E, child: E)
|
|||
where
|
||||
E: TElement,
|
||||
{
|
||||
if child.get_data().is_none() {
|
||||
if !child.has_data() {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -845,7 +845,7 @@ where
|
|||
//
|
||||
// By consequence, any element without data has no descendants with
|
||||
// data.
|
||||
if kid.get_data().is_some() {
|
||||
if kid.has_data() {
|
||||
kid.clear_data();
|
||||
parents.push(kid);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue