Skip to content

Commit

Permalink
Bug 1729330 - Add a simple CSSLayerRule implementation. r=smaug
Browse files Browse the repository at this point in the history
The specifics of how this is going to work are still getting spec'd /
discussed in w3c/csswg-drafts#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
  • Loading branch information
emilio committed Sep 8, 2021
1 parent 1fc2475 commit 597b7bc
Show file tree
Hide file tree
Showing 54 changed files with 409 additions and 248 deletions.
2 changes: 1 addition & 1 deletion dom/base/nsAttrValue.cpp
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion dom/svg/SVGElement.cpp
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion dom/webidl/CSSGroupingRule.webidl
Expand Up @@ -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]
Expand Down
12 changes: 12 additions & 0 deletions dom/webidl/CSSLayerRule.webidl
@@ -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 {
};
2 changes: 1 addition & 1 deletion dom/webidl/CSSRule.webidl
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions dom/webidl/moz.build
Expand Up @@ -477,6 +477,7 @@ WEBIDL_FILES = [
"CSSImportRule.webidl",
"CSSKeyframeRule.webidl",
"CSSKeyframesRule.webidl",
"CSSLayerRule.webidl",
"CSSMediaRule.webidl",
"CSSMozDocumentRule.webidl",
"CSSNamespaceRule.webidl",
Expand Down
2 changes: 1 addition & 1 deletion dom/xul/nsXULElement.cpp
Expand Up @@ -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);

Expand Down
53 changes: 32 additions & 21 deletions layout/inspector/ServoStyleRuleMap.cpp
Expand Up @@ -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");
}
}

Expand All @@ -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;
}
}

Expand Down
4 changes: 2 additions & 2 deletions layout/style/CSSCounterStyleRule.cpp
Expand Up @@ -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(
Expand Down
8 changes: 3 additions & 5 deletions layout/style/CSSCounterStyleRule.h
Expand Up @@ -12,8 +12,7 @@

struct RawServoCounterStyleRule;

namespace mozilla {
namespace dom {
namespace mozilla::dom {

class CSSCounterStyleRule final : public css::Rule {
public:
Expand Down Expand Up @@ -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);
Expand All @@ -59,7 +58,6 @@ class CSSCounterStyleRule final : public css::Rule {
RefPtr<RawServoCounterStyleRule> mRawRule;
};

} // namespace dom
} // namespace mozilla
} // namespace mozilla::dom

#endif // mozilla_CSSCounterStyleRule_h
4 changes: 2 additions & 2 deletions layout/style/CSSFontFaceRule.cpp
Expand Up @@ -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) {
Expand Down
8 changes: 3 additions & 5 deletions layout/style/CSSFontFaceRule.h
Expand Up @@ -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;
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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
10 changes: 6 additions & 4 deletions layout/style/CSSFontFeatureValuesRule.cpp
Expand Up @@ -8,15 +8,18 @@
#include "mozilla/dom/CSSFontFeatureValuesRuleBinding.h"
#include "mozilla/ServoBindings.h"

namespace mozilla {
namespace dom {
namespace mozilla::dom {

size_t CSSFontFeatureValuesRule::SizeOfIncludingThis(
MallocSizeOf aMallocSizeOf) const {
// TODO Implement this!
return aMallocSizeOf(this);
}

StyleCssRuleType CSSFontFeatureValuesRule::Type() const {
return StyleCssRuleType::FontFeatureValues;
}

#ifdef DEBUG
void CSSFontFeatureValuesRule::List(FILE* out, int32_t aIndent) const {
nsAutoCString str;
Expand Down Expand Up @@ -78,5 +81,4 @@ JSObject* CSSFontFeatureValuesRule::WrapObject(
return CSSFontFeatureValuesRule_Binding::Wrap(aCx, this, aGivenProto);
}

} // namespace dom
} // namespace mozilla
} // namespace mozilla::dom
10 changes: 3 additions & 7 deletions layout/style/CSSFontFeatureValuesRule.h
Expand Up @@ -12,8 +12,7 @@

#include "nsICSSDeclaration.h"

namespace mozilla {
namespace dom {
namespace mozilla::dom {

class CSSFontFeatureValuesRule final : public css::Rule {
public:
Expand All @@ -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);
Expand All @@ -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
4 changes: 4 additions & 0 deletions layout/style/CSSImportRule.cpp
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion layout/style/CSSImportRule.h
Expand Up @@ -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();
Expand Down
12 changes: 7 additions & 5 deletions layout/style/CSSKeyframeRule.cpp
Expand Up @@ -10,8 +10,7 @@
#include "mozilla/dom/CSSKeyframeRuleBinding.h"
#include "nsDOMCSSDeclaration.h"

namespace mozilla {
namespace dom {
namespace mozilla::dom {

// -------------------------------------------
// CSSKeyframeDeclaration
Expand Down Expand Up @@ -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; }

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -214,5 +217,4 @@ JSObject* CSSKeyframeRule::WrapObject(JSContext* aCx,
return CSSKeyframeRule_Binding::Wrap(aCx, this, aGivenProto);
}

} // namespace dom
} // namespace mozilla
} // namespace mozilla::dom
9 changes: 3 additions & 6 deletions layout/style/CSSKeyframeRule.h
Expand Up @@ -11,10 +11,8 @@
#include "mozilla/ServoBindingTypes.h"

class nsICSSDeclaration;
class DeclarationBlock;

namespace mozilla {
namespace dom {
namespace mozilla::dom {

class CSSKeyframeDeclaration;

Expand All @@ -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);
Expand All @@ -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

0 comments on commit 597b7bc

Please sign in to comment.