Bug 1345206 - Extract CSSPageRule base class. r=xidorn
Extract a `CSSPageRule` base class from the existing Gecko `nsCSSPageRule`
class. This will be used in the next commit as the parent of a new
`ServoPageRule` for the Servo variant.
MozReview-Commit-ID: 1F3FWfVKH29
--- a/dom/bindings/Bindings.conf
+++ b/dom/bindings/Bindings.conf
@@ -236,21 +236,16 @@ DOMInterfaces = {
'wrapperCache': False
},
'CSSMozDocumentRule': {
'nativeType': 'mozilla::css::DocumentRule',
'headerFile': 'nsCSSRules.h',
},
-'CSSPageRule': {
- 'nativeType': 'nsCSSPageRule',
- 'headerFile': 'nsCSSRules.h',
-},
-
'CSSPrimitiveValue': {
'nativeType': 'nsROCSSPrimitiveValue',
},
'CSSRule': {
'concrete': False,
'nativeType': 'mozilla::css::Rule'
},
new file mode 100644
--- /dev/null
+++ b/layout/style/CSSPageRule.cpp
@@ -0,0 +1,36 @@
+/* -*- 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"
+
+namespace mozilla {
+namespace dom {
+
+NS_IMPL_ADDREF_INHERITED(CSSPageRule, css::Rule)
+NS_IMPL_RELEASE_INHERITED(CSSPageRule, css::Rule)
+
+// QueryInterface implementation for CSSPageRule
+NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(CSSPageRule)
+ NS_INTERFACE_MAP_ENTRY(nsIDOMCSSPageRule)
+NS_INTERFACE_MAP_END_INHERITING(css::Rule)
+
+NS_IMETHODIMP
+CSSPageRule::GetStyle(nsIDOMCSSStyleDeclaration** aStyle)
+{
+ NS_ADDREF(*aStyle = Style());
+ return NS_OK;
+}
+
+JSObject*
+CSSPageRule::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
+{
+ return CSSPageRuleBinding::Wrap(aCx, this, aGivenProto);
+}
+
+} // namespace dom
+} // namespace mozilla
new file mode 100644
--- /dev/null
+++ b/layout/style/CSSPageRule.h
@@ -0,0 +1,52 @@
+/* -*- 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/. */
+
+#ifndef mozilla_dom_CSSPageRule_h
+#define mozilla_dom_CSSPageRule_h
+
+#include "mozilla/css/Rule.h"
+
+#include "nsICSSDeclaration.h"
+#include "nsIDOMCSSPageRule.h"
+#include "nsIDOMCSSStyleDeclaration.h"
+
+namespace mozilla {
+namespace dom {
+
+class CSSPageRule : public css::Rule
+ , public nsIDOMCSSPageRule
+{
+protected:
+ using Rule::Rule;
+ virtual ~CSSPageRule() {};
+
+public:
+ NS_DECL_ISUPPORTS_INHERITED
+
+ // nsIDOMCSSPageRule interface
+ NS_DECL_NSIDOMCSSPAGERULE
+
+ virtual bool IsCCLeaf() const override = 0;
+
+ int32_t GetType() const final { return Rule::PAGE_RULE; }
+ using Rule::GetType;
+
+ // WebIDL interfaces
+ uint16_t Type() const final { return nsIDOMCSSRule::PAGE_RULE; }
+ virtual void GetCssTextImpl(nsAString& aCssText) const override = 0;
+ virtual nsICSSDeclaration* Style() = 0;
+
+ virtual size_t
+ SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const override = 0;
+
+ JSObject*
+ WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
+};
+
+} // namespace dom
+} // namespace mozilla
+
+#endif // mozilla_dom_CSSPageRule_h
--- a/layout/style/moz.build
+++ b/layout/style/moz.build
@@ -126,16 +126,17 @@ EXPORTS.mozilla += [
'URLExtraData.h',
]
EXPORTS.mozilla.dom += [
'CSS.h',
'CSSLexer.h',
'CSSMediaRule.h',
'CSSNamespaceRule.h',
+ 'CSSPageRule.h',
'CSSRuleList.h',
'CSSValue.h',
'FontFace.h',
'FontFaceSet.h',
'FontFaceSetIterator.h',
'MediaList.h',
'MediaQueryList.h',
]
@@ -155,16 +156,17 @@ EXPORTS.mozilla.css += [
UNIFIED_SOURCES += [
'AnimationCollection.cpp',
'BindingStyleRule.cpp',
'CounterStyleManager.cpp',
'CSS.cpp',
'CSSLexer.cpp',
'CSSMediaRule.cpp',
+ 'CSSPageRule.cpp',
'CSSRuleList.cpp',
'CSSStyleSheet.cpp',
'CSSVariableDeclarations.cpp',
'CSSVariableResolver.cpp',
'CSSVariableValues.cpp',
'Declaration.cpp',
'DocumentStyleRootIterator.cpp',
'ErrorReporter.cpp',
--- a/layout/style/nsCSSRules.cpp
+++ b/layout/style/nsCSSRules.cpp
@@ -33,17 +33,16 @@
#include "nsStyleUtil.h"
#include "mozilla/DeclarationBlockInlines.h"
#include "nsCSSParser.h"
#include "nsDOMClassInfoID.h"
#include "mozilla/dom/CSSStyleDeclarationBinding.h"
#include "mozilla/dom/CSSImportRuleBinding.h"
#include "mozilla/dom/CSSSupportsRuleBinding.h"
#include "mozilla/dom/CSSMozDocumentRuleBinding.h"
-#include "mozilla/dom/CSSPageRuleBinding.h"
#include "mozilla/dom/CSSFontFaceRuleBinding.h"
#include "mozilla/dom/CSSFontFeatureValuesRuleBinding.h"
#include "mozilla/dom/CSSKeyframeRuleBinding.h"
#include "mozilla/dom/CSSKeyframesRuleBinding.h"
#include "mozilla/dom/CSSCounterStyleRuleBinding.h"
#include "StyleRule.h"
#include "nsFont.h"
#include "nsIURI.h"
@@ -2156,17 +2155,17 @@ nsCSSPageStyleDeclaration::GetParentObje
}
// -------------------------------------------
// nsCSSPageRule
//
nsCSSPageRule::nsCSSPageRule(const nsCSSPageRule& aCopy)
// copy everything except our reference count and mDOMDeclaration
- : Rule(aCopy)
+ : dom::CSSPageRule(aCopy)
, mDeclaration(new css::Declaration(*aCopy.mDeclaration))
{
mDeclaration->SetOwningRule(this);
}
nsCSSPageRule::~nsCSSPageRule()
{
mDeclaration->SetOwningRule(nullptr);
@@ -2177,44 +2176,43 @@ nsCSSPageRule::~nsCSSPageRule()
/* virtual */ already_AddRefed<css::Rule>
nsCSSPageRule::Clone() const
{
RefPtr<css::Rule> clone = new nsCSSPageRule(*this);
return clone.forget();
}
-NS_IMPL_ADDREF_INHERITED(nsCSSPageRule, mozilla::css::Rule)
-NS_IMPL_RELEASE_INHERITED(nsCSSPageRule, mozilla::css::Rule)
+NS_IMPL_ADDREF_INHERITED(nsCSSPageRule, dom::CSSPageRule)
+NS_IMPL_RELEASE_INHERITED(nsCSSPageRule, dom::CSSPageRule)
NS_IMPL_CYCLE_COLLECTION_CLASS(nsCSSPageRule)
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(nsCSSPageRule,
- mozilla::css::Rule)
+ dom::CSSPageRule)
if (tmp->mDOMDeclaration) {
tmp->mDOMDeclaration->DropReference();
tmp->mDOMDeclaration = nullptr;
}
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsCSSPageRule,
- mozilla::css::Rule)
+ dom::CSSPageRule)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDOMDeclaration)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
bool
nsCSSPageRule::IsCCLeaf() const
{
// Let's not worry about figuring out whether we're a leaf or not.
return false;
}
// QueryInterface implementation for nsCSSPageRule
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(nsCSSPageRule)
- NS_INTERFACE_MAP_ENTRY(nsIDOMCSSPageRule)
-NS_INTERFACE_MAP_END_INHERITING(mozilla::css::Rule)
+NS_INTERFACE_MAP_END_INHERITING(dom::CSSPageRule)
#ifdef DEBUG
void
nsCSSPageRule::List(FILE* out, int32_t aIndent) const
{
nsAutoCString str;
for (int32_t indent = aIndent; --indent >= 0; ) {
str.AppendLiteral(" ");
@@ -2224,45 +2222,26 @@ nsCSSPageRule::List(FILE* out, int32_t a
nsAutoString tmp;
mDeclaration->ToString(tmp);
AppendUTF16toUTF8(tmp, str);
str.AppendLiteral("}\n");
fprintf_stderr(out, "%s", str.get());
}
#endif
-/* virtual */ int32_t
-nsCSSPageRule::GetType() const
-{
- return Rule::PAGE_RULE;
-}
-
-uint16_t
-nsCSSPageRule::Type() const
-{
- return nsIDOMCSSRule::PAGE_RULE;
-}
-
void
nsCSSPageRule::GetCssTextImpl(nsAString& aCssText) const
{
aCssText.AppendLiteral("@page { ");
nsAutoString tmp;
mDeclaration->ToString(tmp);
aCssText.Append(tmp);
aCssText.AppendLiteral(" }");
}
-NS_IMETHODIMP
-nsCSSPageRule::GetStyle(nsIDOMCSSStyleDeclaration** aStyle)
-{
- NS_ADDREF(*aStyle = Style());
- return NS_OK;
-}
-
nsICSSDeclaration*
nsCSSPageRule::Style()
{
if (!mDOMDeclaration) {
mDOMDeclaration = new nsCSSPageStyleDeclaration(this);
}
return mDOMDeclaration;
}
@@ -2282,23 +2261,16 @@ nsCSSPageRule::ChangeDeclaration(css::De
}
/* virtual */ size_t
nsCSSPageRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
{
return aMallocSizeOf(this);
}
-/* virtual */ JSObject*
-nsCSSPageRule::WrapObject(JSContext* aCx,
- JS::Handle<JSObject*> aGivenProto)
-{
- return CSSPageRuleBinding::Wrap(aCx, this, aGivenProto);
-}
-
namespace mozilla {
CSSSupportsRule::CSSSupportsRule(bool aConditionMet,
const nsString& aCondition,
uint32_t aLineNumber, uint32_t aColumnNumber)
: css::ConditionRule(aLineNumber, aColumnNumber)
, mUseGroup(aConditionMet)
, mCondition(aCondition)
--- a/layout/style/nsCSSRules.h
+++ b/layout/style/nsCSSRules.h
@@ -13,26 +13,26 @@
#include "StyleRule.h"
#include "gfxFontFeatures.h"
#include "mozilla/Attributes.h"
#include "mozilla/MemoryReporting.h"
#include "mozilla/Move.h"
#include "mozilla/SheetType.h"
#include "mozilla/css/GroupRule.h"
#include "mozilla/dom/CSSMediaRule.h"
+#include "mozilla/dom/CSSPageRule.h"
#include "nsAutoPtr.h"
#include "nsCSSPropertyID.h"
#include "nsCSSValue.h"
#include "nsDOMCSSDeclaration.h"
#include "nsIDOMCSSConditionRule.h"
#include "nsIDOMCSSCounterStyleRule.h"
#include "nsIDOMCSSFontFeatureValuesRule.h"
#include "nsIDOMCSSGroupingRule.h"
#include "nsIDOMCSSMozDocumentRule.h"
-#include "nsIDOMCSSPageRule.h"
#include "nsIDOMCSSSupportsRule.h"
#include "nsIDOMCSSKeyframeRule.h"
#include "nsIDOMCSSKeyframesRule.h"
#include "nsTArray.h"
class nsMediaList;
namespace mozilla {
@@ -400,59 +400,49 @@ public:
protected:
virtual ~nsCSSPageStyleDeclaration();
// This reference is not reference-counted. The rule object tells us
// when it's about to go away.
nsCSSPageRule* MOZ_NON_OWNING_REF mRule;
};
-class nsCSSPageRule final : public mozilla::css::Rule,
- public nsIDOMCSSPageRule
+class nsCSSPageRule final : public mozilla::dom::CSSPageRule
{
public:
nsCSSPageRule(mozilla::css::Declaration* aDeclaration,
uint32_t aLineNumber, uint32_t aColumnNumber)
- : mozilla::css::Rule(aLineNumber, aColumnNumber)
+ : mozilla::dom::CSSPageRule(aLineNumber, aColumnNumber)
, mDeclaration(aDeclaration)
{
mDeclaration->SetOwningRule(this);
}
private:
nsCSSPageRule(const nsCSSPageRule& aCopy);
~nsCSSPageRule();
public:
NS_DECL_ISUPPORTS_INHERITED
- NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsCSSPageRule, mozilla::css::Rule)
+ NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsCSSPageRule, mozilla::dom::CSSPageRule)
virtual bool IsCCLeaf() const override;
#ifdef DEBUG
virtual void List(FILE* out = stdout, int32_t aIndent = 0) const override;
#endif
- virtual int32_t GetType() const override;
- using Rule::GetType;
virtual already_AddRefed<mozilla::css::Rule> Clone() const override;
- // nsIDOMCSSPageRule interface
- NS_DECL_NSIDOMCSSPAGERULE
-
- // WebIDL interface
- uint16_t Type() const override;
- void GetCssTextImpl(nsAString& aCssText) const override;
- nsICSSDeclaration* Style();
+ // WebIDL interfaces
+ virtual void GetCssTextImpl(nsAString& aCssText) const override;
+ virtual nsICSSDeclaration* Style() override;
mozilla::css::Declaration* Declaration() { return mDeclaration; }
void ChangeDeclaration(mozilla::css::Declaration* aDeclaration);
virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const override;
- virtual JSObject* WrapObject(JSContext* aCx,
- JS::Handle<JSObject*> aGivenProto) override;
-
private:
RefPtr<mozilla::css::Declaration> mDeclaration;
// lazily created when needed:
RefPtr<nsCSSPageStyleDeclaration> mDOMDeclaration;
};
namespace mozilla {