Skip to content

Commit

Permalink
[view-transitions] Support style inheritance in the pseudo-element tree
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=269808
rdar://123331760

Reviewed by Anne van Kesteren.

The style inheritance must follow the pseudo-element tree structure. This allows the different `inherit` declarations in the `viewTransitions.css` UA stylesheet to work.

This is also ergonomic for developers since they can just set the animation-duration once and have it cascade down the pseudo-element tree.

Also fix the cache to actually store the named view transition style when resolving, otherwise `TreeResolver::makeResolutionContextForPseudoElement` can't fetch it.

* LayoutTests/imported/w3c/web-platform-tests/css/css-view-transitions/style-inheritance-expected.txt: Rebaselined test.
* Source/WebCore/dom/Element.cpp:
(WebCore::Element::resolvePseudoElementStyle):
* Source/WebCore/rendering/style/RenderStyleSetters.h:
(WebCore::RenderStyle::setPseudoElementNameArgument):
* Source/WebCore/style/StyleTreeResolver.cpp:
(WebCore::Style::TreeResolver::resolveElement):
(WebCore::Style::TreeResolver::makeResolutionContextForPseudoElement):

Canonical link: https://commits.webkit.org/275121@main
  • Loading branch information
nt1m committed Feb 21, 2024
1 parent 71b8fba commit ce47267
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
CONSOLE MESSAGE: Unhandled Promise Rejection: Error: assert_equals: group expected "rgb(255, 0, 0)" but got "rgba(0, 0, 0, 0)"

Harness Error (FAIL), message = Unhandled rejection: assert_equals: group expected "rgb(255, 0, 0)" but got "rgba(0, 0, 0, 0)"

PASS style inheritance of pseudo elements

3 changes: 1 addition & 2 deletions Source/WebCore/dom/Element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4141,8 +4141,7 @@ const RenderStyle& Element::resolvePseudoElementStyle(const Style::PseudoElement
style->inheritFrom(*parentStyle);
// FIXME: RenderStyle should switch to use PseudoElementIdentifier.
style->setPseudoElementType(pseudoElementIdentifier.pseudoId);
if (!pseudoElementIdentifier.nameArgument.isNull())
style->setPseudoElementNameArgument(pseudoElementIdentifier.nameArgument);
style->setPseudoElementNameArgument(pseudoElementIdentifier.nameArgument);
}

auto* computedStyle = style.get();
Expand Down
3 changes: 2 additions & 1 deletion Source/WebCore/rendering/style/RenderStyleSetters.h
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,8 @@ inline void RenderStyle::setPseudoElementNameArgument(const AtomString& identifi
|| pseudoElementType() == PseudoId::ViewTransitionImagePair
|| pseudoElementType() == PseudoId::ViewTransitionNew
|| pseudoElementType() == PseudoId::ViewTransitionOld
|| pseudoElementType() == PseudoId::Highlight);
|| pseudoElementType() == PseudoId::Highlight
|| identifier.isNull());
SET_NESTED(m_nonInheritedData, rareData, pseudoElementNameArgument, identifier);
}

Expand Down
22 changes: 19 additions & 3 deletions Source/WebCore/style/StyleTreeResolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,7 @@ auto TreeResolver::resolveElement(Element& element, const RenderStyle* existingS
return pseudoElementChange;
if (pseudoElementUpdate->recompositeLayer)
update.recompositeLayer = true;
if (pseudoElementIdentifier.nameArgument.isNull())
update.style->addCachedPseudoStyle(WTFMove(pseudoElementUpdate->style));
update.style->addCachedPseudoStyle(WTFMove(pseudoElementUpdate->style));
return pseudoElementUpdate->change;
};

Expand Down Expand Up @@ -547,9 +546,26 @@ ResolutionContext TreeResolver::makeResolutionContext()
ResolutionContext TreeResolver::makeResolutionContextForPseudoElement(const ElementUpdate& elementUpdate, const PseudoElementIdentifier& pseudoElementIdentifier)
{
auto parentStyle = [&]() -> const RenderStyle* {
if (pseudoElementIdentifier.pseudoId == PseudoId::FirstLetter) {
switch (pseudoElementIdentifier.pseudoId) {
case PseudoId::FirstLetter:
if (auto* firstLineStyle = elementUpdate.style->getCachedPseudoStyle({ PseudoId::FirstLine }))
return firstLineStyle;
break;
case PseudoId::ViewTransitionGroup:
if (auto* viewTransitionStyle = elementUpdate.style->getCachedPseudoStyle({ PseudoId::ViewTransition }))
return viewTransitionStyle;
break;
case PseudoId::ViewTransitionImagePair:
if (auto* groupStyle = elementUpdate.style->getCachedPseudoStyle({ PseudoId::ViewTransitionGroup, pseudoElementIdentifier.nameArgument }))
return groupStyle;
break;
case PseudoId::ViewTransitionOld:
case PseudoId::ViewTransitionNew:
if (auto* imagePairStyle = elementUpdate.style->getCachedPseudoStyle({ PseudoId::ViewTransitionImagePair, pseudoElementIdentifier.nameArgument }))
return imagePairStyle;
break;
default:
break;
}
return elementUpdate.style.get();
};
Expand Down

0 comments on commit ce47267

Please sign in to comment.