Renaming and refactoring spec_or_default.

`spec_or_default` is now `specified_or_default` and `specified_or_zero` was
added to handle the most common case.
This commit is contained in:
Jack Moffitt 2013-07-18 20:02:22 -06:00
parent 9a1d4d593b
commit 4d1e21bd8e
4 changed files with 19 additions and 15 deletions

View file

@ -134,8 +134,8 @@ impl BlockFlowData {
let (left_margin, right_margin) = match width{
Auto => (left_margin, right_margin),
Specified(width) => {
let left = left_margin.spec_or_default(Au(0));
let right = right_margin.spec_or_default(Au(0));
let left = left_margin.specified_or_zero();
let right = right_margin.specified_or_zero();
if((left + right + width) > available_width) {
(Specified(left), Specified(right))
@ -203,10 +203,10 @@ impl BlockFlowData {
// Top and bottom margins for blocks are 0 if auto.
let margin_top = MaybeAuto::from_margin(style.margin_top(),
remaining_width,
style.font_size()).spec_or_default(Au(0));
style.font_size()).specified_or_zero();
let margin_bottom = MaybeAuto::from_margin(style.margin_bottom(),
remaining_width,
style.font_size()).spec_or_default(Au(0));
style.font_size()).specified_or_zero();
let (width, margin_left, margin_right) =
(MaybeAuto::from_width(style.width(), remaining_width, style.font_size()),
@ -300,7 +300,7 @@ impl BlockFlowData {
for self.box.iter().advance |&box| {
let style = box.style();
let maybe_height = MaybeAuto::from_height(style.height(), Au(0), style.font_size());
let maybe_height = maybe_height.spec_or_default(Au(0));
let maybe_height = maybe_height.specified_or_zero();
height = geometry::max(height, maybe_height);
}

View file

@ -392,13 +392,13 @@ impl RenderBox {
let font_size = style.font_size();
let w = MaybeAuto::from_width(style.width(),
Au(0),
font_size).spec_or_default(Au(0));
font_size).specified_or_zero();
let ml = MaybeAuto::from_margin(style.margin_left(),
Au(0),
font_size).spec_or_default(Au(0));
font_size).specified_or_zero();
let mr = MaybeAuto::from_margin(style.margin_right(),
Au(0),
font_size).spec_or_default(Au(0));
font_size).specified_or_zero();
let pl = base.model.compute_padding_length(style.padding_left(),
Au(0),
font_size);

View file

@ -107,16 +107,16 @@ impl FloatFlowData {
// Margins for floats are 0 if auto.
let margin_top = MaybeAuto::from_margin(style.margin_top(),
remaining_width,
style.font_size()).spec_or_default(Au(0));
style.font_size()).specified_or_zero();
let margin_bottom = MaybeAuto::from_margin(style.margin_bottom(),
remaining_width,
style.font_size()).spec_or_default(Au(0));
style.font_size()).specified_or_zero();
let margin_left = MaybeAuto::from_margin(style.margin_left(),
remaining_width,
style.font_size()).spec_or_default(Au(0));
style.font_size()).specified_or_zero();
let margin_right = MaybeAuto::from_margin(style.margin_right(),
remaining_width,
style.font_size()).spec_or_default(Au(0));
style.font_size()).specified_or_zero();
@ -127,7 +127,7 @@ impl FloatFlowData {
let width = MaybeAuto::from_width(style.width(),
remaining_width,
style.font_size()).spec_or_default(shrink_to_fit);
style.font_size()).specified_or_default(shrink_to_fit);
debug!("assign_widths_float -- width: %?", width);
model.margin.top = margin_top;
@ -205,7 +205,7 @@ impl FloatFlowData {
let height_prop =
MaybeAuto::from_height(box.style().height(),
Au(0),
box.style().font_size()).spec_or_default(Au(0));
box.style().font_size()).specified_or_zero();
height = geometry::max(height, height_prop) + noncontent_height;
debug!("assign_height_float -- height: %?", height);

View file

@ -80,12 +80,16 @@ impl MaybeAuto {
}
}
pub fn spec_or_default(&self, default: Au) -> Au {
pub fn specified_or_default(&self, default: Au) -> Au {
match *self {
Auto => default,
Specified(value) => value,
}
}
pub fn specified_or_zero(&self) -> Au {
self.specified_or_default(Au(0))
}
}
impl Zero for BoxModel {