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/D5961
  • Loading branch information
ehsan committed Sep 16, 2018
1 parent bfef218 commit 7c90f6f
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 93 deletions.
6 changes: 1 addition & 5 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 @@ -233,6 +229,6 @@ 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);
extern already_AddRefed<nsITheme> NS_NewNativeTheme();

#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 = NS_NewNativeTheme();
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 = NS_NewNativeTheme();
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
6 changes: 6 additions & 0 deletions widget/android/nsNativeThemeAndroid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,3 +313,9 @@ nsNativeThemeAndroid::GetWidgetTransparency(nsIFrame* aFrame, WidgetType aWidget
{
return eUnknownTransparency;
}

already_AddRefed<nsITheme>
NS_NewNativeTheme()
{
return do_AddRef(new nsNativeThemeAndroid());
}
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
6 changes: 6 additions & 0 deletions widget/cocoa/nsNativeThemeCocoa.mm
Original file line number Diff line number Diff line change
Expand Up @@ -4971,3 +4971,9 @@ static float VerticalAlignFactor(nsIFrame *aFrame)
return eUnknownTransparency;
}
}

already_AddRefed<nsITheme>
NS_NewNativeTheme()
{
return do_AddRef(new nsNativeThemeCocoa());
}
6 changes: 0 additions & 6 deletions widget/cocoa/nsWidgetFactory.mm
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,6 @@
#include "nsBidiKeyboard.h"
NS_GENERIC_FACTORY_CONSTRUCTOR(nsBidiKeyboard)

#include "nsNativeThemeCocoa.h"
NS_GENERIC_FACTORY_CONSTRUCTOR(nsNativeThemeCocoa)

#include "nsMacDockSupport.h"
NS_GENERIC_FACTORY_CONSTRUCTOR(nsMacDockSupport)

Expand Down Expand Up @@ -121,7 +118,6 @@
NS_DEFINE_NAMED_CID(NS_CLIPBOARDHELPER_CID);
NS_DEFINE_NAMED_CID(NS_DRAGSERVICE_CID);
NS_DEFINE_NAMED_CID(NS_BIDIKEYBOARD_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 @@ -154,7 +150,6 @@
mozilla::Module::MAIN_PROCESS_ONLY },
{ &kNS_BIDIKEYBOARD_CID, false, NULL, nsBidiKeyboardConstructor,
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 @@ -190,7 +185,6 @@
mozilla::Module::MAIN_PROCESS_ONLY },
{ "@mozilla.org/widget/bidikeyboard;1", &kNS_BIDIKEYBOARD_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
21 changes: 21 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 Down Expand Up @@ -65,6 +66,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 +2147,20 @@ nsNativeThemeGTK::WidgetAppearanceDependsOnWindowFocus(StyleAppearance aWidgetTy
return false;
}
}

already_AddRefed<nsITheme>
NS_NewNativeTheme()
{
nsCOMPtr<nsITheme> inst;

if (gDisableNativeTheme) {
return nullptr;
}

if (gfxPlatform::IsHeadless()) {
inst = new HeadlessThemeGTK();
} else {
inst = new nsNativeThemeGTK();
}
return inst.forget();
}
39 changes: 0 additions & 39 deletions widget/gtk/nsWidgetFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@
#include "GfxInfoX11.h"
#endif

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

