From 7ac889e53372786d10421dbe940dcd8395cf39b1 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 18 Sep 2021 00:04:19 +0200 Subject: [PATCH] LibWeb: Add a bare-bones SVG element --- Userland/Libraries/LibWeb/CMakeLists.txt | 1 + .../Libraries/LibWeb/DOM/ElementFactory.cpp | 3 +++ Userland/Libraries/LibWeb/SVG/SVGGElement.cpp | 27 +++++++++++++++++++ Userland/Libraries/LibWeb/SVG/SVGGElement.h | 23 ++++++++++++++++ Userland/Libraries/LibWeb/SVG/TagNames.h | 1 + 5 files changed, 55 insertions(+) create mode 100644 Userland/Libraries/LibWeb/SVG/SVGGElement.cpp create mode 100644 Userland/Libraries/LibWeb/SVG/SVGGElement.h diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt index faadd9ac60..8eb80979b4 100644 --- a/Userland/Libraries/LibWeb/CMakeLists.txt +++ b/Userland/Libraries/LibWeb/CMakeLists.txt @@ -225,6 +225,7 @@ set(SOURCES RequestIdleCallback/IdleDeadline.cpp SVG/AttributeNames.cpp SVG/SVGElement.cpp + SVG/SVGGElement.cpp SVG/SVGGeometryElement.cpp SVG/SVGGraphicsElement.cpp SVG/SVGPathElement.cpp diff --git a/Userland/Libraries/LibWeb/DOM/ElementFactory.cpp b/Userland/Libraries/LibWeb/DOM/ElementFactory.cpp index db06933113..50a3522266 100644 --- a/Userland/Libraries/LibWeb/DOM/ElementFactory.cpp +++ b/Userland/Libraries/LibWeb/DOM/ElementFactory.cpp @@ -76,6 +76,7 @@ #include #include #include +#include #include #include #include @@ -235,6 +236,8 @@ NonnullRefPtr create_element(Document& document, const FlyString& tag_n return adopt_ref(*new SVG::SVGSVGElement(document, move(qualified_name))); if (lowercase_tag_name == SVG::TagNames::path) return adopt_ref(*new SVG::SVGPathElement(document, move(qualified_name))); + if (lowercase_tag_name == SVG::TagNames::g) + return adopt_ref(*new SVG::SVGGElement(document, move(qualified_name))); // FIXME: If name is a valid custom element name, then return HTMLElement. diff --git a/Userland/Libraries/LibWeb/SVG/SVGGElement.cpp b/Userland/Libraries/LibWeb/SVG/SVGGElement.cpp new file mode 100644 index 0000000000..9b6da36fbc --- /dev/null +++ b/Userland/Libraries/LibWeb/SVG/SVGGElement.cpp @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2021, Andreas Kling + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include +#include +#include + +namespace Web::SVG { + +SVGGElement::SVGGElement(DOM::Document& document, QualifiedName qualified_name) + : SVGGraphicsElement(document, move(qualified_name)) +{ +} + +RefPtr SVGGElement::create_layout_node() +{ + auto style = document().style_resolver().resolve_style(*this); + if (style->display() == CSS::Display::None) + return nullptr; + return adopt_ref(*new Layout::SVGGraphicsBox(document(), *this, move(style))); +} + +} diff --git a/Userland/Libraries/LibWeb/SVG/SVGGElement.h b/Userland/Libraries/LibWeb/SVG/SVGGElement.h new file mode 100644 index 0000000000..a05a12fc5f --- /dev/null +++ b/Userland/Libraries/LibWeb/SVG/SVGGElement.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2021, Andreas Kling + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include + +namespace Web::SVG { + +class SVGGElement final : public SVGGraphicsElement { +public: + using WrapperType = Bindings::SVGPathElementWrapper; + + SVGGElement(DOM::Document&, QualifiedName); + virtual ~SVGGElement() override = default; + + virtual RefPtr create_layout_node() override; +}; + +} diff --git a/Userland/Libraries/LibWeb/SVG/TagNames.h b/Userland/Libraries/LibWeb/SVG/TagNames.h index 142963c7a2..072a404bae 100644 --- a/Userland/Libraries/LibWeb/SVG/TagNames.h +++ b/Userland/Libraries/LibWeb/SVG/TagNames.h @@ -11,6 +11,7 @@ namespace Web::SVG::TagNames { #define ENUMERATE_SVG_GRAPHICS_TAGS \ + __ENUMERATE_SVG_TAG(g) \ __ENUMERATE_SVG_TAG(path) \ __ENUMERATE_SVG_TAG(svg)