From 7bfdf9ceaf099f1dc89f603aafad7b4daefb50b5 Mon Sep 17 00:00:00 2001 From: "dbaron%fas.harvard.edu" Date: Tue, 19 Nov 2002 15:21:57 +0000 Subject: [PATCH] Remove static nsCOMPtr from nsTextControlFrame. b=179228 r=jkeiser sr=bzbarsky git-svn-id: svn://10.0.0.236/trunk@134104 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/layout/build/nsLayoutModule.cpp | 2 ++ mozilla/layout/forms/nsTextControlFrame.cpp | 30 +++++++++++-------- mozilla/layout/forms/nsTextControlFrame.h | 2 ++ .../html/forms/src/nsTextControlFrame.cpp | 30 +++++++++++-------- .../html/forms/src/nsTextControlFrame.h | 2 ++ 5 files changed, 40 insertions(+), 26 deletions(-) diff --git a/mozilla/layout/build/nsLayoutModule.cpp b/mozilla/layout/build/nsLayoutModule.cpp index cdf04f6ca07..be119a18660 100644 --- a/mozilla/layout/build/nsLayoutModule.cpp +++ b/mozilla/layout/build/nsLayoutModule.cpp @@ -52,6 +52,7 @@ #include "nsIPrintContext.h" #include "nsIPrintPreviewContext.h" #include "nsTextTransformer.h" +#include "nsTextControlFrame.h" #include "nsXBLAtoms.h" // to addref/release table #include "nsHTMLAtoms.h" // to addref/release table @@ -175,6 +176,7 @@ Shutdown(nsIModule* self) nsTextTransformer::Shutdown(); nsSpaceManager::Shutdown(); + nsTextControlFrame::ReleaseGlobals(); } #ifdef NS_DEBUG diff --git a/mozilla/layout/forms/nsTextControlFrame.cpp b/mozilla/layout/forms/nsTextControlFrame.cpp index 7f2a5284f11..55650af4dd4 100644 --- a/mozilla/layout/forms/nsTextControlFrame.cpp +++ b/mozilla/layout/forms/nsTextControlFrame.cpp @@ -139,22 +139,20 @@ static const PRInt32 DEFAULT_COLS = 20; static const PRInt32 DEFAULT_ROWS = 1; static const PRInt32 DEFAULT_ROWS_TEXTAREA = 2; +static nsIWeakReference *sElementFactory = nsnull; + static nsresult GetElementFactoryService(nsIElementFactory **aFactory) { - nsresult rv(NS_OK); - static nsWeakPtr sElementFactory = getter_AddRefs( NS_GetWeakReference(nsCOMPtr(do_GetService( - NS_ELEMENT_FACTORY_CONTRACTID_PREFIX"http://www.w3.org/1999/xhtml", &rv) ))); - if (sElementFactory) - { - nsCOMPtr fac(do_QueryReferent(sElementFactory)); - *aFactory = fac.get(); - if (!*aFactory) - rv = NS_ERROR_FAILURE; - NS_IF_ADDREF(*aFactory); + if (!sElementFactory) { + sElementFactory = NS_GetWeakReference( + nsCOMPtr( + do_GetService( + NS_ELEMENT_FACTORY_CONTRACTID_PREFIX + "http://www.w3.org/1999/xhtml"))); + if (!sElementFactory) + return NS_ERROR_FAILURE; } - else - return NS_ERROR_FAILURE; - return rv; + return CallQueryReferent(sElementFactory, aFactory); } @@ -1323,6 +1321,12 @@ nsTextControlFrame::~nsTextControlFrame() //delete mTextSelImpl; dont delete this since mSelCon will release it. } +/* static */ void +nsTextControlFrame::ReleaseGlobals() +{ + NS_IF_RELEASE(sElementFactory); +} + static PRBool SuppressEventHandlers(nsIPresContext* aPresContext) { diff --git a/mozilla/layout/forms/nsTextControlFrame.h b/mozilla/layout/forms/nsTextControlFrame.h index 21f09f56f2f..bdc2d41395b 100644 --- a/mozilla/layout/forms/nsTextControlFrame.h +++ b/mozilla/layout/forms/nsTextControlFrame.h @@ -75,6 +75,8 @@ public: nsTextControlFrame(nsIPresShell* aShell); virtual ~nsTextControlFrame(); + static void ReleaseGlobals(); + virtual void RemovedAsPrimaryFrame(nsIPresContext* aPresContext); NS_IMETHOD Destroy(nsIPresContext* aPresContext); diff --git a/mozilla/layout/html/forms/src/nsTextControlFrame.cpp b/mozilla/layout/html/forms/src/nsTextControlFrame.cpp index 7f2a5284f11..55650af4dd4 100644 --- a/mozilla/layout/html/forms/src/nsTextControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsTextControlFrame.cpp @@ -139,22 +139,20 @@ static const PRInt32 DEFAULT_COLS = 20; static const PRInt32 DEFAULT_ROWS = 1; static const PRInt32 DEFAULT_ROWS_TEXTAREA = 2; +static nsIWeakReference *sElementFactory = nsnull; + static nsresult GetElementFactoryService(nsIElementFactory **aFactory) { - nsresult rv(NS_OK); - static nsWeakPtr sElementFactory = getter_AddRefs( NS_GetWeakReference(nsCOMPtr(do_GetService( - NS_ELEMENT_FACTORY_CONTRACTID_PREFIX"http://www.w3.org/1999/xhtml", &rv) ))); - if (sElementFactory) - { - nsCOMPtr fac(do_QueryReferent(sElementFactory)); - *aFactory = fac.get(); - if (!*aFactory) - rv = NS_ERROR_FAILURE; - NS_IF_ADDREF(*aFactory); + if (!sElementFactory) { + sElementFactory = NS_GetWeakReference( + nsCOMPtr( + do_GetService( + NS_ELEMENT_FACTORY_CONTRACTID_PREFIX + "http://www.w3.org/1999/xhtml"))); + if (!sElementFactory) + return NS_ERROR_FAILURE; } - else - return NS_ERROR_FAILURE; - return rv; + return CallQueryReferent(sElementFactory, aFactory); } @@ -1323,6 +1321,12 @@ nsTextControlFrame::~nsTextControlFrame() //delete mTextSelImpl; dont delete this since mSelCon will release it. } +/* static */ void +nsTextControlFrame::ReleaseGlobals() +{ + NS_IF_RELEASE(sElementFactory); +} + static PRBool SuppressEventHandlers(nsIPresContext* aPresContext) { diff --git a/mozilla/layout/html/forms/src/nsTextControlFrame.h b/mozilla/layout/html/forms/src/nsTextControlFrame.h index 21f09f56f2f..bdc2d41395b 100644 --- a/mozilla/layout/html/forms/src/nsTextControlFrame.h +++ b/mozilla/layout/html/forms/src/nsTextControlFrame.h @@ -75,6 +75,8 @@ public: nsTextControlFrame(nsIPresShell* aShell); virtual ~nsTextControlFrame(); + static void ReleaseGlobals(); + virtual void RemovedAsPrimaryFrame(nsIPresContext* aPresContext); NS_IMETHOD Destroy(nsIPresContext* aPresContext);