Bug 1361994 - Part 3: Implement CSSOM support for @-moz-document. r=xidorn
MozReview-Commit-ID: HnFDV9h7SYW
--- a/layout/style/ServoArcTypeList.h
+++ b/layout/style/ServoArcTypeList.h
@@ -13,9 +13,10 @@ SERVO_ARC_TYPE(DeclarationBlock, RawServ
SERVO_ARC_TYPE(StyleRule, RawServoStyleRule)
SERVO_ARC_TYPE(ImportRule, RawServoImportRule)
SERVO_ARC_TYPE(AnimationValue, RawServoAnimationValue)
SERVO_ARC_TYPE(MediaList, RawServoMediaList)
SERVO_ARC_TYPE(MediaRule, RawServoMediaRule)
SERVO_ARC_TYPE(NamespaceRule, RawServoNamespaceRule)
SERVO_ARC_TYPE(PageRule, RawServoPageRule)
SERVO_ARC_TYPE(SupportsRule, RawServoSupportsRule)
+SERVO_ARC_TYPE(DocumentRule, RawServoDocumentRule)
SERVO_ARC_TYPE(RuleNode, RawServoRuleNode)
--- a/layout/style/ServoBindingList.h
+++ b/layout/style/ServoBindingList.h
@@ -109,16 +109,17 @@ SERVO_BINDING_FUNC(Servo_CssRules_Delete
BASIC_RULE_FUNCS(type_) \
SERVO_BINDING_FUNC(Servo_##type_##Rule_GetRules, ServoCssRulesStrong, \
RawServo##type_##RuleBorrowed rule)
BASIC_RULE_FUNCS(Style)
GROUP_RULE_FUNCS(Media)
BASIC_RULE_FUNCS(Namespace)
BASIC_RULE_FUNCS(Page)
GROUP_RULE_FUNCS(Supports)
+GROUP_RULE_FUNCS(Document)
#undef GROUP_RULE_FUNCS
#undef BASIC_RULE_FUNCS
SERVO_BINDING_FUNC(Servo_CssRules_GetFontFaceRuleAt, nsCSSFontFaceRule*,
ServoCssRulesBorrowed rules, uint32_t index)
SERVO_BINDING_FUNC(Servo_StyleRule_GetStyle, RawServoDeclarationBlockStrong,
RawServoStyleRuleBorrowed rule)
SERVO_BINDING_FUNC(Servo_StyleRule_SetStyle, void,
RawServoStyleRuleBorrowed rule,
@@ -133,16 +134,18 @@ SERVO_BINDING_FUNC(Servo_NamespaceRule_G
RawServoNamespaceRuleBorrowed rule)
SERVO_BINDING_FUNC(Servo_PageRule_GetStyle, RawServoDeclarationBlockStrong,
RawServoPageRuleBorrowed rule)
SERVO_BINDING_FUNC(Servo_PageRule_SetStyle, void,
RawServoPageRuleBorrowed rule,
RawServoDeclarationBlockBorrowed declarations)
SERVO_BINDING_FUNC(Servo_SupportsRule_GetConditionText, void,
RawServoSupportsRuleBorrowed rule, nsAString* result)
+SERVO_BINDING_FUNC(Servo_DocumentRule_GetConditionText, void,
+ RawServoDocumentRuleBorrowed rule, nsAString* result)
// Animations API
SERVO_BINDING_FUNC(Servo_ParseProperty,
RawServoDeclarationBlockStrong,
nsCSSPropertyID property, const nsACString* value,
RawGeckoURLExtraData* data,
mozilla::LengthParsingMode length_parsing_mode)
SERVO_BINDING_FUNC(Servo_ParseEasing, bool,
--- a/layout/style/ServoCSSRuleList.cpp
+++ b/layout/style/ServoCSSRuleList.cpp
@@ -4,20 +4,21 @@
* 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/ServoBindings.h"
-#include "mozilla/ServoStyleRule.h"
+#include "mozilla/ServoDocumentRule.h"
#include "mozilla/ServoMediaRule.h"
#include "mozilla/ServoNamespaceRule.h"
#include "mozilla/ServoPageRule.h"
+#include "mozilla/ServoStyleRule.h"
#include "mozilla/ServoSupportsRule.h"
#include "nsCSSFontFaceRule.h"
namespace mozilla {
ServoCSSRuleList::ServoCSSRuleList(already_AddRefed<ServoCssRules> aRawRules)
: mRawRules(aRawRules)
{
@@ -87,16 +88,17 @@ ServoCSSRuleList::GetRule(uint32_t aInde
Servo_CssRules_Get##name_##RuleAt(mRawRules, aIndex).Consume()); \
break; \
}
CASE_RULE(STYLE, Style)
CASE_RULE(MEDIA, Media)
CASE_RULE(NAMESPACE, Namespace)
CASE_RULE(PAGE, Page)
CASE_RULE(SUPPORTS, Supports)
+ CASE_RULE(DOCUMENT, Document)
#undef CASE_RULE
case nsIDOMCSSRule::FONT_FACE_RULE: {
// Returns a borrowed nsCSSFontFaceRule object directly, so we
// don't need to create anything here, but we still need to have
// the style sheet and parent rule set properly.
ruleObj = Servo_CssRules_GetFontFaceRuleAt(mRawRules, aIndex);
break;
}
@@ -212,17 +214,18 @@ ServoCSSRuleList::FillStyleRuleHashtable
{
for (uint32_t i = 0; i < mRules.Length(); i++) {
uint16_t type = GetRuleType(i);
if (type == nsIDOMCSSRule::STYLE_RULE) {
ServoStyleRule* castedRule = static_cast<ServoStyleRule*>(GetRule(i));
RawServoStyleRule* rawRule = castedRule->Raw();
aTable.Put(rawRule, castedRule);
} else if (type == nsIDOMCSSRule::MEDIA_RULE ||
- type == nsIDOMCSSRule::SUPPORTS_RULE) {
+ type == nsIDOMCSSRule::SUPPORTS_RULE ||
+ type == nsIDOMCSSRule::DOCUMENT_RULE) {
css::GroupRule* castedRule = static_cast<css::GroupRule*>(GetRule(i));
// Call this method recursively on the ServoCSSRuleList in the rule.
ServoCSSRuleList* castedRuleList = static_cast<ServoCSSRuleList*>(
castedRule->CssRules());
castedRuleList->FillStyleRuleHashtable(aTable);
}
}
new file mode 100644
--- /dev/null
+++ b/layout/style/ServoDocumentRule.cpp
@@ -0,0 +1,95 @@
+/* -*- 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 CSSMozDocumentRule for stylo */
+
+#include "mozilla/ServoBindings.h"
+#include "mozilla/ServoDocumentRule.h"
+
+using namespace mozilla::dom;
+
+namespace mozilla {
+
+ServoDocumentRule::ServoDocumentRule(RefPtr<RawServoDocumentRule> aRawRule)
+ : CSSMozDocumentRule(Servo_DocumentRule_GetRules(aRawRule).Consume())
+ , mRawRule(Move(aRawRule))
+{
+}
+
+ServoDocumentRule::~ServoDocumentRule()
+{
+}
+
+NS_IMPL_ADDREF_INHERITED(ServoDocumentRule, CSSMozDocumentRule)
+NS_IMPL_RELEASE_INHERITED(ServoDocumentRule, CSSMozDocumentRule)
+
+// QueryInterface implementation for MozDocumentRule
+NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(ServoDocumentRule)
+NS_INTERFACE_MAP_END_INHERITING(CSSMozDocumentRule)
+
+/* virtual */ already_AddRefed<css::Rule>
+ServoDocumentRule::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 ServoDocumentRule");
+ return nullptr;
+}
+
+/* virtual */ bool
+ServoDocumentRule::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;
+}
+
+#ifdef DEBUG
+/* virtual */ void
+ServoDocumentRule::List(FILE* out, int32_t aIndent) const
+{
+ nsAutoCString str;
+ for (int32_t i = 0; i < aIndent; i++) {
+ str.AppendLiteral(" ");
+ }
+ Servo_DocumentRule_Debug(mRawRule, &str);
+ fprintf_stderr(out, "%s\n", str.get());
+}
+#endif
+
+// nsIDOMCSSConditionRule methods
+
+NS_IMETHODIMP
+ServoDocumentRule::GetConditionText(nsAString& aConditionText)
+{
+ Servo_DocumentRule_GetConditionText(mRawRule, &aConditionText);
+ return NS_OK;
+}
+
+NS_IMETHODIMP
+ServoDocumentRule::SetConditionText(const nsAString& aConditionText)
+{
+ return NS_ERROR_NOT_IMPLEMENTED;
+}
+
+/* virtual */ void
+ServoDocumentRule::GetCssTextImpl(nsAString& aCssText) const
+{
+ Servo_DocumentRule_GetCssText(mRawRule, &aCssText);
+}
+
+/* virtual */ size_t
+ServoDocumentRule::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf)
+ const
+{
+ // TODO Implement this!
+ return aMallocSizeOf(this);
+}
+
+} // namespace mozilla
new file mode 100644
--- /dev/null
+++ b/layout/style/ServoDocumentRule.h
@@ -0,0 +1,51 @@
+/* -*- 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 CSSMozDocumentRule for stylo */
+
+#ifndef mozilla_ServoMozDocumentRule_h
+#define mozilla_ServoMozDocumentRule_h
+
+#include "mozilla/dom/CSSMozDocumentRule.h"
+#include "mozilla/ServoBindingTypes.h"
+
+namespace mozilla {
+
+class ServoDocumentRule final : public dom::CSSMozDocumentRule
+{
+public:
+ explicit ServoDocumentRule(RefPtr<RawServoDocumentRule> aRawRule);
+
+ NS_DECL_ISUPPORTS_INHERITED
+
+ already_AddRefed<css::Rule> Clone() const override;
+ bool UseForPresentation(nsPresContext* aPresContext,
+ nsMediaQueryResultCacheKey& aKey) final;
+#ifdef DEBUG
+ void List(FILE* out = stdout, int32_t aIndent = 0) const final;
+#endif
+
+ RawServoDocumentRule* Raw() const { return mRawRule; }
+
+ // nsIDOMCSSConditionRule interface
+ NS_DECL_NSIDOMCSSCONDITIONRULE
+
+ // WebIDL interface
+ void GetCssTextImpl(nsAString& aCssText) const override;
+ using CSSMozDocumentRule::SetConditionText;
+
+ size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf)
+ const override;
+
+private:
+ virtual ~ServoDocumentRule();
+
+ RefPtr<RawServoDocumentRule> mRawRule;
+};
+
+} // namespace mozilla
+
+#endif // mozilla_ServoDocumentRule_h
--- a/layout/style/moz.build
+++ b/layout/style/moz.build
@@ -98,16 +98,17 @@ EXPORTS.mozilla += [
'RuleNodeCacheConditions.h',
'RuleProcessorCache.h',
'ServoArcTypeList.h',
'ServoBindingList.h',
'ServoBindings.h',
'ServoBindingTypes.h',
'ServoCSSRuleList.h',
'ServoDeclarationBlock.h',
+ 'ServoDocumentRule.h',
'ServoElementSnapshot.h',
'ServoElementSnapshotTable.h',
'ServoMediaList.h',
'ServoMediaRule.h',
'ServoNamespaceRule.h',
'ServoPageRule.h',
'ServoPropPrefList.h',
'ServoSpecifiedValues.h',
@@ -226,16 +227,17 @@ UNIFIED_SOURCES += [
'nsTransitionManager.cpp',
'PostTraversalTask.cpp',
'PreloadedStyleSheet.cpp',
'RuleNodeCacheConditions.cpp',
'RuleProcessorCache.cpp',
'ServoBindings.cpp',
'ServoCSSRuleList.cpp',
'ServoDeclarationBlock.cpp',
+ 'ServoDocumentRule.cpp',
'ServoElementSnapshot.cpp',
'ServoMediaList.cpp',
'ServoMediaRule.cpp',
'ServoNamespaceRule.cpp',
'ServoPageRule.cpp',
'ServoSpecifiedValues.cpp',
'ServoStyleRule.cpp',
'ServoStyleSet.cpp',