Bug 1451289 - Part 3: Merge ServoMediaRule and CSSMediaRule r?emilio
MozReview-Commit-ID: I7vpKO4LFt4
--- a/layout/style/CSSMediaRule.cpp
+++ b/layout/style/CSSMediaRule.cpp
@@ -7,16 +7,108 @@
#include "mozilla/dom/CSSMediaRule.h"
#include "mozilla/dom/CSSMediaRuleBinding.h"
#include "mozilla/dom/MediaList.h"
namespace mozilla {
namespace dom {
+CSSMediaRule::CSSMediaRule(RefPtr<RawServoMediaRule> aRawRule,
+ uint32_t aLine, uint32_t aColumn)
+ : ConditionRule(Servo_MediaRule_GetRules(aRawRule).Consume(), aLine, aColumn)
+ , 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
+
+/* virtual */ void
+CSSMediaRule::SetStyleSheet(StyleSheet* aSheet)
+{
+ if (mMediaList) {
+ mMediaList->SetStyleSheet(aSheet);
+ }
+ ConditionRule::SetStyleSheet(aSheet);
+}
+
+#ifdef DEBUG
+/* virtual */ void
+CSSMediaRule::List(FILE* out, int32_t aIndent) const
+{
+ 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
+
+void
+CSSMediaRule::GetConditionText(nsAString& aConditionText)
+{
+ Media()->GetMediaText(aConditionText);
+}
+
+void
+CSSMediaRule::SetConditionText(const nsAString& aConditionText,
+ ErrorResult& aRv)
+{
+ Media()->SetMediaText(aConditionText);
+}
+
+/* virtual */ void
+CSSMediaRule::GetCssText(nsAString& aCssText) const
+{
+ 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;
+}
+
+/* virtual */ size_t
+CSSMediaRule::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
+{
+ // TODO Implement this!
+ return aMallocSizeOf(this);
+}
+
/* virtual */ JSObject*
CSSMediaRule::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
{
return CSSMediaRuleBinding::Wrap(aCx, this, aGivenProto);
}
} // namespace dom
} // namespace mozilla
--- a/layout/style/CSSMediaRule.h
+++ b/layout/style/CSSMediaRule.h
@@ -3,31 +3,56 @@
/* 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_CSSMediaRule_h
#define mozilla_dom_CSSMediaRule_h
#include "mozilla/css/GroupRule.h"
+#include "mozilla/ServoBindingTypes.h"
namespace mozilla {
namespace dom {
-class CSSMediaRule : public css::ConditionRule
+class CSSMediaRule final : public css::ConditionRule
{
-protected:
- using ConditionRule::ConditionRule;
- virtual ~CSSMediaRule() {}
+public:
+ CSSMediaRule(RefPtr<RawServoMediaRule> aRawRule,
+ uint32_t aLine, uint32_t aColumn);
+
+ NS_DECL_ISUPPORTS_INHERITED
+ NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(CSSMediaRule, css::ConditionRule)
-public:
+ void SetStyleSheet(StyleSheet* aSheet) override;
+
+#ifdef DEBUG
+ void List(FILE* out = stdout, int32_t aIndent = 0) const final;
+#endif
+
+ RawServoMediaRule* Raw() const { return mRawRule; }
+
// WebIDL interface
uint16_t Type() const override { return CSSRuleBinding::MEDIA_RULE; }
- virtual MediaList* Media() = 0;
+ // WebIDL interface
+ void GetCssText(nsAString& aCssText) const final;
+ void GetConditionText(nsAString& aConditionText) final;
+ void SetConditionText(const nsAString& aConditionText,
+ ErrorResult& aRv) final;
+ dom::MediaList* Media();
+
+ size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf)
+ const override;
JSObject* WrapObject(JSContext* aCx,
JS::Handle<JSObject*> aGivenProto) override;
+
+private:
+ virtual ~CSSMediaRule();
+
+ RefPtr<RawServoMediaRule> mRawRule;
+ RefPtr<dom::MediaList> mMediaList;
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_CSSMediaRule_h
--- a/layout/style/ServoCSSRuleList.cpp
+++ b/layout/style/ServoCSSRuleList.cpp
@@ -4,25 +4,25 @@
* 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/. */
/* representation of CSSRuleList for stylo */
#include "mozilla/ServoCSSRuleList.h"
#include "mozilla/dom/CSSKeyframesRule.h"
+#include "mozilla/dom/CSSMediaRule.h"
#include "mozilla/dom/CSSNamespaceRule.h"
#include "mozilla/IntegerRange.h"
#include "mozilla/ServoBindings.h"
#include "mozilla/ServoCounterStyleRule.h"
#include "mozilla/ServoDocumentRule.h"
#include "mozilla/ServoImportRule.h"
#include "mozilla/ServoFontFaceRule.h"
#include "mozilla/ServoFontFeatureValuesRule.h"
-#include "mozilla/ServoMediaRule.h"
#include "mozilla/ServoPageRule.h"
#include "mozilla/ServoStyleRule.h"
#include "mozilla/ServoSupportsRule.h"
#include "mozilla/StyleSheet.h"
using namespace mozilla::dom;
namespace mozilla {
@@ -101,17 +101,17 @@ ServoCSSRuleList::GetRule(uint32_t aInde
mRawRules, aIndex, &line, &column \
).Consume(); \
MOZ_ASSERT(rule); \
ruleObj = new CSS##name_##Rule(rule.forget(), line, column); \
break; \
}
CASE_RULE(STYLE, Style)
CASE_RULE_CSS(KEYFRAMES, Keyframes)
- CASE_RULE(MEDIA, Media)
+ CASE_RULE_CSS(MEDIA, Media)
CASE_RULE_CSS(NAMESPACE, Namespace)
CASE_RULE(PAGE, Page)
CASE_RULE(SUPPORTS, Supports)
CASE_RULE(DOCUMENT, Document)
CASE_RULE(IMPORT, Import)
CASE_RULE(FONT_FEATURE_VALUES, FontFeatureValues)
CASE_RULE(FONT_FACE, FontFace)
CASE_RULE(COUNTER_STYLE, CounterStyle)
deleted file mode 100644
--- a/layout/style/ServoMediaRule.cpp
+++ /dev/null
@@ -1,110 +0,0 @@
-/* -*- 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/. */
-
-/* representation of CSSMediaRule for stylo */
-
-#include "mozilla/ServoMediaRule.h"
-
-#include "mozilla/ServoBindings.h"
-#include "mozilla/dom/MediaList.h"
-
-using namespace mozilla::dom;
-
-namespace mozilla {
-
-ServoMediaRule::ServoMediaRule(RefPtr<RawServoMediaRule> aRawRule,
- uint32_t aLine, uint32_t aColumn)
- : CSSMediaRule(Servo_MediaRule_GetRules(aRawRule).Consume(), aLine, aColumn)
- , mRawRule(std::move(aRawRule))
-{
-}
-
-ServoMediaRule::~ServoMediaRule()
-{
- if (mMediaList) {
- mMediaList->SetStyleSheet(nullptr);
- }
-}
-
-NS_IMPL_ADDREF_INHERITED(ServoMediaRule, CSSMediaRule)
-NS_IMPL_RELEASE_INHERITED(ServoMediaRule, CSSMediaRule)
-
-// QueryInterface implementation for MediaRule
-NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(ServoMediaRule)
-NS_INTERFACE_MAP_END_INHERITING(CSSMediaRule)
-
-NS_IMPL_CYCLE_COLLECTION_CLASS(ServoMediaRule)
-
-NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(ServoMediaRule, CSSMediaRule)
- if (tmp->mMediaList) {
- tmp->mMediaList->SetStyleSheet(nullptr);
- tmp->mMediaList = nullptr;
- }
-NS_IMPL_CYCLE_COLLECTION_UNLINK_END
-
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(ServoMediaRule, CSSMediaRule)
- NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mMediaList)
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
-
-/* virtual */ void
-ServoMediaRule::SetStyleSheet(StyleSheet* aSheet)
-{
- if (mMediaList) {
- mMediaList->SetStyleSheet(aSheet);
- }
- CSSMediaRule::SetStyleSheet(aSheet);
-}
-
-#ifdef DEBUG
-/* virtual */ void
-ServoMediaRule::List(FILE* out, int32_t aIndent) const
-{
- 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
-
-void
-ServoMediaRule::GetConditionText(nsAString& aConditionText)
-{
- Media()->GetMediaText(aConditionText);
-}
-
-void
-ServoMediaRule::SetConditionText(const nsAString& aConditionText,
- ErrorResult& aRv)
-{
- Media()->SetMediaText(aConditionText);
-}
-
-/* virtual */ void
-ServoMediaRule::GetCssText(nsAString& aCssText) const
-{
- Servo_MediaRule_GetCssText(mRawRule, &aCssText);
-}
-
-/* virtual */ dom::MediaList*
-ServoMediaRule::Media()
-{
- if (!mMediaList) {
- mMediaList = new MediaList(Servo_MediaRule_GetMedia(mRawRule).Consume());
- mMediaList->SetStyleSheet(GetStyleSheet());
- }
- return mMediaList;
-}
-
-/* virtual */ size_t
-ServoMediaRule::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
-{
- // TODO Implement this!
- return aMallocSizeOf(this);
-}
-
-} // namespace mozilla
deleted file mode 100644
--- a/layout/style/ServoMediaRule.h
+++ /dev/null
@@ -1,52 +0,0 @@
-/* -*- 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/. */
-
-/* representation of CSSMediaRule for stylo */
-
-#ifndef mozilla_ServoMediaRule_h
-#define mozilla_ServoMediaRule_h
-
-#include "mozilla/dom/CSSMediaRule.h"
-#include "mozilla/ServoBindingTypes.h"
-
-namespace mozilla {
-
-class ServoMediaRule final : public dom::CSSMediaRule
-{
-public:
- ServoMediaRule(RefPtr<RawServoMediaRule> aRawRule,
- uint32_t aLine, uint32_t aColumn);
-
- NS_DECL_ISUPPORTS_INHERITED
- NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ServoMediaRule, dom::CSSMediaRule)
-
- void SetStyleSheet(StyleSheet* aSheet) override;
-#ifdef DEBUG
- void List(FILE* out = stdout, int32_t aIndent = 0) const final;
-#endif
-
- RawServoMediaRule* Raw() const { return mRawRule; }
-
- // WebIDL interface
- void GetCssText(nsAString& aCssText) const final;
- void GetConditionText(nsAString& aConditionText) final;
- void SetConditionText(const nsAString& aConditionText,
- ErrorResult& aRv) final;
- dom::MediaList* Media() final;
-
- size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf)
- const override;
-
-private:
- virtual ~ServoMediaRule();
-
- RefPtr<RawServoMediaRule> mRawRule;
- RefPtr<dom::MediaList> mMediaList;
-};
-
-} // namespace mozilla
-
-#endif // mozilla_ServoMediaRule_h
--- a/layout/style/StyleSheet.cpp
+++ b/layout/style/StyleSheet.cpp
@@ -10,16 +10,17 @@
#include "mozilla/css/ErrorReporter.h"
#include "mozilla/css/GroupRule.h"
#include "mozilla/dom/CSSImportRule.h"
#include "mozilla/dom/CSSRuleList.h"
#include "mozilla/dom/Element.h"
#include "mozilla/dom/MediaList.h"
#include "mozilla/dom/ShadowRoot.h"
#include "mozilla/dom/ShadowRootBinding.h"
+#include "mozilla/ServoBindings.h"
#include "mozilla/ServoCSSRuleList.h"
#include "mozilla/ServoStyleSet.h"
#include "mozilla/StaticPrefs.h"
#include "mozilla/StyleSheetInlines.h"
#include "mozAutoDocUpdate.h"
#include "NullPrincipal.h"
--- a/layout/style/moz.build
+++ b/layout/style/moz.build
@@ -86,17 +86,16 @@ EXPORTS.mozilla += [
'ServoCSSParser.h',
'ServoCSSRuleList.h',
'ServoDocumentRule.h',
'ServoElementSnapshot.h',
'ServoElementSnapshotTable.h',
'ServoFontFaceRule.h',
'ServoFontFeatureValuesRule.h',
'ServoImportRule.h',
- 'ServoMediaRule.h',
'ServoPageRule.h',
'ServoSpecifiedValues.h',
'ServoStyleRule.h',
'ServoStyleSet.h',
'ServoStyleSetInlines.h',
'ServoSupportsRule.h',
'ServoTraversalStatistics.h',
'ServoTypes.h',
@@ -203,17 +202,16 @@ UNIFIED_SOURCES += [
'ServoCounterStyleRule.cpp',
'ServoCSSParser.cpp',
'ServoCSSRuleList.cpp',
'ServoDocumentRule.cpp',
'ServoElementSnapshot.cpp',
'ServoFontFaceRule.cpp',
'ServoFontFeatureValuesRule.cpp',
'ServoImportRule.cpp',
- 'ServoMediaRule.cpp',
'ServoPageRule.cpp',
'ServoSpecifiedValues.cpp',
'ServoStyleRule.cpp',
'ServoStyleSet.cpp',
'ServoSupportsRule.cpp',
'StreamLoader.cpp',
'StyleAnimationValue.cpp',
'StyleComplexColor.cpp',