Bug 1122918 - Put the logical values for 'float' and 'clear' behind a pref, and enable them only on nightly builds and for B2G. r=heycam
authorJonathan Kew <jkew@mozilla.com>
Tue, 10 Nov 2015 09:07:01 +0000
changeset 271975 66862e989b01a262f43f7ea84c8b18503a09dc55
parent 271974 a1fc3b32d69f4affc07b81c29af6b9cb19d44f06
child 271976 9184d15b52be414d46f920feb0a1710949b53c69
push id29659
push usercbook@mozilla.com
push dateWed, 11 Nov 2015 11:43:09 +0000
treeherdermozilla-central@84a7cf29f4f1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersheycam
bugs1122918
milestone45.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
Bug 1122918 - Put the logical values for 'float' and 'clear' behind a pref, and enable them only on nightly builds and for B2G. r=heycam
layout/base/nsLayoutUtils.cpp
layout/reftests/floats/reftest.list
layout/style/nsCSSProps.cpp
layout/style/nsCSSProps.h
layout/style/test/property_database.js
modules/libpref/init/all.js
--- a/layout/base/nsLayoutUtils.cpp
+++ b/layout/base/nsLayoutUtils.cpp
@@ -130,16 +130,17 @@ using namespace mozilla::layers;
 using namespace mozilla::layout;
 using namespace mozilla::gfx;
 
 #define GRID_ENABLED_PREF_NAME "layout.css.grid.enabled"
 #define RUBY_ENABLED_PREF_NAME "layout.css.ruby.enabled"
 #define STICKY_ENABLED_PREF_NAME "layout.css.sticky.enabled"
 #define DISPLAY_CONTENTS_ENABLED_PREF_NAME "layout.css.display-contents.enabled"
 #define TEXT_ALIGN_TRUE_ENABLED_PREF_NAME "layout.css.text-align-true-value.enabled"
+#define FLOAT_LOGICAL_VALUES_ENABLED_PREF_NAME "layout.css.float-logical-values.enabled"
 
 #ifdef DEBUG
 // TODO: remove, see bug 598468.
 bool nsLayoutUtils::gPreventAssertInCompareTreePosition = false;
 #endif // DEBUG
 
 typedef FrameMetrics::ViewID ViewID;
 typedef nsStyleTransformMatrix::TransformReferenceBox TransformReferenceBox;
@@ -379,16 +380,71 @@ TextAlignTrueEnabledPrefChangeCallback(c
   MOZ_ASSERT(sIndexOfTrueInTextAlignTable >= 0);
   nsCSSProps::kTextAlignKTable[sIndexOfTrueInTextAlignTable] =
     isTextAlignTrueEnabled ? eCSSKeyword_true : eCSSKeyword_UNKNOWN;
   MOZ_ASSERT(sIndexOfTrueInTextAlignLastTable >= 0);
   nsCSSProps::kTextAlignLastKTable[sIndexOfTrueInTextAlignLastTable] =
     isTextAlignTrueEnabled ? eCSSKeyword_true : eCSSKeyword_UNKNOWN;
 }
 
