From 652bca05def39002306a8952d4906e567f070d80 Mon Sep 17 00:00:00 2001 From: "dbaron%dbaron.org" Date: Thu, 25 Sep 2003 05:36:25 +0000 Subject: [PATCH] Call moz_gtk_shutdown before the event loop shuts down so that objects can be freed completely on shutdown. b=219523 r=bryner sr=blizzard --- gfx/src/gtk/nsNativeThemeGTK.cpp | 24 ++++++++++++++++++++++-- gfx/src/gtk/nsNativeThemeGTK.h | 5 ++++- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/gfx/src/gtk/nsNativeThemeGTK.cpp b/gfx/src/gtk/nsNativeThemeGTK.cpp index b1f3e6dc4bf9..3d87af035f73 100644 --- a/gfx/src/gtk/nsNativeThemeGTK.cpp +++ b/gfx/src/gtk/nsNativeThemeGTK.cpp @@ -41,6 +41,8 @@ #include "nsDrawingSurfaceGTK.h" #include "gtkdrawing.h" +#include "nsIObserverService.h" +#include "nsIServiceManager.h" #include "nsIFrame.h" #include "nsIPresShell.h" #include "nsIDocument.h" @@ -57,7 +59,7 @@ #include -NS_IMPL_ISUPPORTS1(nsNativeThemeGTK, nsITheme) +NS_IMPL_ISUPPORTS2(nsNativeThemeGTK, nsITheme, nsIObserver) static int gLastXError; @@ -68,6 +70,11 @@ nsNativeThemeGTK::nsNativeThemeGTK() return; } + // We have to call moz_gtk_shutdown before the event loop stops running. + nsCOMPtr obsServ = + do_GetService("@mozilla.org/observer-service;1"); + obsServ->AddObserver(this, "quit-application", PR_FALSE); + mDisabledAtom = do_GetAtom("disabled"); mCheckedAtom = do_GetAtom("checked"); mSelectedAtom = do_GetAtom("selected"); @@ -90,7 +97,20 @@ nsNativeThemeGTK::nsNativeThemeGTK() } nsNativeThemeGTK::~nsNativeThemeGTK() { - moz_gtk_shutdown(); +} + +NS_IMETHODIMP +nsNativeThemeGTK::Observe(nsISupports *aSubject, const char *aTopic, + const PRUnichar *aData) +{ + if (!nsCRT::strcmp(aTopic, "quit-application")) { + moz_gtk_shutdown(); + } else { + NS_NOTREACHED("unexpected topic"); + return NS_ERROR_UNEXPECTED; + } + + return NS_OK; } static void GetPrimaryPresShell(nsIFrame* aFrame, nsIPresShell** aResult) diff --git a/gfx/src/gtk/nsNativeThemeGTK.h b/gfx/src/gtk/nsNativeThemeGTK.h index 2004ae66e7da..dd9b3193bd9c 100644 --- a/gfx/src/gtk/nsNativeThemeGTK.h +++ b/gfx/src/gtk/nsNativeThemeGTK.h @@ -39,14 +39,17 @@ #include "nsITheme.h" #include "nsCOMPtr.h" #include "nsIAtom.h" +#include "nsIObserver.h" #include #include "gtkdrawing.h" -class nsNativeThemeGTK: public nsITheme { +class nsNativeThemeGTK: public nsITheme, public nsIObserver { public: NS_DECL_ISUPPORTS + NS_DECL_NSIOBSERVER + // The nsITheme interface. NS_IMETHOD DrawWidgetBackground(nsIRenderingContext* aContext, nsIFrame* aFrame, PRUint8 aWidgetType,