ServoStyleSet.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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_ServoStyleSet_h
  6. #define mozilla_ServoStyleSet_h
  7. #include "mozilla/EnumeratedArray.h"
  8. #include "mozilla/EventStates.h"
  9. #include "mozilla/ServoBindingTypes.h"
  10. #include "mozilla/ServoElementSnapshot.h"
  11. #include "mozilla/StyleSheetInlines.h"
  12. #include "mozilla/SheetType.h"
  13. #include "mozilla/UniquePtr.h"
  14. #include "nsCSSPseudoElements.h"
  15. #include "nsChangeHint.h"
  16. #include "nsIAtom.h"
  17. #include "nsTArray.h"
  18. namespace mozilla {
  19. namespace dom {
  20. class Element;
  21. } // namespace dom
  22. class CSSStyleSheet;
  23. class ServoRestyleManager;
  24. class ServoStyleSheet;
  25. } // namespace mozilla
  26. class nsIDocument;
  27. class nsStyleContext;
  28. class nsPresContext;
  29. struct TreeMatchContext;
  30. namespace mozilla {
  31. /**
  32. * The set of style sheets that apply to a document, backed by a Servo
  33. * Stylist. A ServoStyleSet contains ServoStyleSheets.
  34. */
  35. class ServoStyleSet
  36. {
  37. friend class ServoRestyleManager;
  38. public:
  39. ServoStyleSet();
  40. void Init(nsPresContext* aPresContext);
  41. void BeginShutdown();
  42. void Shutdown();
  43. bool GetAuthorStyleDisabled() const;
  44. nsresult SetAuthorStyleDisabled(bool aStyleDisabled);
  45. void BeginUpdate();
  46. nsresult EndUpdate();
  47. already_AddRefed<nsStyleContext>
  48. ResolveStyleFor(dom::Element* aElement,
  49. nsStyleContext* aParentContext);
  50. already_AddRefed<nsStyleContext>
  51. ResolveStyleFor(dom::Element* aElement,
  52. nsStyleContext* aParentContext,
  53. TreeMatchContext& aTreeMatchContext);
  54. already_AddRefed<nsStyleContext>
  55. ResolveStyleForText(nsIContent* aTextNode,
  56. nsStyleContext* aParentContext);
  57. already_AddRefed<nsStyleContext>
  58. ResolveStyleForOtherNonElement(nsStyleContext* aParentContext);
  59. already_AddRefed<nsStyleContext>
  60. ResolvePseudoElementStyle(dom::Element* aParentElement,
  61. mozilla::CSSPseudoElementType aType,
  62. nsStyleContext* aParentContext,
  63. dom::Element* aPseudoElement);
  64. // aFlags is an nsStyleSet flags bitfield
  65. already_AddRefed<nsStyleContext>
  66. ResolveAnonymousBoxStyle(nsIAtom* aPseudoTag, nsStyleContext* aParentContext,
  67. uint32_t aFlags = 0);
  68. // manage the set of style sheets in the style set
  69. nsresult AppendStyleSheet(SheetType aType, ServoStyleSheet* aSheet);
  70. nsresult PrependStyleSheet(SheetType aType, ServoStyleSheet* aSheet);
  71. nsresult RemoveStyleSheet(SheetType aType, ServoStyleSheet* aSheet);
  72. nsresult ReplaceSheets(SheetType aType,
  73. const nsTArray<RefPtr<ServoStyleSheet>>& aNewSheets);
  74. nsresult InsertStyleSheetBefore(SheetType aType,
  75. ServoStyleSheet* aNewSheet,
  76. ServoStyleSheet* aReferenceSheet);
  77. int32_t SheetCount(SheetType aType) const;
  78. ServoStyleSheet* StyleSheetAt(SheetType aType, int32_t aIndex) const;
  79. nsresult RemoveDocStyleSheet(ServoStyleSheet* aSheet);
  80. nsresult AddDocStyleSheet(ServoStyleSheet* aSheet, nsIDocument* aDocument);
  81. // check whether there is ::before/::after style for an element
  82. already_AddRefed<nsStyleContext>
  83. ProbePseudoElementStyle(dom::Element* aParentElement,
  84. mozilla::CSSPseudoElementType aType,
  85. nsStyleContext* aParentContext);
  86. already_AddRefed<nsStyleContext>
  87. ProbePseudoElementStyle(dom::Element* aParentElement,
  88. mozilla::CSSPseudoElementType aType,
  89. nsStyleContext* aParentContext,
  90. TreeMatchContext& aTreeMatchContext,
  91. dom::Element* aPseudoElement = nullptr);
  92. // Test if style is dependent on content state
  93. nsRestyleHint HasStateDependentStyle(dom::Element* aElement,
  94. EventStates aStateMask);
  95. nsRestyleHint HasStateDependentStyle(
  96. dom::Element* aElement, mozilla::CSSPseudoElementType aPseudoType,
  97. dom::Element* aPseudoElement, EventStates aStateMask);
  98. /**
  99. * Computes a restyle hint given a element and a previous element snapshot.
  100. */
  101. nsRestyleHint ComputeRestyleHint(dom::Element* aElement,
  102. ServoElementSnapshot* aSnapshot);
  103. /**
  104. * Performs a Servo traversal to compute style for all dirty nodes in the
  105. * document. The root element must be non-null.
  106. *
  107. * If aLeaveDirtyBits is true, the dirty/dirty-descendant bits are not
  108. * cleared.
  109. */
  110. void StyleDocument(bool aLeaveDirtyBits);
  111. /**
  112. * Eagerly styles a subtree of dirty nodes that were just appended to the
  113. * tree. This is used in situations where we need the style immediately and
  114. * cannot wait for a future batch restyle.
  115. *
  116. * The subtree must have the root dirty bit set, which currently gets
  117. * propagated to all descendants. The dirty bits are cleared before
  118. * returning.
  119. */
  120. void StyleNewSubtree(nsIContent* aContent);
  121. /**
  122. * Like the above, but does not assume that the root node is dirty. When
  123. * appending multiple children to a potentially-non-dirty node, it's
  124. * preferable to call StyleNewChildren on the node rather than making multiple
  125. * calls to StyleNewSubtree on each child, since it allows for more
  126. * parallelism.
  127. */
  128. void StyleNewChildren(nsIContent* aParent);
  129. private:
  130. already_AddRefed<nsStyleContext> GetContext(already_AddRefed<ServoComputedValues>,
  131. nsStyleContext* aParentContext,
  132. nsIAtom* aPseudoTag,
  133. CSSPseudoElementType aPseudoType);
  134. already_AddRefed<nsStyleContext> GetContext(nsIContent* aContent,
  135. nsStyleContext* aParentContext,
  136. nsIAtom* aPseudoTag,
  137. CSSPseudoElementType aPseudoType);
  138. nsPresContext* mPresContext;
  139. UniquePtr<RawServoStyleSet> mRawSet;
  140. EnumeratedArray<SheetType, SheetType::Count,
  141. nsTArray<RefPtr<ServoStyleSheet>>> mSheets;
  142. int32_t mBatching;
  143. };
  144. } // namespace mozilla
  145. #endif // mozilla_ServoStyleSet_h