2017-04-01 03:14:49 +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/CSSPageRule.h"
|
|
|
|
#include "mozilla/dom/CSSPageRuleBinding.h"
|
|
|
|
|
2018-06-05 14:39:42 +03:00
|
|
|
#include "mozilla/DeclarationBlock.h"
|
|
|
|
#include "mozilla/ServoBindings.h"
|
|
|
|
|
2017-04-01 03:14:49 +03:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2018-06-05 14:39:42 +03:00
|
|
|
// -- CSSPageRuleDeclaration ---------------------------------------
|
|
|
|
|
|
|
|
CSSPageRuleDeclaration::CSSPageRuleDeclaration(
|
|
|
|
already_AddRefed<RawServoDeclarationBlock> aDecls)
|
2021-07-14 00:36:05 +03:00
|
|
|
: mDecls(new DeclarationBlock(std::move(aDecls))) {}
|
2018-06-05 14:39:42 +03:00
|
|
|
|
|
|
|
CSSPageRuleDeclaration::~CSSPageRuleDeclaration() {
|
|
|
|
mDecls->SetOwningRule(nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
// QueryInterface implementation for CSSPageRuleDeclaration
|
|
|
|
NS_INTERFACE_MAP_BEGIN(CSSPageRuleDeclaration)
|
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
|
|
|
// We forward the cycle collection interfaces to Rule(), which is
|
|
|
|
// never null (in fact, we're part of that object!)
|
|
|
|
if (aIID.Equals(NS_GET_IID(nsCycleCollectionISupports)) ||
|
|
|
|
aIID.Equals(NS_GET_IID(nsXPCOMCycleCollectionParticipant))) {
|
|
|
|
return Rule()->QueryInterface(aIID, aInstancePtr);
|
|
|
|
}
|
|
|
|
NS_INTERFACE_MAP_END_INHERITING(nsDOMCSSDeclaration)
|
|
|
|
|
2018-12-20 22:33:09 +03:00
|
|
|
NS_IMPL_ADDREF_USING_AGGREGATOR(CSSPageRuleDeclaration, Rule())
|
|
|
|
NS_IMPL_RELEASE_USING_AGGREGATOR(CSSPageRuleDeclaration, Rule())
|
2018-06-05 14:39:42 +03:00
|
|
|
|
2018-12-20 22:33:09 +03:00
|
|
|
/* nsDOMCSSDeclaration implementation */
|
2018-06-05 14:39:42 +03:00
|
|
|
|
2018-12-20 22:33:09 +03:00
|
|
|
css::Rule* CSSPageRuleDeclaration::GetParentRule() { return Rule(); }
|
2018-06-05 14:39:42 +03:00
|
|
|
|
2021-03-23 00:15:34 +03:00
|
|
|
nsINode* CSSPageRuleDeclaration::GetAssociatedNode() const {
|
|
|
|
return Rule()->GetAssociatedDocumentOrShadowRoot();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsISupports* CSSPageRuleDeclaration::GetParentObject() const {
|
2018-12-20 22:33:09 +03:00
|
|
|
return Rule()->GetParentObject();
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-12-20 22:33:09 +03:00
|
|
|
DeclarationBlock* CSSPageRuleDeclaration::GetOrCreateCSSDeclaration(
|
|
|
|
Operation aOperation, DeclarationBlock** aCreated) {
|
|
|
|
return mDecls;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-12-20 22:33:09 +03:00
|
|
|
nsresult CSSPageRuleDeclaration::SetCSSDeclaration(
|
|
|
|
DeclarationBlock* aDecl, MutationClosureData* aClosureData) {
|
|
|
|
MOZ_ASSERT(aDecl, "must be non-null");
|
|
|
|
CSSPageRule* rule = Rule();
|
|
|
|
|
2021-07-14 00:36:05 +03:00
|
|
|
if (rule->IsReadOnly()) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2018-12-20 22:33:09 +03:00
|
|
|
if (aDecl != mDecls) {
|
|
|
|
mDecls->SetOwningRule(nullptr);
|
|
|
|
RefPtr<DeclarationBlock> decls = aDecl;
|
|
|
|
Servo_PageRule_SetStyle(rule->Raw(), decls->Raw());
|
2020-02-13 17:38:48 +03:00
|
|
|
mDecls = std::move(decls);
|
2018-12-20 22:33:09 +03:00
|
|
|
mDecls->SetOwningRule(rule);
|
2018-06-05 14:39:42 +03:00
|
|
|
}
|
|
|
|
|
2018-12-20 22:33:09 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2018-06-05 14:39:42 +03:00
|
|
|
|
2018-12-20 22:33:09 +03:00
|
|
|
nsDOMCSSDeclaration::ParsingEnvironment
|
|
|
|
CSSPageRuleDeclaration::GetParsingEnvironment(
|
|
|
|
nsIPrincipal* aSubjectPrincipal) const {
|
2020-09-21 12:57:46 +03:00
|
|
|
return GetParsingEnvironmentForRule(Rule(), CSSRule_Binding::PAGE_RULE);
|
2018-12-20 22:33:09 +03:00
|
|
|
}
|
2018-06-05 14:39:42 +03:00
|
|
|
|
2018-12-20 22:33:09 +03:00
|
|
|
// -- CSSPageRule --------------------------------------------------
|
2018-06-05 14:39:42 +03:00
|
|
|
|
2018-12-20 22:33:09 +03:00
|
|
|
CSSPageRule::CSSPageRule(RefPtr<RawServoPageRule> aRawRule, StyleSheet* aSheet,
|
|
|
|
css::Rule* aParentRule, uint32_t aLine,
|
|
|
|
uint32_t aColumn)
|
|
|
|
: css::Rule(aSheet, aParentRule, aLine, aColumn),
|
|
|
|
mRawRule(std::move(aRawRule)),
|
|
|
|
mDecls(Servo_PageRule_GetStyle(mRawRule).Consume()) {}
|
2018-06-05 14:39:42 +03:00
|
|
|
|
2018-12-20 22:33:09 +03:00
|
|
|
NS_IMPL_ADDREF_INHERITED(CSSPageRule, css::Rule)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(CSSPageRule, css::Rule)
|
2018-06-05 14:39:42 +03:00
|
|
|
|
2018-12-20 22:33:09 +03:00
|
|
|
// QueryInterface implementation for PageRule
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(CSSPageRule)
|
|
|
|
NS_INTERFACE_MAP_END_INHERITING(css::Rule)
|
2018-06-05 14:39:42 +03:00
|
|
|
|
2018-12-20 22:33:09 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(CSSPageRule)
|
2018-06-05 14:39:42 +03:00
|
|
|
|
2018-12-20 22:33:09 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(CSSPageRule, css::Rule)
|
|
|
|
// Keep this in sync with IsCCLeaf.
|
2018-06-05 14:39:42 +03:00
|
|
|
|
2018-12-20 22:33:09 +03:00
|
|
|
// Trace the wrapper for our declaration. This just expands out
|
|
|
|
// NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER which we can't use
|
|
|
|
// directly because the wrapper is on the declaration, not on us.
|
|
|
|
tmp->mDecls.TraceWrapper(aCallbacks, aClosure);
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_END
|
2018-06-05 14:39:42 +03:00
|
|
|
|
2019-07-22 21:33:29 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(CSSPageRule)
|
2018-12-20 22:33:09 +03:00
|
|
|
// Keep this in sync with IsCCLeaf.
|
2018-06-05 14:39:42 +03:00
|
|
|
|
2019-07-22 22:27:28 +03:00
|
|
|
// Unlink the wrapper for our declaration.
|
2019-07-22 21:33:29 +03:00
|
|
|
//
|
|
|
|
// Note that this has to happen before unlinking css::Rule.
|
|
|
|
tmp->UnlinkDeclarationWrapper(tmp->mDecls);
|
2018-12-20 22:33:09 +03:00
|
|
|
tmp->mDecls.mDecls->SetOwningRule(nullptr);
|
2019-07-22 21:33:29 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END_INHERITED(css::Rule)
|
2018-06-05 14:39:42 +03:00
|
|
|
|
2018-12-20 22:33:09 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(CSSPageRule, css::Rule)
|
|
|
|
// Keep this in sync with IsCCLeaf.
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
2018-06-05 14:39:42 +03:00
|
|
|
|
2018-12-20 22:33:09 +03:00
|
|
|
bool CSSPageRule::IsCCLeaf() const {
|
|
|
|
if (!Rule::IsCCLeaf()) {
|
|
|
|
return false;
|
2018-06-05 14:39:42 +03:00
|
|
|
}
|
|
|
|
|
2018-12-20 22:33:09 +03:00
|
|
|
return !mDecls.PreservingWrapper();
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t CSSPageRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const {
|
|
|
|
// TODO Implement this!
|
|
|
|
return aMallocSizeOf(this);
|
|
|
|
}
|
2018-06-05 14:39:42 +03:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2018-12-20 22:33:09 +03:00
|
|
|
void CSSPageRule::List(FILE* out, int32_t aIndent) const {
|
|
|
|
nsAutoCString str;
|
|
|
|
for (int32_t i = 0; i < aIndent; i++) {
|
|
|
|
str.AppendLiteral(" ");
|
2018-06-05 14:39:42 +03:00
|
|
|
}
|
2018-12-20 22:33:09 +03:00
|
|
|
Servo_PageRule_Debug(mRawRule, &str);
|
|
|
|
fprintf_stderr(out, "%s\n", str.get());
|
|
|
|
}
|
2018-06-05 14:39:42 +03:00
|
|
|
#endif
|
|
|
|
|
2018-12-20 22:33:09 +03:00
|
|
|
/* CSSRule implementation */
|
2018-06-05 14:39:42 +03:00
|
|
|
|
2020-12-17 17:04:35 +03:00
|
|
|
void CSSPageRule::GetCssText(nsACString& aCssText) const {
|
2018-12-20 22:33:09 +03:00
|
|
|
Servo_PageRule_GetCssText(mRawRule, &aCssText);
|
|
|
|
}
|
2018-06-05 14:39:42 +03:00
|
|
|
|
2018-12-20 22:33:09 +03:00
|
|
|
/* CSSPageRule implementation */
|
2018-06-05 14:39:42 +03:00
|
|
|
|
2018-12-20 22:33:09 +03:00
|
|
|
nsICSSDeclaration* CSSPageRule::Style() { return &mDecls; }
|
2018-06-05 14:39:42 +03:00
|
|
|
|
2018-12-20 22:33:09 +03:00
|
|
|
JSObject* CSSPageRule::WrapObject(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) {
|
|
|
|
return CSSPageRule_Binding::Wrap(aCx, this, aGivenProto);
|
|
|
|
}
|
2017-04-01 03:14:49 +03:00
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|