2020-07-19 23:01:53 -07:00
|
|
|
/*
|
2021-04-22 16:53:07 -07:00
|
|
|
* Copyright (c) 2020, Matthew Olsson <mattco@serenityos.org>
|
2022-01-24 15:43:44 +00:00
|
|
|
* Copyright (c) 2021-2022, Sam Atkins <atkinssj@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
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2024-08-08 10:22:03 +02:00
|
|
|
#include <LibGfx/DeprecatedPath.h>
|
2023-04-23 01:31:17 +01:00
|
|
|
#include <LibGfx/PaintStyle.h>
|
2020-07-23 09:44:42 -07:00
|
|
|
#include <LibWeb/DOM/Node.h>
|
2023-04-10 12:25:40 +01:00
|
|
|
#include <LibWeb/SVG/AttributeParser.h>
|
2024-04-01 00:49:02 +01:00
|
|
|
#include <LibWeb/SVG/SVGAnimatedTransformList.h>
|
2020-07-23 09:44:42 -07:00
|
|
|
#include <LibWeb/SVG/SVGElement.h>
|
2023-04-23 01:31:17 +01:00
|
|
|
#include <LibWeb/SVG/SVGGradientElement.h>
|
2020-07-23 09:44:42 -07:00
|
|
|
#include <LibWeb/SVG/TagNames.h>
|
2023-07-31 18:37:44 +02:00
|
|
|
#include <LibWeb/SVG/ViewBox.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
|
|
|
|
2024-04-01 00:49:02 +01:00
|
|
|
struct SVGBoundingBoxOptions {
|
|
|
|
|
bool fill { true };
|
|
|
|
|
bool stroke { false };
|
|
|
|
|
bool markers { false };
|
|
|
|
|
bool clipped { false };
|
|
|
|
|
};
|
|
|
|
|
|
2020-07-23 09:44:42 -07:00
|
|
|
class SVGGraphicsElement : public SVGElement {
|
2022-08-28 13:42:07 +02:00
|
|
|
WEB_PLATFORM_OBJECT(SVGGraphicsElement, SVGElement);
|
2020-07-19 23:01:53 -07:00
|
|
|
|
2022-08-28 13:42:07 +02:00
|
|
|
public:
|
2022-01-24 15:43:44 +00:00
|
|
|
virtual void apply_presentational_hints(CSS::StyleProperties&) const override;
|
2020-07-19 23:01:53 -07:00
|
|
|
|
2024-07-09 20:18:41 +01:00
|
|
|
virtual void attribute_changed(FlyString const& name, Optional<String> const& old_value, Optional<String> const& value) override;
|
2023-04-10 12:25:00 +01:00
|
|
|
|
2021-09-16 12:28:14 +01:00
|
|
|
Optional<Gfx::Color> fill_color() const;
|
|
|
|
|
Optional<Gfx::Color> stroke_color() const;
|
|
|
|
|
Optional<float> stroke_width() const;
|
2023-05-19 20:35:39 +01:00
|
|
|
Optional<float> fill_opacity() const;
|
2024-10-10 10:15:49 -04:00
|
|
|
Optional<CSS::StrokeLinecap> stroke_linecap() const;
|
2024-10-28 20:51:16 -04:00
|
|
|
Optional<CSS::StrokeLinejoin> stroke_linejoin() const;
|
|
|
|
|
Optional<CSS::NumberOrCalculated> stroke_miterlimit() const;
|
2023-05-19 20:35:39 +01:00
|
|
|
Optional<float> stroke_opacity() const;
|
2024-05-12 20:19:43 +01:00
|
|
|
Optional<FillRule> fill_rule() const;
|
|
|
|
|
Optional<ClipRule> clip_rule() const;
|
2022-08-28 13:42:07 +02:00
|
|
|
|
2023-04-15 15:32:17 +01:00
|
|
|
float visible_stroke_width() const
|
|
|
|
|
{
|
|
|
|
|
if (auto color = stroke_color(); color.has_value() && color->alpha() > 0)
|
|
|
|
|
return stroke_width().value_or(0);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-10 12:25:40 +01:00
|
|
|
Gfx::AffineTransform get_transform() const;
|
|
|
|
|
|
2024-06-13 15:22:46 +03:00
|
|
|
Optional<Painting::PaintStyle> fill_paint_style(SVGPaintContext const&) const;
|
|
|
|
|
Optional<Painting::PaintStyle> stroke_paint_style(SVGPaintContext const&) const;
|
2023-04-23 01:31:17 +01:00
|
|
|
|
2023-09-10 14:10:55 +01:00
|
|
|
JS::GCPtr<SVG::SVGMaskElement const> mask() const;
|
2024-03-27 00:06:35 +00:00
|
|
|
JS::GCPtr<SVG::SVGClipPathElement const> clip_path() const;
|
|
|
|
|
|
2024-04-01 00:49:02 +01:00
|
|
|
JS::NonnullGCPtr<Geometry::DOMRect> get_b_box(Optional<SVGBoundingBoxOptions>);
|
|
|
|
|
JS::NonnullGCPtr<SVGAnimatedTransformList> transform() const;
|
|
|
|
|
|
2024-11-09 18:30:38 +01:00
|
|
|
JS::GCPtr<Geometry::DOMMatrix> get_screen_ctm();
|
|
|
|
|
|
2022-08-28 13:42:07 +02:00
|
|
|
protected:
|
|
|
|
|
SVGGraphicsElement(DOM::Document&, DOM::QualifiedName);
|
2023-01-10 06:28:20 -05:00
|
|
|
|
2023-08-07 08:41:28 +02:00
|
|
|
virtual void initialize(JS::Realm&) override;
|
2023-04-10 12:25:00 +01:00
|
|
|
|
2023-08-31 08:58:41 +01:00
|
|
|
virtual Gfx::AffineTransform element_transform() const
|
|
|
|
|
{
|
|
|
|
|
return m_transform;
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-13 15:22:46 +03:00
|
|
|
Optional<Painting::PaintStyle> svg_paint_computed_value_to_gfx_paint_style(SVGPaintContext const& paint_context, Optional<CSS::SVGPaint> const& paint_value) const;
|
2023-06-06 20:40:10 +01:00
|
|
|
|
2023-04-10 12:25:40 +01:00
|
|
|
Gfx::AffineTransform m_transform = {};
|
2023-08-03 13:26:29 +02:00
|
|
|
|
2023-09-10 14:10:55 +01:00
|
|
|
template<typename T>
|
2024-03-18 16:22:27 +13:00
|
|
|
JS::GCPtr<T> try_resolve_url_to(URL::URL const& url) const
|
2023-09-10 14:10:55 +01:00
|
|
|
{
|
|
|
|
|
if (!url.fragment().has_value())
|
|
|
|
|
return {};
|
|
|
|
|
auto node = document().get_element_by_id(*url.fragment());
|
|
|
|
|
if (!node)
|
|
|
|
|
return {};
|
|
|
|
|
if (is<T>(*node))
|
|
|
|
|
return static_cast<T&>(*node);
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-03 13:26:29 +02:00
|
|
|
private:
|
|
|
|
|
virtual bool is_svg_graphics_element() const final { return true; }
|
2020-07-19 23:01:53 -07:00
|
|
|
};
|
|
|
|
|
|
2023-04-12 13:32:21 -04:00
|
|
|
Gfx::AffineTransform transform_from_transform_list(ReadonlySpan<Transform> transform_list);
|
2023-04-10 12:25:40 +01:00
|
|
|
|
2020-07-23 09:44:42 -07:00
|
|
|
}
|
2023-08-03 13:26:29 +02:00
|
|
|
|
|
|
|
|
namespace Web::DOM {
|
|
|
|
|
|
|
|
|
|
template<>
|
|
|
|
|
inline bool Node::fast_is<SVG::SVGGraphicsElement>() const { return is_svg_graphics_element(); }
|
|
|
|
|
|
|
|
|
|
}
|