/src/serenity/Userland/Libraries/LibWeb/SVG/SVGSVGElement.h
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 2020, Matthew Olsson <matthewcolsson@gmail.com> |
3 | | * |
4 | | * SPDX-License-Identifier: BSD-2-Clause |
5 | | */ |
6 | | |
7 | | #pragma once |
8 | | |
9 | | #include <LibGfx/Bitmap.h> |
10 | | #include <LibWeb/DOM/NonElementParentNode.h> |
11 | | #include <LibWeb/Geometry/DOMMatrix.h> |
12 | | #include <LibWeb/Geometry/DOMPoint.h> |
13 | | #include <LibWeb/SVG/AttributeParser.h> |
14 | | #include <LibWeb/SVG/SVGAnimatedLength.h> |
15 | | #include <LibWeb/SVG/SVGGraphicsElement.h> |
16 | | #include <LibWeb/SVG/SVGLength.h> |
17 | | #include <LibWeb/SVG/SVGTransform.h> |
18 | | #include <LibWeb/SVG/SVGViewport.h> |
19 | | #include <LibWeb/SVG/ViewBox.h> |
20 | | #include <LibWeb/WebIDL/Types.h> |
21 | | |
22 | | namespace Web::SVG { |
23 | | |
24 | | class SVGSVGElement final : public SVGGraphicsElement |
25 | | , public SVGViewport |
26 | | // SVGSVGElement is not strictly a NonElementParentNode, but it implements the same get_element_by_id() method. |
27 | | , public DOM::NonElementParentNode<SVGSVGElement> { |
28 | | WEB_PLATFORM_OBJECT(SVGSVGElement, SVGGraphicsElement); |
29 | | JS_DECLARE_ALLOCATOR(SVGSVGElement); |
30 | | |
31 | | public: |
32 | | virtual JS::GCPtr<Layout::Node> create_layout_node(NonnullRefPtr<CSS::StyleProperties>) override; |
33 | | |
34 | | virtual void apply_presentational_hints(CSS::StyleProperties&) const override; |
35 | | |
36 | 0 | virtual bool requires_svg_container() const override { return false; } |
37 | 0 | virtual bool is_svg_container() const override { return true; } |
38 | | |
39 | | virtual Optional<ViewBox> view_box() const override; |
40 | 0 | virtual Optional<PreserveAspectRatio> preserve_aspect_ratio() const override { return m_preserve_aspect_ratio; } |
41 | | |
42 | | void set_fallback_view_box_for_svg_as_image(Optional<ViewBox>); |
43 | | |
44 | 0 | JS::NonnullGCPtr<SVGAnimatedRect> view_box_for_bindings() { return *m_view_box_for_bindings; } |
45 | | |
46 | | JS::NonnullGCPtr<SVGAnimatedLength> x() const; |
47 | | JS::NonnullGCPtr<SVGAnimatedLength> y() const; |
48 | | JS::NonnullGCPtr<SVGAnimatedLength> width() const; |
49 | | JS::NonnullGCPtr<SVGAnimatedLength> height() const; |
50 | | |
51 | | float current_scale() const; |
52 | | void set_current_scale(float); |
53 | | |
54 | | JS::NonnullGCPtr<Geometry::DOMPointReadOnly> current_translate() const; |
55 | | |
56 | | JS::NonnullGCPtr<DOM::NodeList> get_intersection_list(JS::NonnullGCPtr<Geometry::DOMRectReadOnly> rect, JS::GCPtr<SVGElement> reference_element) const; |
57 | | JS::NonnullGCPtr<DOM::NodeList> get_enclosure_list(JS::NonnullGCPtr<Geometry::DOMRectReadOnly> rect, JS::GCPtr<SVGElement> reference_element) const; |
58 | | bool check_intersection(JS::NonnullGCPtr<SVGElement> element, JS::NonnullGCPtr<Geometry::DOMRectReadOnly> rect) const; |
59 | | bool check_enclosure(JS::NonnullGCPtr<SVGElement> element, JS::NonnullGCPtr<Geometry::DOMRectReadOnly> rect) const; |
60 | | |
61 | | void deselect_all() const; |
62 | | |
63 | | JS::NonnullGCPtr<SVGLength> create_svg_length() const; |
64 | | JS::NonnullGCPtr<Geometry::DOMPoint> create_svg_point() const; |
65 | | JS::NonnullGCPtr<Geometry::DOMMatrix> create_svg_matrix() const; |
66 | | JS::NonnullGCPtr<Geometry::DOMRect> create_svg_rect() const; |
67 | | JS::NonnullGCPtr<SVGTransform> create_svg_transform() const; |
68 | | |
69 | | // Deprecated methods that have no effect when called, but which are kept for compatibility reasons. |
70 | | WebIDL::UnsignedLong suspend_redraw(WebIDL::UnsignedLong max_wait_milliseconds) const |
71 | 0 | { |
72 | 0 | (void)max_wait_milliseconds; |
73 | | // When the suspendRedraw method is called, it must return 1. |
74 | 0 | return 1; |
75 | 0 | } |
76 | | void unsuspend_redraw(WebIDL::UnsignedLong suspend_handle_id) const |
77 | 0 | { |
78 | 0 | (void)suspend_handle_id; |
79 | 0 | } |
80 | 0 | void unsuspend_redraw_all() const { } |
81 | 0 | void force_redraw() const { } |
82 | | |
83 | | [[nodiscard]] RefPtr<CSS::CSSStyleValue> width_style_value_from_attribute() const; |
84 | | [[nodiscard]] RefPtr<CSS::CSSStyleValue> height_style_value_from_attribute() const; |
85 | | |
86 | | private: |
87 | | SVGSVGElement(DOM::Document&, DOM::QualifiedName); |
88 | | |
89 | | virtual void initialize(JS::Realm&) override; |
90 | | virtual void visit_edges(Visitor&) override; |
91 | | |
92 | 0 | virtual bool is_svg_svg_element() const override { return true; } |
93 | | |
94 | | virtual void attribute_changed(FlyString const& name, Optional<String> const& old_value, Optional<String> const& value) override; |
95 | | |
96 | | void update_fallback_view_box_for_svg_as_image(); |
97 | | |
98 | | Optional<ViewBox> m_view_box; |
99 | | Optional<PreserveAspectRatio> m_preserve_aspect_ratio; |
100 | | |
101 | | Optional<ViewBox> m_fallback_view_box_for_svg_as_image; |
102 | | |
103 | | JS::GCPtr<SVGAnimatedRect> m_view_box_for_bindings; |
104 | | }; |
105 | | |
106 | | } |
107 | | |
108 | | namespace Web::DOM { |
109 | | |
110 | | template<> |
111 | 0 | inline bool Node::fast_is<SVG::SVGSVGElement>() const { return is_svg_svg_element(); } |
112 | | |
113 | | } |