Bug 1358968 - Part 2: Use nsCSSAnonBoxList.h data to skip parent display-based style fixups when resolving anon box style. r=bz
MozReview-Commit-ID: HugxFcRcCqv
--- a/layout/forms/nsComboboxControlFrame.cpp
+++ b/layout/forms/nsComboboxControlFrame.cpp
@@ -1367,18 +1367,17 @@ nsComboboxControlFrame::CreateFrameForDi
// Get PresShell
nsIPresShell *shell = PresContext()->PresShell();
StyleSetHandle styleSet = shell->StyleSet();
// create the style contexts for the anonymous block frame and text frame
RefPtr<nsStyleContext> styleContext;
styleContext = styleSet->
ResolveInheritingAnonymousBoxStyle(nsCSSAnonBoxes::mozDisplayComboboxControlFrame,
- mStyleContext,
- nsStyleSet::eSkipParentDisplayBasedStyleFixup);
+ mStyleContext);
RefPtr<nsStyleContext> textStyleContext;
textStyleContext =
styleSet->ResolveStyleForText(mDisplayContent, mStyleContext);
// Start by creating our anonymous block frame
mDisplayFrame = new (shell) nsComboboxDisplayFrame(styleContext, this);
mDisplayFrame->Init(mContent, this, nullptr);
--- a/layout/style/ServoStyleSet.cpp
+++ b/layout/style/ServoStyleSet.cpp
@@ -464,28 +464,25 @@ ServoStyleSet::ResolveTransientStyle(Ele
already_AddRefed<ServoComputedValues>
ServoStyleSet::ResolveTransientServoStyle(Element* aElement,
nsIAtom* aPseudoTag)
{
PreTraverseSync();
return ResolveStyleLazily(aElement, aPseudoTag);
}
-// aFlags is an nsStyleSet flags bitfield
already_AddRefed<nsStyleContext>
ServoStyleSet::ResolveInheritingAnonymousBoxStyle(nsIAtom* aPseudoTag,
- nsStyleContext* aParentContext,
- uint32_t aFlags)
+ nsStyleContext* aParentContext)
{
MOZ_ASSERT(nsCSSAnonBoxes::IsAnonBox(aPseudoTag) &&
!nsCSSAnonBoxes::IsNonInheritingAnonBox(aPseudoTag));
- MOZ_ASSERT(aFlags == 0 ||
- aFlags == nsStyleSet::eSkipParentDisplayBasedStyleFixup);
- bool skipFixup = aFlags & nsStyleSet::eSkipParentDisplayBasedStyleFixup;
+ bool skipFixup =
+ nsCSSAnonBoxes::AnonBoxSkipsParentDisplayBasedStyleFixup(aPseudoTag);
const ServoComputedValues* parentStyle =
aParentContext ? aParentContext->StyleSource().AsServoComputedValues()
: nullptr;
RefPtr<ServoComputedValues> computedValues =
Servo_ComputedValues_GetForAnonymousBox(parentStyle, aPseudoTag, skipFixup,
mRawSet.get()).Consume();
#ifdef DEBUG
@@ -493,21 +490,22 @@ ServoStyleSet::ResolveInheritingAnonymou
nsString pseudo;
aPseudoTag->ToString(pseudo);
NS_ERROR(nsPrintfCString("stylo: could not get anon-box: %s",
NS_ConvertUTF16toUTF8(pseudo).get()).get());
MOZ_CRASH();
}
#endif
- // FIXME(bz, bug 1344914) We should really GetContext here and make skipFixup
- // work there.
+ // FIXME(bz, bug 1344914) We should really GetContext here.
+ // FIXME(heycam) We pass in false for the "skip fixup" argument, since it
+ // does nothing for nsStyleContexts backed by ServoComputedValues.
return NS_NewStyleContext(aParentContext, mPresContext, aPseudoTag,
CSSPseudoElementType::InheritingAnonBox,
- computedValues.forget(), skipFixup);
+ computedValues.forget(), false);
}
already_AddRefed<nsStyleContext>
ServoStyleSet::ResolveNonInheritingAnonymousBoxStyle(nsIAtom* aPseudoTag)
{
MOZ_ASSERT(nsCSSAnonBoxes::IsAnonBox(aPseudoTag) &&
nsCSSAnonBoxes::IsNonInheritingAnonBox(aPseudoTag));
MOZ_ASSERT(aPseudoTag != nsCSSAnonBoxes::pageContent,
@@ -520,17 +518,19 @@ ServoStyleSet::ResolveNonInheritingAnony
nsCSSAnonBoxes::NonInheritingTypeForPseudoTag(aPseudoTag);
RefPtr<nsStyleContext>& cache = mNonInheritingStyleContexts[type];
if (cache) {
RefPtr<nsStyleContext> retval = cache;
return retval.forget();
}
// We always want to skip parent-based display fixup here. It never makes
- // sense for non-inheriting anonymous boxes.
+ // sense for non-inheriting anonymous boxes. (Static assertions in
+ // nsCSSAnonBoxes.cpp ensure that all non-inheriting non-anonymous boxes
+ // are indeed annotated as skipping this fixup.)
MOZ_ASSERT(!nsCSSAnonBoxes::IsNonInheritingAnonBox(nsCSSAnonBoxes::viewport),
"viewport needs fixup to handle blockifying it");
RefPtr<ServoComputedValues> computedValues =
Servo_ComputedValues_GetForAnonymousBox(nullptr, aPseudoTag, true,
mRawSet.get()).Consume();
#ifdef DEBUG
if (!computedValues) {
nsString pseudo;
--- a/layout/style/ServoStyleSet.h
+++ b/layout/style/ServoStyleSet.h
@@ -169,22 +169,20 @@ public:
// Similar to ResolveTransientStyle() but returns ServoComputedValues.
// Unlike ResolveServoStyle() this function calls PreTraverseSync().
already_AddRefed<ServoComputedValues>
ResolveTransientServoStyle(dom::Element* aElement, nsIAtom* aPseudoTag);
// Get a style context for an anonymous box. aPseudoTag is the pseudo-tag to
// use and must be non-null. It must be an anon box, and must be one that
- // inherits style from the given aParentContext. aFlags is an nsStyleSet
- // flags bitfield.
+ // inherits style from the given aParentContext.
already_AddRefed<nsStyleContext>
ResolveInheritingAnonymousBoxStyle(nsIAtom* aPseudoTag,
- nsStyleContext* aParentContext,
- uint32_t aFlags = 0);
+ nsStyleContext* aParentContext);
// Get a style context for an anonymous box that does not inherit style from
// anything. aPseudoTag is the pseudo-tag to use and must be non-null. It
// must be an anon box, and must be a non-inheriting one.
already_AddRefed<nsStyleContext>
ResolveNonInheritingAnonymousBoxStyle(nsIAtom* aPseudoTag);
// manage the set of style sheets in the style set
--- a/layout/style/StyleSetHandle.h
+++ b/layout/style/StyleSetHandle.h
@@ -132,18 +132,17 @@ public:
ResolveStyleForPlaceholder();
inline already_AddRefed<nsStyleContext>
ResolvePseudoElementStyle(dom::Element* aParentElement,
mozilla::CSSPseudoElementType aType,
nsStyleContext* aParentContext,
dom::Element* aPseudoElement);
inline already_AddRefed<nsStyleContext>
ResolveInheritingAnonymousBoxStyle(nsIAtom* aPseudoTag,
- nsStyleContext* aParentContext,
- uint32_t aFlags = 0);
+ nsStyleContext* aParentContext);
inline already_AddRefed<nsStyleContext>
ResolveNonInheritingAnonymousBoxStyle(nsIAtom* aPseudoTag);
inline nsresult AppendStyleSheet(SheetType aType, StyleSheet* aSheet);
inline nsresult PrependStyleSheet(SheetType aType, StyleSheet* aSheet);
inline nsresult RemoveStyleSheet(SheetType aType, StyleSheet* aSheet);
inline nsresult ReplaceSheets(SheetType aType,
const nsTArray<RefPtr<StyleSheet>>& aNewSheets);
inline nsresult InsertStyleSheetBefore(SheetType aType,
--- a/layout/style/StyleSetHandleInlines.h
+++ b/layout/style/StyleSetHandleInlines.h
@@ -118,24 +118,21 @@ StyleSetHandle::Ptr::ResolvePseudoElemen
CSSPseudoElementType aType,
nsStyleContext* aParentContext,
dom::Element* aPseudoElement)
{
FORWARD(ResolvePseudoElementStyle, (aParentElement, aType, aParentContext,
aPseudoElement));
}
-// aFlags is an nsStyleSet flags bitfield
already_AddRefed<nsStyleContext>
StyleSetHandle::Ptr::ResolveInheritingAnonymousBoxStyle(nsIAtom* aPseudoTag,
- nsStyleContext* aParentContext,
- uint32_t aFlags)
+ nsStyleContext* aParentContext)
{
- FORWARD(ResolveInheritingAnonymousBoxStyle, (aPseudoTag, aParentContext,
- aFlags));
+ FORWARD(ResolveInheritingAnonymousBoxStyle, (aPseudoTag, aParentContext));
}
already_AddRefed<nsStyleContext>
StyleSetHandle::Ptr::ResolveNonInheritingAnonymousBoxStyle(nsIAtom* aPseudoTag)
{
FORWARD(ResolveNonInheritingAnonymousBoxStyle, (aPseudoTag));
}
--- a/layout/style/nsStyleSet.cpp
+++ b/layout/style/nsStyleSet.cpp
@@ -2078,18 +2078,17 @@ nsStyleSet::ProbePseudoElementStyle(Elem
}
}
return result.forget();
}
already_AddRefed<nsStyleContext>
nsStyleSet::ResolveInheritingAnonymousBoxStyle(nsIAtom* aPseudoTag,
- nsStyleContext* aParentContext,
- uint32_t aFlags)
+ nsStyleContext* aParentContext)
{
NS_ENSURE_FALSE(mInShutdown, nullptr);
#ifdef DEBUG
bool isAnonBox = nsCSSAnonBoxes::IsAnonBox(aPseudoTag) &&
!nsCSSAnonBoxes::IsNonInheritingAnonBox(aPseudoTag)
#ifdef MOZ_XUL
&& !nsCSSAnonBoxes::IsTreePseudoElement(aPseudoTag)
@@ -2118,19 +2117,24 @@ nsStyleSet::ResolveInheritingAnonymousBo
importantRules.AppendElement(importantRule);
}
}
for (uint32_t i = 0, i_end = importantRules.Length(); i != i_end; ++i) {
ruleWalker.Forward(importantRules[i]);
}
}
+ uint32_t flags = eNoFlags;
+ if (nsCSSAnonBoxes::AnonBoxSkipsParentDisplayBasedStyleFixup(aPseudoTag)) {
+ flags |= eSkipParentDisplayBasedStyleFixup;
+ }
+
return GetContext(aParentContext, ruleWalker.CurrentNode(), nullptr,
aPseudoTag, CSSPseudoElementType::InheritingAnonBox,
- nullptr, aFlags);
+ nullptr, flags);
}
already_AddRefed<nsStyleContext>
nsStyleSet::ResolveNonInheritingAnonymousBoxStyle(nsIAtom* aPseudoTag)
{
NS_ENSURE_FALSE(mInShutdown, nullptr);
#ifdef DEBUG
--- a/layout/style/nsStyleSet.h
+++ b/layout/style/nsStyleSet.h
@@ -255,18 +255,17 @@ class nsStyleSet final
already_AddRefed<nsStyleContext>
ProbePseudoElementStyle(mozilla::dom::Element* aParentElement,
mozilla::CSSPseudoElementType aType,
nsStyleContext* aParentContext,
TreeMatchContext& aTreeMatchContext,
mozilla::dom::Element* aPseudoElement = nullptr);
/**
- * Bit-flags that can be passed to ResolveInheritingAnonymousBoxStyle and
- * GetContext in their parameter 'aFlags'.
+ * Bit-flags that can be passed to GetContext in its parameter 'aFlags'.
*/
enum {
eNoFlags = 0,
eIsLink = 1 << 0,
eIsVisitedLink = 1 << 1,
eDoAnimation = 1 << 2,
// Indicates that we should skip the flex/grid item specific chunk of
@@ -274,22 +273,20 @@ class nsStyleSet final
// or "display: grid" but we can tell we're not going to honor that (e.g. if
// it's the outer frame of a button widget, and we're the inline frame for
// the button's label).
eSkipParentDisplayBasedStyleFixup = 1 << 3
};
// Get a style context for an anonymous box. aPseudoTag is the pseudo-tag to
// use and must be non-null. It must be an anon box, and must be one that
- // inherits style from the given aParentContext. aFlags will be forwarded to
- // a GetContext call internally.
+ // inherits style from the given aParentContext.
already_AddRefed<nsStyleContext>
ResolveInheritingAnonymousBoxStyle(nsIAtom* aPseudoTag,
- nsStyleContext* aParentContext,
- uint32_t aFlags = eNoFlags);
+ nsStyleContext* aParentContext);
// Get a style context for an anonymous box that does not inherit style from
// anything. aPseudoTag is the pseudo-tag to use and must be non-null. It
// must be an anon box, and must be a non-inheriting one.
already_AddRefed<nsStyleContext>
ResolveNonInheritingAnonymousBoxStyle(nsIAtom* aPseudoTag);
#ifdef MOZ_XUL