diff --git a/src/components/main/layout/box_.rs b/src/components/main/layout/box_.rs index fe052de786a..bd7ba5bd000 100644 --- a/src/components/main/layout/box_.rs +++ b/src/components/main/layout/box_.rs @@ -532,38 +532,35 @@ impl Box { // needed. We could use display list optimization to clean this up, but it still seems // inefficient. What we really want is something like "nearest ancestor element that // doesn't have a box". + let info = self.inline_info.borrow(); + match info.get() { + &Some(ref box_info) => { + let mut bg_rect = absolute_bounds.clone(); + for info in box_info.parent_info.rev_iter() { + // TODO (ksh8281) compute vertical-align, line-height + bg_rect.origin.y = box_info.baseline + offset.y - info.font_ascent; + bg_rect.size.height = info.font_ascent + info.font_descent; + let background_color = info.style.get().resolve_color( + info.style.get().Background.background_color); + if !background_color.alpha.approx_eq(&0.0) { + list.with_mut(|list| { + let solid_color_display_item = ~SolidColorDisplayItem { + base: BaseDisplayItem { + bounds: bg_rect.clone(), + extra: ExtraDisplayListData::new(self), + }, + color: background_color.to_gfx_color(), + }; - self.inline_info.with( |info| { - match info { - &Some(ref box_info) => { - let mut bg_rect = absolute_bounds.clone(); - for info in box_info.parent_info.rev_iter() { - // TODO (ksh8281) compute vertical-align, line-height - bg_rect.origin.y = box_info.baseline + offset.y - info.font_ascent; - bg_rect.size.height = info.font_ascent + info.font_descent; - let background_color = info.style.get().resolve_color( - info.style.get().Background.background_color); - - if !background_color.alpha.approx_eq(&0.0) { - list.with_mut(|list| { - let solid_color_display_item = ~SolidColorDisplayItem { - base: BaseDisplayItem { - bounds: bg_rect.clone(), - extra: ExtraDisplayListData::new(self), - }, - color: background_color.to_gfx_color(), - }; - - list.append_item(SolidColorDisplayItemClass(solid_color_display_item)) - }); - } - + list.append_item(SolidColorDisplayItemClass(solid_color_display_item)) + }); } - }, - &None => {} - } - }); + + } + }, + &None => {} + } let style = self.style(); let background_color = style.resolve_color(style.Background.background_color); if !background_color.alpha.approx_eq(&0.0) { diff --git a/src/components/main/layout/construct.rs b/src/components/main/layout/construct.rs index 27d350fa62d..017dffecd0b 100644 --- a/src/components/main/layout/construct.rs +++ b/src/components/main/layout/construct.rs @@ -418,39 +418,7 @@ impl<'fc> FlowConstructor<'fc> { match opt_box_accumulator { Some(ref mut boxes) => { - let parent_box = self.build_box_for_node(node); - let font_style = parent_box.font_style(); - let font_group = self.layout_context.font_ctx.get_resolved_font_for_style(&font_style); - let (font_ascent,font_descent) = font_group.borrow().with_mut( |fg| { - fg.fonts[0].borrow().with_mut( |font| { - (font.metrics.ascent,font.metrics.descent) - }) - }); - - for box_ in boxes.mut_iter() { - if box_.inline_info.with( |data| data.is_none() ) { - box_.inline_info.set(Some(InlineInfo::new())); - } - - box_.inline_info.with_mut( |info| { - match info { - &Some(ref mut info) => { - // TODO(ksh8281) compute margin,border,padding - info.parent_info.push( - InlineParentInfo { - padding: Zero::zero(), - border: Zero::zero(), - margin: Zero::zero(), - style: parent_box.style.clone(), - font_ascent: font_ascent, - font_descent: font_descent, - }); - }, - &None => {} - } - }); - - } + self.set_inline_info_for_inline_child(boxes, node) }, None => {} } @@ -467,6 +435,39 @@ impl<'fc> FlowConstructor<'fc> { } } + fn set_inline_info_for_inline_child(&mut self, boxes: &mut ~[Box], parent_node: LayoutNode) { + let parent_box = self.build_box_for_node(parent_node); + let font_style = parent_box.font_style(); + let font_group = self.layout_context.font_ctx.get_resolved_font_for_style(&font_style); + let (font_ascent,font_descent) = font_group.borrow().with_mut( |fg| { + fg.fonts[0].borrow().with_mut( |font| { + (font.metrics.ascent,font.metrics.descent) + }) + }); + + for box_ in boxes.mut_iter() { + if box_.inline_info.with( |data| data.is_none() ) { + box_.inline_info.set(Some(InlineInfo::new())); + } + + let mut info = box_.inline_info.borrow_mut(); + match info.get() { + &Some(ref mut info) => { + // TODO(ksh8281) compute margin,border,padding + info.parent_info.push( + InlineParentInfo { + padding: Zero::zero(), + border: Zero::zero(), + margin: Zero::zero(), + style: parent_box.style.clone(), + font_ascent: font_ascent, + font_descent: font_descent, + }); + }, + &None => {} + } + } + } /// Creates an `InlineBoxesConstructionResult` for replaced content. Replaced content doesn't /// render its children, so this just nukes a child's boxes and creates a `Box`. fn build_boxes_for_replaced_inline_content(&mut self, node: LayoutNode) -> ConstructionResult {