mirror of
https://github.com/servo/servo.git
synced 2025-08-08 15:05:35 +01:00
Fix 'grid' shorthand serialization
This commit is contained in:
parent
af96e09c7f
commit
8827cb1440
3 changed files with 41 additions and 20 deletions
|
@ -307,7 +307,9 @@ ${helpers.predefined_type("object-position",
|
||||||
#[derive(PartialEq, Clone, Eq, Copy, Debug)]
|
#[derive(PartialEq, Clone, Eq, Copy, Debug)]
|
||||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||||
pub struct T {
|
pub struct T {
|
||||||
pub autoflow: AutoFlow,
|
// 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<AutoFlow>,
|
||||||
pub dense: bool,
|
pub dense: bool,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -317,7 +319,7 @@ ${helpers.predefined_type("object-position",
|
||||||
|
|
||||||
impl ToCss for computed_value::T {
|
impl ToCss for computed_value::T {
|
||||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||||
dest.write_str(match self.autoflow {
|
dest.write_str(match self.autoflow.unwrap_or(computed_value::AutoFlow::Row) {
|
||||||
computed_value::AutoFlow::Column => "column",
|
computed_value::AutoFlow::Column => "column",
|
||||||
computed_value::AutoFlow::Row => "row"
|
computed_value::AutoFlow::Row => "row"
|
||||||
})?;
|
})?;
|
||||||
|
@ -330,7 +332,8 @@ ${helpers.predefined_type("object-position",
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn get_initial_value() -> computed_value::T {
|
pub fn get_initial_value() -> computed_value::T {
|
||||||
computed_value::T {
|
computed_value::T {
|
||||||
autoflow: computed_value::AutoFlow::Row,
|
// None should resolve to `computed_value::AutoFlow::Row` in layout.
|
||||||
|
autoflow: None,
|
||||||
dense: false
|
dense: false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -367,7 +370,7 @@ ${helpers.predefined_type("object-position",
|
||||||
|
|
||||||
if value.is_some() || dense {
|
if value.is_some() || dense {
|
||||||
Ok(computed_value::T {
|
Ok(computed_value::T {
|
||||||
autoflow: value.unwrap_or(AutoFlow::Row),
|
autoflow: value,
|
||||||
dense: dense,
|
dense: dense,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
|
@ -382,12 +385,12 @@ ${helpers.predefined_type("object-position",
|
||||||
use self::computed_value::AutoFlow;
|
use self::computed_value::AutoFlow;
|
||||||
|
|
||||||
SpecifiedValue {
|
SpecifiedValue {
|
||||||
autoflow:
|
autoflow: Some(
|
||||||
if bits & structs::NS_STYLE_GRID_AUTO_FLOW_ROW as u8 != 0 {
|
if bits & structs::NS_STYLE_GRID_AUTO_FLOW_ROW as u8 != 0 {
|
||||||
AutoFlow::Row
|
AutoFlow::Row
|
||||||
} else {
|
} else {
|
||||||
AutoFlow::Column
|
AutoFlow::Column
|
||||||
},
|
}),
|
||||||
dense:
|
dense:
|
||||||
bits & structs::NS_STYLE_GRID_AUTO_FLOW_DENSE as u8 != 0,
|
bits & structs::NS_STYLE_GRID_AUTO_FLOW_DENSE as u8 != 0,
|
||||||
}
|
}
|
||||||
|
@ -400,7 +403,7 @@ ${helpers.predefined_type("object-position",
|
||||||
use gecko_bindings::structs;
|
use gecko_bindings::structs;
|
||||||
use self::computed_value::AutoFlow;
|
use self::computed_value::AutoFlow;
|
||||||
|
|
||||||
let mut result: u8 = match v.autoflow {
|
let mut result: u8 = match v.autoflow.unwrap_or(AutoFlow::Row) {
|
||||||
AutoFlow::Row => structs::NS_STYLE_GRID_AUTO_FLOW_ROW as u8,
|
AutoFlow::Row => structs::NS_STYLE_GRID_AUTO_FLOW_ROW as u8,
|
||||||
AutoFlow::Column => structs::NS_STYLE_GRID_AUTO_FLOW_COLUMN as u8,
|
AutoFlow::Column => structs::NS_STYLE_GRID_AUTO_FLOW_COLUMN as u8,
|
||||||
};
|
};
|
||||||
|
|
|
@ -437,7 +437,7 @@
|
||||||
|
|
||||||
auto_flow.map(|flow| {
|
auto_flow.map(|flow| {
|
||||||
SpecifiedAutoFlow {
|
SpecifiedAutoFlow {
|
||||||
autoflow: flow,
|
autoflow: Some(flow),
|
||||||
dense: dense,
|
dense: dense,
|
||||||
}
|
}
|
||||||
}).ok_or(StyleParseError::UnspecifiedError.into())
|
}).ok_or(StyleParseError::UnspecifiedError.into())
|
||||||
|
@ -450,10 +450,10 @@
|
||||||
} else if let Ok(rows) = input.try(|i| GridTemplateComponent::parse(context, i)) {
|
} else if let Ok(rows) = input.try(|i| GridTemplateComponent::parse(context, i)) {
|
||||||
temp_rows = rows;
|
temp_rows = rows;
|
||||||
input.expect_delim('/')?;
|
input.expect_delim('/')?;
|
||||||
flow = parse_auto_flow(input, false)?;
|
flow = parse_auto_flow(input, true)?;
|
||||||
auto_cols = grid_auto_columns::parse(context, input).unwrap_or_default();
|
auto_cols = grid_auto_columns::parse(context, input).unwrap_or_default();
|
||||||
} else {
|
} else {
|
||||||
flow = parse_auto_flow(input, true)?;
|
flow = parse_auto_flow(input, false)?;
|
||||||
auto_rows = input.try(|i| grid_auto_rows::parse(context, i)).unwrap_or_default();
|
auto_rows = input.try(|i| grid_auto_rows::parse(context, i)).unwrap_or_default();
|
||||||
input.expect_delim('/')?;
|
input.expect_delim('/')?;
|
||||||
temp_cols = GridTemplateComponent::parse(context, input)?;
|
temp_cols = GridTemplateComponent::parse(context, input)?;
|
||||||
|
@ -474,28 +474,39 @@
|
||||||
|
|
||||||
impl<'a> ToCss for LonghandsToSerialize<'a> {
|
impl<'a> ToCss for LonghandsToSerialize<'a> {
|
||||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||||
if let Either::First(_) = *self.grid_template_areas {
|
if self.grid_auto_flow.autoflow.is_none() {
|
||||||
super::grid_template::serialize_grid_template(self.grid_template_rows,
|
return super::grid_template::serialize_grid_template(self.grid_template_rows,
|
||||||
self.grid_template_columns,
|
self.grid_template_columns,
|
||||||
self.grid_template_areas, dest)
|
self.grid_template_areas, dest);
|
||||||
} else if self.grid_auto_flow.autoflow == AutoFlow::Row {
|
}
|
||||||
|
|
||||||
|
// This unwrap is safe because we checked the None part in previous if condition.
|
||||||
|
if self.grid_auto_flow.autoflow.unwrap() == AutoFlow::Row {
|
||||||
self.grid_template_rows.to_css(dest)?;
|
self.grid_template_rows.to_css(dest)?;
|
||||||
dest.write_str(" / auto-flow")?;
|
dest.write_str(" / auto-flow")?;
|
||||||
if self.grid_auto_flow.dense {
|
if self.grid_auto_flow.dense {
|
||||||
dest.write_str(" dense")?;
|
dest.write_str(" dense")?;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.grid_auto_columns.to_css(dest)
|
if !self.grid_auto_columns.is_default() {
|
||||||
|
dest.write_str(" ")?;
|
||||||
|
self.grid_auto_columns.to_css(dest)?;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
dest.write_str("auto-flow ")?;
|
dest.write_str("auto-flow")?;
|
||||||
if self.grid_auto_flow.dense {
|
if self.grid_auto_flow.dense {
|
||||||
dest.write_str("dense ")?;
|
dest.write_str(" dense")?;
|
||||||
|
}
|
||||||
|
|
||||||
|
if !self.grid_auto_rows.is_default() {
|
||||||
|
dest.write_str(" ")?;
|
||||||
|
self.grid_auto_rows.to_css(dest)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.grid_auto_rows.to_css(dest)?;
|
|
||||||
dest.write_str(" / ")?;
|
dest.write_str(" / ")?;
|
||||||
self.grid_template_columns.to_css(dest)
|
self.grid_template_columns.to_css(dest)?;
|
||||||
}
|
}
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</%helpers:shorthand>
|
</%helpers:shorthand>
|
||||||
|
|
|
@ -252,6 +252,13 @@ impl<L> Default for TrackSize<L> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<L: PartialEq> TrackSize<L> {
|
||||||
|
/// Returns true if current TrackSize is same as default.
|
||||||
|
pub fn is_default(&self) -> bool {
|
||||||
|
*self == TrackSize::default()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<L: ToCss> ToCss for TrackSize<L> {
|
impl<L: ToCss> ToCss for TrackSize<L> {
|
||||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||||
match *self {
|
match *self {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue