Update for impl language changes

This commit is contained in:
Patrick Walton 2012-08-09 12:12:23 -07:00
parent 7e8d0949d0
commit 95c9188f58
31 changed files with 120 additions and 151 deletions

View file

@ -17,7 +17,6 @@ import result::{ok, err};
import dom::base::{Node, NodeScope, define_bindings}; import dom::base::{Node, NodeScope, define_bindings};
import dom::event::{Event, ResizeEvent}; import dom::event::{Event, ResizeEvent};
import dom::rcu::WriterMethods;
import dom::style; import dom::style;
import dom::style::Stylesheet; import dom::style::Stylesheet;
import gfx::renderer::Sink; import gfx::renderer::Sink;
@ -31,7 +30,6 @@ import js::rust::methods;
import js::global::{global_class, debug_fns}; import js::global::{global_class, debug_fns};
import either::{either, left, right}; import either::{either, left, right};
import result::extensions;
import dom::bindings::utils::rust_box; import dom::bindings::utils::rust_box;
import js::rust::compartment; import js::rust::compartment;

View file

@ -1,6 +1,5 @@
#[doc="The core DOM types. Defines the basic DOM hierarchy as well as all the HTML elements."] #[doc="The core DOM types. Defines the basic DOM hierarchy as well as all the HTML elements."]
import dom::rcu::WriterMethods;
import gfx::geometry::au; import gfx::geometry::au;
import geom::size::Size2D; import geom::size::Size2D;
import layout::base::LayoutData; import layout::base::LayoutData;
@ -10,12 +9,11 @@ import js::jsapi::{JSClass, JSObject, JSPropertySpec, JSContext, jsid, jsval, JS
import js::{JSPROP_ENUMERATE, JSPROP_SHARED}; import js::{JSPROP_ENUMERATE, JSPROP_SHARED};
import js::crust::*; import js::crust::*;
import js::glue::bindgen::RUST_OBJECT_TO_JSVAL; import js::glue::bindgen::RUST_OBJECT_TO_JSVAL;
import dvec::dvec;
import ptr::null; import ptr::null;
import content::Document; import content::Document;
import bindings; import bindings;
import dvec::{dvec, extensions};
enum NodeData = { enum NodeData = {
tree: tree::Tree<Node>, tree: tree::Tree<Node>,
kind: ~NodeKind, kind: ~NodeKind,
@ -86,19 +84,19 @@ fn NodeScope() -> NodeScope {
rcu::Scope() rcu::Scope()
} }
trait node_scope { trait NodeScopeExtensions {
fn new_node(-k: NodeKind) -> Node; fn new_node(-k: NodeKind) -> Node;
} }
#[allow(non_implicitly_copyable_typarams)] #[allow(non_implicitly_copyable_typarams)]
impl NodeScope of node_scope for NodeScope { impl NodeScope : NodeScopeExtensions {
fn new_node(-k: NodeKind) -> Node { fn new_node(-k: NodeKind) -> Node {
self.handle(NodeData({tree: tree::empty(), kind: ~k})) self.handle(NodeData({tree: tree::empty(), kind: ~k}))
} }
} }
#[allow(non_implicitly_copyable_typarams)] #[allow(non_implicitly_copyable_typarams)]
impl TreeReadMethods of tree::ReadMethods<Node> for NodeScope { impl NodeScope : tree::ReadMethods<Node> {
fn each_child(node: Node, f: fn(Node) -> bool) { fn each_child(node: Node, f: fn(Node) -> bool) {
tree::each_child(self, node, f) tree::each_child(self, node, f)
} }
@ -113,7 +111,7 @@ impl TreeReadMethods of tree::ReadMethods<Node> for NodeScope {
} }
#[allow(non_implicitly_copyable_typarams)] #[allow(non_implicitly_copyable_typarams)]
impl TreeWriteMethods of tree::WriteMethods<Node> for NodeScope { impl NodeScope : tree::WriteMethods<Node> {
fn add_child(node: Node, child: Node) { fn add_child(node: Node, child: Node) {
tree::add_child(self, node, child) tree::add_child(self, node, child)
} }

View file

@ -13,7 +13,6 @@ import dom::base::{Node, Element};
import utils::{rust_box, squirrel_away_unique, get_compartment, domstring_to_jsval, str}; import utils::{rust_box, squirrel_away_unique, get_compartment, domstring_to_jsval, str};
import libc::c_uint; import libc::c_uint;
import ptr::null; import ptr::null;
import rcu::ReaderMethods;
extern fn finalize(_fop: *JSFreeOp, obj: *JSObject) { extern fn finalize(_fop: *JSFreeOp, obj: *JSObject) {
#debug("node finalize!"); #debug("node finalize!");

View file

@ -49,8 +49,8 @@ of the RCU nodes themselves.
")]; ")];
import ptr::extensions;
import core::libc::types::os::arch::c95::size_t; import core::libc::types::os::arch::c95::size_t;
import ptr::ptr;
import vec::push; import vec::push;
export Handle; export Handle;
@ -84,7 +84,8 @@ enum Handle<T:send,A> {
_Handle(*HandleData<T,A>) _Handle(*HandleData<T,A>)
} }
impl HandlePrivate<T:send,A> for Handle<T,A> { // Private methods
impl<T:send,A> Handle<T,A> {
fn read_ptr() -> *T unsafe { (**self).read_ptr } fn read_ptr() -> *T unsafe { (**self).read_ptr }
fn write_ptr() -> *mut T unsafe { (**self).write_ptr } fn write_ptr() -> *mut T unsafe { (**self).write_ptr }
fn read_aux() -> *A unsafe { (**self).read_aux } fn read_aux() -> *A unsafe { (**self).read_aux }
@ -99,7 +100,7 @@ impl HandlePrivate<T:send,A> for Handle<T,A> {
fn is_not_null() -> bool { (*self).is_not_null() } fn is_not_null() -> bool { (*self).is_not_null() }
} }
impl ReaderMethods<T:send,A> for Handle<T,A> { impl<T:send,A> Handle<T,A> {
#[doc(str = "Access the reader's view of the handle's data.")] #[doc(str = "Access the reader's view of the handle's data.")]
fn read<U>(f: fn(T) -> U) -> U unsafe { fn read<U>(f: fn(T) -> U) -> U unsafe {
f(*self.read_ptr()) f(*self.read_ptr())
@ -128,7 +129,8 @@ impl ReaderMethods<T:send,A> for Handle<T,A> {
} }
} }
impl ScopePrivate<T: copy send,A> for Scope<T,A> { // Private methods
impl<T: copy send,A> Scope<T,A> {
fn clone(v: *T) -> *T unsafe { fn clone(v: *T) -> *T unsafe {
let n: *mut T = let n: *mut T =
unsafe::reinterpret_cast(libc::calloc(sys::size_of::<T>() as size_t, 1u as size_t)); unsafe::reinterpret_cast(libc::calloc(sys::size_of::<T>() as size_t, 1u as size_t));
@ -164,7 +166,8 @@ fn Scope<T:send,A>() -> Scope<T,A> {
mut first_dirty: null_handle()}) mut first_dirty: null_handle()})
} }
impl WriterMethods<T:copy send,A> for Scope<T,A> { // Writer methods
impl<T:copy send,A> Scope<T,A> {
fn is_reader_forked() -> bool { fn is_reader_forked() -> bool {
self.d.layout_active self.d.layout_active
} }
@ -228,7 +231,6 @@ impl WriterMethods<T:copy send,A> for Scope<T,A> {
#[cfg(test)] #[cfg(test)]
#[allow(non_implicitly_copyable_typarams)] #[allow(non_implicitly_copyable_typarams)]
mod test { mod test {
type animal = {name: ~str, species: species}; type animal = {name: ~str, species: species};
enum species { enum species {
chicken(~chicken), chicken(~chicken),
@ -307,5 +309,4 @@ mod test {
assert henrietta.read(read_characteristic) == iter1 * iter2; assert henrietta.read(read_characteristic) == iter1 * iter2;
assert ferdinand.read(read_characteristic) == iter1 * iter2; assert ferdinand.read(read_characteristic) == iter1 * iter2;
} }
} }

View file

@ -5,7 +5,7 @@ import num::num;
enum au = int; enum au = int;
impl au of num for au { impl au : num {
pure fn add(&&other: au) -> au { au(*self + *other) } pure fn add(&&other: au) -> au { au(*self + *other) }
pure fn sub(&&other: au) -> au { au(*self - *other) } pure fn sub(&&other: au) -> au { au(*self - *other) }
pure fn mul(&&other: au) -> au { au(*self * *other) } pure fn mul(&&other: au) -> au { au(*self * *other) }

View file

@ -35,7 +35,7 @@ enum Msg {
Exit Exit
} }
impl PngSink of Sink for chan<Msg> { impl chan<Msg> : Sink {
fn begin_drawing(+next_dt: pipes::chan<AzDrawTargetRef>) { fn begin_drawing(+next_dt: pipes::chan<AzDrawTargetRef>) {
self.send(BeginDrawing(next_dt)) self.send(BeginDrawing(next_dt))
} }

View file

@ -77,7 +77,7 @@ trait to_float {
fn to_float() -> float; fn to_float() -> float;
} }
impl to_float of to_float for u8 { impl u8 : to_float {
fn to_float() -> float { fn to_float() -> float {
(self as float) / 255f (self as float) / 255f
} }

View file

@ -1,5 +1,4 @@
import geom::size::Size2D; import geom::size::Size2D;
import int::num;
enum format { enum format {
fo_rgba_8888 fo_rgba_8888
@ -12,7 +11,7 @@ type image_surface = {
buffer: ~[u8] buffer: ~[u8]
}; };
impl format for format { impl format {
fn bpp() -> uint { fn bpp() -> uint {
match self { match self {
fo_rgba_8888 => 32u fo_rgba_8888 => 32u

View file

@ -3,7 +3,6 @@
import dom::base::{Element, ElementKind, HTMLDivElement, HTMLImageElement, Node, NodeData}; import dom::base::{Element, ElementKind, HTMLDivElement, HTMLImageElement, Node, NodeData};
import dom::base::{NodeKind}; import dom::base::{NodeKind};
import dom::rcu; import dom::rcu;
import dom::rcu::ReaderMethods;
import dom::style::Unit; import dom::style::Unit;
import gfx::geometry; import gfx::geometry;
import gfx::geometry::{au, zero_size_au}; import gfx::geometry::{au, zero_size_au};
@ -11,13 +10,10 @@ import geom::point::Point2D;
import geom::rect::Rect; import geom::rect::Rect;
import geom::size::Size2D; import geom::size::Size2D;
import image::base::{image, load}; import image::base::{image, load};
import layout::block::block_layout_methods;
import layout::inline::inline_layout_methods;
import util::tree; import util::tree;
import util::color::{Color, css_colors}; import util::color::{Color, css_colors};
import text::text_box; import style::style::SpecifiedStyle;
import style::style::{SpecifiedStyle, default_style_methods}; import text::TextBox;
import text::text_layout_methods;
import vec::{push, push_all}; import vec::{push, push_all};
import arc::{arc, clone}; import arc::{arc, clone};
@ -26,7 +22,7 @@ enum BoxKind {
BlockBox, BlockBox,
InlineBox, InlineBox,
IntrinsicBox(@Size2D<au>), IntrinsicBox(@Size2D<au>),
TextBox(@text_box) TextBoxKind(@TextBox)
} }
class Appearance { class Appearance {
@ -127,7 +123,7 @@ enum LayoutData = {
// FIXME: This is way too complex! Why do these have to have dummy receivers? --pcw // FIXME: This is way too complex! Why do these have to have dummy receivers? --pcw
enum NTree { NTree } enum NTree { NTree }
impl NodeTreeReadMethods of tree::ReadMethods<Node> for NTree { impl NTree : tree::ReadMethods<Node> {
fn each_child(node: Node, f: fn(Node) -> bool) { fn each_child(node: Node, f: fn(Node) -> bool) {
tree::each_child(self, node, f) tree::each_child(self, node, f)
} }
@ -139,7 +135,7 @@ impl NodeTreeReadMethods of tree::ReadMethods<Node> for NTree {
enum BTree { BTree } enum BTree { BTree }
impl BoxTreeReadMethods of tree::ReadMethods<@Box> for BTree { impl BTree : tree::ReadMethods<@Box> {
fn each_child(node: @Box, f: fn(&&@Box) -> bool) { fn each_child(node: @Box, f: fn(&&@Box) -> bool) {
tree::each_child(self, node, f) tree::each_child(self, node, f)
} }
@ -149,7 +145,7 @@ impl BoxTreeReadMethods of tree::ReadMethods<@Box> for BTree {
} }
} }
impl BoxTreeWriteMethods of tree::WriteMethods<@Box> for BTree { impl BTree : tree::WriteMethods<@Box> {
fn add_child(node: @Box, child: @Box) { fn add_child(node: @Box, child: @Box) {
tree::add_child(self, node, child) tree::add_child(self, node, child)
} }
@ -159,7 +155,8 @@ impl BoxTreeWriteMethods of tree::WriteMethods<@Box> for BTree {
} }
} }
impl layout_methods_priv for @Box { // Private methods
impl @Box {
#[doc="Dumps the box tree, for debugging, with indentation."] #[doc="Dumps the box tree, for debugging, with indentation."]
fn dump_indent(indent: uint) { fn dump_indent(indent: uint) {
let mut s = ~""; let mut s = ~"";
@ -176,14 +173,15 @@ impl layout_methods_priv for @Box {
} }
} }
impl layout_methods for @Box { // Public methods
impl @Box {
#[doc="The main reflow routine."] #[doc="The main reflow routine."]
fn reflow(available_width: au) { fn reflow(available_width: au) {
match self.kind { match self.kind {
BlockBox => self.reflow_block(available_width), BlockBox => self.reflow_block(available_width),
InlineBox => self.reflow_inline(available_width), InlineBox => self.reflow_inline(available_width),
IntrinsicBox(size) => self.reflow_intrinsic(*size), IntrinsicBox(size) => self.reflow_intrinsic(*size),
TextBox(subbox) => self.reflow_text(available_width, subbox) TextBoxKind(subbox) => self.reflow_text(available_width, subbox)
} }
} }
@ -202,11 +200,11 @@ impl layout_methods for @Box {
// Debugging // Debugging
trait PrivateNodeMethods{ trait PrivateNodeMethods {
fn dump_indent(ident: uint); fn dump_indent(ident: uint);
} }
impl PrivateNodeMethods of PrivateNodeMethods for Node { impl Node : PrivateNodeMethods {
#[doc="Dumps the node tree, for debugging, with indentation."] #[doc="Dumps the node tree, for debugging, with indentation."]
fn dump_indent(indent: uint) { fn dump_indent(indent: uint) {
let mut s = ~""; let mut s = ~"";
@ -227,7 +225,7 @@ trait NodeMethods {
fn dump(); fn dump();
} }
impl NodeMethods of NodeMethods for Node { impl Node : NodeMethods {
#[doc="Dumps the subtree rooted at this node, for debugging."] #[doc="Dumps the subtree rooted at this node, for debugging."]
fn dump() { fn dump() {
self.dump_indent(0u); self.dump_indent(0u);
@ -237,9 +235,8 @@ impl NodeMethods of NodeMethods for Node {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
import dom::base::{Element, ElementData, HTMLDivElement, HTMLImageElement, Node, NodeKind}; import dom::base::{Element, ElementData, HTMLDivElement, HTMLImageElement, Node, NodeKind};
import dom::base::{NodeScope, TreeWriteMethods}; import dom::base::{NodeScope};
import dom::rcu::Scope; import dom::rcu::Scope;
import box_builder::{box_builder_methods};
/* /*
use sdl; use sdl;

View file

@ -4,14 +4,14 @@ import geom::point::Point2D;
import geom::size::Size2D; import geom::size::Size2D;
import gfx::geometry::au; import gfx::geometry::au;
import util::tree; import util::tree;
import base::{Box, BlockBox, BTree, layout_methods, BoxTreeReadMethods}; import base::{Box, BlockBox, BTree};
trait block_layout_methods { trait BlockLayoutMethods {
fn reflow_block(available_widh: au); fn reflow_block(available_widh: au);
} }
#[doc="The public block layout methods."] #[doc="The public block layout methods."]
impl block_layout_methods of block_layout_methods for @Box { impl @Box : BlockLayoutMethods {
#[doc="The main reflow routine for block layout."] #[doc="The main reflow routine for block layout."]
fn reflow_block(available_width: au) { fn reflow_block(available_width: au) {
assert self.kind == BlockBox; assert self.kind == BlockBox;

View file

@ -2,13 +2,10 @@
import dom::base::{ElementData, HTMLDivElement, HTMLImageElement, Element, Text, Node}; import dom::base::{ElementData, HTMLDivElement, HTMLImageElement, Element, Text, Node};
import dom::style::{DisplayType, DisBlock, DisInline, DisNone}; import dom::style::{DisplayType, DisBlock, DisInline, DisNone};
import dom::rcu::ReaderMethods;
import gfx::geometry; import gfx::geometry;
import layout::base::{BlockBox, Box, BoxKind, BoxTreeReadMethods, BoxTreeWriteMethods, InlineBox}; import layout::base::{Appearance, BTree, BlockBox, Box, BoxKind, InlineBox, IntrinsicBox, NTree};
import layout::base::{IntrinsicBox, NodeMethods, NodeTreeReadMethods, TextBox}; import layout::base::{TextBoxKind};
import layout::base::{Appearance, BTree, NTree}; import layout::text::TextBox;
import layout::style::style::{style_methods};
import layout::text::text_box;
import util::tree; import util::tree;
import option::is_none; import option::is_none;
@ -37,7 +34,7 @@ fn create_context(parent_node: Node, parent_box: @Box) -> ctxt {
}); });
} }
impl methods for ctxt { impl ctxt {
#[doc=" #[doc="
Constructs boxes for the parent's children, when the parent's 'display' attribute is 'block'. Constructs boxes for the parent's children, when the parent's 'display' attribute is 'block'.
"] "]
@ -149,18 +146,18 @@ impl methods for ctxt {
} }
} }
trait box_builder_priv { trait PrivBoxBuilder {
fn determine_box_kind() -> BoxKind; fn determine_box_kind() -> BoxKind;
} }
impl box_builder_priv of box_builder_priv for Node { impl Node : PrivBoxBuilder {
#[doc=" #[doc="
Determines the kind of box that this node needs. Also, for images, computes the intrinsic Determines the kind of box that this node needs. Also, for images, computes the intrinsic
size. size.
"] "]
fn determine_box_kind() -> BoxKind { fn determine_box_kind() -> BoxKind {
match self.read(|n| copy n.kind) { match self.read(|n| copy n.kind) {
~Text(string) => TextBox(@text_box(copy string)), ~Text(string) => TextBoxKind(@TextBox(copy string)),
~Element(element) => { ~Element(element) => {
match *element.kind { match *element.kind {
HTMLDivElement => BlockBox, HTMLDivElement => BlockBox,
@ -172,11 +169,11 @@ impl box_builder_priv of box_builder_priv for Node {
} }
} }
trait box_builder_methods { trait BoxBuilder {
fn construct_boxes() -> @Box; fn construct_boxes() -> @Box;
} }
impl box_builder_methods of box_builder_methods for Node { impl Node : BoxBuilder {
#[doc="Creates boxes for this node. This is the entry point."] #[doc="Creates boxes for this node. This is the entry point."]
fn construct_boxes() -> @Box { fn construct_boxes() -> @Box {
let box_kind = self.determine_box_kind(); let box_kind = self.determine_box_kind();

View file

@ -1,7 +1,6 @@
export build_display_list; export build_display_list;
import base::{Box, TextBox, BTree, BoxTreeReadMethods, ImageHolder}; import base::{Box, BTree, ImageHolder, TextBoxKind};
import box_builder::box_builder_methods;
import dl = display_list; import dl = display_list;
import dom::base::{Text, NodeScope}; import dom::base::{Text, NodeScope};
import dom::rcu::Scope; import dom::rcu::Scope;
@ -12,11 +11,9 @@ import geom::size::Size2D;
import gfx::geometry::{au, au_to_px, box, px_to_au}; import gfx::geometry::{au, au_to_px, box, px_to_au};
import gfx::renderer; import gfx::renderer;
import image::base::load; import image::base::load;
import text::text_layout_methods;
import util::color::methods;
import util::tree; import util::tree;
import dvec::{dvec, extensions}; import dvec::dvec;
import vec::push; import vec::push;
#[doc = " #[doc = "
@ -73,7 +70,7 @@ fn box_to_display_items(list: dl::display_list, box: @Box, origin: Point2D<au>)
let col = box.appearance.background_color; let col = box.appearance.background_color;
match box.kind { match box.kind {
TextBox(subbox) => { TextBoxKind(subbox) => {
let run = copy subbox.run; let run = copy subbox.run;
assert run.is_some(); assert run.is_some();
list.push(dl::display_item({ list.push(dl::display_item({
@ -119,7 +116,7 @@ fn should_convert_text_boxes_to_solid_color_background_items() {
let n = s.new_node(Text(~"firecracker")); let n = s.new_node(Text(~"firecracker"));
let b = n.construct_boxes(); let b = n.construct_boxes();
let subbox = match check b.kind { TextBox(subbox) => subbox }; let subbox = match check b.kind { TextBoxKind(subbox) => subbox };
b.reflow_text(px_to_au(800), subbox); b.reflow_text(px_to_au(800), subbox);
let list = dvec(); let list = dvec();
@ -140,7 +137,7 @@ fn should_convert_text_boxes_to_text_items() {
let n = s.new_node(Text(~"firecracker")); let n = s.new_node(Text(~"firecracker"));
let b = n.construct_boxes(); let b = n.construct_boxes();
let subbox = match check b.kind { TextBox(subbox) => { subbox } }; let subbox = match check b.kind { TextBoxKind(subbox) => { subbox } };
b.reflow_text(px_to_au(800), subbox); b.reflow_text(px_to_au(800), subbox);
let list = dvec(); let list = dvec();
@ -160,7 +157,7 @@ fn should_calculate_the_bounds_of_the_text_box_background_color() {
let n = s.new_node(Text(~"firecracker")); let n = s.new_node(Text(~"firecracker"));
let b = n.construct_boxes(); let b = n.construct_boxes();
let subbox = match check b.kind { TextBox(subbox) => { subbox } }; let subbox = match check b.kind { TextBoxKind(subbox) => { subbox } };
b.reflow_text(px_to_au(800), subbox); b.reflow_text(px_to_au(800), subbox);
let list = dvec(); let list = dvec();
@ -182,7 +179,7 @@ fn should_calculate_the_bounds_of_the_text_items() {
let n = s.new_node(Text(~"firecracker")); let n = s.new_node(Text(~"firecracker"));
let b = n.construct_boxes(); let b = n.construct_boxes();
let subbox = match check b.kind { TextBox(subbox) => { subbox } }; let subbox = match check b.kind { TextBoxKind(subbox) => { subbox } };
b.reflow_text(px_to_au(800), subbox); b.reflow_text(px_to_au(800), subbox);
let list = dvec(); let list = dvec();

View file

@ -1,19 +1,18 @@
#[doc="Inline layout."] #[doc="Inline layout."]
import dom::rcu; import dom::rcu;
import dom::rcu::ReaderMethods;
import geom::point::Point2D; import geom::point::Point2D;
import geom::size::Size2D; import geom::size::Size2D;
import gfx::geometry::au; import gfx::geometry::au;
import util::tree; import util::tree;
import base::{Box, InlineBox, BTree, layout_methods, BoxTreeReadMethods}; import base::{Box, InlineBox, BTree};
trait inline_layout_methods { trait InlineLayout {
fn reflow_inline(available_width: au); fn reflow_inline(available_width: au);
} }
#[doc="The main reflow routine for inline layout."] #[doc="The main reflow routine for inline layout."]
impl inline_layout_methods of inline_layout_methods for @Box { impl @Box : InlineLayout {
fn reflow_inline(available_width: au) { fn reflow_inline(available_width: au) {
assert self.kind == InlineBox; assert self.kind == InlineBox;

View file

@ -4,16 +4,11 @@
"]; "];
import arc::arc; import arc::arc;
import display_list_builder::build_display_list; import display_list_builder::build_display_list;
import dom::base::{Node}; import dom::base::Node;
import dom::style::Stylesheet; import dom::style::Stylesheet;
import gfx::geometry::px_to_au; import gfx::geometry::px_to_au;
import gfx::renderer::Renderer; import gfx::renderer::Renderer;
import base::{NodeMethods, layout_methods};
import layout::style::style::style_methods;
import box_builder::box_builder_methods;
import layout::style::apply::ApplyStyleBoxMethods;
import task::*; import task::*;
import comm::*; import comm::*;

View file

@ -1,11 +1,9 @@
#[doc="Applies the appropriate CSS style to boxes."] #[doc="Applies the appropriate CSS style to boxes."]
import dom::base::{Element, HTMLImageElement, Node}; import dom::base::{Element, HTMLImageElement, Node};
import dom::rcu::ReaderMethods;
import either::right; import either::right;
import image::base::load; import image::base::load;
import base::{Box, BTree, NTree, LayoutData, BoxTreeReadMethods, SpecifiedStyle, ImageHolder}; import base::{Box, BTree, ImageHolder, LayoutData, NTree, SpecifiedStyle};
import style::{default_style_methods, style_methods};
import traverse::top_down_traversal; import traverse::top_down_traversal;
trait ApplyStyleBoxMethods { trait ApplyStyleBoxMethods {
@ -18,7 +16,7 @@ fn apply_style_wrapper(box : @Box) {
box.apply_style(); box.apply_style();
} }
impl ApplyStyleBoxMethods of ApplyStyleBoxMethods for @Box { impl @Box : ApplyStyleBoxMethods {
fn apply_css_style() { fn apply_css_style() {
top_down_traversal(self, apply_style_wrapper); top_down_traversal(self, apply_style_wrapper);
} }

View file

@ -6,11 +6,8 @@ import base::{ElementData, Node, Text};
import dom::style::{Selector, StyleDeclaration, FontSize, Display, TextColor, BackgroundColor, import dom::style::{Selector, StyleDeclaration, FontSize, Display, TextColor, BackgroundColor,
Stylesheet, Element, Child, Descendant, Sibling, Attr, Exact, Exists, Includes, Stylesheet, Element, Child, Descendant, Sibling, Attr, Exact, Exists, Includes,
StartsWith, Width, Height}; StartsWith, Width, Height};
import dom::rcu::ReaderMethods;
import style::{SpecifiedStyle}; import style::{SpecifiedStyle};
export matching_methods;
#[doc="Check if a CSS attribute matches the attribute of an HTML element."] #[doc="Check if a CSS attribute matches the attribute of an HTML element."]
fn attrs_match(attr: Attr, elmt: ElementData) -> bool { fn attrs_match(attr: Attr, elmt: ElementData) -> bool {
match attr { match attr {
@ -55,12 +52,12 @@ fn attrs_match(attr: Attr, elmt: ElementData) -> bool {
} }
} }
trait priv_matching_methods { trait PrivMatchingMethods {
fn matches_element(sel: ~Selector) -> bool; fn matches_element(sel: ~Selector) -> bool;
fn matches_selector(sel : ~Selector) -> bool; fn matches_selector(sel : ~Selector) -> bool;
} }
impl priv_matching_methods of priv_matching_methods for Node { impl Node : PrivMatchingMethods {
#[doc=" #[doc="
Checks if the given CSS selector, which must describe a single element with no relational Checks if the given CSS selector, which must describe a single element with no relational
information, describes the given HTML element. information, describes the given HTML element.
@ -162,11 +159,11 @@ impl priv_matching_methods of priv_matching_methods for Node {
} }
} }
trait priv_style_methods { trait PrivStyleMethods {
fn update_style(decl : StyleDeclaration); fn update_style(decl : StyleDeclaration);
} }
impl priv_style_methods of priv_style_methods for Node { impl Node : PrivStyleMethods {
#[doc="Update the computed style of an HTML element with a style specified by CSS."] #[doc="Update the computed style of an HTML element with a style specified by CSS."]
fn update_style(decl : StyleDeclaration) { fn update_style(decl : StyleDeclaration) {
self.aux(|layout| { self.aux(|layout| {
@ -182,11 +179,11 @@ impl priv_style_methods of priv_style_methods for Node {
} }
} }
trait matching_methods { trait MatchingMethods {
fn match_css_style(styles : Stylesheet); fn match_css_style(styles : Stylesheet);
} }
impl matching_methods of matching_methods for Node { impl Node : MatchingMethods {
#[doc="Compare an html element to a list of css rules and update its #[doc="Compare an html element to a list of css rules and update its
style according to the rules matching it."] style according to the rules matching it."]
fn match_css_style(styles : Stylesheet) { fn match_css_style(styles : Stylesheet) {
@ -213,8 +210,8 @@ impl matching_methods of matching_methods for Node {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
import dom::base::{Attr, HTMLDivElement, HTMLHeadElement, HTMLImageElement}; import dom::base::{Attr, HTMLDivElement, HTMLHeadElement, HTMLImageElement};
import dom::base::{NodeScope, TreeReadMethods, TreeWriteMethods, UnknownElement}; import dom::base::{NodeScope, UnknownElement};
import dvec::{dvec, extensions}; import dvec::dvec;
import io::println; import io::println;
#[allow(non_implicitly_copyable_typarams)] #[allow(non_implicitly_copyable_typarams)]

View file

@ -5,11 +5,9 @@ import arc::{arc, get, clone};
import dom::style::{DisplayType, DisBlock, DisInline, DisNone, Stylesheet, Unit, Auto}; import dom::style::{DisplayType, DisBlock, DisInline, DisNone, Stylesheet, Unit, Auto};
import dom::base::{Element, HTMLDivElement, HTMLHeadElement, HTMLImageElement, Node, NodeKind}; import dom::base::{Element, HTMLDivElement, HTMLHeadElement, HTMLImageElement, Node, NodeKind};
import dom::base::{Text}; import dom::base::{Text};
import dom::rcu::ReaderMethods;
import matching::matching_methods;
import util::color::{Color, rgb}; import util::color::{Color, rgb};
import util::color::css_colors::{white, black}; import util::color::css_colors::{white, black};
import base::{LayoutData, NTree, NodeTreeReadMethods}; import base::{LayoutData, NTree};
type SpecifiedStyle = {mut background_color : option<Color>, type SpecifiedStyle = {mut background_color : option<Color>,
mut display_type : option<DisplayType>, mut display_type : option<DisplayType>,
@ -19,15 +17,15 @@ type SpecifiedStyle = {mut background_color : option<Color>,
mut width : option<Unit> mut width : option<Unit>
}; };
trait default_style_methods { trait DefaultStyleMethods {
fn default_color() -> Color; fn default_color() -> Color;
fn default_display_type() -> DisplayType; fn default_display_type() -> DisplayType;
fn default_width() -> Unit; fn default_width() -> Unit;
fn default_height() -> Unit; fn default_height() -> Unit;
} }
#[doc="Default stylesfor various attributes in case they don't get initialized from css selectors"] /// Default styles for various attributes in case they don't get initialized from CSS selectors.
impl default_style_methods of default_style_methods for NodeKind { impl NodeKind : DefaultStyleMethods {
fn default_color() -> Color { fn default_color() -> Color {
match self { match self {
Text(*) => { white() } Text(*) => { white() }
@ -61,14 +59,13 @@ impl default_style_methods of default_style_methods for NodeKind {
} }
} }
#[doc="Create a specified style that can be used to initialize a node before selector matching. /**
* Create a specified style that can be used to initialize a node before selector matching.
Everything is initialized to none except the display style. The *
default value of thee display style is computed so that it can be * Everything is initialized to none except the display style. The default value of the display
used to short-circuit selector matching to avoid computing style * style is computed so that it can be used to short-circuit selector matching to avoid computing
for children of display:none objects. * style for children of display:none objects.
*/
"]
fn empty_style_for_node_kind(kind: NodeKind) -> SpecifiedStyle { fn empty_style_for_node_kind(kind: NodeKind) -> SpecifiedStyle {
let display_type = kind.default_display_type(); let display_type = kind.default_display_type();
@ -80,12 +77,13 @@ fn empty_style_for_node_kind(kind: NodeKind) -> SpecifiedStyle {
mut width : none} mut width : none}
} }
trait style_priv { trait StylePriv {
fn initialize_style(); fn initialize_style();
} }
impl style_priv of style_priv for Node { impl Node : StylePriv {
#[doc="Set a default auxilliary data so that other threads can modify it. #[doc="
Set a default auxiliary data so that other threads can modify it.
This is, importantly, the function that creates the layout This is, importantly, the function that creates the layout
data for the node (the reader-auxiliary box in the RCU model) data for the node (the reader-auxiliary box in the RCU model)
@ -105,13 +103,13 @@ impl style_priv of style_priv for Node {
} }
} }
trait style_methods { trait StyleMethods {
fn initialize_style_for_subtree(); fn initialize_style_for_subtree();
fn get_specified_style() -> SpecifiedStyle; fn get_specified_style() -> SpecifiedStyle;
fn recompute_style_for_subtree(styles : arc<Stylesheet>); fn recompute_style_for_subtree(styles : arc<Stylesheet>);
} }
impl style_methods of style_methods for Node { impl Node : StyleMethods {
#[doc="Sequentially initialize the nodes' auxilliary data so they can be updated in parallel."] #[doc="Sequentially initialize the nodes' auxilliary data so they can be updated in parallel."]
fn initialize_style_for_subtree() { fn initialize_style_for_subtree() {
self.initialize_style(); self.initialize_style();

View file

@ -4,11 +4,11 @@ import geom::size::Size2D;
import gfx::geometry::au; import gfx::geometry::au;
import servo_text::text_run::TextRun; import servo_text::text_run::TextRun;
import servo_text::font_library::FontLibrary; import servo_text::font_library::FontLibrary;
import base::{Box, TextBox}; import base::{Box, TextBoxKind};
class text_box { struct TextBox {
let text: ~str; text: ~str;
let mut run: option<TextRun>; mut run: option<TextRun>;
new(-text: ~str) { new(-text: ~str) {
self.text = text; self.text = text;
@ -16,15 +16,15 @@ class text_box {
} }
} }
trait text_layout_methods { trait TextLayout {
fn reflow_text(_available_width: au, subbox: @text_box); fn reflow_text(_available_width: au, subbox: @TextBox);
} }
#[doc="The main reflow routine for text layout."] #[doc="The main reflow routine for text layout."]
impl text_layout_methods of text_layout_methods for @Box { impl @Box : TextLayout {
fn reflow_text(_available_width: au, subbox: @text_box) { fn reflow_text(_available_width: au, subbox: @TextBox) {
match self.kind { match self.kind {
TextBox(*) => { /* ok */ } TextBoxKind(*) => { /* ok */ }
_ => { fail ~"expected text box in reflow_text!" } _ => { fail ~"expected text box in reflow_text!" }
}; };
@ -43,7 +43,6 @@ fn should_calculate_the_size_of_the_text_box() {
import dom::rcu::{Scope}; import dom::rcu::{Scope};
import dom::base::{Text, NodeScope}; import dom::base::{Text, NodeScope};
import box_builder::box_builder_methods;
import util::tree; import util::tree;
import gfx::geometry::px_to_au; import gfx::geometry::px_to_au;
@ -51,7 +50,7 @@ fn should_calculate_the_size_of_the_text_box() {
let n = s.new_node(Text(~"firecracker")); let n = s.new_node(Text(~"firecracker"));
let b = n.construct_boxes(); let b = n.construct_boxes();
let subbox = match check b.kind { TextBox(subbox) => { subbox } }; let subbox = match check b.kind { TextBoxKind(subbox) => { subbox } };
b.reflow_text(px_to_au(800), subbox); b.reflow_text(px_to_au(800), subbox);
let expected = Size2D(px_to_au(84), px_to_au(20)); let expected = Size2D(px_to_au(84), px_to_au(20));
assert b.bounds.size == expected; assert b.bounds.size == expected;

View file

@ -19,12 +19,12 @@ import vec::push;
type TokenReader = {stream : pipes::port<Token>, mut lookahead : option<Token>}; type TokenReader = {stream : pipes::port<Token>, mut lookahead : option<Token>};
trait util_methods { trait TokenReaderMethods {
fn get() -> Token; fn get() -> Token;
fn unget(-tok : Token); fn unget(-tok : Token);
} }
impl util_methods of util_methods for TokenReader { impl TokenReader : TokenReaderMethods {
fn get() -> Token { fn get() -> Token {
match copy self.lookahead { match copy self.lookahead {
some(tok) => { self.lookahead = none; copy tok } some(tok) => { self.lookahead = none; copy tok }
@ -38,14 +38,14 @@ impl util_methods of util_methods for TokenReader {
} }
} }
trait parser_methods { trait ParserMethods {
fn parse_element() -> option<~style::Selector>; fn parse_element() -> option<~style::Selector>;
fn parse_selector() -> option<~[~Selector]>; fn parse_selector() -> option<~[~Selector]>;
fn parse_description() -> option<~[StyleDeclaration]>; fn parse_description() -> option<~[StyleDeclaration]>;
fn parse_rule() -> option<~style::Rule>; fn parse_rule() -> option<~style::Rule>;
} }
impl parser_methods of parser_methods for TokenReader { impl TokenReader : ParserMethods {
fn parse_element() -> option<~style::Selector> { fn parse_element() -> option<~style::Selector> {
// Get the current element type // Get the current element type
let elmt_name = match self.get() { let elmt_name = match self.get() {

View file

@ -38,7 +38,7 @@ enum Token {
Eof Eof
} }
trait css_methods { trait CssLexerMethods {
fn parse_css() -> Token; fn parse_css() -> Token;
fn parse_css_relation(c : u8) -> Token; fn parse_css_relation(c : u8) -> Token;
fn parse_css_element(c : u8) -> Token; fn parse_css_element(c : u8) -> Token;
@ -46,7 +46,7 @@ trait css_methods {
fn parse_css_description(c: u8) -> Token; fn parse_css_description(c: u8) -> Token;
} }
impl css_methods of css_methods for CssLexer { impl CssLexer : CssLexerMethods {
fn parse_css() -> Token { fn parse_css() -> Token {
let mut ch: u8; let mut ch: u8;
match self.input_state.get() { match self.input_state.get() {

View file

@ -2,9 +2,7 @@
import dom::base::{Attr, Element, ElementData, ElementKind, HTMLDivElement, HTMLHeadElement, import dom::base::{Attr, Element, ElementData, ElementKind, HTMLDivElement, HTMLHeadElement,
HTMLScriptElement}; HTMLScriptElement};
import dom::base::{HTMLImageElement, Node, NodeScope, Text, TreeReadMethods, TreeWriteMethods}; import dom::base::{HTMLImageElement, Node, NodeScope, Text, UnknownElement};
import dom::base::{UnknownElement};
import dom::rcu::WriterMethods;
import geom::size::Size2D; import geom::size::Size2D;
import gfx::geometry; import gfx::geometry;
import gfx::geometry::au; import gfx::geometry::au;
@ -14,7 +12,6 @@ import dom::style::Stylesheet;
import vec::{push, push_all_move, flat_map}; import vec::{push, push_all_move, flat_map};
import std::net::url::url; import std::net::url::url;
import resource::resource_task::{ResourceTask, Load, Payload, Done}; import resource::resource_task::{ResourceTask, Load, Payload, Done};
import dvec::extensions;
import result::{ok, err}; import result::{ok, err};
import to_str::to_str; import to_str::to_str;

View file

@ -29,13 +29,13 @@ type HtmlLexer = {
mut parser_state: ParseState mut parser_state: ParseState
}; };
trait html_methods { trait HtmlLexerMethods {
fn parse_html() -> Token; fn parse_html() -> Token;
fn parse_in_normal_state(c: u8) -> Token; fn parse_in_normal_state(c: u8) -> Token;
fn parse_in_tag_state(c: u8) -> Token; fn parse_in_tag_state(c: u8) -> Token;
} }
impl html_methods of html_methods for HtmlLexer { impl HtmlLexer : HtmlLexerMethods {
fn parse_html() -> Token { fn parse_html() -> Token {
let mut ch: u8; let mut ch: u8;
match self.input_state.get() { match self.input_state.get() {

View file

@ -3,7 +3,7 @@
import option::is_none; import option::is_none;
import str::from_bytes; import str::from_bytes;
import vec::push; import vec::push;
import comm::{port, methods}; import comm::port;
import resource::resource_task::{ProgressMsg, Payload, Done}; import resource::resource_task::{ProgressMsg, Payload, Done};
enum CharOrEof { enum CharOrEof {
@ -18,12 +18,12 @@ type InputState = {
mut eof: bool mut eof: bool
}; };
trait u8_methods { trait U8Methods {
fn is_whitespace() -> bool; fn is_whitespace() -> bool;
fn is_alpha() -> bool; fn is_alpha() -> bool;
} }
impl u8_methods of u8_methods for u8 { impl u8 : U8Methods {
fn is_whitespace() -> bool { fn is_whitespace() -> bool {
return self == ' ' as u8 || self == '\n' as u8 || self == '\t' as u8; return self == ' ' as u8 || self == '\n' as u8 || self == '\t' as u8;
} }
@ -34,7 +34,7 @@ impl u8_methods of u8_methods for u8 {
} }
} }
trait util_methods { trait InputStateUtil {
fn get() -> CharOrEof; fn get() -> CharOrEof;
fn unget(ch: u8); fn unget(ch: u8);
fn parse_err(err: ~str) -> !; fn parse_err(err: ~str) -> !;
@ -44,7 +44,7 @@ trait util_methods {
fn eat_whitespace(); fn eat_whitespace();
} }
impl util_methods of util_methods for InputState { impl InputState : InputStateUtil {
fn get() -> CharOrEof { fn get() -> CharOrEof {
match copy self.lookahead { match copy self.lookahead {
some(coe) => { some(coe) => {

View file

@ -6,9 +6,9 @@ import azure::bindgen::*;
import azure::cairo; import azure::cairo;
import azure::cairo::bindgen::*; import azure::cairo::bindgen::*;
import comm::*; import comm::*;
import dvec::{dvec, extensions}; import dvec::dvec;
import azure::cairo::cairo_surface_t; import azure::cairo::cairo_surface_t;
import gfx::renderer::{Sink}; import gfx::renderer::Sink;
import dom::event::{Event, ResizeEvent}; import dom::event::{Event, ResizeEvent};
import layers::ImageLayer; import layers::ImageLayer;
import geom::size::Size2D; import geom::size::Size2D;
@ -131,7 +131,7 @@ fn mainloop(po: port<Msg>) {
Implementation to allow the osmain channel to be used as a graphics Implementation to allow the osmain channel to be used as a graphics
sink for the renderer sink for the renderer
"] "]
impl OSMain of Sink for OSMain { impl OSMain : Sink {
fn begin_drawing(+next_dt: pipes::chan<AzDrawTargetRef>) { fn begin_drawing(+next_dt: pipes::chan<AzDrawTargetRef>) {
self.send(BeginDrawing(next_dt)) self.send(BeginDrawing(next_dt))
} }

View file

@ -1,6 +1,6 @@
export factory; export factory;
import comm::{chan, methods}; import comm::chan;
import task::spawn; import task::spawn;
import resource_task::{ProgressMsg, Payload, Done}; import resource_task::{ProgressMsg, Payload, Done};
import std::net::url::url; import std::net::url::url;

View file

@ -1,6 +1,6 @@
export factory; export factory;
import comm::{chan, methods}; import comm::chan;
import task::spawn; import task::spawn;
import resource_task::{ProgressMsg, Payload, Done}; import resource_task::{ProgressMsg, Payload, Done};
import std::net::url::url; import std::net::url::url;

View file

@ -8,7 +8,7 @@ export ControlMsg, Load, Exit;
export ProgressMsg, Payload, Done; export ProgressMsg, Payload, Done;
export ResourceTask, ResourceManager, LoaderTaskFactory; export ResourceTask, ResourceManager, LoaderTaskFactory;
import comm::{chan, port, methods}; import comm::{chan, port};
import task::{spawn, spawn_listener}; import task::{spawn, spawn_listener};
import std::net::url; import std::net::url;
import std::net::url::url; import std::net::url::url;

View file

@ -182,12 +182,12 @@ fn get_cairo_face(buf: &~[u8]) -> (*cairo_font_face_t, fn@()) {
import azure::cairo_ft; import azure::cairo_ft;
import cairo_ft::bindgen::cairo_ft_font_face_create_for_ft_face; import cairo_ft::bindgen::cairo_ft_font_face_create_for_ft_face;
trait methods { trait FTErrorMethods {
fn for_sure(); fn for_sure();
fn failed() -> bool; fn failed() -> bool;
} }
impl methods of methods for FT_Error { impl FT_Error : FTErrorMethods {
fn for_sure() { assert !self.failed() } fn for_sure() { assert !self.failed() }
fn failed() -> bool { self != 0 as FT_Error } fn failed() -> bool { self != 0 as FT_Error }
} }

View file

@ -81,11 +81,11 @@ fn create(lib: FT_Library, buf: &~[u8]) -> result<FreeTypeNativeFont, ()> {
}) })
} }
trait methods { trait FTErrorMethods {
fn succeeded() -> bool; fn succeeded() -> bool;
} }
impl methods of methods for FT_Error { impl FT_Error : FTErrorMethods {
fn succeeded() -> bool { self == 0 as FT_Error } fn succeeded() -> bool { self == 0 as FT_Error }
} }

View file

@ -11,7 +11,7 @@ import cmp::eq;
enum Color = {red : u8, green : u8, blue : u8, alpha : float}; enum Color = {red : u8, green : u8, blue : u8, alpha : float};
impl Color of eq for Color { impl Color : eq {
pure fn eq(&&other: Color) -> bool { pure fn eq(&&other: Color) -> bool {
return self.red == other.red && self.green == other.green && self.blue == other.blue && return self.red == other.red && self.green == other.green && self.blue == other.blue &&
self.alpha == other.alpha; self.alpha == other.alpha;
@ -56,7 +56,7 @@ fn hsl(h : float, s : float, l : float) -> Color {
return hsla(h, s, l, 1.0); return hsla(h, s, l, 1.0);
} }
impl methods for Color { impl Color {
fn print() -> ~str { fn print() -> ~str {
#fmt["rgba(%u,%u,%u,%f)", self.red as uint, self.green as uint, #fmt["rgba(%u,%u,%u,%f)", self.red as uint, self.green as uint,
self.blue as uint, self.alpha] self.blue as uint, self.alpha]

View file

@ -83,13 +83,13 @@ mod test {
enum dtree { dtree } enum dtree { dtree }
impl of ReadMethods<dummy> for dtree { impl dtree : ReadMethods<dummy> {
fn with_tree_fields<R>(d: dummy, f: fn(Tree<dummy>) -> R) -> R { fn with_tree_fields<R>(d: dummy, f: fn(Tree<dummy>) -> R) -> R {
f(d.fields) f(d.fields)
} }
} }
impl of WriteMethods<dummy> for dtree { impl dtree : WriteMethods<dummy> {
fn with_tree_fields<R>(d: dummy, f: fn(Tree<dummy>) -> R) -> R { fn with_tree_fields<R>(d: dummy, f: fn(Tree<dummy>) -> R) -> R {
f(d.fields) f(d.fields)
} }