mirror of
https://github.com/servo/servo.git
synced 2025-07-23 15:23:42 +01:00
Implement the LayoutData getters on LayoutJS<Node> rather than Node itself.
This commit is contained in:
parent
a217ffb00a
commit
eb2c508df0
3 changed files with 33 additions and 28 deletions
|
@ -8,7 +8,7 @@ use construct::{ConstructionItem, ConstructionResult};
|
|||
use incremental::RestyleDamage;
|
||||
use msg::constellation_msg::ConstellationChan;
|
||||
use parallel::DomParallelInfo;
|
||||
use script::dom::node::SharedLayoutData;
|
||||
use script::dom::node::{LayoutNodeHelpers, SharedLayoutData};
|
||||
use script::layout_interface::LayoutChan;
|
||||
use std::cell::{Ref, RefMut};
|
||||
use std::mem;
|
||||
|
@ -116,20 +116,20 @@ pub trait LayoutDataAccess {
|
|||
impl<'ln> LayoutDataAccess for LayoutNode<'ln> {
|
||||
#[inline(always)]
|
||||
unsafe fn borrow_layout_data_unchecked(&self) -> *const Option<LayoutDataWrapper> {
|
||||
mem::transmute(self.get().layout_data_unchecked())
|
||||
mem::transmute(self.get_jsmanaged().layout_data_unchecked())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn borrow_layout_data<'a>(&'a self) -> Ref<'a,Option<LayoutDataWrapper>> {
|
||||
unsafe {
|
||||
mem::transmute(self.get().layout_data())
|
||||
mem::transmute(self.get_jsmanaged().layout_data())
|
||||
}
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn mutate_layout_data<'a>(&'a self) -> RefMut<'a,Option<LayoutDataWrapper>> {
|
||||
unsafe {
|
||||
mem::transmute(self.get().layout_data_mut())
|
||||
mem::transmute(self.get_jsmanaged().layout_data_mut())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -889,11 +889,11 @@ impl<'ln> ThreadSafeLayoutNode<'ln> {
|
|||
layout_data_wrapper_ref.data.after_style.is_some()
|
||||
}
|
||||
|
||||
/// Borrows the layout data without checking. Fails on a conflicting borrow.
|
||||
/// Borrows the layout data without checking.
|
||||
#[inline(always)]
|
||||
fn borrow_layout_data_unchecked<'a>(&'a self) -> *const Option<LayoutDataWrapper> {
|
||||
unsafe {
|
||||
mem::transmute(self.get().layout_data_unchecked())
|
||||
self.node.borrow_layout_data_unchecked()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -902,9 +902,7 @@ impl<'ln> ThreadSafeLayoutNode<'ln> {
|
|||
/// TODO(pcwalton): Make this private. It will let us avoid borrow flag checks in some cases.
|
||||
#[inline(always)]
|
||||
pub fn borrow_layout_data<'a>(&'a self) -> Ref<'a,Option<LayoutDataWrapper>> {
|
||||
unsafe {
|
||||
mem::transmute(self.get().layout_data())
|
||||
}
|
||||
self.node.borrow_layout_data()
|
||||
}
|
||||
|
||||
/// Borrows the layout data mutably. Fails on a conflicting borrow.
|
||||
|
@ -912,9 +910,7 @@ impl<'ln> ThreadSafeLayoutNode<'ln> {
|
|||
/// TODO(pcwalton): Make this private. It will let us avoid borrow flag checks in some cases.
|
||||
#[inline(always)]
|
||||
pub fn mutate_layout_data<'a>(&'a self) -> RefMut<'a,Option<LayoutDataWrapper>> {
|
||||
unsafe {
|
||||
mem::transmute(self.get().layout_data_mut())
|
||||
}
|
||||
self.node.mutate_layout_data()
|
||||
}
|
||||
|
||||
/// Traverses the tree in postorder.
|
||||
|
|
|
@ -1091,6 +1091,13 @@ pub trait LayoutNodeHelpers {
|
|||
unsafe fn get_flag(&self, flag: NodeFlags) -> bool;
|
||||
#[allow(unsafe_code)]
|
||||
unsafe fn set_flag(&self, flag: NodeFlags, value: bool);
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
unsafe fn layout_data(&self) -> Ref<Option<LayoutData>>;
|
||||
#[allow(unsafe_code)]
|
||||
unsafe fn layout_data_mut(&self) -> RefMut<Option<LayoutData>>;
|
||||
#[allow(unsafe_code)]
|
||||
unsafe fn layout_data_unchecked(&self) -> *const Option<LayoutData>;
|
||||
}
|
||||
|
||||
impl LayoutNodeHelpers for LayoutJS<Node> {
|
||||
|
@ -1162,6 +1169,24 @@ impl LayoutNodeHelpers for LayoutJS<Node> {
|
|||
|
||||
(*this).flags.set(flags);
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[allow(unsafe_code)]
|
||||
unsafe fn layout_data(&self) -> Ref<Option<LayoutData>> {
|
||||
(*self.unsafe_get()).layout_data.borrow()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[allow(unsafe_code)]
|
||||
unsafe fn layout_data_mut(&self) -> RefMut<Option<LayoutData>> {
|
||||
(*self.unsafe_get()).layout_data.borrow_mut()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[allow(unsafe_code)]
|
||||
unsafe fn layout_data_unchecked(&self) -> *const Option<LayoutData> {
|
||||
(*self.unsafe_get()).layout_data.borrow_unchecked()
|
||||
}
|
||||
}
|
||||
|
||||
pub trait RawLayoutNodeHelpers {
|
||||
|
@ -1461,22 +1486,6 @@ impl Node {
|
|||
}
|
||||
}
|
||||
|
||||
#[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]
|
||||
#[allow(unsafe_code)]
|
||||
pub unsafe fn layout_data_unchecked(&self) -> *const Option<LayoutData> {
|
||||
self.layout_data.borrow_unchecked()
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#concept-node-adopt
|
||||
pub fn adopt(node: &Node, document: &Document) {
|
||||
// Step 1.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue