mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-26 04:09:50 +00:00
Bug 1749531 - Manage native theme lifetime from Theme.cpp. r=mstange
Differential Revision: https://phabricator.services.mozilla.com/D136127
This commit is contained in:
parent
8fd03d2f80
commit
4c41f32a27
@ -32,6 +32,9 @@ namespace layers {
|
||||
class StackingContextHelper;
|
||||
class RenderRootStateManager;
|
||||
} // namespace layers
|
||||
namespace widget {
|
||||
class Theme;
|
||||
} // namespace widget
|
||||
namespace wr {
|
||||
class DisplayListBuilder;
|
||||
class IpcResourceUpdateQueue;
|
||||
@ -268,4 +271,8 @@ extern already_AddRefed<nsITheme> do_GetNativeThemeDoNotUseDirectly();
|
||||
extern already_AddRefed<nsITheme> do_GetBasicNativeThemeDoNotUseDirectly();
|
||||
extern already_AddRefed<nsITheme> do_GetRDMThemeDoNotUseDirectly();
|
||||
|
||||
// Native theme creation function, these should never return null.
|
||||
extern already_AddRefed<mozilla::widget::Theme>
|
||||
do_CreateNativeThemeDoNotUseDirectly();
|
||||
|
||||
#endif
|
||||
|
@ -107,30 +107,39 @@ struct MOZ_RAII AutoClipRect {
|
||||
DrawTarget& mDt;
|
||||
};
|
||||
|
||||
static StaticRefPtr<nsITheme> gInstance;
|
||||
static StaticRefPtr<nsITheme> gRDMInstance;
|
||||
static StaticRefPtr<Theme> gNativeInstance;
|
||||
static StaticRefPtr<Theme> gNonNativeInstance;
|
||||
static StaticRefPtr<Theme> gRDMInstance;
|
||||
|
||||
} // namespace
|
||||
|
||||
#ifdef ANDROID
|
||||
already_AddRefed<Theme> do_CreateNativeThemeDoNotUseDirectly() {
|
||||
// Android doesn't have a native theme.
|
||||
return do_AddRef(new Theme(Theme::ScrollbarStyle()));
|
||||
}
|
||||
#endif
|
||||
|
||||
already_AddRefed<nsITheme> do_GetBasicNativeThemeDoNotUseDirectly() {
|
||||
if (MOZ_UNLIKELY(!gInstance)) {
|
||||
if (MOZ_UNLIKELY(!gNonNativeInstance)) {
|
||||
UniquePtr<ScrollbarDrawing> scrollbarDrawing = Theme::ScrollbarStyle();
|
||||
#ifdef MOZ_WIDGET_COCOA
|
||||
gInstance = new ThemeCocoa(std::move(scrollbarDrawing));
|
||||
gNonNativeInstance = new ThemeCocoa(std::move(scrollbarDrawing));
|
||||
#else
|
||||
gInstance = new Theme(std::move(scrollbarDrawing));
|
||||
gNonNativeInstance = new Theme(std::move(scrollbarDrawing));
|
||||
#endif
|
||||
ClearOnShutdown(&gInstance);
|
||||
ClearOnShutdown(&gNonNativeInstance);
|
||||
}
|
||||
return do_AddRef(gInstance);
|
||||
return do_AddRef(gNonNativeInstance);
|
||||
}
|
||||
|
||||
#ifdef ANDROID
|
||||
already_AddRefed<nsITheme> do_GetNativeThemeDoNotUseDirectly() {
|
||||
// Android doesn't have a native theme.
|
||||
return do_GetBasicNativeThemeDoNotUseDirectly();
|
||||
if (MOZ_UNLIKELY(!gNativeInstance)) {
|
||||
gNativeInstance = do_CreateNativeThemeDoNotUseDirectly();
|
||||
ClearOnShutdown(&gNativeInstance);
|
||||
}
|
||||
return do_AddRef(gNativeInstance);
|
||||
}
|
||||
#endif
|
||||
|
||||
already_AddRefed<nsITheme> do_GetRDMThemeDoNotUseDirectly() {
|
||||
if (MOZ_UNLIKELY(!gRDMInstance)) {
|
||||
@ -167,10 +176,9 @@ void Theme::Shutdown() {
|
||||
/* static */
|
||||
void Theme::LookAndFeelChanged() {
|
||||
ThemeColors::RecomputeAccentColors();
|
||||
auto* basicTheme = static_cast<Theme*>(gInstance.get());
|
||||
if (basicTheme) {
|
||||
basicTheme->SetScrollbarDrawing(Theme::ScrollbarStyle());
|
||||
basicTheme->GetScrollbarDrawing().RecomputeScrollbarParams();
|
||||
if (gNonNativeInstance) {
|
||||
gNonNativeInstance->SetScrollbarDrawing(Theme::ScrollbarStyle());
|
||||
gNonNativeInstance->GetScrollbarDrawing().RecomputeScrollbarParams();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3644,13 +3644,6 @@ nsITheme::Transparency nsNativeThemeCocoa::GetWidgetTransparency(nsIFrame* aFram
|
||||
}
|
||||
}
|
||||
|
||||
already_AddRefed<nsITheme> do_GetNativeThemeDoNotUseDirectly() {
|
||||
static nsCOMPtr<nsITheme> inst;
|
||||
|
||||
if (!inst) {
|
||||
inst = new nsNativeThemeCocoa(MakeUnique<ScrollbarDrawingCocoa>());
|
||||
ClearOnShutdown(&inst);
|
||||
}
|
||||
|
||||
return do_AddRef(inst);
|
||||
already_AddRefed<widget::Theme> do_CreateNativeThemeDoNotUseDirectly() {
|
||||
return do_AddRef(new nsNativeThemeCocoa(MakeUnique<ScrollbarDrawingCocoa>()));
|
||||
}
|
||||
|
@ -1668,17 +1668,9 @@ nsITheme::Transparency nsNativeThemeGTK::GetWidgetTransparency(
|
||||
}
|
||||
}
|
||||
|
||||
already_AddRefed<nsITheme> do_GetNativeThemeDoNotUseDirectly() {
|
||||
static nsCOMPtr<nsITheme> inst;
|
||||
|
||||
if (!inst) {
|
||||
if (gfxPlatform::IsHeadless()) {
|
||||
inst = new Theme(Theme::DefaultPlatformScrollbarStyle());
|
||||
} else {
|
||||
inst = new nsNativeThemeGTK();
|
||||
}
|
||||
ClearOnShutdown(&inst);
|
||||
already_AddRefed<Theme> do_CreateNativeThemeDoNotUseDirectly() {
|
||||
if (gfxPlatform::IsHeadless()) {
|
||||
return do_AddRef(new Theme(Theme::DefaultPlatformScrollbarStyle()));
|
||||
}
|
||||
|
||||
return do_AddRef(inst);
|
||||
return do_AddRef(new nsNativeThemeGTK());
|
||||
}
|
||||
|
@ -3662,13 +3662,6 @@ uint32_t nsNativeThemeWin::GetWidgetNativeDrawingFlags(
|
||||
// Creation Routine
|
||||
///////////////////////////////////////////
|
||||
|
||||
already_AddRefed<nsITheme> do_GetNativeThemeDoNotUseDirectly() {
|
||||
static nsCOMPtr<nsITheme> inst;
|
||||
|
||||
if (!inst) {
|
||||
inst = new nsNativeThemeWin();
|
||||
ClearOnShutdown(&inst);
|
||||
}
|
||||
|
||||
return do_AddRef(inst);
|
||||
already_AddRefed<Theme> do_CreateNativeThemeDoNotUseDirectly() {
|
||||
return do_AddRef(new nsNativeThemeWin());
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user