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();
nsRepeatService::Shutdown();
nsStackLayout::Shutdown();
nsBox::Shutdown();
#ifdef MOZ_XUL
nsXULContentUtils::Finish();

View File

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

View File

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

View File

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