Bug 1789123 - Unify anonymous flex/grid items. r=dholbert

This has no behavior change, just unifies the pseudo-element used for
these.

Differential Revision: https://phabricator.services.mozilla.com/D156736
This commit is contained in:
Emilio Cobos Álvarez
2022-09-08 11:45:31 +00:00
parent d0e812bfc7
commit a714922f5c
5 changed files with 20 additions and 40 deletions

View File

@@ -260,10 +260,8 @@ nsIFrame* NS_NewImageFrameForGeneratedContentIndex(PresShell*, ComputedStyle*);
nsIFrame* NS_NewImageFrameForListStyleImage(PresShell*, ComputedStyle*); nsIFrame* NS_NewImageFrameForListStyleImage(PresShell*, ComputedStyle*);
// Returns true if aFrame is an anonymous flex/grid item. // Returns true if aFrame is an anonymous flex/grid item.
static inline bool IsAnonymousFlexOrGridItem(const nsIFrame* aFrame) { static inline bool IsAnonymousItem(const nsIFrame* aFrame) {
auto pseudoType = aFrame->Style()->GetPseudoType(); return aFrame->Style()->GetPseudoType() == PseudoStyleType::anonymousItem;
return pseudoType == PseudoStyleType::anonymousFlexItem ||
pseudoType == PseudoStyleType::anonymousGridItem;
} }
// Returns true IFF the given nsIFrame is a nsFlexContainerFrame and // Returns true IFF the given nsIFrame is a nsFlexContainerFrame and
@@ -276,19 +274,12 @@ static inline bool IsFlexContainerForLegacyBox(const nsIFrame* aFrame) {
#if DEBUG #if DEBUG
static void AssertAnonymousFlexOrGridItemParent(const nsIFrame* aChild, static void AssertAnonymousFlexOrGridItemParent(const nsIFrame* aChild,
const nsIFrame* aParent) { const nsIFrame* aParent) {
MOZ_ASSERT(IsAnonymousFlexOrGridItem(aChild), MOZ_ASSERT(IsAnonymousItem(aChild),
"expected an anonymous flex or grid item child frame"); "expected an anonymous flex or grid item child frame");
MOZ_ASSERT(aParent, "expected a parent frame"); MOZ_ASSERT(aParent, "expected a parent frame");
auto pseudoType = aChild->Style()->GetPseudoType(); MOZ_ASSERT(aParent->IsFlexContainerFrame() || aParent->IsGridContainerFrame(),
if (pseudoType == PseudoStyleType::anonymousFlexItem) { "anonymous items should only exist as children of "
MOZ_ASSERT(aParent->IsFlexContainerFrame(), "flex/grid container frames");
"anonymous flex items should only exist as children "
"of flex container frames");
} else {
MOZ_ASSERT(aParent->IsGridContainerFrame(),
"anonymous grid items should only exist as children "
"of grid container frames");
}
} }
#else #else
# define AssertAnonymousFlexOrGridItemParent(x, y) PR_BEGIN_MACRO PR_END_MACRO # define AssertAnonymousFlexOrGridItemParent(x, y) PR_BEGIN_MACRO PR_END_MACRO
@@ -8608,7 +8599,7 @@ bool nsCSSFrameConstructor::MaybeRecreateContainerForFrameRemoval(
// we're only interested in anonymous flex items here, and those can never // we're only interested in anonymous flex items here, and those can never
// be adjacent to whitespace, since they absorb contiguous runs of inline // be adjacent to whitespace, since they absorb contiguous runs of inline
// non-replaced content (including whitespace). // non-replaced content (including whitespace).
if (nextSibling && IsAnonymousFlexOrGridItem(nextSibling)) { if (nextSibling && IsAnonymousItem(nextSibling)) {
AssertAnonymousFlexOrGridItemParent(nextSibling, parent); AssertAnonymousFlexOrGridItemParent(nextSibling, parent);
TRACE("Anon flex or grid item next sibling"); TRACE("Anon flex or grid item next sibling");
// Recreate frames for the flex container (the removed frame's parent) // Recreate frames for the flex container (the removed frame's parent)
@@ -8619,7 +8610,7 @@ bool nsCSSFrameConstructor::MaybeRecreateContainerForFrameRemoval(
// Might need to reconstruct things if the removed frame's nextSibling is // Might need to reconstruct things if the removed frame's nextSibling is
// null and its parent is an anonymous flex item. (This might be the last // null and its parent is an anonymous flex item. (This might be the last
// remaining child of that anonymous flex item, which can then go away.) // remaining child of that anonymous flex item, which can then go away.)
if (!nextSibling && IsAnonymousFlexOrGridItem(parent)) { if (!nextSibling && IsAnonymousItem(parent)) {
AssertAnonymousFlexOrGridItemParent(parent, parent->GetParent()); AssertAnonymousFlexOrGridItemParent(parent, parent->GetParent());
TRACE("Anon flex or grid item parent"); TRACE("Anon flex or grid item parent");
// Recreate frames for the flex container (the removed frame's grandparent) // Recreate frames for the flex container (the removed frame's grandparent)
@@ -8989,14 +8980,10 @@ void nsCSSFrameConstructor::CreateNeededAnonFlexOrGridItems(
// Now, we create the anonymous flex or grid item to contain the children // Now, we create the anonymous flex or grid item to contain the children
// between |iter| and |endIter|. // between |iter| and |endIter|.
auto pseudoType = aParentFrame->IsFlexContainerFrame()
? PseudoStyleType::anonymousFlexItem
: PseudoStyleType::anonymousGridItem;
ComputedStyle* parentStyle = aParentFrame->Style();
nsIContent* parentContent = aParentFrame->GetContent(); nsIContent* parentContent = aParentFrame->GetContent();
RefPtr<ComputedStyle> wrapperStyle = RefPtr<ComputedStyle> wrapperStyle =
mPresShell->StyleSet()->ResolveInheritingAnonymousBoxStyle(pseudoType, mPresShell->StyleSet()->ResolveInheritingAnonymousBoxStyle(
parentStyle); PseudoStyleType::anonymousItem, aParentFrame->Style());
static constexpr FrameConstructionData sBlockFormattingContextFCData( static constexpr FrameConstructionData sBlockFormattingContextFCData(
ToCreationFunc(NS_NewBlockFormattingContext), ToCreationFunc(NS_NewBlockFormattingContext),
@@ -9590,7 +9577,7 @@ static void VerifyGridFlexContainerChildren(nsIFrame* aParentFrame,
for (const nsIFrame* child : aChildren) { for (const nsIFrame* child : aChildren) {
MOZ_ASSERT(!FrameWantsToBeInAnonymousItem(aParentFrame, child), MOZ_ASSERT(!FrameWantsToBeInAnonymousItem(aParentFrame, child),
"frame wants to be inside an anonymous item, but it isn't"); "frame wants to be inside an anonymous item, but it isn't");
if (IsAnonymousFlexOrGridItem(child)) { if (IsAnonymousItem(child)) {
AssertAnonymousFlexOrGridItemParent(child, aParentFrame); AssertAnonymousFlexOrGridItemParent(child, aParentFrame);
MOZ_ASSERT(!prevChildWasAnonItem, "two anon items in a row"); MOZ_ASSERT(!prevChildWasAnonItem, "two anon items in a row");
nsIFrame* firstWrappedChild = child->PrincipalChildList().FirstChild(); nsIFrame* firstWrappedChild = child->PrincipalChildList().FirstChild();
@@ -11447,7 +11434,7 @@ bool nsCSSFrameConstructor::WipeContainingBlock(
// Check if we're adding to-be-wrapped content right *after* an existing // 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). // anonymous flex or grid item (which would need to absorb this content).
const bool isLegacyBox = IsFlexContainerForLegacyBox(aFrame); const bool isLegacyBox = IsFlexContainerForLegacyBox(aFrame);
if (aPrevSibling && IsAnonymousFlexOrGridItem(aPrevSibling) && if (aPrevSibling && IsAnonymousItem(aPrevSibling) &&
iter.item().NeedsAnonFlexOrGridItem(aState, isLegacyBox)) { iter.item().NeedsAnonFlexOrGridItem(aState, isLegacyBox)) {
TRACE("Inserting inline after anon flex or grid item"); TRACE("Inserting inline after anon flex or grid item");
RecreateFramesForContent(aFrame->GetContent(), InsertionKind::Async); RecreateFramesForContent(aFrame->GetContent(), InsertionKind::Async);
@@ -11456,7 +11443,7 @@ bool nsCSSFrameConstructor::WipeContainingBlock(
// Check if we're adding to-be-wrapped content right *before* an existing // Check if we're adding to-be-wrapped content right *before* an existing
// anonymous flex or grid item (which would need to absorb this content). // anonymous flex or grid item (which would need to absorb this content).
if (nextSibling && IsAnonymousFlexOrGridItem(nextSibling)) { if (nextSibling && IsAnonymousItem(nextSibling)) {
// Jump to the last entry in the list // Jump to the last entry in the list
iter.SetToEnd(); iter.SetToEnd();
iter.Prev(); iter.Prev();
@@ -11470,7 +11457,7 @@ bool nsCSSFrameConstructor::WipeContainingBlock(
// Situation #3 is an anonymous flex or grid item that's getting new children // Situation #3 is an anonymous flex or grid item that's getting new children
// who don't want to be wrapped. // who don't want to be wrapped.
if (IsAnonymousFlexOrGridItem(aFrame)) { if (IsAnonymousItem(aFrame)) {
AssertAnonymousFlexOrGridItemParent(aFrame, aFrame->GetParent()); AssertAnonymousFlexOrGridItemParent(aFrame, aFrame->GetParent());
// We need to push a null float containing block to be sure that // We need to push a null float containing block to be sure that

View File

@@ -10401,8 +10401,7 @@ nsIFrame::Focusable nsIFrame::IsFocusable(bool aWithMouse) {
} }
PseudoStyleType pseudo = Style()->GetPseudoType(); PseudoStyleType pseudo = Style()->GetPseudoType();
if (pseudo == PseudoStyleType::anonymousFlexItem || if (pseudo == PseudoStyleType::anonymousItem) {
pseudo == PseudoStyleType::anonymousGridItem) {
return {}; return {};
} }

View File

@@ -125,13 +125,9 @@ CSS_ANON_BOX(columnContent, ":-moz-column-content")
CSS_ANON_BOX(viewport, ":-moz-viewport") CSS_ANON_BOX(viewport, ":-moz-viewport")
CSS_ANON_BOX(viewportScroll, ":-moz-viewport-scroll") CSS_ANON_BOX(viewportScroll, ":-moz-viewport-scroll")
// Inside a flex container, a contiguous run of text gets wrapped in // Inside a flex/grid container, a contiguous run of text gets wrapped in an
// an anonymous block, which is then treated as a flex item. // anonymous block, which is then treated as a flex item.
CSS_WRAPPER_ANON_BOX(anonymousFlexItem, ":-moz-anonymous-flex-item") CSS_WRAPPER_ANON_BOX(anonymousItem, ":-moz-anonymous-item")
// Inside a grid container, a contiguous run of text gets wrapped in
// an anonymous block, which is then treated as a grid item.
CSS_WRAPPER_ANON_BOX(anonymousGridItem, ":-moz-anonymous-grid-item")
CSS_ANON_BOX(blockRubyContent, ":-moz-block-ruby-content") CSS_ANON_BOX(blockRubyContent, ":-moz-block-ruby-content")
CSS_WRAPPER_ANON_BOX(ruby, ":-moz-ruby") CSS_WRAPPER_ANON_BOX(ruby, ":-moz-ruby")

View File

@@ -298,8 +298,7 @@
column-span: all; column-span: all;
} }
*|*::-moz-anonymous-flex-item, *|*::-moz-anonymous-item {
*|*::-moz-anonymous-grid-item {
/* Anonymous blocks that wrap contiguous runs of text /* Anonymous blocks that wrap contiguous runs of text
* inside of a flex or grid container. */ * inside of a flex or grid container. */
display: block; display: block;

View File

@@ -2517,8 +2517,7 @@ STATIC_ATOMS = [
InheritingAnonBoxAtom("AnonBox_columnContent", ":-moz-column-content"), InheritingAnonBoxAtom("AnonBox_columnContent", ":-moz-column-content"),
InheritingAnonBoxAtom("AnonBox_viewport", ":-moz-viewport"), InheritingAnonBoxAtom("AnonBox_viewport", ":-moz-viewport"),
InheritingAnonBoxAtom("AnonBox_viewportScroll", ":-moz-viewport-scroll"), InheritingAnonBoxAtom("AnonBox_viewportScroll", ":-moz-viewport-scroll"),
InheritingAnonBoxAtom("AnonBox_anonymousFlexItem", ":-moz-anonymous-flex-item"), InheritingAnonBoxAtom("AnonBox_anonymousItem", ":-moz-anonymous-item"),
InheritingAnonBoxAtom("AnonBox_anonymousGridItem", ":-moz-anonymous-grid-item"),
InheritingAnonBoxAtom("AnonBox_blockRubyContent", ":-moz-block-ruby-content"), InheritingAnonBoxAtom("AnonBox_blockRubyContent", ":-moz-block-ruby-content"),
InheritingAnonBoxAtom("AnonBox_ruby", ":-moz-ruby"), InheritingAnonBoxAtom("AnonBox_ruby", ":-moz-ruby"),
InheritingAnonBoxAtom("AnonBox_rubyBase", ":-moz-ruby-base"), InheritingAnonBoxAtom("AnonBox_rubyBase", ":-moz-ruby-base"),