Replace IntegerOrAuto with ZIndex

It's its only use.
This commit is contained in:
Anthony Ramine 2018-02-20 10:13:01 +01:00
parent 6a7ae3b12e
commit b44ffcf498
9 changed files with 75 additions and 50 deletions

View file

@ -61,7 +61,8 @@ pub use self::list::ListStyleType;
pub use self::outline::OutlineStyle;
pub use self::rect::LengthOrNumberRect;
pub use self::percentage::Percentage;
pub use self::position::{Position, PositionComponent, GridAutoFlow, GridTemplateAreas};
pub use self::position::{GridAutoFlow, GridTemplateAreas, Position};
pub use self::position::{PositionComponent, ZIndex};
pub use self::pointing::Cursor;
#[cfg(feature = "gecko")]
pub use self::pointing::CursorImage;
@ -518,24 +519,6 @@ impl ToCss for Integer {
}
}
/// <integer> | auto
pub type IntegerOrAuto = Either<Integer, Auto>;
impl IntegerOrAuto {
/// Parse `auto` or a positive integer.
pub fn parse_positive<'i, 't>(
context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<IntegerOrAuto, ParseError<'i>> {
match IntegerOrAuto::parse(context, input) {
Ok(Either::First(integer)) if integer.value() <= 0 => {
Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
}
result => result,
}
}
}
/// A wrapper of Integer, with value >= 1.
pub type PositiveInteger = GreaterThanOrEqualToOne<Integer>;

View file

@ -20,7 +20,8 @@ use values::{Either, None_};
use values::computed::{CalcLengthOrPercentage, LengthOrPercentage as ComputedLengthOrPercentage};
use values::computed::{Context, Percentage, ToComputedValue};
use values::generics::position::Position as GenericPosition;
use values::specified::{AllowQuirks, LengthOrPercentage};
use values::generics::position::ZIndex as GenericZIndex;
use values::specified::{AllowQuirks, Integer, LengthOrPercentage};
use values::specified::transform::OriginComponent;
/// The specified value of a CSS `<position>`
@ -702,3 +703,18 @@ impl GridTemplateAreas {
Either::Second(None_)
}
}
/// A specified value for the `z-index` property.
pub type ZIndex = GenericZIndex<Integer>;
impl Parse for ZIndex {
fn parse<'i, 't>(
context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> {
if input.try(|i| i.expect_ident_matching("auto")).is_ok() {
return Ok(GenericZIndex::Auto);
}
Ok(GenericZIndex::Integer(Integer::parse(context, input)?))
}
}