mirror of
https://github.com/servo/servo.git
synced 2025-08-04 13:10:20 +01:00
Auto merge of #16024 - Wafflespeanut:gal, r=Wafflespeanut
Add parsing/serialisation for 'grid-auto-flow' Didn't want the work (and review comments) in #15364 to go wasted. Fixes #15313 <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/16024) <!-- Reviewable:end -->
This commit is contained in:
commit
e2aecc3ed7
2 changed files with 111 additions and 0 deletions
|
@ -322,3 +322,89 @@ ${helpers.predefined_type("object-position",
|
||||||
products="gecko",
|
products="gecko",
|
||||||
boxed=True)}
|
boxed=True)}
|
||||||
% endfor
|
% endfor
|
||||||
|
|
||||||
|
<%helpers:longhand name="grid-auto-flow"
|
||||||
|
spec="https://drafts.csswg.org/css-grid/#propdef-grid-auto-flow"
|
||||||
|
products="none"
|
||||||
|
animatable="False">
|
||||||
|
use std::fmt;
|
||||||
|
use style_traits::ToCss;
|
||||||
|
use values::HasViewportPercentage;
|
||||||
|
use values::computed::ComputedValueAsSpecified;
|
||||||
|
|
||||||
|
pub type SpecifiedValue = computed_value::T;
|
||||||
|
|
||||||
|
pub mod computed_value {
|
||||||
|
#[derive(PartialEq, Clone, Eq, Copy, Debug)]
|
||||||
|
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||||
|
pub enum AutoFlow {
|
||||||
|
Row,
|
||||||
|
Column,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(PartialEq, Clone, Eq, Copy, Debug)]
|
||||||
|
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||||
|
pub struct T {
|
||||||
|
pub autoflow: AutoFlow,
|
||||||
|
pub dense: bool,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
no_viewport_percentage!(SpecifiedValue);
|
||||||
|
impl ComputedValueAsSpecified for SpecifiedValue {}
|
||||||
|
|
||||||
|
impl ToCss for computed_value::T {
|
||||||
|
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||||
|
dest.write_str(match self.autoflow {
|
||||||
|
computed_value::AutoFlow::Column => "column",
|
||||||
|
computed_value::AutoFlow::Row => "row"
|
||||||
|
})?;
|
||||||
|
|
||||||
|
if self.dense { dest.write_str(" dense")?; }
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn get_initial_value() -> computed_value::T {
|
||||||
|
computed_value::T {
|
||||||
|
autoflow: computed_value::AutoFlow::Row,
|
||||||
|
dense: false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// [ row | column ] || dense
|
||||||
|
pub fn parse(_context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
|
||||||
|
use self::computed_value::AutoFlow;
|
||||||
|
|
||||||
|
let mut value = None;
|
||||||
|
let mut dense = false;
|
||||||
|
|
||||||
|
while !input.is_exhausted() {
|
||||||
|
match_ignore_ascii_case! { &input.expect_ident()?,
|
||||||
|
"row" if value.is_none() => {
|
||||||
|
value = Some(AutoFlow::Row);
|
||||||
|
continue
|
||||||
|
},
|
||||||
|
"column" if value.is_none() => {
|
||||||
|
value = Some(AutoFlow::Column);
|
||||||
|
continue
|
||||||
|
},
|
||||||
|
"dense" if !dense => {
|
||||||
|
dense = true;
|
||||||
|
continue
|
||||||
|
},
|
||||||
|
_ => return Err(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if value.is_some() || dense {
|
||||||
|
Ok(computed_value::T {
|
||||||
|
autoflow: value.unwrap_or(AutoFlow::Row),
|
||||||
|
dense: dense,
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
Err(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</%helpers:longhand>
|
||||||
|
|
|
@ -142,3 +142,28 @@ fn test_vertical_position() {
|
||||||
assert!(parse(VerticalPosition::parse, "left right").is_err());
|
assert!(parse(VerticalPosition::parse, "left right").is_err());
|
||||||
assert!(parse(VerticalPosition::parse, "20px 30px").is_err());
|
assert!(parse(VerticalPosition::parse, "20px 30px").is_err());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_grid_auto_flow() {
|
||||||
|
use style::properties::longhands::grid_auto_flow;
|
||||||
|
|
||||||
|
assert_roundtrip_with_context!(grid_auto_flow::parse, "row dense", "row dense");
|
||||||
|
assert_roundtrip_with_context!(grid_auto_flow::parse, "dense row", "row dense");
|
||||||
|
assert_roundtrip_with_context!(grid_auto_flow::parse, "column dense", "column dense");
|
||||||
|
assert_roundtrip_with_context!(grid_auto_flow::parse, "dense column", "column dense");
|
||||||
|
assert_roundtrip_with_context!(grid_auto_flow::parse, "dense", "row dense");
|
||||||
|
assert_roundtrip_with_context!(grid_auto_flow::parse, "row", "row");
|
||||||
|
assert_roundtrip_with_context!(grid_auto_flow::parse, "column", "column");
|
||||||
|
|
||||||
|
// Neither row, column or dense can be repeated
|
||||||
|
assert!(parse(grid_auto_flow::parse, "dense dense").is_err());
|
||||||
|
assert!(parse(grid_auto_flow::parse, "row row").is_err());
|
||||||
|
assert!(parse(grid_auto_flow::parse, "column column").is_err());
|
||||||
|
assert!(parse(grid_auto_flow::parse, "row dense dense").is_err());
|
||||||
|
assert!(parse(grid_auto_flow::parse, "column dense dense").is_err());
|
||||||
|
|
||||||
|
// Only row, column, dense idents are allowed
|
||||||
|
assert!(parse(grid_auto_flow::parse, "dense 1").is_err());
|
||||||
|
assert!(parse(grid_auto_flow::parse, "column 'dense'").is_err());
|
||||||
|
assert!(parse(grid_auto_flow::parse, "column 2px dense").is_err());
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue