Privatize Node

This commit is contained in:
Tim Taubert 2014-10-13 00:32:48 +02:00
parent da7590d108
commit 28061b1c91
3 changed files with 23 additions and 7 deletions

View file

@ -78,20 +78,20 @@ pub trait LayoutDataAccess {
impl<'ln> LayoutDataAccess for LayoutNode<'ln> { impl<'ln> LayoutDataAccess for LayoutNode<'ln> {
#[inline(always)] #[inline(always)]
unsafe fn borrow_layout_data_unchecked(&self) -> *const Option<LayoutDataWrapper> { unsafe fn borrow_layout_data_unchecked(&self) -> *const Option<LayoutDataWrapper> {
mem::transmute(self.get().layout_data.borrow_unchecked()) mem::transmute(self.get().layout_data_unchecked())
} }
#[inline(always)] #[inline(always)]
fn borrow_layout_data<'a>(&'a self) -> Ref<'a,Option<LayoutDataWrapper>> { fn borrow_layout_data<'a>(&'a self) -> Ref<'a,Option<LayoutDataWrapper>> {
unsafe { unsafe {
mem::transmute(self.get().layout_data.borrow()) mem::transmute(self.get().layout_data())
} }
} }
#[inline(always)] #[inline(always)]
fn mutate_layout_data<'a>(&'a self) -> RefMut<'a,Option<LayoutDataWrapper>> { fn mutate_layout_data<'a>(&'a self) -> RefMut<'a,Option<LayoutDataWrapper>> {
unsafe { unsafe {
mem::transmute(self.get().layout_data.borrow_mut()) mem::transmute(self.get().layout_data_mut())
} }
} }
} }

View file

@ -721,7 +721,7 @@ impl<'ln> ThreadSafeLayoutNode<'ln> {
#[inline(always)] #[inline(always)]
pub fn borrow_layout_data<'a>(&'a self) -> Ref<'a,Option<LayoutDataWrapper>> { pub fn borrow_layout_data<'a>(&'a self) -> Ref<'a,Option<LayoutDataWrapper>> {
unsafe { unsafe {
mem::transmute(self.get().layout_data.borrow()) mem::transmute(self.get().layout_data())
} }
} }
@ -729,7 +729,7 @@ impl<'ln> ThreadSafeLayoutNode<'ln> {
#[inline(always)] #[inline(always)]
pub fn mutate_layout_data<'a>(&'a self) -> RefMut<'a,Option<LayoutDataWrapper>> { pub fn mutate_layout_data<'a>(&'a self) -> RefMut<'a,Option<LayoutDataWrapper>> {
unsafe { unsafe {
mem::transmute(self.get().layout_data.borrow_mut()) mem::transmute(self.get().layout_data_mut())
} }
} }

View file

@ -73,9 +73,10 @@ use uuid;
/// An HTML node. /// An HTML node.
#[jstraceable] #[jstraceable]
#[must_root] #[must_root]
#[privatize]
pub struct Node { pub struct Node {
/// The JavaScript reflector for this node. /// The JavaScript reflector for this node.
pub eventtarget: EventTarget, eventtarget: EventTarget,
/// The type of node that this is. /// The type of node that this is.
type_id: NodeTypeId, type_id: NodeTypeId,
@ -108,7 +109,7 @@ pub struct Node {
/// ///
/// Must be sent back to the layout task to be destroyed when this /// Must be sent back to the layout task to be destroyed when this
/// node is finalized. /// node is finalized.
pub layout_data: LayoutDataRef, layout_data: LayoutDataRef,
unique_id: RefCell<String>, unique_id: RefCell<String>,
} }
@ -1149,6 +1150,21 @@ impl Node {
&self.eventtarget &self.eventtarget
} }
#[inline]
pub fn layout_data(&self) -> Ref<Option<LayoutData>> {
self.layout_data.borrow()
}
#[inline]
pub fn layout_data_mut(&self) -> RefMut<Option<LayoutData>> {
self.layout_data.borrow_mut()
}
#[inline]
pub unsafe fn layout_data_unchecked(&self) -> *const Option<LayoutData> {
self.layout_data.borrow_unchecked()
}
// http://dom.spec.whatwg.org/#concept-node-adopt // http://dom.spec.whatwg.org/#concept-node-adopt
pub fn adopt(node: JSRef<Node>, document: JSRef<Document>) { pub fn adopt(node: JSRef<Node>, document: JSRef<Document>) {
// Step 1. // Step 1.