#include "nsIComponentRegistrar.h"
#include "nsComponentManagerUtils.h"
#include "mozilla/gfx/2D.h"
Expand All @@ -74,39 +71,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 @@ -214,7 +178,6 @@ NS_DEFINE_NAMED_CID(NS_DRAGSERVICE_CID);
NS_DEFINE_NAMED_CID(NS_HTMLFORMATCONVERTER_CID);
NS_DEFINE_NAMED_CID(NS_BIDIKEYBOARD_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 @@ -248,7 +211,6 @@ static const mozilla::Module::CIDEntry kWidgetCIDs[] = {
{ &kNS_BIDIKEYBOARD_CID, false, nullptr, nsBidiKeyboardConstructor },
{ &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 @@ -284,7 +246,6 @@ static const mozilla::Module::ContractIDEntry kWidgetContracts[] = {
Module::MAIN_PROCESS_ONLY },
{ "@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
14 changes: 5 additions & 9 deletions widget/windows/nsNativeThemeWin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4446,16 +4446,12 @@ nsNativeThemeWin::DrawCustomScrollbarPart(gfxContext* aContext,
// from nsWindow.cpp
extern bool gDisableNativeTheme;

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

if (aOuter)
return NS_ERROR_NO_AGGREGATION;
return nullptr;

nsNativeThemeWin* theme = new nsNativeThemeWin();
if (!theme)
return NS_ERROR_OUT_OF_MEMORY;
return theme->QueryInterface(aIID, aResult);
nsCOMPtr<nsITheme> theme = new nsNativeThemeWin();
return theme.forget();
}
4 changes: 0 additions & 4 deletions widget/windows/nsWidgetFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
// Desktop
#include "nsFilePicker.h" // needs to be included before other shobjidl.h includes
#include "nsColorPicker.h"
#include "nsNativeThemeWin.h"
// Content processes
#include "nsFilePickerProxy.h"

Expand Down Expand Up @@ -134,7 +133,6 @@ NS_DEFINE_NAMED_CID(NS_COLORPICKER_CID);
NS_DEFINE_NAMED_CID(NS_APPSHELL_CID);
NS_DEFINE_NAMED_CID(NS_SCREENMANAGER_CID);
NS_DEFINE_NAMED_CID(NS_GFXINFO_CID);
NS_DEFINE_NAMED_CID(NS_THEMERENDERER_CID);
NS_DEFINE_NAMED_CID(NS_IDLE_SERVICE_CID);
NS_DEFINE_NAMED_CID(NS_CLIPBOARD_CID);
NS_DEFINE_NAMED_CID(NS_CLIPBOARDHELPER_CID);
Expand Down Expand Up @@ -167,7 +165,6 @@ static const mozilla::Module::CIDEntry kWidgetCIDs[] = {
{ &kNS_SCREENMANAGER_CID, false, nullptr, ScreenManagerConstructor,
Module::MAIN_PROCESS_ONLY },
{ &kNS_GFXINFO_CID, false, nullptr, GfxInfoConstructor, Module::ALLOW_IN_GPU_PROCESS },
{ &kNS_THEMERENDERER_CID, false, nullptr, NS_NewNativeTheme },
{ &kNS_IDLE_SERVICE_CID, false, nullptr, nsIdleServiceWinConstructor },
{ &kNS_CLIPBOARD_CID, false, nullptr, nsClipboardConstructor, Module::MAIN_PROCESS_ONLY },
{ &kNS_CLIPBOARDHELPER_CID, false, nullptr, nsClipboardHelperConstructor },
Expand Down Expand Up @@ -200,7 +197,6 @@ static const mozilla::Module::ContractIDEntry kWidgetContracts[] = {
{ "@mozilla.org/widget/appshell/win;1", &kNS_APPSHELL_CID, Module::ALLOW_IN_GPU_PROCESS },
{ "@mozilla.org/gfx/screenmanager;1", &kNS_SCREENMANAGER_CID, Module::MAIN_PROCESS_ONLY },
{ "@mozilla.org/gfx/info;1", &kNS_GFXINFO_CID, Module::ALLOW_IN_GPU_PROCESS },
{ "@mozilla.org/chrome/chrome-native-theme;1", &kNS_THEMERENDERER_CID },
{ "@mozilla.org/widget/idleservice;1", &kNS_IDLE_SERVICE_CID },
{ "@mozilla.org/widget/clipboard;1", &kNS_CLIPBOARD_CID, Module::MAIN_PROCESS_ONLY },
{ "@mozilla.org/widget/clipboardhelper;1", &kNS_CLIPBOARDHELPER_CID },
Expand Down

0 comments on commit 7c90f6f

Please sign in to comment.