Bug 1231682 part 2: Support "-webkit-box-pack: justify" as a special-case exception during "justify-content" parsing. r=mats draft
authorDaniel Holbert <dholbert@cs.stanford.edu>
Tue, 22 Mar 2016 11:23:45 -0700
changeset 343450 cad52a56be20e66f51e5be398138d1ee61e75971
parent 343449 34e1cc00eb4e24a7e42ac4af56dbd202c52b53db
child 516777 85a0ca31bf064fdae8760a7fcc761aadf4ce0fda
push id13627
push userdholbert@mozilla.com
push dateTue, 22 Mar 2016 18:23:56 +0000
reviewersmats
bugs1231682
milestone48.0a1
Bug 1231682 part 2: Support "-webkit-box-pack: justify" as a special-case exception during "justify-content" parsing. r=mats MozReview-Commit-ID: 3eFWEvHBlDq
layout/reftests/webkit-box/reftest.list
layout/reftests/webkit-box/webkit-box-pack-horiz-1-ref.html
layout/reftests/webkit-box/webkit-box-pack-horiz-1a.html
layout/reftests/webkit-box/webkit-box-pack-horiz-1b.html
layout/reftests/webkit-box/webkit-box-pack-justify-supports-1-ref.html
layout/reftests/webkit-box/webkit-box-pack-justify-supports-1.html
layout/reftests/webkit-box/webkit-box-pack-vert-1-ref.html
layout/reftests/webkit-box/webkit-box-pack-vert-1.html
layout/style/nsCSSParser.cpp
layout/style/nsCSSProps.cpp
layout/style/nsCSSProps.h
layout/style/test/property_database.js
--- a/layout/reftests/webkit-box/reftest.list
+++ b/layout/reftests/webkit-box/reftest.list
@@ -9,8 +9,11 @@ default-preferences pref(layout.css.pref
 == webkit-box-align-horiz-1a.html webkit-box-align-horiz-1-ref.html
 == webkit-box-align-horiz-1b.html webkit-box-align-horiz-1-ref.html
 == webkit-box-align-vert-1.html webkit-box-align-vert-1-ref.html
 
 # Tests for "-webkit-box-pack" (main-axis alignment):
 == webkit-box-pack-horiz-1a.html webkit-box-pack-horiz-1-ref.html
 == webkit-box-pack-horiz-1b.html webkit-box-pack-horiz-1-ref.html
 == webkit-box-pack-vert-1.html webkit-box-pack-vert-1-ref.html
+
+# Tests for "-webkit-box-pack: justify" in @supports conditions
+== webkit-box-pack-justify-supports-1.html webkit-box-pack-justify-supports-1-ref.html
--- a/layout/reftests/webkit-box/webkit-box-pack-horiz-1-ref.html
+++ b/layout/reftests/webkit-box/webkit-box-pack-horiz-1-ref.html
@@ -23,21 +23,20 @@
     }
     .box > *:nth-child(2) {
       background: salmon;
       font-size: 50%;
       width: 2em;
       /* auto height */
     }
 
-    .bpstart   { justify-content: flex-start; }
-    .bpcenter  { justify-content: center;     }
-    .bpend     { justify-content: flex-end;   }
-    .bpjustify { justify-content: justify;
-                 display:none; /* XXXdholbert Disabling until bug 1231682 is fixed */ }
+    .bpstart   { justify-content: flex-start;    }
+    .bpcenter  { justify-content: center;        }
+    .bpend     { justify-content: flex-end;      }
+    .bpjustify { justify-content: space-between; }
     br { clear: both; }
   </style>
 </head>
 <body>
   <!-- FIRST ROW: Default -webkit-box-pack -->
   <!-- intrinsically sized -->
   <div class="box">
     <div>a</div><div>b</div>
--- a/layout/reftests/webkit-box/webkit-box-pack-horiz-1a.html
+++ b/layout/reftests/webkit-box/webkit-box-pack-horiz-1a.html
@@ -27,18 +27,17 @@
       font-size: 50%;
       width: 2em;
       /* auto height */
     }
 
     .bpstart   { -webkit-box-pack: start;   }
     .bpcenter  { -webkit-box-pack: center;  }
     .bpend     { -webkit-box-pack: end;     }
