From d6f4c8c6dd75b187d2c92eb7409a5a67534ac45e Mon Sep 17 00:00:00 2001 From: tamamu Date: Mon, 10 Apr 2017 02:58:02 +0900 Subject: [PATCH 1/6] Add place-content shorthand property --- .../properties/shorthand/position.mako.rs | 49 +++++++++++++++++++ tests/unit/style/properties/serialization.rs | 17 +++++++ 2 files changed, 66 insertions(+) diff --git a/components/style/properties/shorthand/position.mako.rs b/components/style/properties/shorthand/position.mako.rs index 3d4009d750f..0f4a97528bd 100644 --- a/components/style/properties/shorthand/position.mako.rs +++ b/components/style/properties/shorthand/position.mako.rs @@ -137,3 +137,52 @@ } + +<%helpers:shorthand name="place-content" sub_properties="align-content justify-content" + spec="https://drafts.csswg.org/css-align/#propdef-place-content" + products="gecko"> + use properties::longhands::align_content; + use properties::longhands::justify_content; + +% if product == "servo": + impl From for justify_content::SpecifiedValue { + fn from(align: align_content::SpecifiedValue) -> + justify_content::SpecifiedValue { + match align { + align_content::SpecifiedValue::stretch => + justify_content::SpecifiedValue::stretch, + align_content::SpecifiedValue::flex_start => + justify_content::SpecifiedValue::flex_start, + align_content::SpecifiedValue::flex_end => + justify_content::SpecifiedValue::flex_end, + align_content::SpecifiedValue::center => + justify_content::SpecifiedValue::center, + align_content::SpecifiedValue::space_between => + justify_content::SpecifiedValue::space_between, + align_content::SpecifiedValue::space_around => + justify_content::SpecifiedValue::space_around, + } + } + } +% endif + + pub fn parse_value(context: &ParserContext, input: &mut Parser) -> Result { + let align = align_content::parse(context, input)?; + let justify = input.try(|input| justify_content::parse(context, input)) + .unwrap_or(justify_content::SpecifiedValue::from(align)); + + Ok(Longhands { + align_content: align, + justify_content: justify, + }) + } + + impl<'a> ToCss for LonghandsToSerialize<'a> { + fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + self.align_content.to_css(dest)?; + dest.write_str(" ")?; + self.justify_content.to_css(dest) + } + } + + diff --git a/tests/unit/style/properties/serialization.rs b/tests/unit/style/properties/serialization.rs index 535a52daa6d..112fb97e0c6 100644 --- a/tests/unit/style/properties/serialization.rs +++ b/tests/unit/style/properties/serialization.rs @@ -1246,4 +1246,21 @@ mod shorthand_serialization { assert_eq!(counter_increment.to_css_string(), counter_increment_css); } } + + #[test] + fn place_content_serialize_all_available_properties() { + use style::properties::longhands::align_content::SpecifiedValue as AlignContent; + use style::properties::longhands::justify_content::SpecifiedValue as JustifyContent; + + let mut properties = Vec::new(); + + let align = AlignContent::stretch; + let justify = JustifyContent::center; + + properties.push(PropertyDeclaration::AlignContent(align)); + properties.push(PropertyDeclaration::JustifyContent(justify)); + + let serialization = shorthand_properties_to_string(properties); + assert_eq!(serialization, "place-content: stretch center;"); + } } From b6cbd31b7303189eb29e7ef65692a2871046017e Mon Sep 17 00:00:00 2001 From: tamamu Date: Mon, 10 Apr 2017 03:16:04 +0900 Subject: [PATCH 2/6] Add place-self shorthand property (it fails unit-test) --- .../properties/shorthand/position.mako.rs | 24 +++++++++++++++++++ tests/unit/style/properties/serialization.rs | 17 +++++++++++++ 2 files changed, 41 insertions(+) diff --git a/components/style/properties/shorthand/position.mako.rs b/components/style/properties/shorthand/position.mako.rs index 0f4a97528bd..9acbd9047db 100644 --- a/components/style/properties/shorthand/position.mako.rs +++ b/components/style/properties/shorthand/position.mako.rs @@ -186,3 +186,27 @@ } +<%helpers:shorthand name="place-self" sub_properties="align-self justify-self" + spec="https://drafts.csswg.org/css-align/#place-self-property" + products="gecko"> + use values::specified::align::AlignJustifySelf; + use parser::Parse; + + pub fn parse_value(context: &ParserContext, input: &mut Parser) -> Result { + let align = AlignJustifySelf::parse(context, input)?; + let justify = input.try(|input| AlignJustifySelf::parse(context, input)).unwrap_or(align.clone()); + + Ok(Longhands { + align_self: align, + justify_self: justify, + }) + } + + impl<'a> ToCss for LonghandsToSerialize<'a> { + fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + self.align_self.to_css(dest)?; + dest.write_str(" ")?; + self.justify_self.to_css(dest) + } + } + diff --git a/tests/unit/style/properties/serialization.rs b/tests/unit/style/properties/serialization.rs index 112fb97e0c6..ee867505420 100644 --- a/tests/unit/style/properties/serialization.rs +++ b/tests/unit/style/properties/serialization.rs @@ -1263,4 +1263,21 @@ mod shorthand_serialization { let serialization = shorthand_properties_to_string(properties); assert_eq!(serialization, "place-content: stretch center;"); } + + #[test] + fn place_self_serialize_all_available_properties() { + use style::properties::longhands::align_self::SpecifiedValue as AlignSelf; + use style::properties::longhands::justify_self::SpecifiedValue as JustifySelf; + + let mut properties = Vec::new(); + + let align = AlignSelf::auto; + let justify = JustifySelf::baseline; + + properties.push(PropertyDeclaration::AlignSelf(align)); + properties.push(PropertyDeclaration::JustifySelf(justify)); + + let serialization = shorthand_properties_to_string(properties); + assert_eq!(serialization, "place-self: auto baseline;"); + } } From bfa408255f4aa3d7a96454ed8769507f192a116e Mon Sep 17 00:00:00 2001 From: tamamu Date: Mon, 10 Apr 2017 04:38:23 +0900 Subject: [PATCH 3/6] Add place-items shorthand property (it fails unit-test) --- .../properties/shorthand/position.mako.rs | 32 +++++++++++++++++++ tests/unit/style/properties/serialization.rs | 17 ++++++++++ 2 files changed, 49 insertions(+) diff --git a/components/style/properties/shorthand/position.mako.rs b/components/style/properties/shorthand/position.mako.rs index 9acbd9047db..f001c5690ca 100644 --- a/components/style/properties/shorthand/position.mako.rs +++ b/components/style/properties/shorthand/position.mako.rs @@ -210,3 +210,35 @@ } } + +<%helpers:shorthand name="place-items" sub_properties="align-items justify-items" + spec="https://drafts.csswg.org/css-align/#place-items-property" + products="gecko"> + use values::specified::align::{AlignItems, JustifyItems}; + use parser::Parse; + + impl From for JustifyItems { + fn from(align: AlignItems) -> JustifyItems { + JustifyItems(align.0) + } + } + + pub fn parse_value(context: &ParserContext, input: &mut Parser) -> Result { + let align = AlignItems::parse(context, input)?; + let justify = input.try(|input| JustifyItems::parse(context, input)) + .unwrap_or(JustifyItems::from(align)); + + Ok(Longhands { + align_items: align, + justify_items: justify, + }) + } + + impl<'a> ToCss for LonghandsToSerialize<'a> { + fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + self.align_items.to_css(dest)?; + dest.write_str(" ")?; + self.justify_items.to_css(dest) + } + } + diff --git a/tests/unit/style/properties/serialization.rs b/tests/unit/style/properties/serialization.rs index ee867505420..e23a66f4289 100644 --- a/tests/unit/style/properties/serialization.rs +++ b/tests/unit/style/properties/serialization.rs @@ -1280,4 +1280,21 @@ mod shorthand_serialization { let serialization = shorthand_properties_to_string(properties); assert_eq!(serialization, "place-self: auto baseline;"); } + + #[test] + fn place_items_serialize_all_available_properties() { + use style::properties::longhands::align_items::SpecifiedValue as AlignItems; + use style::properties::longhands::justify_items::SpecifiedValue as JustifyItems; + + let mut properties = Vec::new(); + + let align = AlignItems::flex_start; + let justify = JustifyItems::baseline; + + properties.push(PropertyDeclaration::AlignItems(align)); + properties.push(PropertyDeclaration::JustifyItems(justify)); + + let serialization = shorthand_properties_to_string(properties); + assert_eq!(serialization, "place-items: flex-start baseline;"); + } } From 4253d6390a3ac589e30f5bcb3b140cb8b98fa176 Mon Sep 17 00:00:00 2001 From: tamamu Date: Mon, 10 Apr 2017 20:08:54 +0900 Subject: [PATCH 4/6] Mark disable_when_testing --- components/style/properties/shorthand/position.mako.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/components/style/properties/shorthand/position.mako.rs b/components/style/properties/shorthand/position.mako.rs index f001c5690ca..94c3bee9ddc 100644 --- a/components/style/properties/shorthand/position.mako.rs +++ b/components/style/properties/shorthand/position.mako.rs @@ -140,7 +140,7 @@ <%helpers:shorthand name="place-content" sub_properties="align-content justify-content" spec="https://drafts.csswg.org/css-align/#propdef-place-content" - products="gecko"> + products="gecko" disable_when_testing="True"> use properties::longhands::align_content; use properties::longhands::justify_content; @@ -188,7 +188,7 @@ <%helpers:shorthand name="place-self" sub_properties="align-self justify-self" spec="https://drafts.csswg.org/css-align/#place-self-property" - products="gecko"> + products="gecko" disable_when_testing="True"> use values::specified::align::AlignJustifySelf; use parser::Parse; @@ -213,7 +213,7 @@ <%helpers:shorthand name="place-items" sub_properties="align-items justify-items" spec="https://drafts.csswg.org/css-align/#place-items-property" - products="gecko"> + products="gecko" disable_when_testing="True"> use values::specified::align::{AlignItems, JustifyItems}; use parser::Parse; From a864300a57d6c4d3bbb71e3f129fa1491e85f4a1 Mon Sep 17 00:00:00 2001 From: tamamu Date: Mon, 10 Apr 2017 20:09:33 +0900 Subject: [PATCH 5/6] Remove the serialization tests --- tests/unit/style/properties/serialization.rs | 51 -------------------- 1 file changed, 51 deletions(-) diff --git a/tests/unit/style/properties/serialization.rs b/tests/unit/style/properties/serialization.rs index e23a66f4289..535a52daa6d 100644 --- a/tests/unit/style/properties/serialization.rs +++ b/tests/unit/style/properties/serialization.rs @@ -1246,55 +1246,4 @@ mod shorthand_serialization { assert_eq!(counter_increment.to_css_string(), counter_increment_css); } } - - #[test] - fn place_content_serialize_all_available_properties() { - use style::properties::longhands::align_content::SpecifiedValue as AlignContent; - use style::properties::longhands::justify_content::SpecifiedValue as JustifyContent; - - let mut properties = Vec::new(); - - let align = AlignContent::stretch; - let justify = JustifyContent::center; - - properties.push(PropertyDeclaration::AlignContent(align)); - properties.push(PropertyDeclaration::JustifyContent(justify)); - - let serialization = shorthand_properties_to_string(properties); - assert_eq!(serialization, "place-content: stretch center;"); - } - - #[test] - fn place_self_serialize_all_available_properties() { - use style::properties::longhands::align_self::SpecifiedValue as AlignSelf; - use style::properties::longhands::justify_self::SpecifiedValue as JustifySelf; - - let mut properties = Vec::new(); - - let align = AlignSelf::auto; - let justify = JustifySelf::baseline; - - properties.push(PropertyDeclaration::AlignSelf(align)); - properties.push(PropertyDeclaration::JustifySelf(justify)); - - let serialization = shorthand_properties_to_string(properties); - assert_eq!(serialization, "place-self: auto baseline;"); - } - - #[test] - fn place_items_serialize_all_available_properties() { - use style::properties::longhands::align_items::SpecifiedValue as AlignItems; - use style::properties::longhands::justify_items::SpecifiedValue as JustifyItems; - - let mut properties = Vec::new(); - - let align = AlignItems::flex_start; - let justify = JustifyItems::baseline; - - properties.push(PropertyDeclaration::AlignItems(align)); - properties.push(PropertyDeclaration::JustifyItems(justify)); - - let serialization = shorthand_properties_to_string(properties); - assert_eq!(serialization, "place-items: flex-start baseline;"); - } } From f91b3d4cf6a2a8ff757748f7ececd162e5fb37ef Mon Sep 17 00:00:00 2001 From: tamamu Date: Tue, 11 Apr 2017 18:59:31 +0900 Subject: [PATCH 6/6] Fix serialization when the second value is identical to the first --- .../properties/shorthand/position.mako.rs | 52 ++++++++----------- 1 file changed, 21 insertions(+), 31 deletions(-) diff --git a/components/style/properties/shorthand/position.mako.rs b/components/style/properties/shorthand/position.mako.rs index 94c3bee9ddc..b1d40e52a19 100644 --- a/components/style/properties/shorthand/position.mako.rs +++ b/components/style/properties/shorthand/position.mako.rs @@ -144,28 +144,6 @@ use properties::longhands::align_content; use properties::longhands::justify_content; -% if product == "servo": - impl From for justify_content::SpecifiedValue { - fn from(align: align_content::SpecifiedValue) -> - justify_content::SpecifiedValue { - match align { - align_content::SpecifiedValue::stretch => - justify_content::SpecifiedValue::stretch, - align_content::SpecifiedValue::flex_start => - justify_content::SpecifiedValue::flex_start, - align_content::SpecifiedValue::flex_end => - justify_content::SpecifiedValue::flex_end, - align_content::SpecifiedValue::center => - justify_content::SpecifiedValue::center, - align_content::SpecifiedValue::space_between => - justify_content::SpecifiedValue::space_between, - align_content::SpecifiedValue::space_around => - justify_content::SpecifiedValue::space_around, - } - } - } -% endif - pub fn parse_value(context: &ParserContext, input: &mut Parser) -> Result { let align = align_content::parse(context, input)?; let justify = input.try(|input| justify_content::parse(context, input)) @@ -179,9 +157,13 @@ impl<'a> ToCss for LonghandsToSerialize<'a> { fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { - self.align_content.to_css(dest)?; - dest.write_str(" ")?; - self.justify_content.to_css(dest) + if self.align_content == self.justify_content { + self.align_content.to_css(dest) + } else { + self.justify_content.to_css(dest)?; + dest.write_str(" ")?; + self.justify_content.to_css(dest) + } } } @@ -204,9 +186,13 @@ impl<'a> ToCss for LonghandsToSerialize<'a> { fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { - self.align_self.to_css(dest)?; - dest.write_str(" ")?; - self.justify_self.to_css(dest) + if self.align_self == self.justify_self { + self.align_self.to_css(dest) + } else { + self.align_self.to_css(dest)?; + dest.write_str(" ")?; + self.justify_self.to_css(dest) + } } } @@ -236,9 +222,13 @@ impl<'a> ToCss for LonghandsToSerialize<'a> { fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { - self.align_items.to_css(dest)?; - dest.write_str(" ")?; - self.justify_items.to_css(dest) + if self.align_items.0 == self.justify_items.0 { + self.align_items.to_css(dest) + } else { + self.align_items.to_css(dest)?; + dest.write_str(" ")?; + self.justify_items.to_css(dest) + } } }