Bug 1257661: Make the CSS parser accept "display:-webkit-inline-box" as an alias for "display:inline-flex". r=heycam draft
authorDaniel Holbert <dholbert@cs.stanford.edu>
Thu, 17 Mar 2016 16:11:28 -0700
changeset 343401 f97703f074ccdb5d97ad16c282be4d24c1fb0eff
parent 341774 7521187099901a39edfea213b477975bbb98ba99
child 516772 25c4a5db8af3f8e0b676a447595ac2da296d99f5
push id13622
push userdholbert@mozilla.com
push dateTue, 22 Mar 2016 17:08:18 +0000
reviewersheycam
bugs1257661
milestone48.0a1
Bug 1257661: Make the CSS parser accept "display:-webkit-inline-box" as an alias for "display:inline-flex". r=heycam (We already map "display:-webkit-box" to "display:flex" in this way. This is just extending that existing support to cover the inline version.) MozReview-Commit-ID: F7gH3QMSmn0
layout/reftests/webkit-box/reftest.list
layout/reftests/webkit-box/webkit-display-values-1-ref.html
layout/reftests/webkit-box/webkit-display-values-1.html
layout/style/nsCSSKeywordList.h
layout/style/nsCSSParser.cpp
--- a/layout/reftests/webkit-box/reftest.list
+++ b/layout/reftests/webkit-box/reftest.list
@@ -1,12 +1,15 @@
 # This directory contains tests for "display: -webkit-box" and associated
 # CSS properties. These tests require webkit prefix support to be enabled.
 default-preferences pref(layout.css.prefixes.webkit,true)
 
+# Tests for "-webkit-box" & "-webkit-inline-box" as display values:
+== webkit-display-values-1.html webkit-display-values-1-ref.html
+
 # Tests for "-webkit-box-align" (cross-axis alignment):
 == 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
new file mode 100644
--- /dev/null
+++ b/layout/reftests/webkit-box/webkit-display-values-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 {
+      border: 1px solid black;
+      width: 50px;
+      height: 20px;
+      justify-content: center;
+    }
+  </style>
+</head>
+<body>
+  <div style="display: flex;">a</div>
+  <div style="display: flex;">b</div>
+  <div style="display: flex;">c</div>
+  <br>
+  <div style="display: inline-flex;">d</div>
+  <div style="display: inline-flex;">e</div>
+  <div style="display: inline-flex;">f</div>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/webkit-box/webkit-display-values-1.html
@@ -0,0 +1,41 @@
+<!DOCTYPE html>
+<!--
+     Any copyright is dedicated to the Public Domain.
+     http://creativecommons.org/publicdomain/zero/1.0/
+-->
+<html>
+<head>
+  <title>
+    CSS Test: -webkit-box & -webkit-inline-box as "display" values
+  </title>
+  <style>
+    div {
+      border: 1px solid black;
+      width: 50px;
+      height: 20px;
+      /* Lets us see whether 'display:-webkit-box' styling worked:*/
+      -webkit-box-pack: center;
+    }
+  </style>
+</head>
+<body>
+  <!-- -webkit-box, possibly mixed with -moz-box: -->
+  <div style="display: -webkit-box;">a</div>
+
+  <div style="display: -webkit-box;
+              display: -moz-box;">b</div>
+
+  <div style="display: -moz-box;
+              display: -webkit-box;">c</div>
+  <br>
+
+  <!-- -webkit-inline-box, possibly mixed with -moz-inline-box: -->
+  <div style="display: -webkit-inline-box;">d</div>
+
+  <div style="display: -webkit-inline-box;
+              display: -moz-inline-box;">e</div>
+
+  <div style="display: -moz-inline-box;
+              display: -webkit-inline-box;">f</div>
+</body>
+</html>
--- a/layout/style/nsCSSKeywordList.h
+++ b/layout/style/nsCSSKeywordList.h
@@ -121,16 +121,17 @@ CSS_KEY(-moz-text, _moz_text)
 CSS_KEY(-moz-use-system-font, _moz_use_system_font)
 CSS_KEY(-moz-use-text-color, _moz_use_text_color)
 CSS_KEY(-moz-visitedhyperlinktext, _moz_visitedhyperlinktext)
 CSS_KEY(-moz-window, _moz_window)
 CSS_KEY(-moz-workspace, _moz_workspace)
 CSS_KEY(-moz-zoom-in, _moz_zoom_in)
 CSS_KEY(-moz-zoom-out, _moz_zoom_out)
 CSS_KEY(-webkit-box, _webkit_box)