-    .bpjustify { -webkit-box-pack: justify;
-                 display:none; /* XXXdholbert Disabling until bug 1231682 is fixed */ }
+    .bpjustify { -webkit-box-pack: justify; }
     br { clear: both; }
   </style>
 </head>
 <body>
   <!-- FIRST ROW: Default -webkit-box-pack -->
   <!-- intrinsically sized -->
   <div class="box">
     <div>a</div><div>b</div>
--- a/layout/reftests/webkit-box/webkit-box-pack-horiz-1b.html
+++ b/layout/reftests/webkit-box/webkit-box-pack-horiz-1b.html
@@ -28,18 +28,17 @@
       font-size: 50%;
       width: 2em;
       /* auto height */
     }
 
     .bpstart   { -webkit-box-pack: start;   }
     .bpcenter  { -webkit-box-pack: center;  }
     .bpend     { -webkit-box-pack: end;     }
-    .bpjustify { -webkit-box-pack: justify;
-                 display:none; /* XXXdholbert Disabling until bug 1231682 is fixed */ }
+    .bpjustify { -webkit-box-pack: justify; }
     br { clear: both; }
   </style>
 </head>
 <body>
   <!-- FIRST ROW: Default -webkit-box-pack -->
   <!-- intrinsically sized -->
   <div class="box">
     <div>a</div><div>b</div>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/webkit-box/webkit-box-pack-justify-supports-1-ref.html
@@ -0,0 +1,29 @@
+<!DOCTYPE html>
+<!--
+     Any copyright is dedicated to the Public Domain.
+     http://creativecommons.org/publicdomain/zero/1.0/
+-->
+<html>
+<head>
+  <title>
+    CSS Reference
+  </title>
+  <style>
+    div {
+      width: 10px;
+      height: 10px;
+      border: 1px solid black;
+      background: lime;
+    }
+  </style>
+</head>
+<body>
+  <div id="wbp_justify"></div>
+  <div id="jc_justify"></div>
+
+  <div id="script_wbp_justify1"></div>
+  <div id="script_wbp_justify2"></div>
+  <div id="script_jc_justify1"></div>
+  <div id="script_jc_justify2"></div>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/webkit-box/webkit-box-pack-justify-supports-1.html
@@ -0,0 +1,75 @@
+<!DOCTYPE html>
+<!--
+     Any copyright is dedicated to the Public Domain.
+     http://creativecommons.org/publicdomain/zero/1.0/
+-->
+<html>
+<head>
+  <title>
+    CSS Test: "-webkit-box-pack: justify" in an @supports condition
+  </title>
+  <!-- Some background: We support the legacy "-webkit-box-pack" property by
+       treating it as an alias for the "justify-content" property. But we have
+       to handle the "justify" value specially, because it's not a valid value
+       for "justify-content" (but it is valid for "-webkit-box-pack").
+
+       This testcase ensures that we evaluate @supports conditions correctly
+       for this special "justify" value: we should reject it for
+       "justify-content", but we should accept it for "-webkit-box-pack".
+    -->
+  <style>
+    div {
+      width: 10px;
+      height: 10px;
+      border: 1px solid black;
+    }
+
+    div#wbp_justify   {
+      background: red; /* should be overridden by @supports clause below */
+    }
+    @supports (-webkit-box-pack: justify) {
+      div#wbp_justify { background: lime; }
+    }
+
+
+    div#jc_justify {
+      background: lime; /* shouldn't be overridden by @supports clause below */
+    }
+    @supports (justify-content: justify) {
+      div#simple_jc_justify { background: orange; }
+    }
+  </style>
+  <script>
+    function testSupportsCondition(elemId, supportsArgs, shouldPass) {
+      var elem = document.getElementById(elemId);
+      if (CSS.supports.apply(this, supportsArgs) == shouldPass) {
+        elem.style.background = "lime";
+      } else {
+        elem.style.background = "red";
+      }
+    }
+
+    function go() {
+      testSupportsCondition("script_wbp_justify1",
+                            ["-webkit-box-pack", "justify"], true);
+      testSupportsCondition("script_wbp_justify2",
+                            ["(-webkit-box-pack: justify)"], true);
+      testSupportsCondition("script_jc_justify1",
+                            ["justify-content", "justify"], false);
+      testSupportsCondition("script_jc_justify2",
+                            ["(justify-content: justify)"], false);
+    }
+  </script>
+</head>
+<body onload="go()">
+  <!-- Tests for @supports in CSS: -->
+  <div id="wbp_justify"></div>
+  <div id="jc_justify"></div>
+
+  <!-- Tests for scripted CSS.supports API: -->
+  <div id="script_wbp_justify1"></div>
+  <div id="script_wbp_justify2"></div>
+  <div id="script_jc_justify1"></div>
+  <div id="script_jc_justify2"></div>
+</body>
+</html>
--- a/layout/reftests/webkit-box/webkit-box-pack-vert-1-ref.html
+++ b/layout/reftests/webkit-box/webkit-box-pack-vert-1-ref.html
@@ -24,21 +24,20 @@
     }
     .box > *:nth-child(2) {
       background: salmon;
       font-size: 50%;
       width: 2em;
       /* auto height */
     }
 
