Bug 1619664 - Remove nsBox::gTheme. r=dholbert

The boxes can just poke at the prescontext theme like literally everything else.

Differential Revision: https://phabricator.services.mozilla.com/D65161
This commit is contained in:
Emilio Cobos Álvarez
2020-03-03 23:39:07 +00:00
parent 514d6b9db1
commit ab3e2032e5
4 changed files with 21 additions and 37 deletions

View File

@@ -348,7 +348,6 @@ void nsLayoutStatics::Shutdown() {
nsCSSProps::ReleaseTable(); nsCSSProps::ReleaseTable();
nsRepeatService::Shutdown(); nsRepeatService::Shutdown();
nsStackLayout::Shutdown(); nsStackLayout::Shutdown();
nsBox::Shutdown();
#ifdef MOZ_XUL #ifdef MOZ_XUL
nsXULContentUtils::Finish(); nsXULContentUtils::Finish();

View File

@@ -53,18 +53,9 @@ nsresult nsBox::EndXULLayout(nsBoxLayoutState& aState) {
return SyncLayout(aState); return SyncLayout(aState);
} }
bool nsBox::gGotTheme = false;
StaticRefPtr<nsITheme> nsBox::gTheme;
nsBox::nsBox(ComputedStyle* aStyle, nsPresContext* aPresContext, ClassID aID) nsBox::nsBox(ComputedStyle* aStyle, nsPresContext* aPresContext, ClassID aID)
: nsIFrame(aStyle, aPresContext, aID) { : nsIFrame(aStyle, aPresContext, aID) {
MOZ_COUNT_CTOR(nsBox); MOZ_COUNT_CTOR(nsBox);
if (!gGotTheme) {
gTheme = do_GetNativeTheme();
if (gTheme) {
gGotTheme = true;
}
}
} }
nsBox::~nsBox() { nsBox::~nsBox() {
@@ -73,12 +64,6 @@ nsBox::~nsBox() {
MOZ_COUNT_DTOR(nsBox); MOZ_COUNT_DTOR(nsBox);
} }
/* static */
void nsBox::Shutdown() {
gGotTheme = false;
gTheme = nullptr;
}
nsresult nsBox::XULRelayoutChildAtOrdinal(nsIFrame* aChild) { return NS_OK; } nsresult nsBox::XULRelayoutChildAtOrdinal(nsIFrame* aChild) { return NS_OK; }
nsresult nsIFrame::GetXULClientRect(nsRect& aClientRect) { nsresult nsIFrame::GetXULClientRect(nsRect& aClientRect) {
@@ -142,14 +127,15 @@ nsresult nsBox::GetXULBorder(nsMargin& aMargin) {
aMargin.SizeTo(0, 0, 0, 0); aMargin.SizeTo(0, 0, 0, 0);
const nsStyleDisplay* disp = StyleDisplay(); const nsStyleDisplay* disp = StyleDisplay();
if (disp->HasAppearance() && gTheme) { if (disp->HasAppearance()) {
// Go to the theme for the border. // Go to the theme for the border.
nsPresContext* context = PresContext(); nsPresContext* pc = PresContext();
if (gTheme->ThemeSupportsWidget(context, this, disp->mAppearance)) { nsITheme* theme = pc->GetTheme();
LayoutDeviceIntMargin margin = gTheme->GetWidgetBorder( if (theme && theme->ThemeSupportsWidget(pc, this, disp->mAppearance)) {
context->DeviceContext(), this, disp->mAppearance); LayoutDeviceIntMargin margin =
theme->GetWidgetBorder(pc->DeviceContext(), this, disp->mAppearance);
aMargin = aMargin =
LayoutDevicePixel::ToAppUnits(margin, context->AppUnitsPerDevPixel()); LayoutDevicePixel::ToAppUnits(margin, pc->AppUnitsPerDevPixel());
return NS_OK; return NS_OK;
} }
} }
@@ -161,16 +147,17 @@ nsresult nsBox::GetXULBorder(nsMargin& aMargin) {
nsresult nsBox::GetXULPadding(nsMargin& aPadding) { nsresult nsBox::GetXULPadding(nsMargin& aPadding) {
const nsStyleDisplay* disp = StyleDisplay(); const nsStyleDisplay* disp = StyleDisplay();
if (disp->HasAppearance() && gTheme) { if (disp->HasAppearance()) {
// Go to the theme for the padding. // Go to the theme for the padding.
nsPresContext* context = PresContext(); nsPresContext* pc = PresContext();
if (gTheme->ThemeSupportsWidget(context, this, disp->mAppearance)) { nsITheme* theme = pc->GetTheme();
if (theme && theme->ThemeSupportsWidget(pc, this, disp->mAppearance)) {
LayoutDeviceIntMargin padding; LayoutDeviceIntMargin padding;
bool useThemePadding = gTheme->GetWidgetPadding( bool useThemePadding = theme->GetWidgetPadding(
context->DeviceContext(), this, disp->mAppearance, &padding); pc->DeviceContext(), this, disp->mAppearance, &padding);
if (useThemePadding) { if (useThemePadding) {
aPadding = LayoutDevicePixel::ToAppUnits( aPadding =
padding, context->AppUnitsPerDevPixel()); LayoutDevicePixel::ToAppUnits(padding, pc->AppUnitsPerDevPixel());
return NS_OK; return NS_OK;
} }
} }

View File

@@ -17,8 +17,6 @@ class nsBox : public nsIFrame {
public: public:
friend class nsIFrame; friend class nsIFrame;
static void Shutdown();
virtual nsSize GetXULPrefSize(nsBoxLayoutState& aBoxLayoutState) override; virtual nsSize GetXULPrefSize(nsBoxLayoutState& aBoxLayoutState) override;
virtual nsSize GetXULMinSize(nsBoxLayoutState& aBoxLayoutState) override; virtual nsSize GetXULMinSize(nsBoxLayoutState& aBoxLayoutState) override;
virtual nsSize GetXULMaxSize(nsBoxLayoutState& aBoxLayoutState) override; virtual nsSize GetXULMaxSize(nsBoxLayoutState& aBoxLayoutState) override;
@@ -81,9 +79,6 @@ class nsBox : public nsIFrame {
nsresult BeginXULLayout(nsBoxLayoutState& aState); nsresult BeginXULLayout(nsBoxLayoutState& aState);
NS_IMETHOD DoXULLayout(nsBoxLayoutState& aBoxLayoutState); NS_IMETHOD DoXULLayout(nsBoxLayoutState& aBoxLayoutState);
nsresult EndXULLayout(nsBoxLayoutState& aState); nsresult EndXULLayout(nsBoxLayoutState& aState);
static bool gGotTheme;
static mozilla::StaticRefPtr<nsITheme> gTheme;
}; };
#endif #endif

View File

@@ -606,10 +606,13 @@ bool nsImageBoxFrame::CanOptimizeToImageLayer() {
imgRequestProxy* nsImageBoxFrame::GetRequestFromStyle() { imgRequestProxy* nsImageBoxFrame::GetRequestFromStyle() {
const nsStyleDisplay* disp = StyleDisplay(); const nsStyleDisplay* disp = StyleDisplay();
if (disp->HasAppearance() && nsBox::gTheme && if (disp->HasAppearance()) {
nsBox::gTheme->ThemeSupportsWidget(nullptr, this, disp->mAppearance)) { nsPresContext* pc = PresContext();
nsITheme* theme = pc->GetTheme();
if (theme && theme->ThemeSupportsWidget(pc, this, disp->mAppearance)) {
return nullptr; return nullptr;
} }
}
return StyleList()->GetListStyleImage(); return StyleList()->GetListStyleImage();
} }