summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2022-04-10 19:05:12 +0200
committerAndreas Kling <kling@serenityos.org>2022-04-10 21:35:55 +0200
commite81594d9a1528c57d5c94b475e11efe26a324766 (patch)
tree7c6f70dcfc6bde1e46dc00bd1c9a345931a799b5 /Userland/Libraries/LibWeb
parentc6e79124c7f479da5bb2b97cc59868763d013d51 (diff)
downloadserenity-e81594d9a1528c57d5c94b475e11efe26a324766.zip
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 :^)
Diffstat (limited to 'Userland/Libraries/LibWeb')
-rw-r--r--Userland/Libraries/LibWeb/Bindings/WindowObjectHelper.h3
-rw-r--r--Userland/Libraries/LibWeb/CMakeLists.txt3
-rw-r--r--Userland/Libraries/LibWeb/DOM/ElementFactory.cpp4
-rw-r--r--Userland/Libraries/LibWeb/Forward.h2
-rw-r--r--Userland/Libraries/LibWeb/SVG/SVGClipPathElement.cpp25
-rw-r--r--Userland/Libraries/LibWeb/SVG/SVGClipPathElement.h23
-rw-r--r--Userland/Libraries/LibWeb/SVG/SVGClipPathElement.idl7
-rw-r--r--Userland/Libraries/LibWeb/SVG/TagNames.h1
8 files changed, 68 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/Bindings/WindowObjectHelper.h b/Userland/Libraries/LibWeb/Bindings/WindowObjectHelper.h
index 917c188366..242e9dbf21 100644
--- a/Userland/Libraries/LibWeb/Bindings/WindowObjectHelper.h
+++ b/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) \
diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt
index ae3f664a38..578fd3d8b3 100644
--- a/Userland/Libraries/LibWeb/CMakeLists.txt
+++ b/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)
diff --git a/Userland/Libraries/LibWeb/DOM/ElementFactory.cpp b/Userland/Libraries/LibWeb/DOM/ElementFactory.cpp
index 1e7cc2f1d5..0a5806cec0 100644
--- a/Userland/Libraries/LibWeb/DOM/ElementFactory.cpp
+++ b/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)
diff --git a/Userland/Libraries/LibWeb/Forward.h b/Userland/Libraries/LibWeb/Forward.h
index 94ff7aee15..7f940c53e5 100644
--- a/Userland/Libraries/LibWeb/Forward.h
+++ b/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;
diff --git a/Userland/Libraries/LibWeb/SVG/SVGClipPathElement.cpp b/Userland/Libraries/LibWeb/SVG/SVGClipPathElement.cpp
new file mode 100644
index 0000000000..c1a9f0f1a8
--- /dev/null
+++ b/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;
+}
+
+}
diff --git a/Userland/Libraries/LibWeb/SVG/SVGClipPathElement.h b/Userland/Libraries/LibWeb/SVG/SVGClipPathElement.h
new file mode 100644
index 0000000000..20755d6842
--- /dev/null
+++ b/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;
+};
+
+}
diff --git a/Userland/Libraries/LibWeb/SVG/SVGClipPathElement.idl b/Userland/Libraries/LibWeb/SVG/SVGClipPathElement.idl
new file mode 100644
index 0000000000..15b1022160
--- /dev/null
+++ b/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;
+
+};
diff --git a/Userland/Libraries/LibWeb/SVG/TagNames.h b/Userland/Libraries/LibWeb/SVG/TagNames.h
index 8593a204ce..ac005c6af9 100644
--- a/Userland/Libraries/LibWeb/SVG/TagNames.h
+++ b/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) \