StyleSheetInlines.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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 mozilla_StyleSheetInlines_h
  6. #define mozilla_StyleSheetInlines_h
  7. #include "mozilla/StyleSheetInfo.h"
  8. #include "mozilla/ServoStyleSheet.h"
  9. #include "mozilla/CSSStyleSheet.h"
  10. namespace mozilla {
  11. MOZ_DEFINE_STYLO_METHODS(StyleSheet, CSSStyleSheet, ServoStyleSheet)
  12. StyleSheetInfo&
  13. StyleSheet::SheetInfo()
  14. {
  15. if (IsServo()) {
  16. return AsServo()->mSheetInfo;
  17. }
  18. return *AsGecko()->mInner;
  19. }
  20. const StyleSheetInfo&
  21. StyleSheet::SheetInfo() const
  22. {
  23. if (IsServo()) {
  24. return AsServo()->mSheetInfo;
  25. }
  26. return *AsGecko()->mInner;
  27. }
  28. bool
  29. StyleSheet::IsInline() const
  30. {
  31. return !SheetInfo().mOriginalSheetURI;
  32. }
  33. nsIURI*
  34. StyleSheet::GetSheetURI() const
  35. {
  36. return SheetInfo().mSheetURI;
  37. }
  38. nsIURI*
  39. StyleSheet::GetOriginalURI() const
  40. {
  41. return SheetInfo().mOriginalSheetURI;
  42. }
  43. nsIURI*
  44. StyleSheet::GetBaseURI() const
  45. {
  46. return SheetInfo().mBaseURI;
  47. }
  48. void
  49. StyleSheet::SetURIs(nsIURI* aSheetURI, nsIURI* aOriginalSheetURI,
  50. nsIURI* aBaseURI)
  51. {
  52. NS_PRECONDITION(aSheetURI && aBaseURI, "null ptr");
  53. StyleSheetInfo& info = SheetInfo();
  54. MOZ_ASSERT(!HasRules() && !info.mComplete,
  55. "Can't call SetURIs on sheets that are complete or have rules");
  56. info.mSheetURI = aSheetURI;
  57. info.mOriginalSheetURI = aOriginalSheetURI;
  58. info.mBaseURI = aBaseURI;
  59. }
  60. bool
  61. StyleSheet::IsApplicable() const
  62. {
  63. return !mDisabled && SheetInfo().mComplete;
  64. }
  65. bool
  66. StyleSheet::HasRules() const
  67. {
  68. MOZ_STYLO_FORWARD(HasRules, ())
  69. }
  70. void
  71. StyleSheet::SetAssociatedDocument(nsIDocument* aDocument,
  72. DocumentAssociationMode aAssociationMode)
  73. {
  74. MOZ_ASSERT(aDocument);
  75. MOZ_STYLO_FORWARD(SetAssociatedDocument, (aDocument, aAssociationMode))
  76. }
  77. void
  78. StyleSheet::ClearAssociatedDocument()
  79. {
  80. MOZ_STYLO_FORWARD(SetAssociatedDocument, (nullptr, NotOwnedByDocument));
  81. }
  82. StyleSheet*
  83. StyleSheet::GetParentSheet() const
  84. {
  85. MOZ_STYLO_FORWARD(GetParentSheet, ())
  86. }
  87. StyleSheet*
  88. StyleSheet::GetParentStyleSheet() const
  89. {
  90. return GetParentSheet();
  91. }
  92. dom::ParentObject
  93. StyleSheet::GetParentObject() const
  94. {
  95. if (mOwningNode) {
  96. return dom::ParentObject(mOwningNode);
  97. }
  98. return dom::ParentObject(GetParentSheet());
  99. }
  100. void
  101. StyleSheet::AppendStyleSheet(StyleSheet* aSheet)
  102. {
  103. MOZ_STYLO_FORWARD_CONCRETE(AppendStyleSheet,
  104. (aSheet->AsGecko()), (aSheet->AsServo()))
  105. }
  106. nsIPrincipal*
  107. StyleSheet::Principal() const
  108. {
  109. return SheetInfo().mPrincipal;
  110. }
  111. void
  112. StyleSheet::SetPrincipal(nsIPrincipal* aPrincipal)
  113. {
  114. StyleSheetInfo& info = SheetInfo();
  115. NS_PRECONDITION(!info.mPrincipalSet, "Should only set principal once");
  116. if (aPrincipal) {
  117. info.mPrincipal = aPrincipal;
  118. #ifdef DEBUG
  119. info.mPrincipalSet = true;
  120. #endif
  121. }
  122. }
  123. CORSMode
  124. StyleSheet::GetCORSMode() const
  125. {
  126. return SheetInfo().mCORSMode;
  127. }
  128. net::ReferrerPolicy
  129. StyleSheet::GetReferrerPolicy() const
  130. {
  131. return SheetInfo().mReferrerPolicy;
  132. }
  133. void
  134. StyleSheet::GetIntegrity(dom::SRIMetadata& aResult) const
  135. {
  136. aResult = SheetInfo().mIntegrity;
  137. }
  138. size_t
  139. StyleSheet::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
  140. {
  141. MOZ_STYLO_FORWARD(SizeOfIncludingThis, (aMallocSizeOf))
  142. }
  143. #ifdef DEBUG
  144. void
  145. StyleSheet::List(FILE* aOut, int32_t aIndex) const
  146. {
  147. MOZ_STYLO_FORWARD(List, (aOut, aIndex))
  148. }
  149. #endif
  150. void StyleSheet::WillDirty() { MOZ_STYLO_FORWARD(WillDirty, ()) }
  151. void StyleSheet::DidDirty() { MOZ_STYLO_FORWARD(DidDirty, ()) }
  152. }
  153. #endif // mozilla_StyleSheetInlines_h