From bcd179e7d1f7553233f6eb498df355db14d92c97 Mon Sep 17 00:00:00 2001 From: Mats Palmgren Date: Thu, 20 Nov 2014 18:24:09 +0000 Subject: [PATCH] Bug 907396 - Put display:contents support behind a pref - disabled by default. r=dholbert --- layout/base/nsLayoutUtils.cpp | 35 +++++++++++++++++++++++++++++++++++ layout/style/nsCSSProps.h | 4 ++-- modules/libpref/init/all.js | 3 +++ 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/layout/base/nsLayoutUtils.cpp b/layout/base/nsLayoutUtils.cpp index 86a0d30c592..932ba5964b3 100644 --- a/layout/base/nsLayoutUtils.cpp +++ b/layout/base/nsLayoutUtils.cpp @@ -114,6 +114,7 @@ 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" #ifdef DEBUG @@ -295,6 +296,36 @@ StickyEnabledPrefChangeCallback(const char* aPrefName, void* aClosure) isStickyEnabled ? eCSSKeyword_sticky : eCSSKeyword_UNKNOWN; } +// When the pref "layout.css.display-contents.enabled" changes, this function is +// invoked to let us update kDisplayKTable, to selectively disable or restore +// the entries for "contents" in that table. +static void +DisplayContentsEnabledPrefChangeCallback(const char* aPrefName, void* aClosure) +{ + NS_ASSERTION(strcmp(aPrefName, DISPLAY_CONTENTS_ENABLED_PREF_NAME) == 0, + "Did you misspell " DISPLAY_CONTENTS_ENABLED_PREF_NAME " ?"); + + static bool sIsDisplayContentsKeywordIndexInitialized; + static int32_t sIndexOfContentsInDisplayTable; + bool isDisplayContentsEnabled = + Preferences::GetBool(DISPLAY_CONTENTS_ENABLED_PREF_NAME, false); + + if (!sIsDisplayContentsKeywordIndexInitialized) { + // First run: find the position of "contents" in kDisplayKTable. + sIndexOfContentsInDisplayTable = + nsCSSProps::FindIndexOfKeyword(eCSSKeyword_contents, + nsCSSProps::kDisplayKTable); + sIsDisplayContentsKeywordIndexInitialized = true; + } + + // OK -- now, stomp on or restore the "contents" entry in kDisplayKTable, + // depending on whether the pref is enabled vs. disabled. + if (sIndexOfContentsInDisplayTable >= 0) { + nsCSSProps::kDisplayKTable[sIndexOfContentsInDisplayTable] = + isDisplayContentsEnabled ? eCSSKeyword_contents : eCSSKeyword_UNKNOWN; + } +} + // When the pref "layout.css.text-align-true-value.enabled" changes, this // function is called to let us update kTextAlignKTable & kTextAlignLastKTable, // to selectively disable or restore the entries for "true" in those tables. @@ -6670,6 +6701,10 @@ nsLayoutUtils::Initialize() StickyEnabledPrefChangeCallback(STICKY_ENABLED_PREF_NAME, nullptr); 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); diff --git a/layout/style/nsCSSProps.h b/layout/style/nsCSSProps.h index 5df212f32ba..1b68ade5e18 100644 --- a/layout/style/nsCSSProps.h +++ b/layout/style/nsCSSProps.h @@ -564,8 +564,8 @@ public: static const KTableValue kControlCharacterVisibilityKTable[]; static const KTableValue kCursorKTable[]; static const KTableValue kDirectionKTable[]; - // Not const because we modify its entries when the pref - // "layout.css.grid.enabled" changes: + // Not const because we modify its entries when various + // "layout.css.*.enabled" prefs changes: static KTableValue kDisplayKTable[]; static const KTableValue kElevationKTable[]; static const KTableValue kEmptyCellsKTable[]; diff --git a/modules/libpref/init/all.js b/modules/libpref/init/all.js index bde27754488..b4a0df9c707 100644 --- a/modules/libpref/init/all.js +++ b/modules/libpref/init/all.js @@ -2156,6 +2156,9 @@ pref("layout.css.grid.enabled", false); // otherwise needed) are removed. pref("layout.css.ruby.enabled", false); +// Is support for CSS display:contents enabled? +pref("layout.css.display-contents.enabled", false); + // Is support for CSS box-decoration-break enabled? pref("layout.css.box-decoration-break.enabled", true);