Skip to content

Commit

Permalink
some refactor & add comment
Browse files Browse the repository at this point in the history
  • Loading branch information
ksh8281 committed Jan 16, 2014
1 parent 25a3da6 commit 6364103
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 63 deletions.
57 changes: 27 additions & 30 deletions src/components/main/layout/box_.rs
Expand Up @@ -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) {
Expand Down
67 changes: 34 additions & 33 deletions src/components/main/layout/construct.rs
Expand Up @@ -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 => {}
}
Expand All @@ -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 {
Expand Down

9 comments on commit 6364103

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from pcwalton
at ksh8281@6364103

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging ksh8281/servo/inline_add = 6364103 into auto

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ksh8281/servo/inline_add = 6364103 merged ok, testing candidate = fe3ad8f

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from pcwalton
at ksh8281@6364103

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging ksh8281/servo/inline_add = 6364103 into auto

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ksh8281/servo/inline_add = 6364103 merged ok, testing candidate = 87b25f9

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 87b25f9

Please sign in to comment.