mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
Add ::from_layout_js factory to LayoutNode, LayoutElement, and LayoutDocument.
This commit is contained in:
parent
7fa7936657
commit
b29369296c
1 changed files with 24 additions and 27 deletions
|
@ -91,14 +91,17 @@ impl<'a> PartialEq for LayoutNode<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'ln> LayoutNode<'ln> {
|
impl<'ln> LayoutNode<'ln> {
|
||||||
pub unsafe fn new(address: &TrustedNodeAddress) -> LayoutNode {
|
pub fn from_layout_js(n: LayoutJS<Node>) -> LayoutNode<'ln> {
|
||||||
let node = LayoutJS::from_trusted_node_address(*address);
|
|
||||||
LayoutNode {
|
LayoutNode {
|
||||||
node: node,
|
node: n,
|
||||||
chain: PhantomData,
|
chain: PhantomData,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub unsafe fn new(address: &TrustedNodeAddress) -> LayoutNode {
|
||||||
|
LayoutNode::from_layout_js(LayoutJS::from_trusted_node_address(*address))
|
||||||
|
}
|
||||||
|
|
||||||
/// Creates a new layout node with the same lifetime as this layout node.
|
/// Creates a new layout node with the same lifetime as this layout node.
|
||||||
pub unsafe fn new_with_this_lifetime(&self, node: &LayoutJS<Node>) -> LayoutNode<'ln> {
|
pub unsafe fn new_with_this_lifetime(&self, node: &LayoutJS<Node>) -> LayoutNode<'ln> {
|
||||||
LayoutNode {
|
LayoutNode {
|
||||||
|
@ -215,12 +218,7 @@ impl<'ln> LayoutNode<'ln> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn as_document(&self) -> Option<LayoutDocument<'ln>> {
|
pub fn as_document(&self) -> Option<LayoutDocument<'ln>> {
|
||||||
self.node.downcast().map(|document| {
|
self.node.downcast().map(|document| LayoutDocument::from_layout_js(document))
|
||||||
LayoutDocument {
|
|
||||||
document: document,
|
|
||||||
chain: PhantomData,
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parent_node(&self) -> Option<LayoutNode<'ln>> {
|
fn parent_node(&self) -> Option<LayoutNode<'ln>> {
|
||||||
|
@ -363,24 +361,24 @@ pub struct LayoutDocument<'le> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'le> LayoutDocument<'le> {
|
impl<'le> LayoutDocument<'le> {
|
||||||
pub fn as_node(&self) -> LayoutNode<'le> {
|
pub fn from_layout_js(doc: LayoutJS<Document>) -> LayoutDocument<'le> {
|
||||||
LayoutNode {
|
LayoutDocument {
|
||||||
node: self.document.upcast(),
|
document: doc,
|
||||||
chain: PhantomData,
|
chain: PhantomData,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn as_node(&self) -> LayoutNode<'le> {
|
||||||
|
LayoutNode::from_layout_js(self.document.upcast())
|
||||||
|
}
|
||||||
|
|
||||||
pub fn root_node(&self) -> Option<LayoutNode<'le>> {
|
pub fn root_node(&self) -> Option<LayoutNode<'le>> {
|
||||||
self.as_node().children().find(LayoutNode::is_element)
|
self.as_node().children().find(LayoutNode::is_element)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn drain_modified_elements(&self) -> Vec<(LayoutElement, ElementSnapshot)> {
|
pub fn drain_modified_elements(&self) -> Vec<(LayoutElement, ElementSnapshot)> {
|
||||||
let elements = unsafe { self.document.drain_modified_elements() };
|
let elements = unsafe { self.document.drain_modified_elements() };
|
||||||
elements.into_iter().map(|(el, snapshot)|
|
elements.into_iter().map(|(el, snapshot)| (LayoutElement::from_layout_js(el), snapshot)).collect()
|
||||||
(LayoutElement {
|
|
||||||
element: el,
|
|
||||||
chain: PhantomData,
|
|
||||||
}, snapshot)).collect()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -392,6 +390,13 @@ pub struct LayoutElement<'le> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'le> LayoutElement<'le> {
|
impl<'le> LayoutElement<'le> {
|
||||||
|
pub fn from_layout_js(el: LayoutJS<Element>) -> LayoutElement<'le> {
|
||||||
|
LayoutElement {
|
||||||
|
element: el,
|
||||||
|
chain: PhantomData,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn style_attribute(&self) -> &'le Option<PropertyDeclarationBlock> {
|
pub fn style_attribute(&self) -> &'le Option<PropertyDeclarationBlock> {
|
||||||
unsafe {
|
unsafe {
|
||||||
&*self.element.style_attribute()
|
&*self.element.style_attribute()
|
||||||
|
@ -399,10 +404,7 @@ impl<'le> LayoutElement<'le> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn as_node(&self) -> LayoutNode<'le> {
|
pub fn as_node(&self) -> LayoutNode<'le> {
|
||||||
LayoutNode {
|
LayoutNode::from_layout_js(self.element.upcast())
|
||||||
node: self.element.upcast(),
|
|
||||||
chain: PhantomData,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_state(&self) -> ElementState {
|
pub fn get_state(&self) -> ElementState {
|
||||||
|
@ -466,12 +468,7 @@ impl<'le> LayoutElement<'le> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn as_element<'le>(node: LayoutJS<Node>) -> Option<LayoutElement<'le>> {
|
fn as_element<'le>(node: LayoutJS<Node>) -> Option<LayoutElement<'le>> {
|
||||||
node.downcast().map(|element| {
|
node.downcast().map(|element| LayoutElement::from_layout_js(element))
|
||||||
LayoutElement {
|
|
||||||
element: element,
|
|
||||||
chain: PhantomData,
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! state_getter {
|
macro_rules! state_getter {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue