diff --git a/layout/base/nsLayoutUtils.cpp b/layout/base/nsLayoutUtils.cpp index b0dae69150..085e0e5ef4 100644 --- a/layout/base/nsLayoutUtils.cpp +++ b/layout/base/nsLayoutUtils.cpp @@ -9338,7 +9338,7 @@ nsLayoutUtils::ComputeGeometryBox(nsIFrame* aFrame, return r; } -/* static */ nsStyleContext* +/* static */ already_AddRefed nsLayoutUtils::GetNonAnonymousStyleContext(nsIFrame* aFrame) { nsIContent* node = aFrame->GetContent(); @@ -9348,7 +9348,8 @@ nsLayoutUtils::GetNonAnonymousStyleContext(nsIFrame* aFrame) } MOZ_ASSERT(node, "Native anonymous element with no originating node?"); if (nsIFrame* primaryFrame = node->GetPrimaryFrame()) { - return primaryFrame->StyleContext(); + RefPtr context = primaryFrame->StyleContext(); + return context.forget(); } // If the element doesn't have primary frame, get the computed style // from the element directly. @@ -9356,9 +9357,5 @@ nsLayoutUtils::GetNonAnonymousStyleContext(nsIFrame* aFrame) MOZ_ASSERT(node == pc->Document()->GetRootElement(), "Root element is the only case for this fallback " "path to be triggered"); - RefPtr styleContext = - pc->StyleSet()->ResolveStyleFor(node->AsElement(), nullptr); - // Dropping the strong reference is fine because the style should be - // held strongly by the element. - return styleContext.get(); + return pc->StyleSet()->ResolveStyleFor(node->AsElement(), nullptr); } diff --git a/layout/base/nsLayoutUtils.h b/layout/base/nsLayoutUtils.h index ea9a026007..b18edbc9c9 100644 --- a/layout/base/nsLayoutUtils.h +++ b/layout/base/nsLayoutUtils.h @@ -2885,7 +2885,7 @@ public: * @param aFrame The frame associated with native anonymous content. * @return The resolved style context of the nearest non-anonymous DOM ancestor. */ - static nsStyleContext* GetNonAnonymousStyleContext(nsIFrame* aFrame); + static already_AddRefed GetNonAnonymousStyleContext(nsIFrame* aFrame); private: static uint32_t sFontSizeInflationEmPerLine; diff --git a/layout/generic/nsGfxScrollFrame.cpp b/layout/generic/nsGfxScrollFrame.cpp index 53b028837b..f6fe2bf77f 100644 --- a/layout/generic/nsGfxScrollFrame.cpp +++ b/layout/generic/nsGfxScrollFrame.cpp @@ -1060,7 +1060,7 @@ nsHTMLScrollFrame::Reflow(nsPresContext* aPresContext, // This is only needed for root element because scrollbars of non- // root elements with "scrollbar-width: none" is already suppressed // in ScrollFrameHelper::CreateAnonymousContent. - nsStyleContext* scrollbarStyle = nsLayoutUtils::GetNonAnonymousStyleContext(this); + RefPtr scrollbarStyle = nsLayoutUtils::GetNonAnonymousStyleContext(this); auto scrollbarWidth = scrollbarStyle->StyleUIReset()->mScrollbarWidth; if (scrollbarWidth == StyleScrollbarWidth::None) { state.mVScrollbar = ShowScrollbar::Never; diff --git a/widget/cocoa/nsNativeThemeCocoa.mm b/widget/cocoa/nsNativeThemeCocoa.mm index 056c453f2a..ad16ecb0ec 100644 --- a/widget/cocoa/nsNativeThemeCocoa.mm +++ b/widget/cocoa/nsNativeThemeCocoa.mm @@ -2282,7 +2282,9 @@ IsHiDPIContext(nsPresContext* aContext) static bool IsScrollbarWidthThin(nsIFrame* aFrame) { - return aFrame->StyleUserInterface()->mScrollbarWidth == StyleScrollbarWidth::Thin; + RefPtr styleContext = nsLayoutUtils::GetNonAnonymousStyleContext(aFrame); + auto scrollbarWidth = styleContext->StyleUIReset()->mScrollbarWidth; + return scrollbarWidth == StyleScrollbarWidth::Thin; } NS_IMETHODIMP diff --git a/widget/gtk/nsNativeThemeGTK.cpp b/widget/gtk/nsNativeThemeGTK.cpp index cb4e7debf2..59f611e723 100644 --- a/widget/gtk/nsNativeThemeGTK.cpp +++ b/widget/gtk/nsNativeThemeGTK.cpp @@ -1101,7 +1101,9 @@ nsNativeThemeGTK::GetExtraSizeForWidget(nsIFrame* aFrame, uint8_t aWidgetType, static bool IsScrollbarWidthThin(nsIFrame* aFrame) { - return aFrame->StyleUserInterface()->mScrollbarWidth == StyleScrollbarWidth::Thin; + RefPtr styleContext = nsLayoutUtils::GetNonAnonymousStyleContext(aFrame); + auto scrollbarWidth = styleContext->StyleUIReset()->mScrollbarWidth; + return scrollbarWidth == StyleScrollbarWidth::Thin; } NS_IMETHODIMP diff --git a/widget/windows/nsNativeThemeWin.cpp b/widget/windows/nsNativeThemeWin.cpp index 3250fec5c9..cb14f74f69 100644 --- a/widget/windows/nsNativeThemeWin.cpp +++ b/widget/windows/nsNativeThemeWin.cpp @@ -1572,7 +1572,7 @@ GetThemeDpiScaleFactor(nsIFrame* aFrame) static bool IsScrollbarWidthThin(nsIFrame* aFrame) { - nsStyleContext* styleContext = nsLayoutUtils::GetNonAnonymousStyleContext(aFrame); + RefPtr styleContext = nsLayoutUtils::GetNonAnonymousStyleContext(aFrame); auto scrollbarWidth = styleContext->StyleUIReset()->mScrollbarWidth; return scrollbarWidth == StyleScrollbarWidth::Thin; }