diff options
author | Jack Moffitt <jack@metajack.im> | 2013-10-14 23:11:35 -0600 |
---|---|---|
committer | Jack Moffitt <jack@metajack.im> | 2013-10-21 17:38:34 -0600 |
commit | 94202661c03500fffcc7ec3e566e2a2a168c7dfc (patch) | |
tree | 111764fc98e2cfe3995e2c9d20332c29b989f761 /src/components/main/layout | |
parent | 8b47221ff8c77281eb55c5c671f23ae455cfe6bd (diff) | |
download | servo-94202661c03500fffcc7ec3e566e2a2a168c7dfc.tar.gz servo-94202661c03500fffcc7ec3e566e2a2a168c7dfc.zip |
Update to latest Rust.
Diffstat (limited to 'src/components/main/layout')
-rw-r--r-- | src/components/main/layout/block.rs | 21 | ||||
-rw-r--r-- | src/components/main/layout/box.rs | 14 | ||||
-rw-r--r-- | src/components/main/layout/box_builder.rs | 2 | ||||
-rw-r--r-- | src/components/main/layout/display_list_builder.rs | 2 | ||||
-rw-r--r-- | src/components/main/layout/float.rs | 18 | ||||
-rw-r--r-- | src/components/main/layout/float_context.rs | 4 | ||||
-rw-r--r-- | src/components/main/layout/flow.rs | 4 | ||||
-rw-r--r-- | src/components/main/layout/incremental.rs | 11 | ||||
-rw-r--r-- | src/components/main/layout/inline.rs | 34 | ||||
-rw-r--r-- | src/components/main/layout/layout_task.rs | 14 | ||||
-rw-r--r-- | src/components/main/layout/model.rs | 12 | ||||
-rw-r--r-- | src/components/main/layout/text.rs | 2 | ||||
-rw-r--r-- | src/components/main/layout/util.rs | 2 |
13 files changed, 71 insertions, 69 deletions
diff --git a/src/components/main/layout/block.rs b/src/components/main/layout/block.rs index f81fa2e45c9..88bb1e9369e 100644 --- a/src/components/main/layout/block.rs +++ b/src/components/main/layout/block.rs @@ -106,10 +106,10 @@ impl BlockFlowData { /* if not an anonymous block context, add in block box's widths. these widths will not include child elements, just padding etc. */ - self.box.map(|&box| { + for box in self.box.iter() { min_width = min_width.add(&box.get_min_width(ctx)); pref_width = pref_width.add(&box.get_pref_width(ctx)); - }); + } self.common.min_width = min_width; self.common.pref_width = pref_width; @@ -409,7 +409,7 @@ impl BlockFlowData { } let mut noncontent_height = Au(0); - self.box.map(|&box| { + for box in self.box.mut_iter() { do box.with_mut_base |base| { //The associated box is the border box of this flow base.model.margin.top = margin_top; @@ -424,7 +424,7 @@ impl BlockFlowData { noncontent_height = noncontent_height + clearance + base.model.margin.top + base.model.margin.bottom; } - }); + } //TODO(eatkinson): compute heights using the 'height' property. self.common.position.size.height = height + noncontent_height; @@ -444,16 +444,16 @@ impl BlockFlowData { -> bool { if self.common.node.is_iframe_element() { - let x = self.common.abs_position.x + do self.box.map_default(Au(0)) |box| { + let x = self.common.abs_position.x + do self.box.as_ref().map_default(Au(0)) |box| { box.with_model(|model| model.margin.left + model.border.left + model.padding.left) }; - let y = self.common.abs_position.y + do self.box.map_default(Au(0)) |box| { + let y = self.common.abs_position.y + do self.box.as_ref().map_default(Au(0)) |box| { box.with_model(|model| model.margin.top + model.border.top + model.padding.top) }; - let w = self.common.position.size.width - do self.box.map_default(Au(0)) |box| { + let w = self.common.position.size.width - do self.box.as_ref().map_default(Au(0)) |box| { box.with_model(|model| model.noncontent_width()) }; - let h = self.common.position.size.height - do self.box.map_default(Au(0)) |box| { + let h = self.common.position.size.height - do self.box.as_ref().map_default(Au(0)) |box| { box.with_model(|model| model.noncontent_height()) }; do self.common.node.with_mut_iframe_element |iframe_element| { @@ -472,10 +472,9 @@ impl BlockFlowData { debug!("build_display_list_block: adding display element"); // add box that starts block context - self.box.map(|&box| { + for box in self.box.iter() { box.build_display_list(builder, dirty, &self.common.abs_position, list) - }); - + } // TODO: handle any out-of-flow elements let this_position = self.common.abs_position; diff --git a/src/components/main/layout/box.rs b/src/components/main/layout/box.rs index 9d1491c11fe..3ee83d4407c 100644 --- a/src/components/main/layout/box.rs +++ b/src/components/main/layout/box.rs @@ -362,10 +362,10 @@ impl RenderBox { None }; - let right_box = do right_range.map_default(None) |range: &Range| { + let right_box = do right_range.map_default(None) |range: Range| { let new_text_box = @mut text::adapt_textbox_with_range(text_box.base, text_box.run, - *range); + range); Some(TextRenderBoxClass(new_text_box)) }; @@ -498,7 +498,7 @@ impl RenderBox { let px_width = if attr_width.is_some() { attr_width.unwrap() } else { - image_box.image.get_size().unwrap_or_default(Size2D(0, 0)).width + image_box.image.get_size().unwrap_or(Size2D(0, 0)).width }; Au::from_px(px_width) @@ -524,7 +524,7 @@ impl RenderBox { let px_height = if attr_height.is_some() { attr_height.unwrap() } else { - image_box.image.get_size().unwrap_or_default(Size2D(0, 0)).height + image_box.image.get_size().unwrap_or(Size2D(0, 0)).height }; Au::from_px(px_height) @@ -852,10 +852,10 @@ impl RenderBox { debug!("(font style) font families: `%s`", font_families); let font_size = match my_style.font_size() { - CSSFontSizeLength(Px(length)) => length, + CSSFontSizeLength(Px(length)) => length as f64, // todo: this is based on a hard coded font size, should be the parent element's font size - CSSFontSizeLength(Em(length)) => length * 16f, - _ => 16f // px units + CSSFontSizeLength(Em(length)) => (length as f64) * 16f64, + _ => 16f64 // px units }; debug!("(font style) font size: `%fpx`", font_size); diff --git a/src/components/main/layout/box_builder.rs b/src/components/main/layout/box_builder.rs index 950370f06cb..e0c821fc945 100644 --- a/src/components/main/layout/box_builder.rs +++ b/src/components/main/layout/box_builder.rs @@ -405,7 +405,7 @@ impl LayoutTreeBuilder { } }; - let sibling_flow: Option<&mut FlowContext> = sibling_generator.map_mut(|gen| &mut *gen.flow); + let sibling_flow: Option<&mut FlowContext> = sibling_generator.as_mut().map(|gen| &mut *gen.flow); // TODO(eatkinson): use the value of the float property to // determine whether to float left or right. diff --git a/src/components/main/layout/display_list_builder.rs b/src/components/main/layout/display_list_builder.rs index cc89f7cb61b..6d175cf6a9a 100644 --- a/src/components/main/layout/display_list_builder.rs +++ b/src/components/main/layout/display_list_builder.rs @@ -63,7 +63,7 @@ pub trait ToGfxColor { impl ToGfxColor for newcss::color::Color { fn to_gfx_color(&self) -> gfx::color::Color { - gfx::color::rgba(self.red, self.green, self.blue, self.alpha) + gfx::color::rgba(self.red, self.green, self.blue, self.alpha as f64) } } diff --git a/src/components/main/layout/float.rs b/src/components/main/layout/float.rs index c63d8e8f8a6..588a0dabff9 100644 --- a/src/components/main/layout/float.rs +++ b/src/components/main/layout/float.rs @@ -81,7 +81,7 @@ impl FloatFlowData { self.floated_children = num_floats; - self.box.map(|&box| { + for box in self.box.iter() { let style = box.style(); do box.with_model |model| { model.compute_borders(style) @@ -89,7 +89,7 @@ impl FloatFlowData { min_width = min_width.add(&box.get_min_width(ctx)); pref_width = pref_width.add(&box.get_pref_width(ctx)); - }); + } self.common.min_width = min_width; self.common.pref_width = pref_width; @@ -185,7 +185,7 @@ impl FloatFlowData { let mut full_noncontent_width = Au(0); let mut margin_height = Au(0); - self.box.map(|&box| { + for box in self.box.iter() { height = do box.with_base |base| { base.position.size.height }; @@ -204,7 +204,7 @@ impl FloatFlowData { margin_height = base.model.margin.top + base.model.margin.bottom; } - }); + } let info = PlacementInfo { width: self.common.position.size.width + full_noncontent_width, @@ -257,7 +257,7 @@ impl FloatFlowData { let mut noncontent_width = Au(0); let mut noncontent_height = Au(0); - self.box.map(|&box| { + for box in self.box.mut_iter() { do box.with_mut_base |base| { //The associated box is the border box of this flow base.position.origin.y = base.model.margin.top; @@ -269,8 +269,7 @@ impl FloatFlowData { base.position.size.height = height + noncontent_height; } - }); - + } //TODO(eatkinson): compute heights properly using the 'height' property. for &box in self.box.iter() { @@ -305,10 +304,9 @@ impl FloatFlowData { let offset = self.common.abs_position + self.rel_pos; // add box that starts block context - self.box.map(|&box| { + for box in self.box.iter() { box.build_display_list(builder, dirty, &offset, list) - }); - + } // TODO: handle any out-of-flow elements diff --git a/src/components/main/layout/float_context.rs b/src/components/main/layout/float_context.rs index adc083105fe..e9f39586081 100644 --- a/src/components/main/layout/float_context.rs +++ b/src/components/main/layout/float_context.rs @@ -300,7 +300,7 @@ impl FloatContextBase{ f_data.bounds.origin.x + f_data.bounds.size.width > left && f_data.bounds.origin.x < left + width { let new_y = f_data.bounds.origin.y; - max_height = Some(min(max_height.unwrap_or_default(new_y), new_y)); + max_height = Some(min(max_height.unwrap_or(new_y), new_y)); } } } @@ -340,7 +340,7 @@ impl FloatContextBase{ let height = self.max_height_for_bounds(rect.origin.x, rect.origin.y, rect.size.width); - let height = height.unwrap_or_default(Au(max_value)); + let height = height.unwrap_or(Au(max_value)); return match info.f_type { FloatLeft => Rect(Point2D(rect.origin.x, float_y), Size2D(rect.size.width, height)), diff --git a/src/components/main/layout/flow.rs b/src/components/main/layout/flow.rs index a1675c46204..273272fbe04 100644 --- a/src/components/main/layout/flow.rs +++ b/src/components/main/layout/flow.rs @@ -425,7 +425,7 @@ impl<'self> FlowContext { pub fn foldl_all_boxes<B:Clone>(&mut self, seed: B, cb: &fn(a: B, b: RenderBox) -> B) -> B { match *self { BlockFlow(ref mut block) => { - do block.box.map_default(seed.clone()) |box| { + do block.box.as_ref().map_default(seed.clone()) |box| { cb(seed.clone(), *box) } } @@ -455,7 +455,7 @@ impl<'self> FlowContext { pub fn iter_all_boxes(&mut self) -> BoxIterator { BoxIterator { boxes: match *self { - BlockFlow (ref mut block) => block.box.map_default(~[], |&x| ~[x]), + BlockFlow(ref mut block) => block.box.as_ref().map_default(~[], |&x| ~[x]), InlineFlow(ref mut inline) => inline.boxes.clone(), _ => fail!(fmt!("Don't know how to iterate node's RenderBoxes for %?", self)) }, diff --git a/src/components/main/layout/incremental.rs b/src/components/main/layout/incremental.rs index 6beea28cf0c..85f565c04bc 100644 --- a/src/components/main/layout/incremental.rs +++ b/src/components/main/layout/incremental.rs @@ -112,9 +112,10 @@ impl RestyleDamage { // version of this macro might be safe anyway, but we want to avoid silent // breakage on modifications. macro_rules! add_if_not_equal( - ([ $($effect:ident),* ], [ $($getter:ident),* ]) => ({ - if $( (old.$getter() != new.$getter()) )||* { - damage.union_in_place( restyle_damage!( $($effect),* ) ); + ($old:ident, $new:ident, $damage:ident, + [ $($effect:ident),* ], [ $($getter:ident),* ]) => ({ + if $( ($old.$getter() != $new.$getter()) )||* { + $damage.union_in_place( restyle_damage!( $($effect),* ) ); } }) ) @@ -132,11 +133,11 @@ pub fn compute_damage(node: &AbstractNode<LayoutView>, // FIXME: We can short-circuit more of this. - add_if_not_equal!([ Repaint ], + add_if_not_equal!(old, new, damage, [ Repaint ], [ color, background_color, border_top_color, border_right_color, border_bottom_color, border_left_color ]); - add_if_not_equal!([ Repaint, BubbleWidths, Reflow ], + add_if_not_equal!(old, new, damage, [ Repaint, BubbleWidths, Reflow ], [ border_top_width, border_right_width, border_bottom_width, border_left_width, margin_top, margin_right, margin_bottom, margin_left, padding_top, padding_right, padding_bottom, padding_left, position, diff --git a/src/components/main/layout/inline.rs b/src/components/main/layout/inline.rs index c623077f519..b19bc15a11f 100644 --- a/src/components/main/layout/inline.rs +++ b/src/components/main/layout/inline.rs @@ -171,11 +171,11 @@ impl LineboxScanner { fn calculate_line_height(&self, box: RenderBox, font_size: Au) -> Au { match box.line_height() { - CSSLineHeightNormal => font_size.scale_by(1.14f), - CSSLineHeightNumber(l) => font_size.scale_by(l), - CSSLineHeightLength(Em(l)) => font_size.scale_by(l), - CSSLineHeightLength(Px(l)) => Au::from_frac_px(l), - CSSLineHeightPercentage(p) => font_size.scale_by(p / 100.0f) + CSSLineHeightNormal => font_size.scale_by(1.14f64), + CSSLineHeightNumber(l) => font_size.scale_by(l as f64), + CSSLineHeightLength(Em(l)) => font_size.scale_by(l as f64), + CSSLineHeightLength(Px(l)) => Au::from_frac_px(l as f64), + CSSLineHeightPercentage(p) => font_size.scale_by(p as f64 / 100.0f64) } } @@ -183,7 +183,7 @@ impl LineboxScanner { match box { ImageRenderBoxClass(image_box) => { let size = image_box.image.get_size(); - let height = Au::from_px(size.unwrap_or_default(Size2D(0, 0)).height); + let height = Au::from_px(size.unwrap_or(Size2D(0, 0)).height); image_box.base.position.size.height = height; debug!("box_height: found image height: %?", height); height @@ -645,7 +645,7 @@ impl InlineFlowData { } } CSSTextAlignCenter => { - offset_x = offset_x + slack_width.scale_by(0.5f); + offset_x = offset_x + slack_width.scale_by(0.5f64); for i in line.range.eachi() { do self.boxes[i].with_mut_base |base| { base.position.origin.x = offset_x; @@ -715,7 +715,7 @@ impl InlineFlowData { let text_ascent = text_box.run.font.metrics.ascent; // Offset from the top of the box is 1/2 of the leading + ascent - let text_offset = text_ascent + (line_height - em_size).scale_by(0.5f); + let text_offset = text_ascent + (line_height - em_size).scale_by(0.5f64); text_bounds.translate(&Point2D(text_box.base.position.origin.x, Au(0))); (text_offset, line_height - text_offset, text_ascent) @@ -746,13 +746,17 @@ impl InlineFlowData { let parent_text_bottom = Au(0); do cur_box.with_mut_base |base| { // Get parent node - let parent = base.node.parent_node().map_default(base.node, |parent| *parent); + let parent = match base.node.parent_node() { + None => base.node, + Some(parent) => parent, + }; + // TODO: When the calculation of font-size style is supported, it should be updated. let font_size = match parent.style().font_size() { - CSSFontSizeLength(Px(length)) => length, + CSSFontSizeLength(Px(length)) => length as f64, // todo: this is based on a hard coded font size, should be the parent element's font size - CSSFontSizeLength(Em(length)) => length * 16f, - _ => 16f // px units + CSSFontSizeLength(Em(length)) => length as f64 * 16f64, + _ => 16f64 // px units }; parent_text_top = Au::from_frac_px(font_size); } @@ -814,15 +818,15 @@ impl InlineFlowData { }, CSSVerticalAlignLength(length) => { let length_offset = match length { - Em(l) => Au::from_frac_px(cur_box.font_style().pt_size * l), - Px(l) => Au::from_frac_px(l), + Em(l) => Au::from_frac_px(cur_box.font_style().pt_size * l as f64), + Px(l) => Au::from_frac_px(l as f64), }; -(length_offset + ascent) }, CSSVerticalAlignPercentage(p) => { let pt_size = cur_box.font_style().pt_size; let line_height = scanner.calculate_line_height(cur_box, Au::from_pt(pt_size)); - let percent_offset = line_height.scale_by(p / 100.0f); + let percent_offset = line_height.scale_by(p as f64 / 100.0f64); -(percent_offset + ascent) } }; diff --git a/src/components/main/layout/layout_task.rs b/src/components/main/layout/layout_task.rs index 1feb7338c62..056b9477b19 100644 --- a/src/components/main/layout/layout_task.rs +++ b/src/components/main/layout/layout_task.rs @@ -391,7 +391,7 @@ impl LayoutTask { for child in node.children() { let rect = box_for_node(child); match rect { - None => loop, + None => continue, Some(rect) => acc = match acc { Some(acc) => Some(acc.union(&rect)), None => Some(rect) @@ -404,8 +404,8 @@ impl LayoutTask { } } - let rect = box_for_node(node).unwrap_or_default(Rect(Point2D(Au(0), Au(0)), - Size2D(Au(0), Au(0)))); + let rect = box_for_node(node).unwrap_or(Rect(Point2D(Au(0), Au(0)), + Size2D(Au(0), Au(0)))); reply_chan.send(ContentBoxResponse(rect)) } ContentBoxesQuery(node, reply_chan) => { @@ -444,8 +444,8 @@ impl LayoutTask { match self.display_list { Some(ref list) => { let display_list = list.get(); - let (x, y) = (Au::from_frac_px(point.x as float), - Au::from_frac_px(point.y as float)); + let (x, y) = (Au::from_frac_px(point.x as f64), + Au::from_frac_px(point.y as f64)); let mut resp = Err(()); // iterate in reverse to ensure we have the most recently painted render box for display_item in display_list.list.rev_iter() { @@ -482,13 +482,13 @@ impl LayoutTask { // re-requested. We probably don't need to go all the way back to // the script task for this. fn make_on_image_available_cb(&self, script_chan: ScriptChan) - -> @fn() -> ~fn(ImageResponseMsg) { + -> ~fn() -> ~fn(ImageResponseMsg) { // This has a crazy signature because the image cache needs to // make multiple copies of the callback, and the dom event // channel is not a copyable type, so this is actually a // little factory to produce callbacks let id = self.id.clone(); - let f: @fn() -> ~fn(ImageResponseMsg) = || { + let f: ~fn() -> ~fn(ImageResponseMsg) = || { let script_chan = script_chan.clone(); let f: ~fn(ImageResponseMsg) = |_| { script_chan.send(SendEventMsg(id.clone(), ReflowEvent)) diff --git a/src/components/main/layout/model.rs b/src/components/main/layout/model.rs index e51095ae086..c4d6e453ec5 100644 --- a/src/components/main/layout/model.rs +++ b/src/components/main/layout/model.rs @@ -26,10 +26,10 @@ pub struct BoxModel { fn from_length(length: Length, font_size: CSSFontSize) -> Au { match length { - Px(v) => Au::from_frac_px(v), + Px(v) => Au::from_frac_px(v as f64), Em(em) => { match font_size { - CSSFontSizeLength(Px(v)) => Au::from_frac_px(em * v), + CSSFontSizeLength(Px(v)) => Au::from_frac_px((em * v) as f64), _ => fail!("expected non-relative font size") } } @@ -46,7 +46,7 @@ impl MaybeAuto { pub fn from_margin(margin: CSSMargin, containing_width: Au, font_size: CSSFontSize) -> MaybeAuto { match margin { CSSMarginAuto => Auto, - CSSMarginPercentage(percent) => Specified(containing_width.scale_by(percent/100.0)), + CSSMarginPercentage(percent) => Specified(containing_width.scale_by(percent as f64 / 100.0f64)), CSSMarginLength(length) => Specified(from_length(length, font_size)) } } @@ -54,7 +54,7 @@ impl MaybeAuto { pub fn from_width(width: CSSWidth, containing_width: Au, font_size: CSSFontSize) -> MaybeAuto { match width { CSSWidthAuto => Auto, - CSSWidthPercentage(percent) => Specified(containing_width.scale_by(percent/100.0)), + CSSWidthPercentage(percent) => Specified(containing_width.scale_by(percent as f64 / 100.0f64)), CSSWidthLength(length) => Specified(from_length(length, font_size)) } } @@ -62,7 +62,7 @@ impl MaybeAuto { pub fn from_height(height: CSSHeight, cb_height: Au, font_size: CSSFontSize) -> MaybeAuto { match height { CSSHeightAuto => Auto, - CSSHeightPercentage(percent) => Specified(cb_height.scale_by(percent/100.0)), + CSSHeightPercentage(percent) => Specified(cb_height.scale_by(percent as f64 / 100.0f64)), CSSHeightLength(length) => Specified(from_length(length, font_size)) } } @@ -140,7 +140,7 @@ impl BoxModel { pub fn compute_padding_length(&self, padding: CSSPadding, content_box_width: Au, font_size: CSSFontSize) -> Au { match padding { CSSPaddingLength(length) => from_length(length, font_size), - CSSPaddingPercentage(p) => content_box_width.scale_by(p/100.0) + CSSPaddingPercentage(p) => content_box_width.scale_by(p as f64 / 100.0f64) } } } diff --git a/src/components/main/layout/text.rs b/src/components/main/layout/text.rs index 5dd9306c26d..a14dd2bf74a 100644 --- a/src/components/main/layout/text.rs +++ b/src/components/main/layout/text.rs @@ -231,7 +231,7 @@ impl TextRunScanner { debug!("Elided an `UnscannedTextbox` because it was zero-length after \ compression; %s", in_boxes[i].debug_str()); - loop + continue } do in_boxes[i].with_base |base| { diff --git a/src/components/main/layout/util.rs b/src/components/main/layout/util.rs index e976e50c635..c45ca1f3631 100644 --- a/src/components/main/layout/util.rs +++ b/src/components/main/layout/util.rs @@ -6,7 +6,7 @@ use layout::box::{RenderBox}; use script::dom::node::{AbstractNode, LayoutView}; use servo_util::range::Range; -use std::iterator::Enumerate; +use std::iter::Enumerate; use std::vec::VecIterator; pub struct NodeRange { |