Bug 1729330 - Add a simple CSSLayerRule implementation. r=smaug

The specifics of how this is going to work are still getting spec'd /
discussed in https://github.com/w3c/csswg-drafts/issues/6576, but this
allows DevTools to work fine and the feature to be complete enough for
Nightly experimentation (with the other in-flight patches).

Otherwise devtools crashes when trying to inspect pages that use them.

Differential Revision: https://phabricator.services.mozilla.com/D124656
This commit is contained in:
Emilio Cobos Álvarez 2021-09-08 11:18:32 +00:00
Родитель 1fc2475b41
Коммит 597b7bc37d
54 изменённых файлов: 409 добавлений и 248 удалений

Просмотреть файл

@ -1739,7 +1739,7 @@ bool nsAttrValue::ParseStyleAttribute(const nsAString& aString,
auto data = MakeRefPtr<URLExtraData>(baseURI, referrerInfo, principal);
RefPtr<DeclarationBlock> decl = DeclarationBlock::FromCssText(
aString, data, ownerDoc->GetCompatibilityMode(), ownerDoc->CSSLoader(),
dom::CSSRule_Binding::STYLE_RULE);
StyleCssRuleType::Style);
if (!decl) {
return false;
}

Просмотреть файл

@ -1217,7 +1217,7 @@ void MappedAttrParser::ParseMappedAttrValue(nsAtom* aMappedAttrName,
mDecl->Raw(), propertyID, &value, false, data,
ParsingMode::AllowUnitlessLength,
mElement->OwnerDoc()->GetCompatibilityMode(), mLoader,
CSSRule_Binding::STYLE_RULE, {});
StyleCssRuleType::Style, {});
// TODO(emilio): If we want to record these from CSSOM more generally, we
// can pass the document use counters down the FFI call. For now manually

Просмотреть файл

