Skip to content

Commit

Permalink
Bug 1491594 - Remove the XPCOM registration for the native theme rend…
Browse files Browse the repository at this point in the history
…erer r=mstange

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

--HG--
extra : moz-landing-system : lando
  • Loading branch information
ehsan committed Sep 20, 2018
1 parent bb5a089 commit 8d7c299
Show file tree
Hide file tree
Showing 12 changed files with 76 additions and 93 deletions.
8 changes: 2 additions & 6 deletions gfx/src/nsITheme.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ class IpcResourceUpdateQueue;
#define NS_ITHEME_IID \
{ 0x7329f760, 0x08cb, 0x450f, \
{ 0x82, 0x25, 0xda, 0xe7, 0x29, 0x09, 0x6d, 0xec } }
// {0ae05515-cf7a-45a8-9e02-6556de7685b1}
#define NS_THEMERENDERER_CID \
{ 0x0ae05515, 0xcf7a, 0x45a8, \
{ 0x9e, 0x02, 0x65, 0x56, 0xde, 0x76, 0x85, 0xb1 } }

/**
* nsITheme is a service that provides platform-specific native
Expand Down Expand Up @@ -232,7 +228,7 @@ class nsITheme: public nsISupports {

NS_DEFINE_STATIC_IID_ACCESSOR(nsITheme, NS_ITHEME_IID)

// Creator function
extern nsresult NS_NewNativeTheme(nsISupports *aOuter, REFNSIID aIID, void **aResult);
// Singleton accessor function
extern already_AddRefed<nsITheme> do_GetNativeTheme();

#endif
2 changes: 1 addition & 1 deletion layout/base/nsPresContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1634,7 +1634,7 @@ nsITheme*
nsPresContext::GetTheme()
{
if (!sNoTheme && !mTheme) {
mTheme = do_GetService("@mozilla.org/chrome/chrome-native-theme;1");
mTheme = do_GetNativeTheme();
if (!mTheme)
sNoTheme = true;
}
Expand Down
10 changes: 6 additions & 4 deletions layout/xul/nsBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,17 @@ nsBox::EndXULLayout(nsBoxLayoutState& aState)
}

bool nsBox::gGotTheme = false;
nsITheme* nsBox::gTheme = nullptr;
StaticRefPtr<nsITheme> nsBox::gTheme;

nsBox::nsBox(ClassID aID)
: nsIFrame(aID)
{
MOZ_COUNT_CTOR(nsBox);
if (!gGotTheme) {
gGotTheme = true;
CallGetService("@mozilla.org/chrome/chrome-native-theme;1", &gTheme);
gTheme = do_GetNativeTheme();
if (gTheme) {
gGotTheme = true;
}
}
}

Expand All @@ -86,7 +88,7 @@ nsBox::~nsBox()
nsBox::Shutdown()
{
gGotTheme = false;
NS_IF_RELEASE(gTheme);
gTheme = nullptr;
}

nsresult
Expand Down
3 changes: 2 additions & 1 deletion layout/xul/nsBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#define nsBox_h___

#include "mozilla/Attributes.h"
#include "mozilla/StaticPtr.h"
#include "nsIFrame.h"

class nsITheme;
Expand Down Expand Up @@ -79,7 +80,7 @@ class nsBox : public nsIFrame {
nsresult EndXULLayout(nsBoxLayoutState& aState);

static bool gGotTheme;
static nsITheme* gTheme;
static mozilla::StaticRefPtr<nsITheme> gTheme;

enum eMouseThrough {
unset,
Expand Down
14 changes: 14 additions & 0 deletions widget/android/nsNativeThemeAndroid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "AndroidColors.h"
#include "nsCSSRendering.h"
#include "PathHelpers.h"
#include "mozilla/ClearOnShutdown.h"

NS_IMPL_ISUPPORTS_INHERITED(nsNativeThemeAndroid, nsNativeTheme, nsITheme)

Expand Down Expand Up @@ -313,3 +314,16 @@ nsNativeThemeAndroid::GetWidgetTransparency(nsIFrame* aFrame, WidgetType aWidget
{
return eUnknownTransparency;
}

already_AddRefed<nsITheme>
do_GetNativeTheme()
{
static nsCOMPtr<nsITheme> inst;

if (!inst) {
inst = new nsNativeThemeAndroid();
ClearOnShutdown(&inst);
}

return do_AddRef(inst);
}
24 changes: 0 additions & 24 deletions widget/android/nsWidgetFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

#include "nsToolkitCompsCID.h"
#include "AndroidAlerts.h"
#include "nsNativeThemeAndroid.h"

#include "mozilla/widget/ScreenManager.h"

Expand Down Expand Up @@ -56,29 +55,8 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(AndroidAlerts)
}
}

static nsresult
nsNativeThemeAndroidConstructor(nsISupports *aOuter, REFNSIID aIID,
void **aResult)
{
nsresult rv;

if (aOuter) {
rv = NS_ERROR_NO_AGGREGATION;
return rv;
}

*aResult = nullptr;
nsNativeThemeAndroid* inst = new nsNativeThemeAndroid();
NS_ADDREF(inst);
rv = inst->QueryInterface(aIID, aResult);
NS_RELEASE(inst);

return rv;
}

NS_DEFINE_NAMED_CID(NS_APPSHELL_CID);
NS_DEFINE_NAMED_CID(NS_SCREENMANAGER_CID);
NS_DEFINE_NAMED_CID(NS_THEMERENDERER_CID);
NS_DEFINE_NAMED_CID(NS_IDLE_SERVICE_CID);
NS_DEFINE_NAMED_CID(NS_TRANSFERABLE_CID);
NS_DEFINE_NAMED_CID(NS_CLIPBOARD_CID);
Expand All @@ -96,7 +74,6 @@ static const mozilla::Module::CIDEntry kWidgetCIDs[] = {
{ &kNS_APPSHELL_CID, false, nullptr, nsAppShellConstructor },
{ &kNS_SCREENMANAGER_CID, false, nullptr, ScreenManagerConstructor,
mozilla::Module::MAIN_PROCESS_ONLY },
{ &kNS_THEMERENDERER_CID, false, nullptr, nsNativeThemeAndroidConstructor },
{ &kNS_IDLE_SERVICE_CID, false, nullptr, nsIdleServiceAndroidConstructor },
{ &kNS_TRANSFERABLE_CID, false, nullptr, nsTransferableConstructor },
{ &kNS_CLIPBOARD_CID, false, nullptr, nsClipboardConstructor },
Expand All @@ -116,7 +93,6 @@ static const mozilla::Module::ContractIDEntry kWidgetContracts[] = {
{ "@mozilla.org/widget/appshell/android;1", &kNS_APPSHELL_CID },
{ "@mozilla.org/gfx/screenmanager;1", &kNS_SCREENMANAGER_CID,
mozilla::Module::MAIN_PROCESS_ONLY },
{ "@mozilla.org/chrome/chrome-native-theme;1", &kNS_THEMERENDERER_CID },
{ "@mozilla.org/widget/idleservice;1", &kNS_IDLE_SERVICE_CID },
{ "@mozilla.org/widget/transferable;1", &kNS_TRANSFERABLE_CID },
{ "@mozilla.org/widget/clipboard;1", &kNS_CLIPBOARD_CID },
Expand Down
14 changes: 14 additions & 0 deletions widget/cocoa/nsNativeThemeCocoa.mm
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "nsCocoaWindow.h"
#include "nsNativeThemeColors.h"
#include "nsIScrollableFrame.h"
#include "mozilla/ClearOnShutdown.h"
#include "mozilla/EventStates.h"
#include "mozilla/Range.h"
#include "mozilla/RelativeLuminanceUtils.h"
Expand Down Expand Up @@ -4971,3 +4972,16 @@ static float VerticalAlignFactor(nsIFrame *aFrame)
return eUnknownTransparency;
}
}

already_AddRefed<nsITheme>
do_GetNativeTheme()
{
static nsCOMPtr<nsITheme> inst;

if (!inst) {
inst = new nsNativeThemeCocoa();
ClearOnShutdown(&inst);
}

return do_AddRef(inst);
}
6 changes: 0 additions & 6 deletions widget/cocoa/nsWidgetFactory.mm
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,6 @@
#include "nsMenuBarX.h"
NS_GENERIC_FACTORY_CONSTRUCTOR(nsNativeMenuServiceX)

#include "nsNativeThemeCocoa.h"
NS_GENERIC_FACTORY_CONSTRUCTOR(nsNativeThemeCocoa)

#include "nsMacDockSupport.h"
NS_GENERIC_FACTORY_CONSTRUCTOR(nsMacDockSupport)

Expand Down Expand Up @@ -117,7 +114,6 @@
NS_DEFINE_NAMED_CID(NS_CLIPBOARD_CID);
NS_DEFINE_NAMED_CID(NS_CLIPBOARDHELPER_CID);
NS_DEFINE_NAMED_CID(NS_DRAGSERVICE_CID);
NS_DEFINE_NAMED_CID(NS_THEMERENDERER_CID);
NS_DEFINE_NAMED_CID(NS_SCREENMANAGER_CID);
NS_DEFINE_NAMED_CID(NS_DEVICE_CONTEXT_SPEC_CID);
NS_DEFINE_NAMED_CID(NS_PRINTSESSION_CID);
Expand Down Expand Up @@ -148,7 +144,6 @@
{ &kNS_CLIPBOARDHELPER_CID, false, NULL, nsClipboardHelperConstructor },
{ &kNS_DRAGSERVICE_CID, false, NULL, nsDragServiceConstructor,
mozilla::Module::MAIN_PROCESS_ONLY },
{ &kNS_THEMERENDERER_CID, false, NULL, nsNativeThemeCocoaConstructor },
{ &kNS_SCREENMANAGER_CID, false, NULL, ScreenManagerConstructor,
mozilla::Module::MAIN_PROCESS_ONLY },
{ &kNS_DEVICE_CONTEXT_SPEC_CID, false, NULL, nsDeviceContextSpecXConstructor },
Expand Down Expand Up @@ -182,7 +177,6 @@
{ "@mozilla.org/widget/clipboardhelper;1", &kNS_CLIPBOARDHELPER_CID },
{ "@mozilla.org/widget/dragservice;1", &kNS_DRAGSERVICE_CID,
mozilla::Module::MAIN_PROCESS_ONLY },
{ "@mozilla.org/chrome/chrome-native-theme;1", &kNS_THEMERENDERER_CID },
{ "@mozilla.org/gfx/screenmanager;1", &kNS_SCREENMANAGER_CID,
mozilla::Module::MAIN_PROCESS_ONLY },
{ "@mozilla.org/gfx/devicecontextspec;1", &kNS_DEVICE_CONTEXT_SPEC_CID },
Expand Down
26 changes: 26 additions & 0 deletions widget/gtk/nsNativeThemeGTK.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "nsNativeThemeGTK.h"
#include "HeadlessThemeGTK.h"
#include "nsStyleConsts.h"
#include "gtkdrawing.h"
#include "ScreenHelperGTK.h"
Expand All @@ -25,6 +26,7 @@
#include "nsAttrValueInlines.h"

#include "mozilla/dom/HTMLInputElement.h"
#include "mozilla/ClearOnShutdown.h"
#include "mozilla/EventStates.h"
#include "mozilla/Services.h"

Expand Down Expand Up @@ -65,6 +67,9 @@ NS_IMPL_ISUPPORTS_INHERITED(nsNativeThemeGTK, nsNativeTheme, nsITheme,

static int gLastGdkError;

// from nsWindow.cpp
extern bool gDisableNativeTheme;

// Return scale factor of the monitor where the window is located
// by the most part or layout.css.devPixelsPerPx pref if set to > 0.
static inline gint
Expand Down Expand Up @@ -2143,3 +2148,24 @@ nsNativeThemeGTK::WidgetAppearanceDependsOnWindowFocus(StyleAppearance aWidgetTy
return false;
}
}

already_AddRefed<nsITheme>
do_GetNativeTheme()
{
if (gDisableNativeTheme) {
return nullptr;
}

static nsCOMPtr<nsITheme> inst;

if (!inst) {
if (gfxPlatform::IsHeadless()) {
inst = new HeadlessThemeGTK();
} else {
inst = new nsNativeThemeGTK();
}
ClearOnShutdown(&inst);
}

return do_AddRef(inst);
}
39 changes: 0 additions & 39 deletions widget/gtk/nsWidgetFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@
#include "GfxInfoX11.h"
#endif

#include "nsNativeThemeGTK.h"
#include "HeadlessThemeGTK.h"

#include "nsIComponentRegistrar.h"
#include "nsComponentManagerUtils.h"
#include "mozilla/gfx/2D.h"
Expand All @@ -72,39 +69,6 @@ NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(ScreenManager, ScreenManager::GetAddRef
NS_GENERIC_FACTORY_CONSTRUCTOR(nsImageToPixbuf)
NS_GENERIC_FACTORY_CONSTRUCTOR(TaskbarProgress)


// from nsWindow.cpp
extern bool gDisableNativeTheme;

static nsresult
nsNativeThemeGTKConstructor(nsISupports *aOuter, REFNSIID aIID,
void **aResult)
{
nsresult rv;
nsCOMPtr<nsITheme> inst;

if (gDisableNativeTheme)
return NS_ERROR_NO_INTERFACE;

*aResult = nullptr;
if (nullptr != aOuter) {
rv = NS_ERROR_NO_AGGREGATION;
return rv;
}
if (gfxPlatform::IsHeadless()) {
inst = new HeadlessThemeGTK();
} else {
inst = new nsNativeThemeGTK();
}
if (nullptr == inst) {
rv = NS_ERROR_OUT_OF_MEMORY;
return rv;
}
rv = inst->QueryInterface(aIID, aResult);

return rv;
}

#if defined(MOZ_X11)
namespace mozilla {
namespace widget {
Expand Down Expand Up @@ -211,7 +175,6 @@ NS_DEFINE_NAMED_CID(NS_DRAGSERVICE_CID);
#endif
NS_DEFINE_NAMED_CID(NS_HTMLFORMATCONVERTER_CID);
NS_DEFINE_NAMED_CID(NS_SCREENMANAGER_CID);
NS_DEFINE_NAMED_CID(NS_THEMERENDERER_CID);
#ifdef NS_PRINTING
NS_DEFINE_NAMED_CID(NS_PRINTSETTINGSSERVICE_CID);
NS_DEFINE_NAMED_CID(NS_PRINTER_ENUMERATOR_CID);
Expand Down Expand Up @@ -244,7 +207,6 @@ static const mozilla::Module::CIDEntry kWidgetCIDs[] = {
{ &kNS_HTMLFORMATCONVERTER_CID, false, nullptr, nsHTMLFormatConverterConstructor },
{ &kNS_SCREENMANAGER_CID, false, nullptr, ScreenManagerConstructor,
Module::MAIN_PROCESS_ONLY },
{ &kNS_THEMERENDERER_CID, false, nullptr, nsNativeThemeGTKConstructor },
#ifdef NS_PRINTING
{ &kNS_PRINTSETTINGSSERVICE_CID, false, nullptr, nsPrintSettingsServiceGTKConstructor },
{ &kNS_PRINTER_ENUMERATOR_CID, false, nullptr, nsPrinterEnumeratorGTKConstructor },
Expand Down Expand Up @@ -278,7 +240,6 @@ static const mozilla::Module::ContractIDEntry kWidgetContracts[] = {
{ "@mozilla.org/widget/htmlformatconverter;1", &kNS_HTMLFORMATCONVERTER_CID },
{ "@mozilla.org/gfx/screenmanager;1", &kNS_SCREENMANAGER_CID,
Module::MAIN_PROCESS_ONLY },
{ "@mozilla.org/chrome/chrome-native-theme;1", &kNS_THEMERENDERER_CID },
#ifdef NS_PRINTING
{ "@mozilla.org/gfx/printsettings-service;1", &kNS_PRINTSETTINGSSERVICE_CID },
{ "@mozilla.org/gfx/printerenumerator;1", &kNS_PRINTER_ENUMERATOR_CID },
Expand Down
19 changes: 11 additions & 8 deletions widget/windows/nsNativeThemeWin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "nsNativeThemeWin.h"

#include "mozilla/ClearOnShutdown.h"
#include "mozilla/EventStates.h"
#include "mozilla/Logging.h"
#include "mozilla/RelativeLuminanceUtils.h"
Expand Down Expand Up @@ -4446,16 +4447,18 @@ nsNativeThemeWin::DrawCustomScrollbarPart(gfxContext* aContext,
// from nsWindow.cpp
extern bool gDisableNativeTheme;

nsresult NS_NewNativeTheme(nsISupports *aOuter, REFNSIID aIID, void **aResult)
already_AddRefed<nsITheme>
do_GetNativeTheme()
{
if (gDisableNativeTheme)
return NS_ERROR_NO_INTERFACE;
return nullptr;

if (aOuter)
return NS_ERROR_NO_AGGREGATION;
static nsCOMPtr<nsITheme> inst;

nsNativeThemeWin* theme = new nsNativeThemeWin();
if (!theme)
return NS_ERROR_OUT_OF_MEMORY;
return theme->QueryInterface(aIID, aResult);
if (!inst) {
inst = new nsNativeThemeWin();
ClearOnShutdown(&inst);
}

return do_AddRef(inst);
}
Loading

0 comments on commit 8d7c299

Please sign in to comment.