1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 /* representation of CSSRuleList for stylo */
9 #ifndef mozilla_ServoCSSRuleList_h
10 #define mozilla_ServoCSSRuleList_h
12 #include "mozilla/ServoBindingTypes.h"
13 #include "mozilla/dom/CSSRuleList.h"
26 class ServoCSSRuleList final
: public dom::CSSRuleList
{
28 ServoCSSRuleList(already_AddRefed
<StyleLockedCssRules
> aRawRules
,
29 StyleSheet
* aSheet
, css::GroupRule
* aParentRule
);
30 css::GroupRule
* GetParentRule() const { return mParentRule
; }
31 void DropSheetReference();
32 void DropParentRuleReference();
34 void DropReferences() {
36 DropParentRuleReference();
39 NS_DECL_ISUPPORTS_INHERITED
40 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ServoCSSRuleList
, dom::CSSRuleList
)
42 StyleSheet
* GetParentObject() final
{ return mStyleSheet
; }
44 css::Rule
* IndexedGetter(uint32_t aIndex
, bool& aFound
) final
;
45 uint32_t Length() final
{ return mRules
.Length(); }
47 css::Rule
* GetRule(uint32_t aIndex
);
48 nsresult
InsertRule(const nsACString
& aRule
, uint32_t aIndex
);
49 nsresult
DeleteRule(uint32_t aIndex
);
51 // aFromClone says whether this comes from a clone of the stylesheet (and thus
52 // we should also fix up the wrappers for the individual rules in the rule
54 void SetRawContents(RefPtr
<StyleLockedCssRules
>, bool aFromClone
);
55 void SetRawAfterClone(RefPtr
<StyleLockedCssRules
> aRules
) {
56 SetRawContents(std::move(aRules
), /* aFromClone = */ true);
60 virtual ~ServoCSSRuleList();
62 // XXX Is it possible to have an address lower than or equal to 255?
63 // Is it possible to have more than 255 CSS rule types?
64 static const uintptr_t kMaxRuleType
= UINT8_MAX
;
66 static uintptr_t CastToUint(css::Rule
* aPtr
) {
67 return reinterpret_cast<uintptr_t>(aPtr
);
69 static css::Rule
* CastToPtr(uintptr_t aInt
) {
70 MOZ_ASSERT(aInt
> kMaxRuleType
);
71 return reinterpret_cast<css::Rule
*>(aInt
);
74 template <typename Func
>
75 void EnumerateInstantiatedRules(Func aCallback
);
80 bool IsReadOnly() const;
82 // mStyleSheet may be nullptr when it drops the reference to us.
83 StyleSheet
* mStyleSheet
= nullptr;
84 // mParentRule is nullptr if it isn't a nested rule list.
85 css::GroupRule
* mParentRule
= nullptr;
86 RefPtr
<StyleLockedCssRules
> mRawRules
;
87 // Array stores either a number indicating rule type, or a pointer to
88 // css::Rule. If the value is less than kMaxRuleType, the given rule
89 // instance has not been constructed, and the value means the type
90 // of the rule. Otherwise, it is a pointer.
91 nsTArray
<uintptr_t> mRules
;
94 } // namespace mozilla
96 #endif // mozilla_ServoCSSRuleList_h