From 709adbc4ab1cf43640638c7e0c598d1d02513e9c Mon Sep 17 00:00:00 2001 From: "jst%mozilla.org" Date: Thu, 22 Feb 2007 22:38:25 +0000 Subject: [PATCH] Fixing bug 371200. Make us have only one pref observer for browser.chrome.toolbar_tips rather than having every single XUL tooltip listener listen for changes to the pref only to update a global variable. r+sr=jonas@sicking.cc --- layout/xul/base/src/nsXULTooltipListener.cpp | 25 +++++++++++--------- layout/xul/base/src/nsXULTooltipListener.h | 1 + 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/layout/xul/base/src/nsXULTooltipListener.cpp b/layout/xul/base/src/nsXULTooltipListener.cpp index 9e7294093a7e..123ad1afc210 100644 --- a/layout/xul/base/src/nsXULTooltipListener.cpp +++ b/layout/xul/base/src/nsXULTooltipListener.cpp @@ -76,15 +76,25 @@ nsXULTooltipListener::nsXULTooltipListener() , mLastTreeRow(-1) #endif { + if (sTooltipListenerCount++ == 0) { + // register the callback so we get notified of updates + nsContentUtils::RegisterPrefCallback("browser.chrome.toolbar_tips", + ToolbarTipsPrefChanged, this); + + // Call the pref callback to initialize our state. + ToolbarTipsPrefChanged("browser.chrome.toolbar_tips", nsnull); + } } nsXULTooltipListener::~nsXULTooltipListener() { HideTooltip(); - // Unregister our pref observer - nsContentUtils::UnregisterPrefCallback("browser.chrome.toolbar_tips", - ToolbarTipsPrefChanged, this); + if (--sTooltipListenerCount == 0) { + // Unregister our pref observer + nsContentUtils::UnregisterPrefCallback("browser.chrome.toolbar_tips", + ToolbarTipsPrefChanged, this); + } } NS_IMPL_ADDREF(nsXULTooltipListener) @@ -272,6 +282,7 @@ nsXULTooltipListener::PopupHiding(nsIDOMEvent* aEvent) //// nsXULTooltipListener PRBool nsXULTooltipListener::sShowTooltips = PR_FALSE; +PRUint32 nsXULTooltipListener::sTooltipListenerCount = 0; // XXX: This could all be done in the ctor. nsresult @@ -286,14 +297,6 @@ nsXULTooltipListener::Init(nsIContent* aSourceNode) mIsSourceTree = mSourceNode->Tag() == nsGkAtoms::treechildren; #endif - // get the initial value of the pref - sShowTooltips = - nsContentUtils::GetBoolPref("browser.chrome.toolbar_tips", sShowTooltips); - - // register the callback so we get notified of updates - nsContentUtils::RegisterPrefCallback("browser.chrome.toolbar_tips", - ToolbarTipsPrefChanged, this); - return NS_OK; } diff --git a/layout/xul/base/src/nsXULTooltipListener.h b/layout/xul/base/src/nsXULTooltipListener.h index 4111edd87329..2e9113f6992c 100644 --- a/layout/xul/base/src/nsXULTooltipListener.h +++ b/layout/xul/base/src/nsXULTooltipListener.h @@ -105,6 +105,7 @@ protected: // pref callback for when the "show tooltips" pref changes static int sTooltipPrefChanged (const char* aPref, void* aData); static PRBool sShowTooltips; + static PRUint32 sTooltipListenerCount; void KillTooltipTimer(); void CreateAutoHideTimer();