зеркало из https://github.com/mozilla/gecko-dev.git
servo: Fix naming in tree
Source-Repo: https://github.com/servo/servo Source-Revision: 1ec640b047d536317bf4d49d4c3011fc8932e12d
This commit is contained in:
Родитель
33fabf85c4
Коммит
d6e358f4eb
|
@ -9,7 +9,7 @@ import util::tree;
|
|||
import dvec::{dvec, extensions};
|
||||
|
||||
enum NodeData = {
|
||||
tree: tree::fields<Node>,
|
||||
tree: tree::Tree<Node>,
|
||||
kind: ~NodeKind,
|
||||
};
|
||||
|
||||
|
@ -78,7 +78,7 @@ impl NodeScope for NodeScope {
|
|||
}
|
||||
}
|
||||
|
||||
impl of tree::rd_tree_ops<Node> for NodeScope {
|
||||
impl TreeReadMethods of tree::ReadMethods<Node> 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<Node> for NodeScope {
|
|||
tree::get_parent(self, node)
|
||||
}
|
||||
|
||||
fn with_tree_fields<R>(node: Node, f: fn(tree::fields<Node>) -> R) -> R {
|
||||
fn with_tree_fields<R>(node: Node, f: fn(tree::Tree<Node>) -> R) -> R {
|
||||
self.read(node) { |n| f(n.tree) }
|
||||
}
|
||||
}
|
||||
|
||||
impl of tree::wr_tree_ops<Node> for NodeScope {
|
||||
impl TreeWriteMethods of tree::WriteMethods<Node> for NodeScope {
|
||||
fn add_child(node: Node, child: Node) {
|
||||
tree::add_child(self, node, child)
|
||||
}
|
||||
|
||||
fn with_tree_fields<R>(node: Node, f: fn(tree::fields<Node>) -> R) -> R {
|
||||
fn with_tree_fields<R>(node: Node, f: fn(tree::Tree<Node>) -> R) -> R {
|
||||
self.write(node) { |n| f(n.tree) }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<au>;
|
||||
|
@ -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<Node> for ntree {
|
||||
impl NodeTreeReadMethods of tree::ReadMethods<Node> for ntree {
|
||||
fn each_child(node: Node, f: fn(Node) -> bool) {
|
||||
tree::each_child(self, node, f)
|
||||
}
|
||||
|
||||
fn with_tree_fields<R>(&&n: Node, f: fn(tree::fields<Node>) -> R) -> R {
|
||||
fn with_tree_fields<R>(&&n: Node, f: fn(tree::Tree<Node>) -> 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<R>(&&b: @Box, f: fn(tree::fields<@Box>) -> R) -> R {
|
||||
fn with_tree_fields<R>(&&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<R>(&&b: @Box, f: fn(tree::fields<@Box>) -> R) -> R {
|
||||
fn with_tree_fields<R>(&&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};
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
//
|
||||
// TODO: Use traits.
|
||||
|
||||
type fields<T> = {
|
||||
type Tree<T> = {
|
||||
mut parent: option<T>,
|
||||
mut first_child: option<T>,
|
||||
mut last_child: option<T>,
|
||||
|
@ -10,17 +10,15 @@ type fields<T> = {
|
|||
mut next_sibling: option<T>
|
||||
};
|
||||
|
||||
iface rd_tree_ops<T> {
|
||||
fn with_tree_fields<R>(T, f: fn(fields<T>) -> R) -> R;
|
||||
iface ReadMethods<T> {
|
||||
fn with_tree_fields<R>(T, f: fn(Tree<T>) -> R) -> R;
|
||||
}
|
||||
|
||||
iface wr_tree_ops<T> {
|
||||
fn with_tree_fields<R>(T, f: fn(fields<T>) -> R) -> R;
|
||||
iface WriteMethods<T> {
|
||||
fn with_tree_fields<R>(T, f: fn(Tree<T>) -> R) -> R;
|
||||
}
|
||||
|
||||
fn each_child<T:copy,O:rd_tree_ops<T>>(
|
||||
ops: O, node: T, f: fn(T) -> bool) {
|
||||
|
||||
fn each_child<T:copy,O:ReadMethods<T>>(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<T:copy,O:rd_tree_ops<T>>(
|
|||
}
|
||||
}
|
||||
|
||||
fn empty<T>() -> fields<T> {
|
||||
fn empty<T>() -> Tree<T> {
|
||||
{mut parent: none,
|
||||
mut first_child: none,
|
||||
mut last_child: none,
|
||||
|
@ -41,7 +39,7 @@ fn empty<T>() -> fields<T> {
|
|||
mut next_sibling: none}
|
||||
}
|
||||
|
||||
fn add_child<T:copy,O:wr_tree_ops<T>>(
|
||||
fn add_child<T:copy,O:WriteMethods<T>>(
|
||||
ops: O, parent: T, child: T) {
|
||||
|
||||
ops.with_tree_fields(child) { |child_tf|
|
||||
|
@ -73,27 +71,27 @@ fn add_child<T:copy,O:wr_tree_ops<T>>(
|
|||
}
|
||||
}
|
||||
|
||||
fn get_parent<T:copy,O:rd_tree_ops<T>>(ops: O, node: T) -> option<T> {
|
||||
fn get_parent<T:copy,O:ReadMethods<T>>(ops: O, node: T) -> option<T> {
|
||||
ops.with_tree_fields(node) { |tf| tf.parent }
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
enum dummy = @{
|
||||
fields: fields<dummy>,
|
||||
fields: Tree<dummy>,
|
||||
value: uint
|
||||
};
|
||||
|
||||
enum dtree { dtree }
|
||||
|
||||
impl of rd_tree_ops<dummy> for dtree {
|
||||
fn with_tree_fields<R>(d: dummy, f: fn(fields<dummy>) -> R) -> R {
|
||||
impl of ReadMethods<dummy> for dtree {
|
||||
fn with_tree_fields<R>(d: dummy, f: fn(Tree<dummy>) -> R) -> R {
|
||||
f(d.fields)
|
||||
}
|
||||
}
|
||||
|
||||
impl of wr_tree_ops<dummy> for dtree {
|
||||
fn with_tree_fields<R>(d: dummy, f: fn(fields<dummy>) -> R) -> R {
|
||||
impl of WriteMethods<dummy> for dtree {
|
||||
fn with_tree_fields<R>(d: dummy, f: fn(Tree<dummy>) -> R) -> R {
|
||||
f(d.fields)
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче