servo: Merge #16780 - Add comments to shorthand alias logic that explains the interesting bahavior (from canaltinova:shorthand-aliases); r=emilio
authorNazım Can Altınova <canaltinova@gmail.com>
Tue, 09 May 2017 07:34:42 -0500
changeset 357419 2ca07f25550d45756a17bb2e885a0139f4f73534
parent 357418 4bbf624389f10470ba2259232892a986125d4766
child 357420 553198d4b70fef266094ba0e397dee72b429b61c
push id90127
push usercbook@mozilla.com
push dateWed, 10 May 2017 13:31:57 +0000
treeherdermozilla-inbound@4126603b0e55 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersemilio
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
servo: Merge #16780 - Add comments to shorthand alias logic that explains the interesting bahavior (from canaltinova:shorthand-aliases); r=emilio <!-- Please describe your changes on the following line: --> --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors <!-- Either: --> - [X] These changes do not require tests because they are just comments and variable name change. Source-Repo: https://github.com/servo/servo Source-Revision: 121662aa570f9e4005deec6d502acba7ab56c076
servo/components/style/properties/declaration_block.rs
servo/components/style/properties/properties.mako.rs
servo/components/style/properties/shorthand/box.mako.rs
--- a/servo/components/style/properties/declaration_block.rs
+++ b/servo/components/style/properties/declaration_block.rs
@@ -477,17 +477,17 @@ impl ToCss for PropertyDeclarationBlock 
                                 with_variables: false,
                             }
                         }
                     };
 
                     // Substeps 7 and 8
                     // We need to check the shorthand whether it's an alias property or not.
                     // If it's an alias property, it should be serialized like its longhand.
-                    if shorthand.flags().contains(ALIAS_PROPERTY) {
+                    if shorthand.flags().contains(SHORTHAND_ALIAS_PROPERTY) {
                         append_serialization::<_, Cloned<slice::Iter< _>>, _>(
                              dest,
                              &property,
                              value,
                              importance,
                              &mut is_first_serialization)?;
                     } else {
                         append_serialization::<_, Cloned<slice::Iter< _>>, _>(
--- a/servo/components/style/properties/properties.mako.rs
+++ b/servo/components/style/properties/properties.mako.rs
@@ -479,18 +479,18 @@ bitflags! {
         /// This property requires a stacking context.
         const CREATES_STACKING_CONTEXT = 1 << 0,
         /// This property has values that can establish a containing block for
         /// fixed positioned and absolutely positioned elements.
         const FIXPOS_CB = 1 << 1,
         /// This property has values that can establish a containing block for
         /// absolutely positioned elements.
         const ABSPOS_CB = 1 << 2,
-        /// This property(shorthand) is an alias of another property.
-        const ALIAS_PROPERTY = 1 << 3,
+        /// This shorthand property is an alias of another property.
+        const SHORTHAND_ALIAS_PROPERTY = 1 << 3,
     }
 }
 
 /// An identifier for a given longhand property.
 #[derive(Clone, Copy, Eq, PartialEq, Debug)]
 #[cfg_attr(feature = "servo", derive(HeapSizeOf))]
 pub enum LonghandId {
     % for i, property in enumerate(data.longhands):
@@ -1258,17 +1258,20 @@ impl ToCss for PropertyDeclaration {
                     PropertyDeclaration::${property.camel_case}(ref value) =>
                         value.to_css(dest),
                 % endif
             % endfor
             PropertyDeclaration::CSSWideKeyword(_, keyword) => keyword.to_css(dest),
             PropertyDeclaration::WithVariables(_, ref with_variables) => {
                 // https://drafts.csswg.org/css-variables/#variables-in-shorthands
                 match with_variables.from_shorthand {
-                    Some(shorthand) if shorthand.flags().contains(ALIAS_PROPERTY) =>
+                    // Normally, we shouldn't be printing variables here if they came from
+                    // shorthands. But we should allow properties that came from shorthand
+                    // aliases. That also matches with the Gecko behavior.
+                    Some(shorthand) if shorthand.flags().contains(SHORTHAND_ALIAS_PROPERTY) =>
                         dest.write_str(&*with_variables.css)?,
                     None => dest.write_str(&*with_variables.css)?,
                     _ => {},
                 }
                 Ok(())
             },
             PropertyDeclaration::Custom(_, ref value) => value.borrow().to_css(dest),
             % if any(property.derived_from for property in data.longhands):
@@ -1340,17 +1343,21 @@ impl PropertyDeclaration {
     fn with_variables_from_shorthand(&self, shorthand: ShorthandId) -> Option< &str> {
         match *self {
             PropertyDeclaration::WithVariables(_, ref with_variables) => {
                 if let Some(s) = with_variables.from_shorthand {
                     if s == shorthand {
                         Some(&*with_variables.css)
                     } else { None }
                 } else {
-                    if shorthand.flags().contains(ALIAS_PROPERTY) {
+                    // Normally, longhand property that doesn't come from a shorthand
+                    // should return None here. But we return Some to longhands if they
+                    // came from a shorthand alias. Because for example, we should be able to
+                    // get -moz-transform's value from transform.
+                    if shorthand.flags().contains(SHORTHAND_ALIAS_PROPERTY) {
                         return Some(&*with_variables.css);
                     }
                     None
                 }
             },
             _ => None,
         }
     }
--- a/servo/components/style/properties/shorthand/box.mako.rs
+++ b/servo/components/style/properties/shorthand/box.mako.rs
@@ -322,17 +322,17 @@ macro_rules! try_parse_one {
             }
         }
     }
 </%helpers:shorthand>
 
 
 <%helpers:shorthand name="-moz-transform" products="gecko"
                     sub_properties="transform"
-                    flags="ALIAS_PROPERTY"
+                    flags="SHORTHAND_ALIAS_PROPERTY"
                     spec="Non-standard: https://developer.mozilla.org/en-US/docs/Web/CSS/transform">
     use properties::longhands::transform;
 
     pub fn parse_value(context: &ParserContext, input: &mut Parser) -> Result<Longhands, ()> {
         Ok(Longhands {
             transform: transform::parse_prefixed(context, input)?,
         })
     }