Explorar o código

LibWeb: Sketch out a very basic SVG <clipPath> element

This element doesn't actually support anything at the moment, but it
still massively speeds up painting performance on Wikipedia! :^)

How? Because we no longer paint SVG <path> elements found inside
<clipPath> elements. SVGClipPathElement::create_layout_node() returns
nullptr which stops the layout tree builder from recursing further into
the subtree, and so the <path> element never gets a layout or paint box.

Mousing over Wikipedia now barely break 50% CPU usage on my machine :^)
Andreas Kling %!s(int64=3) %!d(string=hai) anos
pai
achega
e81594d9a1

+ 3 - 0
Userland/Libraries/LibWeb/Bindings/WindowObjectHelper.h

@@ -267,6 +267,8 @@
 #include <LibWeb/Bindings/ResizeObserverPrototype.h>
 #include <LibWeb/Bindings/SVGCircleElementConstructor.h>
 #include <LibWeb/Bindings/SVGCircleElementPrototype.h>
+#include <LibWeb/Bindings/SVGClipPathElementConstructor.h>
+#include <LibWeb/Bindings/SVGClipPathElementPrototype.h>
 #include <LibWeb/Bindings/SVGElementConstructor.h>
 #include <LibWeb/Bindings/SVGElementPrototype.h>
 #include <LibWeb/Bindings/SVGEllipseElementConstructor.h>
@@ -484,6 +486,7 @@
     ADD_WINDOW_OBJECT_INTERFACE(SubtleCrypto)                                                       \
     ADD_WINDOW_OBJECT_INTERFACE(SVGElement)                                                         \
     ADD_WINDOW_OBJECT_INTERFACE(SVGCircleElement)                                                   \
+    ADD_WINDOW_OBJECT_INTERFACE(SVGClipPathElement)                                                 \
     ADD_WINDOW_OBJECT_INTERFACE(SVGEllipseElement)                                                  \
     ADD_WINDOW_OBJECT_INTERFACE(SVGGeometryElement)                                                 \
     ADD_WINDOW_OBJECT_INTERFACE(SVGGraphicsElement)                                                 \

+ 3 - 0
Userland/Libraries/LibWeb/CMakeLists.txt

@@ -317,6 +317,8 @@ set(SOURCES
     SVG/AttributeNames.cpp
     SVG/AttributeParser.cpp
     SVG/SVGAnimatedLength.cpp
+    SVG/SVGClipPathElement.cpp
+    SVG/SVGElement.cpp
     SVG/SVGElement.cpp
     SVG/SVGGElement.cpp
     SVG/SVGGeometryElement.cpp
@@ -581,6 +583,7 @@ libweb_js_wrapper(NavigationTiming/PerformanceTiming)
 libweb_js_wrapper(RequestIdleCallback/IdleDeadline)
 libweb_js_wrapper(ResizeObserver/ResizeObserver)
 libweb_js_wrapper(SVG/SVGAnimatedLength)
+libweb_js_wrapper(SVG/SVGClipPathElement)
 libweb_js_wrapper(SVG/SVGElement)
 libweb_js_wrapper(SVG/SVGGeometryElement)
 libweb_js_wrapper(SVG/SVGGraphicsElement)

+ 4 - 0
Userland/Libraries/LibWeb/DOM/ElementFactory.cpp

@@ -77,6 +77,7 @@
 #include <LibWeb/HTML/HTMLUnknownElement.h>
 #include <LibWeb/HTML/HTMLVideoElement.h>
 #include <LibWeb/SVG/SVGCircleElement.h>
+#include <LibWeb/SVG/SVGClipPathElement.h>
 #include <LibWeb/SVG/SVGEllipseElement.h>
 #include <LibWeb/SVG/SVGGElement.h>
 #include <LibWeb/SVG/SVGLineElement.h>
@@ -260,6 +261,9 @@ NonnullRefPtr<Element> create_element(Document& document, FlyString local_name,
         return adopt_ref(*new HTML::HTMLElement(document, move(qualified_name)));
     if (lowercase_tag_name == SVG::TagNames::svg)
         return adopt_ref(*new SVG::SVGSVGElement(document, move(qualified_name)));
+    // FIXME: Support SVG's mixedCase tag names properly.
+    if (lowercase_tag_name.equals_ignoring_case(SVG::TagNames::clipPath))
+        return adopt_ref(*new SVG::SVGClipPathElement(document, move(qualified_name)));
     if (lowercase_tag_name == SVG::TagNames::circle)
         return adopt_ref(*new SVG::SVGCircleElement(document, move(qualified_name)));
     if (lowercase_tag_name == SVG::TagNames::ellipse)

+ 2 - 0
Userland/Libraries/LibWeb/Forward.h

@@ -296,6 +296,7 @@ class ResizeObserver;
 namespace Web::SVG {
 class SVGAnimatedLength;
 class SVGCircleElement;
+class SVGClipPathElement;
 class SVGElement;
 class SVGEllipseElement;
 class SVGGeometryElement;
@@ -522,6 +523,7 @@ class SubmitEventWrapper;
 class SubtleCryptoWrapper;
 class SVGAnimatedLengthWrapper;
 class SVGCircleElementWrapper;
+class SVGClipPathElementWrapper;
 class SVGElementWrapper;
 class SVGEllipseElementWrapper;
 class SVGGeometryElementWrapper;

+ 25 - 0
Userland/Libraries/LibWeb/SVG/SVGClipPathElement.cpp

@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <LibWeb/SVG/SVGClipPathElement.h>
+
+namespace Web::SVG {
+
+SVGClipPathElement::SVGClipPathElement(DOM::Document& document, DOM::QualifiedName qualified_name)
+    : SVGElement(document, move(qualified_name))
+{
+}
+
+SVGClipPathElement::~SVGClipPathElement()
+{
+}
+
+RefPtr<Layout::Node> SVGClipPathElement::create_layout_node(NonnullRefPtr<CSS::StyleProperties>)
+{
+    return nullptr;
+}
+
+}

+ 23 - 0
Userland/Libraries/LibWeb/SVG/SVGClipPathElement.h

@@ -0,0 +1,23 @@
+/*
+ * Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+#include <LibWeb/SVG/SVGElement.h>
+
+namespace Web::SVG {
+
+class SVGClipPathElement final : public SVGElement {
+public:
+    using WrapperType = Bindings::SVGClipPathElementWrapper;
+
+    SVGClipPathElement(DOM::Document&, DOM::QualifiedName);
+    virtual ~SVGClipPathElement();
+
+    virtual RefPtr<Layout::Node> create_layout_node(NonnullRefPtr<CSS::StyleProperties>) override;
+};
+
+}

+ 7 - 0
Userland/Libraries/LibWeb/SVG/SVGClipPathElement.idl

@@ -0,0 +1,7 @@
+[Exposed=Window]
+interface SVGClipPathElement : SVGElement {
+
+    // FIXME: readonly attribute SVGAnimatedEnumeration clipPathUnits;
+    // FIXME: readonly attribute SVGAnimatedTransformList transform;
+
+};

+ 1 - 0
Userland/Libraries/LibWeb/SVG/TagNames.h

@@ -24,6 +24,7 @@ namespace Web::SVG::TagNames {
 
 #define ENUMERATE_SVG_TAGS             \
     ENUMERATE_SVG_GRAPHICS_TAGS        \
+    __ENUMERATE_SVG_TAG(clipPath)      \
     __ENUMERATE_SVG_TAG(desc)          \
     __ENUMERATE_SVG_TAG(foreignObject) \
     __ENUMERATE_SVG_TAG(script)        \