-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[motion-path] Refactor various parts of path operation and RenderStyle
https://bugs.webkit.org/show_bug.cgi?id=260818 rdar://114584136 Reviewed by Simon Fraser. This refactoring addresses a few issues with the current motion path design. First, for paths that need additional data including its containing block rect or the element's offset from its containing block, it is not correct to use the path operation to hold these values, as the path operation is supposed to represent just the path specified by the css. Instead, pass down these necessary values through a TransformOperationData struct. Also added a test for this case to ensure that style sharing is not broken after this change. Also, factor out some of the code related to computing the ray path into the new MotionPath class, which now also includes applyMotionPathTransform. * LayoutTests/TestExpectations: * LayoutTests/imported/w3c/web-platform-tests/css/motion/offset-path-ray-019-expected.html: Added. * LayoutTests/imported/w3c/web-platform-tests/css/motion/offset-path-ray-019.html: Added. * Source/WebCore/Sources.txt: * Source/WebCore/WebCore.xcodeproj/project.pbxproj: * Source/WebCore/animation/KeyframeEffect.cpp: (WebCore::KeyframeEffect::computeTransformedExtentViaMatrix const): * Source/WebCore/css/ComputedStyleExtractor.cpp: (WebCore::computedTransform): * Source/WebCore/platform/animation/AcceleratedEffectValues.cpp: (WebCore::AcceleratedEffectValues::AcceleratedEffectValues): * Source/WebCore/rendering/PathOperation.cpp: (WebCore::RayPathOperation::create): (WebCore::RayPathOperation::clone const): (WebCore::RayPathOperation::getPath const): (WebCore::RayPathOperation::lengthForPath const): Deleted. (WebCore::RayPathOperation::lengthForContainPath const): Deleted. * Source/WebCore/rendering/PathOperation.h: (WebCore::PathOperation::getPath): Deleted. * Source/WebCore/rendering/RenderBlockFlow.cpp: * Source/WebCore/rendering/RenderBox.cpp: (WebCore::RenderBox::applyTransform const): * Source/WebCore/rendering/RenderLayer.cpp: (WebCore::RenderLayer::updateTransform): (WebCore::RenderLayer::setReferenceBoxForPathOperations): Deleted. * Source/WebCore/rendering/RenderLayer.h: * Source/WebCore/rendering/RenderLayerModelObject.cpp: (WebCore::RenderLayerModelObject::applySVGTransform const): * Source/WebCore/rendering/style/RenderStyle.cpp: (WebCore::RenderStyle::applyTransform const): (WebCore::RenderStyle::applyCSSTransform const): (WebCore::getTraversalStateAtDistance): Deleted. (WebCore::RenderStyle::applyMotionPathTransform const): Deleted. * Source/WebCore/rendering/style/RenderStyle.h: * Source/WebCore/svg/SVGGraphicsElement.cpp: (WebCore::SVGGraphicsElement::animatedLocalTransform const): * Source/WebKit/Shared/WebCoreArgumentCoders.serialization.in: Canonical link: https://commits.webkit.org/267416@main
- Loading branch information
Showing
23 changed files
with
379 additions
and
191 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
LayoutTests/imported/w3c/web-platform-tests/css/motion/offset-path-ray-019-expected.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>CSS Motion Path: ray paths</title> | ||
<style> | ||
#container1 { | ||
width: 100px; | ||
height: 100px; | ||
} | ||
#container2 { | ||
width: 200px; | ||
height: 200px; | ||
} | ||
#target1 { | ||
position: relative; | ||
width: 50px; | ||
height: 50px; | ||
background-color: lime; | ||
transform-origin: 0px 0px; | ||
transform: translateX(100px); | ||
} | ||
#target2 { | ||
position: relative; | ||
width: 50px; | ||
height: 50px; | ||
background-color: lime; | ||
transform-origin: 0px 0px; | ||
transform: translateX(200px); | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div id="container1"> | ||
<div id="target1"></div> | ||
</div> | ||
<div id="container2"> | ||
<div id="target2"></div> | ||
</div> | ||
</body> | ||
</html> |
38 changes: 38 additions & 0 deletions
38
LayoutTests/imported/w3c/web-platform-tests/css/motion/offset-path-ray-019.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>CSS Motion Path: ray paths</title> | ||
<link rel="help" href="https://drafts.fxtf.org/motion-1/#offset-path-property"> | ||
<link rel="match" href="offset-path-ray-007-ref.html"> | ||
<meta name="assert" content="Tests ray() when sharing style with different sized containing blocks."> | ||
<style> | ||
#container1 { | ||
width: 100px; | ||
height: 100px; | ||
} | ||
#container2 { | ||
width: 200px; | ||
height: 200px; | ||
} | ||
#target { | ||
position: relative; | ||
width: 50px; | ||
height: 50px; | ||
background-color: lime; | ||
transform-origin: 0px 0px; | ||
offset-path: ray(90deg sides); | ||
offset-distance: 100%; | ||
offset-position: auto; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div id="container1"> | ||
<div id="target"></div> | ||
</div> | ||
<div id="container2"> | ||
<div id="target"></div> | ||
</div> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
/* | ||
* 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. ``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 | ||
* 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. | ||
*/ | ||
|
||
#include "config.h" | ||
#include "MotionPath.h" | ||
|
||
#include "GeometryUtilities.h" | ||
#include "PathOperation.h" | ||
#include "PathTraversalState.h" | ||
|
||
namespace WebCore { | ||
|
||
std::optional<MotionPathData> MotionPath::motionPathDataForRenderer(const RenderElement& renderer) | ||
{ | ||
MotionPathData data; | ||
auto pathOperation = renderer.style().offsetPath(); | ||
if (!pathOperation || !is<RenderLayerModelObject>(renderer)) | ||
return std::nullopt; | ||
if (is<BoxPathOperation>(pathOperation)) { | ||
auto& boxPathOperation = downcast<BoxPathOperation>(*pathOperation); | ||
data.containingBlockBoundingRect = snapRectToDevicePixelsIfNeeded(renderer.referenceBoxRect(boxPathOperation.referenceBox()), downcast<RenderLayerModelObject>(renderer)); | ||
return data; | ||
} | ||
if (is<RayPathOperation>(pathOperation)) { | ||
if (auto* parentBlock = renderer.containingBlock()) { | ||
auto pathReferenceBoxRect = snapRectToDevicePixelsIfNeeded(parentBlock->transformReferenceBoxRect(parentBlock->style()), downcast<RenderLayerModelObject>(renderer)); | ||
data.containingBlockBoundingRect = pathReferenceBoxRect; | ||
auto left = renderer.style().left(); | ||
auto top = renderer.style().top(); | ||
data.offsetFromContainingBlock = FloatPoint(left.isPercent() ? left.value() / 100 * pathReferenceBoxRect.width() : left.value(), top.isPercent() ? top.value() / 100 * pathReferenceBoxRect.height() : top.value()); | ||
return data; | ||
} | ||
} | ||
return std::nullopt; | ||
} | ||
|
||
static PathTraversalState traversalStateAtDistance(const Path& path, const Length& distance) | ||
{ | ||
auto pathLength = path.length(); | ||
auto distanceValue = floatValueForLength(distance, pathLength); | ||
|
||
float resolvedLength = 0; | ||
if (path.isClosed()) { | ||
if (pathLength) { | ||
resolvedLength = fmod(distanceValue, pathLength); | ||
if (resolvedLength < 0) | ||
resolvedLength += pathLength; | ||
} | ||
} else | ||
resolvedLength = clampTo<float>(distanceValue, 0, pathLength); | ||
|
||
ASSERT(resolvedLength >= 0); | ||
return path.traversalStateAtLength(resolvedLength); | ||
} | ||
|
||
void MotionPath::applyMotionPathTransform(const RenderStyle& style, const TransformOperationData& transformData, TransformationMatrix& transform) | ||
{ | ||
if (!style.offsetPath()) | ||
return; | ||
|
||
auto& boundingBox = transformData.boundingBox(); | ||
auto transformOrigin = style.computeTransformOrigin(boundingBox).xy(); | ||
auto anchor = transformOrigin; | ||
if (!style.offsetAnchor().x().isAuto()) | ||
anchor = floatPointForLengthPoint(style.offsetAnchor(), boundingBox.size()) + boundingBox.location(); | ||
|
||
// Shift element to the point on path specified by offset-path and offset-distance. | ||
auto path = style.offsetPath()->getPath(transformData); | ||
if (!path) | ||
return; | ||
auto traversalState = traversalStateAtDistance(*path, style.offsetDistance()); | ||
transform.translate(traversalState.current().x(), traversalState.current().y()); | ||
|
||
// Shift element to the anchor specified by offset-anchor. | ||
transform.translate(-anchor.x(), -anchor.y()); | ||
|
||
auto shiftToOrigin = anchor - transformOrigin; | ||
transform.translate(shiftToOrigin.width(), shiftToOrigin.height()); | ||
|
||
// Apply rotation. | ||
auto rotation = style.offsetRotate(); | ||
if (rotation.hasAuto()) | ||
transform.rotate(traversalState.normalAngle() + rotation.angle()); | ||
else | ||
transform.rotate(rotation.angle()); | ||
|
||
transform.translate(-shiftToOrigin.width(), -shiftToOrigin.height()); | ||
} | ||
|
||
bool MotionPath::needsUpdateAfterContainingBlockLayout(const PathOperation& pathOperation) | ||
{ | ||
return is<RayPathOperation>(pathOperation) || is<BoxPathOperation>(pathOperation); | ||
} | ||
|
||
double MotionPath::lengthForRayPath(const RayPathOperation& rayPathOperation, const MotionPathData& data) | ||
{ | ||
auto& boundingBox = data.containingBlockBoundingRect; | ||
auto distances = distanceOfPointToSidesOfRect(boundingBox, data.offsetFromContainingBlock); | ||
|
||
switch (rayPathOperation.size()) { | ||
case RayPathOperation::Size::ClosestSide: | ||
return std::min( { distances.top(), distances.bottom(), distances.left(), distances.right() } ); | ||
case RayPathOperation::Size::FarthestSide: | ||
return std::max( { distances.top(), distances.bottom(), distances.left(), distances.right() } ); | ||
case RayPathOperation::Size::FarthestCorner: | ||
return std::hypot(std::max(distances.left(), distances.right()), std::max(distances.top(), distances.bottom())); | ||
case RayPathOperation::Size::ClosestCorner: | ||
return std::hypot(std::min(distances.left(), distances.right()), std::min(distances.top(), distances.bottom())); | ||
case RayPathOperation::Size::Sides: | ||
return lengthOfRayIntersectionWithBoundingBox(boundingBox, std::make_pair(data.offsetFromContainingBlock, rayPathOperation.angle())); | ||
} | ||
RELEASE_ASSERT_NOT_REACHED(); | ||
} | ||
|
||
double MotionPath::lengthForRayContainPath(const FloatRect& elementRect, double computedPathLength) | ||
{ | ||
return std::max(0.0, computedPathLength - (std::max(elementRect.width(), elementRect.height()) / 2)); | ||
} | ||
|
||
std::optional<Path> MotionPath::computePathForRay(const RayPathOperation& rayPathOperation, const TransformOperationData& data) | ||
{ | ||
auto motionPathData = data.motionPathData(); | ||
auto elementBoundingBox = data.boundingBox(); | ||
if (!motionPathData || motionPathData->containingBlockBoundingRect.isZero()) | ||
return std::nullopt; | ||
|
||
double length = lengthForRayPath(rayPathOperation, *motionPathData); | ||
if (rayPathOperation.isContaining()) | ||
length = lengthForRayContainPath(elementBoundingBox, length); | ||
|
||
auto radians = deg2rad(toPositiveAngle(rayPathOperation.angle()) - 90.0); | ||
auto point = FloatPoint(std::cos(radians) * length, std::sin(radians) * length); | ||
|
||
Path path; | ||
path.addLineTo(point); | ||
return path; | ||
} | ||
|
||
} // namespace WebCore |
Oops, something went wrong.