1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 02:27:43 +00:00

LibWeb: Implement the <style> SVG element

The `<style>` element is allowed to be in the SVG namespace, so we now
support this element.

It has the same behaviour as the HTML namespace `<style>` element as
described in the spec.

"The semantics and processing of a ‘style’ and its attributes must be
the same as is defined for the HTML ‘style’ element."
This commit is contained in:
PrestonLTaylor 2023-06-08 17:48:33 +01:00 committed by Andreas Kling
parent 7f7ebc4b8b
commit e2a935b1dc
7 changed files with 118 additions and 0 deletions

View file

@ -0,0 +1,64 @@
/*
* Copyright (c) 2023, Preston Taylor <PrestonLeeTaylor@proton.me>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/SVG/SVGStyleElement.h>
namespace Web::SVG {
SVGStyleElement::SVGStyleElement(DOM::Document& document, DOM::QualifiedName qualified_name)
: SVGElement(document, move(qualified_name))
{
}
SVGStyleElement::~SVGStyleElement() = default;
JS::ThrowCompletionOr<void> SVGStyleElement::initialize(JS::Realm& realm)
{
MUST_OR_THROW_OOM(Base::initialize(realm));
set_prototype(&Bindings::ensure_web_prototype<Bindings::SVGStyleElementPrototype>(realm, "SVGStyleElement"));
return {};
}
void SVGStyleElement::visit_edges(Cell::Visitor& visitor)
{
Base::visit_edges(visitor);
visitor.visit(m_style_element_utils.sheet());
}
void SVGStyleElement::children_changed()
{
m_style_element_utils.update_a_style_block(*this);
Base::children_changed();
}
void SVGStyleElement::inserted()
{
m_style_element_utils.update_a_style_block(*this);
Base::inserted();
}
void SVGStyleElement::removed_from(Node* old_parent)
{
m_style_element_utils.update_a_style_block(*this);
Base::removed_from(old_parent);
}
// https://www.w3.org/TR/cssom/#dom-linkstyle-sheet
CSS::CSSStyleSheet* SVGStyleElement::sheet()
{
// The sheet attribute must return the associated CSS style sheet for the node or null if there is no associated CSS style sheet.
return m_style_element_utils.sheet();
}
// https://www.w3.org/TR/cssom/#dom-linkstyle-sheet
CSS::CSSStyleSheet const* SVGStyleElement::sheet() const
{
// The sheet attribute must return the associated CSS style sheet for the node or null if there is no associated CSS style sheet.
return m_style_element_utils.sheet();
}
}

View file

@ -0,0 +1,37 @@
/*
* Copyright (c) 2023, Preston Taylor <PrestonLeeTaylor@proton.me>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibWeb/DOM/StyleElementUtils.h>
#include <LibWeb/SVG/SVGElement.h>
namespace Web::SVG {
class SVGStyleElement final : public SVGElement {
WEB_PLATFORM_OBJECT(HTMLStyleElement, SVGElement);
public:
virtual ~SVGStyleElement() override;
virtual void children_changed() override;
virtual void inserted() override;
virtual void removed_from(Node*) override;
CSS::CSSStyleSheet* sheet();
CSS::CSSStyleSheet const* sheet() const;
private:
SVGStyleElement(DOM::Document&, DOM::QualifiedName);
virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
virtual void visit_edges(Cell::Visitor&) override;
// The semantics and processing of a style and its attributes must be the same as is defined for the HTML style element.
DOM::StyleElementUtils m_style_element_utils;
};
}

View file

@ -0,0 +1,11 @@
#import <CSS/LinkStyle.idl>
#import <SVG/SVGElement.idl>
[Exposed=Window]
interface SVGStyleElement : SVGElement {
[Reflect] attribute DOMString type;
[Reflect] attribute DOMString media;
[Reflect] attribute DOMString title;
};
SVGStyleElement includes LinkStyle;

View file

@ -33,6 +33,7 @@ namespace Web::SVG::TagNames {
__ENUMERATE_SVG_TAG(radialGradient) \
__ENUMERATE_SVG_TAG(script) \
__ENUMERATE_SVG_TAG(stop) \
__ENUMERATE_SVG_TAG(style) \
__ENUMERATE_SVG_TAG(symbol) \
__ENUMERATE_SVG_TAG(title) \
__ENUMERATE_SVG_TAG(use)