Bug 1822393 - consistently use getGeckoViewDependency() in browser-engine-gecko....
[gecko.git] / layout / style / CSSMediaRule.cpp
blob75b4ce4571be85f9b9e974ab961716201b904044
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/CSSMediaRule.h"
9 #include "mozilla/dom/CSSMediaRuleBinding.h"
10 #include "mozilla/dom/MediaList.h"
11 #include "mozilla/ServoBindings.h"
13 namespace mozilla::dom {
15 CSSMediaRule::CSSMediaRule(RefPtr<StyleMediaRule> aRawRule, StyleSheet* aSheet,
16 css::Rule* aParentRule, uint32_t aLine,
17 uint32_t aColumn)
18 : ConditionRule(aSheet, aParentRule, aLine, aColumn),
19 mRawRule(std::move(aRawRule)) {}
21 CSSMediaRule::~CSSMediaRule() {
22 if (mMediaList) {
23 mMediaList->SetStyleSheet(nullptr);
27 NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED_0(CSSMediaRule, css::ConditionRule)
29 NS_IMPL_CYCLE_COLLECTION_CLASS(CSSMediaRule)
31 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(CSSMediaRule,
32 css::ConditionRule)
33 if (tmp->mMediaList) {
34 tmp->mMediaList->SetStyleSheet(nullptr);
35 tmp->mMediaList = nullptr;
37 NS_IMPL_CYCLE_COLLECTION_UNLINK_END
39 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(CSSMediaRule,
40 css::ConditionRule)
41 NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mMediaList)
42 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
44 bool CSSMediaRule::IsCCLeaf() const {
45 return ConditionRule::IsCCLeaf() && !mMediaList;
48 /* virtual */
49 void CSSMediaRule::DropSheetReference() {
50 if (mMediaList) {
51 mMediaList->SetStyleSheet(nullptr);
53 ConditionRule::DropSheetReference();
56 void CSSMediaRule::SetRawAfterClone(RefPtr<StyleMediaRule> aRaw) {
57 mRawRule = std::move(aRaw);
58 if (mMediaList) {
59 mMediaList->SetRawAfterClone(Servo_MediaRule_GetMedia(mRawRule).Consume());
60 mMediaList->SetStyleSheet(nullptr);
61 mMediaList->SetStyleSheet(GetStyleSheet());
63 css::ConditionRule::DidSetRawAfterClone();
66 already_AddRefed<StyleLockedCssRules> CSSMediaRule::GetOrCreateRawRules() {
67 return Servo_MediaRule_GetRules(mRawRule).Consume();
70 StyleCssRuleType CSSMediaRule::Type() const { return StyleCssRuleType::Media; }
72 #ifdef DEBUG
73 /* virtual */
74 void CSSMediaRule::List(FILE* out, int32_t aIndent) const {
75 nsAutoCString str;
76 for (int32_t i = 0; i < aIndent; i++) {
77 str.AppendLiteral(" ");
79 Servo_MediaRule_Debug(mRawRule, &str);
80 fprintf_stderr(out, "%s\n", str.get());
82 #endif
84 void CSSMediaRule::GetConditionText(nsACString& aConditionText) {
85 Media()->GetMediaText(aConditionText);
88 /* virtual */
89 void CSSMediaRule::GetCssText(nsACString& aCssText) const {
90 Servo_MediaRule_GetCssText(mRawRule, &aCssText);
93 /* virtual */ dom::MediaList* CSSMediaRule::Media() {
94 if (!mMediaList) {
95 mMediaList = new MediaList(Servo_MediaRule_GetMedia(mRawRule).Consume());
96 mMediaList->SetStyleSheet(GetStyleSheet());
98 return mMediaList;
101 /* virtual */
102 size_t CSSMediaRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const {
103 // TODO Implement this!
104 return aMallocSizeOf(this);
107 /* virtual */
108 JSObject* CSSMediaRule::WrapObject(JSContext* aCx,
109 JS::Handle<JSObject*> aGivenProto) {
110 return CSSMediaRule_Binding::Wrap(aCx, this, aGivenProto);
113 } // namespace mozilla::dom