Add new methods to Fragment for size calculation of replaced element

These new methods calculate both the used width and height of an
replaced element and the same time. The `has_intrinsic_ratio()` method
also exposes information about whether a fragment has intrinsic aspect
ratio.
This commit is contained in:
Pu Xingyu 2016-12-11 01:37:48 +08:00
parent 39780e894b
commit d3ab919745
2 changed files with 193 additions and 2 deletions

View file

@ -436,6 +436,21 @@ impl MaybeAuto {
}
}
/// Receive an optional container size and return used value for width or height.
///
/// `style_length`: content size as given in the CSS.
pub fn style_length(style_length: LengthOrPercentageOrAuto,
container_size: Option<Au>) -> MaybeAuto {
match container_size {
Some(length) => MaybeAuto::from_style(style_length, length),
None => if let LengthOrPercentageOrAuto::Length(length) = style_length {
MaybeAuto::Specified(length)
} else {
MaybeAuto::Auto
}
}
}
pub fn specified_or_none(length: LengthOrPercentageOrNone, containing_length: Au) -> Option<Au> {
match length {
LengthOrPercentageOrNone::None => None,