From abaea77ccbc3658186b2027d2721451e8acb34a3 Mon Sep 17 00:00:00 2001 From: athenian200 Date: Thu, 3 Sep 2020 18:55:28 -0500 Subject: Issue #1641 - Implement CSS flow-root keyword This is just a clean port of 1322191 and follow-up 1325970. It really seems to add create a new way to access existing code relating to block formatting and floating elements rather than implementing new functionality, and it is mercifully straightforwards. --- layout/base/nsCSSFrameConstructor.cpp | 8 +++++--- layout/base/nsLayoutUtils.cpp | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 3 deletions(-) (limited to 'layout/base') diff --git a/layout/base/nsCSSFrameConstructor.cpp b/layout/base/nsCSSFrameConstructor.cpp index 6642a090d..d28e60740 100644 --- a/layout/base/nsCSSFrameConstructor.cpp +++ b/layout/base/nsCSSFrameConstructor.cpp @@ -2614,7 +2614,8 @@ nsCSSFrameConstructor::ConstructDocElementFrame(Element* aDocEle newFrame = frameItems.FirstChild(); NS_ASSERTION(frameItems.OnlyChild(), "multiple root element frames"); } else { - MOZ_ASSERT(display->mDisplay == StyleDisplay::Block, + MOZ_ASSERT(display->mDisplay == StyleDisplay::Block || + display->mDisplay == StyleDisplay::FlowRoot, "Unhandled display type for root element"); contentFrame = NS_NewBlockFormattingContext(mPresShell, styleContext); nsFrameItems frameItems; @@ -4758,6 +4759,7 @@ nsCSSFrameConstructor::FindDisplayData(const nsStyleDisplay* aDisplay, static const FrameConstructionDataByDisplay sDisplayData[] = { FCDATA_FOR_DISPLAY(StyleDisplay::None, UNREACHABLE_FCDATA()), FCDATA_FOR_DISPLAY(StyleDisplay::Block, UNREACHABLE_FCDATA()), + FCDATA_FOR_DISPLAY(StyleDisplay::FlowRoot, UNREACHABLE_FCDATA()), // To keep the hash table small don't add inline frames (they're // typically things like FONT and B), because we can quickly // find them if we need to. @@ -4943,7 +4945,7 @@ nsCSSFrameConstructor::ConstructNonScrollableBlockWithConstructor( StyleDisplay::InlineBlock == aDisplay->mDisplay || clipPaginatedOverflow) && !aParentFrame->IsSVGText()) { - flags = NS_BLOCK_FLOAT_MGR | NS_BLOCK_MARGIN_ROOT; + flags = NS_BLOCK_FORMATTING_CONTEXT_STATE_BITS; if (clipPaginatedOverflow) { flags |= NS_BLOCK_CLIP_PAGINATED_OVERFLOW; } @@ -5112,7 +5114,7 @@ nsCSSFrameConstructor::FlushAccumulatedBlock(nsFrameConstructorState& aState, // is not a suitable block. nsContainerFrame* blockFrame = NS_NewMathMLmathBlockFrame(mPresShell, blockContext); - blockFrame->AddStateBits(NS_BLOCK_FLOAT_MGR | NS_BLOCK_MARGIN_ROOT); + blockFrame->AddStateBits(NS_BLOCK_FORMATTING_CONTEXT_STATE_BITS); InitAndRestoreFrame(aState, aContent, aParentFrame, blockFrame); ReparentFrames(this, blockFrame, aBlockItems); diff --git a/layout/base/nsLayoutUtils.cpp b/layout/base/nsLayoutUtils.cpp index 5de6f2013..9b204d734 100644 --- a/layout/base/nsLayoutUtils.cpp +++ b/layout/base/nsLayoutUtils.cpp @@ -149,6 +149,7 @@ 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 DISPLAY_CONTENTS_ENABLED_PREF_NAME "layout.css.display-contents.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" @@ -314,6 +315,37 @@ WebkitPrefixEnabledPrefChangeCallback(const char* aPrefName, void* aClosure) } } +// 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.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. @@ -7635,6 +7667,8 @@ static const PrefCallbacks kPrefCallbacks[] = { WebkitPrefixEnabledPrefChangeCallback }, { TEXT_ALIGN_UNSAFE_ENABLED_PREF_NAME, TextAlignUnsafeEnabledPrefChangeCallback }, + { DISPLAY_FLOW_ROOT_ENABLED_PREF_NAME, + DisplayFlowRootEnabledPrefChangeCallback }, { DISPLAY_CONTENTS_ENABLED_PREF_NAME, DisplayContentsEnabledPrefChangeCallback }, { FLOAT_LOGICAL_VALUES_ENABLED_PREF_NAME, -- cgit v1.2.3