-    .bpstart   { justify-content: flex-start; }
-    .bpcenter  { justify-content: center;     }
-    .bpend     { justify-content: flex-end;   }
-    .bpjustify { justify-content: justify;
-                 display:none; /* XXXdholbert Disabling until bug 1231682 is fixed */ }
+    .bpstart   { justify-content: flex-start;    }
+    .bpcenter  { justify-content: center;        }
+    .bpend     { justify-content: flex-end;      }
+    .bpjustify { justify-content: space-between; }
     br { clear: both; }
   </style>
 </head>
 <body>
   <!-- FIRST ROW: Default -webkit-box-pack -->
   <!-- intrinsically sized -->
   <div class="box">
     <div>a</div><div>b</div>
--- a/layout/reftests/webkit-box/webkit-box-pack-vert-1.html
+++ b/layout/reftests/webkit-box/webkit-box-pack-vert-1.html
@@ -28,18 +28,17 @@
       font-size: 50%;
       width: 2em;
       /* auto height */
     }
 
     .bpstart   { -webkit-box-pack: start;   }
     .bpcenter  { -webkit-box-pack: center;  }
     .bpend     { -webkit-box-pack: end;     }
-    .bpjustify { -webkit-box-pack: justify;
-                 display:none; /* XXXdholbert Disabling until bug 1231682 is fixed */ }
+    .bpjustify { -webkit-box-pack: justify; }
     br { clear: both; }
   </style>
 </head>
 <body>
   <!-- FIRST ROW: Default -webkit-box-pack -->
   <!-- intrinsically sized -->
   <div class="box">
     <div>a</div><div>b</div>
