From 0275654c4a11c424dc5c763ca8cefee6631d4216 Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Fri, 11 Apr 2014 17:26:27 +0100 Subject: [PATCH 1/5] Use #[deriving(Clone)] for ThreadSafeLayoutNode --- src/components/main/layout/wrapper.rs | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/components/main/layout/wrapper.rs b/src/components/main/layout/wrapper.rs index b1160b46847..6687c9c0e48 100644 --- a/src/components/main/layout/wrapper.rs +++ b/src/components/main/layout/wrapper.rs @@ -406,6 +406,7 @@ pub enum ElementType { /// A thread-safe version of `LayoutNode`, used during flow construction. This type of layout /// node does not allow any parents or siblings of nodes to be accessed, to avoid races. +#[deriving(Clone)] pub struct ThreadSafeLayoutNode<'ln> { /// The wrapped node. priv node: LayoutNode<'ln>, @@ -486,14 +487,6 @@ impl<'ln> TLayoutNode for ThreadSafeLayoutNode<'ln> { } } -impl<'ln> Clone for ThreadSafeLayoutNode<'ln> { - fn clone(&self) -> ThreadSafeLayoutNode<'ln> { - ThreadSafeLayoutNode { - node: self.node.clone(), - pseudo: self.pseudo, - } - } -} impl<'ln> ThreadSafeLayoutNode<'ln> { /// Creates a new `ThreadSafeLayoutNode` from the given `LayoutNode`. @@ -533,7 +526,7 @@ impl<'ln> ThreadSafeLayoutNode<'ln> { pub fn children(&self) -> ThreadSafeLayoutNodeChildrenIterator<'ln> { ThreadSafeLayoutNodeChildrenIterator { current_node: self.first_child(), - parent_node: Some(ThreadSafeLayoutNode::new_with_pseudo_without_self(&self.node, self.pseudo)), + parent_node: Some(self.clone()), } } From 49521baee7507dc0e5a85a626e98c2373e6e9d7a Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Fri, 11 Apr 2014 17:33:33 +0100 Subject: [PATCH 2/5] Rename ElementType to PseudoElementType, to avoid confusion with ElementTypeId. --- src/components/main/css/node_util.rs | 2 +- src/components/main/layout/construct.rs | 6 +++--- src/components/main/layout/wrapper.rs | 16 ++++++++-------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/components/main/css/node_util.rs b/src/components/main/css/node_util.rs index f449a99ac44..5c88632eb55 100644 --- a/src/components/main/css/node_util.rs +++ b/src/components/main/css/node_util.rs @@ -25,7 +25,7 @@ impl<'ln> NodeUtil for ThreadSafeLayoutNode<'ln> { fn get_css_select_results<'a>(&'a self) -> &'a Arc { unsafe { let layout_data_ref = self.borrow_layout_data(); - match self.get_element_type() { + match self.get_pseudo_element_type() { Before | BeforeBlock => { cast::transmute_region(layout_data_ref.as_ref() .unwrap() diff --git a/src/components/main/layout/construct.rs b/src/components/main/layout/construct.rs index bf5ed0673d0..e3be9167d39 100644 --- a/src/components/main/layout/construct.rs +++ b/src/components/main/layout/construct.rs @@ -487,7 +487,7 @@ impl<'a> FlowConstructor<'a> { // List of absolute descendants, in tree order. let mut abs_descendants = Descendants::new(); for kid in node.children() { - if kid.get_element_type() != Normal { + if kid.get_pseudo_element_type() != Normal { self.process(&kid); } @@ -1127,7 +1127,7 @@ impl<'ln> NodeUtils for ThreadSafeLayoutNode<'ln> { let mut layout_data_ref = self.mutate_layout_data(); match &mut *layout_data_ref { &Some(ref mut layout_data) =>{ - match self.get_element_type() { + match self.get_pseudo_element_type() { Before | BeforeBlock => { layout_data.data.before_flow_construction_result = result }, @@ -1146,7 +1146,7 @@ impl<'ln> NodeUtils for ThreadSafeLayoutNode<'ln> { let mut layout_data_ref = self.mutate_layout_data(); match &mut *layout_data_ref { &Some(ref mut layout_data) => { - match self.get_element_type() { + match self.get_pseudo_element_type() { Before | BeforeBlock => { mem::replace(&mut layout_data.data.before_flow_construction_result, NoConstructionResult) diff --git a/src/components/main/layout/wrapper.rs b/src/components/main/layout/wrapper.rs index 6687c9c0e48..85ada5e486e 100644 --- a/src/components/main/layout/wrapper.rs +++ b/src/components/main/layout/wrapper.rs @@ -396,7 +396,7 @@ fn get_content(content_list: &content::T) -> ~str { } #[deriving(Eq, Clone)] -pub enum ElementType { +pub enum PseudoElementType { Normal, Before, After, @@ -411,7 +411,7 @@ pub struct ThreadSafeLayoutNode<'ln> { /// The wrapped node. priv node: LayoutNode<'ln>, - priv pseudo: ElementType, + priv pseudo: PseudoElementType, } impl<'ln> TLayoutNode for ThreadSafeLayoutNode<'ln> { @@ -497,19 +497,19 @@ impl<'ln> ThreadSafeLayoutNode<'ln> { } } - pub fn new_with_pseudo_without_self<'a>(node: &LayoutNode<'a>, element_type: ElementType) -> ThreadSafeLayoutNode<'a> { + pub fn new_with_pseudo_without_self<'a>(node: &LayoutNode<'a>, pseudo: PseudoElementType) -> ThreadSafeLayoutNode<'a> { ThreadSafeLayoutNode { node: node.clone(), - pseudo: element_type, + pseudo: pseudo, } } /// Creates a new `ThreadSafeLayoutNode` from the given `LayoutNode`. - pub fn new_with_pseudo<'a>(&'a self, element_type: ElementType) -> ThreadSafeLayoutNode<'a> { + pub fn new_with_pseudo<'a>(&'a self, pseudo: PseudoElementType) -> ThreadSafeLayoutNode<'a> { ThreadSafeLayoutNode { node: self.node.clone(), - pseudo: element_type, + pseudo: pseudo, } } @@ -544,11 +544,11 @@ impl<'ln> ThreadSafeLayoutNode<'ln> { } } - pub fn get_element_type(&self) -> ElementType { + pub fn get_pseudo_element_type(&self) -> PseudoElementType { self.pseudo } - pub fn is_block(&self, kind: ElementType) -> bool { + pub fn is_block(&self, kind: PseudoElementType) -> bool { let mut layout_data_ref = self.mutate_layout_data(); let node_layout_data_wrapper = layout_data_ref.get_mut_ref(); From 7f139b2b0700973d4e4a2e7c1a99652e90414555 Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Fri, 11 Apr 2014 19:18:19 +0100 Subject: [PATCH 3/5] Merge new_with_pseudo_without_self() and new_with_pseudo() into with_pseudo() --- src/components/main/layout/wrapper.rs | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/src/components/main/layout/wrapper.rs b/src/components/main/layout/wrapper.rs index 85ada5e486e..b4b385d54f5 100644 --- a/src/components/main/layout/wrapper.rs +++ b/src/components/main/layout/wrapper.rs @@ -450,10 +450,10 @@ impl<'ln> TLayoutNode for ThreadSafeLayoutNode<'ln> { if self.has_before_pseudo() { if self.is_block(Before) && self.pseudo == Normal { - let pseudo_before_node = ThreadSafeLayoutNode::new_with_pseudo_without_self(&self.node, BeforeBlock); + let pseudo_before_node = self.with_pseudo(BeforeBlock); return Some(pseudo_before_node) } else if self.pseudo == Normal || self.pseudo == BeforeBlock { - let pseudo_before_node = ThreadSafeLayoutNode::new_with_pseudo_without_self(&self.node, Before); + let pseudo_before_node = self.with_pseudo(Before); return Some(pseudo_before_node) } } @@ -497,16 +497,9 @@ impl<'ln> ThreadSafeLayoutNode<'ln> { } } - pub fn new_with_pseudo_without_self<'a>(node: &LayoutNode<'a>, pseudo: PseudoElementType) -> ThreadSafeLayoutNode<'a> { - ThreadSafeLayoutNode { - node: node.clone(), - pseudo: pseudo, - } - } - - - /// Creates a new `ThreadSafeLayoutNode` from the given `LayoutNode`. - pub fn new_with_pseudo<'a>(&'a self, pseudo: PseudoElementType) -> ThreadSafeLayoutNode<'a> { + /// Creates a new `ThreadSafeLayoutNode` for the same `LayoutNode` + /// with a differet pseudo-element type. + pub fn with_pseudo(&self, pseudo: PseudoElementType) -> ThreadSafeLayoutNode<'ln> { ThreadSafeLayoutNode { node: self.node.clone(), pseudo: pseudo, @@ -661,10 +654,10 @@ impl<'a> Iterator> for ThreadSafeLayoutNodeChildrenIter Some(ref parent_node) => { if parent_node.has_after_pseudo() { let pseudo_after_node = if parent_node.is_block(After) && parent_node.pseudo == Normal { - let pseudo_after_node = ThreadSafeLayoutNode::new_with_pseudo_without_self(&parent_node.node, AfterBlock); + let pseudo_after_node = parent_node.with_pseudo(AfterBlock); Some(pseudo_after_node) } else if parent_node.pseudo == Normal || parent_node.pseudo == AfterBlock { - let pseudo_after_node = ThreadSafeLayoutNode::new_with_pseudo_without_self(&parent_node.node, After); + let pseudo_after_node = parent_node.with_pseudo(After); Some(pseudo_after_node) } else { None From d9c6ac5ca1e1da871de0546a6091b3b6fcf7351a Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Fri, 11 Apr 2014 21:26:16 +0100 Subject: [PATCH 4/5] fixup! Merge new_with_pseudo_without_self() and new_with_pseudo() into with_pseudo() --- src/components/main/layout/wrapper.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/main/layout/wrapper.rs b/src/components/main/layout/wrapper.rs index b4b385d54f5..b0b8c82c252 100644 --- a/src/components/main/layout/wrapper.rs +++ b/src/components/main/layout/wrapper.rs @@ -498,7 +498,7 @@ impl<'ln> ThreadSafeLayoutNode<'ln> { } /// Creates a new `ThreadSafeLayoutNode` for the same `LayoutNode` - /// with a differet pseudo-element type. + /// with a different pseudo-element type. pub fn with_pseudo(&self, pseudo: PseudoElementType) -> ThreadSafeLayoutNode<'ln> { ThreadSafeLayoutNode { node: self.node.clone(), From 583892bf6989250b2b50066eee28bf7c7c131d94 Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Mon, 14 Apr 2014 15:22:23 +0100 Subject: [PATCH 5/5] fixup! Rename ElementType to PseudoElementType, to avoid confusion with ElementTypeId. --- src/components/main/layout/construct.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/main/layout/construct.rs b/src/components/main/layout/construct.rs index e3be9167d39..b0451c363a7 100644 --- a/src/components/main/layout/construct.rs +++ b/src/components/main/layout/construct.rs @@ -558,7 +558,7 @@ impl<'a> FlowConstructor<'a> { // Concatenate all the boxes of our kids, creating {ib} splits as necessary. for kid in node.children() { - if kid.get_element_type() != Normal { + if kid.get_pseudo_element_type() != Normal { self.process(&kid); } match kid.swap_out_construction_result() {