2023-04-20 20:51:00 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2023, MacDue <macdue@dueutil.tech>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <LibWeb/Bindings/Intrinsics.h>
|
2024-04-27 03:09:58 +03:00
|
|
|
#include <LibWeb/Bindings/SVGStopElementPrototype.h>
|
2023-04-20 20:51:00 +03:00
|
|
|
#include <LibWeb/CSS/Parser/Parser.h>
|
2024-03-11 21:26:58 +03:00
|
|
|
#include <LibWeb/CSS/StyleProperties.h>
|
2023-04-20 20:51:00 +03:00
|
|
|
#include <LibWeb/SVG/AttributeNames.h>
|
|
|
|
#include <LibWeb/SVG/AttributeParser.h>
|
|
|
|
#include <LibWeb/SVG/SVGStopElement.h>
|
|
|
|
|
|
|
|
namespace Web::SVG {
|
|
|
|
|
2023-11-19 21:47:52 +03:00
|
|
|
JS_DEFINE_ALLOCATOR(SVGStopElement);
|
|
|
|
|
2023-04-20 20:51:00 +03:00
|
|
|
SVGStopElement::SVGStopElement(DOM::Document& document, DOM::QualifiedName qualified_name)
|
|
|
|
: SVGElement(document, qualified_name)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-11-19 08:10:36 +03:00
|
|
|
void SVGStopElement::attribute_changed(FlyString const& name, Optional<String> const& value)
|
2023-04-20 20:51:00 +03:00
|
|
|
{
|
2023-07-03 18:08:37 +03:00
|
|
|
SVGElement::attribute_changed(name, value);
|
2023-04-20 20:51:00 +03:00
|
|
|
if (name == SVG::AttributeNames::offset) {
|
2023-11-19 08:10:36 +03:00
|
|
|
m_offset = AttributeParser::parse_number_percentage(value.value_or(String {}));
|
2023-04-20 20:51:00 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SVGStopElement::apply_presentational_hints(CSS::StyleProperties& style) const
|
|
|
|
{
|
|
|
|
CSS::Parser::ParsingContext parsing_context { document() };
|
|
|
|
for_each_attribute([&](auto& name, auto& value) {
|
2023-05-19 22:35:39 +03:00
|
|
|
CSS::Parser::ParsingContext parsing_context { document() };
|
2023-04-20 20:51:00 +03:00
|
|
|
if (name.equals_ignoring_ascii_case("stop-color"sv)) {
|
2023-08-19 17:01:21 +03:00
|
|
|
if (auto stop_color = parse_css_value(parsing_context, value, CSS::PropertyID::StopColor)) {
|
2023-04-20 20:51:00 +03:00
|
|
|
style.set_property(CSS::PropertyID::StopColor, stop_color.release_nonnull());
|
|
|
|
}
|
2023-05-19 22:35:39 +03:00
|
|
|
} else if (name.equals_ignoring_ascii_case("stop-opacity"sv)) {
|
2023-08-19 17:01:21 +03:00
|
|
|
if (auto stop_opacity = parse_css_value(parsing_context, value, CSS::PropertyID::StopOpacity)) {
|
2023-05-19 22:35:39 +03:00
|
|
|
style.set_property(CSS::PropertyID::StopOpacity, stop_opacity.release_nonnull());
|
|
|
|
}
|
2023-04-20 20:51:00 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
Gfx::Color SVGStopElement::stop_color() const
|
|
|
|
{
|
|
|
|
if (auto css_values = computed_css_values())
|
|
|
|
return css_values->stop_color();
|
|
|
|
return Color::Black;
|
|
|
|
}
|
|
|
|
|
2023-05-19 22:35:39 +03:00
|
|
|
float SVGStopElement::stop_opacity() const
|
|
|
|
{
|
|
|
|
if (auto css_values = computed_css_values())
|
|
|
|
return css_values->stop_opacity();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2023-04-20 20:51:00 +03:00
|
|
|
JS::NonnullGCPtr<SVGAnimatedNumber> SVGStopElement::offset() const
|
|
|
|
{
|
2024-03-11 17:34:24 +03:00
|
|
|
// FIXME: Implement this properly.
|
|
|
|
return SVGAnimatedNumber::create(realm(), 0, 0);
|
2023-04-20 20:51:00 +03:00
|
|
|
}
|
|
|
|
|
2023-08-07 09:41:28 +03:00
|
|
|
void SVGStopElement::initialize(JS::Realm& realm)
|
2023-04-20 20:51:00 +03:00
|
|
|
{
|
2023-08-07 09:41:28 +03:00
|
|
|
Base::initialize(realm);
|
2024-03-16 15:13:08 +03:00
|
|
|
WEB_SET_PROTOTYPE_FOR_INTERFACE(SVGStopElement);
|
2023-04-20 20:51:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|