Bug 1352968 part 3 - Add basic CSSOM support for @import rule. r=heycam
Initialization of mChildSheet will be implemented in a later patch.
MozReview-Commit-ID: 3SX3GJEhpBQ
--- a/layout/style/ServoBindingList.h
+++ b/layout/style/ServoBindingList.h
@@ -117,16 +117,17 @@ SERVO_BINDING_FUNC(Servo_CssRules_Delete
ServoCssRulesBorrowed rules, uint32_t index, \
uint32_t* line, uint32_t* column) \
BASIC_RULE_FUNCS_WITHOUT_GETTER(type_##Rule)
#define GROUP_RULE_FUNCS(type_) \
BASIC_RULE_FUNCS(type_) \
SERVO_BINDING_FUNC(Servo_##type_##Rule_GetRules, ServoCssRulesStrong, \
RawServo##type_##RuleBorrowed rule)
BASIC_RULE_FUNCS(Style)
+BASIC_RULE_FUNCS(Import)
BASIC_RULE_FUNCS_WITHOUT_GETTER(Keyframe)
BASIC_RULE_FUNCS(Keyframes)
GROUP_RULE_FUNCS(Media)
BASIC_RULE_FUNCS(Namespace)
BASIC_RULE_FUNCS(Page)
GROUP_RULE_FUNCS(Supports)
GROUP_RULE_FUNCS(Document)
#undef GROUP_RULE_FUNCS
@@ -138,16 +139,18 @@ SERVO_BINDING_FUNC(Servo_CssRules_GetCou
ServoCssRulesBorrowed rules, uint32_t index)
SERVO_BINDING_FUNC(Servo_StyleRule_GetStyle, RawServoDeclarationBlockStrong,
RawServoStyleRuleBorrowed rule)
SERVO_BINDING_FUNC(Servo_StyleRule_SetStyle, void,
RawServoStyleRuleBorrowed rule,
RawServoDeclarationBlockBorrowed declarations)
SERVO_BINDING_FUNC(Servo_StyleRule_GetSelectorText, void,
RawServoStyleRuleBorrowed rule, nsAString* result)
+SERVO_BINDING_FUNC(Servo_ImportRule_GetHref, void,
+ RawServoImportRuleBorrowed rule, nsAString* result)
SERVO_BINDING_FUNC(Servo_Keyframe_GetKeyText, void,
RawServoKeyframeBorrowed keyframe, nsAString* result)
// Returns whether it successfully changes the key text.
SERVO_BINDING_FUNC(Servo_Keyframe_SetKeyText, bool,
RawServoKeyframeBorrowed keyframe, const nsACString* text)
SERVO_BINDING_FUNC(Servo_Keyframe_GetStyle, RawServoDeclarationBlockStrong,
RawServoKeyframeBorrowed keyframe)
SERVO_BINDING_FUNC(Servo_Keyframe_SetStyle, void,
--- 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/ServoDocumentRule.h"
+#include "mozilla/ServoImportRule.h"
#include "mozilla/ServoKeyframesRule.h"
#include "mozilla/ServoMediaRule.h"
#include "mozilla/ServoNamespaceRule.h"
#include "mozilla/ServoPageRule.h"
#include "mozilla/ServoStyleRule.h"
#include "mozilla/ServoSupportsRule.h"
#include "nsCSSCounterStyleRule.h"
#include "nsCSSFontFaceRule.h"
@@ -93,16 +94,17 @@ ServoCSSRuleList::GetRule(uint32_t aInde
RefPtr<RawServo##name_##Rule> rule = \
Servo_CssRules_Get##name_##RuleAt( \
mRawRules, aIndex, &line, &column \
).Consume(); \
ruleObj = new Servo##name_##Rule(rule.forget(), line, column); \
break; \
}
CASE_RULE(STYLE, Style)
+ CASE_RULE(IMPORT, Import)
CASE_RULE(KEYFRAMES, Keyframes)
CASE_RULE(MEDIA, Media)
CASE_RULE(NAMESPACE, Namespace)
CASE_RULE(PAGE, Page)
CASE_RULE(SUPPORTS, Supports)
CASE_RULE(DOCUMENT, Document)
#undef CASE_RULE
// For @font-face and @counter-style rules, the function returns
new file mode 100644
--- /dev/null
+++ b/layout/style/ServoImportRule.cpp
@@ -0,0 +1,96 @@
+/* -*- 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 CSSImportRule for stylo */
+
+#include "mozilla/ServoImportRule.h"
+
+#include "mozilla/ServoBindings.h"
+#include "mozilla/ServoStyleSheet.h"
+
+namespace mozilla {
+
+ServoImportRule::ServoImportRule(RefPtr<RawServoImportRule> aRawRule,
+ uint32_t aLine, uint32_t aColumn)
+ : CSSImportRule(aLine, aColumn)
+ , mRawRule(Move(aRawRule))
+ , mChildSheet(nullptr)
+{
+}
+
+ServoImportRule::~ServoImportRule()
+{
+ if (mChildSheet) {
+ mChildSheet->SetOwnerRule(nullptr);
+ }
+}
+
+NS_IMPL_ADDREF_INHERITED(ServoImportRule, dom::CSSImportRule)
+NS_IMPL_RELEASE_INHERITED(ServoImportRule, dom::CSSImportRule)
+
+NS_IMPL_CYCLE_COLLECTION_INHERITED(ServoImportRule,
+ dom::CSSImportRule, mChildSheet)
+
+// QueryInterface implementation for ServoImportRule
+NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(ServoImportRule)
+NS_INTERFACE_MAP_END_INHERITING(dom::CSSImportRule)
+
+/* virtual */ already_AddRefed<css::Rule>
+ServoImportRule::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 ServoSupportsRule");
+ return nullptr;
+}
+
+#ifdef DEBUG
+/* virtual */ void
+ServoImportRule::List(FILE* out, int32_t aIndent) const
+{
+ nsAutoCString str;
+ for (int32_t i = 0; i < aIndent; i++) {
+ str.AppendLiteral(" ");
+ }
+ Servo_ImportRule_Debug(mRawRule, &str);
+ fprintf_stderr(out, "%s\n", str.get());
+}
+#endif
+
+dom::MediaList*
+ServoImportRule::Media() const
+{
+ return mChildSheet->Media();
+}
+
+StyleSheet*
+ServoImportRule::GetStyleSheet() const
+{
+ return mChildSheet;
+}
+
+NS_IMETHODIMP
+ServoImportRule::GetHref(nsAString& aHref)
+{
+ Servo_ImportRule_GetHref(mRawRule, &aHref);
+ return NS_OK;
+}
+
+/* virtual */ void
+ServoImportRule::GetCssTextImpl(nsAString& aCssText) const
+{
+ Servo_ImportRule_GetCssText(mRawRule, &aCssText);
+}
+
+/* virtual */ size_t
+ServoImportRule::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
+{
+ // TODO Implement this!
+ return aMallocSizeOf(this);
+}
+
+} // namespace mozilla
new file mode 100644
--- /dev/null
+++ b/layout/style/ServoImportRule.h
@@ -0,0 +1,55 @@
+/* -*- 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 CSSImportRule for stylo */
+
+#ifndef mozilla_ServoImportRule_h
+#define mozilla_ServoImportRule_h
+
+#include "mozilla/dom/CSSImportRule.h"
+#include "mozilla/ServoBindingTypes.h"
+
+namespace mozilla {
+
+class ServoStyleSheet;
+class ServoMediaList;
+
+class ServoImportRule final : public dom::CSSImportRule
+{
+public:
+ ServoImportRule(RefPtr<RawServoImportRule> aRawRule,
+ uint32_t aLine, uint32_t aColumn);
+
+ NS_DECL_ISUPPORTS_INHERITED
+ NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ServoImportRule, dom::CSSImportRule)
+
+ // unhide since nsIDOMCSSImportRule has its own GetStyleSheet
+ using dom::CSSImportRule::GetStyleSheet;
+
+#ifdef DEBUG
+ void List(FILE* out = stdout, int32_t aIndent = 0) const final;
+#endif
+ already_AddRefed<css::Rule> Clone() const final;
+ size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const final;
+
+ // nsIDOMCSSImportRule interface
+ NS_IMETHOD GetHref(nsAString& aHref) final;
+
+ // WebIDL interface
+ void GetCssTextImpl(nsAString& aCssText) const override;
+ dom::MediaList* Media() const final;
+ StyleSheet* GetStyleSheet() const final;
+
+private:
+ ~ServoImportRule();
+
+ RefPtr<RawServoImportRule> mRawRule;
+ RefPtr<ServoStyleSheet> mChildSheet;
+};
+
+} // namespace mozilla
+
+#endif // mozilla_ServoImportRule_h
--- a/layout/style/moz.build
+++ b/layout/style/moz.build
@@ -102,16 +102,17 @@ EXPORTS.mozilla += [
'ServoBindingList.h',
'ServoBindings.h',
'ServoBindingTypes.h',
'ServoCSSRuleList.h',
'ServoDeclarationBlock.h',
'ServoDocumentRule.h',
'ServoElementSnapshot.h',
'ServoElementSnapshotTable.h',
+ 'ServoImportRule.h',
'ServoKeyframeRule.h',
'ServoKeyframesRule.h',
'ServoMediaList.h',
'ServoMediaRule.h',
'ServoNamespaceRule.h',
'ServoPageRule.h',
'ServoPropPrefList.h',
'ServoSpecifiedValues.h',
@@ -238,16 +239,17 @@ UNIFIED_SOURCES += [
'PreloadedStyleSheet.cpp',
'RuleNodeCacheConditions.cpp',
'RuleProcessorCache.cpp',
'ServoBindings.cpp',
'ServoCSSRuleList.cpp',
'ServoDeclarationBlock.cpp',
'ServoDocumentRule.cpp',
'ServoElementSnapshot.cpp',
+ 'ServoImportRule.cpp',
'ServoKeyframeRule.cpp',
'ServoKeyframesRule.cpp',
'ServoMediaList.cpp',
'ServoMediaRule.cpp',
'ServoNamespaceRule.cpp',
'ServoPageRule.cpp',
'ServoSpecifiedValues.cpp',
'ServoStyleRule.cpp',