/src/serenity/Userland/Libraries/LibWeb/CSS/StyleValues/ImageStyleValue.h
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> |
3 | | * Copyright (c) 2021, Tobias Christiansen <tobyase@serenityos.org> |
4 | | * Copyright (c) 2021-2023, Sam Atkins <atkinssj@serenityos.org> |
5 | | * Copyright (c) 2022-2023, MacDue <macdue@dueutil.tech> |
6 | | * |
7 | | * SPDX-License-Identifier: BSD-2-Clause |
8 | | */ |
9 | | |
10 | | #pragma once |
11 | | |
12 | | #include <LibJS/Heap/Cell.h> |
13 | | #include <LibJS/Heap/Handle.h> |
14 | | #include <LibURL/URL.h> |
15 | | #include <LibWeb/CSS/Enums.h> |
16 | | #include <LibWeb/CSS/StyleValues/AbstractImageStyleValue.h> |
17 | | #include <LibWeb/HTML/SharedResourceRequest.h> |
18 | | |
19 | | namespace Web::CSS { |
20 | | |
21 | | class ImageStyleValue final |
22 | | : public AbstractImageStyleValue |
23 | | , public Weakable<ImageStyleValue> { |
24 | | public: |
25 | | static ValueComparingNonnullRefPtr<ImageStyleValue> create(URL::URL const& url) |
26 | 0 | { |
27 | 0 | return adopt_ref(*new (nothrow) ImageStyleValue(url)); |
28 | 0 | } |
29 | | virtual ~ImageStyleValue() override; |
30 | | |
31 | | void visit_edges(JS::Cell::Visitor& visitor) const |
32 | 0 | { |
33 | | // FIXME: visit_edges in non-GC allocated classes is confusing pattern. |
34 | | // Consider making CSSStyleValue to be GC allocated instead. |
35 | 0 | visitor.visit(m_resource_request); |
36 | 0 | } |
37 | | |
38 | | virtual String to_string() const override; |
39 | | virtual bool equals(CSSStyleValue const& other) const override; |
40 | | |
41 | | virtual void load_any_resources(DOM::Document&) override; |
42 | | |
43 | | Optional<CSSPixels> natural_width() const override; |
44 | | Optional<CSSPixels> natural_height() const override; |
45 | | Optional<CSSPixelFraction> natural_aspect_ratio() const override; |
46 | | |
47 | | virtual bool is_paintable() const override; |
48 | | void paint(PaintContext& context, DevicePixelRect const& dest_rect, CSS::ImageRendering image_rendering, RefPtr<Painting::DisplayList> clip_paths = {}) const override; |
49 | | |
50 | | virtual Optional<Gfx::Color> color_if_single_pixel_bitmap() const override; |
51 | | |
52 | | Function<void()> on_animate; |
53 | | |
54 | | JS::GCPtr<HTML::DecodedImageData> image_data() const; |
55 | | |
56 | | private: |
57 | | ImageStyleValue(URL::URL const&); |
58 | | |
59 | | JS::GCPtr<HTML::SharedResourceRequest> m_resource_request; |
60 | | |
61 | | void animate(); |
62 | | Gfx::ImmutableBitmap const* bitmap(size_t frame_index, Gfx::IntSize = {}) const; |
63 | | |
64 | | URL::URL m_url; |
65 | | WeakPtr<DOM::Document> m_document; |
66 | | |
67 | | size_t m_current_frame_index { 0 }; |
68 | | size_t m_loops_completed { 0 }; |
69 | | RefPtr<Platform::Timer> m_timer; |
70 | | }; |
71 | | |
72 | | } |