Title: [292382] trunk
Revision
292382
Author
[email protected]
Date
2022-04-05 01:03:38 -0700 (Tue, 05 Apr 2022)

Log Message

Support rendering url(), CSS basic shapes other than path(), and coord-box for offset-path
https://bugs.webkit.org/show_bug.cgi?id=233382

Reviewed by Simon Fraser.

LayoutTests/imported/w3c:

* web-platform-tests/css/motion/offset-path-shape-expected.html: Added.
* web-platform-tests/css/motion/offset-path-shape.html: Added.
* web-platform-tests/css/motion/offset-path-url-expected.html: Added.
* web-platform-tests/css/motion/offset-path-url.html: Added.

Source/WebCore:

Introduce support for url(), CSS basic shapes, and coord-box. Url() allows references to SVG
shapes, so we check for either an SVGPathElement or SVGGeometryElement (which includes
circles, polygons, etc.). We can then get a Path object for that particular SVGElement
 using pathFromGraphicsElement(). For coord-box, we check the value for the BoxPathOperation
(if it exists) in updateTransform(), and choose the corresponding reference box to the
referenceBox() value of the BoxPathOperation.

Tests: imported/w3c/web-platform-tests/css/motion/offset-path-shape.html
       imported/w3c/web-platform-tests/css/motion/offset-path-url.html

* Sources.txt:
* rendering/PathOperation.cpp: Added.
(WebCore::ReferencePathOperation::create):
(WebCore::ReferencePathOperation::ReferencePathOperation):
(WebCore::ReferencePathOperation::element const):
* rendering/PathOperation.h:
* rendering/RenderLayer.cpp:
(WebCore::RenderLayer::updateTransform):
* rendering/style/RenderStyle.cpp:
(WebCore::getPathFromPathOperation):
* style/StyleBuilderConverter.h:
(WebCore::Style::BuilderConverter::convertPathOperation):

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (292381 => 292382)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2022-04-05 08:01:50 UTC (rev 292381)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2022-04-05 08:03:38 UTC (rev 292382)
@@ -1,3 +1,15 @@
+2022-04-05  Nikolaos Mouchtaris  <[email protected]>
+
+        Support rendering url(), CSS basic shapes other than path(), and coord-box for offset-path
+        https://bugs.webkit.org/show_bug.cgi?id=233382
+
+        Reviewed by Simon Fraser.
+
+        * web-platform-tests/css/motion/offset-path-shape-expected.html: Added.
+        * web-platform-tests/css/motion/offset-path-shape.html: Added.
+        * web-platform-tests/css/motion/offset-path-url-expected.html: Added.
+        * web-platform-tests/css/motion/offset-path-url.html: Added.
+
 2022-04-04  Ziran Sun  <[email protected]>
 
         [Forms] change the default appearance of button, checkbox etc. to 'auto'

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/css/motion/offset-path-geometry-box-expected.html (0 => 292382)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/motion/offset-path-geometry-box-expected.html	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/motion/offset-path-geometry-box-expected.html	2022-04-05 08:03:38 UTC (rev 292382)
@@ -0,0 +1,21 @@
+<!DOCTYPE html>
+<html>
+  <head>
+    <title>CSS Motion Path: path(geometry-box) paths</title>
+    <style>
+      #target {
+        position: absolute;
+        left: 300px;
+        top: 0px;
+        width: 300px;
+        height: 200px;
+        background-color: lime;
+        transform-origin: 0px 0px;
+        transform: translate(0px, 0px);
+      }
+    </style>
+  </head>
+  <body>
+    <div id="target"></div>
+  </body>
+</html>

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/css/motion/offset-path-geometry-box.html (0 => 292382)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/motion/offset-path-geometry-box.html	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/motion/offset-path-geometry-box.html	2022-04-05 08:03:38 UTC (rev 292382)
@@ -0,0 +1,24 @@
+<!DOCTYPE html>
+<html>
+  <head>
+    <title>CSS Motion Path: path(basic-shape) paths</title>
+    <link rel="help" href=""
+    <link rel="match" href=""
+    <meta name="assert" content="This tests that path(<geometry-box>) generates a rotation and translation.">
+    <style>
+      #target {
+        position: absolute;
+        left: 300px;
+        top: 0px;
+        width: 300px;
+        height: 200px;
+        background-color: lime;
+        transform-origin: 0px 0px;
+        offset-path: stroke-box;
+      }
+    </style>
+  </head>
+  <body>
+    <div id="target"></div>
+  </body>
+</html>

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/css/motion/offset-path-shape-expected.html (0 => 292382)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/motion/offset-path-shape-expected.html	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/motion/offset-path-shape-expected.html	2022-04-05 08:03:38 UTC (rev 292382)
@@ -0,0 +1,21 @@
+<!DOCTYPE html>
+<html>
+  <head>
+    <title>CSS Motion Path: path(basic-shape) paths</title>
+    <style>
+      #target {
+        position: absolute;
+        left: 300px;
+        top: 0px;
+        width: 300px;
+        height: 200px;
+        background-color: lime;
+        transform-origin: 0px 0px;
+        transform: translate(35px, 44px);
+      }
+    </style>
+  </head>
+  <body>
+    <div id="target"></div>
+  </body>
+</html>

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/css/motion/offset-path-shape.html (0 => 292382)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/motion/offset-path-shape.html	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/motion/offset-path-shape.html	2022-04-05 08:03:38 UTC (rev 292382)
@@ -0,0 +1,24 @@
+<!DOCTYPE html>
+<html>
+  <head>
+    <title>CSS Motion Path: path(basic-shape) paths</title>
+    <link rel="help" href=""
+    <link rel="match" href=""
+    <meta name="assert" content="This tests that path(<basic-shape>) generates a rotation and translation.">
+    <style>
+      #target {
+        position: absolute;
+        left: 300px;
+        top: 0px;
+        width: 300px;
+        height: 200px;
+        background-color: lime;
+        transform-origin: 0px 0px;
+        offset-path: inset(22% 12% 15px 35px);
+      }
+    </style>
+  </head>
+  <body>
+    <div id="target"></div>
+  </body>
+</html>

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/css/motion/offset-path-url-expected.html (0 => 292382)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/motion/offset-path-url-expected.html	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/motion/offset-path-url-expected.html	2022-04-05 08:03:38 UTC (rev 292382)
@@ -0,0 +1,21 @@
+<!DOCTYPE html>
+<html>
+  <head>
+    <title>CSS Motion Path: path(url) paths</title>
+    <style>
+      #target {
+        position: absolute;
+        left: 300px;
+        top: 0px;
+        width: 300px;
+        height: 200px;
+        background-color: lime;
+        transform-origin: 0px 0px;
+        transform: rotate(90deg) translate(120px);
+      }
+    </style>
+  </head>
+  <body>
+    <div id="target"></div>
+  </body>
+</html>

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/css/motion/offset-path-url.html (0 => 292382)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/motion/offset-path-url.html	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/motion/offset-path-url.html	2022-04-05 08:03:38 UTC (rev 292382)
@@ -0,0 +1,27 @@
+<!DOCTYPE html>
+<html>
+  <head>
+    <title>CSS Motion Path: path(url) paths</title>
+    <link rel="help" href=""
+    <link rel="match" href=""
+    <meta name="assert" content="This tests that path(<url>) generates a rotation and translation.">
+    <style>
+      #target {
+        position: absolute;
+        left: 300px;
+        top: 0px;
+        width: 300px;
+        height: 200px;
+        background-color: lime;
+        transform-origin: 0px 0px;
+        offset-path: url(#svgPath);
+      }
+    </style>
+  </head>
+  <body>
+    <div id="target"></div>
+    <svg height="220" width="300" xmlns="http://www.w3.org/2000/svg">
+        <path id="svgPath" d='m 0 120 v 200'/>
+    </svg>
+  </body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (292381 => 292382)


--- trunk/Source/WebCore/ChangeLog	2022-04-05 08:01:50 UTC (rev 292381)
+++ trunk/Source/WebCore/ChangeLog	2022-04-05 08:03:38 UTC (rev 292382)
@@ -1,3 +1,33 @@
+2022-04-05  Nikolaos Mouchtaris  <[email protected]>
+
+        Support rendering url(), CSS basic shapes other than path(), and coord-box for offset-path
+        https://bugs.webkit.org/show_bug.cgi?id=233382
+
+        Reviewed by Simon Fraser.
+
+        Introduce support for url(), CSS basic shapes, and coord-box. Url() allows references to SVG 
+        shapes, so we check for either an SVGPathElement or SVGGeometryElement (which includes 
+        circles, polygons, etc.). We can then get a Path object for that particular SVGElement 
+         using pathFromGraphicsElement(). For coord-box, we check the value for the BoxPathOperation
+        (if it exists) in updateTransform(), and choose the corresponding reference box to the 
+        referenceBox() value of the BoxPathOperation.
+
+        Tests: imported/w3c/web-platform-tests/css/motion/offset-path-shape.html
+               imported/w3c/web-platform-tests/css/motion/offset-path-url.html
+
+        * Sources.txt:
+        * rendering/PathOperation.cpp: Added.
+        (WebCore::ReferencePathOperation::create):
+        (WebCore::ReferencePathOperation::ReferencePathOperation):
+        (WebCore::ReferencePathOperation::element const):
+        * rendering/PathOperation.h:
+        * rendering/RenderLayer.cpp:
+        (WebCore::RenderLayer::updateTransform):
+        * rendering/style/RenderStyle.cpp:
+        (WebCore::getPathFromPathOperation):
+        * style/StyleBuilderConverter.h:
+        (WebCore::Style::BuilderConverter::convertPathOperation):
+
 2022-04-05  Megan Gardner  <[email protected]>
 
         Moving forwards and backwards by sentences across a table results in different breaks in each direction.

Modified: trunk/Source/WebCore/Sources.txt (292381 => 292382)


--- trunk/Source/WebCore/Sources.txt	2022-04-05 08:01:50 UTC (rev 292381)
+++ trunk/Source/WebCore/Sources.txt	2022-04-05 08:03:38 UTC (rev 292382)
@@ -2327,6 +2327,7 @@
 rendering/LegacyInlineTextBox.cpp
 rendering/MarkedText.cpp
 rendering/OrderIterator.cpp
+rendering/PathOperation.cpp
 rendering/PointerEventsHitRules.cpp
 rendering/ReferencedSVGResources.cpp
 rendering/RenderAttachment.cpp

Added: trunk/Source/WebCore/rendering/PathOperation.cpp (0 => 292382)


--- trunk/Source/WebCore/rendering/PathOperation.cpp	                        (rev 0)
+++ trunk/Source/WebCore/rendering/PathOperation.cpp	2022-04-05 08:03:38 UTC (rev 292382)
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2022 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.
+ */
+
+#include "config.h"
+#include "PathOperation.h"
+
+#include "SVGElement.h"
+
+namespace WebCore {
+
+Ref<ReferencePathOperation> ReferencePathOperation::create(const String& url, const String& fragment, const RefPtr<SVGElement> element)
+{
+    return adoptRef(*new ReferencePathOperation(url, fragment, element));
+}
+
+
+ReferencePathOperation::ReferencePathOperation(const String& url, const String& fragment, const RefPtr<SVGElement> element)
+    : PathOperation(Reference)
+    , m_url(url)
+    , m_fragment(fragment)
+    , m_element(element)
+{
+}
+
+const SVGElement* ReferencePathOperation::element() const
+{
+    return m_element.get();
+}
+} // namespace WebCore

Modified: trunk/Source/WebCore/rendering/PathOperation.h (292381 => 292382)


--- trunk/Source/WebCore/rendering/PathOperation.h	2022-04-05 08:01:50 UTC (rev 292381)
+++ trunk/Source/WebCore/rendering/PathOperation.h	2022-04-05 08:03:38 UTC (rev 292382)
@@ -38,6 +38,8 @@
 
 namespace WebCore {
 
+class SVGElement;
+
 class PathOperation : public RefCounted<PathOperation> {
 public:
     enum OperationType {
@@ -66,13 +68,10 @@
 
 class ReferencePathOperation final : public PathOperation {
 public:
-    static Ref<ReferencePathOperation> create(const String& url, const String& fragment)
-    {
-        return adoptRef(*new ReferencePathOperation(url, fragment));
-    }
-
+    static Ref<ReferencePathOperation> create(const String& url, const String& fragment, const RefPtr<SVGElement>);
     const String& url() const { return m_url; }
     const String& fragment() const { return m_fragment; }
+    const SVGElement* element() const;
 
 private:
     bool operator==(const PathOperation& other) const override
@@ -83,15 +82,11 @@
         return m_url == referenceClip.m_url;
     }
 
-    ReferencePathOperation(const String& url, const String& fragment)
-        : PathOperation(Reference)
-        , m_url(url)
-        , m_fragment(fragment)
-    {
-    }
+    ReferencePathOperation(const String& url, const String& fragment, const RefPtr<SVGElement>);
 
     String m_url;
     String m_fragment;
+    RefPtr<SVGElement> m_element;
 };
 
 class ShapePathOperation final : public PathOperation {
@@ -142,6 +137,14 @@
         path.addRoundedRect(boundingRect);
         return path;
     }
+    
+    void setPathForReferenceRect(const FloatRoundedRect& boundingRect)
+    {
+        m_path.clear();
+        m_path.addRoundedRect(boundingRect);
+    }
+    
+    const Path getPath() const { return m_path; }
     CSSBoxType referenceBox() const { return m_referenceBox; }
 
 private:
@@ -158,7 +161,7 @@
         , m_referenceBox(referenceBox)
     {
     }
-
+    Path m_path;
     CSSBoxType m_referenceBox;
 };
 

Modified: trunk/Source/WebCore/rendering/RenderLayer.cpp (292381 => 292382)


--- trunk/Source/WebCore/rendering/RenderLayer.cpp	2022-04-05 08:01:50 UTC (rev 292381)
+++ trunk/Source/WebCore/rendering/RenderLayer.cpp	2022-04-05 08:03:38 UTC (rev 292382)
@@ -1334,8 +1334,15 @@
 
         // FIXME: [LBSE] Upstream reference box computation for RenderSVGModelObject derived renderers
         FloatRect referenceBox;
-        if (is<RenderBox>(renderer()))
+        if (is<RenderBox>(renderer())) {
             referenceBox = snapRectToDevicePixels(downcast<RenderBox>(renderer()).referenceBox(transformBoxToCSSBoxType(renderer().style().transformBox())), renderer().document().deviceScaleFactor());
+            if (auto pathOperation = renderer().style().offsetPath()) {
+                if (is<BoxPathOperation>(pathOperation)) {
+                    auto boxPathOperation = downcast<BoxPathOperation>(pathOperation);
+                    boxPathOperation->setPathForReferenceRect(FloatRoundedRect(snapRectToDevicePixels(downcast<RenderBox>(renderer()).referenceBox(boxPathOperation->referenceBox()), renderer().document().deviceScaleFactor())));
+                }
+            }
+        }
 
         renderer().applyTransform(*m_transform, referenceBox);
         makeMatrixRenderable(*m_transform, canRender3DTransforms());

Modified: trunk/Source/WebCore/rendering/style/RenderStyle.cpp (292381 => 292382)


--- trunk/Source/WebCore/rendering/style/RenderStyle.cpp	2022-04-05 08:01:50 UTC (rev 292381)
+++ trunk/Source/WebCore/rendering/style/RenderStyle.cpp	2022-04-05 08:03:38 UTC (rev 292382)
@@ -41,6 +41,7 @@
 #include "RenderBlock.h"
 #include "RenderObject.h"
 #include "RenderTheme.h"
+#include "SVGPathData.h"
 #include "ScaleTransformOperation.h"
 #include "ShadowData.h"
 #include "StyleBuilderConverter.h"
@@ -1523,12 +1524,19 @@
 
 static std::optional<Path> getPathFromPathOperation(const FloatRect& box, const PathOperation& operation)
 {
-    if (operation.type() == PathOperation::Shape)
+    switch (operation.type()) {
+    case PathOperation::Shape:
         return downcast<ShapePathOperation>(operation).pathForReferenceRect(box);
-
-    // FIXME: support Reference and Box type.
-    // https://bugs.webkit.org/show_bug.cgi?id=233382
-    return std::nullopt;
+    case PathOperation::Reference:
+        if (!is<SVGPathElement>(downcast<ReferencePathOperation>(operation).element()) && !is<SVGGeometryElement>(downcast<ReferencePathOperation>(operation).element()))
+            return std::nullopt;
+        return pathFromGraphicsElement(downcast<ReferencePathOperation>(operation).element());
+    case PathOperation::Box:
+        return downcast<BoxPathOperation>(operation).getPath();
+    case PathOperation::Ray:
+        // FIXME: implement ray- https://bugs.webkit.org/show_bug.cgi?id=233344
+        return std::nullopt;
+    }
 }
 
 static PathTraversalState getTraversalStateAtDistance(const Path& path, const Length& distance)

Modified: trunk/Source/WebCore/style/StyleBuilderConverter.h (292381 => 292382)


--- trunk/Source/WebCore/style/StyleBuilderConverter.h	2022-04-05 08:01:50 UTC (rev 292381)
+++ trunk/Source/WebCore/style/StyleBuilderConverter.h	2022-04-05 08:03:38 UTC (rev 292382)
@@ -55,6 +55,8 @@
 #include "Pair.h"
 #include "QuotesData.h"
 #include "RuntimeEnabledFeatures.h"
+#include "SVGElementTypeHelpers.h"
+#include "SVGPathElement.h"
 #include "SVGURIReference.h"
 #include "Settings.h"
 #include "StyleBuilderState.h"
@@ -633,7 +635,8 @@
             String cssURLValue = primitiveValue.stringValue();
             String fragment = SVGURIReference::fragmentIdentifierFromIRIString(cssURLValue, builderState.document());
             // FIXME: It doesn't work with external SVG references (see https://bugs.webkit.org/show_bug.cgi?id=126133)
-            return ReferencePathOperation::create(cssURLValue, fragment);
+            auto target = SVGURIReference::targetElementFromIRIString(cssURLValue, builderState.document());
+            return ReferencePathOperation::create(cssURLValue, fragment, downcast<SVGElement>(target.element.get()));
         }
         ASSERT(primitiveValue.valueID() == CSSValueNone);
         return nullptr;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to