diff --git a/src/servo/css/lexer.rs b/src/servo/css/lexer.rs index 7c949e745c6..a4067945464 100644 --- a/src/servo/css/lexer.rs +++ b/src/servo/css/lexer.rs @@ -237,7 +237,7 @@ fn parser(input_port: comm::Port, state : ParserState) -> CssLexer }; } -fn lex_css_from_bytes(+input_port: comm::Port, result_chan : Chan) { +fn lex_css_from_bytes(+input_port: comm::Port, result_chan : &Chan) { let lexer = parser(input_port, CssElement); loop { @@ -252,7 +252,7 @@ fn lex_css_from_bytes(+input_port: comm::Port, result_chan : Chan pipes::Port { +fn spawn_css_lexer_from_string(+content : ~str) -> pipes::Port { let (result_chan, result_port) = pipes::stream(); do task::spawn { @@ -260,14 +260,14 @@ fn spawn_css_lexer_from_string(-content : ~str) -> pipes::Port { input_port.send(Payload(str::to_bytes(content))); input_port.send(Done(Ok(()))); - lex_css_from_bytes(input_port, result_chan); + lex_css_from_bytes(input_port, &result_chan); } return result_port; } #[allow(non_implicitly_copyable_typarams)] -pub fn spawn_css_lexer_task(-url: Url, resource_task: ResourceTask) -> pipes::Port { +pub fn spawn_css_lexer_task(+url: Url, resource_task: ResourceTask) -> pipes::Port { let (result_chan, result_port) = pipes::stream(); do task::spawn || { @@ -276,7 +276,7 @@ pub fn spawn_css_lexer_task(-url: Url, resource_task: ResourceTask) -> pipes::Po // TODO: change copy to move once the compiler permits it resource_task.send(Load(copy url, input_port.chan())); - lex_css_from_bytes(input_port, result_chan); + lex_css_from_bytes(input_port, &result_chan); }; return result_port; diff --git a/src/servo/css/parser.rs b/src/servo/css/parser.rs index 7643dca9249..f925392110e 100644 --- a/src/servo/css/parser.rs +++ b/src/servo/css/parser.rs @@ -21,7 +21,7 @@ type TokenReader = {stream : pipes::Port, mut lookahead : Option}; trait TokenReaderMethods { fn get() -> Token; - fn unget(-tok : Token); + fn unget(+tok : Token); } impl TokenReader : TokenReaderMethods { @@ -32,7 +32,7 @@ impl TokenReader : TokenReaderMethods { } } - fn unget(-tok : Token) { + fn unget(+tok : Token) { assert is_none(&self.lookahead); self.lookahead = Some(tok); } diff --git a/src/servo/css/parser_util.rs b/src/servo/css/parser_util.rs index fd6f476acb7..74d4e395d4a 100644 --- a/src/servo/css/parser_util.rs +++ b/src/servo/css/parser_util.rs @@ -11,27 +11,28 @@ export parse_box_sizing; export parse_display_type; -fn parse_length(str : ~str) -> Option { +fn parse_length(str : &str) -> Option { // TODO: use these once we stop lexing below const PTS_PER_INCH: float = 72.0; const CM_PER_INCH: float = 2.54; const PX_PER_PT: float = 1.0 / 0.75; match str { - s if s.ends_with(~"in") => from_str(str.substr(0, str.len() - 2)).map(|f| Px(1.0/0.75 * 72.0 * *f)), - s if s.ends_with(~"cm") => from_str(str.substr(0, str.len() - 2)).map(|f| Px(*f / 2.54 * 72.0 * 1.0/0.75)), - s if s.ends_with(~"mm") => from_str(str.substr(0, str.len() - 2)).map(|f| Px(*f * 0.1 / 2.54 * 72.0 * 1.0/0.75)), - s if s.ends_with(~"pt") => from_str(str.substr(0, str.len() - 2)).map(|f| Px(1.0/0.75 * *f)), - s if s.ends_with(~"pc") => from_str(str.substr(0, str.len() - 2)).map(|f| Px(1.0/0.75 * 12.0 * *f)), - s if s.ends_with(~"px") => from_str(str.substr(0, str.len() - 2)).map(|f| Px(*f)), - s if s.ends_with(~"em") => from_str(str.substr(0, str.len() - 2)).map(|f| Em(*f)), - s if s.ends_with(~"ex") => from_str(str.substr(0, str.len() - 2)).map(|f| Em(0.5 * *f)), + s if s.ends_with("in") => from_str(str.substr(0, str.len() - 2)).map(|f| Px(1.0/0.75 * 72.0 * *f)), + s if s.ends_with("cm") => from_str(str.substr(0, str.len() - 2)).map(|f| Px(*f / 2.54 * 72.0 * 1.0/0.75)), + s if s.ends_with("mm") => from_str(str.substr(0, str.len() - 2)).map(|f| Px(*f * 0.1 / 2.54 * 72.0 * 1.0/0.75)), + s if s.ends_with("pt") => from_str(str.substr(0, str.len() - 2)).map(|f| Px(1.0/0.75 * *f)), + s if s.ends_with("pc") => from_str(str.substr(0, str.len() - 2)).map(|f| Px(1.0/0.75 * 12.0 * *f)), + s if s.ends_with("px") => from_str(str.substr(0, str.len() - 2)).map(|f| Px(*f)), + s if s.ends_with("em") => from_str(str.substr(0, str.len() - 2)).map(|f| Em(*f)), + s if s.ends_with("ex") => from_str(str.substr(0, str.len() - 2)).map(|f| Em(0.5 * *f)), _ => None, } } -fn parse_absolute_size(str : ~str) -> ParseResult { - match str { +fn parse_absolute_size(str : &str) -> ParseResult { + // FIXME: Bad copy. Can't match &str + match str.to_str() { ~"xx-small" => Value(XXSmall), ~"x-small" => Value(XSmall), ~"small" => Value(Small), @@ -43,30 +44,33 @@ fn parse_absolute_size(str : ~str) -> ParseResult { } } -fn parse_relative_size(str: ~str) -> ParseResult { - match str { +fn parse_relative_size(str: &str) -> ParseResult { + // FIXME: Bad copy. Can't match &str + match str.to_str() { ~"smaller" => Value(Smaller), ~"larger" => Value(Larger), _ => Fail } } -fn parse_font_size(_str: ~str) -> ParseResult { +fn parse_font_size(_str: &str) -> ParseResult { // TODO: complete me Value(LengthSize(Px(14.0))) } // For width / height, and anything else with the same attribute values -fn parse_box_sizing(str : ~str) -> ParseResult { - match str { +fn parse_box_sizing(str : &str) -> ParseResult { + // FIXME: Bad copy. Can't match &str + match str.to_str() { ~"auto" => Value(BoxAuto), ~"inherit" => CSSInherit, _ => Fail, } } -fn parse_display_type(str : ~str) -> ParseResult { - match str { +fn parse_display_type(str : &str) -> ParseResult { + // FIXME: Bad copy. Can't match &str + match str.to_str() { ~"inline" => Value(DisplayInline), ~"block" => Value(DisplayBlock), ~"none" => Value(DisplayNone), diff --git a/src/servo/css/resolve/apply.rs b/src/servo/css/resolve/apply.rs index 722915fba44..e3cc05c84e7 100644 --- a/src/servo/css/resolve/apply.rs +++ b/src/servo/css/resolve/apply.rs @@ -41,7 +41,7 @@ struct StyleApplicator { } // TODO: normalize this into a normal preorder tree traversal function -fn apply_style(layout_ctx: &LayoutContext, node: Node, reflow: fn~()) { +fn apply_style(layout_ctx: &LayoutContext, node: Node, +reflow: fn~()) { let applicator = StyleApplicator { node: node, reflow: reflow @@ -55,7 +55,7 @@ fn apply_style(layout_ctx: &LayoutContext, node: Node, reflow: fn~()) { /** A wrapper around a set of functions that can be applied as a * top-down traversal of layout boxes. */ -fn inheritance_wrapper(layout_ctx: &LayoutContext, node : Node, reflow: fn~()) { +fn inheritance_wrapper(layout_ctx: &LayoutContext, node : Node, +reflow: fn~()) { let applicator = StyleApplicator { node: node, reflow: reflow diff --git a/src/servo/css/resolve/matching.rs b/src/servo/css/resolve/matching.rs index d1d058cf0c2..94822b25ca3 100644 --- a/src/servo/css/resolve/matching.rs +++ b/src/servo/css/resolve/matching.rs @@ -11,8 +11,8 @@ use styles::{SpecifiedStyle}; /** Check if a CSS attribute matches the attribute of an HTML element. */ -fn attrs_match(attr: Attr, elmt: ElementData) -> bool { - match attr { +fn attrs_match(attr: &Attr, elmt: &ElementData) -> bool { + match *attr { Exists(name) => { match elmt.get_attr(name) { Some(_) => true, @@ -55,8 +55,8 @@ fn attrs_match(attr: Attr, elmt: ElementData) -> bool { } trait PrivMatchingMethods { - fn matches_element(sel: ~Selector) -> bool; - fn matches_selector(sel : ~Selector) -> bool; + fn matches_element(sel: &Selector) -> bool; + fn matches_selector(sel: &Selector) -> bool; } impl Node : PrivMatchingMethods { @@ -66,7 +66,7 @@ impl Node : PrivMatchingMethods { element with no relational information, describes the given HTML element. */ - fn matches_element(sel: ~Selector) -> bool { + fn matches_element(sel: &Selector) -> bool { match *sel { Child(_, _) | Descendant(_, _) | Sibling(_, _) => { return false; } Element(tag, attrs) => { @@ -78,7 +78,7 @@ impl Node : PrivMatchingMethods { let mut i = 0u; while i < attrs.len() { - if !attrs_match(attrs[i], elmt) { return false; } + if !attrs_match(&attrs[i], &elmt) { return false; } i += 1u; } @@ -96,7 +96,7 @@ impl Node : PrivMatchingMethods { /** Checks if a generic CSS selector matches a given HTML element */ - fn matches_selector(sel : ~Selector) -> bool { + fn matches_selector(sel : &Selector) -> bool { match *sel { Element(*) => { return self.matches_element(sel); } Child(sel1, sel2) => { @@ -188,7 +188,7 @@ impl Node : PrivStyleMethods { } trait MatchingMethods { - fn match_css_style(styles : Stylesheet); + fn match_css_style(styles : &Stylesheet); } impl Node : MatchingMethods { @@ -196,7 +196,7 @@ impl Node : MatchingMethods { Compare an html element to a list of css rules and update its style according to the rules matching it. */ - fn match_css_style(styles : Stylesheet) { + fn match_css_style(styles : &Stylesheet) { // Loop over each rule, see if our node matches what is // described in the rule. If it matches, update its style. As // we don't currently have priorities of style information, @@ -225,7 +225,7 @@ mod test { use dvec::DVec; #[allow(non_implicitly_copyable_typarams)] - fn new_node_from_attr(scope: NodeScope, -name: ~str, -val: ~str) -> Node { + fn new_node_from_attr(scope: NodeScope, +name: ~str, +val: ~str) -> Node { let elmt = ElementData(~"div", ~HTMLDivElement); let attr = ~Attr(name, val); elmt.attrs.push(attr); diff --git a/src/servo/css/styles.rs b/src/servo/css/styles.rs index efae44c1b37..4df3d88003b 100644 --- a/src/servo/css/styles.rs +++ b/src/servo/css/styles.rs @@ -72,7 +72,7 @@ impl NodeKind : DefaultStyleMethods { * style is computed so that it can be used to short-circuit selector matching to avoid computing * 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(); {mut background_color : Initial, @@ -89,7 +89,7 @@ trait StyleMethods { fn style() -> SpecifiedStyle; fn initialize_style_for_subtree(ctx: &LayoutContext, refs: &DVec<@LayoutData>); - fn recompute_style_for_subtree(ctx: &LayoutContext, styles : ARC); + fn recompute_style_for_subtree(ctx: &LayoutContext, styles : &ARC); } impl Node : StyleMethods { @@ -101,7 +101,7 @@ impl Node : StyleMethods { false => { let node_kind = self.read(|n| copy *n.kind); let data = @LayoutData({ - mut style : ~empty_style_for_node_kind(node_kind), + mut style : ~empty_style_for_node_kind(&node_kind), mut flow : None }); self.set_aux(data); Some(data) @@ -142,17 +142,15 @@ impl Node : StyleMethods { * the node (the reader-auxiliary box in the RCU model) with the * computed style. */ - fn recompute_style_for_subtree(ctx: &LayoutContext, styles : ARC) { + fn recompute_style_for_subtree(ctx: &LayoutContext, styles : &ARC) { let mut i = 0u; // Compute the styles of each of our children in parallel for NodeTree.each_child(&self) |kid| { i = i + 1u; - let new_styles = clone(&styles); - - kid.recompute_style_for_subtree(ctx, new_styles); + kid.recompute_style_for_subtree(ctx, styles); } - self.match_css_style(*get(&styles)); + self.match_css_style(get(styles)); } } diff --git a/src/servo/css/values.rs b/src/servo/css/values.rs index 89044910348..c73eca1c9c6 100644 --- a/src/servo/css/values.rs +++ b/src/servo/css/values.rs @@ -24,11 +24,11 @@ enum CSSValue { } impl ParseResult { - pure fn extract(f: fn(CSSValue) -> U) -> Option { extract(self, f) } + pure fn extract(f: fn(+v: CSSValue) -> U) -> Option { extract(&self, f) } } -pure fn extract(res: ParseResult, f: fn(CSSValue) -> U) -> Option { - match res { +pure fn extract(res: &ParseResult, f: fn(+v: CSSValue) -> U) -> Option { + match *res { Fail => None, CSSInitial => Some(f(Initial)), CSSInherit => Some(f(Inherit)), diff --git a/src/servo/layout/box_builder.rs b/src/servo/layout/box_builder.rs index 01983435570..4e21459ff48 100644 --- a/src/servo/layout/box_builder.rs +++ b/src/servo/layout/box_builder.rs @@ -50,7 +50,7 @@ impl LayoutTreeBuilder { // TODO: remove this once UA styles work // TODO: handle interactions with 'float', 'position' (CSS 2.1, Section 9.7) - let simulated_display = match self.simulate_UA_display_rules(cur_node, style) { + let simulated_display = match self.simulate_UA_display_rules(cur_node, &style) { DisplayNone => return, // tree ends here if 'display: none' v => v }; @@ -151,7 +151,7 @@ impl LayoutTreeBuilder { fail ~"TODO: handle case where an inline is split by a block" } - priv fn simulate_UA_display_rules(node: Node, style: SpecifiedStyle) -> CSSDisplay { + priv fn simulate_UA_display_rules(node: Node, style: &SpecifiedStyle) -> CSSDisplay { let resolved = match style.display_type { Inherit | Initial => DisplayInline, // TODO: remove once resolve works Specified(v) => v diff --git a/src/servo/layout/flow.rs b/src/servo/layout/flow.rs index ccb675dfc36..75efaf2ea98 100644 --- a/src/servo/layout/flow.rs +++ b/src/servo/layout/flow.rs @@ -170,7 +170,7 @@ impl FlowContext { // Actual methods that do not require much flow-specific logic impl FlowContext { - pure fn foldl_boxes_for_node(node: Node, seed: B, blk: pure fn&(B,@RenderBox) -> B) -> B { + pure fn foldl_boxes_for_node(node: Node, +seed: B, blk: pure fn&(+a: B,@RenderBox) -> B) -> B { match self { RootFlow(*) => match self.root().box { Some(box) if box.d().node == node => { blk(seed, box) }, @@ -181,6 +181,7 @@ impl FlowContext { _ => seed }, InlineFlow(*) => do self.inline().boxes.foldl(seed) |acc, box| { + // FIXME: Bad copies. foldl's accumulator should be by-value if box.d().node == node { blk(*acc, *box) } else { *acc } }, diff --git a/src/servo/layout/layout_task.rs b/src/servo/layout/layout_task.rs index d9ba3b6e7a9..79af4717e06 100644 --- a/src/servo/layout/layout_task.rs +++ b/src/servo/layout/layout_task.rs @@ -144,7 +144,7 @@ impl Layout { do util::time::time(~"layout") { // TODO: this is dumb. we don't need 3 separate traversals. node.initialize_style_for_subtree(&layout_ctx, &self.layout_refs); - node.recompute_style_for_subtree(&layout_ctx, styles); + node.recompute_style_for_subtree(&layout_ctx, &styles); /* resolve styles (convert relative values) down the node tree */ apply_style(&layout_ctx, node, layout_ctx.reflow_cb);