Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement attribute restyle hints #8381

Merged
merged 7 commits into from Nov 10, 2015

Add ::from_layout_js factory to LayoutNode, LayoutElement, and Layout…

…Document.
  • Loading branch information
bholley committed Nov 10, 2015
commit b29369296c4ffb3e40326121923d6ac5f6396a45
@@ -91,14 +91,17 @@ impl<'a> PartialEq for LayoutNode<'a> {
}

impl<'ln> LayoutNode<'ln> {
pub unsafe fn new(address: &TrustedNodeAddress) -> LayoutNode {
let node = LayoutJS::from_trusted_node_address(*address);
pub fn from_layout_js(n: LayoutJS<Node>) -> LayoutNode<'ln> {
LayoutNode {
node: node,
node: n,
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.
pub unsafe fn new_with_this_lifetime(&self, node: &LayoutJS<Node>) -> LayoutNode<'ln> {
LayoutNode {
@@ -215,12 +218,7 @@ impl<'ln> LayoutNode<'ln> {
}

pub fn as_document(&self) -> Option<LayoutDocument<'ln>> {
self.node.downcast().map(|document| {
LayoutDocument {
document: document,
chain: PhantomData,
}
})
self.node.downcast().map(|document| LayoutDocument::from_layout_js(document))
}

fn parent_node(&self) -> Option<LayoutNode<'ln>> {
@@ -363,24 +361,24 @@ pub struct LayoutDocument<'le> {
}

impl<'le> LayoutDocument<'le> {
pub fn as_node(&self) -> LayoutNode<'le> {
LayoutNode {
node: self.document.upcast(),
pub fn from_layout_js(doc: LayoutJS<Document>) -> LayoutDocument<'le> {
LayoutDocument {
document: doc,
chain: PhantomData,
}
}

pub fn as_node(&self) -> LayoutNode<'le> {
LayoutNode::from_layout_js(self.document.upcast())
}

pub fn root_node(&self) -> Option<LayoutNode<'le>> {
self.as_node().children().find(LayoutNode::is_element)
}

pub fn drain_modified_elements(&self) -> Vec<(LayoutElement, ElementSnapshot)> {
let elements = unsafe { self.document.drain_modified_elements() };
elements.into_iter().map(|(el, snapshot)|
(LayoutElement {
element: el,
chain: PhantomData,
}, snapshot)).collect()
elements.into_iter().map(|(el, snapshot)| (LayoutElement::from_layout_js(el), snapshot)).collect()
}
}

@@ -392,17 +390,21 @@ pub struct 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> {
unsafe {
&*self.element.style_attribute()
}
}

pub fn as_node(&self) -> LayoutNode<'le> {
LayoutNode {
node: self.element.upcast(),
chain: PhantomData,
}
LayoutNode::from_layout_js(self.element.upcast())
}

pub fn get_state(&self) -> ElementState {
@@ -466,12 +468,7 @@ impl<'le> LayoutElement<'le> {
}

fn as_element<'le>(node: LayoutJS<Node>) -> Option<LayoutElement<'le>> {
node.downcast().map(|element| {
LayoutElement {
element: element,
chain: PhantomData,
}
})
node.downcast().map(|element| LayoutElement::from_layout_js(element))
}

macro_rules! state_getter {
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.