From 332fa4dc43609ea301641b45b6562ebd1e654fdc Mon Sep 17 00:00:00 2001 From: Emily McDonough Date: Wed, 21 Jun 2023 19:02:23 +0000 Subject: [PATCH] Bug 1833471 Part 2 - Export @page pseudo-class flags to Gecko style code r=emilio Differential Revision: https://phabricator.services.mozilla.com/D178869 --- layout/base/nsCSSFrameConstructor.cpp | 3 ++- layout/generic/nsPageContentFrame.cpp | 3 ++- layout/style/ServoStyleSet.cpp | 16 +++++++++------- layout/style/ServoStyleSet.h | 6 ++++-- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/layout/base/nsCSSFrameConstructor.cpp b/layout/base/nsCSSFrameConstructor.cpp index c79c53782c90..2508c8e14179 100644 --- a/layout/base/nsCSSFrameConstructor.cpp +++ b/layout/base/nsCSSFrameConstructor.cpp @@ -2910,7 +2910,8 @@ nsContainerFrame* nsCSSFrameConstructor::ConstructPageFrame( "Page name from prev-in-flow should not have been null"); } RefPtr pageContentPseudoStyle = - styleSet->ResolvePageContentStyle(pageName); + styleSet->ResolvePageContentStyle(pageName, + StylePagePseudoClassFlags::NONE); nsContainerFrame* pageContentFrame = NS_NewPageContentFrame( aPresShell, pageContentPseudoStyle, pageName.forget()); diff --git a/layout/generic/nsPageContentFrame.cpp b/layout/generic/nsPageContentFrame.cpp index 6f277190ee1a..503b6aee4aa4 100644 --- a/layout/generic/nsPageContentFrame.cpp +++ b/layout/generic/nsPageContentFrame.cpp @@ -419,7 +419,8 @@ void nsPageContentFrame::EnsurePageName() { return; } RefPtr pageContentPseudoStyle = - PresShell()->StyleSet()->ResolvePageContentStyle(mPageName); + PresShell()->StyleSet()->ResolvePageContentStyle( + mPageName, StylePagePseudoClassFlags::FIRST); SetComputedStyleWithoutNotification(pageContentPseudoStyle); } diff --git a/layout/style/ServoStyleSet.cpp b/layout/style/ServoStyleSet.cpp index 49af140c6112..24c974bdc510 100644 --- a/layout/style/ServoStyleSet.cpp +++ b/layout/style/ServoStyleSet.cpp @@ -572,7 +572,7 @@ ServoStyleSet::ResolveNonInheritingAnonymousBoxStyle(PseudoStyleType aType) { } already_AddRefed ServoStyleSet::ResolvePageContentStyle( - const nsAtom* aPageName) { + const nsAtom* aPageName, const StylePagePseudoClassFlags& aPseudo) { // The empty atom is used to indicate no specified page name, and is not // usable as a page-rule selector. Changing this to null is a slight // optimization to avoid the Servo code from doing an unnecessary hashtable @@ -580,10 +580,12 @@ already_AddRefed ServoStyleSet::ResolvePageContentStyle( if (aPageName == nsGkAtoms::_empty) { aPageName = nullptr; } - // Only use the cache if we are not doing a lookup for a named page style. + // Only use the cache when we are doing a lookup for page styles without a + // page-name or any pseudo classes. + const bool useCache = !aPageName && !aPseudo; RefPtr& cache = mNonInheritingComputedStyles[nsCSSAnonBoxes::NonInheriting::pageContent]; - if (!aPageName && cache) { + if (useCache && cache) { RefPtr retval = cache; return retval.forget(); } @@ -591,12 +593,11 @@ already_AddRefed ServoStyleSet::ResolvePageContentStyle( UpdateStylistIfNeeded(); RefPtr computedValues = - Servo_ComputedValues_GetForPageContent(mRawData.get(), aPageName, - StylePagePseudoClassFlags::NONE) + Servo_ComputedValues_GetForPageContent(mRawData.get(), aPageName, aPseudo) .Consume(); MOZ_ASSERT(computedValues); - if (!aPageName) { + if (useCache) { cache = computedValues; } return computedValues.forget(); @@ -686,7 +687,8 @@ StyleSheet* ServoStyleSet::SheetAt(Origin aOrigin, size_t aIndex) const { ServoStyleSet::FirstPageSizeAndOrientation ServoStyleSet::GetFirstPageSizeAndOrientation(const nsAtom* aFirstPageName) { FirstPageSizeAndOrientation retval; - const RefPtr style = ResolvePageContentStyle(aFirstPageName); + const RefPtr style = + ResolvePageContentStyle(aFirstPageName, StylePagePseudoClassFlags::FIRST); const StylePageSize& pageSize = style->StylePage()->mSize; if (pageSize.IsSize()) { diff --git a/layout/style/ServoStyleSet.h b/layout/style/ServoStyleSet.h index c91241ef5d9b..35a827dfda4b 100644 --- a/layout/style/ServoStyleSet.h +++ b/layout/style/ServoStyleSet.h @@ -35,6 +35,7 @@ enum class StyleRuleChangeKind : uint32_t; template struct StyleTimingFunction; +struct StylePagePseudoClassFlags; struct StylePiecewiseLinearFunction; using StyleComputedTimingFunction = StyleTimingFunction; @@ -254,9 +255,10 @@ class ServoStyleSet { PseudoStyleType aType); // Get a ComputedStyle for a pageContent box with the specified page-name. - // A page name that is null or the empty atom gets the global page style. + // A page name that is null or the empty atom and has no pseudo classes gets + // the global page style. already_AddRefed ResolvePageContentStyle( - const nsAtom* aPageName); + const nsAtom* aPageName, const StylePagePseudoClassFlags& aPseudo); already_AddRefed ResolveXULTreePseudoStyle( dom::Element* aParentElement, nsCSSAnonBoxPseudoStaticAtom* aPseudoTag,