| 
									
										
										
										
											2023-05-20 16:34:52 +02:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2024-10-04 13:19:50 +02:00
										 |  |  |  * Copyright (c) 2023, Andreas Kling <andreas@ladybird.org> | 
					
						
							| 
									
										
										
										
											2023-05-20 16:34:52 +02:00
										 |  |  |  * | 
					
						
							|  |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-11 14:46:54 +02:00
										 |  |  | #include <LibWeb/DOM/Document.h>
 | 
					
						
							| 
									
										
										
										
											2023-05-20 16:34:52 +02:00
										 |  |  | #include <LibWeb/HTML/DecodedImageData.h>
 | 
					
						
							| 
									
										
										
										
											2024-08-06 21:56:24 -06:00
										 |  |  | #include <LibWeb/Page/Page.h>
 | 
					
						
							| 
									
										
										
										
											2023-05-20 16:34:52 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace Web::SVG { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class SVGDecodedImageData final : public HTML::DecodedImageData { | 
					
						
							| 
									
										
										
										
											2024-11-15 04:01:23 +13:00
										 |  |  |     GC_CELL(SVGDecodedImageData, HTML::DecodedImageData); | 
					
						
							|  |  |  |     GC_DECLARE_ALLOCATOR(SVGDecodedImageData); | 
					
						
							| 
									
										
										
										
											2023-12-12 20:07:19 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-20 16:34:52 +02:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2024-02-29 18:13:24 +01:00
										 |  |  |     class SVGPageClient; | 
					
						
							| 
									
										
										
										
											2024-11-15 04:01:23 +13:00
										 |  |  |     static ErrorOr<GC::Ref<SVGDecodedImageData>> create(JS::Realm&, GC::Ref<Page>, URL::URL const&, ByteBuffer encoded_svg); | 
					
						
							| 
									
										
										
										
											2023-05-20 16:34:52 +02:00
										 |  |  |     virtual ~SVGDecodedImageData() override; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-24 14:45:45 +01:00
										 |  |  |     virtual RefPtr<Gfx::ImmutableBitmap> bitmap(size_t frame_index, Gfx::IntSize) const override; | 
					
						
							| 
									
										
										
										
											2023-05-20 16:34:52 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     virtual Optional<CSSPixels> intrinsic_width() const override; | 
					
						
							|  |  |  |     virtual Optional<CSSPixels> intrinsic_height() const override; | 
					
						
							| 
									
										
										
										
											2023-09-03 17:33:58 -05:00
										 |  |  |     virtual Optional<CSSPixelFraction> intrinsic_aspect_ratio() const override; | 
					
						
							| 
									
										
										
										
											2023-05-20 16:34:52 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // FIXME: Support SVG animations. :^)
 | 
					
						
							|  |  |  |     virtual int frame_duration(size_t) const override { return 0; } | 
					
						
							|  |  |  |     virtual size_t frame_count() const override { return 1; } | 
					
						
							|  |  |  |     virtual size_t loop_count() const override { return 0; } | 
					
						
							|  |  |  |     virtual bool is_animated() const override { return false; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-21 07:02:41 +02:00
										 |  |  |     DOM::Document const& svg_document() const { return *m_document; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-12 20:07:19 +01:00
										 |  |  |     virtual void visit_edges(Cell::Visitor& visitor) override; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-20 16:34:52 +02:00
										 |  |  | private: | 
					
						
							| 
									
										
										
										
											2024-11-15 04:01:23 +13:00
										 |  |  |     SVGDecodedImageData(GC::Ref<Page>, GC::Ref<SVGPageClient>, GC::Ref<DOM::Document>, GC::Ref<SVG::SVGSVGElement>); | 
					
						
							| 
									
										
										
										
											2023-05-20 17:19:11 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-24 14:45:45 +01:00
										 |  |  |     RefPtr<Gfx::Bitmap> render(Gfx::IntSize) const; | 
					
						
							| 
									
										
										
										
											2024-02-24 08:34:49 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     mutable HashMap<Gfx::IntSize, NonnullRefPtr<Gfx::ImmutableBitmap>> m_cached_rendered_bitmaps; | 
					
						
							| 
									
										
										
										
											2023-05-20 17:19:11 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-15 04:01:23 +13:00
										 |  |  |     GC::Ref<Page> m_page; | 
					
						
							|  |  |  |     GC::Ref<SVGPageClient> m_page_client; | 
					
						
							| 
									
										
										
										
											2023-05-20 17:19:11 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-15 04:01:23 +13:00
										 |  |  |     GC::Ref<DOM::Document> m_document; | 
					
						
							|  |  |  |     GC::Ref<SVG::SVGSVGElement> m_root_element; | 
					
						
							| 
									
										
										
										
											2023-05-20 16:34:52 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-29 18:13:24 +01:00
										 |  |  | class SVGDecodedImageData::SVGPageClient final : public PageClient { | 
					
						
							| 
									
										
										
										
											2024-11-15 04:01:23 +13:00
										 |  |  |     GC_CELL(SVGDecodedImageData::SVGPageClient, PageClient); | 
					
						
							|  |  |  |     GC_DECLARE_ALLOCATOR(SVGDecodedImageData::SVGPageClient); | 
					
						
							| 
									
										
										
										
											2024-02-29 18:13:24 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | public: | 
					
						
							| 
									
										
										
										
											2024-11-15 04:01:23 +13:00
										 |  |  |     static GC::Ref<SVGPageClient> create(JS::VM& vm, Page& page) | 
					
						
							| 
									
										
										
										
											2024-02-29 18:13:24 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2024-11-14 06:13:46 +13:00
										 |  |  |         return vm.heap().allocate<SVGPageClient>(page); | 
					
						
							| 
									
										
										
										
											2024-02-29 18:13:24 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     virtual ~SVGPageClient() override = default; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-15 04:01:23 +13:00
										 |  |  |     GC::Ref<Page> m_host_page; | 
					
						
							|  |  |  |     GC::Ptr<Page> m_svg_page; | 
					
						
							| 
									
										
										
										
											2024-02-29 18:13:24 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     virtual Page& page() override { return *m_svg_page; } | 
					
						
							|  |  |  |     virtual Page const& page() const override { return *m_svg_page; } | 
					
						
							|  |  |  |     virtual bool is_connection_open() const override { return false; } | 
					
						
							| 
									
										
										
										
											2024-04-05 13:47:48 -07:00
										 |  |  |     virtual Gfx::Palette palette() const override { return m_host_page->client().palette(); } | 
					
						
							| 
									
										
										
										
											2024-02-29 18:13:24 +01:00
										 |  |  |     virtual DevicePixelRect screen_rect() const override { return {}; } | 
					
						
							|  |  |  |     virtual double device_pixels_per_css_pixel() const override { return 1.0; } | 
					
						
							| 
									
										
										
										
											2024-04-05 13:47:48 -07:00
										 |  |  |     virtual CSS::PreferredColorScheme preferred_color_scheme() const override { return m_host_page->client().preferred_color_scheme(); } | 
					
						
							| 
									
										
										
										
											2024-06-13 01:03:56 +02:00
										 |  |  |     virtual CSS::PreferredContrast preferred_contrast() const override { return m_host_page->client().preferred_contrast(); } | 
					
						
							| 
									
										
										
										
											2024-06-13 16:15:59 +02:00
										 |  |  |     virtual CSS::PreferredMotion preferred_motion() const override { return m_host_page->client().preferred_motion(); } | 
					
						
							| 
									
										
										
										
											2024-02-29 18:13:24 +01:00
										 |  |  |     virtual void request_file(FileRequest) override { } | 
					
						
							| 
									
										
										
										
											2024-05-28 15:51:53 +02:00
										 |  |  |     virtual void paint_next_frame() override { } | 
					
						
							| 
									
										
										
										
											2024-07-03 22:12:28 +10:00
										 |  |  |     virtual void process_screenshot_requests() override { } | 
					
						
							| 
									
										
										
										
											2025-02-25 04:07:53 +01:00
										 |  |  |     virtual void start_display_list_rendering(DevicePixelRect const&, Painting::BackingStore&, PaintOptions, Function<void()>&&) override { } | 
					
						
							| 
									
										
										
										
											2024-02-29 18:13:24 +01:00
										 |  |  |     virtual bool is_ready_to_paint() const override { return true; } | 
					
						
							| 
									
										
										
										
											2025-02-14 23:25:12 +01:00
										 |  |  |     virtual Queue<QueuedInputEvent>& input_event_queue() override { VERIFY_NOT_REACHED(); } | 
					
						
							|  |  |  |     virtual void report_finished_handling_input_event([[maybe_unused]] u64 page_id, [[maybe_unused]] EventResult event_was_handled) override { } | 
					
						
							| 
									
										
										
										
											2024-02-29 18:13:24 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-23 18:42:39 +02:00
										 |  |  |     virtual DisplayListPlayerType display_list_player_type() const override { return m_host_page->client().display_list_player_type(); } | 
					
						
							| 
									
										
										
										
											2024-12-09 21:51:19 +00:00
										 |  |  |     virtual bool is_headless() const override { return m_host_page->client().is_headless(); } | 
					
						
							| 
									
										
										
										
											2024-06-19 14:46:27 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-29 18:13:24 +01:00
										 |  |  | private: | 
					
						
							|  |  |  |     explicit SVGPageClient(Page& host_page) | 
					
						
							|  |  |  |         : m_host_page(host_page) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2024-04-06 10:30:13 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-18 10:37:08 +02:00
										 |  |  |     virtual bool is_svg_page_client() const override { return true; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-06 10:30:13 -07:00
										 |  |  |     virtual void visit_edges(Visitor&) override; | 
					
						
							| 
									
										
										
										
											2024-02-29 18:13:24 +01:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-20 16:34:52 +02:00
										 |  |  | } |