Skip to content

Commit

Permalink
Add ScopedName type
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=260493
rdar://114224001

Reviewed by Alan Baradlay.

Refactor animation name type to a generic struct. There are some other things in CSS
that need scoped names too.

* Source/WebCore/WebCore.xcodeproj/project.pbxproj:
* Source/WebCore/animation/CSSAnimation.cpp:
(WebCore::CSSAnimation::CSSAnimation):
* Source/WebCore/animation/KeyframeEffect.cpp:
(WebCore::KeyframeEffect::getKeyframes):
(WebCore::KeyframeEffect::computeCSSAnimationBlendingKeyframes):
* Source/WebCore/css/CSSToStyleMap.cpp:
(WebCore::CSSToStyleMap::mapAnimationName):
* Source/WebCore/css/ComputedStyleExtractor.cpp:
(WebCore::valueForScopedName):
(WebCore::ComputedStyleExtractor::addValueForAnimationPropertyToList):
(WebCore::valueForAnimationName): Deleted.
* Source/WebCore/platform/animation/Animation.cpp:
(WebCore::Animation::Animation):
(WebCore::Animation::animationsMatch const):
(WebCore::Animation::initialName const):
(WebCore::operator<<):
* Source/WebCore/platform/animation/Animation.h:
(WebCore::Animation::isValidAnimation const):
(WebCore::Animation::name const):
(WebCore::Animation::setName):
(WebCore::Animation::nameStyleScopeOrdinal const): Deleted.
* Source/WebCore/style/ScopedName.h: Added.
* Source/WebCore/style/Styleable.cpp:
(WebCore::keyframesRuleExistsForAnimation):
(WebCore::Styleable::animationListContainsNewlyValidAnimation const):
(WebCore::Styleable::updateCSSAnimations const):

Canonical link: https://commits.webkit.org/267135@main
  • Loading branch information
