From 9e22f01ebad1b08367b3a9719e79f396351ea175 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 10 Aug 2023 09:55:15 +0200 Subject: [PATCH] LibWeb: Stub out SVGMaskElement Just enough that we stop creating layout nodes for mask elements, which was making some SVG content look very wrong. :^) --- ...ement-should-not-participate-in-layout.txt | 17 ++++++++++ ...ment-should-not-participate-in-layout.html | 7 +++++ Userland/Libraries/LibWeb/CMakeLists.txt | 1 + .../Libraries/LibWeb/DOM/ElementFactory.cpp | 3 ++ Userland/Libraries/LibWeb/Forward.h | 1 + .../Libraries/LibWeb/SVG/SVGMaskElement.cpp | 31 +++++++++++++++++++ .../Libraries/LibWeb/SVG/SVGMaskElement.h | 26 ++++++++++++++++ .../Libraries/LibWeb/SVG/SVGMaskElement.idl | 11 +++++++ Userland/Libraries/LibWeb/SVG/TagNames.h | 1 + Userland/Libraries/LibWeb/idl_files.cmake | 1 + 10 files changed, 99 insertions(+) create mode 100644 Tests/LibWeb/Layout/expected/svg/mask-element-should-not-participate-in-layout.txt create mode 100644 Tests/LibWeb/Layout/input/svg/mask-element-should-not-participate-in-layout.html create mode 100644 Userland/Libraries/LibWeb/SVG/SVGMaskElement.cpp create mode 100644 Userland/Libraries/LibWeb/SVG/SVGMaskElement.h create mode 100644 Userland/Libraries/LibWeb/SVG/SVGMaskElement.idl diff --git a/Tests/LibWeb/Layout/expected/svg/mask-element-should-not-participate-in-layout.txt b/Tests/LibWeb/Layout/expected/svg/mask-element-should-not-participate-in-layout.txt new file mode 100644 index 00000000000..ad8b4a1dce9 --- /dev/null +++ b/Tests/LibWeb/Layout/expected/svg/mask-element-should-not-participate-in-layout.txt @@ -0,0 +1,17 @@ +Viewport <#document> at (0,0) content-size 800x600 children: not-inline + BlockContainer at (0,0) content-size 800x116 [BFC] children: not-inline + BlockContainer at (8,8) content-size 784x100 children: inline + line 0 width: 100, height: 100, bottom: 100, baseline: 100 + frag 0 from SVGSVGBox start: 0, length: 0, rect: [8,8 100x100] + SVGSVGBox at (8,8) content-size 100x100 [SVG] children: inline + TextNode <#text> + SVGGeometryBox at (8,8) content-size 100x100 children: not-inline + TextNode <#text> + TextNode <#text> + TextNode <#text> + +PaintableWithLines (Viewport<#document>) [0,0 800x600] + PaintableWithLines (BlockContainer) [0,0 800x116] + PaintableWithLines (BlockContainer) [8,8 784x100] + SVGSVGPaintable (SVGSVGBox) [8,8 100x100] + SVGGeometryPaintable (SVGGeometryBox) [8,8 100x100] diff --git a/Tests/LibWeb/Layout/input/svg/mask-element-should-not-participate-in-layout.html b/Tests/LibWeb/Layout/input/svg/mask-element-should-not-participate-in-layout.html new file mode 100644 index 00000000000..e9096ac122f --- /dev/null +++ b/Tests/LibWeb/Layout/input/svg/mask-element-should-not-participate-in-layout.html @@ -0,0 +1,7 @@ + + + + + + + diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt index 61b47b3e4d8..d9f62a2000e 100644 --- a/Userland/Libraries/LibWeb/CMakeLists.txt +++ b/Userland/Libraries/LibWeb/CMakeLists.txt @@ -543,6 +543,7 @@ set(SOURCES SVG/SVGLength.cpp SVG/SVGLineElement.cpp SVG/SVGLinearGradientElement.cpp + SVG/SVGMaskElement.cpp SVG/SVGPolygonElement.cpp SVG/SVGPolylineElement.cpp SVG/SVGRectElement.cpp diff --git a/Userland/Libraries/LibWeb/DOM/ElementFactory.cpp b/Userland/Libraries/LibWeb/DOM/ElementFactory.cpp index e606e158800..9f522e95d1d 100644 --- a/Userland/Libraries/LibWeb/DOM/ElementFactory.cpp +++ b/Userland/Libraries/LibWeb/DOM/ElementFactory.cpp @@ -90,6 +90,7 @@ #include #include #include +#include #include #include #include @@ -444,6 +445,8 @@ static WebIDL::ExceptionOr> create_svg_element(JS::Re return MUST_OR_THROW_OOM(realm.heap().allocate(realm, document, move(qualified_name))); if (local_name == SVG::TagNames::linearGradient) return MUST_OR_THROW_OOM(realm.heap().allocate(realm, document, move(qualified_name))); + if (local_name == SVG::TagNames::mask) + return MUST_OR_THROW_OOM(realm.heap().allocate(realm, document, move(qualified_name))); if (local_name == SVG::TagNames::path) return MUST_OR_THROW_OOM(realm.heap().allocate(realm, document, move(qualified_name))); if (local_name == SVG::TagNames::polygon) diff --git a/Userland/Libraries/LibWeb/Forward.h b/Userland/Libraries/LibWeb/Forward.h index 6d6ea84061d..6237a38cd9f 100644 --- a/Userland/Libraries/LibWeb/Forward.h +++ b/Userland/Libraries/LibWeb/Forward.h @@ -592,6 +592,7 @@ class SVGGeometryElement; class SVGGraphicsElement; class SVGLength; class SVGLineElement; +class SVGMaskElement; class SVGPathElement; class SVGPolygonElement; class SVGPolylineElement; diff --git a/Userland/Libraries/LibWeb/SVG/SVGMaskElement.cpp b/Userland/Libraries/LibWeb/SVG/SVGMaskElement.cpp new file mode 100644 index 00000000000..d7fcab4e1f5 --- /dev/null +++ b/Userland/Libraries/LibWeb/SVG/SVGMaskElement.cpp @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2023, Andreas Kling + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include +#include + +namespace Web::SVG { + +SVGMaskElement::SVGMaskElement(DOM::Document& document, DOM::QualifiedName tag_name) + : SVGGraphicsElement(document, move(tag_name)) +{ +} + +SVGMaskElement::~SVGMaskElement() = default; + +void SVGMaskElement::initialize(JS::Realm& realm) +{ + Base::initialize(realm); + set_prototype(&Bindings::ensure_web_prototype(realm, "SVGMaskElement")); +} + +JS::GCPtr SVGMaskElement::create_layout_node(NonnullRefPtr) +{ + return nullptr; +} + +} diff --git a/Userland/Libraries/LibWeb/SVG/SVGMaskElement.h b/Userland/Libraries/LibWeb/SVG/SVGMaskElement.h new file mode 100644 index 00000000000..b957890716e --- /dev/null +++ b/Userland/Libraries/LibWeb/SVG/SVGMaskElement.h @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2023, Andreas Kling + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include + +namespace Web::SVG { + +class SVGMaskElement final : public SVGGraphicsElement { + WEB_PLATFORM_OBJECT(SVGMaskElement, SVGGraphicsElement); + +public: + virtual ~SVGMaskElement() override; + + virtual JS::GCPtr create_layout_node(NonnullRefPtr) override; + +private: + SVGMaskElement(DOM::Document&, DOM::QualifiedName); + virtual void initialize(JS::Realm&) override; +}; + +} diff --git a/Userland/Libraries/LibWeb/SVG/SVGMaskElement.idl b/Userland/Libraries/LibWeb/SVG/SVGMaskElement.idl new file mode 100644 index 00000000000..cadc415f23d --- /dev/null +++ b/Userland/Libraries/LibWeb/SVG/SVGMaskElement.idl @@ -0,0 +1,11 @@ +[Exposed=Window] +interface SVGMaskElement : SVGElement { + + // FIXME: readonly attribute SVGAnimatedEnumeration maskUnits; + // FIXME: readonly attribute SVGAnimatedEnumeration maskContentUnits; + // FIXME: readonly attribute SVGAnimatedLength x; + // FIXME: readonly attribute SVGAnimatedLength y; + // FIXME: readonly attribute SVGAnimatedLength width; + // FIXME: readonly attribute SVGAnimatedLength height; + +}; diff --git a/Userland/Libraries/LibWeb/SVG/TagNames.h b/Userland/Libraries/LibWeb/SVG/TagNames.h index fdef9b58d74..ae402846356 100644 --- a/Userland/Libraries/LibWeb/SVG/TagNames.h +++ b/Userland/Libraries/LibWeb/SVG/TagNames.h @@ -31,6 +31,7 @@ namespace Web::SVG::TagNames { __ENUMERATE_SVG_TAG(desc) \ __ENUMERATE_SVG_TAG(foreignObject) \ __ENUMERATE_SVG_TAG(linearGradient) \ + __ENUMERATE_SVG_TAG(mask) \ __ENUMERATE_SVG_TAG(radialGradient) \ __ENUMERATE_SVG_TAG(script) \ __ENUMERATE_SVG_TAG(stop) \ diff --git a/Userland/Libraries/LibWeb/idl_files.cmake b/Userland/Libraries/LibWeb/idl_files.cmake index 8578a2dd8cc..53295dbe21c 100644 --- a/Userland/Libraries/LibWeb/idl_files.cmake +++ b/Userland/Libraries/LibWeb/idl_files.cmake @@ -218,6 +218,7 @@ libweb_js_bindings(SVG/SVGForeignObjectElement) libweb_js_bindings(SVG/SVGLength) libweb_js_bindings(SVG/SVGLineElement) libweb_js_bindings(SVG/SVGLinearGradientElement) +libweb_js_bindings(SVG/SVGMaskElement) libweb_js_bindings(SVG/SVGPathElement) libweb_js_bindings(SVG/SVGPolygonElement) libweb_js_bindings(SVG/SVGPolylineElement)