michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef nsLayoutStatics_h__ michael@0: #define nsLayoutStatics_h__ michael@0: michael@0: #include "nscore.h" michael@0: #include "MainThreadUtils.h" michael@0: #include "nsISupportsImpl.h" michael@0: #include "nsDebug.h" michael@0: michael@0: // This isn't really a class, it's a namespace for static methods. michael@0: // Documents and other objects can hold a reference to the layout static michael@0: // objects so that they last past the xpcom-shutdown notification. michael@0: michael@0: class nsLayoutStatics michael@0: { michael@0: public: michael@0: // Called by the layout module constructor. This call performs an AddRef() michael@0: // internally. michael@0: static nsresult Initialize(); michael@0: michael@0: static void AddRef() michael@0: { michael@0: NS_ASSERTION(NS_IsMainThread(), michael@0: "nsLayoutStatics reference counting must be on main thread"); michael@0: michael@0: NS_ASSERTION(sLayoutStaticRefcnt, michael@0: "nsLayoutStatics already dropped to zero!"); michael@0: michael@0: ++sLayoutStaticRefcnt; michael@0: NS_LOG_ADDREF(&sLayoutStaticRefcnt, sLayoutStaticRefcnt, michael@0: "nsLayoutStatics", 1); michael@0: } michael@0: static void Release() michael@0: { michael@0: NS_ASSERTION(NS_IsMainThread(), michael@0: "nsLayoutStatics reference counting must be on main thread"); michael@0: michael@0: --sLayoutStaticRefcnt; michael@0: NS_LOG_RELEASE(&sLayoutStaticRefcnt, sLayoutStaticRefcnt, michael@0: "nsLayoutStatics"); michael@0: michael@0: if (!sLayoutStaticRefcnt) michael@0: Shutdown(); michael@0: } michael@0: michael@0: private: michael@0: // not to be called! michael@0: nsLayoutStatics(); michael@0: michael@0: static void Shutdown(); michael@0: michael@0: static nsrefcnt sLayoutStaticRefcnt; michael@0: }; michael@0: michael@0: class nsLayoutStaticsRef michael@0: { michael@0: public: michael@0: nsLayoutStaticsRef() michael@0: { michael@0: nsLayoutStatics::AddRef(); michael@0: } michael@0: ~nsLayoutStaticsRef() michael@0: { michael@0: nsLayoutStatics::Release(); michael@0: } michael@0: }; michael@0: michael@0: #endif // nsLayoutStatics_h__