nsLayoutStatics.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. #ifndef nsLayoutStatics_h__
  5. #define nsLayoutStatics_h__
  6. #include "nscore.h"
  7. #include "MainThreadUtils.h"
  8. #include "nsISupportsImpl.h"
  9. #include "nsDebug.h"
  10. // This isn't really a class, it's a namespace for static methods.
  11. // Documents and other objects can hold a reference to the layout static
  12. // objects so that they last past the xpcom-shutdown notification.
  13. class nsLayoutStatics
  14. {
  15. public:
  16. // Called by the layout module constructor. This call performs an AddRef()
  17. // internally.
  18. static nsresult Initialize();
  19. static void AddRef()
  20. {
  21. NS_ASSERTION(NS_IsMainThread(),
  22. "nsLayoutStatics reference counting must be on main thread");
  23. NS_ASSERTION(sLayoutStaticRefcnt,
  24. "nsLayoutStatics already dropped to zero!");
  25. ++sLayoutStaticRefcnt;
  26. NS_LOG_ADDREF(&sLayoutStaticRefcnt, sLayoutStaticRefcnt,
  27. "nsLayoutStatics", 1);
  28. }
  29. static void Release()
  30. {
  31. NS_ASSERTION(NS_IsMainThread(),
  32. "nsLayoutStatics reference counting must be on main thread");
  33. --sLayoutStaticRefcnt;
  34. NS_LOG_RELEASE(&sLayoutStaticRefcnt, sLayoutStaticRefcnt,
  35. "nsLayoutStatics");
  36. if (!sLayoutStaticRefcnt)
  37. Shutdown();
  38. }
  39. private:
  40. // not to be called!
  41. nsLayoutStatics();
  42. static void Shutdown();
  43. static nsrefcnt sLayoutStaticRefcnt;
  44. };
  45. class nsLayoutStaticsRef
  46. {
  47. public:
  48. nsLayoutStaticsRef()
  49. {
  50. nsLayoutStatics::AddRef();
  51. }
  52. ~nsLayoutStaticsRef()
  53. {
  54. nsLayoutStatics::Release();
  55. }
  56. };
  57. #endif // nsLayoutStatics_h__