Bug 1236400 part 3: If webkit prefix support is enabled, skip CSS Parser code that converts "display: -webkit-box" directly to "display: flex". r=mats
authorDaniel Holbert <dholbert@cs.stanford.edu>
Thu, 24 Mar 2016 09:55:11 -0700
changeset 290332 cfab09cee9d9b6e66d1ec46cdc094b02d7c855b1
parent 290331 5dcb4fe4466805c71de8d2f55927dcc17ac6debd
child 290333 02096dbc3c67c6fcb453a0fc3455f64245b7bc46
push id19656
push usergwagner@mozilla.com
push dateMon, 04 Apr 2016 13:43:23 +0000
treeherderb2g-inbound@e99061fde28a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmats
bugs1236400
milestone48.0a1
Bug 1236400 part 3: If webkit prefix support is enabled, skip CSS Parser code that converts "display: -webkit-box" directly to "display: flex". r=mats This makes "display: -webkit-box" & "display: -webkit-inline-box" into bona fide "display" values (instead of just aliases), when webkit prefix support is enabled, and allows us to actually exercise the code added in the earlier patches on this bug. (Note that when webkit prefix support is *disabled*, our CSS Unprefixing Service strategy will instead have an opportunity to take effect, for whitelisted sites, and it'll continue to convert "-webkit-box" to "flex".) MozReview-Commit-ID: BV93xs4ddbK
layout/inspector/tests/test_bug877690.html
layout/style/nsCSSParser.cpp
--- a/layout/inspector/tests/test_bug877690.html
+++ b/layout/inspector/tests/test_bug877690.html
@@ -163,19 +163,21 @@ function do_test() {
 
   // test proprety
   var prop = "display";
   var values = getCSSValuesForProperty(prop);
   var expected = [ "initial", "inherit", "unset", "none", "inline", "block", "inline-block", "list-item",
       "table", "inline-table", "table-row-group", "table-header-group", "table-footer-group", "table-row",
       "table-column-group", "table-column", "table-cell", "table-caption", "-moz-box", "-moz-inline-box",
       "-moz-grid", "-moz-inline-grid", "-moz-grid-group", "-moz-grid-line", "-moz-stack", "-moz-inline-stack",
-      "-moz-deck", "-moz-popup", "-moz-groupbox", "flex", "inline-flex", "grid",
-      "inline-grid", "ruby", "ruby-base", "ruby-base-container", "ruby-text",
-      "ruby-text-container", "contents" ];
+      "-moz-deck", "-moz-popup", "-moz-groupbox",
+      "flex", "inline-flex", "-webkit-box", "-webkit-inline-box",
+      "grid", "inline-grid",
+      "ruby", "ruby-base", "ruby-base-container", "ruby-text", "ruby-text-container",
+      "contents" ];
   ok(testValues(values, expected), "property display's values.");
 
   // test property
   var prop = "float";
   var values = getCSSValuesForProperty(prop);
   var expected = [ "initial", "inherit", "unset", "none", "left", "right", "inline-start", "inline-end" ];
   ok(testValues(values, expected), "property float's values.");
 
--- a/layout/style/nsCSSParser.cpp
+++ b/layout/style/nsCSSParser.cpp
@@ -6918,45 +6918,71 @@ CSSParserImpl::ParseTreePseudoElement(ns
 
 nsCSSKeyword
 CSSParserImpl::LookupKeywordPrefixAware(nsAString& aKeywordStr,
                                         const KTableEntry aKeywordTable[])
 {
   nsCSSKeyword keyword = nsCSSKeywords::LookupKeyword(aKeywordStr);
 
   if (aKeywordTable == nsCSSProps::kDisplayKTable) {
+    // NOTE: This code will be considerably simpler once we can do away with
+    // all Unprefixing Service code, in bug 1259348. But for the time being, we
+    // have to support two different strategies for handling -webkit-box here:
+    // (1) "Native support" (sWebkitPrefixedAliasesEnabled): we assume that
+    //     -webkit-box will parse correctly (via an entry in kDisplayKTable),
+    //     and we simply make a note that we've parsed it (so that we can we
+    //     can give later "-moz-box" styling special handling as noted below).
+    // (2) "Unprefixing Service support" (ShouldUseUnprefixingService): we
+    //     convert "-webkit-box" directly to modern "flex" (& do the same for
+    //     any later "-moz-box" styling).
+    //
+    // Note that sWebkitPrefixedAliasesEnabled and
+    // ShouldUseUnprefixingService() are mutually exlusive, because the latter
+    // explicitly defers to the former.
     if ((keyword == eCSSKeyword__webkit_box ||
-         keyword == eCSSKeyword__webkit_inline_box) &&
-        (sWebkitPrefixedAliasesEnabled || ShouldUseUnprefixingService())) {
-      // 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 (keyword == eCSSKeyword__webkit_box) ?
-        eCSSKeyword_flex : eCSSKeyword_inline_flex;
+         keyword == eCSSKeyword__webkit_inline_box)) {
+      const bool usingUnprefixingService = ShouldUseUnprefixingService();
+      if (sWebkitPrefixedAliasesEnabled || usingUnprefixingService) {
+        // Make a note that we're accepting some "-webkit-{inline-}box" styling,
+        // so we can give special treatment to subsequent "-moz-{inline}-box".
+        // (See special treatment below.)
+        if (mWebkitBoxUnprefixState == eHaveNotUnprefixed) {
+          mWebkitBoxUnprefixState = eHaveUnprefixed;
+        }
+        if (usingUnprefixingService) {
+          // When we're using the unprefixing service, we treat
+          // "display:-webkit-box" as if it were "display:flex"
+          // (and "-webkit-inline-box" as "inline-flex").
+          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").
+    // earlier declaration and we honored 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 treat
+    // "display: -moz-box" & "-moz-inline-box" as if they were simply a
+    // repetition of the webkit equivalent that we already parsed.
     if (mWebkitBoxUnprefixState == eHaveUnprefixed &&
         (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");
+      if (sWebkitPrefixedAliasesEnabled) {
+        return (keyword == eCSSKeyword__moz_box) ?
+          eCSSKeyword__webkit_box : eCSSKeyword__webkit_inline_box;
+      }
+      // (If we get here, we're using the Unprefixing Service, which means
+      // we're unprefixing all the way to modern flexbox display values.)
       return (keyword == eCSSKeyword__moz_box) ?
         eCSSKeyword_flex : eCSSKeyword_inline_flex;
     }
   }
 
   return keyword;
 }