diff --git a/src/components/main/css/node_util.rs b/src/components/main/css/node_util.rs index 4cf8eda956f..e76d2db0607 100644 --- a/src/components/main/css/node_util.rs +++ b/src/components/main/css/node_util.rs @@ -27,10 +27,6 @@ impl<'self> NodeUtil<'self> for AbstractNode { * stored in a box that can be overwritten */ fn get_css_select_results(self) -> &'self CompleteSelectResults { - if !self.has_layout_data() { - fail!(~"style() called on a node without aux data!"); - } - do self.read_layout_data |layout_data| { match layout_data.style { None => fail!(~"style() called on node without a style!"), @@ -41,18 +37,11 @@ impl<'self> NodeUtil<'self> for AbstractNode { /// Does this node have a computed style yet? fn have_css_select_results(self) -> bool { - if !self.has_layout_data() { - return false; - } self.read_layout_data(|data| data.style.is_some()) } /// Update the computed style of an HTML element with a style specified by CSS. fn set_css_select_results(self, decl: CompleteSelectResults) { - if !self.has_layout_data() { - fail!(~"set_css_select_results() called on a node without aux data!"); - } - let cell = Cell::new(decl); self.write_layout_data(|data| data.style = Some(cell.take())); } @@ -68,9 +57,6 @@ impl<'self> NodeUtil<'self> for AbstractNode { RestyleDamage::none() }; - if !self.has_layout_data() { - return default; - } do self.read_layout_data |layout_data| { layout_data.restyle_damage .map(|&x| RestyleDamage::from_int(x)) @@ -80,10 +66,6 @@ impl<'self> NodeUtil<'self> for AbstractNode { /// Set the restyle damage field. fn set_restyle_damage(self, damage: RestyleDamage) { - if !self.has_layout_data() { - fail!(~"set_restyle_damage() called on a node without aux data!"); - } - self.write_layout_data(|data| data.restyle_damage = Some(damage.to_int())); } } diff --git a/src/components/main/layout/aux.rs b/src/components/main/layout/aux.rs index 6325c6de230..98406c802df 100644 --- a/src/components/main/layout/aux.rs +++ b/src/components/main/layout/aux.rs @@ -4,7 +4,7 @@ //! Code for managing the layout data in the DOM. -use script::dom::node::{AbstractNode, LayoutView, LayoutData}; +use script::dom::node::{AbstractNode, LayoutView}; use servo_util::tree::TreeNodeRef; /// Functionality useful for querying the layout-specific data on DOM nodes. @@ -14,21 +14,15 @@ pub trait LayoutAuxMethods { } impl LayoutAuxMethods for AbstractNode { - /// If none exists, creates empty layout data for the node (the reader-auxiliary - /// box in the COW model) and populates it with an empty style object. + /// Resets layout data and styles for the node. fn initialize_layout_data(self) { - if self.has_layout_data() { - do self.write_layout_data |data| { - data.boxes.display_list = None; - data.boxes.range = None; - } - } else { - self.set_layout_data(LayoutData::new()); + do self.write_layout_data |data| { + data.boxes.display_list = None; + data.boxes.range = None; } } - /// Initializes layout data and styles for a Node tree, if any nodes do not have - /// this data already. + /// Resets layout data and styles for a Node tree. fn initialize_style_for_subtree(self) { for n in self.traverse_preorder() { n.initialize_layout_data(); diff --git a/src/components/main/layout/layout_task.rs b/src/components/main/layout/layout_task.rs index 1ad44c4e01c..044fa055b3e 100644 --- a/src/components/main/layout/layout_task.rs +++ b/src/components/main/layout/layout_task.rs @@ -322,7 +322,6 @@ impl LayoutTask { let node: AbstractNode = unsafe { transmute(display_list.get().list[i].base().extra) }; - assert!(node.has_layout_data(), "Node has display item but no layout data"); do node.write_layout_data |layout_data| { layout_data.boxes.display_list = Some(display_list.clone()); diff --git a/src/components/script/dom/node.rs b/src/components/script/dom/node.rs index ad7b6135f83..44dff7bd8a8 100644 --- a/src/components/script/dom/node.rs +++ b/src/components/script/dom/node.rs @@ -16,7 +16,6 @@ use dom::htmliframeelement::HTMLIFrameElement; use dom::text::Text; use std::cast; -use std::cell::Cell; use std::cast::transmute; use std::libc::c_void; use extra::arc::Arc; @@ -90,7 +89,7 @@ pub struct Node { owner_doc: Option, /// Layout information. Only the layout task may touch this data. - priv layout_data: Option, + priv layout_data: LayoutData, } /// The different types of nodes. @@ -415,7 +414,7 @@ impl Node { owner_doc: None, - layout_data: None, + layout_data: LayoutData::new(), } } @@ -644,32 +643,19 @@ impl LayoutData { } impl AbstractNode { - pub fn set_layout_data(self, data: LayoutData) { - let cell = Cell::new(data); - do self.with_mut_base |b| { - b.layout_data = Some(cell.take()); - } - } - - pub fn has_layout_data(self) -> bool { - do self.with_base |b| { - b.layout_data.is_some() - } - } - // These accessors take a continuation rather than returning a reference, because // an AbstractNode doesn't have a lifetime parameter relating to the underlying // Node. Also this makes it easier to switch to RWArc if we decide that is // necessary. pub fn read_layout_data(self, blk: &fn(data: &LayoutData) -> R) -> R { do self.with_base |b| { - blk(b.layout_data.get_ref()) + blk(&b.layout_data) } } pub fn write_layout_data(self, blk: &fn(data: &mut LayoutData) -> R) -> R { do self.with_mut_base |b| { - blk(b.layout_data.get_mut_ref()) + blk(&mut b.layout_data) } } }