nsLayoutStylesheetCache.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #ifndef nsLayoutStylesheetCache_h__
  6. #define nsLayoutStylesheetCache_h__
  7. #include "nsIMemoryReporter.h"
  8. #include "nsIObserver.h"
  9. #include "mozilla/Attributes.h"
  10. #include "mozilla/MemoryReporting.h"
  11. #include "mozilla/StaticPtr.h"
  12. #include "mozilla/StyleBackendType.h"
  13. #include "mozilla/css/Loader.h"
  14. class nsIFile;
  15. class nsIURI;
  16. namespace mozilla {
  17. class CSSStyleSheet;
  18. } // namespace mozilla
  19. namespace mozilla {
  20. namespace css {
  21. // Enum defining how error should be handled.
  22. enum FailureAction {
  23. eCrash = 0,
  24. eLogToConsole
  25. };
  26. }
  27. }
  28. class nsLayoutStylesheetCache final
  29. : public nsIObserver
  30. , public nsIMemoryReporter
  31. {
  32. NS_DECL_ISUPPORTS
  33. NS_DECL_NSIOBSERVER
  34. NS_DECL_NSIMEMORYREPORTER
  35. /**
  36. * Returns the nsLayoutStylesheetCache for the given style backend type.
  37. * Callers should pass in a value for aType that matches the style system
  38. * backend type for the style set in use. (A process may call For
  39. * and obtain nsLayoutStylesheetCache objects for both backend types,
  40. * and a particular UA style sheet might be cached in both, one or neither
  41. * nsLayoutStylesheetCache.)
  42. */
  43. static nsLayoutStylesheetCache* For(mozilla::StyleBackendType aType);
  44. mozilla::StyleSheet* ScrollbarsSheet();
  45. mozilla::StyleSheet* FormsSheet();
  46. // This function is expected to return nullptr when the dom.forms.number
  47. // pref is disabled.
  48. mozilla::StyleSheet* NumberControlSheet();
  49. mozilla::StyleSheet* UserContentSheet();
  50. mozilla::StyleSheet* UserChromeSheet();
  51. mozilla::StyleSheet* UASheet();
  52. mozilla::StyleSheet* HTMLSheet();
  53. mozilla::StyleSheet* MinimalXULSheet();
  54. mozilla::StyleSheet* XULSheet();
  55. mozilla::StyleSheet* QuirkSheet();
  56. mozilla::StyleSheet* SVGSheet();
  57. mozilla::StyleSheet* MathMLSheet();
  58. mozilla::StyleSheet* CounterStylesSheet();
  59. mozilla::StyleSheet* NoScriptSheet();
  60. mozilla::StyleSheet* NoFramesSheet();
  61. mozilla::StyleSheet* ChromePreferenceSheet(nsPresContext* aPresContext);
  62. mozilla::StyleSheet* ContentPreferenceSheet(nsPresContext* aPresContext);
  63. mozilla::StyleSheet* ContentEditableSheet();
  64. mozilla::StyleSheet* DesignModeSheet();
  65. static void InvalidatePreferenceSheets();
  66. static void Shutdown();
  67. static void SetUserContentCSSURL(nsIURI* aURI);
  68. size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
  69. private:
  70. explicit nsLayoutStylesheetCache(mozilla::StyleBackendType aImpl);
  71. ~nsLayoutStylesheetCache();
  72. void InitFromProfile();
  73. void InitMemoryReporter();
  74. void LoadSheetURL(const char* aURL,
  75. RefPtr<mozilla::StyleSheet>* aSheet,
  76. mozilla::css::SheetParsingMode aParsingMode,
  77. mozilla::css::FailureAction aFailureAction);
  78. void LoadSheetFile(nsIFile* aFile,
  79. RefPtr<mozilla::StyleSheet>* aSheet,
  80. mozilla::css::SheetParsingMode aParsingMode,
  81. mozilla::css::FailureAction aFailureAction);
  82. void LoadSheet(nsIURI* aURI, RefPtr<mozilla::StyleSheet>* aSheet,
  83. mozilla::css::SheetParsingMode aParsingMode,
  84. mozilla::css::FailureAction aFailureAction);
  85. static void InvalidateSheet(RefPtr<mozilla::StyleSheet>* aGeckoSheet,
  86. RefPtr<mozilla::StyleSheet>* aServoSheet);
  87. static void DependentPrefChanged(const char* aPref, void* aData);
  88. void BuildPreferenceSheet(RefPtr<mozilla::StyleSheet>* aSheet,
  89. nsPresContext* aPresContext);
  90. static mozilla::StaticRefPtr<nsLayoutStylesheetCache> gStyleCache_Gecko;
  91. static mozilla::StaticRefPtr<nsLayoutStylesheetCache> gStyleCache_Servo;
  92. static mozilla::StaticRefPtr<mozilla::css::Loader> gCSSLoader_Gecko;
  93. static mozilla::StaticRefPtr<mozilla::css::Loader> gCSSLoader_Servo;
  94. static mozilla::StaticRefPtr<nsIURI> gUserContentSheetURL;
  95. mozilla::StyleBackendType mBackendType;
  96. RefPtr<mozilla::StyleSheet> mChromePreferenceSheet;
  97. RefPtr<mozilla::StyleSheet> mContentEditableSheet;
  98. RefPtr<mozilla::StyleSheet> mContentPreferenceSheet;
  99. RefPtr<mozilla::StyleSheet> mCounterStylesSheet;
  100. RefPtr<mozilla::StyleSheet> mDesignModeSheet;
  101. RefPtr<mozilla::StyleSheet> mFormsSheet;
  102. RefPtr<mozilla::StyleSheet> mHTMLSheet;
  103. RefPtr<mozilla::StyleSheet> mMathMLSheet;
  104. RefPtr<mozilla::StyleSheet> mMinimalXULSheet;
  105. RefPtr<mozilla::StyleSheet> mNoFramesSheet;
  106. RefPtr<mozilla::StyleSheet> mNoScriptSheet;
  107. RefPtr<mozilla::StyleSheet> mNumberControlSheet;
  108. RefPtr<mozilla::StyleSheet> mQuirkSheet;
  109. RefPtr<mozilla::StyleSheet> mSVGSheet;
  110. RefPtr<mozilla::StyleSheet> mScrollbarsSheet;
  111. RefPtr<mozilla::StyleSheet> mUASheet;
  112. RefPtr<mozilla::StyleSheet> mUserChromeSheet;
  113. RefPtr<mozilla::StyleSheet> mUserContentSheet;
  114. RefPtr<mozilla::StyleSheet> mXULSheet;
  115. };
  116. #endif