@ -10,7 +10,7 @@
// https://drafts.csswg.org/cssom/#cssgroupingrule
[Exposed=Window]
interface CSSGroupingRule : CSSRule {
[SameObject] readonly attribute CSSRuleList cssRules;
[SameObject] readonly attribute CSSRuleList? cssRules;
[Throws]
unsigned long insertRule(UTF8String rule, optional unsigned long index = 0);
[Throws]

Просмотреть файл

@ -0,0 +1,12 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/.
*
* This is just scaffolding waiting for
* https://github.com/w3c/csswg-drafts/issues/6576 to get resolved.
*/
[Exposed=Window, Pref="layout.css.cascade-layers.enabled"]
interface CSSLayerRule : CSSGroupingRule {
};

Просмотреть файл

@ -25,7 +25,7 @@ interface CSSRule {
// XXXbz Should we expose the constant anyway?
// const unsigned short MARGIN_RULE = 9;
const unsigned short NAMESPACE_RULE = 10;
readonly attribute unsigned short type;
[BinaryName="typeForBindings"] readonly attribute unsigned short type;
attribute UTF8String cssText;
readonly attribute CSSRule? parentRule;
readonly attribute CSSStyleSheet? parentStyleSheet;

Просмотреть файл

@ -477,6 +477,7 @@ WEBIDL_FILES = [
"CSSImportRule.webidl",
"CSSKeyframeRule.webidl",
"CSSKeyframesRule.webidl",
"CSSLayerRule.webidl",
"CSSMediaRule.webidl",
"CSSMozDocumentRule.webidl",
"CSSNamespaceRule.webidl",

Просмотреть файл

@ -1542,7 +1542,7 @@ nsresult nsXULPrototypeElement::SetAttrAt(uint32_t aPos,
auto data = MakeRefPtr<URLExtraData>(aDocumentURI, referrerInfo, principal);
RefPtr<DeclarationBlock> declaration = DeclarationBlock::FromCssText(
aValue, data, eCompatibility_FullStandards, nullptr,
CSSRule_Binding::STYLE_RULE);
StyleCssRuleType::Style);
if (declaration) {
mAttributes[aPos].mValue.SetTo(declaration.forget(), &aValue);

Просмотреть файл

@ -77,29 +77,29 @@ void ServoStyleRuleMap::RuleRemoved(StyleSheet& aStyleSheet,
}
switch (aStyleRule.Type()) {
case CSSRule_Binding::STYLE_RULE: {
case StyleCssRuleType::Style: {
auto& rule = static_cast<CSSStyleRule&>(aStyleRule);
mTable.Remove(rule.Raw());
break;
}
case CSSRule_Binding::IMPORT_RULE:
case CSSRule_Binding::MEDIA_RULE:
case CSSRule_Binding::SUPPORTS_RULE:
case CSSRule_Binding::DOCUMENT_RULE: {
case StyleCssRuleType::Import:
case StyleCssRuleType::Media:
case StyleCssRuleType::Supports:
case StyleCssRuleType::Layer:
case StyleCssRuleType::Document: {
// See the comment in StyleSheetRemoved.
mTable.Clear();
break;
}
case CSSRule_Binding::FONT_FACE_RULE:
case CSSRule_Binding::PAGE_RULE:
case CSSRule_Binding::KEYFRAMES_RULE:
case CSSRule_Binding::KEYFRAME_RULE:
case CSSRule_Binding::NAMESPACE_RULE:
case CSSRule_Binding::COUNTER_STYLE_RULE:
case CSSRule_Binding::FONT_FEATURE_VALUES_RULE:
case StyleCssRuleType::FontFace:
case StyleCssRuleType::Page:
case StyleCssRuleType::Keyframes:
case StyleCssRuleType::Keyframe:
case StyleCssRuleType::Namespace:
case StyleCssRuleType::CounterStyle:
case StyleCssRuleType::FontFeatureValues:
case StyleCssRuleType::Viewport:
break;
default:
MOZ_ASSERT_UNREACHABLE("Unhandled rule");
}
}
@ -112,25 +112,36 @@ size_t ServoStyleRuleMap::SizeOfIncludingThis(
void ServoStyleRuleMap::FillTableFromRule(css::Rule& aRule) {
switch (aRule.Type()) {
case CSSRule_Binding::STYLE_RULE: {
case StyleCssRuleType::Style: {
auto& rule = static_cast<CSSStyleRule&>(aRule);
mTable.InsertOrUpdate(rule.Raw(), &rule);
break;
}
case CSSRule_Binding::MEDIA_RULE:
case CSSRule_Binding::SUPPORTS_RULE:
case CSSRule_Binding::DOCUMENT_RULE: {
case StyleCssRuleType::Layer:
case StyleCssRuleType::Media:
case StyleCssRuleType::Supports:
case StyleCssRuleType::Document: {
auto& rule = static_cast<css::GroupRule&>(aRule);
auto ruleList = static_cast<ServoCSSRuleList*>(rule.CssRules());
FillTableFromRuleList(*ruleList);
if (ServoCSSRuleList* ruleList = rule.GetCssRules()) {
FillTableFromRuleList(*ruleList);
}
break;
}
case CSSRule_Binding::IMPORT_RULE: {
case StyleCssRuleType::Import: {
auto& rule = static_cast<CSSImportRule&>(aRule);
MOZ_ASSERT(aRule.GetStyleSheet());
FillTableFromStyleSheet(*rule.GetStyleSheet());
break;
}
case StyleCssRuleType::FontFace:
case StyleCssRuleType::Page:
case StyleCssRuleType::Keyframes:
case StyleCssRuleType::Keyframe:
case StyleCssRuleType::Namespace:
case StyleCssRuleType::CounterStyle:
case StyleCssRuleType::FontFeatureValues:
case StyleCssRuleType::Viewport:
break;
}
}

Просмотреть файл

@ -27,8 +27,8 @@ void CSSCounterStyleRule::List(FILE* out, int32_t aIndent) const {
}
#endif
uint16_t CSSCounterStyleRule::Type() const {
return CSSRule_Binding::COUNTER_STYLE_RULE;
StyleCssRuleType CSSCounterStyleRule::Type() const {
return StyleCssRuleType::CounterStyle;
}
void CSSCounterStyleRule::SetRawAfterClone(

Просмотреть файл

@ -12,8 +12,7 @@
struct RawServoCounterStyleRule;
namespace mozilla {
namespace dom {
namespace mozilla::dom {
class CSSCounterStyleRule final : public css::Rule {
public:
@ -41,7 +40,7 @@ class CSSCounterStyleRule final : public css::Rule {
#endif
// WebIDL interface
uint16_t Type() const override;
StyleCssRuleType Type() const override;
void GetCssText(nsACString& aCssText) const override;
void GetName(nsAString& aName);
void SetName(const nsAString& aName);
@ -59,7 +58,6 @@ class CSSCounterStyleRule final : public css::Rule {
RefPtr<RawServoCounterStyleRule> mRawRule;
};
} // namespace dom
} // namespace mozilla
} // namespace mozilla::dom
#endif // mozilla_CSSCounterStyleRule_h

Просмотреть файл

@ -197,8 +197,8 @@ void CSSFontFaceRule::List(FILE* out, int32_t aIndent) const {
}
#endif
uint16_t CSSFontFaceRule::Type() const {
return CSSRule_Binding::FONT_FACE_RULE;
StyleCssRuleType CSSFontFaceRule::Type() const {
return StyleCssRuleType::FontFace;
}
void CSSFontFaceRule::SetRawAfterClone(RefPtr<RawServoFontFaceRule> aRaw) {

Просмотреть файл

@ -11,8 +11,7 @@
#include "mozilla/css/Rule.h"
#include "nsICSSDeclaration.h"
namespace mozilla {
namespace dom {
namespace mozilla::dom {
// A CSSFontFaceRuleDecl is always embeded in a CSSFontFaceRule.
class CSSFontFaceRule;
@ -68,7 +67,7 @@ class CSSFontFaceRule final : public css::Rule {
void SetRawAfterClone(RefPtr<RawServoFontFaceRule>);
// WebIDL interface
uint16_t Type() const final;
StyleCssRuleType Type() const final;
void GetCssText(nsACString& aCssText) const final;
nsICSSDeclaration* Style();
@ -100,7 +99,6 @@ inline const CSSFontFaceRule* CSSFontFaceRuleDecl::ContainingRule() const {
reinterpret_cast<const char*>(this) - offsetof(CSSFontFaceRule, mDecl));
}
} // namespace dom
} // namespace mozilla
} // namespace mozilla::dom
#endif // mozilla_CSSFontFaceRule_h

Просмотреть файл

@ -8,8 +8,7 @@
#include "mozilla/dom/CSSFontFeatureValuesRuleBinding.h"
#include "mozilla/ServoBindings.h"
namespace mozilla {
namespace dom {
namespace mozilla::dom {
size_t CSSFontFeatureValuesRule::SizeOfIncludingThis(
MallocSizeOf aMallocSizeOf) const {
@ -17,6 +16,10 @@ size_t CSSFontFeatureValuesRule::SizeOfIncludingThis(
return aMallocSizeOf(this);
}
StyleCssRuleType CSSFontFeatureValuesRule::Type() const {
return StyleCssRuleType::FontFeatureValues;
}
#ifdef DEBUG
void CSSFontFeatureValuesRule::List(FILE* out, int32_t aIndent) const {
nsAutoCString str;
@ -78,5 +81,4 @@ JSObject* CSSFontFeatureValuesRule::WrapObject(
return CSSFontFeatureValuesRule_Binding::Wrap(aCx, this, aGivenProto);
}
} // namespace dom
} // namespace mozilla
} // namespace mozilla::dom

Просмотреть файл

@ -12,8 +12,7 @@
#include "nsICSSDeclaration.h"
namespace mozilla {
namespace dom {
namespace mozilla::dom {
class CSSFontFeatureValuesRule final : public css::Rule {
public:
@ -29,9 +28,7 @@ class CSSFontFeatureValuesRule final : public css::Rule {
void SetRawAfterClone(RefPtr<RawServoFontFeatureValuesRule> aRaw);
// WebIDL interfaces
uint16_t Type() const final {
return CSSRule_Binding::FONT_FEATURE_VALUES_RULE;
}
StyleCssRuleType Type() const final;
void GetCssText(nsACString& aCssText) const override;
void GetFontFamily(nsACString& aFamily);
@ -55,7 +52,6 @@ class CSSFontFeatureValuesRule final : public css::Rule {
RefPtr<RawServoFontFeatureValuesRule> mRawRule;
};
} // namespace dom
} // namespace mozilla
} // namespace mozilla::dom
#endif // mozilla_dom_CSSFontFeatureValuesRule_h

Просмотреть файл

@ -73,6 +73,10 @@ void CSSImportRule::List(FILE* out, int32_t aIndent) const {
}
#endif
StyleCssRuleType CSSImportRule::Type() const {
return StyleCssRuleType::Import;
}
void CSSImportRule::SetRawAfterClone(RefPtr<RawServoImportRule> aRaw) {
mRawRule = std::move(aRaw);
if (mChildSheet) {

Просмотреть файл

@ -32,7 +32,7 @@ class CSSImportRule final : public css::Rule {
size_t SizeOfIncludingThis(MallocSizeOf) const override;
// WebIDL interface
uint16_t Type() const final { return CSSRule_Binding::IMPORT_RULE; }
StyleCssRuleType Type() const final;
void GetCssText(nsACString& aCssText) const override;
void GetHref(nsAString& aHref) const;
dom::MediaList* GetMedia();

Просмотреть файл

@ -10,8 +10,7 @@
#include "mozilla/dom/CSSKeyframeRuleBinding.h"
#include "nsDOMCSSDeclaration.h"
namespace mozilla {
namespace dom {
namespace mozilla::dom {
// -------------------------------------------
// CSSKeyframeDeclaration
@ -62,7 +61,7 @@ class CSSKeyframeDeclaration : public nsDOMCSSDeclaration {
}
ParsingEnvironment GetParsingEnvironment(
nsIPrincipal* aSubjectPrincipal) const final {
return GetParsingEnvironmentForRule(mRule, CSSRule_Binding::KEYFRAME_RULE);
return GetParsingEnvironmentForRule(mRule, StyleCssRuleType::Keyframe);
}
Document* DocToUpdate() final { return nullptr; }
@ -142,6 +141,10 @@ bool CSSKeyframeRule::IsCCLeaf() const {
return Rule::IsCCLeaf() && !mDeclaration;
}
StyleCssRuleType CSSKeyframeRule::Type() const {
return StyleCssRuleType::Keyframe;
}
void CSSKeyframeRule::SetRawAfterClone(RefPtr<RawServoKeyframe> aRaw) {
mRaw = std::move(aRaw);
@ -214,5 +217,4 @@ JSObject* CSSKeyframeRule::WrapObject(JSContext* aCx,
return CSSKeyframeRule_Binding::Wrap(aCx, this, aGivenProto);
}
} // namespace dom
} // namespace mozilla
} // namespace mozilla::dom

Просмотреть файл

@ -11,10 +11,8 @@
#include "mozilla/ServoBindingTypes.h"
class nsICSSDeclaration;
class DeclarationBlock;
namespace mozilla {
namespace dom {
namespace mozilla::dom {
class CSSKeyframeDeclaration;
@ -35,7 +33,7 @@ class CSSKeyframeRule final : public css::Rule {
void SetRawAfterClone(RefPtr<RawServoKeyframe>);
// WebIDL interface
uint16_t Type() const final { return CSSRule_Binding::KEYFRAME_RULE; }
StyleCssRuleType Type() const final;
void GetCssText(nsACString& aCssText) const final;
void GetKeyText(nsACString& aKey);
void SetKeyText(const nsACString& aKey);
@ -58,7 +56,6 @@ class CSSKeyframeRule final : public css::Rule {
RefPtr<CSSKeyframeDeclaration> mDeclaration;
};
} // namespace dom
} // namespace mozilla
} // namespace mozilla::dom
#endif // mozilla_dom_CSSKeyframeRule_h

Просмотреть файл

@ -13,8 +13,7 @@
#include <limits>
namespace mozilla {
namespace dom {
namespace mozilla::dom {
// -------------------------------------------
// CSSKeyframeList
@ -207,6 +206,10 @@ bool CSSKeyframesRule::IsCCLeaf() const {
return Rule::IsCCLeaf() && !mKeyframeList;
}
StyleCssRuleType CSSKeyframesRule::Type() const {
return StyleCssRuleType::Keyframes;
}
void CSSKeyframesRule::SetRawAfterClone(RefPtr<RawServoKeyframesRule> aRaw) {
mRawRule = std::move(aRaw);
if (mKeyframeList) {
@ -347,5 +350,4 @@ JSObject* CSSKeyframesRule::WrapObject(JSContext* aCx,
return CSSKeyframesRule_Binding::Wrap(aCx, this, aGivenProto);
}
} // namespace dom
} // namespace mozilla
} // namespace mozilla::dom

Просмотреть файл

@ -10,8 +10,7 @@
#include "mozilla/css/Rule.h"
#include "mozilla/dom/CSSKeyframeRule.h"
namespace mozilla {
namespace dom {
namespace mozilla::dom {
class CSSKeyframeList;
@ -32,7 +31,7 @@ class CSSKeyframesRule final : public css::Rule {
void DropSheetReference() final;
// WebIDL interface
uint16_t Type() const final { return CSSRule_Binding::KEYFRAMES_RULE; }
StyleCssRuleType Type() const final;
const RawServoKeyframesRule* Raw() const { return mRawRule.get(); }
void SetRawAfterClone(RefPtr<RawServoKeyframesRule>);
@ -60,7 +59,6 @@ class CSSKeyframesRule final : public css::Rule {
RefPtr<CSSKeyframeList> mKeyframeList; // lazily constructed
};
} // namespace dom
} // namespace mozilla
} // namespace mozilla::dom
#endif // mozilla_dom_CSSKeyframesRule_h

Просмотреть файл

@ -0,0 +1,59 @@
/* -*- 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/CSSLayerRule.h"
#include "mozilla/dom/CSSLayerRuleBinding.h"
#include "mozilla/ServoBindings.h"
namespace mozilla::dom {
CSSLayerRule::CSSLayerRule(RefPtr<RawServoLayerRule> aRawRule,
StyleSheet* aSheet, css::Rule* aParentRule,
uint32_t aLine, uint32_t aColumn)
: css::GroupRule(Servo_LayerRule_GetRules(aRawRule).Consume(), aSheet,
aParentRule, aLine, aColumn),
mRawRule(std::move(aRawRule)) {}
NS_IMPL_ADDREF_INHERITED(CSSLayerRule, GroupRule)
NS_IMPL_RELEASE_INHERITED(CSSLayerRule, GroupRule)
// QueryInterface implementation for SupportsRule
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(CSSLayerRule)
NS_INTERFACE_MAP_END_INHERITING(GroupRule)
#ifdef DEBUG
void CSSLayerRule::List(FILE* out, int32_t aIndent) const {
nsAutoCString str;
for (int32_t i = 0; i < aIndent; i++) {
str.AppendLiteral(" ");
}
Servo_LayerRule_Debug(mRawRule, &str);
fprintf_stderr(out, "%s\n", str.get());
}
#endif
StyleCssRuleType CSSLayerRule::Type() const { return StyleCssRuleType::Layer; }
void CSSLayerRule::SetRawAfterClone(RefPtr<RawServoLayerRule> aRaw) {
mRawRule = std::move(aRaw);
css::GroupRule::SetRawAfterClone(
Servo_LayerRule_GetRules(mRawRule).Consume());
}
void CSSLayerRule::GetCssText(nsACString& aCssText) const {
Servo_LayerRule_GetCssText(mRawRule.get(), &aCssText);
}
size_t CSSLayerRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const {
return aMallocSizeOf(this);
}
JSObject* CSSLayerRule::WrapObject(JSContext* aCx,
JS::Handle<JSObject*> aGivenProto) {
return CSSLayerRule_Binding::Wrap(aCx, this, aGivenProto);
}
} // namespace mozilla::dom

Просмотреть файл

@ -0,0 +1,44 @@
/* -*- 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_CSSLayerRule_h
#define mozilla_dom_CSSLayerRule_h
#include "mozilla/css/GroupRule.h"
#include "mozilla/ServoBindingTypes.h"
namespace mozilla::dom {
class CSSLayerRule : public css::GroupRule {
public:
CSSLayerRule(RefPtr<RawServoLayerRule> aRawRule, StyleSheet* aSheet,
css::Rule* aParentRule, uint32_t aLine, uint32_t aColumn);
NS_DECL_ISUPPORTS_INHERITED
#ifdef DEBUG
void List(FILE* out = stdout, int32_t aIndent = 0) const final;
#endif
RawServoLayerRule* Raw() const { return mRawRule; }
void SetRawAfterClone(RefPtr<RawServoLayerRule>);
// WebIDL interface
StyleCssRuleType Type() const final;
void GetCssText(nsACString& aCssText) const final;
size_t SizeOfIncludingThis(MallocSizeOf) const override;
JSObject* WrapObject(JSContext*, JS::Handle<JSObject*>) override;
private:
~CSSLayerRule() = default;
RefPtr<RawServoLayerRule> mRawRule;
};
} // namespace mozilla::dom
#endif // mozilla_dom_CSSLayerRule_h

Просмотреть файл

@ -10,8 +10,7 @@
#include "mozilla/dom/MediaList.h"
#include "mozilla/ServoBindings.h"
namespace mozilla {
namespace dom {
namespace mozilla::dom {
CSSMediaRule::CSSMediaRule(RefPtr<RawServoMediaRule> aRawRule,
StyleSheet* aSheet, css::Rule* aParentRule,
@ -67,6 +66,8 @@ void CSSMediaRule::SetRawAfterClone(RefPtr<RawServoMediaRule> aRaw) {
Servo_MediaRule_GetRules(mRawRule).Consume());
}
StyleCssRuleType CSSMediaRule::Type() const { return StyleCssRuleType::Media; }
#ifdef DEBUG
/* virtual */
void CSSMediaRule::List(FILE* out, int32_t aIndent) const {
@ -116,5 +117,4 @@ JSObject* CSSMediaRule::WrapObject(JSContext* aCx,
return CSSMediaRule_Binding::Wrap(aCx, this, aGivenProto);
}
} // namespace dom
} // namespace mozilla
} // namespace mozilla::dom

Просмотреть файл

@ -31,7 +31,7 @@ class CSSMediaRule final : public css::ConditionRule {
void SetRawAfterClone(RefPtr<RawServoMediaRule>);
// WebIDL interface
uint16_t Type() const override { return CSSRule_Binding::MEDIA_RULE; }
StyleCssRuleType Type() const override;
// WebIDL interface
void GetCssText(nsACString& aCssText) const final;
void GetConditionText(nsACString& aConditionText) final;

Просмотреть файл

@ -12,8 +12,7 @@
#include "nsContentUtils.h"
#include "nsHTMLDocument.h"
namespace mozilla {
namespace dom {
namespace mozilla::dom {
using namespace mozilla::css;
@ -115,6 +114,10 @@ void CSSMozDocumentRule::SetRawAfterClone(
Servo_MozDocumentRule_GetRules(mRawRule).Consume());
}
StyleCssRuleType CSSMozDocumentRule::Type() const {
return StyleCssRuleType::Document;
}
void CSSMozDocumentRule::GetConditionText(nsACString& aConditionText) {
Servo_MozDocumentRule_GetConditionText(mRawRule, &aConditionText);
}
@ -140,5 +143,4 @@ size_t CSSMozDocumentRule::SizeOfIncludingThis(
return aMallocSizeOf(this);
}
} // namespace dom
} // namespace mozilla
} // namespace mozilla::dom

Просмотреть файл

@ -34,7 +34,7 @@ class CSSMozDocumentRule final : public css::ConditionRule {
void SetRawAfterClone(RefPtr<RawServoMozDocumentRule>);
// WebIDL interface
uint16_t Type() const final { return CSSRule_Binding::DOCUMENT_RULE; }
StyleCssRuleType Type() const final;
void GetCssText(nsACString& aCssText) const final;
void GetConditionText(nsACString& aConditionText) final;
void SetConditionText(const nsACString& aConditionText,

Просмотреть файл

@ -8,9 +8,7 @@
#include "mozilla/ServoBindings.h"
using namespace mozilla::dom;
namespace mozilla {
namespace mozilla::dom {
CSSNamespaceRule::~CSSNamespaceRule() = default;
@ -25,6 +23,10 @@ void CSSNamespaceRule::List(FILE* out, int32_t aIndent) const {
}
#endif
StyleCssRuleType CSSNamespaceRule::Type() const {
return StyleCssRuleType::Namespace;
}
nsAtom* CSSNamespaceRule::GetPrefix() const {
return Servo_NamespaceRule_GetPrefix(mRawRule);
}
@ -46,4 +48,4 @@ size_t CSSNamespaceRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const {
return aMallocSizeOf(this);
}
} // namespace mozilla
} // namespace mozilla::dom

Просмотреть файл

@ -36,8 +36,7 @@ class CSSNamespaceRule final : public css::Rule {
// WebIDL interface
void GetCssText(nsACString& aCssText) const final;
// WebIDL interfaces
uint16_t Type() const final { return CSSRule_Binding::NAMESPACE_RULE; }
StyleCssRuleType Type() const final;
const RawServoNamespaceRule* Raw() const { return mRawRule.get(); }
void SetRawAfterClone(RefPtr<RawServoNamespaceRule>);

Просмотреть файл

@ -10,8 +10,7 @@
#include "mozilla/DeclarationBlock.h"
#include "mozilla/ServoBindings.h"
namespace mozilla {
namespace dom {
namespace mozilla::dom {
// -- CSSPageRuleDeclaration ---------------------------------------
@ -87,7 +86,7 @@ nsresult CSSPageRuleDeclaration::SetCSSDeclaration(
nsDOMCSSDeclaration::ParsingEnvironment
CSSPageRuleDeclaration::GetParsingEnvironment(
nsIPrincipal* aSubjectPrincipal) const {
return GetParsingEnvironmentForRule(Rule(), CSSRule_Binding::PAGE_RULE);
return GetParsingEnvironmentForRule(Rule(), StyleCssRuleType::Page);
}
// -- CSSPageRule --------------------------------------------------
@ -144,6 +143,8 @@ void CSSPageRule::SetRawAfterClone(RefPtr<RawServoPageRule> aRaw) {
mDecls.SetRawAfterClone(Servo_PageRule_GetStyle(mRawRule.get()).Consume());
}
StyleCssRuleType CSSPageRule::Type() const { return StyleCssRuleType::Page; }
size_t CSSPageRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const {
// TODO Implement this!
return aMallocSizeOf(this);
@ -175,5 +176,4 @@ JSObject* CSSPageRule::WrapObject(JSContext* aCx,
return CSSPageRule_Binding::Wrap(aCx, this, aGivenProto);
}
} // namespace dom
} // namespace mozilla
} // namespace mozilla::dom

Просмотреть файл

@ -67,7 +67,7 @@ class CSSPageRule final : public css::Rule {
void SetRawAfterClone(RefPtr<RawServoPageRule>);
// WebIDL interfaces
uint16_t Type() const final { return CSSRule_Binding::PAGE_RULE; }
StyleCssRuleType Type() const final;
void GetCssText(nsACString& aCssText) const final;
nsICSSDeclaration* Style();

Просмотреть файл

@ -16,10 +16,7 @@
#include "mozAutoDocUpdate.h"
#include "nsISupports.h"
using namespace mozilla::dom;
namespace mozilla {
namespace dom {
namespace mozilla::dom {
// -- CSSStyleRuleDeclaration ---------------------------------------
@ -104,7 +101,7 @@ Document* CSSStyleRuleDeclaration::DocToUpdate() { return nullptr; }
nsDOMCSSDeclaration::ParsingEnvironment
CSSStyleRuleDeclaration::GetParsingEnvironment(
nsIPrincipal* aSubjectPrincipal) const {
return GetParsingEnvironmentForRule(Rule(), CSSRule_Binding::STYLE_RULE);
return GetParsingEnvironmentForRule(Rule(), StyleCssRuleType::Style);
}
// -- CSSStyleRule --------------------------------------------------
@ -175,6 +172,8 @@ void CSSStyleRule::List(FILE* out, int32_t aIndent) const {
/* CSSRule implementation */
StyleCssRuleType CSSStyleRule::Type() const { return StyleCssRuleType::Style; }
void CSSStyleRule::GetCssText(nsACString& aCssText) const {
Servo_StyleRule_GetCssText(mRawRule, &aCssText);
}
@ -243,5 +242,4 @@ NotNull<DeclarationBlock*> CSSStyleRule::GetDeclarationBlock() const {
return WrapNotNull(mDecls.mDecls);
}
} // namespace dom
} // namespace mozilla
} // namespace mozilla::dom

Просмотреть файл

@ -76,7 +76,7 @@ class CSSStyleRule final : public BindingStyleRule, public SupportsWeakPtr {
NotNull<DeclarationBlock*> GetDeclarationBlock() const override;
// WebIDL interface
uint16_t Type() const final { return dom::CSSRule_Binding::STYLE_RULE; }
StyleCssRuleType Type() const final;
void GetCssText(nsACString& aCssText) const final;
void GetSelectorText(nsACString& aSelectorText) final;
void SetSelectorText(const nsACString& aSelectorText) final;

Просмотреть файл

@ -12,8 +12,7 @@
using namespace mozilla::css;
namespace mozilla {
namespace dom {
namespace mozilla::dom {
CSSSupportsRule::CSSSupportsRule(RefPtr<RawServoSupportsRule> aRawRule,
StyleSheet* aSheet, css::Rule* aParentRule,
@ -41,6 +40,10 @@ void CSSSupportsRule::List(FILE* out, int32_t aIndent) const {
}
#endif
StyleCssRuleType CSSSupportsRule::Type() const {
return StyleCssRuleType::Supports;
}
void CSSSupportsRule::GetConditionText(nsACString& aConditionText) {
Servo_SupportsRule_GetConditionText(mRawRule, &aConditionText);
}
@ -78,5 +81,4 @@ JSObject* CSSSupportsRule::WrapObject(JSContext* aCx,
return CSSSupportsRule_Binding::Wrap(aCx, this, aGivenProto);
}
} // namespace dom
} // namespace mozilla
} // namespace mozilla::dom

Просмотреть файл

@ -28,7 +28,7 @@ class CSSSupportsRule : public css::ConditionRule {
void SetRawAfterClone(RefPtr<RawServoSupportsRule>);
// WebIDL interface
uint16_t Type() const override { return CSSRule_Binding::SUPPORTS_RULE; }
StyleCssRuleType Type() const final;
void GetCssText(nsACString& aCssText) const final;
void GetConditionText(nsACString& aConditionText) final;
void SetConditionText(const nsACString& aConditionText,

Просмотреть файл

@ -148,7 +148,7 @@ class DeclarationBlock final {
static already_AddRefed<DeclarationBlock> FromCssText(
const nsACString& aCssText, URLExtraData* aExtraData,
nsCompatibility aMode, css::Loader* aLoader, uint16_t aRuleType) {
nsCompatibility aMode, css::Loader* aLoader, StyleCssRuleType aRuleType) {
RefPtr<RawServoDeclarationBlock> raw =
Servo_ParseStyleAttribute(&aCssText, aExtraData, aMode, aLoader,
aRuleType)
@ -158,7 +158,7 @@ class DeclarationBlock final {
static already_AddRefed<DeclarationBlock> FromCssText(
const nsAString& aCssText, URLExtraData* aExtraData,
nsCompatibility aMode, css::Loader* aLoader, uint16_t aRuleType) {
nsCompatibility aMode, css::Loader* aLoader, StyleCssRuleType aRuleType) {
NS_ConvertUTF16toUTF8 value(aCssText);
return FromCssText(value, aExtraData, aMode, aLoader, aRuleType);
}

Просмотреть файл

@ -17,8 +17,7 @@
using namespace mozilla::dom;
namespace mozilla {
namespace css {
namespace mozilla::css {
GroupRule::GroupRule(already_AddRefed<ServoCssRules> aRules, StyleSheet* aSheet,
Rule* aParentRule, uint32_t aLineNumber,
@ -135,5 +134,4 @@ size_t GroupRule::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const {
return 0;
}
} // namespace css
} // namespace mozilla
} // namespace mozilla::css

Просмотреть файл

@ -49,14 +49,18 @@ class GroupRule : public Rule {
void DropSheetReference() override;
public:
int32_t StyleRuleCount() const { return mRuleList->Length(); }
int32_t StyleRuleCount() const { return mRuleList ? mRuleList->Length() : 0; }
Rule* GetStyleRuleAt(int32_t aIndex) const {
return mRuleList->GetRule(aIndex);
return mRuleList ? mRuleList->GetRule(aIndex) : nullptr;
}
void SetRawAfterClone(RefPtr<ServoCssRules> aRules) {
mRuleList->SetRawAfterClone(std::move(aRules));
if (mRuleList) {
mRuleList->SetRawAfterClone(std::move(aRules));
} else {
MOZ_ASSERT(!aRules, "Can't move from having no rules to having rules");
}
}
/*
@ -64,6 +68,9 @@ class GroupRule : public Rule {
* WillDirty() on the parent stylesheet.
*/
nsresult DeleteStyleRuleAt(uint32_t aIndex) {
if (!mRuleList) {
return NS_OK;
}
return mRuleList->DeleteRule(aIndex);
}
@ -72,7 +79,7 @@ class GroupRule : public Rule {
size_t SizeOfIncludingThis(MallocSizeOf) const override = 0;
// WebIDL API
dom::CSSRuleList* CssRules() { return mRuleList; }
ServoCSSRuleList* GetCssRules() { return mRuleList; }
uint32_t InsertRule(const nsACString& aRule, uint32_t aIndex,
ErrorResult& aRv);
void DeleteRule(uint32_t aIndex, ErrorResult& aRv);

Просмотреть файл

@ -15,12 +15,12 @@
#include "mozilla/dom/Document.h"
#include "mozilla/HoldDropJSObjects.h"
#include "nsWrapperCacheInlines.h"
#include "mozilla/ServoBindings.h"
using namespace mozilla;
using namespace mozilla::dom;
namespace mozilla {
namespace css {
namespace mozilla::css {
NS_IMPL_CYCLE_COLLECTING_ADDREF(Rule)
NS_IMPL_CYCLE_COLLECTING_RELEASE(Rule)
@ -93,6 +93,21 @@ void Rule::SetCssText(const nsACString& aCssText) {
Rule* Rule::GetParentRule() const { return mParentRule; }
#ifdef DEBUG
void Rule::AssertParentRuleType() {
// Would be nice to check that this->Type() is KEYFRAME_RULE when
// mParentRule->Tye() is KEYFRAMES_RULE, but we can't call
// this->Type() here since it's virtual.
if (mParentRule) {
auto type = mParentRule->Type();
MOZ_ASSERT(
type == StyleCssRuleType::Media || type == StyleCssRuleType::Document ||
type == StyleCssRuleType::Supports ||
type == StyleCssRuleType::Keyframes || type == StyleCssRuleType::Layer);
}
}
#endif
bool Rule::IsReadOnly() const {
MOZ_ASSERT(!mSheet || !mParentRule ||
mSheet->IsReadOnly() == mParentRule->IsReadOnly(),
@ -102,12 +117,11 @@ bool Rule::IsReadOnly() const {
}
bool Rule::IsIncompleteImportRule() const {
if (Type() != CSSRule_Binding::IMPORT_RULE) {
if (Type() != StyleCssRuleType::Import) {
return false;
}
auto* sheet = static_cast<const dom::CSSImportRule*>(this)->GetStyleSheet();
return !sheet || !sheet->IsComplete();
}
} // namespace css
} // namespace mozilla
} // namespace mozilla::css

Просмотреть файл

@ -22,6 +22,9 @@ struct already_AddRefed;
class nsHTMLCSSStyleSheet;
namespace mozilla {
enum class StyleCssRuleType : uint8_t;
namespace css {
class GroupRule;
@ -34,19 +37,14 @@ class Rule : public nsISupports, public nsWrapperCache {
mLineNumber(aLineNumber),
mColumnNumber(aColumnNumber) {
#ifdef DEBUG
// Would be nice to check that this->Type() is KEYFRAME_RULE when
// mParentRule->Tye() is KEYFRAMES_RULE, but we can't call
// this->Type() here since it's virtual.
if (mParentRule) {
int16_t type = mParentRule->Type();
MOZ_ASSERT(type == dom::CSSRule_Binding::MEDIA_RULE ||
type == dom::CSSRule_Binding::DOCUMENT_RULE ||
type == dom::CSSRule_Binding::SUPPORTS_RULE ||
type == dom::CSSRule_Binding::KEYFRAMES_RULE);
}
AssertParentRuleType();
#endif
}
#ifdef DEBUG
void AssertParentRuleType();
#endif
Rule(const Rule& aCopy)
: mSheet(aCopy.mSheet),
mParentRule(aCopy.mParentRule),
@ -93,8 +91,15 @@ class Rule : public nsISupports, public nsWrapperCache {
// thus measured elsewhere.
virtual size_t SizeOfIncludingThis(MallocSizeOf) const MOZ_MUST_OVERRIDE = 0;
virtual StyleCssRuleType Type() const = 0;
// WebIDL interface
virtual uint16_t Type() const = 0;
uint16_t TypeForBindings() const {
auto type = uint16_t(Type());
// Per https://drafts.csswg.org/cssom/#dom-cssrule-type for constants > 15
// we return 0.
return type > 15 ? 0 : type;
}
virtual void GetCssText(nsACString& aCssText) const = 0;
void SetCssText(const nsACString& aCssText);
Rule* GetParentRule() const;

Просмотреть файл

@ -30,6 +30,7 @@ SERVO_ARC_TYPE(ImportRule, RawServoImportRule)
SERVO_ARC_TYPE(AnimationValue, RawServoAnimationValue)
SERVO_ARC_TYPE(Keyframe, RawServoKeyframe)
SERVO_ARC_TYPE(KeyframesRule, RawServoKeyframesRule)
SERVO_ARC_TYPE(LayerRule, RawServoLayerRule)
SERVO_ARC_TYPE(MediaList, RawServoMediaList)
SERVO_ARC_TYPE(MediaRule, RawServoMediaRule)
SERVO_ARC_TYPE(NamespaceRule, RawServoNamespaceRule)

Просмотреть файл

@ -61,6 +61,7 @@ GROUP_RULE_FUNCS(MozDocument)
BASIC_RULE_FUNCS(Namespace)
BASIC_RULE_FUNCS(Page)
GROUP_RULE_FUNCS(Supports)
GROUP_RULE_FUNCS(Layer)
BASIC_RULE_FUNCS(FontFeatureValues)
BASIC_RULE_FUNCS(FontFace)
BASIC_RULE_FUNCS(CounterStyle)

Просмотреть файл

@ -12,6 +12,7 @@
#include "mozilla/dom/CSSFontFaceRule.h"
#include "mozilla/dom/CSSFontFeatureValuesRule.h"
#include "mozilla/dom/CSSImportRule.h"
#include "mozilla/dom/CSSLayerRule.h"
#include "mozilla/dom/CSSKeyframesRule.h"
#include "mozilla/dom/CSSMediaRule.h"
#include "mozilla/dom/CSSMozDocumentRule.h"
@ -61,9 +62,9 @@ css::Rule* ServoCSSRuleList::GetRule(uint32_t aIndex) {
uintptr_t rule = mRules[aIndex];
if (rule <= kMaxRuleType) {
RefPtr<css::Rule> ruleObj = nullptr;
switch (rule) {
switch (StyleCssRuleType(rule)) {
#define CASE_RULE(const_, name_) \
case CSSRule_Binding::const_##_RULE: { \
case StyleCssRuleType::const_: { \
uint32_t line = 0, column = 0; \
RefPtr<RawServo##name_##Rule> raw = \
Servo_CssRules_Get##name_##RuleAt(mRawRules, aIndex, &line, &column) \
@ -71,26 +72,27 @@ css::Rule* ServoCSSRuleList::GetRule(uint32_t aIndex) {
MOZ_ASSERT(raw); \
ruleObj = new CSS##name_##Rule(raw.forget(), mStyleSheet, mParentRule, \
line, column); \
MOZ_ASSERT(ruleObj->Type() == rule); \
MOZ_ASSERT(ruleObj->Type() == StyleCssRuleType(rule)); \
break; \
}
CASE_RULE(STYLE, Style)
CASE_RULE(KEYFRAMES, Keyframes)
CASE_RULE(MEDIA, Media)
CASE_RULE(NAMESPACE, Namespace)
CASE_RULE(PAGE, Page)
CASE_RULE(SUPPORTS, Supports)
CASE_RULE(DOCUMENT, MozDocument)
CASE_RULE(IMPORT, Import)
CASE_RULE(FONT_FEATURE_VALUES, FontFeatureValues)
CASE_RULE(FONT_FACE, FontFace)
CASE_RULE(COUNTER_STYLE, CounterStyle)
CASE_RULE(Style, Style)
CASE_RULE(Keyframes, Keyframes)
CASE_RULE(Media, Media)
CASE_RULE(Namespace, Namespace)
CASE_RULE(Page, Page)
CASE_RULE(Supports, Supports)
CASE_RULE(Document, MozDocument)
CASE_RULE(Import, Import)
CASE_RULE(FontFeatureValues, FontFeatureValues)
CASE_RULE(FontFace, FontFace)
CASE_RULE(CounterStyle, CounterStyle)
CASE_RULE(Layer, Layer)
#undef CASE_RULE
case CSSRule_Binding::KEYFRAME_RULE:
MOZ_ASSERT_UNREACHABLE("keyframe rule cannot be here");
case StyleCssRuleType::Viewport:
MOZ_ASSERT_UNREACHABLE("viewport is not implemented in Gecko");
return nullptr;
default:
NS_WARNING("stylo: not implemented yet");
case StyleCssRuleType::Keyframe:
MOZ_ASSERT_UNREACHABLE("keyframe rule cannot be here");
return nullptr;
}
rule = CastToUint(ruleObj.forget().take());
@ -184,14 +186,14 @@ nsresult ServoCSSRuleList::InsertRule(const nsACString& aRule,
if (Document* doc = mStyleSheet->GetAssociatedDocument()) {
loader = doc->CSSLoader();
}
uint16_t type;
StyleCssRuleType type;
nsresult rv = Servo_CssRules_InsertRule(mRawRules, mStyleSheet->RawContents(),
&aRule, aIndex, nested, loader,
allowImportRules, mStyleSheet, &type);
if (NS_FAILED(rv)) {
return rv;
}
mRules.InsertElementAt(aIndex, type);
mRules.InsertElementAt(aIndex, uintptr_t(type));
return rv;
}
@ -211,19 +213,11 @@ nsresult ServoCSSRuleList::DeleteRule(uint32_t aIndex) {
return rv;
}
uint16_t ServoCSSRuleList::GetDOMCSSRuleType(uint32_t aIndex) const {
uintptr_t rule = mRules[aIndex];
if (rule <= kMaxRuleType) {
return rule;
}
return CastToPtr(rule)->Type();
}
void ServoCSSRuleList::SetRawAfterClone(RefPtr<ServoCssRules> aNewRules) {
mRawRules = std::move(aNewRules);
EnumerateInstantiatedRules([&](css::Rule* aRule, uint32_t aIndex) {
#define CASE_FOR(constant_, type_) \
case CSSRule_Binding::constant_##_RULE: { \
case StyleCssRuleType::constant_: { \
uint32_t line = 0, column = 0; \
RefPtr<RawServo##type_##Rule> raw = \
Servo_CssRules_Get##type_##RuleAt(mRawRules, aIndex, &line, &column) \
@ -233,22 +227,23 @@ void ServoCSSRuleList::SetRawAfterClone(RefPtr<ServoCssRules> aNewRules) {
break; \
}
switch (aRule->Type()) {
CASE_FOR(STYLE, Style)
CASE_FOR(KEYFRAMES, Keyframes)
CASE_FOR(MEDIA, Media)
CASE_FOR(NAMESPACE, Namespace)
CASE_FOR(PAGE, Page)
CASE_FOR(SUPPORTS, Supports)
CASE_FOR(DOCUMENT, MozDocument)
CASE_FOR(IMPORT, Import)
CASE_FOR(FONT_FEATURE_VALUES, FontFeatureValues)
CASE_FOR(FONT_FACE, FontFace)
CASE_FOR(COUNTER_STYLE, CounterStyle)
case CSSRule_Binding::KEYFRAME_RULE:
CASE_FOR(Style, Style)
CASE_FOR(Keyframes, Keyframes)
CASE_FOR(Media, Media)
CASE_FOR(Namespace, Namespace)
CASE_FOR(Page, Page)
CASE_FOR(Supports, Supports)
CASE_FOR(Document, MozDocument)
CASE_FOR(Import, Import)
CASE_FOR(FontFeatureValues, FontFeatureValues)
CASE_FOR(FontFace, FontFace)
CASE_FOR(CounterStyle, CounterStyle)
CASE_FOR(Layer, Layer)
case StyleCssRuleType::Keyframe:
MOZ_ASSERT_UNREACHABLE("keyframe rule cannot be here");
break;
default:
MOZ_ASSERT_UNREACHABLE("Which rule do we have here?");
case StyleCssRuleType::Viewport:
MOZ_ASSERT_UNREACHABLE("Gecko doesn't implemente @viewport?");
break;
}
#undef CASE_FOR

Просмотреть файл

@ -48,8 +48,6 @@ class ServoCSSRuleList final : public dom::CSSRuleList {
nsresult InsertRule(const nsACString& aRule, uint32_t aIndex);
nsresult DeleteRule(uint32_t aIndex);
uint16_t GetDOMCSSRuleType(uint32_t aIndex) const;
void SetRawAfterClone(RefPtr<ServoCssRules>);
private:

Просмотреть файл

@ -41,6 +41,7 @@ template struct StyleStrong<RawServoAnimationValue>;
template struct StyleStrong<RawServoDeclarationBlock>;
template struct StyleStrong<RawServoStyleSheetContents>;
template struct StyleStrong<RawServoKeyframe>;
template struct StyleStrong<RawServoLayerRule>;
template struct StyleStrong<RawServoMediaList>;
template struct StyleStrong<RawServoStyleRule>;
template struct StyleStrong<RawServoImportRule>;

Просмотреть файл

@ -906,34 +906,34 @@ void ServoStyleSet::RuleChangedInternal(StyleSheet& aSheet, css::Rule& aRule,
SetStylistStyleSheetsDirty();
#define CASE_FOR(constant_, type_) \
case CSSRule_Binding::constant_##_RULE: \
case StyleCssRuleType::constant_: \
return Servo_StyleSet_##type_##RuleChanged( \
mRawSet.get(), static_cast<dom::CSS##type_##Rule&>(aRule).Raw(), \
&aSheet, aKind);
switch (aRule.Type()) {
CASE_FOR(COUNTER_STYLE, CounterStyle)
CASE_FOR(STYLE, Style)
CASE_FOR(IMPORT, Import)
CASE_FOR(MEDIA, Media)
CASE_FOR(KEYFRAMES, Keyframes)
CASE_FOR(FONT_FEATURE_VALUES, FontFeatureValues)
CASE_FOR(FONT_FACE, FontFace)
CASE_FOR(PAGE, Page)
CASE_FOR(DOCUMENT, MozDocument)
CASE_FOR(SUPPORTS, Supports)
CASE_FOR(CounterStyle, CounterStyle)
CASE_FOR(Style, Style)
CASE_FOR(Import, Import)
CASE_FOR(Media, Media)
CASE_FOR(Keyframes, Keyframes)
CASE_FOR(FontFeatureValues, FontFeatureValues)
CASE_FOR(FontFace, FontFace)
CASE_FOR(Page, Page)
CASE_FOR(Document, MozDocument)
CASE_FOR(Supports, Supports)
CASE_FOR(Layer, Layer)
// @namespace can only be inserted / removed when there are only other
// @namespace and @import rules, and can't be mutated.
case CSSRule_Binding::NAMESPACE_RULE:
case CSSRule_Binding::CHARSET_RULE:
case StyleCssRuleType::Namespace:
break;
case CSSRule_Binding::KEYFRAME_RULE:
case StyleCssRuleType::Viewport:
MOZ_ASSERT_UNREACHABLE("Gecko doesn't implement @viewport");
break;
case StyleCssRuleType::Keyframe:
// FIXME: We should probably just forward to the parent @keyframes rule? I
// think that'd do the right thing, but meanwhile...
return MarkOriginsDirty(ToOriginFlags(aSheet.GetOrigin()));
default:
MOZ_ASSERT_UNREACHABLE("Unknown rule type changed");
return MarkOriginsDirty(ToOriginFlags(aSheet.GetOrigin()));
}
#undef CASE_FOR

Просмотреть файл

@ -1447,8 +1447,8 @@ nsresult StyleSheet::InsertRuleIntoGroupInternal(const nsACString& aRule,
uint32_t aIndex) {
MOZ_ASSERT(!IsReadOnly());
auto rules = static_cast<ServoCSSRuleList*>(aGroup->CssRules());
MOZ_ASSERT(rules->GetParentRule() == aGroup);
ServoCSSRuleList* rules = aGroup->GetCssRules();
MOZ_ASSERT(rules && rules->GetParentRule() == aGroup);
return rules->InsertRule(aRule, aIndex);
}

Просмотреть файл

@ -126,6 +126,7 @@ EXPORTS.mozilla.dom += [
"CSSImportRule.h",
"CSSKeyframeRule.h",
"CSSKeyframesRule.h",
"CSSLayerRule.h",
"CSSMediaRule.h",
"CSSMozDocumentRule.h",
"CSSNamespaceRule.h",
@ -168,6 +169,7 @@ UNIFIED_SOURCES += [
"CSSImportRule.cpp",
"CSSKeyframeRule.cpp",
"CSSKeyframesRule.cpp",
"CSSLayerRule.cpp",
"CSSMediaRule.cpp",
"CSSMozDocumentRule.cpp",
"CSSNamespaceRule.cpp",

Просмотреть файл

@ -238,7 +238,7 @@ void nsDOMCSSDeclaration::RemoveProperty(const nsACString& aPropertyName,
/* static */ nsDOMCSSDeclaration::ParsingEnvironment
nsDOMCSSDeclaration::GetParsingEnvironmentForRule(const css::Rule* aRule,
uint16_t aRuleType) {
StyleCssRuleType aRuleType) {
if (!aRule) {
return {};
}

Просмотреть файл

@ -23,6 +23,7 @@ struct JSContext;
class JSObject;
namespace mozilla {
enum class StyleCssRuleType : uint8_t;
class DeclarationBlock;
struct DeclarationBlockMutationClosure;
namespace css {
@ -132,7 +133,7 @@ class nsDOMCSSDeclaration : public nsICSSDeclaration {
RefPtr<mozilla::URLExtraData> mUrlExtraData;
nsCompatibility mCompatMode = eCompatibility_FullStandards;
mozilla::css::Loader* mLoader = nullptr;
uint16_t mRuleType{0};
mozilla::StyleCssRuleType mRuleType{1 /* Style */};
};
protected:
@ -182,7 +183,7 @@ class nsDOMCSSDeclaration : public nsICSSDeclaration {
// The RuleType argument is just to avoid a virtual call, since all callers
// know it statically. Should be equal to aRule->Type().
static ParsingEnvironment GetParsingEnvironmentForRule(
const mozilla::css::Rule* aRule, uint16_t aRuleType);
const mozilla::css::Rule* aRule, mozilla::StyleCssRuleType);
nsresult ParsePropertyValue(const nsCSSPropertyID aPropID,
const nsACString& aPropValue, bool aIsImportant,

Просмотреть файл

@ -22,6 +22,7 @@
#include "nsTHashtable.h"
class nsIPrincipal;
class nsITimer;
class nsFontFaceLoader final : public nsIStreamLoaderObserver,
public nsIRequestObserver,

Просмотреть файл

@ -51,7 +51,7 @@ static void ServoParsingBench(const StyleUseCounters* aCounters) {
}
}
static constexpr uint16_t STYLE_RULE = 1;
static constexpr auto STYLE_RULE = StyleCssRuleType::Style;
static void ServoSetPropertyByIdBench(const nsACString& css) {
RefPtr<RawServoDeclarationBlock> block =

Просмотреть файл

@ -9,34 +9,26 @@
#![allow(non_snake_case, missing_docs)]
use crate::gecko::url::CssUrlData;
use crate::gecko_bindings::structs::RawServoAnimationValue;
use crate::gecko_bindings::structs::RawServoCounterStyleRule;
use crate::gecko_bindings::structs::RawServoCssUrlData;
use crate::gecko_bindings::structs::RawServoDeclarationBlock;
use crate::gecko_bindings::structs::RawServoFontFaceRule;
use crate::gecko_bindings::structs::RawServoFontFeatureValuesRule;
use crate::gecko_bindings::structs::RawServoImportRule;
use crate::gecko_bindings::structs::RawServoKeyframe;
use crate::gecko_bindings::structs::RawServoKeyframesRule;
use crate::gecko_bindings::structs::RawServoMediaList;
use crate::gecko_bindings::structs::RawServoMediaRule;
use crate::gecko_bindings::structs::RawServoMozDocumentRule;
use crate::gecko_bindings::structs::RawServoNamespaceRule;
use crate::gecko_bindings::structs::RawServoPageRule;
use crate::gecko_bindings::structs::RawServoStyleRule;
use crate::gecko_bindings::structs::RawServoStyleSheetContents;
use crate::gecko_bindings::structs::RawServoSupportsRule;
use crate::gecko_bindings::structs::ServoCssRules;
use crate::gecko_bindings::structs::{
RawServoAnimationValue, RawServoCounterStyleRule, RawServoCssUrlData,
RawServoDeclarationBlock, RawServoFontFaceRule,
RawServoFontFeatureValuesRule, RawServoImportRule, RawServoKeyframe,
RawServoKeyframesRule, RawServoLayerRule, RawServoMediaList,
RawServoMediaRule, RawServoMozDocumentRule, RawServoNamespaceRule,
RawServoPageRule, RawServoStyleRule, RawServoStyleSheetContents,
RawServoSupportsRule, ServoCssRules
};
use crate::gecko_bindings::sugar::ownership::{HasArcFFI, HasFFI, Strong};
use crate::media_queries::MediaList;
use crate::properties::animated_properties::AnimationValue;
use crate::properties::{ComputedValues, PropertyDeclarationBlock};
use crate::shared_lock::Locked;
use crate::stylesheets::keyframes_rule::Keyframe;
use crate::stylesheets::{CounterStyleRule, CssRules, FontFaceRule, FontFeatureValuesRule};
use crate::stylesheets::{DocumentRule, ImportRule, KeyframesRule, MediaRule};
use crate::stylesheets::{NamespaceRule, PageRule};
use crate::stylesheets::{StyleRule, StylesheetContents, SupportsRule};
use crate::stylesheets::{
CounterStyleRule, CssRules, FontFaceRule, FontFeatureValuesRule,
DocumentRule, ImportRule, KeyframesRule, LayerRule, MediaRule,
NamespaceRule, PageRule, StyleRule, StylesheetContents, SupportsRule
};
use servo_arc::{Arc, ArcBorrow};
use std::{mem, ptr};
@ -83,6 +75,9 @@ impl_arc_ffi!(Locked<Keyframe> => RawServoKeyframe
impl_arc_ffi!(Locked<KeyframesRule> => RawServoKeyframesRule
[Servo_KeyframesRule_AddRef, Servo_KeyframesRule_Release]);
impl_arc_ffi!(Locked<LayerRule> => RawServoLayerRule
[Servo_LayerRule_AddRef, Servo_LayerRule_Release]);
impl_arc_ffi!(Locked<MediaList> => RawServoMediaList
[Servo_MediaList_AddRef, Servo_MediaList_Release]);

Просмотреть файл

@ -310,10 +310,11 @@ impl CssRule {
/// https://drafts.csswg.org/cssom-1/#dom-cssrule-type
#[allow(missing_docs)]
#[derive(Clone, Copy, Debug, Eq, FromPrimitive, PartialEq)]
#[repr(u8)]
pub enum CssRuleType {
// https://drafts.csswg.org/cssom/#the-cssrule-interface
Style = 1,
Charset = 2,
// Charset = 2, // Historical
Import = 3,
Media = 4,
FontFace = 5,
@ -322,7 +323,7 @@ pub enum CssRuleType {
Keyframes = 7,
Keyframe = 8,
// https://drafts.csswg.org/cssom/#the-cssrule-interface
Margin = 9,
// Margin = 9, // Not implemented yet.
Namespace = 10,
// https://drafts.csswg.org/css-counter-styles-3/#extentions-to-cssrule-interface
CounterStyle = 11,

Просмотреть файл

@ -87,7 +87,7 @@ use style::gecko_bindings::structs::{nsINode as RawGeckoNode, Element as RawGeck
use style::gecko_bindings::structs::{
RawServoAnimationValue, RawServoAuthorStyles, RawServoCounterStyleRule,
RawServoDeclarationBlock, RawServoFontFaceRule, RawServoFontFeatureValuesRule,
RawServoImportRule, RawServoKeyframe, RawServoKeyframesRule, RawServoMediaList,
RawServoImportRule, RawServoKeyframe, RawServoKeyframesRule, RawServoLayerRule, RawServoMediaList,
RawServoMediaRule, RawServoMozDocumentRule, RawServoNamespaceRule, RawServoPageRule,
RawServoSharedMemoryBuilder, RawServoStyleSet, RawServoStyleSheetContents,
RawServoSupportsRule, ServoCssRules,
@ -119,12 +119,14 @@ use style::style_adjuster::StyleAdjuster;
use style::stylesheets::import_rule::ImportSheet;
use style::stylesheets::keyframes_rule::{Keyframe, KeyframeSelector, KeyframesStepValue};
use style::stylesheets::supports_rule::parse_condition_or_declaration;
use style::stylesheets::StylesheetLoader as StyleStylesheetLoader;
use style::stylesheets::{AllowImportRules, SanitizationData, SanitizationKind};
use style::stylesheets::{CounterStyleRule, CssRule, CssRuleType, CssRules, CssRulesHelpers};
use style::stylesheets::{DocumentRule, FontFaceRule, FontFeatureValuesRule, ImportRule};
use style::stylesheets::{KeyframesRule, MediaRule, NamespaceRule, Origin, OriginSet, PageRule};
use style::stylesheets::{StyleRule, StylesheetContents, SupportsRule, UrlExtraData};
use style::stylesheets::{
StylesheetLoader as StyleStylesheetLoader, AllowImportRules,
SanitizationData, SanitizationKind, CounterStyleRule, CssRule, CssRuleType,
CssRules, CssRulesHelpers, DocumentRule, FontFaceRule,
FontFeatureValuesRule, ImportRule, KeyframesRule, LayerRule, MediaRule,
NamespaceRule, Origin, OriginSet, PageRule, StyleRule, StylesheetContents,
SupportsRule, UrlExtraData,
};
use style::stylist::{add_size_of_ua_cache, AuthorStylesEnabled, RuleInclusion, Stylist};
use style::thread_state;
use style::traversal::resolve_style;
@ -2106,7 +2108,7 @@ pub extern "C" fn Servo_CssRules_InsertRule(
loader: *mut Loader,
allow_import_rules: AllowImportRules,
gecko_stylesheet: *mut DomStyleSheet,
rule_type: *mut u16,
rule_type: &mut CssRuleType,
) -> nsresult {
let loader = if loader.is_null() {
None
@ -2137,7 +2139,7 @@ pub extern "C" fn Servo_CssRules_InsertRule(
match result {
Ok(new_rule) => {
*unsafe { rule_type.as_mut().unwrap() } = new_rule.rule_type() as u16;
*rule_type = new_rule.rule_type();
nsresult::NS_OK
},
Err(err) => err.into(),
@ -2317,6 +2319,24 @@ impl_group_rule_funcs! { (Supports, SupportsRule, RawServoSupportsRule),
changed: Servo_StyleSet_SupportsRuleChanged,
}
impl_basic_rule_funcs! { (Layer, LayerRule, RawServoLayerRule),
getter: Servo_CssRules_GetLayerRuleAt,
debug: Servo_LayerRule_Debug,
to_css: Servo_LayerRule_GetCssText,
changed: Servo_StyleSet_LayerRuleChanged,
}
#[no_mangle]
pub extern "C" fn Servo_LayerRule_GetRules(rule: &RawServoLayerRule) -> Strong<ServoCssRules> {
use style::stylesheets::layer_rule::LayerRuleKind;
read_locked_arc(rule, |rule: &LayerRule| {
match rule.kind {
LayerRuleKind::Block { ref rules, .. } => rules.clone().into_strong(),
LayerRuleKind::Statement { .. } => Strong::null(),
}
})
}
impl_group_rule_funcs! { (Document, DocumentRule, RawServoMozDocumentRule),
get_rules: Servo_MozDocumentRule_GetRules,
getter: Servo_CssRules_GetMozDocumentRuleAt,
@ -4160,7 +4180,7 @@ pub unsafe extern "C" fn Servo_ParseProperty(
parsing_mode: structs::ParsingMode,
quirks_mode: nsCompatibility,
loader: *mut Loader,
rule_type: u16,
rule_type: CssRuleType,
) -> Strong<RawServoDeclarationBlock> {
let id = get_property_id_from_nscsspropertyid!(property, Strong::null());
let mut declarations = SourcePropertyDeclaration::new();
@ -4174,7 +4194,7 @@ pub unsafe extern "C" fn Servo_ParseProperty(
data,
parsing_mode,
quirks_mode.into(),
to_rule_type(rule_type),
rule_type,
reporter.as_ref().map(|r| r as &dyn ParseErrorReporter),
);
@ -4298,7 +4318,7 @@ pub unsafe extern "C" fn Servo_ParseStyleAttribute(
raw_extra_data: *mut URLExtraData,
quirks_mode: nsCompatibility,
loader: *mut Loader,
rule_type: u16,
rule_type: CssRuleType,
) -> Strong<RawServoDeclarationBlock> {
let global_style_data = &*GLOBAL_STYLE_DATA;
let value = data.as_str_unchecked();
@ -4309,7 +4329,7 @@ pub unsafe extern "C" fn Servo_ParseStyleAttribute(
url_data,
reporter.as_ref().map(|r| r as &dyn ParseErrorReporter),
quirks_mode.into(),
to_rule_type(rule_type),
rule_type,
)))
.into_strong()
}
@ -4563,12 +4583,6 @@ fn set_property(
)
}
#[inline]
fn to_rule_type(ty: u16) -> CssRuleType {
use num_traits::FromPrimitive;
CssRuleType::from_u16(ty).unwrap_or(CssRuleType::Style)
}
#[no_mangle]
pub unsafe extern "C" fn Servo_DeclarationBlock_SetProperty(
declarations: &RawServoDeclarationBlock,
@ -4579,7 +4593,7 @@ pub unsafe extern "C" fn Servo_DeclarationBlock_SetProperty(
parsing_mode: structs::ParsingMode,
quirks_mode: nsCompatibility,
loader: *mut Loader,
rule_type: u16,
rule_type: CssRuleType,
before_change_closure: DeclarationBlockMutationClosure,
) -> bool {
set_property(
@ -4591,7 +4605,7 @@ pub unsafe extern "C" fn Servo_DeclarationBlock_SetProperty(
parsing_mode,
quirks_mode.into(),
loader,
to_rule_type(rule_type),
rule_type,
before_change_closure,
)
}
@ -4623,7 +4637,7 @@ pub unsafe extern "C" fn Servo_DeclarationBlock_SetPropertyById(
parsing_mode: structs::ParsingMode,
quirks_mode: nsCompatibility,
loader: *mut Loader,
rule_type: u16,
rule_type: CssRuleType,
before_change_closure: DeclarationBlockMutationClosure,
) -> bool {
set_property(
@ -4635,7 +4649,7 @@ pub unsafe extern "C" fn Servo_DeclarationBlock_SetPropertyById(
parsing_mode,
quirks_mode.into(),
loader,
to_rule_type(rule_type),
rule_type,
before_change_closure,
)
}