Bug 1361994 - Part 1: Add separate CSSDocumentRule class. r=xidorn
MozReview-Commit-ID: DMDOHvBWLHX
--- a/dom/bindings/Bindings.conf
+++ b/dom/bindings/Bindings.conf
@@ -226,21 +226,16 @@ DOMInterfaces = {
'nativeType': 'nsCSSKeyframesRule',
'headerFile': 'nsCSSRules.h',
},
'CSSLexer': {
'wrapperCache': False
},
-'CSSMozDocumentRule': {
- 'nativeType': 'mozilla::css::DocumentRule',
- 'headerFile': 'nsCSSRules.h',
-},
-
'CSSPrimitiveValue': {
'nativeType': 'nsROCSSPrimitiveValue',
},
'CSSRule': {
'concrete': False,
'nativeType': 'mozilla::css::Rule'
},
new file mode 100644
--- /dev/null
+++ b/layout/style/CSSMozDocumentRule.cpp
@@ -0,0 +1,58 @@
+/* -*- 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/CSSMozDocumentRule.h"
+#include "mozilla/dom/CSSMozDocumentRuleBinding.h"
+
+namespace mozilla {
+namespace dom {
+
+NS_IMPL_ADDREF_INHERITED(CSSMozDocumentRule, css::ConditionRule)
+NS_IMPL_RELEASE_INHERITED(CSSMozDocumentRule, css::ConditionRule)
+
+// QueryInterface implementation for CSSMozDocumentRule
+NS_INTERFACE_MAP_BEGIN(CSSMozDocumentRule)
+ NS_INTERFACE_MAP_ENTRY(nsIDOMCSSGroupingRule)
+ NS_INTERFACE_MAP_ENTRY(nsIDOMCSSConditionRule)
+ NS_INTERFACE_MAP_ENTRY(nsIDOMCSSMozDocumentRule)
+NS_INTERFACE_MAP_END_INHERITING(ConditionRule)
+
+// nsIDOMCSSGroupingRule methods
+NS_IMETHODIMP
+CSSMozDocumentRule::GetCssRules(nsIDOMCSSRuleList** aRuleList)
+{
+ return GroupRule::GetCssRules(aRuleList);
+}
+
+NS_IMETHODIMP
+CSSMozDocumentRule::InsertRule(const nsAString & aRule,
+ uint32_t aIndex, uint32_t* _retval)
+{
+ return GroupRule::InsertRule(aRule, aIndex, _retval);
+}
+
+NS_IMETHODIMP
+CSSMozDocumentRule::DeleteRule(uint32_t aIndex)
+{
+ return GroupRule::DeleteRule(aIndex);
+}
+
+void
+CSSMozDocumentRule::SetConditionText(const nsAString& aConditionText,
+ ErrorResult& aRv)
+{
+ aRv = SetConditionText(aConditionText);
+}
+
+/* virtual */ JSObject*
+CSSMozDocumentRule::WrapObject(JSContext* aCx,
+ JS::Handle<JSObject*> aGivenProto)
+{
+ return CSSMozDocumentRuleBinding::Wrap(aCx, this, aGivenProto);
+}
+
+} // namespace dom
+} // namespace mozilla
new file mode 100644
--- /dev/null
+++ b/layout/style/CSSMozDocumentRule.h
@@ -0,0 +1,53 @@
+/* -*- 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_CSSMozDocumentRule_h
+#define mozilla_dom_CSSMozDocumentRule_h
+
+#include "mozilla/css/GroupRule.h"
+#include "nsIDOMCSSMozDocumentRule.h"
+
+namespace mozilla {
+namespace dom {
+
+class CSSMozDocumentRule : public css::ConditionRule
+ , public nsIDOMCSSMozDocumentRule
+{
+protected:
+ using ConditionRule::ConditionRule;
+ virtual ~CSSMozDocumentRule() {}
+
+public:
+ NS_DECL_ISUPPORTS_INHERITED
+
+ int32_t GetType() const final override { return css::Rule::DOCUMENT_RULE; }
+ using Rule::GetType;
+
+ // nsIDOMCSSGroupingRule interface
+ NS_DECL_NSIDOMCSSGROUPINGRULE
+
+ // nsIDOMCSSConditionRule interface
+ NS_IMETHOD SetConditionText(const nsAString& aConditionText) override = 0;
+
+ // nsIDOMCSSMozDocumentRule interface
+ NS_DECL_NSIDOMCSSMOZDOCUMENTRULE
+
+ // WebIDL interface
+ uint16_t Type() const final override {
+ return nsIDOMCSSRule::DOCUMENT_RULE;
+ }
+ // Our XPCOM GetConditionText is OK
+ void SetConditionText(const nsAString& aConditionText,
+ ErrorResult& aRv) final;
+
+ JSObject* WrapObject(JSContext* aCx,
+ JS::Handle<JSObject*> aGivenProto) override;
+};
+
+} // namespace dom
+} // namespace mozilla
+
+#endif // mozilla_dom_CSSMozDocumentRule_h
--- a/layout/style/moz.build
+++ b/layout/style/moz.build
@@ -129,16 +129,17 @@ EXPORTS.mozilla += [
'StyleSheetInlines.h',
'URLExtraData.h',
]
EXPORTS.mozilla.dom += [
'CSS.h',
'CSSLexer.h',
'CSSMediaRule.h',
+ 'CSSMozDocumentRule.h',
'CSSNamespaceRule.h',
'CSSPageRule.h',
'CSSRuleList.h',
'CSSSupportsRule.h',
'CSSValue.h',
'FontFace.h',
'FontFaceSet.h',
'FontFaceSetIterator.h',
@@ -162,16 +163,17 @@ EXPORTS.mozilla.css += [
UNIFIED_SOURCES += [
'AnimationCollection.cpp',
'BindingStyleRule.cpp',
'CounterStyleManager.cpp',
'CSS.cpp',
'CSSLexer.cpp',
'CSSMediaRule.cpp',
+ 'CSSMozDocumentRule.cpp',
'CSSPageRule.cpp',
'CSSRuleList.cpp',
'CSSStyleSheet.cpp',
'CSSSupportsRule.cpp',
'CSSVariableDeclarations.cpp',
'CSSVariableResolver.cpp',
'CSSVariableValues.cpp',
'Declaration.cpp',
--- a/layout/style/nsCSSRules.cpp
+++ b/layout/style/nsCSSRules.cpp
@@ -31,17 +31,16 @@
#include "nsContentUtils.h"
#include "nsError.h"
#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/CSSMozDocumentRuleBinding.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"
@@ -521,39 +520,36 @@ MediaRule::AppendConditionText(nsAString
if (mMedia) {
nsAutoString mediaText;
mMedia->GetText(mediaText);
aOutput.Append(mediaText);
}
}
DocumentRule::DocumentRule(uint32_t aLineNumber, uint32_t aColumnNumber)
- : ConditionRule(aLineNumber, aColumnNumber)
+ : dom::CSSMozDocumentRule(aLineNumber, aColumnNumber)
{
}
DocumentRule::DocumentRule(const DocumentRule& aCopy)
- : ConditionRule(aCopy)
+ : dom::CSSMozDocumentRule(aCopy)
, mURLs(new URL(*aCopy.mURLs))
{
}
DocumentRule::~DocumentRule()
{
}
NS_IMPL_ADDREF_INHERITED(DocumentRule, ConditionRule)
NS_IMPL_RELEASE_INHERITED(DocumentRule, ConditionRule)
// QueryInterface implementation for DocumentRule
NS_INTERFACE_MAP_BEGIN(DocumentRule)
- NS_INTERFACE_MAP_ENTRY(nsIDOMCSSGroupingRule)
- NS_INTERFACE_MAP_ENTRY(nsIDOMCSSConditionRule)
- NS_INTERFACE_MAP_ENTRY(nsIDOMCSSMozDocumentRule)
-NS_INTERFACE_MAP_END_INHERITING(ConditionRule)
+NS_INTERFACE_MAP_END_INHERITING(dom::CSSMozDocumentRule)
#ifdef DEBUG
/* virtual */ void
DocumentRule::List(FILE* out, int32_t aIndent) const
{
nsAutoCString indentStr;
for (int32_t indent = aIndent; --indent >= 0; ) {
indentStr.AppendLiteral(" ");
@@ -585,85 +581,46 @@ DocumentRule::List(FILE* out, int32_t aI
fprintf_stderr(out, "%s%s {\n", indentStr.get(), str.get());
GroupRule::List(out, aIndent);
fprintf_stderr(out, "%s}\n", indentStr.get());
}
#endif
-/* virtual */ int32_t
-DocumentRule::GetType() const
-{
- return Rule::DOCUMENT_RULE;
-}
-
/* virtual */ already_AddRefed<Rule>
DocumentRule::Clone() const
{
RefPtr<Rule> clone = new DocumentRule(*this);
return clone.forget();
}
-uint16_t
-DocumentRule::Type() const
-{
- // XXX What should really happen here?
- return nsIDOMCSSRule::UNKNOWN_RULE;
-}
-
void
DocumentRule::GetCssTextImpl(nsAString& aCssText) const
{
aCssText.AssignLiteral("@-moz-document ");
AppendConditionText(aCssText);
GroupRule::AppendRulesToCssText(aCssText);
}
-// nsIDOMCSSGroupingRule methods
-NS_IMETHODIMP
-DocumentRule::GetCssRules(nsIDOMCSSRuleList* *aRuleList)
-{
- return GroupRule::GetCssRules(aRuleList);
-}
-
-NS_IMETHODIMP
-DocumentRule::InsertRule(const nsAString & aRule, uint32_t aIndex, uint32_t* _retval)
-{
- return GroupRule::InsertRule(aRule, aIndex, _retval);
-}
-
-NS_IMETHODIMP
-DocumentRule::DeleteRule(uint32_t aIndex)
-{
- return GroupRule::DeleteRule(aIndex);
-}
-
// nsIDOMCSSConditionRule methods
NS_IMETHODIMP
DocumentRule::GetConditionText(nsAString& aConditionText)
{
aConditionText.Truncate(0);
AppendConditionText(aConditionText);
return NS_OK;
}
NS_IMETHODIMP
DocumentRule::SetConditionText(const nsAString& aConditionText)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
-void
-DocumentRule::SetConditionText(const nsAString& aConditionText,
- ErrorResult& aRv)
-{
- aRv.Throw(NS_ERROR_NOT_IMPLEMENTED);
-}
-
// GroupRule interface
/* virtual */ bool
DocumentRule::UseForPresentation(nsPresContext* aPresContext,
nsMediaQueryResultCacheKey& aKey)
{
return UseForPresentation(aPresContext);
}
@@ -748,23 +705,16 @@ DocumentRule::SizeOfIncludingThis(Malloc
// Measurement of the following members may be added later if DMD finds it is
// worthwhile:
// - mURLs
return n;
}
-/* virtual */ JSObject*
-DocumentRule::WrapObject(JSContext* aCx,
- JS::Handle<JSObject*> aGivenProto)
-{
- return CSSMozDocumentRuleBinding::Wrap(aCx, this, aGivenProto);
-}
-
void
DocumentRule::AppendConditionText(nsAString& aCssText) const
{
for (URL *url = mURLs; url; url = url->next) {
switch (url->func) {
case URLMatchingFunction::eURL:
aCssText.AppendLiteral("url(");
break;
--- a/layout/style/nsCSSRules.h
+++ b/layout/style/nsCSSRules.h
@@ -16,16 +16,17 @@
#include "mozilla/MemoryReporting.h"
#include "mozilla/Move.h"
#include "mozilla/SheetType.h"
#include "mozilla/css/GroupRule.h"
#include "mozilla/css/URLMatchingFunction.h"
#include "mozilla/dom/CSSMediaRule.h"
#include "mozilla/dom/CSSPageRule.h"
#include "mozilla/dom/CSSSupportsRule.h"
+#include "mozilla/dom/CSSMozDocumentRule.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"
@@ -89,45 +90,36 @@ public:
const override MOZ_MUST_OVERRIDE;
protected:
void AppendConditionText(nsAString& aOutput) const;
RefPtr<nsMediaList> mMedia;
};
-class DocumentRule final : public ConditionRule,
- public nsIDOMCSSMozDocumentRule
+class DocumentRule final : public dom::CSSMozDocumentRule
{
public:
DocumentRule(uint32_t aLineNumber, uint32_t aColumnNumber);
private:
DocumentRule(const DocumentRule& aCopy);
~DocumentRule();
public:
NS_DECL_ISUPPORTS_INHERITED
// Rule methods
#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<Rule> Clone() const override;
- // nsIDOMCSSGroupingRule interface
- NS_DECL_NSIDOMCSSGROUPINGRULE
-
// nsIDOMCSSConditionRule interface
NS_DECL_NSIDOMCSSCONDITIONRULE
- // nsIDOMCSSMozDocumentRule interface
- NS_DECL_NSIDOMCSSMOZDOCUMENTRULE
-
// rest of GroupRule
virtual bool UseForPresentation(nsPresContext* aPresContext,
nsMediaQueryResultCacheKey& aKey) override;
bool UseForPresentation(nsPresContext* aPresContext);
static bool UseForPresentation(nsIDocument* aDoc,
nsIURI* aDocURI,
@@ -148,28 +140,22 @@ public:
{
}
~URL();
};
void SetURLs(URL *aURLs) { mURLs = aURLs; }
// WebIDL interface
- uint16_t Type() const override;
void GetCssTextImpl(nsAString& aCssText) const override;
- // Our XPCOM GetConditionText is OK
- virtual void SetConditionText(const nsAString& aConditionText,
- ErrorResult& aRv) override;
+ using dom::CSSMozDocumentRule::SetConditionText;
virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf)
const override MOZ_MUST_OVERRIDE;
- virtual JSObject* WrapObject(JSContext* aCx,
- JS::Handle<JSObject*> aGivenProto) override;
-
protected:
void AppendConditionText(nsAString& aOutput) const;
nsAutoPtr<URL> mURLs; // linked list of |struct URL| above.
};
} // namespace css