Skip to content

Commit

Permalink
[CSS] Use "enum class" for ContentsWereClonedForMutation
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=270822
rdar://124412748

Reviewed by Tim Nguyen.

* Source/WebCore/css/CSSStyleSheet.cpp:
(WebCore::CSSStyleSheet::willMutateRules):
(WebCore::CSSStyleSheet::didMutateRules):
(WebCore::CSSStyleSheet::RuleMutationScope::RuleMutationScope):
(WebCore::CSSStyleSheet::RuleMutationScope::~RuleMutationScope):
* Source/WebCore/css/CSSStyleSheet.h:

Canonical link: https://commits.webkit.org/275953@main
  • Loading branch information
mdubet committed Mar 12, 2024
1 parent cedd7cb commit 9b04524
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
19 changes: 9 additions & 10 deletions Source/WebCore/css/CSSStyleSheet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,11 @@ RefPtr<StyleRuleWithNesting> CSSStyleSheet::prepareChildStyleRuleForNesting(Styl
return { };
}

CSSStyleSheet::WhetherContentsWereClonedForMutation CSSStyleSheet::willMutateRules()
{
auto CSSStyleSheet::willMutateRules() -> ContentsClonedForMutation {
// If we are the only client it is safe to mutate.
if (m_contents->hasOneClient() && !m_contents->isInMemoryCache()) {
m_contents->setMutable();
return ContentsWereNotClonedForMutation;
return ContentsClonedForMutation::No;
}
// Only cacheable stylesheets should have multiple clients.
ASSERT(m_contents->isCacheable());
Expand All @@ -217,7 +216,7 @@ CSSStyleSheet::WhetherContentsWereClonedForMutation CSSStyleSheet::willMutateRul
// Any existing CSSOM wrappers need to be connected to the copied child rules.
reattachChildRuleCSSOMWrappers();

return ContentsWereClonedForMutation;
return ContentsClonedForMutation::Yes;
}

void CSSStyleSheet::didMutateRuleFromCSSStyleDeclaration()
Expand All @@ -228,13 +227,13 @@ void CSSStyleSheet::didMutateRuleFromCSSStyleDeclaration()
}

// FIXME: counter-style: we might need something similar for counter-style (rdar://103018993).
void CSSStyleSheet::didMutateRules(RuleMutationType mutationType, WhetherContentsWereClonedForMutation contentsWereClonedForMutation, StyleRuleKeyframes* insertedKeyframesRule, const String& modifiedKeyframesRuleName)
void CSSStyleSheet::didMutateRules(RuleMutationType mutationType, ContentsClonedForMutation contentsClonedForMutation, StyleRuleKeyframes* insertedKeyframesRule, const String& modifiedKeyframesRuleName)
{
ASSERT(m_contents->isMutable());
ASSERT(m_contents->hasOneClient());

forEachStyleScope([&](Style::Scope& scope) {
if ((mutationType == RuleInsertion || mutationType == RuleReplace) && !contentsWereClonedForMutation && !scope.activeStyleSheetsContains(*this)) {
if ((mutationType == RuleInsertion || mutationType == RuleReplace) && contentsClonedForMutation == ContentsClonedForMutation::No && !scope.activeStyleSheetsContains(*this)) {
if (insertedKeyframesRule) {
if (auto* resolver = scope.resolverIfExists())
resolver->addKeyframeStyle(*insertedKeyframesRule);
Expand Down Expand Up @@ -601,27 +600,27 @@ CSSStyleSheet::RuleMutationScope::RuleMutationScope(CSSStyleSheet* sheet, RuleMu
, m_insertedKeyframesRule(insertedKeyframesRule)
{
ASSERT(m_styleSheet);
m_contentsWereClonedForMutation = m_styleSheet->willMutateRules();
m_contentsClonedForMutation = m_styleSheet->willMutateRules();
}

CSSStyleSheet::RuleMutationScope::RuleMutationScope(CSSRule* rule)
: m_styleSheet(rule ? rule->parentStyleSheet() : nullptr)
, m_mutationType(is<CSSKeyframesRule>(rule) ? KeyframesRuleMutation : OtherMutation)
, m_contentsWereClonedForMutation(ContentsWereNotClonedForMutation)
, m_contentsClonedForMutation(ContentsClonedForMutation::No)
, m_insertedKeyframesRule(nullptr)
, m_modifiedKeyframesRuleName([rule] {
auto* cssKeyframeRule = dynamicDowncast<CSSKeyframesRule>(rule);
return cssKeyframeRule ? cssKeyframeRule->name() : emptyAtom();
}())
{
if (m_styleSheet)
m_contentsWereClonedForMutation = m_styleSheet->willMutateRules();
m_contentsClonedForMutation = m_styleSheet->willMutateRules();
}

CSSStyleSheet::RuleMutationScope::~RuleMutationScope()
{
if (m_styleSheet)
m_styleSheet->didMutateRules(m_mutationType, m_contentsWereClonedForMutation, m_insertedKeyframesRule.get(), m_modifiedKeyframesRuleName);
m_styleSheet->didMutateRules(m_mutationType, m_contentsClonedForMutation, m_insertedKeyframesRule.get(), m_modifiedKeyframesRuleName);
}

}
8 changes: 4 additions & 4 deletions Source/WebCore/css/CSSStyleSheet.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class CSSStyleSheet final : public StyleSheet, public CanMakeSingleThreadWeakPtr
RefPtr<StyleRuleWithNesting> prepareChildStyleRuleForNesting(StyleRule&&);

enum RuleMutationType { OtherMutation, RuleInsertion, KeyframesRuleMutation, RuleReplace };
enum WhetherContentsWereClonedForMutation { ContentsWereNotClonedForMutation = 0, ContentsWereClonedForMutation };
enum class ContentsClonedForMutation : bool { No, Yes };

class RuleMutationScope {
WTF_MAKE_NONCOPYABLE(RuleMutationScope);
Expand All @@ -136,13 +136,13 @@ class CSSStyleSheet final : public StyleSheet, public CanMakeSingleThreadWeakPtr
private:
CSSStyleSheet* m_styleSheet;
RuleMutationType m_mutationType;
WhetherContentsWereClonedForMutation m_contentsWereClonedForMutation;
ContentsClonedForMutation m_contentsClonedForMutation;
RefPtr<StyleRuleKeyframes> m_insertedKeyframesRule;
String m_modifiedKeyframesRuleName;
};

WhetherContentsWereClonedForMutation willMutateRules();
void didMutateRules(RuleMutationType, WhetherContentsWereClonedForMutation, StyleRuleKeyframes* insertedKeyframesRule, const String& modifiedKeyframesRuleName);
ContentsClonedForMutation willMutateRules();
void didMutateRules(RuleMutationType, ContentsClonedForMutation, StyleRuleKeyframes* insertedKeyframesRule, const String& modifiedKeyframesRuleName);
void didMutateRuleFromCSSStyleDeclaration();
void didMutate();

Expand Down

0 comments on commit 9b04524

Please sign in to comment.