mirror of
https://github.com/servo/servo.git
synced 2025-06-28 02:53:48 +01:00
Add tests and small fixes for flexbox shorthands
This commit is contained in:
parent
7badba01ea
commit
595eed166f
21 changed files with 22 additions and 129 deletions
|
@ -4,49 +4,47 @@
|
||||||
|
|
||||||
<%namespace name="helpers" file="/helpers.mako.rs" />
|
<%namespace name="helpers" file="/helpers.mako.rs" />
|
||||||
|
|
||||||
|
// https://drafts.csswg.org/css-flexbox/#flex-flow-property
|
||||||
<%helpers:shorthand name="flex-flow" sub_properties="flex-direction flex-wrap"
|
<%helpers:shorthand name="flex-flow" sub_properties="flex-direction flex-wrap"
|
||||||
experimental="True">
|
experimental="True">
|
||||||
use properties::longhands::{flex_direction, flex_wrap};
|
use properties::longhands::{flex_direction, flex_wrap};
|
||||||
|
|
||||||
let mut direction = None;
|
let mut direction = None;
|
||||||
let mut wrap = None;
|
let mut wrap = None;
|
||||||
let mut any = false;
|
|
||||||
loop {
|
loop {
|
||||||
if direction.is_none() {
|
if direction.is_none() {
|
||||||
if let Ok(value) = input.try(|input| flex_direction::parse(context, input)) {
|
if let Ok(value) = input.try(|input| flex_direction::parse(context, input)) {
|
||||||
direction = Some(value);
|
direction = Some(value);
|
||||||
any = true;
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if wrap.is_none() {
|
if wrap.is_none() {
|
||||||
if let Ok(value) = input.try(|input| flex_wrap::parse(context, input)) {
|
if let Ok(value) = input.try(|input| flex_wrap::parse(context, input)) {
|
||||||
wrap = Some(value);
|
wrap = Some(value);
|
||||||
any = true;
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
if any {
|
if direction.is_none() && wrap.is_none() {
|
||||||
Ok(Longhands {
|
return Err(())
|
||||||
flex_direction: direction,
|
|
||||||
flex_wrap: wrap,
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
Err(())
|
|
||||||
}
|
}
|
||||||
|
Ok(Longhands {
|
||||||
|
flex_direction: direction,
|
||||||
|
flex_wrap: wrap,
|
||||||
|
})
|
||||||
</%helpers:shorthand>
|
</%helpers:shorthand>
|
||||||
|
|
||||||
|
// https://drafts.csswg.org/css-flexbox/#flex-property
|
||||||
<%helpers:shorthand name="flex" sub_properties="flex-grow flex-shrink flex-basis"
|
<%helpers:shorthand name="flex" sub_properties="flex-grow flex-shrink flex-basis"
|
||||||
experimental="True">
|
experimental="True">
|
||||||
use app_units::Au;
|
use app_units::Au;
|
||||||
use values::specified::{Number, Length, LengthOrPercentageOrAutoOrContent};
|
use values::specified::{Number, Length, LengthOrPercentageOrAutoOrContent};
|
||||||
|
|
||||||
pub fn parse_flexibility(input: &mut Parser)
|
pub fn parse_flexibility(input: &mut Parser)
|
||||||
-> Result<(Option<Number>, Option<Number>),()> {
|
-> Result<(Number, Option<Number>),()> {
|
||||||
let grow = Some(try!(Number::parse_non_negative(input)));
|
let grow = try!(Number::parse_non_negative(input));
|
||||||
let shrink = input.try(Number::parse_non_negative).ok();
|
let shrink = input.try(Number::parse_non_negative).ok();
|
||||||
Ok((grow, shrink))
|
Ok((grow, shrink))
|
||||||
}
|
}
|
||||||
|
@ -54,7 +52,6 @@
|
||||||
let mut grow = None;
|
let mut grow = None;
|
||||||
let mut shrink = None;
|
let mut shrink = None;
|
||||||
let mut basis = None;
|
let mut basis = None;
|
||||||
let mut any = false;
|
|
||||||
|
|
||||||
if input.try(|input| input.expect_ident_matching("none")).is_ok() {
|
if input.try(|input| input.expect_ident_matching("none")).is_ok() {
|
||||||
return Ok(Longhands {
|
return Ok(Longhands {
|
||||||
|
@ -66,40 +63,26 @@
|
||||||
loop {
|
loop {
|
||||||
if grow.is_none() {
|
if grow.is_none() {
|
||||||
if let Ok((flex_grow, flex_shrink)) = input.try(parse_flexibility) {
|
if let Ok((flex_grow, flex_shrink)) = input.try(parse_flexibility) {
|
||||||
grow = flex_grow;
|
grow = Some(flex_grow);
|
||||||
shrink = flex_shrink;
|
shrink = flex_shrink;
|
||||||
any = true;
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if basis.is_none() {
|
if basis.is_none() {
|
||||||
if let Ok(value) = input.try(LengthOrPercentageOrAutoOrContent::parse) {
|
if let Ok(value) = input.try(LengthOrPercentageOrAutoOrContent::parse) {
|
||||||
basis = Some(value);
|
basis = Some(value);
|
||||||
any = true;
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
if any {
|
|
||||||
if grow == None {
|
if grow.is_none() && basis.is_none() {
|
||||||
grow = Some(Number(1.0));
|
return Err(())
|
||||||
}
|
|
||||||
if shrink == None && basis == None {
|
|
||||||
basis = Some(LengthOrPercentageOrAutoOrContent::Length(Length::Absolute(Au(0))));
|
|
||||||
}
|
|
||||||
if shrink == None {
|
|
||||||
shrink = Some(Number(1.0));
|
|
||||||
}
|
|
||||||
if basis == None {
|
|
||||||
basis = Some(LengthOrPercentageOrAutoOrContent::Auto);
|
|
||||||
}
|
|
||||||
Ok(Longhands {
|
|
||||||
flex_grow: grow,
|
|
||||||
flex_shrink: shrink,
|
|
||||||
flex_basis: basis,
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
Err(())
|
|
||||||
}
|
}
|
||||||
|
Ok(Longhands {
|
||||||
|
flex_grow: grow.or(Some(Number(1.0))),
|
||||||
|
flex_shrink: shrink.or(Some(Number(1.0))),
|
||||||
|
flex_basis: basis.or(Some(LengthOrPercentageOrAutoOrContent::Length(Length::Absolute(Au(0)))))
|
||||||
|
})
|
||||||
</%helpers:shorthand>
|
</%helpers:shorthand>
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
[css-flexbox-column-reverse.htm]
|
||||||
|
type: reftest
|
||||||
|
expected: FAIL
|
|
@ -1,5 +0,0 @@
|
||||||
[flexbox_computedstyle_flex-flow-column-nowrap.htm]
|
|
||||||
type: testharness
|
|
||||||
[flexbox | computed style | flex-flow: column nowrap]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
[flexbox_computedstyle_flex-flow-column-reverse-nowrap.htm]
|
|
||||||
type: testharness
|
|
||||||
[flexbox | computed style | flex-flow: column-reverse nowrap]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
[flexbox_computedstyle_flex-flow-column-reverse-wrap.htm]
|
|
||||||
type: testharness
|
|
||||||
[flexbox | computed style | flex-flow: column-reverse wrap]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
[flexbox_computedstyle_flex-flow-column-reverse.htm]
|
|
||||||
type: testharness
|
|
||||||
[flexbox | computed style | flex-flow: column-reverse]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
[flexbox_computedstyle_flex-flow-column-wrap-reverse.htm]
|
|
||||||
type: testharness
|
|
||||||
[flexbox | computed style | flex-flow: column wrap-reverse]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
[flexbox_computedstyle_flex-flow-column-wrap.htm]
|
|
||||||
type: testharness
|
|
||||||
[flexbox | computed style | flex-flow: column wrap]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
[flexbox_computedstyle_flex-flow-column.htm]
|
|
||||||
type: testharness
|
|
||||||
[flexbox | computed style | flex-flow: column]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
[flexbox_computedstyle_flex-flow-row-reverse-nowrap.htm]
|
|
||||||
type: testharness
|
|
||||||
[flexbox | computed style | flex-flow: row-reverse nowrap]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
[flexbox_computedstyle_flex-flow-row-reverse-wrap-reverse.htm]
|
|
||||||
type: testharness
|
|
||||||
[flexbox | computed style | flex-flow: row-reverse wrap-reverse]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
[flexbox_computedstyle_flex-flow-row-reverse-wrap.htm]
|
|
||||||
type: testharness
|
|
||||||
[flexbox | computed style | flex-flow: row-reverse wrap]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
[flexbox_computedstyle_flex-flow-row-reverse.htm]
|
|
||||||
type: testharness
|
|
||||||
[flexbox | computed style | flex-flow: row-reverse]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
[flexbox_computedstyle_flex-flow-row-wrap-reverse.htm]
|
|
||||||
type: testharness
|
|
||||||
[flexbox | computed style | flex-flow: row wrap-reverse]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
[flexbox_computedstyle_flex-flow-row-wrap.htm]
|
|
||||||
type: testharness
|
|
||||||
[flexbox | computed style | flex-flow: row wrap]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
[flexbox_computedstyle_flex-flow-wrap.htm]
|
|
||||||
type: testharness
|
|
||||||
[flexbox | computed style | flex-flow: wrap]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
[flexbox_computedstyle_flex-shorthand-auto.htm]
|
|
||||||
type: testharness
|
|
||||||
[flexbox | computed style | flex: auto]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
[flexbox_computedstyle_flex-shorthand-none.htm]
|
|
||||||
type: testharness
|
|
||||||
[flexbox | computed style | flex: auto]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
[flexbox_computedstyle_flex-shorthand-number.htm]
|
|
||||||
type: testharness
|
|
||||||
[flexbox | computed style | flex: number]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
[flexbox_computedstyle_flex-shorthand.htm]
|
|
||||||
type: testharness
|
|
||||||
[flexbox | computed style | flex: invalid]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -9,9 +9,6 @@
|
||||||
[.flexbox 3]
|
[.flexbox 3]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[.flexbox 4]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[.flexbox 5]
|
[.flexbox 5]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue