From c351092457f323b9d5de05791472c407f6bf650f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Naz=C4=B1m=20Can=20Alt=C4=B1nova?= Date: Wed, 28 Dec 2016 18:41:39 +0300 Subject: [PATCH] Fix overflow shorthand serialization. --- .../style/properties/declaration_block.rs | 15 ++++-- .../style/properties/properties.mako.rs | 15 ++++++ .../style/properties/shorthand/box.mako.rs | 29 +++++++++-- tests/wpt/metadata/MANIFEST.json | 11 ++++- .../cssom/overflow-serialization.html | 48 +++++++++++++++++++ 5 files changed, 108 insertions(+), 10 deletions(-) create mode 100644 tests/wpt/web-platform-tests/cssom/overflow-serialization.html diff --git a/components/style/properties/declaration_block.rs b/components/style/properties/declaration_block.rs index 0cf96724dcb..80ba5787d96 100644 --- a/components/style/properties/declaration_block.rs +++ b/components/style/properties/declaration_block.rs @@ -111,7 +111,7 @@ impl PropertyDeclarationBlock { // so we treat this as a normal-importance property let importance = Importance::Normal; let appendable_value = shorthand.get_shorthand_appendable_value(list).unwrap(); - append_declaration_value(dest, appendable_value, importance) + append_declaration_value(dest, appendable_value, importance, false) } Err(longhand_or_custom) => { if let Some(&(ref value, _importance)) = self.get(longhand_or_custom) { @@ -377,7 +377,8 @@ fn handle_first_serialization(dest: &mut W, is_first_serialization: &mut bool pub fn append_declaration_value<'a, W, I> (dest: &mut W, appendable_value: AppendableValue<'a, I>, - importance: Importance) + importance: Importance, + is_overflow_with_name: bool) -> fmt::Result where W: fmt::Write, I: Iterator { match appendable_value { @@ -388,7 +389,11 @@ pub fn append_declaration_value<'a, W, I> try!(decl.to_css(dest)); }, AppendableValue::DeclarationsForShorthand(shorthand, decls) => { - try!(shorthand.longhands_to_css(decls, dest)); + if is_overflow_with_name { + try!(shorthand.overflow_longhands_to_css(decls, dest)); + } else { + try!(shorthand.longhands_to_css(decls, dest)); + } } } @@ -414,7 +419,7 @@ pub fn append_serialization<'a, W, I, N>(dest: &mut W, // Overflow does not behave like a normal shorthand. When overflow-x and overflow-y are not of equal // values, they no longer use the shared property name "overflow" and must be handled differently if shorthands::is_overflow_shorthand(&appendable_value) { - return append_declaration_value(dest, appendable_value, importance); + return append_declaration_value(dest, appendable_value, importance, true); } try!(property_name.to_css(dest)); @@ -434,7 +439,7 @@ pub fn append_serialization<'a, W, I, N>(dest: &mut W, &AppendableValue::DeclarationsForShorthand(..) => try!(write!(dest, " ")) } - try!(append_declaration_value(dest, appendable_value, importance)); + try!(append_declaration_value(dest, appendable_value, importance, false)); write!(dest, ";") } diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index 5d1bf766c8a..ab25f16e87d 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -467,6 +467,21 @@ impl ShorthandId { } } + // Overflow does not behave like a normal shorthand. When overflow-x and overflow-y are not of equal + // values, they no longer use the shared property name "overflow". + pub fn overflow_longhands_to_css<'a, W, I>(&self, declarations: I, dest: &mut W) -> fmt::Result + where W: fmt::Write, I: Iterator { + match *self { + ShorthandId::Overflow => { + match shorthands::overflow::LonghandsToSerialize::from_iter(declarations) { + Ok(longhands) => longhands.to_css_declared_with_name(dest), + Err(_) => Err(fmt::Error) + } + }, + _ => Err(fmt::Error) + } + } + /// Serializes the possible shorthand name with value to input buffer given /// a list of longhand declarations. /// diff --git a/components/style/properties/shorthand/box.mako.rs b/components/style/properties/shorthand/box.mako.rs index 08e27c0bde6..836eade0234 100644 --- a/components/style/properties/shorthand/box.mako.rs +++ b/components/style/properties/shorthand/box.mako.rs @@ -15,10 +15,6 @@ }) } - - // Overflow does not behave like a normal shorthand. When overflow-x and overflow-y are not of equal - // values, they no longer use the shared property name "overflow". - // Other shorthands do not include their name in the to_css method impl<'a> LonghandsToSerialize<'a> { fn to_css_declared(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { let x_and_y_equal = match (self.overflow_x, self.overflow_y) { @@ -32,6 +28,31 @@ _ => false }; + if x_and_y_equal { + try!(self.overflow_x.to_css(dest)); + } + Ok(()) + } + + // Overflow does not behave like a normal shorthand. When overflow-x and overflow-y are not of equal + // values, they no longer use the shared property name "overflow". + // Other shorthands do not include their name in the to_css method + pub fn to_css_declared_with_name(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + let x_and_y_equal = match (self.overflow_x, self.overflow_y) { + (&DeclaredValue::Value(ref x_value), &DeclaredValue::Value(ref y_container)) => { + *x_value == y_container.0 + }, + (_, &DeclaredValue::WithVariables { .. }) | + (&DeclaredValue::WithVariables { .. }, _) => { + // We don't serialize shorthands with variables + return dest.write_str(""); + }, + (&DeclaredValue::Initial, &DeclaredValue::Initial) => true, + (&DeclaredValue::Inherit, &DeclaredValue::Inherit) => true, + (&DeclaredValue::Unset, &DeclaredValue::Unset) => true, + _ => false + }; + if x_and_y_equal { try!(write!(dest, "overflow")); try!(write!(dest, ": ")); diff --git a/tests/wpt/metadata/MANIFEST.json b/tests/wpt/metadata/MANIFEST.json index b5300424b2e..93c28136f07 100644 --- a/tests/wpt/metadata/MANIFEST.json +++ b/tests/wpt/metadata/MANIFEST.json @@ -45845,7 +45845,16 @@ "local_changes": { "deleted": [], "deleted_reftests": {}, - "items": {}, + "items": { + "testharness": { + "cssom/overflow-serialization.html": [ + { + "path": "cssom/overflow-serialization.html", + "url": "/cssom/overflow-serialization.html" + } + ] + } + }, "reftest_nodes": {} }, "reftest_nodes": { diff --git a/tests/wpt/web-platform-tests/cssom/overflow-serialization.html b/tests/wpt/web-platform-tests/cssom/overflow-serialization.html new file mode 100644 index 00000000000..c350a1ac211 --- /dev/null +++ b/tests/wpt/web-platform-tests/cssom/overflow-serialization.html @@ -0,0 +1,48 @@ + + + + + CSSOM - Overlow property has different serialization than other shorthands. + + + + + + +