diff --git a/mozilla/widget/src/gtk/nsWidget.cpp b/mozilla/widget/src/gtk/nsWidget.cpp index bd29803019a..ffa3d830ced 100644 --- a/mozilla/widget/src/gtk/nsWidget.cpp +++ b/mozilla/widget/src/gtk/nsWidget.cpp @@ -33,6 +33,8 @@ static NS_DEFINE_IID(kILookAndFeelIID, NS_ILOOKANDFEEL_IID); static NS_DEFINE_IID(kLookAndFeelCID, NS_LOOKANDFEEL_CID); +static nsILookAndFeel *nsWidget::sLookAndFeel = nsnull; +static PRUint32 nsWidget::sWidgetCount = 0; //#define DBG 1 @@ -41,12 +43,17 @@ nsWidget::nsWidget() // XXX Shouldn't this be done in nsBaseWidget? NS_INIT_REFCNT(); - // get the proper color from the look and feel code - nsILookAndFeel * lookAndFeel; - if (NS_OK == nsComponentManager::CreateInstance(kLookAndFeelCID, nsnull, kILookAndFeelIID, (void**)&lookAndFeel)) { - lookAndFeel->GetColor(nsILookAndFeel::eColor_WindowBackground, mBackground); + if (!sLookAndFeel) { + if (NS_OK != nsComponentManager::CreateInstance(kLookAndFeelCID, + nsnull, kILookAndFeelIID, + (void**)&sLookAndFeel)) + sLookAndFeel = nsnull; } - NS_RELEASE(lookAndFeel); + + if (sLookAndFeel) + sLookAndFeel->GetColor(nsILookAndFeel::eColor_WindowBackground, + mBackground); + mWidget = nsnull; mParent = nsnull; mPreferredWidth = 0; @@ -60,6 +67,7 @@ nsWidget::nsWidget() mOnDestroyCalled = PR_FALSE; mIsToplevel = PR_FALSE; mUpdateArea.SetRect(0, 0, 0, 0); + sWidgetCount++; } nsWidget::~nsWidget() @@ -68,6 +76,9 @@ nsWidget::~nsWidget() if (nsnull != mWidget) { Destroy(); } + if (!sWidgetCount--) { + NS_RELEASE_IF(sLookAndFeel); + } } NS_METHOD nsWidget::WidgetToScreen(const nsRect& aOldRect, nsRect& aNewRect) diff --git a/mozilla/widget/src/gtk/nsWidget.h b/mozilla/widget/src/gtk/nsWidget.h index d284feefef0..2a5ff3178d3 100644 --- a/mozilla/widget/src/gtk/nsWidget.h +++ b/mozilla/widget/src/gtk/nsWidget.h @@ -221,6 +221,9 @@ protected: PRBool mShown; PRUint32 mPreferredWidth, mPreferredHeight; +private: + static nsILookAndFeel *sLookAndFeel; + static PRUint32 sWidgetCount; }; #endif /* nsWidget_h__ */