some refactor & add comment

This commit is contained in:
patrick kim 2014-01-16 09:34:38 +09:00
parent 25a3da6180
commit 6364103d29
2 changed files with 60 additions and 62 deletions

View file

@ -532,10 +532,8 @@ impl Box {
// needed. We could use display list optimization to clean this up, but it still seems // 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 // inefficient. What we really want is something like "nearest ancestor element that
// doesn't have a box". // doesn't have a box".
let info = self.inline_info.borrow();
match info.get() {
self.inline_info.with( |info| {
match info {
&Some(ref box_info) => { &Some(ref box_info) => {
let mut bg_rect = absolute_bounds.clone(); let mut bg_rect = absolute_bounds.clone();
for info in box_info.parent_info.rev_iter() { for info in box_info.parent_info.rev_iter() {
@ -563,7 +561,6 @@ impl Box {
}, },
&None => {} &None => {}
} }
});
let style = self.style(); let style = self.style();
let background_color = style.resolve_color(style.Background.background_color); let background_color = style.resolve_color(style.Background.background_color);
if !background_color.alpha.approx_eq(&0.0) { if !background_color.alpha.approx_eq(&0.0) {

View file

@ -418,39 +418,7 @@ impl<'fc> FlowConstructor<'fc> {
match opt_box_accumulator { match opt_box_accumulator {
Some(ref mut boxes) => { Some(ref mut boxes) => {
let parent_box = self.build_box_for_node(node); self.set_inline_info_for_inline_child(boxes, 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 => {}
}
});
}
}, },
None => {} 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 /// 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`. /// 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 { fn build_boxes_for_replaced_inline_content(&mut self, node: LayoutNode) -> ConstructionResult {