Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions LayoutTests/TestExpectations
Original file line number Diff line number Diff line change
Expand Up @@ -7596,16 +7596,6 @@ imported/w3c/web-platform-tests/css/css-view-transitions/web-animations-api-pars
# Test doesn't seem to pass on Chrome Canary.
imported/w3c/web-platform-tests/css/css-view-transitions/view-transition-types-mutable-no-document-element-crashtest.html [ Skip ]

# View transitions Level 2 - classes.
imported/w3c/web-platform-tests/css/css-view-transitions/pseudo-with-classes-entry.html [ ImageOnlyFailure ]
imported/w3c/web-platform-tests/css/css-view-transitions/pseudo-with-classes-exit.html [ ImageOnlyFailure ]
imported/w3c/web-platform-tests/css/css-view-transitions/pseudo-with-classes-mismatch-ident.html [ ImageOnlyFailure ]
imported/w3c/web-platform-tests/css/css-view-transitions/pseudo-with-classes-mismatch-partial.html [ ImageOnlyFailure ]
imported/w3c/web-platform-tests/css/css-view-transitions/pseudo-with-classes-mismatch-wildcard.html [ ImageOnlyFailure ]
imported/w3c/web-platform-tests/css/css-view-transitions/pseudo-with-classes-old-with-class-new-without.html [ ImageOnlyFailure ]
imported/w3c/web-platform-tests/css/css-view-transitions/shadow-part-with-class-inside-shadow-important.html [ ImageOnlyFailure ]
imported/w3c/web-platform-tests/css/css-view-transitions/shadow-part-with-class-inside-shadow.html [ ImageOnlyFailure ]

# View transitions Level 2 - cross document transitions.
imported/w3c/web-platform-tests/css/css-view-transitions/navigation/chromium-paint-holding-timeout.html [ ImageOnlyFailure ]
imported/w3c/web-platform-tests/css/css-view-transitions/navigation/no-view-transition-with-cross-origin-redirect.sub.html [ ImageOnlyFailure ]
Expand Down
8 changes: 4 additions & 4 deletions Source/WTF/Scripts/Preferences/UnifiedWebPreferences.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7555,16 +7555,16 @@ ViewGestureDebuggingEnabled:
ViewTransitionClassesEnabled:
type: bool
category: animation
status: testable
status: stable
humanReadableName: "View Transition Classes"
humanReadableDescription: "Support specifying classes for view transitions"
defaultValue:
WebKitLegacy:
default: false
default: true
WebKit:
default: false
default: true
WebCore:
default: false
default: true

ViewTransitionTypesEnabled:
type: bool
Expand Down
7 changes: 7 additions & 0 deletions Source/WebCore/css/CSSSelector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,13 @@ static void appendPossiblyQuotedIdentifier(StringBuilder& builder, const Possibl
serializeString(identifier.identifier, builder);
}

WTF::TextStream& operator<<(WTF::TextStream& ts, PossiblyQuotedIdentifier identifier)
{
StringBuilder builder;
appendPossiblyQuotedIdentifier(builder, identifier);
return ts << builder.toString();
}

