mirror of
https://github.com/servo/servo.git
synced 2025-07-23 07:13:52 +01:00
Rename PrivateStyleData to PersistentStyleData and use AtomicRefCell instead of RefCell as a container.
This allows us to eliminate the unsafe borrows. \o/ MozReview-Commit-ID: 29hpGaWUFQz
This commit is contained in:
parent
5bcc4192bf
commit
687e1f701c
12 changed files with 96 additions and 142 deletions
|
@ -52,11 +52,11 @@ use core::nonzero::NonZero;
|
|||
use ipc_channel::ipc::IpcSender;
|
||||
use libc::c_void;
|
||||
use restyle_damage::RestyleDamage;
|
||||
use style::data::PrivateStyleData;
|
||||
use style::refcell::RefCell;
|
||||
use style::atomic_refcell::AtomicRefCell;
|
||||
use style::data::PersistentStyleData;
|
||||
|
||||
pub struct PartialStyleAndLayoutData {
|
||||
pub style_data: PrivateStyleData,
|
||||
pub struct PartialPersistentLayoutData {
|
||||
pub style_data: PersistentStyleData,
|
||||
pub restyle_damage: RestyleDamage,
|
||||
}
|
||||
|
||||
|
@ -64,7 +64,7 @@ pub struct PartialStyleAndLayoutData {
|
|||
pub struct OpaqueStyleAndLayoutData {
|
||||
#[ignore_heap_size_of = "TODO(#6910) Box value that should be counted but \
|
||||
the type lives in layout"]
|
||||
pub ptr: NonZero<*mut RefCell<PartialStyleAndLayoutData>>
|
||||
pub ptr: NonZero<*mut AtomicRefCell<PartialPersistentLayoutData>>
|
||||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
use HTMLCanvasData;
|
||||
use LayoutNodeType;
|
||||
use OpaqueStyleAndLayoutData;
|
||||
use PartialStyleAndLayoutData;
|
||||
use gfx_traits::{ByteIndex, LayerId, LayerType};
|
||||
use msg::constellation_msg::PipelineId;
|
||||
use range::Range;
|
||||
|
@ -13,12 +12,13 @@ use restyle_damage::RestyleDamage;
|
|||
use std::fmt::Debug;
|
||||
use std::sync::Arc;
|
||||
use string_cache::{Atom, Namespace};
|
||||
use style::atomic_refcell::AtomicRefCell;
|
||||
use style::computed_values::display;
|
||||
use style::context::SharedStyleContext;
|
||||
use style::data::PersistentStyleData;
|
||||
use style::dom::{LayoutIterator, NodeInfo, PresentationalHintsSynthetizer, TNode};
|
||||
use style::dom::OpaqueNode;
|
||||
use style::properties::ServoComputedValues;
|
||||
use style::refcell::RefCell;
|
||||
use style::selector_impl::{PseudoElement, PseudoElementCascadeType, ServoSelectorImpl};
|
||||
use url::Url;
|
||||
|
||||
|
@ -76,7 +76,7 @@ pub trait LayoutNode: TNode {
|
|||
/// Returns the type ID of this node.
|
||||
fn type_id(&self) -> LayoutNodeType;
|
||||
|
||||
fn get_style_data(&self) -> Option<&RefCell<PartialStyleAndLayoutData>>;
|
||||
fn get_style_data(&self) -> Option<&AtomicRefCell<PersistentStyleData>>;
|
||||
|
||||
fn init_style_and_layout_data(&self, data: OpaqueStyleAndLayoutData);
|
||||
fn get_style_and_layout_data(&self) -> Option<OpaqueStyleAndLayoutData>;
|
||||
|
@ -183,7 +183,6 @@ pub trait ThreadSafeLayoutNode: Clone + Copy + NodeInfo + PartialEq + Sized {
|
|||
if self.get_style_data()
|
||||
.unwrap()
|
||||
.borrow()
|
||||
.style_data
|
||||
.per_pseudo
|
||||
.contains_key(&PseudoElement::Before) {
|
||||
Some(self.with_pseudo(PseudoElementType::Before(None)))
|
||||
|
@ -197,7 +196,6 @@ pub trait ThreadSafeLayoutNode: Clone + Copy + NodeInfo + PartialEq + Sized {
|
|||
if self.get_style_data()
|
||||
.unwrap()
|
||||
.borrow()
|
||||
.style_data
|
||||
.per_pseudo
|
||||
.contains_key(&PseudoElement::After) {
|
||||
Some(self.with_pseudo(PseudoElementType::After(None)))
|
||||
|
@ -244,7 +242,7 @@ pub trait ThreadSafeLayoutNode: Clone + Copy + NodeInfo + PartialEq + Sized {
|
|||
match self.get_pseudo_element_type() {
|
||||
PseudoElementType::Normal => {
|
||||
self.get_style_data().unwrap().borrow()
|
||||
.style_data.style.as_ref().unwrap().clone()
|
||||
.style.as_ref().unwrap().clone()
|
||||
},
|
||||
other => {
|
||||
// Precompute non-eagerly-cascaded pseudo-element styles if not
|
||||
|
@ -257,14 +255,13 @@ pub trait ThreadSafeLayoutNode: Clone + Copy + NodeInfo + PartialEq + Sized {
|
|||
if !self.get_style_data()
|
||||
.unwrap()
|
||||
.borrow()
|
||||
.style_data
|
||||
.per_pseudo.contains_key(&style_pseudo) {
|
||||
let mut data = self.get_style_data().unwrap().borrow_mut();
|
||||
let new_style =
|
||||
context.stylist
|
||||
.precomputed_values_for_pseudo(&style_pseudo,
|
||||
data.style_data.style.as_ref());
|
||||
data.style_data.per_pseudo
|
||||
data.style.as_ref());
|
||||
data.per_pseudo
|
||||
.insert(style_pseudo.clone(), new_style.unwrap());
|
||||
}
|
||||
}
|
||||
|
@ -273,7 +270,6 @@ pub trait ThreadSafeLayoutNode: Clone + Copy + NodeInfo + PartialEq + Sized {
|
|||
if !self.get_style_data()
|
||||
.unwrap()
|
||||
.borrow()
|
||||
.style_data
|
||||
.per_pseudo.contains_key(&style_pseudo) {
|
||||
let mut data = self.get_style_data().unwrap().borrow_mut();
|
||||
let new_style =
|
||||
|
@ -281,15 +277,15 @@ pub trait ThreadSafeLayoutNode: Clone + Copy + NodeInfo + PartialEq + Sized {
|
|||
.lazily_compute_pseudo_element_style(
|
||||
&self.as_element(),
|
||||
&style_pseudo,
|
||||
data.style_data.style.as_ref().unwrap());
|
||||
data.style_data.per_pseudo
|
||||
data.style.as_ref().unwrap());
|
||||
data.per_pseudo
|
||||
.insert(style_pseudo.clone(), new_style.unwrap());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
self.get_style_data().unwrap().borrow()
|
||||
.style_data.per_pseudo.get(&style_pseudo)
|
||||
.per_pseudo.get(&style_pseudo)
|
||||
.unwrap().clone()
|
||||
}
|
||||
}
|
||||
|
@ -307,18 +303,18 @@ pub trait ThreadSafeLayoutNode: Clone + Copy + NodeInfo + PartialEq + Sized {
|
|||
let data = self.get_style_data().unwrap().borrow();
|
||||
match self.get_pseudo_element_type() {
|
||||
PseudoElementType::Normal
|
||||
=> data.style_data.style.as_ref().unwrap().clone(),
|
||||
=> data.style.as_ref().unwrap().clone(),
|
||||
other
|
||||
=> data.style_data.per_pseudo.get(&other.style_pseudo_element()).unwrap().clone(),
|
||||
=> data.per_pseudo.get(&other.style_pseudo_element()).unwrap().clone(),
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn selected_style(&self, _context: &SharedStyleContext) -> Arc<ServoComputedValues> {
|
||||
let data = self.get_style_data().unwrap().borrow();
|
||||
data.style_data.per_pseudo
|
||||
data.per_pseudo
|
||||
.get(&PseudoElement::Selection)
|
||||
.unwrap_or(data.style_data.style.as_ref().unwrap()).clone()
|
||||
.unwrap_or(data.style.as_ref().unwrap()).clone()
|
||||
}
|
||||
|
||||
/// Removes the style from this node.
|
||||
|
@ -329,10 +325,10 @@ pub trait ThreadSafeLayoutNode: Clone + Copy + NodeInfo + PartialEq + Sized {
|
|||
|
||||
match self.get_pseudo_element_type() {
|
||||
PseudoElementType::Normal => {
|
||||
data.style_data.style = None;
|
||||
data.style = None;
|
||||
}
|
||||
other => {
|
||||
data.style_data.per_pseudo.remove(&other.style_pseudo_element());
|
||||
data.per_pseudo.remove(&other.style_pseudo_element());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -387,7 +383,7 @@ pub trait ThreadSafeLayoutNode: Clone + Copy + NodeInfo + PartialEq + Sized {
|
|||
LayerId::new_of_type(LayerType::OverflowScroll, self.opaque().id() as usize)
|
||||
}
|
||||
|
||||
fn get_style_data(&self) -> Option<&RefCell<PartialStyleAndLayoutData>>;
|
||||
fn get_style_data(&self) -> Option<&AtomicRefCell<PersistentStyleData>>;
|
||||
}
|
||||
|
||||
// This trait is only public so that it can be implemented by the gecko wrapper.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue