Use CustomIdent in GridLine

This commit is contained in:
Anthony Ramine 2017-06-15 12:14:17 +02:00
parent ad79a19587
commit 9f03553ed5
2 changed files with 7 additions and 9 deletions

View file

@ -1190,8 +1190,8 @@ fn static_assert() {
pub fn set_${value.name}(&mut self, v: longhands::${value.name}::computed_value::T) { pub fn set_${value.name}(&mut self, v: longhands::${value.name}::computed_value::T) {
use gecko_bindings::structs::{nsStyleGridLine_kMinLine, nsStyleGridLine_kMaxLine}; use gecko_bindings::structs::{nsStyleGridLine_kMinLine, nsStyleGridLine_kMaxLine};
let ident = v.ident.unwrap_or(String::new()); let ident = v.ident.as_ref().map_or(&[] as &[_], |ident| ident.0.as_slice());
self.gecko.${value.gecko}.mLineName.assign_utf8(&ident); self.gecko.${value.gecko}.mLineName.assign(ident);
self.gecko.${value.gecko}.mHasSpan = v.is_span; self.gecko.${value.gecko}.mHasSpan = v.is_span;
self.gecko.${value.gecko}.mInteger = v.line_num.map(|i| { self.gecko.${value.gecko}.mInteger = v.line_num.map(|i| {
// clamping the integer between a range // clamping the integer between a range

View file

@ -24,7 +24,7 @@ pub struct GridLine {
/// A custom identifier for named lines. /// A custom identifier for named lines.
/// ///
/// https://drafts.csswg.org/css-grid/#grid-placement-slot /// https://drafts.csswg.org/css-grid/#grid-placement-slot
pub ident: Option<String>, pub ident: Option<CustomIdent>,
/// Denotes the nth grid line from grid item's placement. /// Denotes the nth grid line from grid item's placement.
pub line_num: Option<Integer>, pub line_num: Option<Integer>,
} }
@ -62,7 +62,7 @@ impl ToCss for GridLine {
if let Some(ref s) = self.ident { if let Some(ref s) = self.ident {
dest.write_str(" ")?; dest.write_str(" ")?;
serialize_identifier(s, dest)?; s.to_css(dest)?;
} }
Ok(()) Ok(())
@ -100,12 +100,10 @@ impl Parse for GridLine {
grid_line.line_num = Some(i); grid_line.line_num = Some(i);
} else if let Ok(name) = input.try(|i| i.expect_ident()) { } else if let Ok(name) = input.try(|i| i.expect_ident()) {
if val_before_span || grid_line.ident.is_some() || if val_before_span || grid_line.ident.is_some() {
CustomIdent::from_ident((&*name).into(), &[]).is_err() { return Err(StyleParseError::UnspecifiedError.into());
return Err(StyleParseError::UnspecifiedError.into())
} }
grid_line.ident = Some(CustomIdent::from_ident(name, &[])?);
grid_line.ident = Some(name.into_owned());
} else { } else {
break break
} }