Skip to content

Commit

Permalink
layout: Clean up inline_metrics_of_block a little.
Browse files Browse the repository at this point in the history
Previously the variable names were a little confusing (ascent was used
for the space_above_baseline in one branch and the and ascent field in
another branch, and was not really the ascent in one). Also add a
small diagram.
  • Loading branch information
jyc committed Jul 5, 2017
1 parent 522d24d commit 7a7dfe4
Showing 1 changed file with 29 additions and 11 deletions.
40 changes: 29 additions & 11 deletions components/layout/fragment.rs
Expand Up @@ -2158,17 +2158,35 @@ impl Fragment {
let block_flow = flow.as_block();
let start_margin = block_flow.fragment.margin.block_start;
let end_margin = block_flow.fragment.margin.block_end;
if style.get_box().overflow_y == overflow_x::T::visible {
if let Some(baseline_offset) = flow.baseline_offset_of_last_line_box_in_flow() {
let ascent = baseline_offset + start_margin;
let space_below_baseline = block_flow.fragment.border_box.size.block -
baseline_offset + end_margin;
return InlineMetrics::new(ascent, space_below_baseline, baseline_offset)
}
}
let ascent = block_flow.fragment.border_box.size.block + end_margin;
let space_above_baseline = start_margin + ascent;
InlineMetrics::new(space_above_baseline, Au(0), ascent)
let border_box_block_size = block_flow.fragment.border_box.size.block;

// --------
// margin
// top -------- + +
// | |
// | |
// A ..pogo.. | + baseline_offset_of_last_line_box_in_flow()
// |
// -------- + border_box_block_size
// margin
// B --------
//
// § 10.8.1 says that the baseline (and thus ascent, which is the
// distance from the baseline to the top) should be A if it has an
// in-flow line box and if overflow: visible, and B otherwise.
let ascent =
match (flow.baseline_offset_of_last_line_box_in_flow(),
style.get_box().overflow_y) {
// Case A
(Some(baseline_offset), overflow_x::T::visible) => baseline_offset,
// Case B
_ => border_box_block_size + end_margin,
};

let space_below_baseline = border_box_block_size + end_margin - ascent;
let space_above_baseline = ascent + start_margin;

InlineMetrics::new(space_above_baseline, space_below_baseline, ascent)
}
}

Expand Down

0 comments on commit 7a7dfe4

Please sign in to comment.