diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt index 249aeebcd3..efeda19328 100644 --- a/Userland/Libraries/LibWeb/CMakeLists.txt +++ b/Userland/Libraries/LibWeb/CMakeLists.txt @@ -505,6 +505,7 @@ set(SOURCES SVG/SVGPolylineElement.cpp SVG/SVGRectElement.cpp SVG/SVGSVGElement.cpp + SVG/SVGStopElement.cpp SVG/SVGTextContentElement.cpp SVG/TagNames.cpp SVG/ViewBox.cpp diff --git a/Userland/Libraries/LibWeb/DOM/ElementFactory.cpp b/Userland/Libraries/LibWeb/DOM/ElementFactory.cpp index 757d0c9067..0153fc633d 100644 --- a/Userland/Libraries/LibWeb/DOM/ElementFactory.cpp +++ b/Userland/Libraries/LibWeb/DOM/ElementFactory.cpp @@ -93,6 +93,7 @@ #include #include #include +#include #include #include #include @@ -441,6 +442,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::g) return MUST_OR_THROW_OOM(realm.heap().allocate(realm, document, move(qualified_name))); + if (local_name == SVG::TagNames::stop) + return MUST_OR_THROW_OOM(realm.heap().allocate(realm, document, move(qualified_name))); if (local_name == SVG::TagNames::text) return MUST_OR_THROW_OOM(realm.heap().allocate(realm, document, move(qualified_name))); diff --git a/Userland/Libraries/LibWeb/SVG/AttributeNames.h b/Userland/Libraries/LibWeb/SVG/AttributeNames.h index 786de7c486..848d318c89 100644 --- a/Userland/Libraries/LibWeb/SVG/AttributeNames.h +++ b/Userland/Libraries/LibWeb/SVG/AttributeNames.h @@ -42,6 +42,7 @@ namespace Web::SVG::AttributeNames { E(maskContentUnits) \ E(maskUnits) \ E(numOctaves) \ + E(offset) \ E(pathLength) \ E(patternContentUnits) \ E(patternTransform) \ @@ -59,9 +60,9 @@ namespace Web::SVG::AttributeNames { E(repeatCount) \ E(repeatDur) \ E(requiredExtensions) \ + E(requiredFeatures) \ E(rx) \ E(ry) \ - E(requiredFeatures) \ E(specularConstant) \ E(specularExponent) \ E(spreadMethod) \ diff --git a/Userland/Libraries/LibWeb/SVG/SVGStopElement.cpp b/Userland/Libraries/LibWeb/SVG/SVGStopElement.cpp new file mode 100644 index 0000000000..235e82f707 --- /dev/null +++ b/Userland/Libraries/LibWeb/SVG/SVGStopElement.cpp @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2023, MacDue + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include +#include +#include +#include +#include +#include + +namespace Web::SVG { + +SVGStopElement::SVGStopElement(DOM::Document& document, DOM::QualifiedName qualified_name) + : SVGElement(document, qualified_name) +{ +} + +void SVGStopElement::parse_attribute(DeprecatedFlyString const& name, DeprecatedString const& value) +{ + SVGElement::parse_attribute(name, value); + if (name == SVG::AttributeNames::offset) { + m_offset = AttributeParser::parse_number_percentage(value); + } +} + +void SVGStopElement::apply_presentational_hints(CSS::StyleProperties& style) const +{ + CSS::Parser::ParsingContext parsing_context { document() }; + for_each_attribute([&](auto& name, auto& value) { + if (name.equals_ignoring_ascii_case("stop-color"sv)) { + CSS::Parser::ParsingContext parsing_context { document() }; + if (auto stop_color = parse_css_value(parsing_context, value, CSS::PropertyID::StopColor)) { + style.set_property(CSS::PropertyID::StopColor, stop_color.release_nonnull()); + } + } + }); +} + +Gfx::Color SVGStopElement::stop_color() const +{ + if (auto css_values = computed_css_values()) + return css_values->stop_color(); + return Color::Black; +} + +JS::NonnullGCPtr SVGStopElement::offset() const +{ + TODO(); +} + +JS::ThrowCompletionOr SVGStopElement::initialize(JS::Realm& realm) +{ + MUST_OR_THROW_OOM(Base::initialize(realm)); + set_prototype(&Bindings::ensure_web_prototype(realm, "SVGStopElement")); + + return {}; +} + +} diff --git a/Userland/Libraries/LibWeb/SVG/SVGStopElement.h b/Userland/Libraries/LibWeb/SVG/SVGStopElement.h new file mode 100644 index 0000000000..a1167397b5 --- /dev/null +++ b/Userland/Libraries/LibWeb/SVG/SVGStopElement.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2023, MacDue + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include +#include +#include + +namespace Web::SVG { + +class SVGStopElement final : public SVGElement { + WEB_PLATFORM_OBJECT(SVGStopElement, SVGElement); + +public: + virtual ~SVGStopElement() override = default; + + virtual void parse_attribute(DeprecatedFlyString const& name, DeprecatedString const& value) override; + + JS::NonnullGCPtr offset() const; + + virtual void apply_presentational_hints(CSS::StyleProperties&) const override; + + NumberPercentage stop_offset() const { return m_offset.value_or(NumberPercentage::create_number(0)); } + Gfx::Color stop_color() const; + +private: + SVGStopElement(DOM::Document&, DOM::QualifiedName); + + virtual JS::ThrowCompletionOr initialize(JS::Realm&) override; + + Optional m_offset; + Optional m_color; +}; + +} diff --git a/Userland/Libraries/LibWeb/SVG/SVGStopElement.idl b/Userland/Libraries/LibWeb/SVG/SVGStopElement.idl new file mode 100644 index 0000000000..05126e9025 --- /dev/null +++ b/Userland/Libraries/LibWeb/SVG/SVGStopElement.idl @@ -0,0 +1,7 @@ +#import +#import + +[Exposed=Window] +interface SVGStopElement : SVGElement { + [SameObject] readonly attribute SVGAnimatedNumber offset; +}; diff --git a/Userland/Libraries/LibWeb/idl_files.cmake b/Userland/Libraries/LibWeb/idl_files.cmake index 8427632f08..cb73115393 100644 --- a/Userland/Libraries/LibWeb/idl_files.cmake +++ b/Userland/Libraries/LibWeb/idl_files.cmake @@ -207,6 +207,7 @@ libweb_js_bindings(SVG/SVGPolygonElement) libweb_js_bindings(SVG/SVGPolylineElement) libweb_js_bindings(SVG/SVGRectElement) libweb_js_bindings(SVG/SVGSVGElement) +libweb_js_bindings(SVG/SVGStopElement) libweb_js_bindings(SVG/SVGTextContentElement) libweb_js_bindings(Selection/Selection) libweb_js_bindings(UIEvents/FocusEvent)