Bug 1321698 part 2: Use the new frame state bit to check for -webkit-box containers. r=mats

Note that at the callsites in nsCSSFrameConstructor.cpp, we have to also check
the frame type (since the frame state bit is in a range of bits whose meaning
differs depending on frame type).  The first change in this patch is the
addition of a convenience fucntion that checks both the frame type as well as
the frame state bit.

MozReview-Commit-ID: DEOThTX5NAO

--HG--
extra : rebase_source : 95e86eec663b3ef2e7bb86214871fcd3ea86057c
This commit is contained in:
Daniel Holbert 2016-12-02 10:32:31 -08:00
Родитель f2e0c89b68
Коммит a720a44ada
3 изменённых файлов: 45 добавлений и 19 удалений

Просмотреть файл

@ -340,6 +340,20 @@ IsFlexOrGridContainer(const nsIFrame* aFrame)
t == nsGkAtoms::gridContainerFrame;
}
// Returns true IFF the given nsIFrame is a nsFlexContainerFrame and
// represents a -webkit-{inline-}box container. The frame's GetType() result is
// passed as a separate argument, since in most cases, the caller will have
// looked it up already, and we'd rather not make redundant calls to the
// virtual GetType() method.
static inline bool
IsFlexContainerForLegacyBox(const nsIFrame* aFrame,
const nsIAtom* aFrameType)
{
MOZ_ASSERT(aFrame->GetType() == aFrameType, "wrong aFrameType was passed");
return aFrameType == nsGkAtoms::flexContainerFrame &&
aFrame->HasAnyStateBits(NS_STATE_FLEX_IS_LEGACY_WEBKIT_BOX);
}
#if DEBUG
static void
AssertAnonymousFlexOrGridItemParent(const nsIFrame* aChild,
@ -9921,13 +9935,17 @@ nsCSSFrameConstructor::CreateNeededAnonFlexOrGridItems(
FrameConstructionItemList& aItems,
nsIFrame* aParentFrame)
{
if (aItems.IsEmpty() ||
!::IsFlexOrGridContainer(aParentFrame)) {
if (aItems.IsEmpty()) {
return;
}
const nsIAtom* parentType = aParentFrame->GetType();
if (parentType != nsGkAtoms::flexContainerFrame &&
parentType != nsGkAtoms::gridContainerFrame) {
return;
}
const bool isWebkitBox = nsFlexContainerFrame::IsLegacyBox(aParentFrame);
const bool isWebkitBox = IsFlexContainerForLegacyBox(aParentFrame,
parentType);
FCItemIterator iter(aItems);
do {
// Advance iter past children that don't want to be wrapped
@ -12219,12 +12237,14 @@ nsCSSFrameConstructor::WipeContainingBlock(nsFrameConstructorState& aState,
// Situation #2 is a flex or grid container frame into which we're inserting
// new inline non-replaced children, adjacent to an existing anonymous
// flex or grid item.
if (::IsFlexOrGridContainer(aFrame)) {
nsIAtom* frameType = aFrame->GetType();
if (frameType == nsGkAtoms::flexContainerFrame ||
frameType == nsGkAtoms::gridContainerFrame) {
FCItemIterator iter(aItems);
// Check if we're adding to-be-wrapped content right *after* an existing
// anonymous flex or grid item (which would need to absorb this content).
const bool isWebkitBox = nsFlexContainerFrame::IsLegacyBox(aFrame);
const bool isWebkitBox = IsFlexContainerForLegacyBox(aFrame, frameType);
if (aPrevSibling && IsAnonymousFlexOrGridItem(aPrevSibling) &&
iter.item().NeedsAnonFlexOrGridItem(aState, isWebkitBox)) {
RecreateFramesForContent(aFrame->GetContent(), true,
@ -12264,7 +12284,8 @@ nsCSSFrameConstructor::WipeContainingBlock(nsFrameConstructorState& aState,
// Skip over things that _do_ need an anonymous flex item, because
// they're perfectly happy to go here -- they won't cause a reframe.
nsIFrame* containerFrame = aFrame->GetParent();
const bool isWebkitBox = nsFlexContainerFrame::IsLegacyBox(containerFrame);
const bool isWebkitBox =
IsFlexContainerForLegacyBox(containerFrame, containerFrame->GetType());
if (!iter.SkipItemsThatNeedAnonFlexOrGridItem(aState,
isWebkitBox)) {
// We hit something that _doesn't_ need an anonymous flex item!
@ -12288,7 +12309,6 @@ nsCSSFrameConstructor::WipeContainingBlock(nsFrameConstructorState& aState,
// their sibling changes.
// 2) The first effective child of a ruby frame must always be a ruby
// base container. It should be created or destroyed accordingly.
nsIAtom* frameType = aFrame->GetType();
if (IsRubyPseudo(aFrame) ||
frameType == nsGkAtoms::rubyFrame ||
RubyUtils::IsRubyContainerBox(frameType)) {

Просмотреть файл

@ -87,10 +87,22 @@ IsDisplayValueLegacyBox(const nsStyleDisplay* aStyleDisp)
aStyleDisp->mDisplay == mozilla::StyleDisplay::WebkitInlineBox;
}
// Returns true if aFlexContainer is the frame for an element with
// "display:-webkit-box" or "display:-webkit-inline-box". aFlexContainer is
// expected to be an instance of nsFlexContainerFrame (enforced with an assert);
// otherwise, this function's state-bit-check here is bogus.
static bool
IsLegacyBox(const nsIFrame* aFlexContainer)
{
MOZ_ASSERT(aFlexContainer->GetType() == nsGkAtoms::flexContainerFrame,
"only flex containers may be passed to this function");
return aFlexContainer->HasAnyStateBits(NS_STATE_FLEX_IS_LEGACY_WEBKIT_BOX);
}
// XXXdholbert This will be merged into Init(), in a later patch in this series
// (after all callers have been converted to check frame state bit).
/* static */ bool
nsFlexContainerFrame::IsLegacyBox(const nsIFrame* aFrame)
static bool
IsLegacyBoxFOLD_ME(const nsIFrame* aFrame)
{
nsStyleContext* styleContext = aFrame->StyleContext();
const nsStyleDisplay* styleDisp = styleContext->StyleDisplay();
@ -1133,7 +1145,7 @@ IsOrderLEQWithDOMFallback(nsIFrame* aFrame1,
return true;
}
bool isInLegacyBox = nsFlexContainerFrame::IsLegacyBox(aFrame1->GetParent());
const bool isInLegacyBox = IsLegacyBox(aFrame1->GetParent());
int32_t order1 = GetOrderOrBoxOrdinalGroup(aFrame1, isInLegacyBox);
int32_t order2 = GetOrderOrBoxOrdinalGroup(aFrame2, isInLegacyBox);
@ -1211,7 +1223,7 @@ IsOrderLEQ(nsIFrame* aFrame1,
return true;
}
bool isInLegacyBox = nsFlexContainerFrame::IsLegacyBox(aFrame1->GetParent());
const bool isInLegacyBox = IsLegacyBox(aFrame1->GetParent());
int32_t order1 = GetOrderOrBoxOrdinalGroup(aFrame1, isInLegacyBox);
int32_t order2 = GetOrderOrBoxOrdinalGroup(aFrame2, isInLegacyBox);
@ -2284,7 +2296,7 @@ nsFlexContainerFrame::Init(nsIContent* aContent,
{
nsContainerFrame::Init(aContent, aParent, aPrevInFlow);
if (nsFlexContainerFrame::IsLegacyBox(this)) {
if (IsLegacyBoxFOLD_ME(this)) {
// Toggle frame state bit to indicate that this frame represents a
// legacy -webkit-{inline-}box container:
AddStateBits(NS_STATE_FLEX_IS_LEGACY_WEBKIT_BOX);

Просмотреть файл

@ -111,12 +111,6 @@ public:
uint32_t* aNumPackingSpacesRemaining,
nscoord* aPackingSpaceRemaining);
/**
* Returns true if aFrame is the frame for an element with
* "display:-webkit-box" or "display:-webkit-inline-box".
*/
static bool IsLegacyBox(const nsIFrame* aFrame);
protected:
// Protected constructor & destructor
explicit nsFlexContainerFrame(nsStyleContext* aContext)