anttijk committed Aug 22, 2023
1 parent d72a710 commit 25f43ab
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 34 deletions.
1 change: 1 addition & 0 deletions Source/WebCore/Headers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2399,6 +2399,7 @@ set(WebCore_PRIVATE_FRAMEWORK_HEADERS
storage/StorageType.h
storage/StorageUtilities.h

style/ScopedName.h
style/StyleAppearance.h
style/StyleChange.h
style/StyleScope.h
Expand Down
4 changes: 4 additions & 0 deletions Source/WebCore/WebCore.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -5845,6 +5845,7 @@
E3D3C00B2881D90B00ECD5F6 /* GPUAvailabilityMetal.mm in Sources */ = {isa = PBXBuildFile; fileRef = E3D3C00A2881D90B00ECD5F6 /* GPUAvailabilityMetal.mm */; };
E3E4E2A81E3B17100023BB8A /* ScriptElementCachedScriptFetcher.h in Headers */ = {isa = PBXBuildFile; fileRef = E3E4E2A61E3B16FC0023BB8A /* ScriptElementCachedScriptFetcher.h */; settings = {ATTRIBUTES = (Private, ); }; };
E3FA38641D71812D00AA5950 /* PendingScriptClient.h in Headers */ = {isa = PBXBuildFile; fileRef = E3FA38611D716E7600AA5950 /* PendingScriptClient.h */; };
E401B3632A942E3F0018B557 /* ScopedName.h in Headers */ = {isa = PBXBuildFile; fileRef = E401B3622A942E3E0018B557 /* ScopedName.h */; settings = {ATTRIBUTES = (Private, ); }; };
E401C27517CE53EC00C41A35 /* ElementIteratorAssertions.h in Headers */ = {isa = PBXBuildFile; fileRef = E401C27417CE53EC00C41A35 /* ElementIteratorAssertions.h */; settings = {ATTRIBUTES = (Private, ); }; };
E401E0A41C3C0B8300F34D10 /* StyleChange.h in Headers */ = {isa = PBXBuildFile; fileRef = E401E0A31C3C0B8300F34D10 /* StyleChange.h */; settings = {ATTRIBUTES = (Private, ); }; };
E403B7A2251B11930019E800 /* LayoutIntegrationCoverage.h in Headers */ = {isa = PBXBuildFile; fileRef = E403B7A1251B11930019E800 /* LayoutIntegrationCoverage.h */; };
Expand Down Expand Up @@ -19101,6 +19102,7 @@
E3E4E2A51E3B16FC0023BB8A /* ScriptElementCachedScriptFetcher.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ScriptElementCachedScriptFetcher.cpp; sourceTree = "<group>"; };
E3E4E2A61E3B16FC0023BB8A /* ScriptElementCachedScriptFetcher.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScriptElementCachedScriptFetcher.h; sourceTree = "<group>"; };
E3FA38611D716E7600AA5950 /* PendingScriptClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PendingScriptClient.h; sourceTree = "<group>"; };
E401B3622A942E3E0018B557 /* ScopedName.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScopedName.h; sourceTree = "<group>"; };
E401C27417CE53EC00C41A35 /* ElementIteratorAssertions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ElementIteratorAssertions.h; sourceTree = "<group>"; };
E401E0A31C3C0B8300F34D10 /* StyleChange.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StyleChange.h; sourceTree = "<group>"; };
E401E0A51C3C0CF700F34D10 /* StyleChange.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StyleChange.cpp; sourceTree = "<group>"; };
Expand Down Expand Up @@ -34511,6 +34513,7 @@
A79BADA0161E7F3F00C2E652 /* RuleSet.h */,
E47CEBEB2709DFDC00B8D8F5 /* RuleSetBuilder.cpp */,
E47CEBE82709DFD000B8D8F5 /* RuleSetBuilder.h */,
E401B3622A942E3E0018B557 /* ScopedName.h */,
E4643288273D2E7C005B756B /* SelectorMatchingState.h */,
7173DEBD2614DF040097DF32 /* Styleable.cpp */,
713922BC2518AB70005DB3C2 /* Styleable.h */,
Expand Down Expand Up @@ -40652,6 +40655,7 @@
5DFE8F570D16477C0076E937 /* ScheduledAction.h in Headers */,
9BD0BF9312A42BF50072FD43 /* ScopedEventQueue.h in Headers */,
7B7311FB25C092B7003B2796 /* ScopedHighPerformanceGPURequest.h in Headers */,
E401B3632A942E3F0018B557 /* ScopedName.h in Headers */,
BCEC01BE0C274DAC009F4EC9 /* Screen.h in Headers */,
070BED98273F415D00583926 /* ScreenCaptureKitCaptureSource.h in Headers */,
073955BB27AB277F009A08D2 /* ScreenCaptureKitSharingSessionManager.h in Headers */,
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/animation/CSSAnimation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Ref<CSSAnimation> CSSAnimation::create(const Styleable& owningElement, const Ani

CSSAnimation::CSSAnimation(const Styleable& element, const Animation& backingAnimation)
: DeclarativeAnimation(element, backingAnimation)
, m_animationName(backingAnimation.name().string)
, m_animationName(backingAnimation.name().name)
{
}

Expand Down
6 changes: 3 additions & 3 deletions Source/WebCore/animation/KeyframeEffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ auto KeyframeEffect::getKeyframes(Document& document) -> Vector<ComputedKeyframe
return { };

auto& backingAnimation = downcast<CSSAnimation>(*animation()).backingAnimation();
auto* styleScope = Style::Scope::forOrdinal(*m_target, backingAnimation.nameStyleScopeOrdinal());
auto* styleScope = Style::Scope::forOrdinal(*m_target, backingAnimation.name().scopeOrdinal);
if (!styleScope)
return { };

Expand Down Expand Up @@ -1072,8 +1072,8 @@ void KeyframeEffect::computeCSSAnimationBlendingKeyframes(const RenderStyle& una

auto& backingAnimation = downcast<CSSAnimation>(*animation()).backingAnimation();

KeyframeList keyframeList(AtomString { backingAnimation.name().string });
if (auto* styleScope = Style::Scope::forOrdinal(*m_target, backingAnimation.nameStyleScopeOrdinal()))
KeyframeList keyframeList(AtomString { backingAnimation.name().name });
if (auto* styleScope = Style::Scope::forOrdinal(*m_target, backingAnimation.name().scopeOrdinal))
styleScope->resolver().keyframeStylesForAnimation(*m_target, unanimatedStyle, resolutionContext, keyframeList);

// Ensure resource loads for all the frames.
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/css/CSSToStyleMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ void CSSToStyleMap::mapAnimationName(Animation& layer, const CSSValue& value)
if (primitiveValue.valueID() == CSSValueNone)
layer.setIsNoneAnimation(true);
else
layer.setName({ primitiveValue.stringValue(), primitiveValue.isCustomIdent() }, m_builderState.styleScopeOrdinal());
layer.setName({ AtomString { primitiveValue.stringValue() }, primitiveValue.isCustomIdent(), m_builderState.styleScopeOrdinal() });
}

void CSSToStyleMap::mapAnimationPlayState(Animation& layer, const CSSValue& value)
Expand Down
10 changes: 5 additions & 5 deletions Source/WebCore/css/ComputedStyleExtractor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1532,11 +1532,11 @@ static Ref<CSSPrimitiveValue> valueForAnimationPlayState(AnimationPlayState play
RELEASE_ASSERT_NOT_REACHED();
}

static Ref<CSSPrimitiveValue> valueForAnimationName(const Animation::Name& name)
static Ref<CSSPrimitiveValue> valueForScopedName(const Style::ScopedName& scopedName)
{
if (name.isIdentifier)
return CSSPrimitiveValue::createCustomIdent(name.string);
return CSSPrimitiveValue::create(name.string);
if (scopedName.isIdentifier)
return CSSPrimitiveValue::createCustomIdent(scopedName.name);
return CSSPrimitiveValue::create(scopedName.name);
}

static Ref<CSSValue> valueForAnimationTimingFunction(const TimingFunction& timingFunction)
Expand Down Expand Up @@ -1605,7 +1605,7 @@ void ComputedStyleExtractor::addValueForAnimationPropertyToList(CSSValueListBuil
if (!animation || !animation->isPlayStateFilled())
list.append(valueForAnimationPlayState(animation ? animation->playState() : Animation::initialPlayState()));
} else if (property == CSSPropertyAnimationName)
list.append(valueForAnimationName(animation ? animation->name() : Animation::initialName()));
list.append(valueForScopedName(animation ? animation->name() : Animation::initialName()));
else if (property == CSSPropertyAnimationComposition) {
if (!animation || !animation->isCompositeOperationFilled())
list.append(valueForAnimationComposition(animation ? animation->compositeOperation() : Animation::initialCompositeOperation()));
Expand Down
10 changes: 4 additions & 6 deletions Source/WebCore/platform/animation/Animation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ Animation::Animation(const Animation& o)
, m_delay(o.m_delay)
, m_duration(o.m_duration)
, m_timingFunction(o.m_timingFunction)
, m_nameStyleScopeOrdinal(o.m_nameStyleScopeOrdinal)
, m_direction(o.m_direction)
, m_fillMode(o.m_fillMode)
, m_playState(o.m_playState)
Expand Down Expand Up @@ -102,15 +101,14 @@ Animation::~Animation() = default;

bool Animation::animationsMatch(const Animation& other, bool matchProperties) const
{
bool result = m_name.string == other.m_name.string
bool result = m_name == other.m_name
&& m_playState == other.m_playState
&& m_compositeOperation == other.m_compositeOperation
&& m_playStateSet == other.m_playStateSet
&& m_iterationCount == other.m_iterationCount
&& m_delay == other.m_delay
&& m_duration == other.m_duration
&& *(m_timingFunction.get()) == *(other.m_timingFunction.get())
&& m_nameStyleScopeOrdinal == other.m_nameStyleScopeOrdinal
&& m_direction == other.m_direction
&& m_fillMode == other.m_fillMode
&& m_delaySet == other.m_delaySet
Expand All @@ -129,9 +127,9 @@ bool Animation::animationsMatch(const Animation& other, bool matchProperties) co
return !matchProperties || (m_property.mode == other.m_property.mode && m_property.animatableProperty == other.m_property.animatableProperty && m_propertySet == other.m_propertySet);
}

auto Animation::initialName() -> const Name&
auto Animation::initialName() -> const Style::ScopedName&
{
static NeverDestroyed<Name> initialValue { Name { noneAtom(), true } };
static NeverDestroyed<Style::ScopedName> initialValue { Style::ScopedName { noneAtom() } };
return initialValue;
}

Expand Down Expand Up @@ -160,7 +158,7 @@ TextStream& operator<<(TextStream& ts, Animation::Direction direction)
TextStream& operator<<(TextStream& ts, const Animation& animation)
{
ts.dumpProperty("property", animation.property());
ts.dumpProperty("name", animation.name().string);
ts.dumpProperty("name", animation.name().name);
ts.dumpProperty("iteration count", animation.iterationCount());
ts.dumpProperty("delay", animation.iterationCount());
ts.dumpProperty("duration", animation.duration());
Expand Down
21 changes: 6 additions & 15 deletions Source/WebCore/platform/animation/Animation.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include "CSSPropertyNames.h"
#include "CompositeOperation.h"
#include "RenderStyleConstants.h"
#include "StyleScopeOrdinal.h"
#include "ScopedName.h"
#include "TimingFunction.h"
#include "WebAnimationTypes.h"

Expand Down Expand Up @@ -56,7 +56,7 @@ class Animation : public RefCounted<Animation> {

// We can make placeholder Animation objects to keep the comma-separated lists
// of properties in sync. isValidAnimation means this is not a placeholder.
bool isValidAnimation() const { return !m_isNone && !m_name.string.isEmpty(); }
bool isValidAnimation() const { return !m_isNone && !m_name.name.isEmpty(); }

bool isEmpty() const
{
Expand Down Expand Up @@ -125,15 +125,9 @@ class Animation : public RefCounted<Animation> {
double duration() const { return m_duration; }
double playbackRate() const { return m_playbackRate; }

struct Name {
String string;
bool isIdentifier { false };
};

static constexpr double IterationCountInfinite = -1;
double iterationCount() const { return m_iterationCount; }
const Name& name() const { return m_name; }
Style::ScopeOrdinal nameStyleScopeOrdinal() const { return m_nameStyleScopeOrdinal; }
const Style::ScopedName& name() const { return m_name; }
AnimationPlayState playState() const { return static_cast<AnimationPlayState>(m_playState); }
TransitionProperty property() const { return m_property; }
TimingFunction* timingFunction() const { return m_timingFunction.get(); }
Expand All @@ -145,10 +139,9 @@ class Animation : public RefCounted<Animation> {
void setPlaybackRate(double d) { m_playbackRate = d; }
void setFillMode(AnimationFillMode f) { m_fillMode = static_cast<unsigned>(f); m_fillModeSet = true; }
void setIterationCount(double c) { m_iterationCount = c; m_iterationCountSet = true; }
void setName(const Name& name, Style::ScopeOrdinal scope = Style::ScopeOrdinal::Element)
void setName(const Style::ScopedName& name)
{
m_name = name;
m_nameStyleScopeOrdinal = scope;
m_nameSet = true;
}
void setPlayState(AnimationPlayState d) { m_playState = static_cast<unsigned>(d); m_playStateSet = true; }
Expand Down Expand Up @@ -197,16 +190,14 @@ class Animation : public RefCounted<Animation> {
// Packs with m_refCount from the base class.
TransitionProperty m_property { TransitionMode::All, CSSPropertyInvalid };

Name m_name;
Style::ScopedName m_name;
double m_iterationCount;
double m_delay;
double m_duration;
double m_playbackRate { 1 };
RefPtr<TimingFunction> m_timingFunction;
RefPtr<TimingFunction> m_defaultTimingFunctionForKeyframes;

Style::ScopeOrdinal m_nameStyleScopeOrdinal { Style::ScopeOrdinal::Element };

unsigned m_direction : 2; // Direction
unsigned m_fillMode : 2; // AnimationFillMode
unsigned m_playState : 2; // AnimationPlayState
Expand Down Expand Up @@ -241,7 +232,7 @@ class Animation : public RefCounted<Animation> {
static double initialDuration() { return 0; }
static AnimationFillMode initialFillMode() { return AnimationFillMode::None; }
static double initialIterationCount() { return 1.0; }
static const Name& initialName();
static const Style::ScopedName& initialName();
static AnimationPlayState initialPlayState() { return AnimationPlayState::Playing; }
static CompositeOperation initialCompositeOperation() { return CompositeOperation::Replace; }
static TransitionProperty initialProperty() { return { TransitionMode::All, CSSPropertyInvalid }; }
Expand Down
43 changes: 43 additions & 0 deletions Source/WebCore/style/ScopedName.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright (C) 2023 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#pragma once

#include "StyleScopeOrdinal.h"
#include <wtf/text/AtomString.h>

namespace WebCore {
namespace Style {

struct ScopedName {
AtomString name;
bool isIdentifier { true };
ScopeOrdinal scopeOrdinal { ScopeOrdinal::Element };

bool operator==(const ScopedName&) const = default;
};

}
}

6 changes: 3 additions & 3 deletions Source/WebCore/style/Styleable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ void Styleable::cancelDeclarativeAnimations() const

static bool keyframesRuleExistsForAnimation(Element& element, const Animation& animation, const String& animationName)
{
auto* styleScope = Style::Scope::forOrdinal(element, animation.nameStyleScopeOrdinal());
auto* styleScope = Style::Scope::forOrdinal(element, animation.name().scopeOrdinal);
return styleScope && styleScope->resolver().isAnimationNameValid(animationName);
}

Expand All @@ -282,7 +282,7 @@ bool Styleable::animationListContainsNewlyValidAnimation(const AnimationList& an
return false;

for (auto& animation : animations) {
auto& name = animation->name().string;
auto& name = animation->name().name;
if (name != noneAtom() && !name.isEmpty() && keyframeEffectStack.containsInvalidCSSAnimationName(name) && keyframesRuleExistsForAnimation(element, animation.get(), name))
return true;
}
Expand Down Expand Up @@ -327,7 +327,7 @@ void Styleable::updateCSSAnimations(const RenderStyle* currentStyle, const Rende
if (!currentAnimation->isValidAnimation())
continue;

auto& animationName = currentAnimation->name().string;
auto& animationName = currentAnimation->name().name;
if (animationName == noneAtom() || animationName.isEmpty())
continue;

Expand Down

0 comments on commit 25f43ab

Please sign in to comment.