+CSS_KEY(-webkit-inline-box, _webkit_inline_box)
 CSS_KEY(absolute, absolute)
 CSS_KEY(active, active)
 CSS_KEY(activeborder, activeborder)
 CSS_KEY(activecaption, activecaption)
 CSS_KEY(add, add)
 CSS_KEY(additive, additive)
 CSS_KEY(alias, alias)
 CSS_KEY(all, all)
--- a/layout/style/nsCSSParser.cpp
+++ b/layout/style/nsCSSParser.cpp
@@ -6918,41 +6918,47 @@ CSSParserImpl::ParseTreePseudoElement(ns
 
 nsCSSKeyword
 CSSParserImpl::LookupKeywordPrefixAware(nsAString& aKeywordStr,
                                         const KTableEntry aKeywordTable[])
 {
   nsCSSKeyword keyword = nsCSSKeywords::LookupKeyword(aKeywordStr);
 
   if (aKeywordTable == nsCSSProps::kDisplayKTable) {
-    if (keyword == eCSSKeyword__webkit_box &&
+    if ((keyword == eCSSKeyword__webkit_box ||
+         keyword == eCSSKeyword__webkit_inline_box) &&
         (sWebkitPrefixedAliasesEnabled || ShouldUseUnprefixingService())) {
-      // Treat "display: -webkit-box" as "display: flex". In simple scenarios,
-      // they largely behave the same, as long as we alias the associated
-      // properties to modern flexbox equivalents as well.
+      // Treat "display: -webkit-box" as "display: flex", and
+      // "display: -webkit-inline-box" as "display: inline-flex". In simple
+      // scenarios, they largely behave the same, as long as we alias the
+      // associated properties to modern flexbox equivalents as well.
       if (mWebkitBoxUnprefixState == eHaveNotUnprefixed) {
         mWebkitBoxUnprefixState = eHaveUnprefixed;
       }
-      return eCSSKeyword_flex;
-    }
-
-    // If we've seen "display: -webkit-box" in an earlier declaration and we
-    // tried to unprefix it to emulate support for it, then we have to watch
-    // out for later "display: -moz-box" declarations; they're likely just a
-    // halfhearted attempt at compatibility, and they actually end up stomping
-    // on our emulation of the earlier -webkit-box display-value, via the CSS
+      return (keyword == eCSSKeyword__webkit_box) ?
+        eCSSKeyword_flex : eCSSKeyword_inline_flex;
+    }
+
+    // If we've seen "display: -webkit-box" (or "-webkit-inline-box") in an
+    // earlier declaration and we tried to unprefix it to emulate support for
+    // it, then we have to watch out for later "display: -moz-box" (and
+    // "-moz-inline-box") declarations; they're likely just a halfhearted
+    // attempt at compatibility, and they actually end up stomping on our
+    // emulation of the earlier -webkit-box display-value, via the CSS
     // cascade. To prevent this problem, we also treat "display: -moz-box" as
     // "display: flex" (but only if we unprefixed an earlier "-webkit-box").
     if (mWebkitBoxUnprefixState == eHaveUnprefixed &&
-        keyword == eCSSKeyword__moz_box) {
+        (keyword == eCSSKeyword__moz_box ||
+         keyword == eCSSKeyword__moz_inline_box)) {
       MOZ_ASSERT(sWebkitPrefixedAliasesEnabled || ShouldUseUnprefixingService(),
                  "mDidUnprefixWebkitBoxInEarlierDecl should only be set if "
                  "we're supporting webkit-prefixed aliases, or if we're using "
                  "the css unprefixing service on this site");
-      return eCSSKeyword_flex;
+      return (keyword == eCSSKeyword__moz_box) ?
+        eCSSKeyword_flex : eCSSKeyword_inline_flex;
     }
   }
 
   return keyword;
 }
 
 bool
 CSSParserImpl::ShouldUseUnprefixingService() const