diff --git a/layout/base/nsCounterManager.h b/layout/base/nsCounterManager.h index 20d30c865fc8..9295c3dc7528 100644 --- a/layout/base/nsCounterManager.h +++ b/layout/base/nsCounterManager.h @@ -82,7 +82,7 @@ struct nsCounterUseNode : public nsCounterNode { RefPtr mCounterFunction; nsPresContext* mPresContext; - RefPtr mCounterStyle; + mozilla::CounterStylePtr mCounterStyle; // false for counter(), true for counters() bool mAllCounters; @@ -94,7 +94,6 @@ struct nsCounterUseNode : public nsCounterNode { : nsCounterNode(aContentIndex, USE) , mCounterFunction(aCounterFunction) , mPresContext(aPresContext) - , mCounterStyle(nullptr) , mAllCounters(aAllCounters) { NS_ASSERTION(aContentIndex <= INT32_MAX, "out of range"); diff --git a/layout/base/nsPresContext.cpp b/layout/base/nsPresContext.cpp index 97b06dbbcfe1..d054f666ca74 100644 --- a/layout/base/nsPresContext.cpp +++ b/layout/base/nsPresContext.cpp @@ -2282,6 +2282,29 @@ nsPresContext::UserFontSetUpdated(gfxUserFontEntry* aUpdatedFont) } } +class CounterStyleCleaner : public nsAPostRefreshObserver +{ +public: + CounterStyleCleaner(nsRefreshDriver* aRefreshDriver, + CounterStyleManager* aCounterStyleManager) + : mRefreshDriver(aRefreshDriver) + , mCounterStyleManager(aCounterStyleManager) + { + } + virtual ~CounterStyleCleaner() {} + + void DidRefresh() final + { + mRefreshDriver->RemovePostRefreshObserver(this); + mCounterStyleManager->CleanRetiredStyles(); + delete this; + } + +private: + RefPtr mRefreshDriver; + RefPtr mCounterStyleManager; +}; + void nsPresContext::FlushCounterStyles() { @@ -2299,6 +2322,8 @@ nsPresContext::FlushCounterStyles() PresShell()->NotifyCounterStylesAreDirty(); PostRebuildAllStyleDataEvent(NS_STYLE_HINT_REFLOW, eRestyle_ForceDescendants); + RefreshDriver()->AddPostRefreshObserver( + new CounterStyleCleaner(RefreshDriver(), mCounterStyleManager)); } mCounterStylesDirty = false; } diff --git a/layout/generic/ReflowInput.cpp b/layout/generic/ReflowInput.cpp index 2ed8ce93cd2f..34faaefedc9b 100644 --- a/layout/generic/ReflowInput.cpp +++ b/layout/generic/ReflowInput.cpp @@ -133,7 +133,7 @@ FontSizeInflationListMarginAdjustment(const nsIFrame* aFrame) blockFrame->HasBullet() && inflation > 1.0f) { - auto listStyleType = aFrame->StyleList()->GetCounterStyle()->GetStyle(); + auto listStyleType = aFrame->StyleList()->mCounterStyle->GetStyle(); if (listStyleType != NS_STYLE_LIST_STYLE_NONE && listStyleType != NS_STYLE_LIST_STYLE_DISC && listStyleType != NS_STYLE_LIST_STYLE_CIRCLE && diff --git a/layout/generic/nsBlockFrame.cpp b/layout/generic/nsBlockFrame.cpp index d85a25afdd30..a7e029409ba5 100644 --- a/layout/generic/nsBlockFrame.cpp +++ b/layout/generic/nsBlockFrame.cpp @@ -7055,7 +7055,7 @@ nsBlockFrame::SetInitialChildList(ChildListID aListID, !GetPrevInFlow()) { // Resolve style for the bullet frame const nsStyleList* styleList = StyleList(); - CounterStyle* style = styleList->GetCounterStyle(); + CounterStyle* style = styleList->mCounterStyle; CreateBulletFrameForListItem( style->IsBullet(), @@ -7110,7 +7110,7 @@ nsBlockFrame::BulletIsEmpty() const mozilla::StyleDisplay::ListItem && HasOutsideBullet(), "should only care when we have an outside bullet"); const nsStyleList* list = StyleList(); - return list->GetCounterStyle()->IsNone() && + return list->mCounterStyle->IsNone() && !list->GetListStyleImage(); } diff --git a/layout/generic/nsBulletFrame.cpp b/layout/generic/nsBulletFrame.cpp index 8da4a9d5cb5f..a2fd859dd6ed 100644 --- a/layout/generic/nsBulletFrame.cpp +++ b/layout/generic/nsBulletFrame.cpp @@ -96,7 +96,7 @@ nsBulletFrame::IsEmpty() bool nsBulletFrame::IsSelfEmpty() { - return StyleList()->GetCounterStyle()->IsNone(); + return StyleList()->mCounterStyle->IsNone(); } /* virtual */ void @@ -157,11 +157,11 @@ nsBulletFrame::DidSetStyleContext(nsStyleContext* aOldStyleContext) const nsStyleList* oldStyleList = aOldStyleContext->PeekStyleList(); if (oldStyleList) { bool hadBullet = oldStyleList->GetListStyleImage() || - !oldStyleList->GetCounterStyle()->IsNone(); + !oldStyleList->mCounterStyle->IsNone(); const nsStyleList* newStyleList = StyleList(); bool hasBullet = newStyleList->GetListStyleImage() || - !newStyleList->GetCounterStyle()->IsNone(); + !newStyleList->mCounterStyle->IsNone(); if (hadBullet != hasBullet) { accService->UpdateListBullet(PresContext()->GetPresShell(), mContent, @@ -696,7 +696,7 @@ Maybe nsBulletFrame::CreateBulletRenderer(nsRenderingContext& aRenderingContext, nsPoint aPt) { const nsStyleList* myList = StyleList(); - CounterStyle* listStyleType = myList->GetCounterStyle(); + CounterStyle* listStyleType = myList->mCounterStyle; nsMargin padding = mPadding.GetPhysicalMargin(GetWritingMode()); if (myList->GetListStyleImage() && mImageRequest) { @@ -904,7 +904,7 @@ nsBulletFrame::SetListItemOrdinal(int32_t aNextOrdinal, void nsBulletFrame::GetListItemText(nsAString& aResult) { - CounterStyle* style = StyleList()->GetCounterStyle(); + CounterStyle* style = StyleList()->mCounterStyle; NS_ASSERTION(style->GetStyle() != NS_STYLE_LIST_STYLE_NONE && style->GetStyle() != NS_STYLE_LIST_STYLE_DISC && style->GetStyle() != NS_STYLE_LIST_STYLE_CIRCLE && @@ -991,7 +991,7 @@ nsBulletFrame::GetDesiredSize(nsPresContext* aCX, nscoord bulletSize; nsAutoString text; - switch (myList->GetCounterStyle()->GetStyle()) { + switch (myList->mCounterStyle->GetStyle()) { case NS_STYLE_LIST_STYLE_NONE: finalSize.ISize(wm) = finalSize.BSize(wm) = 0; aMetrics.SetBlockStartAscent(0); @@ -1113,7 +1113,7 @@ IsIgnoreable(const nsIFrame* aFrame, nscoord aISize) return false; } auto listStyle = aFrame->StyleList(); - return listStyle->GetCounterStyle()->IsNone() && + return listStyle->mCounterStyle->IsNone() && !listStyle->GetListStyleImage(); } @@ -1350,7 +1350,7 @@ nsBulletFrame::GetLogicalBaseline(WritingMode aWritingMode) const } else { RefPtr fm = nsLayoutUtils::GetFontMetricsForFrame(this, GetFontSizeInflation()); - CounterStyle* listStyleType = StyleList()->GetCounterStyle(); + CounterStyle* listStyleType = StyleList()->mCounterStyle; switch (listStyleType->GetStyle()) { case NS_STYLE_LIST_STYLE_NONE: break; @@ -1387,7 +1387,7 @@ nsBulletFrame::GetLogicalBaseline(WritingMode aWritingMode) const void nsBulletFrame::GetSpokenText(nsAString& aText) { - CounterStyle* style = StyleList()->GetCounterStyle(); + CounterStyle* style = StyleList()->mCounterStyle; bool isBullet; style->GetSpokenCounterText(mOrdinal, GetWritingMode(), aText, isBullet); if (isBullet) { diff --git a/layout/style/CounterStyleManager.cpp b/layout/style/CounterStyleManager.cpp index a1795a8b0844..fb86828aaf4f 100644 --- a/layout/style/CounterStyleManager.cpp +++ b/layout/style/CounterStyleManager.cpp @@ -611,10 +611,6 @@ public: WritingMode aWritingMode, nsSubstring& aResult, bool& aIsRTL) override; - - // Builtin counter style does not need refcount at all - NS_IMETHOD_(MozExternalRefCountType) AddRef() override { return 2; } - NS_IMETHOD_(MozExternalRefCountType) Release() override { return 2; } }; /* virtual */ void @@ -962,8 +958,6 @@ BuiltinCounterStyle::GetInitialCounterText(CounterValue aOrdinal, class DependentBuiltinCounterStyle final : public BuiltinCounterStyle { -private: - ~DependentBuiltinCounterStyle() {} public: DependentBuiltinCounterStyle(int32_t aStyle, CounterStyleManager* aManager) : BuiltinCounterStyle(aStyle), @@ -975,18 +969,12 @@ public: virtual CounterStyle* GetFallback() override; - // DependentBuiltinCounterStyle is managed in the same way as - // CustomCounterStyle. - NS_IMETHOD_(MozExternalRefCountType) AddRef() override; - NS_IMETHOD_(MozExternalRefCountType) Release() override; - void* operator new(size_t sz, nsPresContext* aPresContext) { return aPresContext->PresShell()->AllocateByObjectID( eArenaObjectID_DependentBuiltinCounterStyle, sz); } -private: void Destroy() { nsIPresShell* shell = mManager->PresContext()->PresShell(); @@ -994,15 +982,12 @@ private: shell->FreeByObjectID(eArenaObjectID_DependentBuiltinCounterStyle, this); } +private: + ~DependentBuiltinCounterStyle() {} + CounterStyleManager* mManager; - - nsAutoRefCnt mRefCnt; - NS_DECL_OWNINGTHREAD }; -NS_IMPL_ADDREF(DependentBuiltinCounterStyle) -NS_IMPL_RELEASE_WITH_DESTROY(DependentBuiltinCounterStyle, Destroy()) - /* virtual */ CounterStyle* DependentBuiltinCounterStyle::GetFallback() { @@ -1029,8 +1014,6 @@ DependentBuiltinCounterStyle::GetFallback() class CustomCounterStyle final : public CounterStyle { -private: - ~CustomCounterStyle() {} public: CustomCounterStyle(nsIAtom* aName, CounterStyleManager* aManager, @@ -1095,19 +1078,12 @@ public: return mSystem == NS_STYLE_COUNTER_SYSTEM_EXTENDS; } - // CustomCounterStyle should be reference-counted because it may be - // dereferenced from the manager but still referenced by nodes and - // frames before the style change is propagated. - NS_IMETHOD_(MozExternalRefCountType) AddRef() override; - NS_IMETHOD_(MozExternalRefCountType) Release() override; - void* operator new(size_t sz, nsPresContext* aPresContext) { return aPresContext->PresShell()->AllocateByObjectID( eArenaObjectID_CustomCounterStyle, sz); } -private: void Destroy() { nsIPresShell* shell = mManager->PresContext()->PresShell(); @@ -1115,6 +1091,9 @@ private: shell->FreeByObjectID(eArenaObjectID_CustomCounterStyle, this); } +private: + ~CustomCounterStyle() {} + const nsTArray& GetSymbols(); const nsTArray& GetAdditiveSymbols(); @@ -1190,14 +1169,8 @@ private: // counter must be either a builtin style or a style whose system is // not 'extends'. CounterStyle* mExtendsRoot; - - nsAutoRefCnt mRefCnt; - NS_DECL_OWNINGTHREAD }; -NS_IMPL_ADDREF(CustomCounterStyle) -NS_IMPL_RELEASE_WITH_DESTROY(CustomCounterStyle, Destroy()) - void CustomCounterStyle::ResetCachedData() { @@ -1987,8 +1960,8 @@ CounterStyleManager::CounterStyleManager(nsPresContext* aPresContext) : mPresContext(aPresContext) { // Insert the static styles into cache table - mCacheTable.Put(nsGkAtoms::none, GetNoneStyle()); - mCacheTable.Put(nsGkAtoms::decimal, GetDecimalStyle()); + mStyles.Put(nsGkAtoms::none, GetNoneStyle()); + mStyles.Put(nsGkAtoms::decimal, GetDecimalStyle()); } CounterStyleManager::~CounterStyleManager() @@ -2004,26 +1977,38 @@ CounterStyleManager::InitializeBuiltinCounterStyles() } } +void +CounterStyleManager::DestroyCounterStyle(CounterStyle* aCounterStyle) +{ + if (aCounterStyle->IsCustomStyle()) { + MOZ_ASSERT(!aCounterStyle->AsAnonymous(), "Anonymous counter styles " + "are not managed by CounterStyleManager"); + static_cast(aCounterStyle)->Destroy(); + } else if (aCounterStyle->IsDependentStyle()) { + static_cast(aCounterStyle)->Destroy(); + } else { + MOZ_ASSERT_UNREACHABLE("Builtin counter styles should not be destroyed"); + } +} + void CounterStyleManager::Disconnect() { -#ifdef DEBUG - for (auto iter = mCacheTable.Iter(); !iter.Done(); iter.Next()) { - CounterStyle* style = iter.UserData(); - style->AddRef(); - auto refcnt = style->Release(); - NS_ASSERTION(!style->IsDependentStyle() || refcnt == 1, - "Counter style is still referenced by other objects."); + CleanRetiredStyles(); + for (auto iter = mStyles.Iter(); !iter.Done(); iter.Next()) { + CounterStyle* style = iter.Data(); + if (style->IsDependentStyle()) { + DestroyCounterStyle(style); + } } -#endif - mCacheTable.Clear(); + mStyles.Clear(); mPresContext = nullptr; } CounterStyle* CounterStyleManager::BuildCounterStyle(nsIAtom* aName) { - CounterStyle* data = mCacheTable.GetWeak(aName); + CounterStyle* data = mStyles.Get(aName); if (data) { return data; } @@ -2058,7 +2043,7 @@ CounterStyleManager::BuildCounterStyle(nsIAtom* aName) if (!data) { data = GetDecimalStyle(); } - mCacheTable.Put(aName, data); + mStyles.Put(aName, data); return data; } @@ -2076,9 +2061,8 @@ bool CounterStyleManager::NotifyRuleChanged() { bool changed = false; - nsTArray> kungFuDeathGrip; - for (auto iter = mCacheTable.Iter(); !iter.Done(); iter.Next()) { - RefPtr& style = iter.Data(); + for (auto iter = mStyles.Iter(); !iter.Done(); iter.Next()) { + CounterStyle* style = iter.Data(); bool toBeUpdated = false; bool toBeRemoved = false; // XXXheycam ServoStyleSets do not support custom counter styles yet. Bug @@ -2099,7 +2083,7 @@ CounterStyleManager::NotifyRuleChanged() if (!style->IsCustomStyle()) { toBeRemoved = true; } else { - auto custom = static_cast(style.get()); + auto custom = static_cast(style); if (custom->GetRule() != newRule) { toBeRemoved = true; } else if (custom->GetRuleGeneration() != newRule->GetGeneration()) { @@ -2111,25 +2095,16 @@ CounterStyleManager::NotifyRuleChanged() changed = changed || toBeUpdated || toBeRemoved; if (toBeRemoved) { if (style->IsDependentStyle()) { - if (style->IsCustomStyle()) { - // Since |style| is being removed from mCacheTable, it won't be - // visited by our post-removal iteration. So, we have to give it a - // manual ResetDependentData() call. (This only really matters if - // something else is holding a reference and keeping it alive.) - static_cast(style.get())->ResetDependentData(); - } - // The object has to be held here so that it will not be released - // before all pointers that refer to it are reset. It will be released - // when kungFuDeathGrip goes out of scope at the end of this function. - kungFuDeathGrip.AppendElement(style); + // Add object to retired list so we can clean them up later. + mRetiredStyles.AppendElement(style); } iter.Remove(); } } if (changed) { - for (auto iter = mCacheTable.Iter(); !iter.Done(); iter.Next()) { - CounterStyle* style = iter.UserData(); + for (auto iter = mStyles.Iter(); !iter.Done(); iter.Next()) { + CounterStyle* style = iter.Data(); if (style->IsCustomStyle()) { CustomCounterStyle* custom = static_cast(style); custom->ResetDependentData(); @@ -2141,4 +2116,13 @@ CounterStyleManager::NotifyRuleChanged() return changed; } +void +CounterStyleManager::CleanRetiredStyles() +{ + nsTArray list(Move(mRetiredStyles)); + for (CounterStyle* style : list) { + DestroyCounterStyle(style); + } +} + } // namespace mozilla diff --git a/layout/style/CounterStyleManager.h b/layout/style/CounterStyleManager.h index 5434f73becf4..e595bcb847f6 100644 --- a/layout/style/CounterStyleManager.h +++ b/layout/style/CounterStyleManager.h @@ -7,7 +7,7 @@ #define mozilla_CounterStyleManager_h_ #include "nsStringFwd.h" -#include "nsRefPtrHashtable.h" +#include "nsDataHashtable.h" #include "nsHashKeys.h" #include "nsStyleConsts.h" @@ -96,8 +96,6 @@ public: virtual AnonymousCounterStyle* AsAnonymous() { return nullptr; } - NS_INLINE_DECL_PURE_VIRTUAL_REFCOUNTING - protected: int32_t mStyle; }; @@ -132,7 +130,7 @@ public: uint8_t GetSystem() const { return mSystem; } const nsTArray& GetSymbols() const { return mSymbols; } - NS_INLINE_DECL_REFCOUNTING(AnonymousCounterStyle, override) + NS_INLINE_DECL_REFCOUNTING(AnonymousCounterStyle) private: ~AnonymousCounterStyle() {} @@ -142,6 +140,105 @@ private: nsTArray mSymbols; }; +// A smart pointer to CounterStyle. It either owns a reference to an +// anonymous counter style, or weakly refers to a named counter style +// managed by counter style manager. +class CounterStylePtr +{ +public: + CounterStylePtr() : mRaw(0) {} + CounterStylePtr(const CounterStylePtr& aOther) + : mRaw(aOther.mRaw) + { + if (IsAnonymous()) { + AsAnonymous()->AddRef(); + } + } + ~CounterStylePtr() { Reset(); } + + CounterStylePtr& operator=(const CounterStylePtr& aOther) + { + if (this != &aOther) { + Reset(); + new (this) CounterStylePtr(aOther); + } + return *this; + } + CounterStylePtr& operator=(decltype(nullptr)) + { + Reset(); + return *this; + } + CounterStylePtr& operator=(AnonymousCounterStyle* aCounterStyle) + { + Reset(); + if (aCounterStyle) { + CounterStyle* raw = do_AddRef(aCounterStyle).take(); + AssertPointerAligned(raw); + mRaw = reinterpret_cast(raw) | kAnonymousFlag; + } + return *this; + } + CounterStylePtr& operator=(CounterStyle* aCounterStyle) + { + Reset(); + if (aCounterStyle) { + MOZ_ASSERT(!aCounterStyle->AsAnonymous()); + AssertPointerAligned(aCounterStyle); + mRaw = reinterpret_cast(aCounterStyle); + } + return *this; + } + + operator CounterStyle*() const & { return Get(); } + operator CounterStyle*() const && = delete; + CounterStyle* operator->() const { return Get(); } + explicit operator bool() const { return !!mRaw; } + bool operator!() const { return !mRaw; } + bool operator==(const CounterStylePtr& aOther) const + { return mRaw == aOther.mRaw; } + bool operator!=(const CounterStylePtr& aOther) const + { return mRaw != aOther.mRaw; } + +private: + CounterStyle* Get() const + { + return reinterpret_cast(mRaw & ~kAnonymousFlag); + } + void AssertPointerAligned(CounterStyle* aPointer) + { + // This can be checked at compile time via + // > static_assert(alignof(CounterStyle) >= 2); + // but MSVC2015 doesn't support using alignof on an abstract class. + // Once we move to MSVC2017, we can replace this runtime check with + // the compile time check above. + MOZ_ASSERT(!(reinterpret_cast(aPointer) & kAnonymousFlag)); + } + + bool IsAnonymous() const { return !!(mRaw & kAnonymousFlag); } + AnonymousCounterStyle* AsAnonymous() + { + MOZ_ASSERT(IsAnonymous()); + return static_cast( + reinterpret_cast(mRaw & ~kAnonymousFlag)); + } + + void Reset() + { + if (IsAnonymous()) { + AsAnonymous()->Release(); + } + mRaw = 0; + } + + // mRaw contains the pointer, and its last bit is used for the flag. + // If the flag is set, this pointer owns an AnonymousCounterStyle, + // otherwise, it is a weak pointer referring a named counter style + // managed by CounterStyleManager. + static const uintptr_t kAnonymousFlag = 1; + uintptr_t mRaw; +}; + class CounterStyleManager final { private: @@ -156,7 +253,7 @@ public: bool IsInitial() const { // only 'none' and 'decimal' - return mCacheTable.Count() == 2; + return mStyles.Count() == 2; } CounterStyle* BuildCounterStyle(nsIAtom* aName); @@ -176,14 +273,21 @@ public: // if any counter style is changed, false elsewise. This method should // be called when any counter style may be affected. bool NotifyRuleChanged(); + // NotifyRuleChanged will evict no longer needed counter styles into + // mRetiredStyles, and this function destroys all objects listed there. + // It should be called only after no one may ever use those objects. + void CleanRetiredStyles(); nsPresContext* PresContext() const { return mPresContext; } NS_INLINE_DECL_REFCOUNTING(CounterStyleManager) private: + void DestroyCounterStyle(CounterStyle* aCounterStyle); + nsPresContext* mPresContext; - nsRefPtrHashtable, CounterStyle> mCacheTable; + nsDataHashtable, CounterStyle*> mStyles; + nsTArray mRetiredStyles; }; } // namespace mozilla diff --git a/layout/style/ServoBindings.cpp b/layout/style/ServoBindings.cpp index 3fdcf8ac3b1f..9bec8c23deee 100644 --- a/layout/style/ServoBindings.cpp +++ b/layout/style/ServoBindings.cpp @@ -1112,17 +1112,15 @@ Gecko_CopyImageOrientationFrom(nsStyleVisibility* aDst, } void -Gecko_SetListStyleType(nsStyleList* style_struct, uint32_t type) +Gecko_SetListStyleType(nsStyleList* aList, uint32_t aType) { - // Builtin counter styles are static and use no-op refcounting, and thus are - // safe to use off-main-thread. - style_struct->SetCounterStyle(CounterStyleManager::GetBuiltinStyle(type)); + aList->mCounterStyle = CounterStyleManager::GetBuiltinStyle(aType); } void -Gecko_CopyListStyleTypeFrom(nsStyleList* dst, const nsStyleList* src) +Gecko_CopyListStyleTypeFrom(nsStyleList* aDst, const nsStyleList* aSrc) { - dst->SetCounterStyle(src->GetCounterStyle()); + aDst->mCounterStyle = aSrc->mCounterStyle; } already_AddRefed diff --git a/layout/style/nsComputedDOMStyle.cpp b/layout/style/nsComputedDOMStyle.cpp index 8f11c743d40b..fea262b542a3 100644 --- a/layout/style/nsComputedDOMStyle.cpp +++ b/layout/style/nsComputedDOMStyle.cpp @@ -3714,13 +3714,13 @@ already_AddRefed nsComputedDOMStyle::DoGetListStyleType() { RefPtr val = new nsROCSSPrimitiveValue; - CounterStyle* style = StyleList()->GetCounterStyle(); + CounterStyle* style = StyleList()->mCounterStyle; AnonymousCounterStyle* anonymous = style->AsAnonymous(); nsAutoString tmp; if (!anonymous) { // want SetIdent nsString type; - StyleList()->GetListStyleType(type); + style->GetStyleName(type); nsStyleUtil::AppendEscapedCSSIdent(type, tmp); } else if (anonymous->IsSingleString()) { const nsTArray& symbols = anonymous->GetSymbols(); diff --git a/layout/style/nsRuleNode.cpp b/layout/style/nsRuleNode.cpp index 6f565179a45f..a3c4c7aead2e 100644 --- a/layout/style/nsRuleNode.cpp +++ b/layout/style/nsRuleNode.cpp @@ -7954,24 +7954,28 @@ nsRuleNode::ComputeListData(void* aStartStruct, // list-style-type: string, none, inherit, initial const nsCSSValue* typeValue = aRuleData->ValueForListStyleType(); + auto setListStyleType = [this, list](nsIAtom* type) { + list->mCounterStyle = mPresContext-> + CounterStyleManager()->BuildCounterStyle(type); + }; switch (typeValue->GetUnit()) { case eCSSUnit_Unset: case eCSSUnit_Inherit: { conditions.SetUncacheable(); - list->SetCounterStyle(parentList->GetCounterStyle()); + list->mCounterStyle = parentList->mCounterStyle; break; } case eCSSUnit_Initial: - list->SetListStyleType(nsGkAtoms::disc, mPresContext); + setListStyleType(nsGkAtoms::disc); break; case eCSSUnit_AtomIdent: { - list->SetListStyleType(typeValue->GetAtomValue(), mPresContext); + setListStyleType(typeValue->GetAtomValue()); break; } case eCSSUnit_String: { nsString str; typeValue->GetStringValue(str); - list->SetCounterStyle(new AnonymousCounterStyle(str)); + list->mCounterStyle = new AnonymousCounterStyle(str); break; } case eCSSUnit_Enumerated: { @@ -7997,11 +8001,12 @@ nsRuleNode::ComputeListData(void* aStartStruct, intValue, nsCSSProps::kListStyleKTable)); break; } - list->SetListStyleType(name, mPresContext); + setListStyleType(name); break; } case eCSSUnit_Symbols: - list->SetCounterStyle(new AnonymousCounterStyle(typeValue->GetArrayValue())); + list->mCounterStyle = + new AnonymousCounterStyle(typeValue->GetArrayValue()); break; case eCSSUnit_Null: break; diff --git a/layout/style/nsStyleStruct.h b/layout/style/nsStyleStruct.h index 9fece1219814..ff7e670c166e 100644 --- a/layout/style/nsStyleStruct.h +++ b/layout/style/nsStyleStruct.h @@ -1476,23 +1476,6 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleList already_AddRefed GetListStyleImageURI() const; - void GetListStyleType(nsSubstring& aType) const { mCounterStyle->GetStyleName(aType); } - mozilla::CounterStyle* GetCounterStyle() const - { - return mCounterStyle.get(); - } - void SetCounterStyle(mozilla::CounterStyle* aStyle) - { - // NB: This function is called off-main-thread during parallel restyle, but - // only with builtin styles that use dummy refcounting. - MOZ_ASSERT(NS_IsMainThread() || !aStyle->IsDependentStyle()); - mCounterStyle = aStyle; - } - void SetListStyleType(nsIAtom* aType, nsPresContext* aPresContext) - { - SetCounterStyle(aPresContext->CounterStyleManager()->BuildCounterStyle(aType)); - } - const nsStyleQuoteValues::QuotePairArray& GetQuotePairs() const; void SetQuotesInherit(const nsStyleList* aOther); @@ -1502,8 +1485,8 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleList uint8_t mListStylePosition; // [inherited] RefPtr mListStyleImage; // [inherited] + mozilla::CounterStylePtr mCounterStyle; // [inherited] private: - RefPtr mCounterStyle; // [inherited] RefPtr mQuotes; // [inherited] nsStyleList& operator=(const nsStyleList& aOther) = delete; public: