Bug 669028 part.2 Make nsLookAndFeel singleton r=roc

This commit is contained in:
Masayuki Nakano 2011-09-09 11:27:11 +09:00
parent 60fca38ebd
commit 63c956c546
8 changed files with 84 additions and 10 deletions

View File

@ -63,7 +63,8 @@
NS_GENERIC_FACTORY_CONSTRUCTOR(nsToolkit)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsWindow)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsLookAndFeel)
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsLookAndFeel,
nsLookAndFeel::GetAddRefedInstance)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsScreenManagerAndroid)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsIdleServiceAndroid)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsTransferable)
@ -164,6 +165,7 @@ static const mozilla::Module::ContractIDEntry kWidgetContracts[] = {
static void
nsWidgetAndroidModuleDtor()
{
nsLookAndFeel::Shutdown();
nsAppShellShutdown();
}

View File

@ -80,7 +80,8 @@ using namespace mozilla::widget;
NS_GENERIC_FACTORY_CONSTRUCTOR(nsWindow)
NS_GENERIC_FACTORY_CONSTRUCTOR(ChildWindow)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsFilePicker)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsLookAndFeel)
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsLookAndFeel,
nsLookAndFeel::GetAddRefedInstance)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsToolkit)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsScreenManagerWin)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsIdleServiceWin)
@ -222,6 +223,13 @@ static const mozilla::Module::ContractIDEntry kWidgetContracts[] = {
{ NULL }
};
static void
nsWidgetWindowsModuleDtor()
{
nsLookAndFeel::Shutdown();
nsAppShellShutdown();
}
static const mozilla::Module kWidgetModule = {
mozilla::Module::kVersion,
kWidgetCIDs,
@ -229,7 +237,7 @@ static const mozilla::Module kWidgetModule = {
NULL,
NULL,
nsAppShellInit,
nsAppShellShutdown
nsWidgetWindowsModuleDtor
};
NSMODULE_DEFN(nsWidgetModule) = &kWidgetModule;

View File

@ -70,7 +70,8 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsCocoaWindow)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsChildView)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsFilePicker)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsToolkit)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsLookAndFeel)
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsLookAndFeel,
nsLookAndFeel::GetAddRefedInstance)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSound)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsTransferable)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsHTMLFormatConverter)
@ -193,6 +194,13 @@ static const mozilla::Module::ContractIDEntry kWidgetContracts[] = {
{ NULL }
};
static void
nsWidgetCocoaModuleDtor()
{
nsLookAndFeel::Shutdown();
nsAppShellShutdown();
}
static const mozilla::Module kWidgetModule = {
mozilla::Module::kVersion,
kWidgetCIDs,
@ -200,7 +208,7 @@ static const mozilla::Module kWidgetModule = {
NULL,
NULL,
nsAppShellInit,
nsAppShellShutdown
nsWidgetCocoaModuleDtor
};
NSMODULE_DEFN(nsWidgetMacModule) = &kWidgetModule;

View File

@ -92,7 +92,8 @@ static NS_DEFINE_CID(kNativeFilePickerCID, NS_FILEPICKER_CID);
NS_GENERIC_FACTORY_CONSTRUCTOR(nsWindow)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsChildWindow)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsLookAndFeel)
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsLookAndFeel,
nsLookAndFeel::GetAddRefedInstance)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsTransferable)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsBidiKeyboard)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsHTMLFormatConverter)
@ -339,6 +340,7 @@ static const mozilla::Module::ContractIDEntry kWidgetContracts[] = {
static void
nsWidgetGtk2ModuleDtor()
{
nsLookAndFeel::Shutdown();
nsFilePicker::Shutdown();
nsSound::Shutdown();
nsWindow::ReleaseGlobals();

View File

@ -93,7 +93,8 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsClipboard)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsClipboardHelper)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsFilePicker)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsChildWindow)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsLookAndFeel)
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsLookAndFeel,
nsLookAndFeel::GetAddRefedInstance)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSound)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsToolkit)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsTransferable)
@ -181,6 +182,7 @@ static const mozilla::Module::ContractIDEntry kWidgetContracts[] = {
static void
nsWidgetOS2ModuleDtor()
{
nsLookAndFeel::Shutdown();
nsWindow::ReleaseGlobals();
nsFilePicker::ReleaseGlobals();
nsAppShellShutdown();

View File

@ -83,7 +83,8 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsPopupWindow)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsToolkit)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsHTMLFormatConverter)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsTransferable)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsLookAndFeel)
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsLookAndFeel,
nsLookAndFeel::GetAddRefedInstance)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsScreenManagerQt)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsClipboard)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsClipboardHelper)
@ -248,6 +249,7 @@ static const mozilla::Module::ContractIDEntry kWidgetContracts[] = {
static void
nsWidgetQtModuleDtor()
{
nsLookAndFeel::Shutdown();
nsSound::Shutdown();
nsWindow::ReleaseGlobals();
nsAppShellShutdown();

View File

@ -38,6 +38,7 @@
#include "nscore.h"
#include "nsXPLookAndFeel.h"
#include "nsLookAndFeel.h"
#include "nsCRT.h"
#include "nsFont.h"
#include "mozilla/Preferences.h"
@ -213,6 +214,45 @@ PRInt32 nsXPLookAndFeel::sCachedColorBits[COLOR_CACHE_SIZE] = {0};
PRBool nsXPLookAndFeel::sInitialized = PR_FALSE;
PRBool nsXPLookAndFeel::sUseNativeColors = PR_TRUE;
nsXPLookAndFeel* nsXPLookAndFeel::sInstance = nsnull;
PRBool nsXPLookAndFeel::sShutdown = PR_FALSE;
// static
nsLookAndFeel*
nsXPLookAndFeel::GetAddRefedInstance()
{
nsLookAndFeel* lookAndFeel = GetInstance();
NS_IF_ADDREF(lookAndFeel);
return lookAndFeel;
}
// static
nsLookAndFeel*
nsXPLookAndFeel::GetInstance()
{
if (sInstance) {
return static_cast<nsLookAndFeel*>(sInstance);
}
NS_ENSURE_TRUE(!sShutdown, nsnull);
NS_ADDREF(sInstance = new nsLookAndFeel());
return static_cast<nsLookAndFeel*>(sInstance);
}
// static
void
nsXPLookAndFeel::Shutdown()
{
if (sShutdown) {
return;
}
sShutdown = PR_TRUE;
if (sInstance) {
sInstance->Release();
}
}
nsXPLookAndFeel::nsXPLookAndFeel() : nsILookAndFeel()
{
}
@ -406,6 +446,9 @@ nsXPLookAndFeel::Init()
nsXPLookAndFeel::~nsXPLookAndFeel()
{
NS_ASSERTION(sInstance == this,
"This destroying instance isn't the singleton instance");
sInstance = nsnull;
}
PRBool

View File

@ -45,6 +45,8 @@
struct nsSize;
#endif
class nsLookAndFeel;
typedef enum {
nsLookAndFeelTypeInt,
nsLookAndFeelTypeFloat,
@ -87,6 +89,10 @@ public:
NS_DECL_ISUPPORTS
static nsLookAndFeel* GetAddRefedInstance();
static nsLookAndFeel* GetInstance();
static void Shutdown();
void Init();
//
@ -130,8 +136,9 @@ protected:
static PRInt32 sCachedColors[nsILookAndFeel::eColor_LAST_COLOR];
static PRInt32 sCachedColorBits[COLOR_CACHE_SIZE];
static PRBool sUseNativeColors;
static nsXPLookAndFeel* sInstance;
static PRBool sShutdown;
};
extern nsresult NS_NewXPLookAndFeel(nsILookAndFeel**);
#endif