mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-16 22:04:36 +00:00
bug 281298 replace nsIPref with nsIPrefService/nsIPrefBranch in widget
patch by Vidar Braut Haarr <vhaarr+bmo@gmail.com> r=bryner sr=bz
This commit is contained in:
parent
ece8911f9d
commit
9a9d28f4a0
@ -44,7 +44,8 @@
|
||||
#include "nsIPlatformCharset.h"
|
||||
#include "nsICharsetConverterManager.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIPref.h"
|
||||
#include "nsIPrefBranch.h"
|
||||
#include "nsIPrefService.h"
|
||||
#include <X11/Xatom.h>
|
||||
#include "nsCRT.h"
|
||||
|
||||
@ -53,7 +54,6 @@
|
||||
static NS_DEFINE_CID(kCharsetConverterManagerCID, NS_ICHARSETCONVERTERMANAGER_CID);
|
||||
|
||||
#ifdef USE_XIM
|
||||
static NS_DEFINE_CID(kPrefServiceCID, NS_PREF_CID);
|
||||
|
||||
nsIMEStatus *nsIMEGtkIC::gStatus = 0;
|
||||
nsWindow *nsIMEGtkIC::gGlobalFocusWindow = 0;
|
||||
@ -1221,11 +1221,11 @@ nsIMEGtkIC::GetInputStyle() {
|
||||
return ret_style;
|
||||
#endif
|
||||
|
||||
nsCOMPtr<nsIPref> prefs(do_GetService(kPrefServiceCID, &rv));
|
||||
nsCOMPtr<nsIPrefBranch> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv));
|
||||
if (NS_SUCCEEDED(rv) && (prefs)) {
|
||||
char *input_style;
|
||||
rv = prefs->CopyCharPref(PREF_XIM_INPUTSTYLE, &input_style);
|
||||
if (NS_SUCCEEDED(rv) && input_style[0]) {
|
||||
nsXPIDLCString input_style;
|
||||
rv = prefs->GetCharPref(PREF_XIM_INPUTSTYLE, getter_Copies(input_style));
|
||||
if (NS_SUCCEEDED(rv) && !input_style.IsEmpty()) {
|
||||
if (!nsCRT::strcmp(input_style, VAL_INPUTSTYLE_ONTHESPOT)) {
|
||||
preferred_preedit_style = (GdkIMStyle) GDK_IM_PREEDIT_CALLBACKS;
|
||||
preferred_status_style = (GdkIMStyle) GDK_IM_STATUS_CALLBACKS;
|
||||
@ -1239,13 +1239,12 @@ nsIMEGtkIC::GetInputStyle() {
|
||||
preferred_preedit_style = (GdkIMStyle) GDK_IM_PREEDIT_NONE;
|
||||
preferred_status_style = (GdkIMStyle) GDK_IM_STATUS_NONE;
|
||||
}
|
||||
nsCRT::free(input_style);
|
||||
}
|
||||
/* if PREF_XIM_PREEDIT and PREF_XIM_STATUS are defined, use
|
||||
those values */
|
||||
char *preeditstyle_type;
|
||||
rv = prefs->CopyCharPref(PREF_XIM_PREEDIT, &preeditstyle_type);
|
||||
if (NS_SUCCEEDED(rv) && preeditstyle_type[0]) {
|
||||
nsXPIDLCString preeditstyle_type;
|
||||
rv = prefs->GetCharPref(PREF_XIM_PREEDIT, getter_Copies(preeditstyle_type));
|
||||
if (NS_SUCCEEDED(rv) && !preeditstyle_type.IsEmpty()) {
|
||||
if (!nsCRT::strcmp(preeditstyle_type, VAL_PREEDIT_CALLBACKS)) {
|
||||
ivalue = GDK_IM_PREEDIT_CALLBACKS;
|
||||
} else if (!nsCRT::strcmp(preeditstyle_type, VAL_PREEDIT_POSITION)) {
|
||||
@ -1260,11 +1259,10 @@ nsIMEGtkIC::GetInputStyle() {
|
||||
if (ivalue) {
|
||||
preferred_preedit_style = (GdkIMStyle) ivalue;
|
||||
}
|
||||
nsCRT::free(preeditstyle_type);
|
||||
}
|
||||
char *statusstyle_type;
|
||||
rv = prefs->CopyCharPref(PREF_XIM_STATUS, &statusstyle_type);
|
||||
if (NS_SUCCEEDED(rv) && statusstyle_type[0]) {
|
||||
nsXPIDLCString statusstyle_type;
|
||||
rv = prefs->GetCharPref(PREF_XIM_STATUS, getter_Copies(statusstyle_type));
|
||||
if (NS_SUCCEEDED(rv) && !statusstyle_type.IsEmpty()) {
|
||||
if (!nsCRT::strcmp(statusstyle_type, VAL_STATUS_CALLBACKS)) {
|
||||
ivalue = GDK_IM_STATUS_CALLBACKS;
|
||||
} else if (!nsCRT::strcmp(statusstyle_type, VAL_STATUS_NOTHING)) {
|
||||
@ -1277,7 +1275,6 @@ nsIMEGtkIC::GetInputStyle() {
|
||||
if (ivalue) {
|
||||
preferred_status_style = (GdkIMStyle) ivalue;
|
||||
}
|
||||
nsCRT::free(statusstyle_type);
|
||||
}
|
||||
}
|
||||
style = gdk_im_decide_style((GdkIMStyle)(preferred_preedit_style | preferred_status_style));
|
||||
|
@ -66,7 +66,8 @@
|
||||
#include "nsClipboard.h"
|
||||
#include "nsIRollupListener.h"
|
||||
|
||||
#include "nsIPref.h"
|
||||
#include "nsIPrefService.h"
|
||||
#include "nsIPrefBranch.h"
|
||||
|
||||
#include "nsICharsetConverterManager.h"
|
||||
#include "nsIPlatformCharset.h"
|
||||
@ -305,8 +306,7 @@ nsWindow::nsWindow()
|
||||
if (!gGlobalsInitialized) {
|
||||
gGlobalsInitialized = PR_TRUE;
|
||||
|
||||
// check to see if we should set our raise pref
|
||||
nsCOMPtr<nsIPref> prefs = do_GetService(NS_PREF_CONTRACTID);
|
||||
nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
|
||||
if (prefs) {
|
||||
PRBool val = PR_TRUE;
|
||||
nsresult rv;
|
||||
|
@ -57,7 +57,10 @@
|
||||
#include "nsIEventQueueService.h"
|
||||
#include "nsIObserverService.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIPref.h"
|
||||
#include "nsIPrefBranch2.h"
|
||||
#include "nsIPrefBranch.h"
|
||||
#include "nsIPrefService.h"
|
||||
#include "nsIObserver.h"
|
||||
|
||||
|
||||
static io_connect_t gRootPort = nsnull;
|
||||
@ -86,7 +89,7 @@ nsToolkitBase::~nsToolkitBase()
|
||||
PR_SetThreadPrivate(gToolkitTLSIndex, nsnull);
|
||||
}
|
||||
|
||||
NS_IMPL_THREADSAFE_ISUPPORTS1(nsToolkitBase, nsIToolkit);
|
||||
NS_IMPL_THREADSAFE_ISUPPORTS2(nsToolkitBase, nsIToolkit, nsIObserver);
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsToolkitBase::Init(PRThread * aThread)
|
||||
@ -101,21 +104,21 @@ nsToolkitBase::Init(PRThread * aThread)
|
||||
RegisterForSleepWakeNotifcations();
|
||||
SetupQuartzRendering();
|
||||
|
||||
nsCOMPtr<nsIPref> prefs = do_GetService(NS_PREF_CONTRACTID);
|
||||
nsCOMPtr<nsIPrefBranch2> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
|
||||
if (prefs) {
|
||||
prefs->RegisterCallback(kQuartzRenderingPref, QuartzChangedCallback, nsnull);
|
||||
prefs->RegisterCallback(kAllFontSizesPref, QuartzChangedCallback, nsnull);
|
||||
prefs->AddObserver(kQuartzRenderingPref, this, PR_FALSE);
|
||||
prefs->AddObserver(kAllFontSizesPref, this, PR_FALSE);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// QuartzChangedCallback
|
||||
//
|
||||
// The pref changed, reset the app to use quartz rendering as dictated by the pref
|
||||
//
|
||||
int nsToolkitBase::QuartzChangedCallback(const char* pref, void* data)
|
||||
NS_IMETHODIMP
|
||||
nsToolkitBase::Observe(nsISupports* aSubject,
|
||||
const char* aTopic,
|
||||
const PRUnichar* aData)
|
||||
{
|
||||
SetupQuartzRendering();
|
||||
return NS_OK;
|
||||
@ -145,7 +148,7 @@ void nsToolkitBase::SetupQuartzRendering()
|
||||
// the pref isn't found, assume we want it on. That way, we have to explicitly put
|
||||
// in a pref to disable it, rather than force everyone who wants it to carry around
|
||||
// an extra pref.
|
||||
nsCOMPtr<nsIPref> prefs = do_GetService(NS_PREF_CONTRACTID);
|
||||
nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
|
||||
if (!prefs)
|
||||
return;
|
||||
|
||||
|
@ -44,9 +44,9 @@
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIEventQueueService.h"
|
||||
#include "nsIObserver.h"
|
||||
|
||||
|
||||
class nsToolkitBase : public nsIToolkit
|
||||
class nsToolkitBase : public nsIToolkit : public nsIObserver
|
||||
{
|
||||
public:
|
||||
nsToolkitBase();
|
||||
@ -54,6 +54,7 @@ public:
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSITOOLKIT
|
||||
NS_DECL_NSIOBSERVER
|
||||
|
||||
static void PostSleepWakeNotification(const char* aNotification);
|
||||
|
||||
|
@ -67,7 +67,8 @@
|
||||
#include "nsIRollupListener.h"
|
||||
#include "nsIMenuRollup.h"
|
||||
#include "nsIRegion.h"
|
||||
#include "nsIPref.h"
|
||||
#include "nsIPrefBranch.h"
|
||||
#include "nsIPrefService.h"
|
||||
|
||||
//~~~ windowless plugin support
|
||||
#include "nsplugindefs.h"
|
||||
@ -254,7 +255,7 @@ nsWindow::nsWindow() : nsBaseWidget()
|
||||
// preference set, we put an invisible scroll bar on every child window so we can
|
||||
// scroll. Woohoo!
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIPref> prefs(do_GetService(NS_PREF_CONTRACTID, &rv));
|
||||
nsCOMPtr<nsIPrefBranch> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv));
|
||||
if (NS_SUCCEEDED(rv) && prefs)
|
||||
prefs->GetBoolPref("os2.trackpoint", &gIsTrackPoint);
|
||||
}
|
||||
|
@ -55,7 +55,8 @@
|
||||
#include "nsGfxCIID.h"
|
||||
#include "nsIMenuBar.h"
|
||||
#include "nsToolkit.h"
|
||||
#include "nsIPref.h"
|
||||
#include "nsIPrefBranch.h"
|
||||
#include "nsIPrefService.h"
|
||||
|
||||
#include "nsClipboard.h"
|
||||
#include "nsIRollupListener.h"
|
||||
@ -798,12 +799,12 @@ int nsWindow::EvInfo( PtWidget_t *widget, void *data, PtCallbackInfo_t *cbinfo )
|
||||
if( cbinfo->event && cbinfo->event->type == Ph_EV_INFO && cbinfo->event->subtype == Ph_OFFSCREEN_INVALID ) {
|
||||
nsresult rv;
|
||||
|
||||
nsCOMPtr<nsIPref> pPrefs = do_GetService(NS_PREF_CONTRACTID, &rv);
|
||||
nsCOMPtr<nsIPrefBranch> pPrefs = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
PRBool displayInternalChange = PR_FALSE;
|
||||
pPrefs->GetBoolPref("browser.display.internaluse.graphics_changed", &displayInternalChange);
|
||||
pPrefs->SetBoolPref("browser.display.internaluse.graphics_changed", !displayInternalChange);
|
||||
}
|
||||
}
|
||||
nsCOMPtr<nsIWindowMediator> windowMediator(do_GetService(kWindowMediatorCID));
|
||||
NS_ENSURE_TRUE(windowMediator, NS_ERROR_FAILURE);
|
||||
|
||||
|
@ -37,11 +37,12 @@
|
||||
|
||||
#include "nscore.h"
|
||||
|
||||
static int PR_CALLBACK colorPrefChanged(const char* aPref, void* aData);
|
||||
|
||||
#include "nsXPLookAndFeel.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIPref.h"
|
||||
#include "nsIPrefBranch2.h"
|
||||
#include "nsIPrefBranch.h"
|
||||
#include "nsIPrefService.h"
|
||||
#include "nsIObserver.h"
|
||||
#include "nsCRT.h"
|
||||
#include "nsFont.h"
|
||||
|
||||
@ -49,9 +50,7 @@ static int PR_CALLBACK colorPrefChanged(const char* aPref, void* aData);
|
||||
#include "nsSize.h"
|
||||
#endif
|
||||
|
||||
static NS_DEFINE_CID(kPrefServiceCID, NS_PREF_CID);
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsXPLookAndFeel, nsILookAndFeel)
|
||||
NS_IMPL_ISUPPORTS2(nsXPLookAndFeel, nsILookAndFeel, nsIObserver)
|
||||
|
||||
nsLookAndFeelIntPref nsXPLookAndFeel::sIntPrefs[] =
|
||||
{
|
||||
@ -207,118 +206,109 @@ nsXPLookAndFeel::nsXPLookAndFeel() : nsILookAndFeel()
|
||||
{
|
||||
}
|
||||
|
||||
static int PR_CALLBACK intPrefChanged (const char *newpref, void *data)
|
||||
void
|
||||
nsXPLookAndFeel::IntPrefChanged (nsLookAndFeelIntPref *data)
|
||||
{
|
||||
nsLookAndFeelIntPref* np = (nsLookAndFeelIntPref*)data;
|
||||
if (np)
|
||||
if (data)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIPref> prefService(do_GetService(kPrefServiceCID, &rv));
|
||||
if (NS_SUCCEEDED(rv) && prefService)
|
||||
nsCOMPtr<nsIPrefBranch> prefService(do_GetService(NS_PREFSERVICE_CONTRACTID));
|
||||
if (prefService)
|
||||
{
|
||||
PRInt32 intpref;
|
||||
rv = prefService->GetIntPref(np->name, &intpref);
|
||||
nsresult rv = prefService->GetIntPref(data->name, &intpref);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
np->intVar = intpref;
|
||||
np->isSet = PR_TRUE;
|
||||
data->intVar = intpref;
|
||||
data->isSet = PR_TRUE;
|
||||
#ifdef DEBUG_akkana
|
||||
printf("====== Changed int pref %s to %d\n", np->name, np->intVar);
|
||||
printf("====== Changed int pref %s to %d\n", data->name, data->intVar);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int PR_CALLBACK floatPrefChanged (const char *newpref, void *data)
|
||||
void
|
||||
nsXPLookAndFeel::FloatPrefChanged (nsLookAndFeelFloatPref *data)
|
||||
{
|
||||
nsLookAndFeelFloatPref* np = (nsLookAndFeelFloatPref*)data;
|
||||
if (np)
|
||||
if (data)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIPref> prefService(do_GetService(kPrefServiceCID, &rv));
|
||||
if (NS_SUCCEEDED(rv) && prefService)
|
||||
nsCOMPtr<nsIPrefBranch> prefService(do_GetService(NS_PREFSERVICE_CONTRACTID));
|
||||
if (prefService)
|
||||
{
|
||||
PRInt32 intpref;
|
||||
rv = prefService->GetIntPref(np->name, &intpref);
|
||||
nsresult rv = prefService->GetIntPref(data->name, &intpref);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
np->floatVar = (float)intpref / 100.;
|
||||
np->isSet = PR_TRUE;
|
||||
data->floatVar = (float)intpref / 100.;
|
||||
data->isSet = PR_TRUE;
|
||||
#ifdef DEBUG_akkana
|
||||
printf("====== Changed float pref %s to %f\n", np->name, np->floatVar);
|
||||
printf("====== Changed float pref %s to %f\n", data->name, data->floatVar);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int PR_CALLBACK colorPrefChanged (const char *newpref, void *data)
|
||||
void
|
||||
nsXPLookAndFeel::ColorPrefChanged (unsigned int index, const char *prefName)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIPref> prefService(do_GetService(kPrefServiceCID, &rv));
|
||||
if (NS_SUCCEEDED(rv) && prefService) {
|
||||
nsCOMPtr<nsIPrefBranch> prefService(do_GetService(NS_PREFSERVICE_CONTRACTID));
|
||||
if (prefService) {
|
||||
nsXPIDLCString colorStr;
|
||||
rv = prefService->CopyCharPref(newpref, getter_Copies(colorStr));
|
||||
if (NS_SUCCEEDED(rv) && colorStr[0]) {
|
||||
nsresult rv = prefService->GetCharPref(prefName, getter_Copies(colorStr));
|
||||
if (NS_SUCCEEDED(rv) && !colorStr.IsEmpty()) {
|
||||
nscolor thecolor;
|
||||
if (colorStr[0] == '#') {
|
||||
if (NS_SUCCEEDED(NS_HexToRGB(NS_ConvertASCIItoUCS2(Substring(colorStr, 1, colorStr.Length() - 1)),
|
||||
&thecolor))) {
|
||||
PRInt32 id = NS_PTR_TO_INT32(data);
|
||||
PRInt32 id = NS_PTR_TO_INT32(index);
|
||||
CACHE_COLOR(id, thecolor);
|
||||
}
|
||||
}
|
||||
else if (NS_SUCCEEDED(NS_ColorNameToRGB(NS_ConvertASCIItoUCS2(colorStr),
|
||||
&thecolor))) {
|
||||
PRInt32 id = NS_PTR_TO_INT32(data);
|
||||
PRInt32 id = NS_PTR_TO_INT32(index);
|
||||
CACHE_COLOR(id, thecolor);
|
||||
#ifdef DEBUG_akkana
|
||||
printf("====== Changed color pref %s to 0x%lx\n",
|
||||
newpref, thecolor);
|
||||
prefName, thecolor);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsXPLookAndFeel::InitFromPref(nsLookAndFeelIntPref* aPref, nsIPref* aPrefService)
|
||||
void
|
||||
nsXPLookAndFeel::InitFromPref(nsLookAndFeelIntPref* aPref, nsIPrefBranch* aPrefBranch)
|
||||
{
|
||||
PRInt32 intpref;
|
||||
nsresult rv = aPrefService->GetIntPref(aPref->name, &intpref);
|
||||
nsresult rv = aPrefBranch->GetIntPref(aPref->name, &intpref);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
aPref->isSet = PR_TRUE;
|
||||
aPref->intVar = intpref;
|
||||
}
|
||||
aPrefService->RegisterCallback(aPref->name, intPrefChanged, aPref);
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsXPLookAndFeel::InitFromPref(nsLookAndFeelFloatPref* aPref, nsIPref* aPrefService)
|
||||
void
|
||||
nsXPLookAndFeel::InitFromPref(nsLookAndFeelFloatPref* aPref, nsIPrefBranch* aPrefBranch)
|
||||
{
|
||||
PRInt32 intpref;
|
||||
nsresult rv = aPrefService->GetIntPref(aPref->name, &intpref);
|
||||
nsresult rv = aPrefBranch->GetIntPref(aPref->name, &intpref);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
aPref->isSet = PR_TRUE;
|
||||
aPref->floatVar = (float)intpref / 100.;
|
||||
}
|
||||
aPrefService->RegisterCallback(aPref->name, floatPrefChanged, aPref);
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsXPLookAndFeel::InitColorFromPref(PRInt32 i, nsIPref* aPrefService)
|
||||
void
|
||||
nsXPLookAndFeel::InitColorFromPref(PRInt32 i, nsIPrefBranch* aPrefBranch)
|
||||
{
|
||||
char *colorStr = 0;
|
||||
nsresult rv = aPrefService->CopyCharPref(sColorPrefs[i], &colorStr);
|
||||
if (NS_SUCCEEDED(rv) && colorStr[0])
|
||||
nsXPIDLCString colorStr;
|
||||
nsresult rv = aPrefBranch->GetCharPref(sColorPrefs[i], getter_Copies(colorStr));
|
||||
if (NS_SUCCEEDED(rv) && !colorStr.IsEmpty())
|
||||
{
|
||||
nsAutoString colorNSStr; colorNSStr.AssignWithConversion(colorStr);
|
||||
nscolor thecolor;
|
||||
@ -327,18 +317,46 @@ nsXPLookAndFeel::InitColorFromPref(PRInt32 i, nsIPref* aPrefService)
|
||||
colorNSStr.Right(hexString, colorNSStr.Length() - 1);
|
||||
if (NS_SUCCEEDED(NS_HexToRGB(hexString, &thecolor))) {
|
||||
CACHE_COLOR(i, thecolor);
|
||||
PL_strfree(colorStr);
|
||||
}
|
||||
}
|
||||
else if (NS_SUCCEEDED(NS_ColorNameToRGB(colorNSStr, &thecolor)))
|
||||
{
|
||||
CACHE_COLOR(i, thecolor);
|
||||
PL_strfree(colorStr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXPLookAndFeel::Observe(nsISupports* aSubject,
|
||||
const char* aTopic,
|
||||
const PRUnichar* aData)
|
||||
{
|
||||
|
||||
// looping in the same order as in ::Init
|
||||
|
||||
unsigned int i;
|
||||
for (i = 0; i < NS_ARRAY_LENGTH(sIntPrefs); ++i) {
|
||||
if (nsDependentString(aData).EqualsASCII(sIntPrefs[i].name)) {
|
||||
IntPrefChanged(&sIntPrefs[i]);
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
aPrefService->RegisterCallback(sColorPrefs[i], colorPrefChanged, (void*)i);
|
||||
return rv;
|
||||
for (i = 0; i < NS_ARRAY_LENGTH(sFloatPrefs); ++i) {
|
||||
if (nsDependentString(aData).EqualsASCII(sFloatPrefs[i].name)) {
|
||||
FloatPrefChanged(&sFloatPrefs[i]);
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < NS_ARRAY_LENGTH(sColorPrefs); ++i) {
|
||||
if (nsDependentString(aData).EqualsASCII(sColorPrefs[i])) {
|
||||
ColorPrefChanged(i, sColorPrefs[i]);
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//
|
||||
@ -354,20 +372,28 @@ nsXPLookAndFeel::Init()
|
||||
// protects against some other process writing to our static variables.
|
||||
sInitialized = PR_TRUE;
|
||||
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIPref> prefService(do_GetService(kPrefServiceCID, &rv));
|
||||
if (NS_FAILED(rv) || !prefService)
|
||||
nsCOMPtr<nsIPrefBranch> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID));
|
||||
if (!prefs)
|
||||
return;
|
||||
nsCOMPtr<nsIPrefBranch2> prefBranchInternal(do_QueryInterface(prefs));
|
||||
if (!prefBranchInternal)
|
||||
return;
|
||||
|
||||
unsigned int i;
|
||||
for (i = 0; i < ((sizeof (sIntPrefs) / sizeof (*sIntPrefs))); ++i)
|
||||
InitFromPref(&sIntPrefs[i], prefService);
|
||||
for (i = 0; i < NS_ARRAY_LENGTH(sIntPrefs); ++i) {
|
||||
InitFromPref(&sIntPrefs[i], prefs);
|
||||
prefBranchInternal->AddObserver(sIntPrefs[i].name, this, PR_FALSE);
|
||||
}
|
||||
|
||||
for (i = 0; i < ((sizeof (sFloatPrefs) / sizeof (*sFloatPrefs))); ++i)
|
||||
InitFromPref(&sFloatPrefs[i], prefService);
|
||||
for (i = 0; i < NS_ARRAY_LENGTH(sFloatPrefs); ++i) {
|
||||
InitFromPref(&sFloatPrefs[i], prefs);
|
||||
prefBranchInternal->AddObserver(sFloatPrefs[i].name, this, PR_FALSE);
|
||||
}
|
||||
|
||||
for (i = 0; i < (sizeof(sColorPrefs) / sizeof (*sColorPrefs)); ++i)
|
||||
InitColorFromPref(i, prefService);
|
||||
for (i = 0; i < NS_ARRAY_LENGTH(sColorPrefs); ++i) {
|
||||
InitColorFromPref(i, prefs);
|
||||
prefBranchInternal->AddObserver(sColorPrefs[i], this, PR_FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
nsXPLookAndFeel::~nsXPLookAndFeel()
|
||||
@ -380,7 +406,8 @@ nsXPLookAndFeel::~nsXPLookAndFeel()
|
||||
// otherwise we'll return NS_ERROR_NOT_AVAILABLE, in which case, the
|
||||
// platform-specific nsLookAndFeel should use its own values instead.
|
||||
//
|
||||
NS_IMETHODIMP nsXPLookAndFeel::GetColor(const nsColorID aID, nscolor &aColor)
|
||||
NS_IMETHODIMP
|
||||
nsXPLookAndFeel::GetColor(const nsColorID aID, nscolor &aColor)
|
||||
{
|
||||
if (!sInitialized)
|
||||
Init();
|
||||
@ -494,7 +521,8 @@ NS_IMETHODIMP nsXPLookAndFeel::GetColor(const nsColorID aID, nscolor &aColor)
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsXPLookAndFeel::GetMetric(const nsMetricID aID, PRInt32& aMetric)
|
||||
NS_IMETHODIMP
|
||||
nsXPLookAndFeel::GetMetric(const nsMetricID aID, PRInt32& aMetric)
|
||||
{
|
||||
if (!sInitialized)
|
||||
Init();
|
||||
|
@ -40,6 +40,8 @@
|
||||
|
||||
#include "nsILookAndFeel.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIObserver.h"
|
||||
#include "nsIPrefBranch.h"
|
||||
|
||||
class nsIPref;
|
||||
|
||||
@ -79,7 +81,7 @@ struct nsLookAndFeelFloatPref
|
||||
#define CACHE_COLOR(x, y) nsXPLookAndFeel::sCachedColors[(x)] = y; \
|
||||
nsXPLookAndFeel::sCachedColorBits[CACHE_BLOCK(x)] |= CACHE_BIT(x);
|
||||
|
||||
class nsXPLookAndFeel: public nsILookAndFeel
|
||||
class nsXPLookAndFeel: public nsILookAndFeel, public nsIObserver
|
||||
{
|
||||
public:
|
||||
nsXPLookAndFeel();
|
||||
@ -87,6 +89,8 @@ public:
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_DECL_NSIOBSERVER
|
||||
|
||||
void Init();
|
||||
|
||||
//
|
||||
@ -109,9 +113,12 @@ public:
|
||||
#endif
|
||||
|
||||
protected:
|
||||
nsresult InitFromPref(nsLookAndFeelIntPref* aPref, nsIPref* aPrefService);
|
||||
nsresult InitFromPref(nsLookAndFeelFloatPref* aPref, nsIPref* aPrefService);
|
||||
nsresult InitColorFromPref(PRInt32 aIndex, nsIPref* aPrefService);
|
||||
void IntPrefChanged(nsLookAndFeelIntPref *data);
|
||||
void FloatPrefChanged(nsLookAndFeelFloatPref *data);
|
||||
void ColorPrefChanged(unsigned int index, const char *prefName);
|
||||
void InitFromPref(nsLookAndFeelIntPref* aPref, nsIPrefBranch* aPrefBranch);
|
||||
void InitFromPref(nsLookAndFeelFloatPref* aPref, nsIPrefBranch* aPrefBranch);
|
||||
void InitColorFromPref(PRInt32 aIndex, nsIPrefBranch* aPrefBranch);
|
||||
virtual nsresult NativeGetColor(const nsColorID aID, nscolor& aColor) = 0;
|
||||
|
||||
static PRBool sInitialized;
|
||||
@ -123,8 +130,6 @@ protected:
|
||||
static const char sColorPrefs[][36];
|
||||
static PRInt32 sCachedColors[nsILookAndFeel::eColor_LAST_COLOR];
|
||||
static PRInt32 sCachedColorBits[COLOR_CACHE_SIZE];
|
||||
|
||||
friend int colorPrefChanged(const char* aPref, void* aData);
|
||||
};
|
||||
|
||||
extern nsresult NS_NewXPLookAndFeel(nsILookAndFeel**);
|
||||
|
Loading…
x
Reference in New Issue
Block a user