static void appendCommaSeparatedPossiblyQuotedIdentifierList(StringBuilder& builder, const FixedVector<PossiblyQuotedIdentifier>& list)
{
builder.append(interleave(list, appendPossiblyQuotedIdentifier, ", "_s));
Expand Down
2 changes: 2 additions & 0 deletions Source/WebCore/css/CSSSelector.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ struct PossiblyQuotedIdentifier {
bool isNull() const { return identifier.isNull(); }
};

WTF::TextStream& operator<<(WTF::TextStream&, PossiblyQuotedIdentifier);

enum class SelectorSpecificityIncrement {
ClassA = 0x10000,
ClassB = 0x100,
Expand Down
16 changes: 13 additions & 3 deletions Source/WebCore/css/SelectorChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1271,9 +1271,19 @@ bool SelectorChecker::checkOne(CheckingContext& checkingContext, LocalContext& c
if (checkingContext.pseudoId != CSSSelector::pseudoId(selector.pseudoElement()) || !selector.argumentList())
return false;

// Wildcard always matches.
auto& argument = selector.argumentList()->first();
return argument == starAtom() || argument == checkingContext.pseudoElementNameArgument;
auto& list = *selector.argumentList();
auto& name = list.first();
if (name != starAtom() && name != checkingContext.pseudoElementNameArgument)
return false;

if (list.size() == 1)
return true;

return std::ranges::all_of(list.begin() + 1, list.end(),
[&](const PossiblyQuotedIdentifier& classSelector) {
return checkingContext.classList.contains(classSelector.identifier);
}
);
}

default:
Expand Down
1 change: 1 addition & 0 deletions Source/WebCore/css/SelectorChecker.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class SelectorChecker {
PseudoId pseudoId { PseudoId::None };
AtomString pseudoElementNameArgument;
std::optional<StyleScrollbarState> scrollbarState;
Vector<AtomString> classList;
RefPtr<const ContainerNode> scope;
const Element* hasScope { nullptr };
bool matchesAllHasScopes { false };
Expand Down
23 changes: 22 additions & 1 deletion Source/WebCore/dom/ViewTransition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,21 @@ static ExceptionOr<void> checkDuplicateViewTransitionName(const AtomString& name
return { };
}

static Vector<AtomString> effectiveViewTransitionClassList(RenderLayerModelObject& renderer, Element& originatingElement, Style::Scope& documentScope)
{
auto classList = renderer.style().viewTransitionClasses();
if (classList.isEmpty())
return { };

auto scope = Style::Scope::forOrdinal(originatingElement, classList.first().scopeOrdinal);
if (!scope || scope != &documentScope)
return { };

return WTF::map(classList, [&](auto& item) {
return item.name;
});
}

static LayoutRect captureOverflowRect(RenderLayerModelObject& renderer)
{
if (!renderer.hasLayer())
Expand Down Expand Up @@ -465,6 +480,10 @@ ExceptionOr<void> ViewTransition::captureOldState()
capture.oldImage = snapshotElementVisualOverflowClippedToViewport(*frame, renderer.get(), capture.oldOverflowRect);
capture.oldLayerToLayoutOffset = layerToLayoutOffset(renderer.get());

auto styleable = Styleable::fromRenderer(renderer);
ASSERT(styleable);
capture.classList = effectiveViewTransitionClassList(renderer, styleable->element, document()->styleScope());

auto transitionName = renderer->style().viewTransitionName();
m_namedElements.add(transitionName->name, capture);
}
Expand Down Expand Up @@ -495,7 +514,9 @@ ExceptionOr<void> ViewTransition::captureNewState()
CapturedElement capturedElement;
m_namedElements.add(name, capturedElement);
}
m_namedElements.find(name)->newElement = *styleable;
auto namedElement = m_namedElements.find(name);
namedElement->classList = effectiveViewTransitionClassList(renderer, styleable->element, document()->styleScope());
namedElement->newElement = *styleable;
}
return { };
}, *view->layer());
Expand Down
1 change: 1 addition & 0 deletions Source/WebCore/dom/ViewTransition.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ struct CapturedElement {
LayoutSize oldSize;
RefPtr<MutableStyleProperties> oldProperties;
WeakStyleable newElement;
Vector<AtomString> classList;

RefPtr<MutableStyleProperties> groupStyleProperties;
};
Expand Down
8 changes: 4 additions & 4 deletions Source/WebCore/rendering/updating/RenderTreeUpdater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,15 +372,15 @@ void RenderTreeUpdater::updateAfterDescendants(Element& element, const Style::El

static bool pseudoStyleCacheIsInvalid(RenderElement* renderer, RenderStyle* newStyle)
{
const RenderStyle& currentStyle = renderer->style();
const auto& currentStyle = renderer->style();

const PseudoStyleCache* pseudoStyleCache = currentStyle.cachedPseudoStyles();
const auto* pseudoStyleCache = currentStyle.cachedPseudoStyles();
if (!pseudoStyleCache)
return false;

for (auto& cache : pseudoStyleCache->styles) {
PseudoId pseudoId = cache->pseudoElementType();
std::unique_ptr<RenderStyle> newPseudoStyle = renderer->getUncachedPseudoStyle({ pseudoId }, newStyle, newStyle);
Style::PseudoElementIdentifier pseudoElementIdentifier { cache->pseudoElementType(), cache->pseudoElementNameArgument() };
auto newPseudoStyle = renderer->getUncachedPseudoStyle(pseudoElementIdentifier, newStyle, newStyle);
if (!newPseudoStyle)
return true;
if (*newPseudoStyle != *cache) {
Expand Down
17 changes: 17 additions & 0 deletions Source/WebCore/style/ElementRuleCollector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,21 @@ void ElementRuleCollector::matchUARules(const RuleSet& rules)
sortAndTransferMatchedRules(DeclarationOrigin::UserAgent);
}

static Vector<AtomString> classListForNamedViewTransitionPseudoElement(const Document& document, const AtomString& name)
{
auto* activeViewTransition = document.activeViewTransition();
if (!activeViewTransition)
return { };

ASSERT(!name.isNull());

auto* capturedElement = activeViewTransition->namedElements().find(name);
if (!capturedElement)
return { };

return capturedElement->classList;
}

inline bool ElementRuleCollector::ruleMatches(const RuleData& ruleData, unsigned& specificity, ScopeOrdinal styleScopeOrdinal, const ContainerNode* scopingRoot)
{
// We know a sufficiently simple single part selector matches simply because we found it from the rule hash when filtering the RuleSet.
Expand Down Expand Up @@ -508,6 +523,8 @@ inline bool ElementRuleCollector::ruleMatches(const RuleData& ruleData, unsigned
context.pseudoId = m_pseudoElementRequest->pseudoId();
context.pseudoElementNameArgument = m_pseudoElementRequest->nameArgument();
context.scrollbarState = m_pseudoElementRequest->scrollbarState();
if (isNamedViewTransitionPseudoElement(m_pseudoElementRequest->identifier()))
context.classList = classListForNamedViewTransitionPseudoElement(element().document(), context.pseudoElementNameArgument);
}
context.styleScopeOrdinal = styleScopeOrdinal;
context.selectorMatchingState = m_selectorMatchingState;
Expand Down