--- a/layout/style/nsCSSParser.cpp
+++ b/layout/style/nsCSSParser.cpp
@@ -9822,17 +9822,25 @@ CSSParserImpl::ParseAlignJustifyContent(
   nsCSSValue value;
   if (!ParseSingleTokenVariant(value, VARIANT_INHERIT, nullptr)) {
     if (!ParseEnum(value, nsCSSProps::kAlignNormalBaseline)) {
       nsCSSValue fallbackValue;
       if (!ParseEnum(value, nsCSSProps::kAlignContentDistribution)) {
         if (!ParseAlignJustifyPosition(fallbackValue,
                                        nsCSSProps::kAlignContentPosition) ||
             fallbackValue.GetUnit() == eCSSUnit_Null) {
-          return false;
+          // If we're parsing the alias "-webkit-box-pack" (which is an alias
+          // for "justify-content"), and we failed to parse any valid
+          // "justify-content" value, then we attempt to parse one extra value
+          // that -webkit-box-pack needs to support ("justify").
+          // XXXdholbert Remove this special case in bug 1257688:
+          if (mAliasBeingParsed != eCSSPropertyAlias_WebkitBoxPack ||
+              !ParseEnum(fallbackValue, nsCSSProps::kWebkitBoxPackExtraValue)) {
+            return false;
+          }
         }
         // optional <content-distribution> after <*-position> ...
         if (!ParseEnum(value, nsCSSProps::kAlignContentDistribution)) {
           // ... is missing so the <*-position> is the value, not the fallback
           value = fallbackValue;
           fallbackValue.Reset();
         }
       } else {
--- a/layout/style/nsCSSProps.cpp
+++ b/layout/style/nsCSSProps.cpp
@@ -2168,16 +2168,21 @@ const KTableEntry nsCSSProps::kVerticalA
 
 const KTableEntry nsCSSProps::kVisibilityKTable[] = {
   { eCSSKeyword_visible, NS_STYLE_VISIBILITY_VISIBLE },
   { eCSSKeyword_hidden, NS_STYLE_VISIBILITY_HIDDEN },
   { eCSSKeyword_collapse, NS_STYLE_VISIBILITY_COLLAPSE },
   { eCSSKeyword_UNKNOWN, -1 }
 };
 
+const KTableEntry nsCSSProps::kWebkitBoxPackExtraValue[] = {
+  { eCSSKeyword_justify, NS_STYLE_ALIGN_SPACE_BETWEEN },
+  { eCSSKeyword_UNKNOWN, -1 }
+};
+
 const KTableEntry nsCSSProps::kWhitespaceKTable[] = {
   { eCSSKeyword_normal, NS_STYLE_WHITESPACE_NORMAL },
   { eCSSKeyword_pre, NS_STYLE_WHITESPACE_PRE },
   { eCSSKeyword_nowrap, NS_STYLE_WHITESPACE_NOWRAP },
   { eCSSKeyword_pre_wrap, NS_STYLE_WHITESPACE_PRE_WRAP },
   { eCSSKeyword_pre_line, NS_STYLE_WHITESPACE_PRE_LINE },
   { eCSSKeyword__moz_pre_space, NS_STYLE_WHITESPACE_PRE_SPACE },
   { eCSSKeyword_UNKNOWN, -1 }
--- a/layout/style/nsCSSProps.h
+++ b/layout/style/nsCSSProps.h
@@ -842,16 +842,19 @@ public:
   static const KTableEntry kUnicodeBidiKTable[];
   static const KTableEntry kUserFocusKTable[];
   static const KTableEntry kUserInputKTable[];
   static const KTableEntry kUserModifyKTable[];
   static const KTableEntry kUserSelectKTable[];
   static const KTableEntry kVerticalAlignKTable[];
   static const KTableEntry kVisibilityKTable[];
   static const KTableEntry kVolumeKTable[];
+  // This contains a single extra keyword that "-webkit-box-pack" supports,
+  // but its aliased property ("justify-content") does not:
+  static const KTableEntry kWebkitBoxPackExtraValue[];
   static const KTableEntry kWhitespaceKTable[];
   static const KTableEntry kWidthKTable[]; // also min-width, max-width
   static const KTableEntry kWindowDraggingKTable[];
   static const KTableEntry kWindowShadowKTable[];
   static const KTableEntry kWordBreakKTable[];
   static const KTableEntry kWordWrapKTable[];
   static const KTableEntry kWritingModeKTable[];
 };
--- a/layout/style/test/property_database.js
+++ b/layout/style/test/property_database.js
@@ -7211,16 +7211,22 @@ if (IsCSSPropertyPrefEnabled("layout.css
     subproperties: [ "align-items" ],
   };
   gCSSProperties["-webkit-box-pack"] = {
     domProp: "webkitBoxPack",
     inherited: false,
     type: CSS_TYPE_SHORTHAND_AND_LONGHAND,
     alias_for: "justify-content",
     subproperties: [ "justify-content" ],
+    // Note: We explicitly provide an "other_values" list, with all of the
+    // -webkit-box-pack values that we need to support beyond the default
+    // "start".  We have to do this in order to test for "justify", since
+    // that's not a valid value for our aliased property, "justify-content".
+    // (It's supported via a special case.)
+    other_values: [ "center", "end", "justify" ],
   };
   gCSSProperties["-webkit-user-select"] = {
     domProp: "webkitUserSelect",
     inherited: false,
     type: CSS_TYPE_SHORTHAND_AND_LONGHAND,
     alias_for: "-moz-user-select",
     subproperties: [ "-moz-user-select" ],
   };