+// When the pref "layout.css.float-logical-values.enabled" changes, this
+// function is called to let us update kFloatKTable & kClearKTable,
+// to selectively disable or restore the entries for logical values
+// (inline-start and inline-end) in those tables.
+static void
+FloatLogicalValuesEnabledPrefChangeCallback(const char* aPrefName,
+                                            void* aClosure)
+{
+  NS_ASSERTION(strcmp(aPrefName, FLOAT_LOGICAL_VALUES_ENABLED_PREF_NAME) == 0,
+               "Did you misspell " FLOAT_LOGICAL_VALUES_ENABLED_PREF_NAME " ?");
+
+  static bool sIsInitialized;
+  static int32_t sIndexOfInlineStartInFloatTable;
+  static int32_t sIndexOfInlineEndInFloatTable;
+  static int32_t sIndexOfInlineStartInClearTable;
+  static int32_t sIndexOfInlineEndInClearTable;
+  bool isFloatLogicalValuesEnabled =
+    Preferences::GetBool(FLOAT_LOGICAL_VALUES_ENABLED_PREF_NAME, false);
+
+  if (!sIsInitialized) {
+    // First run: find the position of "inline-start" in kFloatKTable.
+    sIndexOfInlineStartInFloatTable =
+      nsCSSProps::FindIndexOfKeyword(eCSSKeyword_inline_start,
+                                     nsCSSProps::kFloatKTable);
+    // First run: find the position of "inline-end" in kFloatKTable.
+    sIndexOfInlineEndInFloatTable =
+      nsCSSProps::FindIndexOfKeyword(eCSSKeyword_inline_end,
+                                     nsCSSProps::kFloatKTable);
+    // First run: find the position of "inline-start" in kClearKTable.
+    sIndexOfInlineStartInClearTable =
+      nsCSSProps::FindIndexOfKeyword(eCSSKeyword_inline_start,
+                                     nsCSSProps::kClearKTable);
+    // First run: find the position of "inline-end" in kClearKTable.
+    sIndexOfInlineEndInClearTable =
+      nsCSSProps::FindIndexOfKeyword(eCSSKeyword_inline_end,
+                                     nsCSSProps::kClearKTable);
+    sIsInitialized = true;
+  }
+
+  // OK -- now, stomp on or restore the logical entries in the keyword tables,
+  // depending on whether the pref is enabled vs. disabled.
+  MOZ_ASSERT(sIndexOfInlineStartInFloatTable >= 0);
+  nsCSSProps::kFloatKTable[sIndexOfInlineStartInFloatTable] =
+    isFloatLogicalValuesEnabled ? eCSSKeyword_inline_start : eCSSKeyword_UNKNOWN;
+  MOZ_ASSERT(sIndexOfInlineEndInFloatTable >= 0);
+  nsCSSProps::kFloatKTable[sIndexOfInlineEndInFloatTable] =
+    isFloatLogicalValuesEnabled ? eCSSKeyword_inline_end : eCSSKeyword_UNKNOWN;
+  MOZ_ASSERT(sIndexOfInlineStartInClearTable >= 0);
+  nsCSSProps::kClearKTable[sIndexOfInlineStartInClearTable] =
+    isFloatLogicalValuesEnabled ? eCSSKeyword_inline_start : eCSSKeyword_UNKNOWN;
+  MOZ_ASSERT(sIndexOfInlineEndInClearTable >= 0);
+  nsCSSProps::kClearKTable[sIndexOfInlineEndInClearTable] =
+    isFloatLogicalValuesEnabled ? eCSSKeyword_inline_end : eCSSKeyword_UNKNOWN;
+}
+
 bool
 nsLayoutUtils::HasAnimationsForCompositor(const nsIFrame* aFrame,
                                           nsCSSProperty aProperty)
 {
   nsPresContext* presContext = aFrame->PresContext();
   return presContext->AnimationManager()->GetAnimationsForCompositor(aFrame, aProperty) ||
          presContext->TransitionManager()->GetAnimationsForCompositor(aFrame, aProperty);
 }
@@ -7364,16 +7420,20 @@ nsLayoutUtils::Initialize()
   Preferences::RegisterCallback(TextAlignTrueEnabledPrefChangeCallback,
                                 TEXT_ALIGN_TRUE_ENABLED_PREF_NAME);
   Preferences::RegisterCallback(DisplayContentsEnabledPrefChangeCallback,
                                 DISPLAY_CONTENTS_ENABLED_PREF_NAME);
   DisplayContentsEnabledPrefChangeCallback(DISPLAY_CONTENTS_ENABLED_PREF_NAME,
                                            nullptr);
   TextAlignTrueEnabledPrefChangeCallback(TEXT_ALIGN_TRUE_ENABLED_PREF_NAME,
                                          nullptr);
