Bug 1619664 - Decide which theme to use per document, not per-process. r=mstange,spohl

This allows testing much more easily.

There are some edge cases with native theme changes and such (ThemeChanged and
co assume there's only one theme per process). But I don't think they matter
much for our use cases.

Differential Revision: https://phabricator.services.mozilla.com/D65162

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Emilio Cobos Álvarez 2020-03-03 19:46:41 +00:00
parent 4f5e083311
commit 741c54ae79
7 changed files with 27 additions and 20 deletions

View File

@ -222,6 +222,9 @@ class nsITheme : public nsISupports {
NS_DEFINE_STATIC_IID_ACCESSOR(nsITheme, NS_ITHEME_IID)
// Singleton accessor function
extern already_AddRefed<nsITheme> do_GetNativeTheme();
//
// Do not use directly, use nsPresContext::GetTheme instead.
extern already_AddRefed<nsITheme> do_GetNativeThemeDoNotUseDirectly();
extern already_AddRefed<nsITheme> do_GetBasicNativeThemeDoNotUseDirectly();
#endif

View File

@ -82,6 +82,7 @@
#include "mozilla/GlobalStyleSheetCache.h"
#include "mozilla/ServoBindings.h"
#include "mozilla/StaticPrefs_layout.h"
#include "mozilla/StaticPrefs_widget.h"
#include "mozilla/StaticPrefs_zoom.h"
#include "mozilla/StyleSheet.h"
#include "mozilla/StyleSheetInlines.h"
@ -1275,7 +1276,12 @@ void nsPresContext::RecordInteractionTime(InteractionType aType,
nsITheme* nsPresContext::GetTheme() {
if (!sNoTheme && !mTheme) {
mTheme = do_GetNativeTheme();
if (StaticPrefs::widget_disable_native_theme_for_content() &&
(!IsChrome() || XRE_IsContentProcess())) {
mTheme = do_GetBasicNativeThemeDoNotUseDirectly();
} else {
mTheme = do_GetNativeThemeDoNotUseDirectly();
}
if (!mTheme) sNoTheme = true;
}

View File

@ -294,7 +294,7 @@ nsITheme::Transparency nsNativeThemeAndroid::GetWidgetTransparency(
return eUnknownTransparency;
}
already_AddRefed<nsITheme> do_GetNativeTheme() {
already_AddRefed<nsITheme> do_GetNativeThemeDoNotUseDirectly() {
static nsCOMPtr<nsITheme> inst;
if (!inst) {

View File

@ -4370,15 +4370,11 @@ nsITheme::Transparency nsNativeThemeCocoa::GetWidgetTransparency(nsIFrame* aFram
}
}
already_AddRefed<nsITheme> do_GetNativeTheme() {
already_AddRefed<nsITheme> do_GetNativeThemeDoNotUseDirectly() {
static nsCOMPtr<nsITheme> inst;
if (!inst) {
if (XRE_IsContentProcess() && StaticPrefs::widget_disable_native_theme_for_content()) {
inst = new nsNativeBasicTheme();
} else {
inst = new nsNativeThemeCocoa();
}
inst = new nsNativeThemeCocoa();
ClearOnShutdown(&inst);
}

View File

@ -2009,15 +2009,12 @@ bool nsNativeThemeGTK::WidgetAppearanceDependsOnWindowFocus(
}
}
already_AddRefed<nsITheme> do_GetNativeTheme() {
already_AddRefed<nsITheme> do_GetNativeThemeDoNotUseDirectly() {
static nsCOMPtr<nsITheme> inst;
if (!inst) {
if (gfxPlatform::IsHeadless()) {
inst = new HeadlessThemeGTK();
} else if (XRE_IsContentProcess() &&
StaticPrefs::widget_disable_native_theme_for_content()) {
inst = new nsNativeBasicTheme();
} else {
inst = new nsNativeThemeGTK();
}

View File

@ -6,6 +6,7 @@
#include "nsNativeBasicTheme.h"
#include "mozilla/StaticPrefs_layout.h"
#include "mozilla/ClearOnShutdown.h"
#include "nsComboboxControlFrame.h"
#include "nsCSSRendering.h"
#include "nsDateTimeControlFrame.h"
@ -889,3 +890,12 @@ bool nsNativeBasicTheme::ThemeDrawsFocusForWidget(StyleAppearance aAppearance) {
}
bool nsNativeBasicTheme::ThemeNeedsComboboxDropmarker() { return true; }
already_AddRefed<nsITheme> do_GetBasicNativeThemeDoNotUseDirectly() {
static StaticRefPtr<nsITheme> gInstance;
if (MOZ_UNLIKELY(!gInstance)) {
gInstance = new nsNativeBasicTheme();
ClearOnShutdown(&gInstance);
}
return do_AddRef(gInstance);
}

View File

@ -4255,16 +4255,11 @@ bool nsNativeThemeWin::MayDrawCustomScrollbarPart(gfxContext* aContext,
// Creation Routine
///////////////////////////////////////////
already_AddRefed<nsITheme> do_GetNativeTheme() {
already_AddRefed<nsITheme> do_GetNativeThemeDoNotUseDirectly() {
static nsCOMPtr<nsITheme> inst;
if (!inst) {
if (XRE_IsContentProcess() &&
StaticPrefs::widget_disable_native_theme_for_content()) {
inst = new nsNativeBasicTheme();
} else {
inst = new nsNativeThemeWin();
}
inst = new nsNativeThemeWin();
ClearOnShutdown(&inst);
}