Parse perspective property as non negative and add tests

This commit is contained in:
n0max 2017-03-26 23:15:04 +02:00
parent c5c4354f84
commit 20c07332a1
4 changed files with 50 additions and 0 deletions

View file

@ -1711,6 +1711,7 @@ ${helpers.single_keyword("resize",
${helpers.predefined_type("perspective",
"LengthOrNone",
"Either::Second(None_)",
"parse_non_negative_length",
gecko_ffi_name="mChildPerspective",
spec="https://drafts.csswg.org/css-transforms/#perspective",
extra_prefixes="moz webkit",

View file

@ -458,6 +458,17 @@ impl Parse for Length {
}
}
impl Either<Length, None_> {
/// Parse a non-negative length or none
#[inline]
pub fn parse_non_negative_length(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
if input.try(|input| None_::parse(context, input)).is_ok() {
return Ok(Either::Second(None_));
}
Length::parse_non_negative(input).map(Either::First)
}
}
impl Either<Length, Normal> {
#[inline]
#[allow(missing_docs)]

View file

@ -11100,6 +11100,12 @@
{}
]
],
"css/perspective.html": [
[
"/_mozilla/css/perspective.html",
{}
]
],
"css/stylesheet_media_queries.html": [
[
"/_mozilla/css/stylesheet_media_queries.html",
@ -22741,6 +22747,10 @@
"001acfd664f89e45ab321bf549803ca24d44e098",
"support"
],
"css/perspective.html": [
"6d455ef4b9c815d89917f496999268d7410cfa62",
"testharness"
],
"css/perspective_zero.html": [
"bcb877f51808e896d8024877f945ce289dbc6b36",
"reftest"

View file

@ -0,0 +1,28 @@
<!doctype html>
<meta charset="utf-8">
<title>CSS Test: parsing perspective property</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="test"></div>
<script>
test(function () {
var test = document.getElementById('test');
var tests = [
["none", "none"],
["0px", "0px"],
["100px", "100px"],
["-200px", ""],
["300PX", "300px"],
];
for (var i = 0; i < tests.length; ++i) {
var specified = tests[i][0];
var expected = tests[i][1];
test.style.perspective = specified;
assert_equals(test.style.perspective, expected);
test.style.perspective = '';
}
}, "Parsing of the perspective property");
</script>