mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
style: Add auto-fill length field to line name lists returned from Servo.
Rename fill_idx to fill_start, to indicate it is not a single value but a range. Also change a numeric_limits<>::max() involving the fill_start to use decltype() to ensure its type matches that of the auto-generated structure's field, while we're touching that code. The test to ensure only a single repeat value is allowed will be removed by a later commit. Differential Revision: https://phabricator.services.mozilla.com/D60929
This commit is contained in:
parent
bac5248135
commit
b85b6ac16f
1 changed files with 19 additions and 14 deletions
|
@ -655,8 +655,10 @@ impl<L: ToCss, I: ToCss> ToCss for TrackList<L, I> {
|
|||
pub struct LineNameList {
|
||||
/// The optional `<line-name-list>`
|
||||
pub names: crate::OwnedSlice<crate::OwnedSlice<CustomIdent>>,
|
||||
/// Indicates the line name that requires `auto-fill`, if in bounds.
|
||||
pub fill_idx: usize,
|
||||
/// Indicates the starting line names that requires `auto-fill`, if in bounds.
|
||||
pub fill_start: usize,
|
||||
/// Indicates the number of line names in the auto-fill
|
||||
pub fill_len: usize,
|
||||
}
|
||||
|
||||
impl Parse for LineNameList {
|
||||
|
@ -666,7 +668,7 @@ impl Parse for LineNameList {
|
|||
) -> Result<Self, ParseError<'i>> {
|
||||
input.expect_ident_matching("subgrid")?;
|
||||
let mut line_names = vec![];
|
||||
let mut fill_idx = None;
|
||||
let mut fill_data = None;
|
||||
|
||||
loop {
|
||||
let repeat_parse_result = input.try(|input| {
|
||||
|
@ -682,8 +684,7 @@ impl Parse for LineNameList {
|
|||
Ok((names_list, count))
|
||||
})
|
||||
});
|
||||
|
||||
if let Ok((mut names_list, count)) = repeat_parse_result {
|
||||
if let Ok((names_list, count)) = repeat_parse_result {
|
||||
match count {
|
||||
// FIXME(emilio): we shouldn't expand repeat() at
|
||||
// parse time for subgrid. (bug 1583429)
|
||||
|
@ -694,7 +695,7 @@ impl Parse for LineNameList {
|
|||
.cycle()
|
||||
.take(num.value() as usize * names_list.len()),
|
||||
),
|
||||
RepeatCount::AutoFill if fill_idx.is_none() => {
|
||||
RepeatCount::AutoFill if fill_data.is_none() => {
|
||||
// `repeat(autof-fill, ..)` should have just one line name.
|
||||
// FIXME(bug 1341507) the above comment is wrong per:
|
||||
// https://drafts.csswg.org/css-grid-2/#typedef-name-repeat
|
||||
|
@ -703,10 +704,10 @@ impl Parse for LineNameList {
|
|||
input.new_custom_error(StyleParseErrorKind::UnspecifiedError)
|
||||
);
|
||||
}
|
||||
let names = names_list.pop().unwrap();
|
||||
|
||||
line_names.push(names);
|
||||
fill_idx = Some(line_names.len() - 1);
|
||||
let fill_idx = line_names.len();
|
||||
let fill_len = names_list.len();
|
||||
fill_data = Some((fill_idx, fill_len));
|
||||
line_names.extend(names_list.into_iter());
|
||||
},
|
||||
_ => return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError)),
|
||||
}
|
||||
|
@ -721,9 +722,12 @@ impl Parse for LineNameList {
|
|||
line_names.truncate(MAX_GRID_LINE as usize);
|
||||
}
|
||||
|
||||
let (fill_start, fill_len) = fill_data.unwrap_or((usize::MAX, 0));
|
||||
|
||||
Ok(LineNameList {
|
||||
names: line_names.into(),
|
||||
fill_idx: fill_idx.unwrap_or(usize::MAX),
|
||||
fill_start: fill_start,
|
||||
fill_len: fill_len,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -734,9 +738,10 @@ impl ToCss for LineNameList {
|
|||
W: Write,
|
||||
{
|
||||
dest.write_str("subgrid")?;
|
||||
let fill_idx = self.fill_idx;
|
||||
let fill_start = self.fill_start;
|
||||
let fill_len = self.fill_len;
|
||||
for (i, names) in self.names.iter().enumerate() {
|
||||
if i == fill_idx {
|
||||
if i == fill_start {
|
||||
dest.write_str(" repeat(auto-fill,")?;
|
||||
}
|
||||
|
||||
|
@ -751,7 +756,7 @@ impl ToCss for LineNameList {
|
|||
}
|
||||
|
||||
dest.write_str("]")?;
|
||||
if i == fill_idx {
|
||||
if i == fill_start + fill_len - 1 {
|
||||
dest.write_str(")")?;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue