mirror of
https://github.com/servo/servo.git
synced 2025-08-10 16:05:43 +01:00
style: More cleanups around length parsing and viewport rule parsing.
This commit is contained in:
parent
705ecb4557
commit
846c950b6b
6 changed files with 72 additions and 101 deletions
|
@ -483,36 +483,23 @@ ${helpers.single_keyword("background-origin",
|
|||
}
|
||||
|
||||
pub fn parse(_context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue,()> {
|
||||
let width;
|
||||
if let Ok(value) = input.try(|input| {
|
||||
match input.next() {
|
||||
Err(_) => Err(()),
|
||||
Ok(Token::Ident(ref ident)) if ident.eq_ignore_ascii_case("cover") => {
|
||||
Ok(SpecifiedValue::Cover)
|
||||
}
|
||||
Ok(Token::Ident(ref ident)) if ident.eq_ignore_ascii_case("contain") => {
|
||||
Ok(SpecifiedValue::Contain)
|
||||
}
|
||||
Ok(_) => Err(()),
|
||||
}
|
||||
}) {
|
||||
return Ok(value)
|
||||
} else {
|
||||
width = try!(specified::LengthOrPercentageOrAuto::parse_non_negative(input))
|
||||
if input.try(|input| input.expect_ident_matching("cover")).is_ok() {
|
||||
return Ok(SpecifiedValue::Cover);
|
||||
}
|
||||
|
||||
let height;
|
||||
if let Ok(value) = input.try(|input| {
|
||||
match input.next() {
|
||||
Err(_) => Ok(specified::LengthOrPercentageOrAuto::Auto),
|
||||
Ok(_) => Err(()),
|
||||
}
|
||||
}) {
|
||||
height = value
|
||||
} else {
|
||||
height = try!(specified::LengthOrPercentageOrAuto::parse_non_negative(input));
|
||||
if input.try(|input| input.expect_ident_matching("contain")).is_ok() {
|
||||
return Ok(SpecifiedValue::Contain);
|
||||
}
|
||||
|
||||
let width =
|
||||
try!(specified::LengthOrPercentageOrAuto::parse_non_negative(input));
|
||||
|
||||
let height = if input.is_exhausted() {
|
||||
specified::LengthOrPercentageOrAuto::Auto
|
||||
} else {
|
||||
try!(specified::LengthOrPercentageOrAuto::parse_non_negative(input))
|
||||
};
|
||||
|
||||
Ok(SpecifiedValue::Explicit(ExplicitSize {
|
||||
width: width,
|
||||
height: height,
|
||||
|
|
|
@ -142,7 +142,8 @@ ${helpers.predefined_type("flex-basis",
|
|||
"LengthOrPercentageOrAutoOrContent",
|
||||
"computed::LengthOrPercentageOrAuto::Auto" if product == "gecko" else
|
||||
"computed::LengthOrPercentageOrAutoOrContent::Auto",
|
||||
"parse_non_negative_with_context",
|
||||
"parse_non_negative",
|
||||
needs_context=False,
|
||||
spec="https://drafts.csswg.org/css-flexbox/#flex-basis-property",
|
||||
extra_prefixes="webkit",
|
||||
animatable=True if product == "gecko" else False)}
|
||||
|
|
|
@ -48,13 +48,7 @@
|
|||
|
||||
<%helpers:shorthand name="flex" sub_properties="flex-grow flex-shrink flex-basis" extra_prefixes="webkit"
|
||||
spec="https://drafts.csswg.org/css-flexbox/#flex-property">
|
||||
use parser::Parse;
|
||||
use values::specified::{Number, NoCalcLength};
|
||||
% if product == "gecko":
|
||||
use values::specified::LengthOrPercentageOrAuto;
|
||||
% else:
|
||||
use values::specified::LengthOrPercentageOrAutoOrContent;
|
||||
% endif
|
||||
use values::specified::Number;
|
||||
|
||||
fn parse_flexibility(input: &mut Parser)
|
||||
-> Result<(Number, Option<Number>),()> {
|
||||
|
@ -72,12 +66,7 @@
|
|||
return Ok(Longhands {
|
||||
flex_grow: Number::new(0.0),
|
||||
flex_shrink: Number::new(0.0),
|
||||
% if product == "gecko":
|
||||
flex_basis: LengthOrPercentageOrAuto::Auto
|
||||
% else:
|
||||
flex_basis: LengthOrPercentageOrAutoOrContent::Auto
|
||||
% endif
|
||||
|
||||
flex_basis: longhands::flex_basis::SpecifiedValue::auto(),
|
||||
})
|
||||
}
|
||||
loop {
|
||||
|
@ -89,11 +78,7 @@
|
|||
}
|
||||
}
|
||||
if basis.is_none() {
|
||||
% if product == "gecko":
|
||||
if let Ok(value) = input.try(|i| LengthOrPercentageOrAuto::parse(context, i)) {
|
||||
% else:
|
||||
if let Ok(value) = input.try(|i| LengthOrPercentageOrAutoOrContent::parse(context, i)) {
|
||||
% endif
|
||||
if let Ok(value) = input.try(|input| longhands::flex_basis::parse(context, input)) {
|
||||
basis = Some(value);
|
||||
continue
|
||||
}
|
||||
|
@ -107,21 +92,17 @@
|
|||
Ok(Longhands {
|
||||
flex_grow: grow.unwrap_or(Number::new(1.0)),
|
||||
flex_shrink: shrink.unwrap_or(Number::new(1.0)),
|
||||
% if product == "gecko":
|
||||
flex_basis: basis.unwrap_or(LengthOrPercentageOrAuto::Length(NoCalcLength::zero()))
|
||||
% else:
|
||||
flex_basis: basis.unwrap_or(LengthOrPercentageOrAutoOrContent::Length(NoCalcLength::zero()))
|
||||
% endif
|
||||
flex_basis: basis.unwrap_or(longhands::flex_basis::SpecifiedValue::zero()),
|
||||
})
|
||||
}
|
||||
|
||||
impl<'a> ToCss for LonghandsToSerialize<'a> {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
try!(self.flex_grow.to_css(dest));
|
||||
try!(write!(dest, " "));
|
||||
try!(dest.write_str(" "));
|
||||
|
||||
try!(self.flex_shrink.to_css(dest));
|
||||
try!(write!(dest, " "));
|
||||
try!(dest.write_str(" "));
|
||||
|
||||
self.flex_basis.to_css(dest)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue