Skip to content

Commit

Permalink
::view-transition-group dynamic styles doesn't compute the transform.
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=269692
<rdar://123213197>

Reviewed by Tim Nguyen.

The dynamically computed style for :root::view-transition-group(transitionName)
should include 'a transform that would map capturedElement’s new element's
border box from the snapshot containing block origin to its current visual
position.'

* Source/WebCore/css/ComputedStyleExtractor.cpp:
(WebCore::ComputedStyleExtractor::matrixTransformValue):
(WebCore::transformOperationAsCSSValue):
(WebCore::computedTransform):
(WebCore::matrixTransformValue): Deleted.
* Source/WebCore/css/ComputedStyleExtractor.h:
* Source/WebCore/dom/ViewTransition.cpp:
(WebCore::ViewTransition::copyElementBaseProperties):

Canonical link: https://commits.webkit.org/275080@main
  • Loading branch information
mattwoodrow committed Feb 21, 2024
1 parent b79f9e5 commit 142e543
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
6 changes: 3 additions & 3 deletions Source/WebCore/css/ComputedStyleExtractor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ static LayoutRect sizingBox(RenderObject& renderer)
return box->style().boxSizing() == BoxSizing::BorderBox ? box->borderBoxRect() : box->computedCSSContentBoxRect();
}

static Ref<CSSFunctionValue> matrixTransformValue(const TransformationMatrix& transform, const RenderStyle& style)
Ref<CSSFunctionValue> ComputedStyleExtractor::matrixTransformValue(const TransformationMatrix& transform, const RenderStyle& style)
{
auto zoom = style.effectiveZoom();
if (transform.isAffine()) {
Expand Down Expand Up @@ -849,7 +849,7 @@ RefPtr<CSSFunctionValue> transformOperationAsCSSValue(const TransformOperation&
case TransformOperation::Type::Matrix3D: {
TransformationMatrix transform;
operation.apply(transform, { });
return matrixTransformValue(transform, style);
return ComputedStyleExtractor::matrixTransformValue(transform, style);
}
case TransformOperation::Type::Identity:
case TransformOperation::Type::None:
Expand All @@ -868,7 +868,7 @@ static Ref<CSSValue> computedTransform(RenderElement* renderer, const RenderStyl
if (renderer) {
TransformationMatrix transform;
style.applyTransform(transform, TransformOperationData(renderer->transformReferenceBoxRect(style), renderer), { });
return CSSTransformListValue::create(matrixTransformValue(transform, style));
return CSSTransformListValue::create(ComputedStyleExtractor::matrixTransformValue(transform, style));
}

// https://w3c.github.io/csswg-drafts/css-transforms-1/#serialization-of-the-computed-value
Expand Down
2 changes: 2 additions & 0 deletions Source/WebCore/css/ComputedStyleExtractor.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class RenderStyle;
class ShadowData;
class StyleColor;
class StylePropertyShorthand;
class TransformationMatrix;
class TransformOperation;

struct PropertyValue;
Expand Down Expand Up @@ -81,6 +82,7 @@ class ComputedStyleExtractor {
static Ref<CSSValue> valueForFilter(const RenderStyle&, const FilterOperations&, AdjustPixelValuesForComputedStyle = AdjustPixelValuesForComputedStyle::Yes);

static Ref<CSSPrimitiveValue> currentColorOrValidColor(const RenderStyle&, const StyleColor&);
static Ref<CSSFunctionValue> matrixTransformValue(const TransformationMatrix&, const RenderStyle&);

static bool updateStyleIfNeededForProperty(Element&, CSSPropertyID);

Expand Down
25 changes: 23 additions & 2 deletions Source/WebCore/dom/ViewTransition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "config.h"
#include "ViewTransition.h"

#include "CSSTransformListValue.h"
#include "CheckVisibilityOptions.h"
#include "ComputedStyleExtractor.h"
#include "Document.h"
Expand Down Expand Up @@ -409,7 +410,6 @@ void ViewTransition::clearViewTransition()

Ref<MutableStyleProperties> ViewTransition::copyElementBaseProperties(Element& element)
{
// FIXME: Transform - ComputedStyleExtractor.cpp::matrixTransformValue
ComputedStyleExtractor styleExtractor(&element);

CSSPropertyID transitionProperties[] = {
Expand All @@ -425,7 +425,28 @@ Ref<MutableStyleProperties> ViewTransition::copyElementBaseProperties(Element& e
CSSPropertyHeight,
};

return styleExtractor.copyProperties(transitionProperties);
Ref<MutableStyleProperties> props = styleExtractor.copyProperties(transitionProperties);

TransformationMatrix transform;
auto* renderer = element.renderer();
RenderElement* container = nullptr;
while (renderer && !renderer->isRenderView()) {
container = renderer->container();
if (!container)
break;
LayoutSize containerOffset = renderer->offsetFromContainer(*container, LayoutPoint());
TransformationMatrix localTransform;
renderer->getTransformFromContainer(nullptr, containerOffset, localTransform);
transform.multiply(localTransform);
renderer = container;
}

if (element.renderer()) {
Ref<CSSValue> transformListValue = CSSTransformListValue::create(ComputedStyleExtractor::matrixTransformValue(transform, element.renderer()->style()));
props->setProperty(CSSPropertyTransform, WTFMove(transformListValue));
}

return props;
}

// https://drafts.csswg.org/css-view-transitions-1/#update-pseudo-element-styles
Expand Down

0 comments on commit 142e543

Please sign in to comment.