From b702426c994d0fec6f164b62351c7224d6d95c30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Tue, 30 May 2023 20:44:25 +0200 Subject: [PATCH] style: Generalize resolved style code to deal with all shorthands This removes the various assumptions that the animation code does. Code size might be a concern, we can optimize if it is a problem, but let's do the obvious thing for now. Differential Revision: https://phabricator.services.mozilla.com/D130017 --- .../style/properties/properties.mako.rs | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index 10b13618a94..0916260adb3 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -3086,7 +3086,10 @@ impl ComputedValues { /// /// Note that the value will usually be the computed value, except for /// colors, where it's resolved. - pub fn get_longhand_property_value( + /// + /// TODO(emilio): We should move all the special resolution from + /// nsComputedDOMStyle to ToResolvedValue instead. + pub fn get_resolved_value( &self, property_id: LonghandId, dest: &mut CssWriter @@ -3112,6 +3115,31 @@ impl ComputedValues { } } + /// Returns the given longhand's resolved value as a property declaration. + pub fn resolved_declaration(&self, property_id: LonghandId) -> PropertyDeclaration { + use crate::values::resolved::ToResolvedValue; + use crate::values::computed::ToComputedValue; + + let context = resolved::Context { + style: self, + }; + + match property_id { + % for prop in data.longhands: + LonghandId::${prop.camel_case} => { + let value = self.clone_${prop.ident}(); + let resolved = value.to_resolved_value(&context); + %if prop.boxed: + let resolved = Box::new(resolved); + %endif + let computed = ToResolvedValue::from_resolved_value(resolved); + let specified = ToComputedValue::from_computed_value(&computed); + PropertyDeclaration::${prop.camel_case}(specified) + } + % endfor + } + } + /// Resolves the currentColor keyword. /// /// Any color value from computed values (except for the 'color' property