Bug 1315601 part 16 - Implement ServoMediaRule. r=heycam
MozReview-Commit-ID: GcDNr5Lv73m
--- a/layout/style/GroupRule.cpp
+++ b/layout/style/GroupRule.cpp
@@ -218,16 +218,23 @@ ServoGroupRuleRules::SizeOfExcludingThis
//
GroupRule::GroupRule(uint32_t aLineNumber, uint32_t aColumnNumber)
: Rule(aLineNumber, aColumnNumber)
, mInner(GeckoGroupRuleRules())
{
}
+GroupRule::GroupRule(already_AddRefed<ServoCssRules> aRules)
+ : Rule(0, 0) // TODO
+ , mInner(ServoGroupRuleRules(Move(aRules)))
+{
+ mInner.as<ServoGroupRuleRules>().SetParentRule(this);
+}
+
GroupRule::GroupRule(const GroupRule& aCopy)
: Rule(aCopy)
, mInner(aCopy.mInner)
{
CALL_INNER(mInner, SetParentRule(this));
}
GroupRule::~GroupRule()
--- a/layout/style/GroupRule.h
+++ b/layout/style/GroupRule.h
@@ -75,16 +75,18 @@ struct GeckoGroupRuleRules
IncrementalClearCOMRuleArray mRules;
RefPtr<GroupRuleRuleList> mRuleCollection; // lazily constructed
};
struct ServoGroupRuleRules
{
explicit ServoGroupRuleRules(already_AddRefed<ServoCssRules> aRawRules)
: mRuleList(new ServoCSSRuleList(Move(aRawRules))) {}
+ ServoGroupRuleRules(ServoGroupRuleRules&& aOther)
+ : mRuleList(Move(aOther.mRuleList)) {}
ServoGroupRuleRules(const ServoGroupRuleRules& aCopy) {
// Do we ever clone Servo rules?
MOZ_ASSERT_UNREACHABLE("stylo: Cloning GroupRule not implemented");
}
void SetParentRule(GroupRule* aParentRule) {
if (mRuleList) {
mRuleList->SetParentRule(aParentRule);
@@ -134,16 +136,17 @@ struct ServoGroupRuleRules
} \
// inherits from Rule so it can be shared between
// MediaRule and DocumentRule
class GroupRule : public Rule
{
protected:
GroupRule(uint32_t aLineNumber, uint32_t aColumnNumber);
+ explicit GroupRule(already_AddRefed<ServoCssRules> aRules);
GroupRule(const GroupRule& aCopy);
virtual ~GroupRule();
public:
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(GroupRule, Rule)
NS_DECL_ISUPPORTS_INHERITED
virtual bool IsCCLeaf() const override;
--- a/layout/style/ServoCSSRuleList.cpp
+++ b/layout/style/ServoCSSRuleList.cpp
@@ -5,16 +5,17 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/* representation of CSSRuleList for stylo */
#include "mozilla/ServoCSSRuleList.h"
#include "mozilla/ServoBindings.h"
#include "mozilla/ServoStyleRule.h"
+#include "mozilla/ServoMediaRule.h"
namespace mozilla {
ServoCSSRuleList::ServoCSSRuleList(already_AddRefed<ServoCssRules> aRawRules)
: mRawRules(aRawRules)
{
Servo_CssRules_ListTypes(mRawRules, &mRules);
// XXX We may want to eagerly create object for import rule, so that
@@ -69,17 +70,21 @@ ServoCSSRuleList::GetRule(uint32_t aInde
if (rule <= kMaxRuleType) {
RefPtr<css::Rule> ruleObj = nullptr;
switch (rule) {
case nsIDOMCSSRule::STYLE_RULE: {
ruleObj = new ServoStyleRule(
Servo_CssRules_GetStyleRuleAt(mRawRules, aIndex).Consume());
break;
}
- case nsIDOMCSSRule::MEDIA_RULE:
+ case nsIDOMCSSRule::MEDIA_RULE: {
+ ruleObj = new ServoMediaRule(
+ Servo_CssRules_GetMediaRuleAt(mRawRules, aIndex).Consume());
+ break;
+ }
case nsIDOMCSSRule::FONT_FACE_RULE:
case nsIDOMCSSRule::KEYFRAMES_RULE:
case nsIDOMCSSRule::NAMESPACE_RULE:
// XXX create corresponding rules
default:
NS_WARNING("stylo: not implemented yet");
return nullptr;
}
new file mode 100644
--- /dev/null
+++ b/layout/style/ServoMediaRule.cpp
@@ -0,0 +1,117 @@
+/* -*- 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"
+
+using namespace mozilla::dom;
+
+namespace mozilla {
+
+ServoMediaRule::ServoMediaRule(RefPtr<RawServoMediaRule> aRawRule)
+ : CSSMediaRule(Servo_MediaRule_GetRules(aRawRule).Consume())
+ , mRawRule(Move(aRawRule))
+{
+}
+
+ServoMediaRule::~ServoMediaRule()
+{
+}
+
+NS_IMPL_ADDREF_INHERITED(ServoMediaRule, CSSMediaRule)
+NS_IMPL_RELEASE_INHERITED(ServoMediaRule, CSSMediaRule)
+
+// QueryInterface implementation for MediaRule
+NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(ServoMediaRule)
+NS_INTERFACE_MAP_END_INHERITING(CSSMediaRule)
+
+NS_IMPL_CYCLE_COLLECTION_INHERITED(ServoMediaRule, CSSMediaRule,
+ mMediaList)
+
+/* virtual */ already_AddRefed<css::Rule>
+ServoMediaRule::Clone() const
+{
+ // Rule::Clone is only used when CSSStyleSheetInner is cloned in
+ // preparation of being mutated. However, ServoStyleSheet never clones
+ // anything, so this method should never be called.
+ MOZ_ASSERT_UNREACHABLE("Shouldn't be cloning ServoMediaRule");
+ return nullptr;
+}
+
+/* virtual */ bool
+ServoMediaRule::UseForPresentation(nsPresContext* aPresContext,
+ nsMediaQueryResultCacheKey& aKey)
+{
+ // GroupRule::UseForPresentation is only used in nsCSSRuleProcessor,
+ // so this should never be called.
+ MOZ_ASSERT_UNREACHABLE("Shouldn't be calling UseForPresentation");
+ return false;
+}
+
+/* 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
+
+// nsIDOMCSSConditionRule methods
+
+NS_IMETHODIMP
+ServoMediaRule::GetConditionText(nsAString& aConditionText)
+{
+ return Media()->GetMediaText(aConditionText);
+}
+
+NS_IMETHODIMP
+ServoMediaRule::SetConditionText(const nsAString& aConditionText)
+{
+ return Media()->SetMediaText(aConditionText);
+}
+
+/* virtual */ void
+ServoMediaRule::GetCssTextImpl(nsAString& aCssText) const
+{
+ Servo_MediaRule_GetCssText(mRawRule, &aCssText);
+}
+
+/* virtual */ dom::MediaList*
+ServoMediaRule::Media()
+{
+ if (!mMediaList) {
+ mMediaList =
+ new ServoMediaList(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
new file mode 100644
--- /dev/null
+++ b/layout/style/ServoMediaRule.h
@@ -0,0 +1,57 @@
+/* -*- 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 ServoMediaList;
+
+class ServoMediaRule final : public dom::CSSMediaRule
+{
+public:
+ explicit ServoMediaRule(RefPtr<RawServoMediaRule> aRawRule);
+
+ NS_DECL_ISUPPORTS_INHERITED
+ NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ServoMediaRule, dom::CSSMediaRule)
+
+ already_AddRefed<css::Rule> Clone() const override;
+ bool UseForPresentation(nsPresContext* aPresContext,
+ nsMediaQueryResultCacheKey& aKey) final;
+ void SetStyleSheet(StyleSheet* aSheet) override;
+#ifdef DEBUG
+ void List(FILE* out = stdout, int32_t aIndent = 0) const final;
+#endif
+
+ RawServoMediaRule* Raw() const { return mRawRule; }
+
+ // nsIDOMCSSConditionRule interface
+ NS_DECL_NSIDOMCSSCONDITIONRULE
+
+ // WebIDL interface
+ void GetCssTextImpl(nsAString& aCssText) const override;
+ using CSSMediaRule::SetConditionText;
+ dom::MediaList* Media() override;
+
+ size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf)
+ const override;
+
+private:
+ virtual ~ServoMediaRule();
+
+ RefPtr<RawServoMediaRule> mRawRule;
+ RefPtr<ServoMediaList> mMediaList;
+};
+
+} // namespace mozilla
+
+#endif // mozilla_ServoMediaRule_h
--- a/layout/style/moz.build
+++ b/layout/style/moz.build
@@ -98,16 +98,17 @@ EXPORTS.mozilla += [
'ServoArcTypeList.h',
'ServoBindingList.h',
'ServoBindings.h',
'ServoBindingTypes.h',
'ServoCSSRuleList.h',
'ServoDeclarationBlock.h',
'ServoElementSnapshot.h',
'ServoMediaList.h',
+ 'ServoMediaRule.h',
'ServoPropPrefList.h',
'ServoSpecifiedValues.h',
'ServoStyleRule.h',
'ServoStyleSet.h',
'ServoStyleSheet.h',
'ServoTypes.h',
'ServoUtils.h',
'SheetType.h',
@@ -211,16 +212,17 @@ UNIFIED_SOURCES += [
'PreloadedStyleSheet.cpp',
'RuleNodeCacheConditions.cpp',
'RuleProcessorCache.cpp',
'ServoBindings.cpp',
'ServoCSSRuleList.cpp',
'ServoDeclarationBlock.cpp',
'ServoElementSnapshot.cpp',
'ServoMediaList.cpp',
+ 'ServoMediaRule.cpp',
'ServoSpecifiedValues.cpp',
'ServoStyleRule.cpp',
'ServoStyleSet.cpp',
'ServoStyleSheet.cpp',
'StyleAnimationValue.cpp',
'StyleRule.cpp',
'StyleSheet.cpp',
'SVGAttrAnimationRuleProcessor.cpp',