diff --git a/src/servo/dom/base.rs b/src/servo/dom/base.rs index 93bcd6d73e7..04065a80db4 100644 --- a/src/servo/dom/base.rs +++ b/src/servo/dom/base.rs @@ -9,7 +9,7 @@ import util::tree; import dvec::{dvec, extensions}; enum NodeData = { - tree: tree::fields, + tree: tree::Tree, kind: ~NodeKind, }; @@ -78,7 +78,7 @@ impl NodeScope for NodeScope { } } -impl of tree::rd_tree_ops for NodeScope { +impl TreeReadMethods of tree::ReadMethods for NodeScope { fn each_child(node: Node, f: fn(Node) -> bool) { tree::each_child(self, node, f) } @@ -87,17 +87,17 @@ impl of tree::rd_tree_ops for NodeScope { tree::get_parent(self, node) } - fn with_tree_fields(node: Node, f: fn(tree::fields) -> R) -> R { + fn with_tree_fields(node: Node, f: fn(tree::Tree) -> R) -> R { self.read(node) { |n| f(n.tree) } } } -impl of tree::wr_tree_ops for NodeScope { +impl TreeWriteMethods of tree::WriteMethods for NodeScope { fn add_child(node: Node, child: Node) { tree::add_child(self, node, child) } - fn with_tree_fields(node: Node, f: fn(tree::fields) -> R) -> R { + fn with_tree_fields(node: Node, f: fn(tree::Tree) -> R) -> R { self.write(node) { |n| f(n.tree) } } } diff --git a/src/servo/layout/base.rs b/src/servo/layout/base.rs index 13497778385..2d5f03746a2 100644 --- a/src/servo/layout/base.rs +++ b/src/servo/layout/base.rs @@ -35,7 +35,7 @@ class appearance { } class Box { - let tree: tree::fields<@Box>; + let tree: tree::Tree<@Box>; let node: Node; let kind: BoxKind; let mut bounds: Rect; @@ -55,34 +55,36 @@ enum layout_data = { mut box: option<@Box> }; +// FIXME: This is way too complex! Why do these have to have dummy receivers? --pcw + enum ntree { ntree } -impl of tree::rd_tree_ops for ntree { +impl NodeTreeReadMethods of tree::ReadMethods for ntree { fn each_child(node: Node, f: fn(Node) -> bool) { tree::each_child(self, node, f) } - fn with_tree_fields(&&n: Node, f: fn(tree::fields) -> R) -> R { + fn with_tree_fields(&&n: Node, f: fn(tree::Tree) -> R) -> R { n.read { |n| f(n.tree) } } } enum btree { btree } -impl of tree::rd_tree_ops<@Box> for btree { +impl BoxTreeReadMethods of tree::ReadMethods<@Box> for btree { fn each_child(node: @Box, f: fn(&&@Box) -> bool) { tree::each_child(self, node, f) } - fn with_tree_fields(&&b: @Box, f: fn(tree::fields<@Box>) -> R) -> R { + fn with_tree_fields(&&b: @Box, f: fn(tree::Tree<@Box>) -> R) -> R { f(b.tree) } } -impl of tree::wr_tree_ops<@Box> for btree { +impl BoxTreeWriteMethods of tree::WriteMethods<@Box> for btree { fn add_child(node: @Box, child: @Box) { tree::add_child(self, node, child) } - fn with_tree_fields(&&b: @Box, f: fn(tree::fields<@Box>) -> R) -> R { + fn with_tree_fields(&&b: @Box, f: fn(tree::Tree<@Box>) -> R) -> R { f(b.tree) } } @@ -155,7 +157,7 @@ impl NodeMethods for Node { #[cfg(test)] mod test { import dom::base::{Element, ElementData, HTMLDivElement, HTMLImageElement, Node, NodeKind}; - import dom::base::{NodeScope, wr_tree_ops}; + import dom::base::{NodeScope, TreeWriteMethods}; import dom::rcu::Scope; import box_builder::{box_builder_methods}; diff --git a/src/servo/layout/box_builder.rs b/src/servo/layout/box_builder.rs index cdb121b8bb1..1678e5075e7 100644 --- a/src/servo/layout/box_builder.rs +++ b/src/servo/layout/box_builder.rs @@ -4,8 +4,9 @@ import dom::base::{ElementData, HTMLDivElement, HTMLImageElement, Element, Text, import dom::style::{display_type, di_block, di_inline, di_none}; import dom::rcu::ReaderMethods; import gfx::geometry; -import layout::base::{BlockBox, Box, BoxKind, InlineBox, IntrinsicBox, NodeMethods, TextBox}; -import layout::base::{appearance, btree, ntree, rd_tree_ops, wr_tree_ops}; +import layout::base::{BlockBox, Box, BoxKind, BoxTreeReadMethods, BoxTreeWriteMethods, InlineBox}; +import layout::base::{IntrinsicBox, NodeMethods, NodeTreeReadMethods, TextBox}; +import layout::base::{appearance, btree, ntree}; import layout::style::style::{style_methods}; import layout::text::text_box; import util::tree; diff --git a/src/servo/layout/style/matching.rs b/src/servo/layout/style/matching.rs index 5a0b00fdb57..0554319a622 100644 --- a/src/servo/layout/style/matching.rs +++ b/src/servo/layout/style/matching.rs @@ -203,7 +203,7 @@ impl matching_methods for Node { mod test { import dom::base::{Attr, Element, HTMLDivElement, HTMLHeadElement, HTMLImageElement}; - import dom::base::{NodeScope, UnknownElement, wr_tree_ops}; + import dom::base::{NodeScope, TreeReadMethods, TreeWriteMethods, UnknownElement}; import dvec::{dvec, extensions}; import io::println; diff --git a/src/servo/parser/html_builder.rs b/src/servo/parser/html_builder.rs index 91163d11555..097012a661e 100644 --- a/src/servo/parser/html_builder.rs +++ b/src/servo/parser/html_builder.rs @@ -1,8 +1,8 @@ #[doc="Constructs a DOM tree from an incoming token stream."] import dom::base::{Attr, Element, ElementData, ElementKind, HTMLDivElement, HTMLHeadElement}; -import dom::base::{HTMLImageElement, Node, NodeScope, Text, UnknownElement, rd_tree_ops}; -import dom::base::{wr_tree_ops}; +import dom::base::{HTMLImageElement, Node, NodeScope, Text, TreeReadMethods, TreeWriteMethods}; +import dom::base::{UnknownElement}; import dom::rcu::WriterMethods; import geom::size::Size2D; import gfx::geometry; diff --git a/src/servo/util/tree.rs b/src/servo/util/tree.rs index 38e734c715b..cbb3db09620 100644 --- a/src/servo/util/tree.rs +++ b/src/servo/util/tree.rs @@ -2,7 +2,7 @@ // // TODO: Use traits. -type fields = { +type Tree = { mut parent: option, mut first_child: option, mut last_child: option, @@ -10,17 +10,15 @@ type fields = { mut next_sibling: option }; -iface rd_tree_ops { - fn with_tree_fields(T, f: fn(fields) -> R) -> R; +iface ReadMethods { + fn with_tree_fields(T, f: fn(Tree) -> R) -> R; } -iface wr_tree_ops { - fn with_tree_fields(T, f: fn(fields) -> R) -> R; +iface WriteMethods { + fn with_tree_fields(T, f: fn(Tree) -> R) -> R; } -fn each_child>( - ops: O, node: T, f: fn(T) -> bool) { - +fn each_child>(ops: O, node: T, f: fn(T) -> bool) { let mut p = ops.with_tree_fields(node) { |f| f.first_child }; loop { alt copy p { @@ -33,7 +31,7 @@ fn each_child>( } } -fn empty() -> fields { +fn empty() -> Tree { {mut parent: none, mut first_child: none, mut last_child: none, @@ -41,7 +39,7 @@ fn empty() -> fields { mut next_sibling: none} } -fn add_child>( +fn add_child>( ops: O, parent: T, child: T) { ops.with_tree_fields(child) { |child_tf| @@ -73,27 +71,27 @@ fn add_child>( } } -fn get_parent>(ops: O, node: T) -> option { +fn get_parent>(ops: O, node: T) -> option { ops.with_tree_fields(node) { |tf| tf.parent } } #[cfg(test)] mod test { enum dummy = @{ - fields: fields, + fields: Tree, value: uint }; enum dtree { dtree } - impl of rd_tree_ops for dtree { - fn with_tree_fields(d: dummy, f: fn(fields) -> R) -> R { + impl of ReadMethods for dtree { + fn with_tree_fields(d: dummy, f: fn(Tree) -> R) -> R { f(d.fields) } } - impl of wr_tree_ops for dtree { - fn with_tree_fields(d: dummy, f: fn(fields) -> R) -> R { + impl of WriteMethods for dtree { + fn with_tree_fields(d: dummy, f: fn(Tree) -> R) -> R { f(d.fields) } }