2017-03-09 09:37:38 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "mozilla/dom/CSSMediaRule.h"
|
|
|
|
|
|
|
|
#include "mozilla/dom/CSSMediaRuleBinding.h"
|
|
|
|
#include "mozilla/dom/MediaList.h"
|
2018-08-02 00:52:07 +03:00
|
|
|
#include "mozilla/ServoBindings.h"
|
2017-03-09 09:37:38 +03:00
|
|
|
|
2021-09-08 14:18:32 +03:00
|
|
|
namespace mozilla::dom {
|
2017-03-09 09:37:38 +03:00
|
|
|
|
2018-06-04 15:14:47 +03:00
|
|
|
CSSMediaRule::CSSMediaRule(RefPtr<RawServoMediaRule> aRawRule,
|
2018-06-29 05:56:09 +03:00
|
|
|
StyleSheet* aSheet, css::Rule* aParentRule,
|
|
|
|
uint32_t aLine, uint32_t aColumn)
|
|
|
|
: ConditionRule(Servo_MediaRule_GetRules(aRawRule).Consume(), aSheet,
|
|
|
|
aParentRule, aLine, aColumn),
|
2018-06-04 15:14:47 +03:00
|
|
|
mRawRule(std::move(aRawRule)) {}
|
|
|
|
|
|
|
|
CSSMediaRule::~CSSMediaRule() {
|
|
|
|
if (mMediaList) {
|
|
|
|
mMediaList->SetStyleSheet(nullptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF_INHERITED(CSSMediaRule, css::ConditionRule)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(CSSMediaRule, css::ConditionRule)
|
|
|
|
|
|
|
|
// QueryInterface implementation for MediaRule
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(CSSMediaRule)
|
|
|
|
NS_INTERFACE_MAP_END_INHERITING(css::ConditionRule)
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(CSSMediaRule)
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(CSSMediaRule,
|
|
|
|
css::ConditionRule)
|
|
|
|
if (tmp->mMediaList) {
|
|
|
|
tmp->mMediaList->SetStyleSheet(nullptr);
|
|
|
|
tmp->mMediaList = nullptr;
|
|
|
|
}
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(CSSMediaRule,
|
|
|
|
css::ConditionRule)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mMediaList)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
2019-02-26 01:09:24 +03:00
|
|
|
/* virtual */
|
|
|
|
void CSSMediaRule::DropSheetReference() {
|
2018-06-04 15:14:47 +03:00
|
|
|
if (mMediaList) {
|
2018-06-29 05:56:09 +03:00
|
|
|
mMediaList->SetStyleSheet(nullptr);
|
2018-06-04 15:14:47 +03:00
|
|
|
}
|
2018-06-29 05:56:09 +03:00
|
|
|
ConditionRule::DropSheetReference();
|
2018-06-04 15:14:47 +03:00
|
|
|
}
|
|
|
|
|
2021-07-20 16:17:02 +03:00
|
|
|
void CSSMediaRule::SetRawAfterClone(RefPtr<RawServoMediaRule> aRaw) {
|
|
|
|
mRawRule = std::move(aRaw);
|
|
|
|
if (mMediaList) {
|
|
|
|
mMediaList->SetRawAfterClone(Servo_MediaRule_GetMedia(mRawRule).Consume());
|
|
|
|
mMediaList->SetStyleSheet(nullptr);
|
|
|
|
mMediaList->SetStyleSheet(GetStyleSheet());
|
|
|
|
}
|
|
|
|
css::ConditionRule::SetRawAfterClone(
|
|
|
|
Servo_MediaRule_GetRules(mRawRule).Consume());
|
|
|
|
}
|
|
|
|
|
2021-09-08 14:18:32 +03:00
|
|
|
StyleCssRuleType CSSMediaRule::Type() const { return StyleCssRuleType::Media; }
|
|
|
|
|
2018-06-04 15:14:47 +03:00
|
|
|
#ifdef DEBUG
|
2019-02-26 01:09:24 +03:00
|
|
|
/* virtual */
|
|
|
|
void CSSMediaRule::List(FILE* out, int32_t aIndent) const {
|
2018-06-04 15:14:47 +03:00
|
|
|
nsAutoCString str;
|
|
|
|
for (int32_t i = 0; i < aIndent; i++) {
|
|
|
|
str.AppendLiteral(" ");
|
|
|
|
}
|
|
|
|
Servo_MediaRule_Debug(mRawRule, &str);
|
|
|
|
fprintf_stderr(out, "%s\n", str.get());
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-12-17 17:04:35 +03:00
|
|
|
void CSSMediaRule::GetConditionText(nsACString& aConditionText) {
|
2018-06-04 15:14:47 +03:00
|
|
|
Media()->GetMediaText(aConditionText);
|
|
|
|
}
|
|
|
|
|
2020-12-17 17:04:35 +03:00
|
|
|
void CSSMediaRule::SetConditionText(const nsACString& aConditionText,
|
2018-06-04 15:14:47 +03:00
|
|
|
ErrorResult& aRv) {
|
2019-04-29 08:34:06 +03:00
|
|
|
if (IsReadOnly()) {
|
|
|
|
return;
|
|
|
|
}
|
2018-06-04 15:14:47 +03:00
|
|
|
Media()->SetMediaText(aConditionText);
|
|
|
|
}
|
|
|
|
|
2019-02-26 01:09:24 +03:00
|
|
|
/* virtual */
|
2020-12-17 17:04:35 +03:00
|
|
|
void CSSMediaRule::GetCssText(nsACString& aCssText) const {
|
2018-06-04 15:14:47 +03:00
|
|
|
Servo_MediaRule_GetCssText(mRawRule, &aCssText);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ dom::MediaList* CSSMediaRule::Media() {
|
|
|
|
if (!mMediaList) {
|
|
|
|
mMediaList = new MediaList(Servo_MediaRule_GetMedia(mRawRule).Consume());
|
|
|
|
mMediaList->SetStyleSheet(GetStyleSheet());
|
|
|
|
}
|
|
|
|
return mMediaList;
|
|
|
|
}
|
|
|
|
|
2019-02-26 01:09:24 +03:00
|
|
|
/* virtual */
|
2019-11-30 14:57:10 +03:00
|
|
|
size_t CSSMediaRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const {
|
2018-06-04 15:14:47 +03:00
|
|
|
// TODO Implement this!
|
|
|
|
return aMallocSizeOf(this);
|
|
|
|
}
|
|
|
|
|
2019-02-26 01:09:24 +03:00
|
|
|
/* virtual */
|
|
|
|
JSObject* CSSMediaRule::WrapObject(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) {
|
2018-06-26 00:20:54 +03:00
|
|
|
return CSSMediaRule_Binding::Wrap(aCx, this, aGivenProto);
|
2017-03-09 09:37:38 +03:00
|
|
|
}
|
|
|
|
|
2021-09-08 14:18:32 +03:00
|
|
|
} // namespace mozilla::dom
|