From 6393c0d04d1b015b023b6ef4c7bd040970dc6501 Mon Sep 17 00:00:00 2001 From: Jonathan Kew Date: Tue, 10 Nov 2015 09:07:01 +0000 Subject: [PATCH] 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 | 60 ++++++++++++++++++++++++++ layout/reftests/floats/reftest.list | 8 ++-- layout/style/nsCSSProps.cpp | 4 +- layout/style/nsCSSProps.h | 8 +++- layout/style/test/property_database.js | 16 ++++++- modules/libpref/init/all.js | 8 ++++ 6 files changed, 94 insertions(+), 10 deletions(-) diff --git a/layout/base/nsLayoutUtils.cpp b/layout/base/nsLayoutUtils.cpp index 4e639915f4e..4c9fffb22a4 100644 --- a/layout/base/nsLayoutUtils.cpp +++ b/layout/base/nsLayoutUtils.cpp @@ -135,6 +135,7 @@ using namespace mozilla::gfx; #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. @@ -384,6 +385,61 @@ TextAlignTrueEnabledPrefChangeCallback(const char* aPrefName, void* aClosure) 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) @@ -7369,6 +7425,10 @@ nsLayoutUtils::Initialize() 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(); } diff --git a/layout/reftests/floats/reftest.list b/layout/reftests/floats/reftest.list index f66a2a01907..801074d4b87 100644 --- a/layout/reftests/floats/reftest.list +++ b/layout/reftests/floats/reftest.list @@ -90,10 +90,10 @@ fuzzy-if(OSX==1010,26,7) == orthogonal-floats-1b.html orthogonal-floats-1-ref.ht 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 diff --git a/layout/style/nsCSSProps.cpp b/layout/style/nsCSSProps.cpp index 5fd7de60fdc..80c90a288a3 100644 --- a/layout/style/nsCSSProps.cpp +++ b/layout/style/nsCSSProps.cpp @@ -1004,7 +1004,7 @@ const KTableValue nsCSSProps::kCaptionSideKTable[] = { 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, @@ -1354,7 +1354,7 @@ const KTableValue nsCSSProps::kHyphensKTable[] = { 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, diff --git a/layout/style/nsCSSProps.h b/layout/style/nsCSSProps.h index 30f75593f88..265e95b8baa 100644 --- a/layout/style/nsCSSProps.h +++ b/layout/style/nsCSSProps.h @@ -677,7 +677,9 @@ public: 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[]; @@ -703,7 +705,9 @@ public: // ------------------------------------------------------------------ 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[]; diff --git a/layout/style/test/property_database.js b/layout/style/test/property_database.js index 04452ab004d..12ef71de725 100644 --- a/layout/style/test/property_database.js +++ b/layout/style/test/property_database.js @@ -2498,7 +2498,7 @@ var gCSSProperties = { 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": { @@ -2602,7 +2602,7 @@ var gCSSProperties = { inherited: false, type: CSS_TYPE_LONGHAND, initial_values: [ "none" ], - other_values: [ "left", "right", "inline-start", "inline-end" ], + other_values: [ "left", "right" ], invalid_values: [] }, "font": { @@ -6806,6 +6806,18 @@ if (IsCSSPropertyPrefEnabled("layout.css.unset-value.enabled")) { } } +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]; diff --git a/modules/libpref/init/all.js b/modules/libpref/init/all.js index ed53f787417..ad9b92331e2 100644 --- a/modules/libpref/init/all.js +++ b/modules/libpref/init/all.js @@ -2296,6 +2296,14 @@ pref("layout.css.unicode-range.enabled", true); // 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);