Bug 1637593 [wpt PR 23564] - Fix superclass calls in MarionetteRefTestExecutor, a...
[gecko.git] / layout / style / CSSImportRule.cpp
blob28bc7f19e56dbb865d8de46ba90ab7366f27f1a9
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 #include "mozilla/dom/CSSImportRule.h"
9 #include "mozilla/dom/CSSImportRuleBinding.h"
10 #include "mozilla/dom/MediaList.h"
11 #include "mozilla/ServoBindings.h"
12 #include "mozilla/StyleSheet.h"
14 namespace mozilla {
15 namespace dom {
17 CSSImportRule::CSSImportRule(RefPtr<RawServoImportRule> aRawRule,
18 StyleSheet* aSheet, css::Rule* aParentRule,
19 uint32_t aLine, uint32_t aColumn)
20 : css::Rule(aSheet, aParentRule, aLine, aColumn),
21 mRawRule(std::move(aRawRule)) {
22 const auto* sheet = Servo_ImportRule_GetSheet(mRawRule.get());
23 MOZ_ASSERT(sheet);
24 mChildSheet = const_cast<StyleSheet*>(sheet);
25 mChildSheet->SetOwnerRule(this);
28 CSSImportRule::~CSSImportRule() {
29 if (mChildSheet) {
30 mChildSheet->SetOwnerRule(nullptr);
34 // QueryInterface implementation for CSSImportRule
35 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(CSSImportRule)
36 NS_INTERFACE_MAP_END_INHERITING(css::Rule)
38 NS_IMPL_CYCLE_COLLECTION_CLASS(CSSImportRule)
40 NS_IMPL_ADDREF_INHERITED(CSSImportRule, css::Rule)
41 NS_IMPL_RELEASE_INHERITED(CSSImportRule, css::Rule)
43 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(CSSImportRule, css::Rule)
44 // Note the child sheet twice, since the Servo rule also holds a strong
45 // reference to it.
46 NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mChildSheet");
47 cb.NoteXPCOMChild(tmp->mChildSheet);
48 MOZ_ASSERT_IF(tmp->mRawRule,
49 Servo_ImportRule_GetSheet(tmp->mRawRule) == tmp->mChildSheet);
50 cb.NoteXPCOMChild(tmp->mChildSheet);
51 NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mRawRule.stylesheet");
52 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
54 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(CSSImportRule)
55 if (tmp->mChildSheet) {
56 tmp->mChildSheet->SetOwnerRule(nullptr);
57 tmp->mChildSheet = nullptr;
59 tmp->mRawRule = nullptr;
60 NS_IMPL_CYCLE_COLLECTION_UNLINK_END_INHERITED(css::Rule)
62 #ifdef DEBUG
63 /* virtual */
64 void CSSImportRule::List(FILE* out, int32_t aIndent) const {
65 nsAutoCString str;
66 for (int32_t i = 0; i < aIndent; i++) {
67 str.AppendLiteral(" ");
69 Servo_ImportRule_Debug(mRawRule, &str);
70 fprintf_stderr(out, "%s\n", str.get());
72 #endif
74 dom::MediaList* CSSImportRule::GetMedia() const {
75 // When Bug 1326509 is fixed, we can assert mChildSheet instead.
76 return mChildSheet ? mChildSheet->Media() : nullptr;
79 void CSSImportRule::DropSheetReference() {
80 if (mChildSheet) {
81 mChildSheet->RemoveFromParent();
83 Rule::DropSheetReference();
86 void CSSImportRule::GetHref(nsAString& aHref) const {
87 Servo_ImportRule_GetHref(mRawRule, &aHref);
90 /* virtual */
91 void CSSImportRule::GetCssText(nsAString& aCssText) const {
92 Servo_ImportRule_GetCssText(mRawRule, &aCssText);
95 /* virtual */
96 size_t CSSImportRule::SizeOfIncludingThis(
97 mozilla::MallocSizeOf aMallocSizeOf) const {
98 // TODO Implement this!
99 return aMallocSizeOf(this);
102 bool CSSImportRule::IsCCLeaf() const {
103 // We're not a leaf.
104 return false;
107 /* virtual */
108 JSObject* CSSImportRule::WrapObject(JSContext* aCx,
109 JS::Handle<JSObject*> aGivenProto) {
110 return CSSImportRule_Binding::Wrap(aCx, this, aGivenProto);
113 } // namespace dom
114 } // namespace mozilla