mirror of
https://github.com/servo/servo.git
synced 2025-08-04 13:10:20 +01:00
some refactor & add comment
This commit is contained in:
parent
25a3da6180
commit
6364103d29
2 changed files with 60 additions and 62 deletions
|
@ -532,38 +532,35 @@ 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() {
|
||||||
|
&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| {
|
list.append_item(SolidColorDisplayItemClass(solid_color_display_item))
|
||||||
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))
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
},
|
|
||||||
&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) {
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue