nsStyleStructInlines.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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. /*
  5. * Inline methods that belong in nsStyleStruct.h, except that they
  6. * require more headers.
  7. */
  8. #ifndef nsStyleStructInlines_h_
  9. #define nsStyleStructInlines_h_
  10. #include "nsIFrame.h"
  11. #include "nsStyleStruct.h"
  12. #include "nsIContent.h" // for GetParent()
  13. #include "nsTextFrame.h" // for nsTextFrame::ShouldSuppressLineBreak
  14. inline void
  15. nsStyleImage::EnsureCachedBIData() const
  16. {
  17. if (!mCachedBIData) {
  18. const_cast<nsStyleImage*>(this)->mCachedBIData =
  19. mozilla::MakeUnique<CachedBorderImageData>();
  20. }
  21. }
  22. inline void
  23. nsStyleImage::SetSubImage(uint8_t aIndex, imgIContainer* aSubImage) const
  24. {
  25. EnsureCachedBIData();
  26. mCachedBIData->SetSubImage(aIndex, aSubImage);
  27. }
  28. inline imgIContainer*
  29. nsStyleImage::GetSubImage(uint8_t aIndex) const
  30. {
  31. return (mCachedBIData) ? mCachedBIData->GetSubImage(aIndex) : nullptr;
  32. }
  33. bool
  34. nsStyleText::HasTextShadow() const
  35. {
  36. return mTextShadow;
  37. }
  38. nsCSSShadowArray*
  39. nsStyleText::GetTextShadow() const
  40. {
  41. return mTextShadow;
  42. }
  43. bool
  44. nsStyleText::NewlineIsSignificant(const nsTextFrame* aContextFrame) const
  45. {
  46. NS_ASSERTION(aContextFrame->StyleText() == this, "unexpected aContextFrame");
  47. return NewlineIsSignificantStyle() &&
  48. !aContextFrame->ShouldSuppressLineBreak() &&
  49. !aContextFrame->StyleContext()->IsTextCombined();
  50. }
  51. bool
  52. nsStyleText::WhiteSpaceCanWrap(const nsIFrame* aContextFrame) const
  53. {
  54. NS_ASSERTION(aContextFrame->StyleText() == this, "unexpected aContextFrame");
  55. return WhiteSpaceCanWrapStyle() && !aContextFrame->IsSVGText() &&
  56. !aContextFrame->StyleContext()->IsTextCombined();
  57. }
  58. bool
  59. nsStyleText::WordCanWrap(const nsIFrame* aContextFrame) const
  60. {
  61. NS_ASSERTION(aContextFrame->StyleText() == this, "unexpected aContextFrame");
  62. return WordCanWrapStyle() && !aContextFrame->IsSVGText();
  63. }
  64. bool
  65. nsStyleDisplay::IsBlockInside(const nsIFrame* aContextFrame) const
  66. {
  67. NS_ASSERTION(aContextFrame->StyleDisplay() == this, "unexpected aContextFrame");
  68. if (aContextFrame->IsSVGText()) {
  69. return aContextFrame->GetType() == nsGkAtoms::blockFrame;
  70. }
  71. return IsBlockInsideStyle();
  72. }
  73. bool
  74. nsStyleDisplay::IsBlockOutside(const nsIFrame* aContextFrame) const
  75. {
  76. NS_ASSERTION(aContextFrame->StyleDisplay() == this, "unexpected aContextFrame");
  77. if (aContextFrame->IsSVGText()) {
  78. return aContextFrame->GetType() == nsGkAtoms::blockFrame;
  79. }
  80. return IsBlockOutsideStyle();
  81. }
  82. bool
  83. nsStyleDisplay::IsInlineOutside(const nsIFrame* aContextFrame) const
  84. {
  85. NS_ASSERTION(aContextFrame->StyleDisplay() == this, "unexpected aContextFrame");
  86. if (aContextFrame->IsSVGText()) {
  87. return aContextFrame->GetType() != nsGkAtoms::blockFrame;
  88. }
  89. return IsInlineOutsideStyle();
  90. }
  91. bool
  92. nsStyleDisplay::IsOriginalDisplayInlineOutside(const nsIFrame* aContextFrame) const
  93. {
  94. NS_ASSERTION(aContextFrame->StyleDisplay() == this, "unexpected aContextFrame");
  95. if (aContextFrame->IsSVGText()) {
  96. return aContextFrame->GetType() != nsGkAtoms::blockFrame;
  97. }
  98. return IsOriginalDisplayInlineOutsideStyle();
  99. }
  100. mozilla::StyleDisplay
  101. nsStyleDisplay::GetDisplay(const nsIFrame* aContextFrame) const
  102. {
  103. NS_ASSERTION(aContextFrame->StyleDisplay() == this, "unexpected aContextFrame");
  104. if (aContextFrame->IsSVGText() && mDisplay != mozilla::StyleDisplay::None) {
  105. return aContextFrame->GetType() == nsGkAtoms::blockFrame ?
  106. mozilla::StyleDisplay::Block : mozilla::StyleDisplay::Inline;
  107. }
  108. return mDisplay;
  109. }
  110. bool
  111. nsStyleDisplay::IsFloating(const nsIFrame* aContextFrame) const
  112. {
  113. NS_ASSERTION(aContextFrame->StyleDisplay() == this, "unexpected aContextFrame");
  114. return IsFloatingStyle() && !aContextFrame->IsSVGText();
  115. }
  116. // If you change this function, also change the corresponding block in
  117. // nsCSSFrameConstructor::ConstructFrameFromItemInternal that references
  118. // this function in comments.
  119. bool
  120. nsStyleDisplay::HasTransform(const nsIFrame* aContextFrame) const
  121. {
  122. NS_ASSERTION(aContextFrame->StyleDisplay() == this, "unexpected aContextFrame");
  123. return HasTransformStyle() && aContextFrame->IsFrameOfType(nsIFrame::eSupportsCSSTransforms);
  124. }
  125. template<class StyleContextLike>
  126. bool
  127. nsStyleDisplay::HasFixedPosContainingBlockStyleInternal(
  128. StyleContextLike* aStyleContext) const
  129. {
  130. // NOTE: Any CSS properties that influence the output of this function
  131. // should have the CSS_PROPERTY_FIXPOS_CB set on them.
  132. NS_ASSERTION(aStyleContext->StyleDisplay() == this,
  133. "unexpected aStyleContext");
  134. return IsContainPaint() ||
  135. HasPerspectiveStyle() ||
  136. (mWillChangeBitField & NS_STYLE_WILL_CHANGE_FIXPOS_CB) ||
  137. aStyleContext->StyleEffects()->HasFilters();
  138. }
  139. template<class StyleContextLike>
  140. bool
  141. nsStyleDisplay::IsFixedPosContainingBlockForAppropriateFrame(
  142. StyleContextLike* aStyleContext) const
  143. {
  144. // NOTE: Any CSS properties that influence the output of this function
  145. // should have the CSS_PROPERTY_FIXPOS_CB set on them.
  146. return HasFixedPosContainingBlockStyleInternal(aStyleContext) ||
  147. HasTransformStyle();
  148. }
  149. bool
  150. nsStyleDisplay::IsFixedPosContainingBlock(const nsIFrame* aContextFrame) const
  151. {
  152. // NOTE: Any CSS properties that influence the output of this function
  153. // should have the CSS_PROPERTY_FIXPOS_CB set on them.
  154. if (!HasFixedPosContainingBlockStyleInternal(aContextFrame->StyleContext()) &&
  155. !HasTransform(aContextFrame)) {
  156. return false;
  157. }
  158. return !aContextFrame->IsSVGText();
  159. }
  160. template<class StyleContextLike>
  161. bool
  162. nsStyleDisplay::HasAbsPosContainingBlockStyleInternal(
  163. StyleContextLike* aStyleContext) const
  164. {
  165. // NOTE: Any CSS properties that influence the output of this function
  166. // should have the CSS_PROPERTY_ABSPOS_CB set on them.
  167. NS_ASSERTION(aStyleContext->StyleDisplay() == this,
  168. "unexpected aStyleContext");
  169. return IsAbsolutelyPositionedStyle() ||
  170. IsRelativelyPositionedStyle() ||
  171. (mWillChangeBitField & NS_STYLE_WILL_CHANGE_ABSPOS_CB);
  172. }
  173. template<class StyleContextLike>
  174. bool
  175. nsStyleDisplay::IsAbsPosContainingBlockForAppropriateFrame(StyleContextLike* aStyleContext) const
  176. {
  177. // NOTE: Any CSS properties that influence the output of this function
  178. // should have the CSS_PROPERTY_ABSPOS_CB set on them.
  179. return HasAbsPosContainingBlockStyleInternal(aStyleContext) ||
  180. IsFixedPosContainingBlockForAppropriateFrame(aStyleContext);
  181. }
  182. bool
  183. nsStyleDisplay::IsAbsPosContainingBlock(const nsIFrame* aContextFrame) const
  184. {
  185. // NOTE: Any CSS properties that influence the output of this function
  186. // should have the CSS_PROPERTY_ABSPOS_CB set on them.
  187. nsStyleContext* sc = aContextFrame->StyleContext();
  188. if (!HasAbsPosContainingBlockStyleInternal(sc) &&
  189. !HasFixedPosContainingBlockStyleInternal(sc) &&
  190. !HasTransform(aContextFrame)) {
  191. return false;
  192. }
  193. return !aContextFrame->IsSVGText();
  194. }
  195. bool
  196. nsStyleDisplay::IsRelativelyPositioned(const nsIFrame* aContextFrame) const
  197. {
  198. NS_ASSERTION(aContextFrame->StyleDisplay() == this, "unexpected aContextFrame");
  199. return IsRelativelyPositionedStyle() && !aContextFrame->IsSVGText();
  200. }
  201. bool
  202. nsStyleDisplay::IsAbsolutelyPositioned(const nsIFrame* aContextFrame) const
  203. {
  204. NS_ASSERTION(aContextFrame->StyleDisplay() == this, "unexpected aContextFrame");
  205. return IsAbsolutelyPositionedStyle() && !aContextFrame->IsSVGText();
  206. }
  207. uint8_t
  208. nsStyleUserInterface::GetEffectivePointerEvents(nsIFrame* aFrame) const
  209. {
  210. if (aFrame->GetContent() && !aFrame->GetContent()->GetParent()) {
  211. // The root element has a cluster of frames associated with it
  212. // (root scroll frame, canvas frame, the actual primary frame). Make
  213. // those take their pointer-events value from the root element's primary
  214. // frame.
  215. nsIFrame* f = aFrame->GetContent()->GetPrimaryFrame();
  216. if (f) {
  217. return f->StyleUserInterface()->mPointerEvents;
  218. }
  219. }
  220. return mPointerEvents;
  221. }
  222. bool
  223. nsStyleBackground::HasLocalBackground() const
  224. {
  225. NS_FOR_VISIBLE_IMAGE_LAYERS_BACK_TO_FRONT(i, mImage) {
  226. const nsStyleImageLayers::Layer& layer = mImage.mLayers[i];
  227. if (!layer.mImage.IsEmpty() &&
  228. layer.mAttachment == NS_STYLE_IMAGELAYER_ATTACHMENT_LOCAL) {
  229. return true;
  230. }
  231. }
  232. return false;
  233. }
  234. #endif /* !defined(nsStyleStructInlines_h_) */