Bug 1967530 - Remove some xpcom gunk from nsITheme. r=win-reviewers,gstoll

Differential Revision: https://phabricator.services.mozilla.com/D250282
This commit is contained in:
Emilio Cobos Álvarez
2025-05-20 20:06:06 +00:00
committed by ealvarez@mozilla.com
parent 9531e0dcfa
commit c6c3fc84c0
11 changed files with 65 additions and 95 deletions

View File

@@ -80,10 +80,11 @@ class nsITheme : public nsISupports {
* box-shadow, though it's not a hard requirement.
*/
enum class DrawOverflow { No, Yes };
NS_IMETHOD DrawWidgetBackground(gfxContext* aContext, nsIFrame* aFrame,
StyleAppearance aWidgetType,
const nsRect& aRect, const nsRect& aDirtyRect,
DrawOverflow = DrawOverflow::Yes) = 0;
virtual void DrawWidgetBackground(gfxContext* aContext, nsIFrame* aFrame,
StyleAppearance aWidgetType,
const nsRect& aRect,
const nsRect& aDirtyRect,
DrawOverflow = DrawOverflow::Yes) = 0;
/**
* Create WebRender commands for the theme background.
@@ -182,7 +183,7 @@ class nsITheme : public nsISupports {
virtual bool WidgetAttributeChangeRequiresRepaint(StyleAppearance,
nsAtom* aAttribute) = 0;
NS_IMETHOD ThemeChanged() = 0;
virtual void ThemeChanged() {}
virtual bool WidgetAppearanceDependsOnWindowFocus(
StyleAppearance aWidgetType) {

View File

@@ -1043,16 +1043,13 @@ void Theme::PaintButton(PaintBackendData& aPaintData,
}
}
NS_IMETHODIMP
Theme::DrawWidgetBackground(gfxContext* aContext, nsIFrame* aFrame,
StyleAppearance aAppearance, const nsRect& aRect,
const nsRect& /* aDirtyRect */,
DrawOverflow aDrawOverflow) {
if (!DoDrawWidgetBackground(*aContext->GetDrawTarget(), aFrame, aAppearance,
aRect, aDrawOverflow)) {
return NS_ERROR_NOT_IMPLEMENTED;
}
return NS_OK;
void Theme::DrawWidgetBackground(gfxContext* aContext, nsIFrame* aFrame,
StyleAppearance aAppearance,
const nsRect& aRect,
const nsRect& /* aDirtyRect */,
DrawOverflow aDrawOverflow) {
DoDrawWidgetBackground(*aContext->GetDrawTarget(), aFrame, aAppearance, aRect,
aDrawOverflow);
}
bool Theme::CreateWebRenderCommandsForWidget(
@@ -1588,9 +1585,6 @@ bool Theme::WidgetAttributeChangeRequiresRepaint(StyleAppearance aAppearance,
aAttribute == nsGkAtoms::_default || aAttribute == nsGkAtoms::open;
}
NS_IMETHODIMP
Theme::ThemeChanged() { return NS_OK; }
bool Theme::WidgetAppearanceDependsOnWindowFocus(StyleAppearance aAppearance) {
return IsWidgetScrollbarPart(aAppearance);
}

View File

@@ -48,10 +48,9 @@ class Theme : protected nsNativeTheme, public nsITheme {
NS_DECL_ISUPPORTS_INHERITED
// The nsITheme interface.
NS_IMETHOD DrawWidgetBackground(gfxContext* aContext, nsIFrame*,
StyleAppearance, const nsRect& aRect,
const nsRect& aDirtyRect,
DrawOverflow) override;
void DrawWidgetBackground(gfxContext* aContext, nsIFrame*, StyleAppearance,
const nsRect& aRect, const nsRect& aDirtyRect,
DrawOverflow) override;
bool CreateWebRenderCommandsForWidget(
wr::DisplayListBuilder& aBuilder, wr::IpcResourceUpdateQueue& aResources,
@@ -79,7 +78,6 @@ class Theme : protected nsNativeTheme, public nsITheme {
Transparency GetWidgetTransparency(nsIFrame*, StyleAppearance) override;
bool WidgetAttributeChangeRequiresRepaint(StyleAppearance,
nsAtom* aAttribute) override;
NS_IMETHOD ThemeChanged() override;
bool WidgetAppearanceDependsOnWindowFocus(StyleAppearance) override;
/*bool NeedToClearBackgroundBehindWidget(
nsIFrame*, StyleAppearance) override;*/

View File

@@ -10,16 +10,16 @@
namespace mozilla::widget {
NS_IMETHODIMP
ThemeCocoa::DrawWidgetBackground(gfxContext* aContext, nsIFrame* aFrame,
StyleAppearance aAppearance,
const nsRect& aRect, const nsRect& aDirtyRect,
DrawOverflow aDrawOverflow) {
void ThemeCocoa::DrawWidgetBackground(gfxContext* aContext, nsIFrame* aFrame,
StyleAppearance aAppearance,
const nsRect& aRect,
const nsRect& aDirtyRect,
DrawOverflow aDrawOverflow) {
switch (aAppearance) {
case StyleAppearance::Tooltip:
// Cocoa tooltip background and border are already drawn by the
// OS window server.
return NS_OK;
return;
default:
break;
}

View File

@@ -16,10 +16,9 @@ class ThemeCocoa : public Theme {
explicit ThemeCocoa(UniquePtr<ScrollbarDrawing>&& aScrollbarDrawing)
: Theme(std::move(aScrollbarDrawing)) {}
NS_IMETHOD DrawWidgetBackground(gfxContext* aContext, nsIFrame*,
StyleAppearance, const nsRect& aRect,
const nsRect& aDirtyRect,
DrawOverflow) override;
void DrawWidgetBackground(gfxContext* aContext, nsIFrame*, StyleAppearance,
const nsRect& aRect, const nsRect& aDirtyRect,
DrawOverflow) override;
bool CreateWebRenderCommandsForWidget(
wr::DisplayListBuilder& aBuilder, wr::IpcResourceUpdateQueue& aResources,

View File

@@ -230,10 +230,9 @@ class nsNativeThemeCocoa : public mozilla::widget::ThemeCocoa {
NS_DECL_ISUPPORTS_INHERITED
// The nsITheme interface.
NS_IMETHOD DrawWidgetBackground(gfxContext* aContext, nsIFrame*,
StyleAppearance, const nsRect& aRect,
const nsRect& aDirtyRect,
DrawOverflow) override;
void DrawWidgetBackground(gfxContext* aContext, nsIFrame*, StyleAppearance,
const nsRect& aRect, const nsRect& aDirtyRect,
DrawOverflow) override;
bool CreateWebRenderCommandsForWidget(
mozilla::wr::DisplayListBuilder& aBuilder,
mozilla::wr::IpcResourceUpdateQueue& aResources,
@@ -254,7 +253,6 @@ class nsNativeThemeCocoa : public mozilla::widget::ThemeCocoa {
StyleAppearance) override;
bool WidgetAttributeChangeRequiresRepaint(StyleAppearance,
nsAtom* aAttribute) override;
NS_IMETHOD ThemeChanged() override;
bool ThemeSupportsWidget(nsPresContext* aPresContext, nsIFrame*,
StyleAppearance) override;
bool WidgetIsContainer(StyleAppearance) override;

View File

@@ -2137,13 +2137,10 @@ Maybe<nsNativeThemeCocoa::WidgetInfo> nsNativeThemeCocoa::ComputeWidgetInfo(
NS_OBJC_END_TRY_BLOCK_RETURN(Nothing());
}
NS_IMETHODIMP
nsNativeThemeCocoa::DrawWidgetBackground(gfxContext* aContext, nsIFrame* aFrame,
StyleAppearance aAppearance,
const nsRect& aRect,
const nsRect& aDirtyRect,
DrawOverflow aDrawOverflow) {
NS_OBJC_BEGIN_TRY_BLOCK_RETURN;
void nsNativeThemeCocoa::DrawWidgetBackground(
gfxContext* aContext, nsIFrame* aFrame, StyleAppearance aAppearance,
const nsRect& aRect, const nsRect& aDirtyRect, DrawOverflow aDrawOverflow) {
NS_OBJC_BEGIN_TRY_IGNORE_BLOCK;
if (IsWidgetAlwaysNonNative(aFrame, aAppearance)) {
return ThemeCocoa::DrawWidgetBackground(aContext, aFrame, aAppearance,
@@ -2153,7 +2150,7 @@ nsNativeThemeCocoa::DrawWidgetBackground(gfxContext* aContext, nsIFrame* aFrame,
Maybe<WidgetInfo> widgetInfo = ComputeWidgetInfo(aFrame, aAppearance, aRect);
if (!widgetInfo) {
return NS_OK;
return;
}
int32_t p2a = aFrame->PresContext()->AppUnitsPerDevPixel();
@@ -2169,9 +2166,7 @@ nsNativeThemeCocoa::DrawWidgetBackground(gfxContext* aContext, nsIFrame* aFrame,
nativeWidgetRect, NSRectToRect(aDirtyRect, p2a),
hidpi ? 2.0f : 1.0f);
return NS_OK;
NS_OBJC_END_TRY_BLOCK_RETURN(NS_ERROR_FAILURE);
NS_OBJC_END_TRY_IGNORE_BLOCK
}
void nsNativeThemeCocoa::RenderWidget(const WidgetInfo& aWidgetInfo,
@@ -2708,14 +2703,6 @@ bool nsNativeThemeCocoa::WidgetAttributeChangeRequiresRepaint(
return Theme::WidgetAttributeChangeRequiresRepaint(aAppearance, aAttribute);
}
NS_IMETHODIMP
nsNativeThemeCocoa::ThemeChanged() {
// This is unimplemented because we don't care if gecko changes its theme
// and macOS system appearance changes are handled by
// nsLookAndFeel::SystemWantsDarkTheme.
return NS_OK;
}
bool nsNativeThemeCocoa::ThemeSupportsWidget(nsPresContext* aPresContext,
nsIFrame* aFrame,
StyleAppearance aAppearance) {

View File

@@ -296,12 +296,9 @@ static void DrawThemeWithCairo(gfxContext* aContext, DrawTarget* aDrawTarget,
}
}
NS_IMETHODIMP
nsNativeThemeGTK::DrawWidgetBackground(gfxContext* aContext, nsIFrame* aFrame,
StyleAppearance aAppearance,
const nsRect& aRect,
const nsRect& aDirtyRect,
DrawOverflow aDrawOverflow) {
void nsNativeThemeGTK::DrawWidgetBackground(
gfxContext* aContext, nsIFrame* aFrame, StyleAppearance aAppearance,
const nsRect& aRect, const nsRect& aDirtyRect, DrawOverflow aDrawOverflow) {
if (IsWidgetNonNative(aFrame, aAppearance) != NonNative::No) {
return Theme::DrawWidgetBackground(aContext, aFrame, aAppearance, aRect,
aDirtyRect, aDrawOverflow);
@@ -309,7 +306,7 @@ nsNativeThemeGTK::DrawWidgetBackground(gfxContext* aContext, nsIFrame* aFrame,
auto gtkType = GeckoToGtkWidgetType(aAppearance);
if (!gtkType) {
return NS_OK;
return;
}
gfxContext* ctx = aContext;
@@ -348,7 +345,7 @@ nsNativeThemeGTK::DrawWidgetBackground(gfxContext* aContext, nsIFrame* aFrame,
int32_t(dirtyRect.Width()), int32_t(dirtyRect.Height()));
if (widgetRect.IsEmpty() ||
!drawingRect.IntersectRect(widgetRect, drawingRect)) {
return NS_OK;
return;
}
Transparency transparency = GetWidgetTransparency(aFrame, aAppearance);
@@ -379,8 +376,6 @@ nsNativeThemeGTK::DrawWidgetBackground(gfxContext* aContext, nsIFrame* aFrame,
DrawThemeWithCairo(ctx, aContext->GetDrawTarget(), params, scaleFactor.scale,
snapped, ToPoint(origin),
drawingRect.Size().ToUnknownSize(), transparency);
return NS_OK;
}
bool nsNativeThemeGTK::CreateWebRenderCommandsForWidget(

View File

@@ -13,9 +13,9 @@ class nsNativeThemeGTK final : public mozilla::widget::Theme {
public:
// The nsITheme interface.
NS_IMETHOD DrawWidgetBackground(gfxContext*, nsIFrame*, StyleAppearance,
const nsRect& aRect, const nsRect& aDirtyRect,
DrawOverflow) override;
void DrawWidgetBackground(gfxContext*, nsIFrame*, StyleAppearance,
const nsRect& aRect, const nsRect& aDirtyRect,
DrawOverflow) override;
bool CreateWebRenderCommandsForWidget(
mozilla::wr::DisplayListBuilder&, mozilla::wr::IpcResourceUpdateQueue&,
@@ -54,7 +54,7 @@ class nsNativeThemeGTK final : public mozilla::widget::Theme {
bool WidgetAttributeChangeRequiresRepaint(StyleAppearance,
nsAtom* aAttribute) override;
NS_IMETHOD ThemeChanged() override;
void ThemeChanged() override;
bool ThemeSupportsWidget(nsPresContext*, nsIFrame*, StyleAppearance) override;
bool WidgetIsContainer(StyleAppearance) override;

View File

@@ -810,29 +810,30 @@ static inline double GetThemeDpiScaleFactor(nsIFrame* aFrame) {
return GetThemeDpiScaleFactor(aFrame->PresContext());
}
NS_IMETHODIMP
nsNativeThemeWin::DrawWidgetBackground(gfxContext* aContext, nsIFrame* aFrame,
StyleAppearance aAppearance,
const nsRect& aRect,
const nsRect& aDirtyRect,
DrawOverflow aDrawOverflow) {
void nsNativeThemeWin::DrawWidgetBackground(
gfxContext* aContext, nsIFrame* aFrame, StyleAppearance aAppearance,
const nsRect& aRect, const nsRect& aDirtyRect, DrawOverflow aDrawOverflow) {
if (IsWidgetNonNative(aFrame, aAppearance) != NonNative::No) {
return Theme::DrawWidgetBackground(aContext, aFrame, aAppearance, aRect,
aDirtyRect, aDrawOverflow);
}
HANDLE theme = GetTheme(aAppearance);
if (!theme)
return ClassicDrawWidgetBackground(aContext, aFrame, aAppearance, aRect,
aDirtyRect);
if (!theme) {
ClassicDrawWidgetBackground(aContext, aFrame, aAppearance, aRect,
aDirtyRect);
return;
}
// ^^ without the right sdk, assume xp theming and fall through.
int32_t part, state;
nsresult rv = GetThemePartAndState(aFrame, aAppearance, part, state);
if (NS_FAILED(rv)) return rv;
if (NS_FAILED(rv)) {
return;
}
if (AssumeThemePartAndStateAreTransparent(part, state)) {
return NS_OK;
return;
}
gfxContextMatrixAutoSaveRestore save(aContext);
@@ -859,7 +860,9 @@ nsNativeThemeWin::DrawWidgetBackground(gfxContext* aContext, nsIFrame* aFrame,
RENDER_AGAIN:
HDC hdc = nativeDrawing.BeginNativeDrawing();
if (!hdc) return NS_ERROR_FAILURE;
if (!hdc) {
return;
}
nativeDrawing.TransformToNativeRect(tr, widgetRect);
nativeDrawing.TransformToNativeRect(dr, clipRect);
@@ -991,8 +994,6 @@ RENDER_AGAIN:
if (nativeDrawing.ShouldRenderAgain()) goto RENDER_AGAIN;
nativeDrawing.PaintToContext();
return NS_OK;
}
bool nsNativeThemeWin::CreateWebRenderCommandsForWidget(
@@ -1263,12 +1264,10 @@ bool nsNativeThemeWin::WidgetAttributeChangeRequiresRepaint(
return Theme::WidgetAttributeChangeRequiresRepaint(aAppearance, aAttribute);
}
NS_IMETHODIMP
nsNativeThemeWin::ThemeChanged() {
void nsNativeThemeWin::ThemeChanged() {
memset(mBorderCacheValid, 0, sizeof(mBorderCacheValid));
memset(mMinimumWidgetSizeCacheValid, 0, sizeof(mMinimumWidgetSizeCacheValid));
mGutterSizeCacheValid = false;
return NS_OK;
}
bool nsNativeThemeWin::ThemeSupportsWidget(nsPresContext* aPresContext,
@@ -1626,8 +1625,8 @@ nsresult nsNativeThemeWin::ClassicDrawWidgetBackground(
int32_t part, state;
bool focused;
nsresult rv;
rv = ClassicGetThemePartAndState(aFrame, aAppearance, part, state, focused);
if (NS_FAILED(rv)) return rv;
MOZ_TRY(
ClassicGetThemePartAndState(aFrame, aAppearance, part, state, focused));
if (AssumeThemePartAndStateAreTransparent(part, state)) {
return NS_OK;

View File

@@ -38,10 +38,9 @@ class nsNativeThemeWin final : public Theme {
NonNative IsWidgetNonNative(nsIFrame*, StyleAppearance);
// The nsITheme interface.
NS_IMETHOD DrawWidgetBackground(gfxContext* aContext, nsIFrame* aFrame,
StyleAppearance aAppearance,
const nsRect& aRect, const nsRect& aDirtyRect,
DrawOverflow) override;
void DrawWidgetBackground(gfxContext* aContext, nsIFrame* aFrame,
StyleAppearance aAppearance, const nsRect& aRect,
const nsRect& aDirtyRect, DrawOverflow) override;
bool CreateWebRenderCommandsForWidget(wr::DisplayListBuilder&,
wr::IpcResourceUpdateQueue&,
@@ -72,7 +71,7 @@ class nsNativeThemeWin final : public Theme {
bool WidgetAttributeChangeRequiresRepaint(StyleAppearance aAppearance,
nsAtom* aAttribute) override;
NS_IMETHOD ThemeChanged() override;
void ThemeChanged() override;
bool ThemeSupportsWidget(nsPresContext* aPresContext, nsIFrame* aFrame,
StyleAppearance aAppearance) override;