diff --git a/widget/src/xpwidgets/nsXPLookAndFeel.cpp b/widget/src/xpwidgets/nsXPLookAndFeel.cpp index 594b481d070..10a1d062223 100644 --- a/widget/src/xpwidgets/nsXPLookAndFeel.cpp +++ b/widget/src/xpwidgets/nsXPLookAndFeel.cpp @@ -51,7 +51,7 @@ using namespace mozilla; -NS_IMPL_ISUPPORTS2(nsXPLookAndFeel, nsILookAndFeel, nsIObserver) +NS_IMPL_ISUPPORTS1(nsXPLookAndFeel, nsILookAndFeel) nsLookAndFeelIntPref nsXPLookAndFeel::sIntPrefs[] = { @@ -217,6 +217,7 @@ nsXPLookAndFeel::nsXPLookAndFeel() : nsILookAndFeel() { } +// static void nsXPLookAndFeel::IntPrefChanged (nsLookAndFeelIntPref *data) { @@ -236,6 +237,7 @@ nsXPLookAndFeel::IntPrefChanged (nsLookAndFeelIntPref *data) #endif } +// static void nsXPLookAndFeel::FloatPrefChanged (nsLookAndFeelFloatPref *data) { @@ -255,6 +257,7 @@ nsXPLookAndFeel::FloatPrefChanged (nsLookAndFeelFloatPref *data) #endif } +// static void nsXPLookAndFeel::ColorPrefChanged (unsigned int index, const char *prefName) { @@ -330,37 +333,37 @@ nsXPLookAndFeel::InitColorFromPref(PRInt32 i) } } -NS_IMETHODIMP -nsXPLookAndFeel::Observe(nsISupports* aSubject, - const char* aTopic, - const PRUnichar* aData) +// static +int +nsXPLookAndFeel::OnPrefChanged(const char* aPref, void* aClosure) { // looping in the same order as in ::Init + nsDependentCString prefName(aPref); unsigned int i; for (i = 0; i < NS_ARRAY_LENGTH(sIntPrefs); ++i) { - if (nsDependentString(aData).EqualsASCII(sIntPrefs[i].name)) { + if (prefName.Equals(sIntPrefs[i].name)) { IntPrefChanged(&sIntPrefs[i]); - return NS_OK; + return 0; } } for (i = 0; i < NS_ARRAY_LENGTH(sFloatPrefs); ++i) { - if (nsDependentString(aData).EqualsASCII(sFloatPrefs[i].name)) { + if (prefName.Equals(sFloatPrefs[i].name)) { FloatPrefChanged(&sFloatPrefs[i]); - return NS_OK; + return 0; } } for (i = 0; i < NS_ARRAY_LENGTH(sColorPrefs); ++i) { - if (nsDependentString(aData).EqualsASCII(sColorPrefs[i])) { + if (prefName.Equals(sColorPrefs[i])) { ColorPrefChanged(i, sColorPrefs[i]); - return NS_OK; + return 0; } } - return NS_OK; + return 0; } // @@ -376,20 +379,23 @@ nsXPLookAndFeel::Init() // protects against some other process writing to our static variables. sInitialized = PR_TRUE; + // XXX If we could reorganize the pref names, we should separate the branch + // for each types. Then, we could reduce the unnecessary loop from + // nsXPLookAndFeel::OnPrefChanged(). + Preferences::RegisterCallback(OnPrefChanged, "ui."); + Preferences::RegisterCallback(OnPrefChanged, "accessibility.tabfocus"); + unsigned int i; for (i = 0; i < NS_ARRAY_LENGTH(sIntPrefs); ++i) { InitFromPref(&sIntPrefs[i]); - Preferences::AddStrongObserver(this, sIntPrefs[i].name); } for (i = 0; i < NS_ARRAY_LENGTH(sFloatPrefs); ++i) { InitFromPref(&sFloatPrefs[i]); - Preferences::AddStrongObserver(this, sFloatPrefs[i].name); } for (i = 0; i < NS_ARRAY_LENGTH(sColorPrefs); ++i) { InitColorFromPref(i); - Preferences::AddStrongObserver(this, sColorPrefs[i]); } PRBool val; diff --git a/widget/src/xpwidgets/nsXPLookAndFeel.h b/widget/src/xpwidgets/nsXPLookAndFeel.h index dc299b574b9..69d0cc8e200 100644 --- a/widget/src/xpwidgets/nsXPLookAndFeel.h +++ b/widget/src/xpwidgets/nsXPLookAndFeel.h @@ -40,7 +40,6 @@ #include "nsILookAndFeel.h" #include "nsCOMPtr.h" -#include "nsIObserver.h" #ifdef NS_DEBUG struct nsSize; @@ -80,7 +79,7 @@ struct nsLookAndFeelFloatPref #define CACHE_COLOR(x, y) nsXPLookAndFeel::sCachedColors[(x)] = y; \ nsXPLookAndFeel::sCachedColorBits[CACHE_BLOCK(x)] |= CACHE_BIT(x); -class nsXPLookAndFeel: public nsILookAndFeel, public nsIObserver +class nsXPLookAndFeel: public nsILookAndFeel { public: nsXPLookAndFeel(); @@ -88,8 +87,6 @@ public: NS_DECL_ISUPPORTS - NS_DECL_NSIOBSERVER - void Init(); // @@ -112,15 +109,17 @@ public: #endif protected: - void IntPrefChanged(nsLookAndFeelIntPref *data); - void FloatPrefChanged(nsLookAndFeelFloatPref *data); - void ColorPrefChanged(unsigned int index, const char *prefName); + static void IntPrefChanged(nsLookAndFeelIntPref *data); + static void FloatPrefChanged(nsLookAndFeelFloatPref *data); + static void ColorPrefChanged(unsigned int index, const char *prefName); void InitFromPref(nsLookAndFeelIntPref* aPref); void InitFromPref(nsLookAndFeelFloatPref* aPref); void InitColorFromPref(PRInt32 aIndex); virtual nsresult NativeGetColor(const nsColorID aID, nscolor& aColor) = 0; PRBool IsSpecialColor(const nsColorID aID, nscolor &aColor); + static int OnPrefChanged(const char* aPref, void* aClosure); + static PRBool sInitialized; static nsLookAndFeelIntPref sIntPrefs[]; static nsLookAndFeelFloatPref sFloatPrefs[];