2020-07-19 23:01:53 -07:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2020, Matthew Olsson <matthewcolsson@gmail.com>
|
2022-07-11 12:26:53 +02:00
|
|
|
* Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
|
2020-07-19 23:01:53 -07:00
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-07-19 23:01:53 -07:00
|
|
|
*/
|
|
|
|
|
|
2020-07-23 09:44:42 -07:00
|
|
|
#include <LibGfx/Painter.h>
|
2022-02-15 16:42:00 +00:00
|
|
|
#include <LibWeb/CSS/Parser/Parser.h>
|
2021-09-24 13:49:57 +02:00
|
|
|
#include <LibWeb/CSS/StyleComputer.h>
|
2020-07-19 23:01:53 -07:00
|
|
|
#include <LibWeb/DOM/Document.h>
|
|
|
|
|
#include <LibWeb/DOM/Event.h>
|
2022-03-26 14:29:52 +01:00
|
|
|
#include <LibWeb/HTML/Parser/HTMLParser.h>
|
2020-11-22 15:53:01 +01:00
|
|
|
#include <LibWeb/Layout/SVGSVGBox.h>
|
2021-09-15 01:12:41 +02:00
|
|
|
#include <LibWeb/SVG/AttributeNames.h>
|
2020-07-23 09:44:42 -07:00
|
|
|
#include <LibWeb/SVG/SVGSVGElement.h>
|
2020-07-19 23:01:53 -07:00
|
|
|
|
2020-07-23 09:44:42 -07:00
|
|
|
namespace Web::SVG {
|
2020-07-19 23:01:53 -07:00
|
|
|
|
2022-02-18 21:00:52 +01:00
|
|
|
SVGSVGElement::SVGSVGElement(DOM::Document& document, DOM::QualifiedName qualified_name)
|
2020-10-10 02:48:05 +01:00
|
|
|
: SVGGraphicsElement(document, qualified_name)
|
2020-07-19 23:01:53 -07:00
|
|
|
{
|
2023-01-10 06:28:20 -05:00
|
|
|
}
|
|
|
|
|
|
2023-01-28 12:33:35 -05:00
|
|
|
JS::ThrowCompletionOr<void> SVGSVGElement::initialize(JS::Realm& realm)
|
2023-01-10 06:28:20 -05:00
|
|
|
{
|
2023-01-28 12:33:35 -05:00
|
|
|
MUST_OR_THROW_OOM(Base::initialize(realm));
|
2023-01-10 06:28:20 -05:00
|
|
|
set_prototype(&Bindings::ensure_web_prototype<Bindings::SVGSVGElementPrototype>(realm, "SVGSVGElement"));
|
2023-01-28 12:33:35 -05:00
|
|
|
|
|
|
|
|
return {};
|
2020-07-19 23:01:53 -07:00
|
|
|
}
|
|
|
|
|
|
2022-10-17 14:41:50 +02:00
|
|
|
JS::GCPtr<Layout::Node> SVGSVGElement::create_layout_node(NonnullRefPtr<CSS::StyleProperties> style)
|
2020-07-19 23:01:53 -07:00
|
|
|
{
|
2022-10-17 14:41:50 +02:00
|
|
|
return heap().allocate_without_realm<Layout::SVGSVGBox>(document(), *this, move(style));
|
2020-07-19 23:01:53 -07:00
|
|
|
}
|
|
|
|
|
|
2022-02-15 16:42:00 +00:00
|
|
|
void SVGSVGElement::apply_presentational_hints(CSS::StyleProperties& style) const
|
2020-07-19 23:01:53 -07:00
|
|
|
{
|
2022-07-11 12:26:53 +02:00
|
|
|
auto width_attribute = attribute(SVG::AttributeNames::width);
|
|
|
|
|
if (auto width_value = HTML::parse_dimension_value(width_attribute)) {
|
2022-02-15 16:42:00 +00:00
|
|
|
style.set_property(CSS::PropertyID::Width, width_value.release_nonnull());
|
2022-07-11 12:26:53 +02:00
|
|
|
} else if (width_attribute == "") {
|
|
|
|
|
// If the `width` attribute is an empty string, it defaults to 100%.
|
|
|
|
|
// This matches WebKit and Blink, but not Firefox. The spec is unclear.
|
|
|
|
|
// FIXME: Figure out what to do here.
|
2022-02-15 16:42:00 +00:00
|
|
|
style.set_property(CSS::PropertyID::Width, CSS::PercentageStyleValue::create(CSS::Percentage { 100 }));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Height defaults to 100%
|
2022-07-11 12:26:53 +02:00
|
|
|
auto height_attribute = attribute(SVG::AttributeNames::height);
|
|
|
|
|
if (auto height_value = HTML::parse_dimension_value(height_attribute)) {
|
2022-02-15 16:42:00 +00:00
|
|
|
style.set_property(CSS::PropertyID::Height, height_value.release_nonnull());
|
2022-07-11 12:26:53 +02:00
|
|
|
} else if (height_attribute == "") {
|
|
|
|
|
// If the `height` attribute is an empty string, it defaults to 100%.
|
|
|
|
|
// This matches WebKit and Blink, but not Firefox. The spec is unclear.
|
|
|
|
|
// FIXME: Figure out what to do here.
|
2022-02-15 16:42:00 +00:00
|
|
|
style.set_property(CSS::PropertyID::Height, CSS::PercentageStyleValue::create(CSS::Percentage { 100 }));
|
|
|
|
|
}
|
2020-07-19 23:01:53 -07:00
|
|
|
}
|
|
|
|
|
|
2023-01-08 19:23:00 -05:00
|
|
|
void SVGSVGElement::parse_attribute(DeprecatedFlyString const& name, DeprecatedString const& value)
|
2021-09-15 01:12:41 +02:00
|
|
|
{
|
|
|
|
|
SVGGraphicsElement::parse_attribute(name, value);
|
|
|
|
|
|
2023-03-10 08:48:54 +01:00
|
|
|
if (name.equals_ignoring_ascii_case(SVG::AttributeNames::viewBox))
|
2021-09-15 01:12:41 +02:00
|
|
|
m_view_box = try_parse_view_box(value);
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-19 23:01:53 -07:00
|
|
|
}
|