+  Preferences::RegisterCallback(FloatLogicalValuesEnabledPrefChangeCallback,
+                                FLOAT_LOGICAL_VALUES_ENABLED_PREF_NAME);
+  FloatLogicalValuesEnabledPrefChangeCallback(FLOAT_LOGICAL_VALUES_ENABLED_PREF_NAME,
+                                              nullptr);
 
   nsComputedDOMStyle::RegisterPrefChangeCallbacks();
 }
 
 /* static */
 void
 nsLayoutUtils::Shutdown()
 {
--- a/layout/reftests/floats/reftest.list
+++ b/layout/reftests/floats/reftest.list
@@ -85,20 +85,20 @@ default-preferences pref(layout.css.vert
 == float-in-rtl-vrl-4b.html float-in-rtl-vrl-4-ref.html
 == float-in-rtl-vrl-4c.html float-in-rtl-vrl-4-ref.html
 == float-in-rtl-vrl-4d.html float-in-rtl-vrl-4-ref.html
 fuzzy-if(OSX==1010,26,7) fuzzy-if(Android,16,2) == orthogonal-floats-1a.html orthogonal-floats-1-ref.html
 fuzzy-if(OSX==1010,26,7) == orthogonal-floats-1b.html orthogonal-floats-1-ref.html
 fuzzy-if(OSX==1010,103,802) fuzzy-if(winWidget,116,700) HTTP(..) == orthogonal-floats-1c.html orthogonal-floats-1-ref.html
 fuzzy-if(OSX==1010,103,802) fuzzy-if(winWidget,116,700) HTTP(..) == orthogonal-floats-1d.html orthogonal-floats-1-ref.html
 
-== logical-float-side-1.html logical-float-side-1-ref.html
-== logical-float-side-2.html logical-float-side-2-ref.html
-== logical-float-side-3.html logical-float-side-3-ref.html
-== logical-float-side-4.html logical-float-side-4-ref.html
+pref(layout.css.float-logical-values.enabled,true) == logical-float-side-1.html logical-float-side-1-ref.html
+pref(layout.css.float-logical-values.enabled,true) == logical-float-side-2.html logical-float-side-2-ref.html
+pref(layout.css.float-logical-values.enabled,true) == logical-float-side-3.html logical-float-side-3-ref.html
+pref(layout.css.float-logical-values.enabled,true) == logical-float-side-4.html logical-float-side-4-ref.html
 
 == float-in-rtl-slr-1a.html float-in-rtl-slr-1-ref.html
 == float-in-rtl-slr-1b.html float-in-rtl-slr-1-ref.html
 == float-in-rtl-slr-1c.html float-in-rtl-slr-1-ref.html
 == float-in-rtl-slr-1d.html float-in-rtl-slr-1-ref.html
 == float-in-rtl-slr-2a.html float-in-rtl-slr-2-ref.html
 == float-in-rtl-slr-2b.html float-in-rtl-slr-2-ref.html
 == float-in-rtl-slr-2c.html float-in-rtl-slr-2-ref.html
--- a/layout/style/nsCSSProps.cpp
+++ b/layout/style/nsCSSProps.cpp
@@ -999,17 +999,17 @@ const KTableValue nsCSSProps::kCaptionSi
   eCSSKeyword_right,                NS_STYLE_CAPTION_SIDE_RIGHT,
   eCSSKeyword_bottom,               NS_STYLE_CAPTION_SIDE_BOTTOM,
   eCSSKeyword_left,                 NS_STYLE_CAPTION_SIDE_LEFT,
   eCSSKeyword_top_outside,          NS_STYLE_CAPTION_SIDE_TOP_OUTSIDE,
   eCSSKeyword_bottom_outside,       NS_STYLE_CAPTION_SIDE_BOTTOM_OUTSIDE,
   eCSSKeyword_UNKNOWN,              -1
 };
 
-const KTableValue nsCSSProps::kClearKTable[] = {
+KTableValue nsCSSProps::kClearKTable[] = {
   eCSSKeyword_none,         NS_STYLE_CLEAR_NONE,
   eCSSKeyword_left,         NS_STYLE_CLEAR_LEFT,
   eCSSKeyword_right,        NS_STYLE_CLEAR_RIGHT,
   eCSSKeyword_inline_start, NS_STYLE_CLEAR_INLINE_START,
   eCSSKeyword_inline_end,   NS_STYLE_CLEAR_INLINE_END,
   eCSSKeyword_both,         NS_STYLE_CLEAR_BOTH,
   eCSSKeyword_UNKNOWN,-1
 };
@@ -1349,17 +1349,17 @@ const KTableValue nsCSSProps::kFlexWrapK
 
 const KTableValue nsCSSProps::kHyphensKTable[] = {
   eCSSKeyword_none, NS_STYLE_HYPHENS_NONE,
   eCSSKeyword_manual, NS_STYLE_HYPHENS_MANUAL,
   eCSSKeyword_auto, NS_STYLE_HYPHENS_AUTO,
   eCSSKeyword_UNKNOWN,-1
 };
 
-const KTableValue nsCSSProps::kFloatKTable[] = {
+KTableValue nsCSSProps::kFloatKTable[] = {
   eCSSKeyword_none,         NS_STYLE_FLOAT_NONE,
   eCSSKeyword_left,         NS_STYLE_FLOAT_LEFT,
   eCSSKeyword_right,        NS_STYLE_FLOAT_RIGHT,
   eCSSKeyword_inline_start, NS_STYLE_FLOAT_INLINE_START,
   eCSSKeyword_inline_end,   NS_STYLE_FLOAT_INLINE_END,
   eCSSKeyword_UNKNOWN,-1
 };
 
--- a/layout/style/nsCSSProps.h
+++ b/layout/style/nsCSSProps.h
@@ -672,17 +672,19 @@ public:
   static const KTableValue kTextAnchorKTable[];
   static const KTableValue kTextRenderingKTable[];
   static const KTableValue kColorInterpolationKTable[];
   static const KTableValue kColumnFillKTable[];
   static const KTableValue kBoxPropSourceKTable[];
   static const KTableValue kBoxShadowTypeKTable[];
   static const KTableValue kBoxSizingKTable[];
   static const KTableValue kCaptionSideKTable[];
-  static const KTableValue kClearKTable[];
+  // Not const because we modify its entries when the pref
+  // "layout.css.float-logical-values.enabled" changes:
+  static KTableValue kClearKTable[];
   static const KTableValue kColorKTable[];
   static const KTableValue kContentKTable[];
   static const KTableValue kControlCharacterVisibilityKTable[];
   static const KTableValue kCursorKTable[];
   static const KTableValue kDirectionKTable[];
   // Not const because we modify its entries when various 
   // "layout.css.*.enabled" prefs changes:
   static KTableValue kDisplayKTable[];
@@ -698,17 +700,19 @@ public:
   static const KTableValue kAlignAutoBaseline[]; // 'auto/baseline/last-baseline'
   static const KTableValue kAlignContentDistribution[]; // <content-distribution>
   static const KTableValue kAlignContentPosition[]; // <content-position>
   static const KTableValue kAlignSelfKTable[];
   static const KTableValue kJustifyContentKTable[];
   // ------------------------------------------------------------------
   static const KTableValue kFlexDirectionKTable[];
   static const KTableValue kFlexWrapKTable[];
-  static const KTableValue kFloatKTable[];
+  // Not const because we modify its entries when the pref
+  // "layout.css.float-logical-values.enabled" changes:
+  static KTableValue kFloatKTable[];
   static const KTableValue kFloatEdgeKTable[];
   static const KTableValue kFontKTable[];
   static const KTableValue kFontKerningKTable[];
   static const KTableValue kFontSizeKTable[];
   static const KTableValue kFontSmoothingKTable[];
   static const KTableValue kFontStretchKTable[];
   static const KTableValue kFontStyleKTable[];
   static const KTableValue kFontSynthesisKTable[];
--- a/layout/style/test/property_database.js
+++ b/layout/style/test/property_database.js
@@ -2493,17 +2493,17 @@ var gCSSProperties = {
     other_values: [ "bottom", "left", "right", "top-outside", "bottom-outside" ],
     invalid_values: []
   },
   "clear": {
     domProp: "clear",
     inherited: false,
     type: CSS_TYPE_LONGHAND,
     initial_values: [ "none" ],
-    other_values: [ "left", "right", "both", "inline-start", "inline-end" ],
+    other_values: [ "left", "right", "both" ],
     invalid_values: []
   },
   "clip": {
     domProp: "clip",
     inherited: false,
     type: CSS_TYPE_LONGHAND,
     initial_values: [ "auto" ],
     other_values: [ "rect(0 0 0 0)", "rect(auto,auto,auto,auto)", "rect(3px, 4px, 4em, 0)", "rect(auto, 3em, 4pt, 2px)", "rect(2px 3px 4px 5px)" ],
@@ -2597,17 +2597,17 @@ var gCSSProperties = {
     other_values: [ "hide" ],
     invalid_values: []
   },
   "float": {
     domProp: "cssFloat",
     inherited: false,
     type: CSS_TYPE_LONGHAND,
     initial_values: [ "none" ],
-    other_values: [ "left", "right", "inline-start", "inline-end" ],
+    other_values: [ "left", "right" ],
     invalid_values: []
   },
   "font": {
     domProp: "font",
     inherited: true,
     type: CSS_TYPE_TRUE_SHORTHAND,
     subproperties: [ "font-style", "font-variant", "font-weight", "font-size", "line-height", "font-family", "font-stretch",
                      "font-size-adjust", "font-feature-settings", "font-language-override",
@@ -6801,16 +6801,28 @@ if (IsCSSPropertyPrefEnabled("layout.css
   }
   if (IsCSSPropertyPrefEnabled("layout.css.text-align-true-value.enabled")) {
     gCSSProperties["text-align"].other_values.push("true left");
   } else {
     gCSSProperties["text-align"].invalid_values.push("true left");
   }
 }
 
+if (IsCSSPropertyPrefEnabled("layout.css.float-logical-values.enabled")) {
+  gCSSProperties["float"].other_values.push("inline-start");
+  gCSSProperties["float"].other_values.push("inline-end");
+  gCSSProperties["clear"].other_values.push("inline-start");
+  gCSSProperties["clear"].other_values.push("inline-end");
+} else {
+  gCSSProperties["float"].invalid_values.push("inline-start");
+  gCSSProperties["float"].invalid_values.push("inline-end");
+  gCSSProperties["clear"].invalid_values.push("inline-start");
+  gCSSProperties["clear"].invalid_values.push("inline-end");
+}
+
 // 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
@@ -2291,16 +2291,24 @@ pref("layout.css.convertFromNode.enabled
 pref("layout.css.unicode-range.enabled", false);
 #else
 pref("layout.css.unicode-range.enabled", true);
 #endif
 
 // Is support for CSS "text-align: true X" enabled?
 pref("layout.css.text-align-true-value.enabled", false);
 
+// Is support for CSS "float: inline-{start,end}" and
+// "clear: inline-{start,end}" enabled?
+#if defined(MOZ_B2G) || defined(NIGHTLY_BUILD)
+pref("layout.css.float-logical-values.enabled", true);
+#else
+pref("layout.css.float-logical-values.enabled", false);
+#endif
+
 // Is support for the CSS4 image-orientation property enabled?
 pref("layout.css.image-orientation.enabled", true);
 
 // Are sets of prefixed properties supported?
 pref("layout.css.prefixes.border-image", true);
 pref("layout.css.prefixes.transforms", true);
 pref("layout.css.prefixes.transitions", true);
 pref("layout.css.prefixes.animations", true);