Implement a MinLength type

Implement an ExtremumLength type which contains all the enumerated
keyword values for min-width, min-height, max-width, and
max-height. Then, implement a MinLength which can be used for min-width
and min-height. So far this just maps to Gecko values.

Refs #13821.
This commit is contained in:
Ethan Glasser-Camp 2016-11-30 16:14:47 -05:00
parent 063aec5ade
commit 76de979231
9 changed files with 199 additions and 10 deletions

View file

@ -18,6 +18,7 @@ use style_traits::ToCss;
use style_traits::values::specified::AllowedNumericType;
use super::{Angle, Number, SimplifiedValueNode, SimplifiedSumNode, Time};
use values::{Auto, CSSFloat, Either, FONT_MEDIUM_PX, HasViewportPercentage, None_, Normal};
use values::ExtremumLength;
use values::computed::Context;
pub use super::image::{AngleOrCorner, ColorStop, EndingShape as GradientEndingShape, Gradient};
@ -1304,3 +1305,51 @@ impl LengthOrNumber {
}
}
}
/// A value suitable for a `min-width` or `min-height` property.
/// Unlike `max-width` or `max-height` properties, a MinLength can be
/// `auto`, and cannot be `none`.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
#[allow(missing_docs)]
pub enum MinLength {
LengthOrPercentage(LengthOrPercentage),
Auto,
ExtremumLength(ExtremumLength),
}
impl HasViewportPercentage for MinLength {
fn has_viewport_percentage(&self) -> bool {
match *self {
MinLength::LengthOrPercentage(ref lop) => lop.has_viewport_percentage(),
_ => false
}
}
}
impl ToCss for MinLength {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
match *self {
MinLength::LengthOrPercentage(ref lop) =>
lop.to_css(dest),
MinLength::Auto =>
dest.write_str("auto"),
MinLength::ExtremumLength(ref ext) =>
ext.to_css(dest),
}
}
}
impl Parse for MinLength {
fn parse(_context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
input.try(ExtremumLength::parse).map(MinLength::ExtremumLength)
.or_else(|()| input.try(LengthOrPercentage::parse_non_negative).map(MinLength::LengthOrPercentage))
.or_else(|()| {
match_ignore_ascii_case! { try!(input.expect_ident()),
"auto" =>
Ok(MinLength::Auto),
_ => Err(())
}
})
}
}