Bug 1105571 Part 2: Add a static selector to swap flex containers in for block containers for non-body blocks.
MozReview-Commit-ID: BpFKCl88gBA
--- a/layout/base/nsCSSFrameConstructor.cpp
+++ b/layout/base/nsCSSFrameConstructor.cpp
@@ -2969,16 +2969,95 @@ nsCSSFrameConstructor::ConstructAnonymou
nsContainerFrame* frameAsContainer = do_QueryFrame(aFrame);
AddFCItemsForAnonymousContent(aState, frameAsContainer, anonymousItems, itemsToConstruct);
nsFrameItems frameItems;
ConstructFramesFromItemList(aState, itemsToConstruct, frameAsContainer, frameItems);
frameAsContainer->AppendFrames(kPrincipalList, frameItems);
}
+bool
+nsCSSFrameConstructor::ShouldRemapBlockToFlex(nsFrameConstructorState& aState,
+ const FrameConstructionItem& aItem)
+{
+ // Bug 1105571: The goal here is to identify blocks that would benefit from
+ // being treated as flex containers. Such blocks have css box align styles
+ // either on themselves or their contents
+
+ uint16_t ourJC = aItem.mStyleContext->StylePosition()->mJustifyContent;
+ uint16_t ourAC = aItem.mStyleContext->StylePosition()->mAlignContent;
+ uint16_t ourJI = aItem.mStyleContext->StylePosition()->ComputedJustifyItems(nullptr);
+
+ if (ourJC == NS_STYLE_JUSTIFY_CENTER ||
+ ourJC == NS_STYLE_JUSTIFY_START ||
+ ourJC == NS_STYLE_JUSTIFY_END ||
+ ourJC == NS_STYLE_JUSTIFY_FLEX_START ||
+ ourJC == NS_STYLE_JUSTIFY_FLEX_END ||
+ ourJC == NS_STYLE_JUSTIFY_LEFT ||
+ ourJC == NS_STYLE_JUSTIFY_RIGHT ||
+ ourJC == NS_STYLE_JUSTIFY_SPACE_BETWEEN ||
+ ourJC == NS_STYLE_JUSTIFY_SPACE_EVENLY ||
+ ourJC == NS_STYLE_JUSTIFY_SPACE_AROUND ||
+ ourAC == NS_STYLE_JUSTIFY_CENTER ||
+ ourAC == NS_STYLE_JUSTIFY_START ||
+ ourAC == NS_STYLE_JUSTIFY_END ||
+ ourAC == NS_STYLE_JUSTIFY_FLEX_START ||
+ ourAC == NS_STYLE_JUSTIFY_FLEX_END ||
+ ourAC == NS_STYLE_JUSTIFY_LEFT ||
+ ourAC == NS_STYLE_JUSTIFY_RIGHT ||
+ ourAC == NS_STYLE_JUSTIFY_SPACE_BETWEEN ||
+ ourAC == NS_STYLE_JUSTIFY_SPACE_EVENLY ||
+ ourAC == NS_STYLE_JUSTIFY_SPACE_AROUND ||
+ ourJI == NS_STYLE_JUSTIFY_CENTER ||
+ ourJI == NS_STYLE_JUSTIFY_START ||
+ ourJI == NS_STYLE_JUSTIFY_END ||
+ ourJI == NS_STYLE_JUSTIFY_FLEX_START ||
+ ourJI == NS_STYLE_JUSTIFY_FLEX_END ||
+ ourJI == NS_STYLE_JUSTIFY_LEFT ||
+ ourJI == NS_STYLE_JUSTIFY_RIGHT ||
+ ourJI == NS_STYLE_JUSTIFY_SPACE_BETWEEN ||
+ ourJI == NS_STYLE_JUSTIFY_SPACE_EVENLY ||
+ ourJI == NS_STYLE_JUSTIFY_SPACE_AROUND) {
+ return true;
+ }
+
+ FlattenedChildIterator iter(aItem.mContent);
+ for (nsIContent* child = iter.GetNextChild(); child; child = iter.GetNextChild()) {
+ RefPtr<nsStyleContext> styleContext = ResolveStyleContext(aItem.mStyleContext,
+ child,
+ &aState);
+ uint16_t childJS = styleContext->StylePosition()->mJustifySelf;
+ uint16_t childAS = styleContext->StylePosition()->mAlignSelf;
+ if (childJS == NS_STYLE_JUSTIFY_CENTER ||
+ childJS == NS_STYLE_JUSTIFY_START ||
+ childJS == NS_STYLE_JUSTIFY_END ||
+ childJS == NS_STYLE_JUSTIFY_FLEX_START ||
+ childJS == NS_STYLE_JUSTIFY_FLEX_END ||
+ childJS == NS_STYLE_JUSTIFY_LEFT ||
+ childJS == NS_STYLE_JUSTIFY_RIGHT ||
+ childJS == NS_STYLE_JUSTIFY_SPACE_BETWEEN ||
+ childJS == NS_STYLE_JUSTIFY_SPACE_EVENLY ||
+ childJS == NS_STYLE_JUSTIFY_SPACE_AROUND ||
+ childAS == NS_STYLE_JUSTIFY_CENTER ||
+ childAS == NS_STYLE_JUSTIFY_START ||
+ childAS == NS_STYLE_JUSTIFY_END ||
+ childAS == NS_STYLE_JUSTIFY_FLEX_START ||
+ childAS == NS_STYLE_JUSTIFY_FLEX_END ||
+ childAS == NS_STYLE_JUSTIFY_LEFT ||
+ childAS == NS_STYLE_JUSTIFY_RIGHT ||
+ childAS == NS_STYLE_JUSTIFY_SPACE_BETWEEN ||
+ childAS == NS_STYLE_JUSTIFY_SPACE_EVENLY ||
+ childAS == NS_STYLE_JUSTIFY_SPACE_AROUND) {
+ return true;
+ }
+ }
+
+ return false;
+}
+
nsContainerFrame*
nsCSSFrameConstructor::ConstructPageFrame(nsIPresShell* aPresShell,
nsContainerFrame* aParentFrame,
nsIFrame* aPrevPageFrame,
nsContainerFrame*& aCanvasFrame)
{
nsStyleContext* parentStyleContext = aParentFrame->StyleContext();
StyleSetHandle styleSet = aPresShell->StyleSet();
@@ -4939,19 +5018,23 @@ nsCSSFrameConstructor::ConstructScrollab
nsIFrame*
nsCSSFrameConstructor::ConstructNonScrollableBlock(nsFrameConstructorState& aState,
FrameConstructionItem& aItem,
nsContainerFrame* aParentFrame,
const nsStyleDisplay* aDisplay,
nsFrameItems& aFrameItems)
{
+ ContainerFrameCreationFunc constructor =
+ ShouldRemapBlockToFlex(aState, aItem) ?
+ NS_NewFlexContainerFrame :
+ NS_NewBlockFrame;
return ConstructNonScrollableBlockWithConstructor(aState, aItem, aParentFrame,
aDisplay, aFrameItems,
- NS_NewBlockFrame);
+ constructor);
}
nsIFrame*
nsCSSFrameConstructor::ConstructNonScrollableBlockWithConstructor(
nsFrameConstructorState& aState,
FrameConstructionItem& aItem,
nsContainerFrame* aParentFrame,
const nsStyleDisplay* aDisplay,
@@ -11111,16 +11194,17 @@ nsCSSFrameConstructor::ProcessChildren(n
nsContentUtils::eXUL_PROPERTIES,
message,
params, ArrayLength(params));
}
RefPtr<nsStyleContext> blockSC = mPresShell->StyleSet()->
ResolveInheritingAnonymousBoxStyle(nsCSSAnonBoxes::mozXULAnonymousBlock,
frameStyleContext);
+
nsContainerFrame* containerFrame = NS_NewBlockFrame(mPresShell, blockSC);
// We might, in theory, want to set NS_BLOCK_FLOAT_MGR and
// NS_BLOCK_MARGIN_ROOT, but I think it's a bad idea given that
// a real block placed here wouldn't get those set on it.
InitAndRestoreFrame(aState, aContent, aFrame, containerFrame, false);
NS_ASSERTION(!containerFrame->HasView(), "need to do view reparenting");
@@ -12233,16 +12317,17 @@ nsCSSFrameConstructor::CreateIBSiblings(
NS_PRECONDITION(aChildItems.NotEmpty(), "Should have child items");
NS_PRECONDITION(!aChildItems.FirstChild()->IsInlineOutside(),
"Must have list starting with block");
// The initial run of blocks belongs to an anonymous block that we create
// right now. The anonymous block will be the parent of these block
// children of the inline.
nsContainerFrame* containerFrame = NS_NewBlockFrame(mPresShell, blockSC);
+
InitAndRestoreFrame(aState, content, parentFrame, containerFrame, false);
// Find the first non-block child which defines the end of our block kids
// and the start of our next inline's kids
nsFrameList::FrameLinkEnumerator firstNonBlock =
FindFirstNonBlock(aChildItems);
nsFrameList blockKids = aChildItems.ExtractHead(firstNonBlock);
--- a/layout/base/nsCSSFrameConstructor.h
+++ b/layout/base/nsCSSFrameConstructor.h
@@ -343,16 +343,19 @@ public:
{
return mTempFrameTreeState;
}
private:
struct FrameConstructionItem;
class FrameConstructionItemList;
+ bool ShouldRemapBlockToFlex(nsFrameConstructorState& aState,
+ const FrameConstructionItem& aItem);
+
nsContainerFrame* ConstructPageFrame(nsIPresShell* aPresShell,
nsContainerFrame* aParentFrame,
nsIFrame* aPrevPageFrame,
nsContainerFrame*& aCanvasFrame);
void InitAndRestoreFrame (const nsFrameConstructorState& aState,
nsIContent* aContent,
nsContainerFrame* aParentFrame,