Bug 1692937 [wpt PR 27636] - new parameter --include-file for wptrunner, a=testonly
[gecko.git] / layout / style / ServoCSSRuleList.h
blobbc27b4c8b9ab66f687a12b2d418df6072b7187d3
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"
15 namespace mozilla {
17 namespace dom {
18 class CSSStyleRule;
19 } // namespace dom
20 class StyleSheet;
21 namespace css {
22 class GroupRule;
23 class Rule;
24 } // namespace css
26 class ServoCSSRuleList final : public dom::CSSRuleList {
27 public:
28 ServoCSSRuleList(already_AddRefed<ServoCssRules> aRawRules,
29 StyleSheet* aSheet, css::GroupRule* aParentRule);
30 css::GroupRule* GetParentRule() const { return mParentRule; }
31 void DropSheetReference();
32 void DropParentRuleReference();
34 void DropReferences() {
35 DropSheetReference();
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 uint16_t GetDOMCSSRuleType(uint32_t aIndex) const;
53 private:
54 virtual ~ServoCSSRuleList();
56 // XXX Is it possible to have an address lower than or equal to 255?
57 // Is it possible to have more than 255 CSS rule types?
58 static const uintptr_t kMaxRuleType = UINT8_MAX;
60 static uintptr_t CastToUint(css::Rule* aPtr) {
61 return reinterpret_cast<uintptr_t>(aPtr);
63 static css::Rule* CastToPtr(uintptr_t aInt) {
64 MOZ_ASSERT(aInt > kMaxRuleType);
65 return reinterpret_cast<css::Rule*>(aInt);
68 template <typename Func>
69 void EnumerateInstantiatedRules(Func aCallback);
71 void DropAllRules();
73 bool IsReadOnly() const;
75 // mStyleSheet may be nullptr when it drops the reference to us.
76 StyleSheet* mStyleSheet = nullptr;
77 // mParentRule is nullptr if it isn't a nested rule list.
78 css::GroupRule* mParentRule = nullptr;
79 RefPtr<ServoCssRules> mRawRules;
80 // Array stores either a number indicating rule type, or a pointer to
81 // css::Rule. If the value is less than kMaxRuleType, the given rule
82 // instance has not been constructed, and the value means the type
83 // of the rule. Otherwise, it is a pointer.
84 nsTArray<uintptr_t> mRules;
87 } // namespace mozilla
89 #endif // mozilla_ServoCSSRuleList_h