mirror of
https://github.com/servo/servo.git
synced 2025-08-10 07:55:33 +01:00
Make use of generics for transform-origin
This allows us to preserve keywords during serialisation.
This commit is contained in:
parent
b42aaf28df
commit
5d70580813
12 changed files with 241 additions and 221 deletions
|
@ -429,96 +429,6 @@ ${helpers.predefined_type("clip",
|
|||
}
|
||||
</%helpers:longhand>
|
||||
|
||||
pub struct OriginParseResult {
|
||||
pub horizontal: Option<specified::LengthOrPercentage>,
|
||||
pub vertical: Option<specified::LengthOrPercentage>,
|
||||
pub depth: Option<specified::NoCalcLength>
|
||||
}
|
||||
|
||||
pub fn parse_origin(context: &ParserContext, input: &mut Parser) -> Result<OriginParseResult,()> {
|
||||
use values::specified::{LengthOrPercentage, Percentage};
|
||||
let (mut horizontal, mut vertical, mut depth, mut horizontal_is_center) = (None, None, None, false);
|
||||
loop {
|
||||
if let Err(_) = input.try(|input| {
|
||||
let token = try!(input.expect_ident());
|
||||
match_ignore_ascii_case! {
|
||||
&token,
|
||||
"left" => {
|
||||
if horizontal.is_none() {
|
||||
horizontal = Some(LengthOrPercentage::Percentage(Percentage(0.0)))
|
||||
} else if horizontal_is_center && vertical.is_none() {
|
||||
vertical = Some(LengthOrPercentage::Percentage(Percentage(0.5)));
|
||||
horizontal = Some(LengthOrPercentage::Percentage(Percentage(0.0)));
|
||||
} else {
|
||||
return Err(())
|
||||
}
|
||||
},
|
||||
"center" => {
|
||||
if horizontal.is_none() {
|
||||
horizontal_is_center = true;
|
||||
horizontal = Some(LengthOrPercentage::Percentage(Percentage(0.5)))
|
||||
} else if vertical.is_none() {
|
||||
vertical = Some(LengthOrPercentage::Percentage(Percentage(0.5)))
|
||||
} else {
|
||||
return Err(())
|
||||
}
|
||||
},
|
||||
"right" => {
|
||||
if horizontal.is_none() {
|
||||
horizontal = Some(LengthOrPercentage::Percentage(Percentage(1.0)))
|
||||
} else if horizontal_is_center && vertical.is_none() {
|
||||
vertical = Some(LengthOrPercentage::Percentage(Percentage(0.5)));
|
||||
horizontal = Some(LengthOrPercentage::Percentage(Percentage(1.0)));
|
||||
} else {
|
||||
return Err(())
|
||||
}
|
||||
},
|
||||
"top" => {
|
||||
if vertical.is_none() {
|
||||
vertical = Some(LengthOrPercentage::Percentage(Percentage(0.0)))
|
||||
} else {
|
||||
return Err(())
|
||||
}
|
||||
},
|
||||
"bottom" => {
|
||||
if vertical.is_none() {
|
||||
vertical = Some(LengthOrPercentage::Percentage(Percentage(1.0)))
|
||||
} else {
|
||||
return Err(())
|
||||
}
|
||||
},
|
||||
_ => return Err(())
|
||||
}
|
||||
Ok(())
|
||||
}) {
|
||||
match input.try(|input| LengthOrPercentage::parse(context, input)) {
|
||||
Ok(value) => {
|
||||
if horizontal.is_none() {
|
||||
horizontal = Some(value);
|
||||
} else if vertical.is_none() {
|
||||
vertical = Some(value);
|
||||
} else if let LengthOrPercentage::Length(length) = value {
|
||||
depth = Some(length);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
_ => break,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if horizontal.is_some() || vertical.is_some() {
|
||||
Ok(OriginParseResult {
|
||||
horizontal: horizontal,
|
||||
vertical: vertical,
|
||||
depth: depth,
|
||||
})
|
||||
} else {
|
||||
Err(())
|
||||
}
|
||||
}
|
||||
|
||||
${helpers.single_keyword("mix-blend-mode",
|
||||
"""normal multiply screen overlay darken lighten color-dodge
|
||||
color-burn hard-light soft-light difference exclusion hue
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue