Bug 1322191 part 1 - [css-display] Add style system support for display:flow-root. Enable it by default. r=dholbert
authorMats Palmgren <mats@mozilla.com>
Fri, 23 Dec 2016 19:11:03 +0100
changeset 453573 0c9ef8b75095adb97df95255aafeb6972c731dda
parent 453572 326d947d6bb6b10fc3b985a1093d3862f561f6a0
child 453574 bf6da68ef7864fab6b1d46341bf8960b637b302f
push id39711
push userdmitchell@mozilla.com
push dateFri, 23 Dec 2016 21:59:47 +0000
reviewersdholbert
bugs1322191
milestone53.0a1
Bug 1322191 part 1 - [css-display] Add style system support for display:flow-root. Enable it by default. r=dholbert
layout/base/nsLayoutUtils.cpp
layout/style/nsCSSKeywordList.h
layout/style/nsCSSProps.cpp
layout/style/nsRuleNode.cpp
layout/style/nsStyleConsts.h
layout/style/nsStyleStruct.h
layout/style/test/property_database.js
modules/libpref/init/all.js
--- a/layout/base/nsLayoutUtils.cpp
+++ b/layout/base/nsLayoutUtils.cpp
@@ -144,16 +144,17 @@ using namespace mozilla::dom;
 using namespace mozilla::image;
 using namespace mozilla::layers;
 using namespace mozilla::layout;
 using namespace mozilla::gfx;
 
 #define GRID_ENABLED_PREF_NAME "layout.css.grid.enabled"
 #define GRID_TEMPLATE_SUBGRID_ENABLED_PREF_NAME "layout.css.grid-template-subgrid-value.enabled"
 #define WEBKIT_PREFIXES_ENABLED_PREF_NAME "layout.css.prefixes.webkit"
+#define DISPLAY_FLOW_ROOT_ENABLED_PREF_NAME "layout.css.display-flow-root.enabled"
 #define TEXT_ALIGN_UNSAFE_ENABLED_PREF_NAME "layout.css.text-align-unsafe-value.enabled"
 #define FLOAT_LOGICAL_VALUES_ENABLED_PREF_NAME "layout.css.float-logical-values.enabled"
 #define BG_CLIP_TEXT_ENABLED_PREF_NAME "layout.css.background-clip-text.enabled"
 
 // The time in number of frames that we estimate for a refresh driver
 // to be quiescent
 #define DEFAULT_QUIESCENT_FRAMES 2
 // The time (milliseconds) we estimate is needed between the end of an
@@ -308,16 +309,46 @@ WebkitPrefixEnabledPrefChangeCallback(co
   }
   if (sIndexOfWebkitInlineFlexInDisplayTable >= 0) {
     nsCSSProps::kDisplayKTable[sIndexOfWebkitInlineFlexInDisplayTable].mKeyword =
       isWebkitPrefixSupportEnabled ?
       eCSSKeyword__webkit_inline_flex : eCSSKeyword_UNKNOWN;
   }
 }
 
+// When the pref "layout.css.display-flow-root.enabled" changes, this function is
+// invoked to let us update kDisplayKTable, to selectively disable or restore
+// the entries for "flow-root" in that table.
+static void
+DisplayFlowRootEnabledPrefChangeCallback(const char* aPrefName, void* aClosure)
+{
+  NS_ASSERTION(strcmp(aPrefName, DISPLAY_FLOW_ROOT_ENABLED_PREF_NAME) == 0,
+               "Did you misspell " DISPLAY_FLOW_ROOT_ENABLED_PREF_NAME " ?");
+
+  static bool sIsDisplayFlowRootKeywordIndexInitialized;
+  static int32_t sIndexOfFlowRootInDisplayTable;
+  bool isDisplayFlowRootEnabled =
+    Preferences::GetBool(DISPLAY_FLOW_ROOT_ENABLED_PREF_NAME, false);
+
+  if (!sIsDisplayFlowRootKeywordIndexInitialized) {
+    // First run: find the position of "flow-root" in kDisplayKTable.
+    sIndexOfFlowRootInDisplayTable =
+      nsCSSProps::FindIndexOfKeyword(eCSSKeyword_flow_root,
+                                     nsCSSProps::kDisplayKTable);
+    sIsDisplayFlowRootKeywordIndexInitialized = true;
+  }
+
+  // OK -- now, stomp on or restore the "flow-root" entry in kDisplayKTable,
+  // depending on whether the pref is enabled vs. disabled.
+  if (sIndexOfFlowRootInDisplayTable >= 0) {
+    nsCSSProps::kDisplayKTable[sIndexOfFlowRootInDisplayTable].mKeyword =
+      isDisplayFlowRootEnabled ? eCSSKeyword_flow_root : eCSSKeyword_UNKNOWN;
+  }
+}
+
 // When the pref "layout.css.text-align-unsafe-value.enabled" changes, this
 // function is called to let us update kTextAlignKTable & kTextAlignLastKTable,
 // to selectively disable or restore the entries for "unsafe" in those tables.
 static void
 TextAlignUnsafeEnabledPrefChangeCallback(const char* aPrefName, void* aClosure)
 {
   NS_ASSERTION(strcmp(aPrefName, TEXT_ALIGN_UNSAFE_ENABLED_PREF_NAME) == 0,
                "Did you misspell " TEXT_ALIGN_UNSAFE_ENABLED_PREF_NAME " ?");
@@ -7539,16 +7570,18 @@ struct PrefCallbacks
 };
 static const PrefCallbacks kPrefCallbacks[] = {
   { GRID_ENABLED_PREF_NAME,
     GridEnabledPrefChangeCallback },
   { WEBKIT_PREFIXES_ENABLED_PREF_NAME,
     WebkitPrefixEnabledPrefChangeCallback },
   { TEXT_ALIGN_UNSAFE_ENABLED_PREF_NAME,
     TextAlignUnsafeEnabledPrefChangeCallback },
+  { DISPLAY_FLOW_ROOT_ENABLED_PREF_NAME,
+    DisplayFlowRootEnabledPrefChangeCallback },
   { FLOAT_LOGICAL_VALUES_ENABLED_PREF_NAME,
     FloatLogicalValuesEnabledPrefChangeCallback },
   { BG_CLIP_TEXT_ENABLED_PREF_NAME,
     BackgroundClipTextEnabledPrefChangeCallback },
 };
 
 /* static */
 void
--- a/layout/style/nsCSSKeywordList.h
+++ b/layout/style/nsCSSKeywordList.h
@@ -279,16 +279,17 @@ CSS_KEY(fill-box, fill_box)
 CSS_KEY(first, first)
 CSS_KEY(fit-content, fit_content)
 CSS_KEY(fixed, fixed)
 CSS_KEY(flat, flat)
 CSS_KEY(flex, flex)
 CSS_KEY(flex-end, flex_end)
 CSS_KEY(flex-start, flex_start)
 CSS_KEY(flip, flip)
+CSS_KEY(flow-root, flow_root)
 CSS_KEY(forwards, forwards)
 CSS_KEY(fraktur, fraktur)
 CSS_KEY(from-image, from_image)
 CSS_KEY(full-width, full_width)
 CSS_KEY(fullscreen, fullscreen)
 CSS_KEY(grab, grab)
 CSS_KEY(grabbing, grabbing)
 CSS_KEY(grad, grad)
--- a/layout/style/nsCSSProps.cpp
+++ b/layout/style/nsCSSProps.cpp
@@ -1292,16 +1292,18 @@ KTableEntry nsCSSProps::kDisplayKTable[]
   { eCSSKeyword_grid,                StyleDisplay::Grid },
   { eCSSKeyword_inline_grid,         StyleDisplay::InlineGrid },
   // The next 4 entries are controlled by the layout.css.prefixes.webkit pref.
   { eCSSKeyword__webkit_box,         StyleDisplay::WebkitBox },
   { eCSSKeyword__webkit_inline_box,  StyleDisplay::WebkitInlineBox },
   { eCSSKeyword__webkit_flex,        StyleDisplay::Flex },
   { eCSSKeyword__webkit_inline_flex, StyleDisplay::InlineFlex },
   { eCSSKeyword_contents,            StyleDisplay::Contents },
+  // The next entry is controlled by the layout.css.display-flow-root.enabled pref.
+  { eCSSKeyword_flow_root,           StyleDisplay::FlowRoot },
   { eCSSKeyword_UNKNOWN,             -1 }
 };
 
 const KTableEntry nsCSSProps::kEmptyCellsKTable[] = {
   { eCSSKeyword_show,                 NS_STYLE_TABLE_EMPTY_CELLS_SHOW },
   { eCSSKeyword_hide,                 NS_STYLE_TABLE_EMPTY_CELLS_HIDE },
   { eCSSKeyword_UNKNOWN,              -1 }
 };
--- a/layout/style/nsRuleNode.cpp
+++ b/layout/style/nsRuleNode.cpp
@@ -228,16 +228,17 @@ nsRuleNode::EnsureBlockDisplay(StyleDisp
   case StyleDisplay::None:
   case StyleDisplay::Contents:
     // never change display:none or display:contents *ever*
   case StyleDisplay::Table:
   case StyleDisplay::Block:
   case StyleDisplay::Flex:
   case StyleDisplay::WebkitBox:
   case StyleDisplay::Grid:
+  case StyleDisplay::FlowRoot:
     // do not muck with these at all - already blocks
     // This is equivalent to nsStyleDisplay::IsBlockOutside.  (XXX Maybe we
     // should just call that?)
     // This needs to match the check done in
     // nsCSSFrameConstructor::FindMathMLData for <math>.
     break;
 
   case StyleDisplay::InlineTable:
@@ -271,16 +272,17 @@ nsRuleNode::EnsureBlockDisplay(StyleDisp
 //    then we set it to a valid inline display value
 /* static */
 void
 nsRuleNode::EnsureInlineDisplay(StyleDisplay& display)
 {
   // see if the display value is already inline
   switch (display) {
     case StyleDisplay::Block:
+    case StyleDisplay::FlowRoot:
       display = StyleDisplay::InlineBlock;
       break;
     case StyleDisplay::Table:
       display = StyleDisplay::InlineTable;
       break;
     case StyleDisplay::Flex:
       display = StyleDisplay::InlineFlex;
       break;
--- a/layout/style/nsStyleConsts.h
+++ b/layout/style/nsStyleConsts.h
@@ -492,16 +492,17 @@ enum class FillMode : uint32_t;
 // See nsStyleDisplay
 //
 // NOTE: Order is important! If you change it, make sure to take a look at
 // the FrameConstructorDataByDisplay stuff (both the XUL and non-XUL version),
 // and ensure it's still correct!
 enum class StyleDisplay : uint8_t {
   None = 0,
   Block,
+  FlowRoot,
   Inline,
   InlineBlock,
   ListItem,
   Table,
   InlineTable,
   TableRowGroup,
   TableColumn,
   TableColumnGroup,
--- a/layout/style/nsStyleStruct.h
+++ b/layout/style/nsStyleStruct.h
@@ -2883,29 +2883,31 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsSt
            mAnimationIterationCountCount;
 
   mozilla::StyleShapeOutside mShapeOutside; // [reset]
 
   bool IsBlockInsideStyle() const {
     return mozilla::StyleDisplay::Block == mDisplay ||
            mozilla::StyleDisplay::ListItem == mDisplay ||
            mozilla::StyleDisplay::InlineBlock == mDisplay ||
-           mozilla::StyleDisplay::TableCaption == mDisplay;
+           mozilla::StyleDisplay::TableCaption == mDisplay ||
+           mozilla::StyleDisplay::FlowRoot == mDisplay;
     // Should TABLE_CELL be included here?  They have
     // block frames nested inside of them.
     // (But please audit all callers before changing.)
   }
 
   bool IsBlockOutsideStyle() const {
     return mozilla::StyleDisplay::Block == mDisplay ||
            mozilla::StyleDisplay::Flex == mDisplay ||
            mozilla::StyleDisplay::WebkitBox == mDisplay ||
            mozilla::StyleDisplay::Grid == mDisplay ||
            mozilla::StyleDisplay::ListItem == mDisplay ||
-           mozilla::StyleDisplay::Table == mDisplay;
+           mozilla::StyleDisplay::Table == mDisplay ||
+           mozilla::StyleDisplay::FlowRoot == mDisplay;
   }
 
   static bool IsDisplayTypeInlineOutside(mozilla::StyleDisplay aDisplay) {
     return mozilla::StyleDisplay::Inline == aDisplay ||
            mozilla::StyleDisplay::InlineBlock == aDisplay ||
            mozilla::StyleDisplay::InlineTable == aDisplay ||
            mozilla::StyleDisplay::MozInlineBox == aDisplay ||
            mozilla::StyleDisplay::InlineFlex == aDisplay ||
--- a/layout/style/test/property_database.js
+++ b/layout/style/test/property_database.js
@@ -7886,16 +7886,20 @@ if (IsCSSPropertyPrefEnabled("layout.css
     "text, text"
   );
   gCSSProperties["background"].invalid_values.push(
     "url(404.png) green padding-box text",
     "content-box text url(404.png) blue"
   );
 }
 
+if (IsCSSPropertyPrefEnabled("layout.css.display-flow-root.enabled")) {
+  gCSSProperties["display"].other_values.push("flow-root");
+}
+
 // Copy aliased properties' fields from their alias targets.
 for (var prop in gCSSProperties) {
   var entry = gCSSProperties[prop];
   if (entry.alias_for) {
     var aliasTargetEntry = gCSSProperties[entry.alias_for];
     if (!aliasTargetEntry) {
       ok(false,
          "Alias '" + prop + "' alias_for field, '" + entry.alias_for + "', " +
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -2619,16 +2619,19 @@ pref("layout.css.overflow-clip-box.enabl
 pref("layout.css.grid.enabled", true);
 
 // Is support for CSS "grid-template-{columns,rows}: subgrid X" enabled?
 pref("layout.css.grid-template-subgrid-value.enabled", false);
 
 // Is support for CSS contain enabled?
 pref("layout.css.contain.enabled", false);
 
+// Is support for CSS display:flow-root enabled?
+pref("layout.css.display-flow-root.enabled", true);
+
 // Is support for CSS box-decoration-break enabled?
 pref("layout.css.box-decoration-break.enabled", true);
 
 // Is layout of CSS outline-style:auto enabled?
 pref("layout.css.outline-style-auto.enabled", false);
 
 // Is CSSOM-View scroll-behavior and its MSD smooth scrolling enabled?
 pref("layout.css.scroll-behavior.enabled", true);