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

Pseudo element build flow and box #1496

Closed

Change after and before parent, child node to struct

  • Loading branch information
sammykim committed Feb 10, 2014
commit 21f58a23263a00912864e9de5f498e5280e04365
@@ -31,7 +31,7 @@ use layout::flow::{Flow, FlowLeafSet, ImmutableFlowUtils, MutableOwnedFlowUtils}
use layout::inline::InlineFlow;
use layout::text::TextRunScanner;
use layout::util::{LayoutDataAccess, OpaqueNode};
use layout::util::PrivateLayoutData;
use layout::util::{PrivateLayoutData, PseudoNode};
use layout::wrapper::{PostorderNodeMutTraversal, TLayoutNode, ThreadSafeLayoutNode};
use layout::wrapper::LayoutPseudoNode;
use layout::extra::LayoutAuxMethods;
@@ -683,11 +683,15 @@ impl<'fc> FlowConstructor<'fc> {

// Store pseudo_parent_node & pseudo_node in node
if pseudo_element == Before {
pseudo_child_ldw.data.before_parent_node = Some(LayoutPseudoNode::from_layout_pseudo(pseudo_parent_abstract_node, pseudo_parent_display));
pseudo_child_ldw.data.before_node = Some(LayoutPseudoNode::from_layout_pseudo(pseudo_abstract_node, display::none));
let parent = LayoutPseudoNode::from_layout_pseudo(pseudo_parent_abstract_node, pseudo_parent_display);
let element = LayoutPseudoNode::from_layout_pseudo(pseudo_abstract_node, display::none);

pseudo_child_ldw.data.before = Some(PseudoNode{parent: parent, element: element});
} else if pseudo_element == After {
pseudo_child_ldw.data.after_parent_node = Some(LayoutPseudoNode::from_layout_pseudo(pseudo_parent_abstract_node, pseudo_parent_display));
pseudo_child_ldw.data.after_node = Some(LayoutPseudoNode::from_layout_pseudo(pseudo_abstract_node, display::none));
let parent = LayoutPseudoNode::from_layout_pseudo(pseudo_parent_abstract_node, pseudo_parent_display);
let element = LayoutPseudoNode::from_layout_pseudo(pseudo_abstract_node, display::none);

pseudo_child_ldw.data.after = Some(PseudoNode{parent: parent, element: element});
}

// Set relation between pseudo_node and pseudo_parent_node
@@ -20,6 +20,7 @@ use std::iter::Enumerate;
use std::libc::uintptr_t;
use std::vec::VecIterator;
use style::{ComputedValues, PropertyDeclaration};
use style::{PseudoElement, Before, After};

/// A range of nodes.
pub struct NodeRange {
@@ -129,6 +130,12 @@ impl ElementMapping {
}
}

#[deriving(Clone)]
pub struct PseudoNode {
parent: LayoutPseudoNode,
element: LayoutPseudoNode
}

/// Data that layout associates with a node.
pub struct PrivateLayoutData {
/// The results of CSS matching for this node.
@@ -145,13 +152,9 @@ pub struct PrivateLayoutData {

after_style: Option<Arc<ComputedValues>>,

before_parent_node: Option<LayoutPseudoNode>,

before_node: Option<LayoutPseudoNode>,

after_parent_node: Option<LayoutPseudoNode>,
before: Option<PseudoNode>,

after_node: Option<LayoutPseudoNode>,
after: Option<PseudoNode>,

/// Description of how to account for recent style changes.
restyle_damage: Option<int>,
@@ -174,10 +177,8 @@ impl PrivateLayoutData {
before_style: None,
style: None,
after_style: None,
before_parent_node: None,
before_node: None,
after_parent_node: None,
after_node: None,
before: None,
after: None,
restyle_damage: None,
flow_construction_result: NoConstructionResult,
parallel: DomParallelInfo::new(),
@@ -192,10 +193,8 @@ impl PrivateLayoutData {
before_style: None,
style: style,
after_style: None,
before_parent_node: None,
before_node: None,
after_parent_node: None,
after_node: None,
before: None,
after: None,
restyle_damage: None,
flow_construction_result: NoConstructionResult,
parallel: DomParallelInfo::new(),
@@ -209,6 +208,14 @@ impl PrivateLayoutData {
self.before_applicable_declarations = SmallVec0::new();
self.after_applicable_declarations = SmallVec0::new();
}

pub fn get_pseudo_element(&self, pseudo_element: PseudoElement) -> Option<PseudoNode> {
if pseudo_element == Before {

This comment has been minimized.

@jdm

jdm Feb 6, 2014

Member

Use a match here, perhaps?

self.before.clone()
} else {
self.after.clone()
}
}
}

pub struct LayoutDataWrapper {
@@ -188,7 +188,46 @@ impl<'ln> TLayoutNode for LayoutNode<'ln> {
self.node
}

fn get_pseudo_node(&self, pseudo_element: PseudoElement) -> Option<LayoutNode<'ln>> {
fn get_pseudo_node(&self, pseudo_type: PseudoElement) -> Option<LayoutNode<'ln>> {
if unsafe { self.get_abstract().is_text() } {
let layout_data_ref = self.borrow_layout_data();
return layout_data_ref.get().as_ref().and_then(|ldw|{
let pseudo_element = ldw.data.get_pseudo_element(pseudo_type);
pseudo_element.and_then(|pseudo_node|{
if pseudo_node.parent.get_display() == display::inline {
unsafe{

This comment has been minimized.

@jdm

jdm Feb 6, 2014

Member

Still space before {. Please search for this through the changes and fix all instances.

Some(self.new_with_this_lifetime(pseudo_node.element.node))
}
} else {
None
}
})
});
} else if self.is_element() {
match self.first_child() {
Some(first_child) => {
let layout_data_ref = first_child.borrow_layout_data();
return layout_data_ref.get().as_ref().and_then(|ldw|{
let pseudo_element = ldw.data.get_pseudo_element(pseudo_type);
pseudo_element.and_then(|pseudo_node|{
if pseudo_node.parent.get_display() == display::block {
unsafe{

This comment has been minimized.

@jdm

jdm Feb 6, 2014

Member

Unindent.

Some(self.new_with_this_lifetime(pseudo_node.parent.node))
}
} else {
None
}
})
});
}
None => {
return None
}
}
} else {
return None

This comment has been minimized.

@jdm

jdm Feb 6, 2014

Member

This will cause the return value of the map call to be ignored. Are there tests that would have caught this?

}
/*
macro_rules! get_pseudo_node(
($pseudo_parent_node: ident, $pseudo_node: ident) => {
if unsafe { self.get_abstract().is_text() } {
@@ -240,6 +279,7 @@ impl<'ln> TLayoutNode for LayoutNode<'ln> {
} else {
return None
}
*/
}
}

@@ -523,7 +563,48 @@ impl<'ln> TLayoutNode for ThreadSafeLayoutNode<'ln> {
self.node
}

fn get_pseudo_node(&self, pseudo_element: PseudoElement) -> Option<ThreadSafeLayoutNode<'ln>> {
fn get_pseudo_node(&self, pseudo_type: PseudoElement) -> Option<ThreadSafeLayoutNode<'ln>> {

if unsafe { self.get_abstract().is_text() } {
let layout_data_ref = self.borrow_layout_data();
return layout_data_ref.get().as_ref().and_then(|ldw|{
let pseudo_element = ldw.data.get_pseudo_element(pseudo_type);
pseudo_element.and_then(|pseudo_node|{
if pseudo_node.parent.get_display() == display::inline {
unsafe{
Some(self.new_with_this_lifetime(pseudo_node.element.node))
}
} else {
None
}
})
});
} else if unsafe { self.get_abstract().is_element() } {
match self.first_child() {
Some(first_child) => {
let layout_data_ref = first_child.borrow_layout_data();
return layout_data_ref.get().as_ref().and_then(|ldw|{
let pseudo_element = ldw.data.get_pseudo_element(pseudo_type);
pseudo_element.and_then(|pseudo_node|{
if pseudo_node.parent.get_display() == display::block {
unsafe{
Some(self.new_with_this_lifetime(pseudo_node.parent.node))
}
} else {
None
}
})
});
}
None => {
return None
}
}
} else {
return None
}

/*
macro_rules! get_pseudo_node(
($pseudo_parent_node: ident, $pseudo_node: ident) => {
if unsafe { self.get_abstract().is_text() } {
@@ -574,7 +655,7 @@ impl<'ln> TLayoutNode for ThreadSafeLayoutNode<'ln> {
return get_pseudo_node!(after_parent_node, after_node)
} else {
return None
}
}*/
}
}

@@ -710,10 +791,10 @@ impl<'ln> ThreadSafeLayoutNode<'ln> {
let p_ldw = p.borrow_layout_data();
let p_ldw_ref = p_ldw.get().get_ref();

if p_ldw_ref.data.before_style.is_some() && ldw_ref.data.before_node.is_none() {
if p_ldw_ref.data.before_style.is_some() && ldw_ref.data.before.is_none() {
pseudo_elements.push(Before);
}
if p_ldw_ref.data.after_style.is_some() && ldw_ref.data.after_node.is_none() {
if p_ldw_ref.data.after_style.is_some() && ldw_ref.data.after.is_none() {
pseudo_elements.push(After);
}

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