diff --git a/components/style/properties/longhand/position.mako.rs b/components/style/properties/longhand/position.mako.rs index bcf6d110fce..526c62e4ceb 100644 --- a/components/style/properties/longhand/position.mako.rs +++ b/components/style/properties/longhand/position.mako.rs @@ -307,9 +307,7 @@ ${helpers.predefined_type("object-position", #[derive(PartialEq, Clone, Eq, Copy, Debug)] #[cfg_attr(feature = "servo", derive(HeapSizeOf))] pub struct T { - // This needs to be an Option because we need an indicator to determine whether this property is - // parsed or not in `grid` shorthand. Otherwise we can't properly serialize it. - pub autoflow: Option, + pub autoflow: AutoFlow, pub dense: bool, } } @@ -319,7 +317,7 @@ ${helpers.predefined_type("object-position", impl ToCss for computed_value::T { fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { - dest.write_str(match self.autoflow.unwrap_or(computed_value::AutoFlow::Row) { + dest.write_str(match self.autoflow { computed_value::AutoFlow::Column => "column", computed_value::AutoFlow::Row => "row" })?; @@ -332,9 +330,8 @@ ${helpers.predefined_type("object-position", #[inline] pub fn get_initial_value() -> computed_value::T { computed_value::T { - // None should resolve to `computed_value::AutoFlow::Row` in layout. - autoflow: None, - dense: false + autoflow: computed_value::AutoFlow::Row, + dense: false, } } @@ -370,7 +367,7 @@ ${helpers.predefined_type("object-position", if value.is_some() || dense { Ok(computed_value::T { - autoflow: value, + autoflow: value.unwrap_or(AutoFlow::Row), dense: dense, }) } else { @@ -385,12 +382,12 @@ ${helpers.predefined_type("object-position", use self::computed_value::AutoFlow; SpecifiedValue { - autoflow: Some( + autoflow: if bits & structs::NS_STYLE_GRID_AUTO_FLOW_ROW as u8 != 0 { AutoFlow::Row } else { AutoFlow::Column - }), + }, dense: bits & structs::NS_STYLE_GRID_AUTO_FLOW_DENSE as u8 != 0, } @@ -403,7 +400,7 @@ ${helpers.predefined_type("object-position", use gecko_bindings::structs; use self::computed_value::AutoFlow; - let mut result: u8 = match v.autoflow.unwrap_or(AutoFlow::Row) { + let mut result: u8 = match v.autoflow { AutoFlow::Row => structs::NS_STYLE_GRID_AUTO_FLOW_ROW as u8, AutoFlow::Column => structs::NS_STYLE_GRID_AUTO_FLOW_COLUMN as u8, }; diff --git a/components/style/properties/shorthand/position.mako.rs b/components/style/properties/shorthand/position.mako.rs index a862cc20e04..55f8c84555e 100644 --- a/components/style/properties/shorthand/position.mako.rs +++ b/components/style/properties/shorthand/position.mako.rs @@ -460,7 +460,7 @@ auto_flow.map(|flow| { SpecifiedAutoFlow { - autoflow: Some(flow), + autoflow: flow, dense: dense, } }).ok_or(StyleParseError::UnspecifiedError.into()) @@ -473,10 +473,10 @@ } else if let Ok(rows) = input.try(|i| GridTemplateComponent::parse(context, i)) { temp_rows = rows; input.expect_delim('/')?; - flow = parse_auto_flow(input, true)?; + flow = parse_auto_flow(input, false)?; auto_cols = grid_auto_columns::parse(context, input).unwrap_or_default(); } else { - flow = parse_auto_flow(input, false)?; + flow = parse_auto_flow(input, true)?; auto_rows = input.try(|i| grid_auto_rows::parse(context, i)).unwrap_or_default(); input.expect_delim('/')?; temp_cols = GridTemplateComponent::parse(context, input)?; @@ -495,16 +495,30 @@ }) } + /// Returns true if every sub property value of `grid` shorthand is initial. + impl<'a> LonghandsToSerialize<'a> { + fn is_initial(&self) -> bool { + *self.grid_template_rows == GridTemplateComponent::None && + *self.grid_template_columns == GridTemplateComponent::None && + *self.grid_template_areas == Either::Second(None_) && + *self.grid_auto_rows == TrackSize::default() && + *self.grid_auto_columns == TrackSize::default() && + *self.grid_auto_flow == grid_auto_flow::get_initial_value() + } + } + impl<'a> ToCss for LonghandsToSerialize<'a> { fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { - if self.grid_auto_flow.autoflow.is_none() { + if *self.grid_template_areas != Either::Second(None_) || + (*self.grid_template_rows != GridTemplateComponent::None && + *self.grid_template_columns != GridTemplateComponent::None) || + self.is_initial() { return super::grid_template::serialize_grid_template(self.grid_template_rows, self.grid_template_columns, self.grid_template_areas, dest); } - // This unwrap is safe because we checked the None part in previous if condition. - if self.grid_auto_flow.autoflow.unwrap() == AutoFlow::Row { + if self.grid_auto_flow.autoflow == AutoFlow::Column { self.grid_template_rows.to_css(dest)?; dest.write_str(" / auto-flow")?; if self.grid_auto_flow.dense {