Skip to content

Commit

Permalink
[@starting-style] Assert when inspecting @starting-style in debug build
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=271373
rdar://125156125

Reviewed by Antoine Quint.

* LayoutTests/inspector/css/getMatchedStylesForNode.html:
* Source/WebCore/css/CSSGroupingRule.h:
(isType):

Add type test.

* Source/WebCore/css/CSSRule.h:
(WebCore::CSSRule::isGroupingRule const):
* Source/WebCore/inspector/InspectorStyleSheet.cpp:
(WebCore::asCSSRuleList):

Return the rule list for @starting-style rules.
Refactor to handle all grouping rules uniformly.

Canonical link: https://commits.webkit.org/276456@main
  • Loading branch information
anttijk committed Mar 21, 2024
1 parent b2f308c commit e746fbb
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 13 deletions.
1 change: 1 addition & 0 deletions LayoutTests/inspector/css/getMatchedStylesForNode.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
@media (min-width: 1px) { body { color: red; } }
@media (min-width: 2px) { @supports(display: block) { body { color: red; } } }
@media screen { @counter-style foo { foo:bar; } }
@starting-style { bar { color: black; } }
</style>
<style media="(min-width: 3px)">
body { color: red;}
Expand Down
5 changes: 5 additions & 0 deletions Source/WebCore/css/CSSGroupingRule.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class CSSGroupingRule : public CSSRule {
RefPtr<StyleRuleWithNesting> prepareChildStyleRuleForNesting(StyleRule&) override;

private:
bool isGroupingRule() const final { return true; }
void appendCSSTextForItemsInternal(StringBuilder&, StringBuilder&) const;
void cssTextForRules(StringBuilder&) const;
void cssTextForRulesWithReplacementURLs(StringBuilder&, const HashMap<String, String>&, const HashMap<RefPtr<CSSStyleSheet>, String>&) const;
Expand All @@ -61,3 +62,7 @@ class CSSGroupingRule : public CSSRule {
};

} // namespace WebCore

SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::CSSGroupingRule)
static bool isType(const WebCore::CSSRule& rule) { return rule.isGroupingRule(); }
SPECIALIZE_TYPE_TRAITS_END()
1 change: 1 addition & 0 deletions Source/WebCore/css/CSSRule.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class CSSRule : public RefCounted<CSSRule> {
WEBCORE_EXPORT unsigned short typeForCSSOM() const;

virtual StyleRuleType styleRuleType() const = 0;
virtual bool isGroupingRule() const { return false; }
virtual String cssText() const = 0;
virtual String cssTextWithReplacementURLs(const HashMap<String, String>&, const HashMap<RefPtr<CSSStyleSheet>, String>&) const { return cssText(); }
virtual void reattach(StyleRuleBase&) = 0;
Expand Down
17 changes: 4 additions & 13 deletions Source/WebCore/inspector/InspectorStyleSheet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -578,20 +578,11 @@ static RefPtr<CSSRuleList> asCSSRuleList(CSSRule* rule)
if (auto* styleRule = dynamicDowncast<CSSStyleRule>(rule))
return &styleRule->cssRules();

if (is<CSSMediaRule>(*rule))
return &downcast<CSSMediaRule>(*rule).cssRules();
if (auto* keyframesRule = dynamicDowncast<CSSKeyframesRule>(*rule))
return &keyframesRule->cssRules();

if (is<CSSKeyframesRule>(*rule))
return &downcast<CSSKeyframesRule>(*rule).cssRules();

if (is<CSSSupportsRule>(*rule))
return &downcast<CSSSupportsRule>(*rule).cssRules();

if (is<CSSLayerBlockRule>(*rule))
return &downcast<CSSLayerBlockRule>(*rule).cssRules();

if (auto* containerRule = dynamicDowncast<CSSContainerRule>(rule))
return &containerRule->cssRules();
if (auto* groupingRule = dynamicDowncast<CSSGroupingRule>(*rule))
return &groupingRule->cssRules();

return nullptr;
}
Expand Down

0 comments on commit e746fbb

Please sign in to comment.