style: Make 'grid-area'/'grid-column'/'grid-row' shorthands serialize to shortest possible form.

Differential Revision: https://phabricator.services.mozilla.com/D54386
This commit is contained in:
Mats Palmgren 2019-11-23 21:24:33 +00:00 committed by Emilio Cobos Álvarez
parent 70ec6ffe36
commit 4359b3bd47
No known key found for this signature in database
GPG key ID: E1152D0994E4BF8A
2 changed files with 55 additions and 4 deletions

View file

@ -58,7 +58,7 @@ pub use self::GenericGridLine as GridLine;
impl<Integer> GridLine<Integer>
where
Integer: Zero,
Integer: PartialEq + Zero,
{
/// The `auto` value.
pub fn auto() -> Self {
@ -73,11 +73,27 @@ where
pub fn is_auto(&self) -> bool {
self.ident == atom!("") && self.line_num.is_zero() && !self.is_span
}
/// Check whether this `<grid-line>` represents a `<custom-ident>` value.
pub fn is_ident_only(&self) -> bool {
self.ident != atom!("") && self.line_num.is_zero() && !self.is_span
}
/// Check if `self` makes `other` omittable according to the rules at:
/// https://drafts.csswg.org/css-grid/#propdef-grid-column
/// https://drafts.csswg.org/css-grid/#propdef-grid-area
pub fn can_omit(&self, other: &Self) -> bool {
if self.is_ident_only() {
self == other
} else {
other.is_auto()
}
}
}
impl<Integer> ToCss for GridLine<Integer>
where
Integer: ToCss + Zero,
Integer: ToCss + PartialEq + Zero,
{
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
where