From ebb57eff22f102579c6e7ce261b4806e31f4efde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Thu, 15 Nov 2018 08:25:13 +0000 Subject: [PATCH] style: Add a mechanism to serialize shorthands for getComputedStyle(). This implements the mechanism reusing the animation machinery for now, so it asserts in a few cases that this wouldn't handle correctly. For shorthands that have colors and other bits we'd need a more sophisticated mechanism with a bit more code (that resolves colors and such), but it'd look something like this regardless, and we should have this in any case. Differential Revision: https://phabricator.services.mozilla.com/D11944 --- components/style/properties/declaration_block.rs | 4 +++- components/style/properties/properties.mako.rs | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/components/style/properties/declaration_block.rs b/components/style/properties/declaration_block.rs index a6d736fb49f..dfe619fc79b 100644 --- a/components/style/properties/declaration_block.rs +++ b/components/style/properties/declaration_block.rs @@ -309,7 +309,9 @@ impl PropertyDeclarationBlock { .find(|(declaration, _)| declaration.id() == property) } - fn shorthand_to_css( + /// Tries to serialize a given shorthand from the declarations in this + /// block. + pub fn shorthand_to_css( &self, shorthand: ShorthandId, dest: &mut CssStringWriter, diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index 072b78cf377..ad51e87fb2f 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -1354,6 +1354,13 @@ impl ShorthandId { NonCustomPropertyId::from(self).to_nscsspropertyid() } + /// Converts from a nsCSSPropertyID to a ShorthandId. + #[cfg(feature = "gecko")] + #[inline] + pub fn from_nscsspropertyid(prop: nsCSSPropertyID) -> Result { + PropertyId::from_nscsspropertyid(prop)?.as_shorthand().map_err(|_| ()) + } + /// Get the longhand ids that form this shorthand. pub fn longhands(&self) -> NonCustomPropertyIterator { % for property in data.shorthands: