2023-03-24 12:17:11 -03:00
|
|
|
/*
|
2024-10-04 08:19:50 -03:00
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <andreas@ladybird.org>
|
2023-03-24 12:17:11 -03:00
|
|
|
* Copyright (c) 2021, Tobias Christiansen <tobyase@serenityos.org>
|
2025-04-10 12:04:34 -03:00
|
|
|
* Copyright (c) 2021-2025, Sam Atkins <sam@ladybird.org>
|
2023-03-24 12:17:11 -03:00
|
|
|
* Copyright (c) 2022-2023, MacDue <macdue@dueutil.tech>
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2023-09-24 13:13:39 -03:00
|
|
|
#include <LibJS/Heap/Cell.h>
|
2023-03-24 12:17:11 -03:00
|
|
|
#include <LibWeb/CSS/Enums.h>
|
2023-03-24 13:42:50 -03:00
|
|
|
#include <LibWeb/CSS/StyleValues/AbstractImageStyleValue.h>
|
2025-04-10 12:04:34 -03:00
|
|
|
#include <LibWeb/CSS/URL.h>
|
2025-04-10 11:52:33 -03:00
|
|
|
#include <LibWeb/Forward.h>
|
2023-03-24 12:17:11 -03:00
|
|
|
|
|
|
|
|
namespace Web::CSS {
|
|
|
|
|
|
|
|
|
|
class ImageStyleValue final
|
|
|
|
|
: public AbstractImageStyleValue
|
2023-06-11 10:37:36 -03:00
|
|
|
, public Weakable<ImageStyleValue> {
|
2025-03-26 11:40:23 -03:00
|
|
|
|
|
|
|
|
using Base = AbstractImageStyleValue;
|
|
|
|
|
|
2023-03-24 12:17:11 -03:00
|
|
|
public:
|
2025-07-27 10:55:16 -03:00
|
|
|
class Client {
|
|
|
|
|
public:
|
|
|
|
|
Client(ImageStyleValue&);
|
|
|
|
|
virtual ~Client();
|
|
|
|
|
virtual void image_style_value_did_update(ImageStyleValue&) = 0;
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
void image_style_value_finalize();
|
|
|
|
|
|
|
|
|
|
ImageStyleValue& m_image_style_value;
|
|
|
|
|
};
|
|
|
|
|
|
2025-04-15 18:18:27 -03:00
|
|
|
static ValueComparingNonnullRefPtr<ImageStyleValue const> create(URL const&);
|
|
|
|
|
static ValueComparingNonnullRefPtr<ImageStyleValue const> create(::URL::URL const&);
|
2024-06-16 05:38:35 -03:00
|
|
|
virtual ~ImageStyleValue() override;
|
2023-03-24 12:17:11 -03:00
|
|
|
|
2025-03-26 11:40:23 -03:00
|
|
|
virtual void visit_edges(JS::Cell::Visitor& visitor) const override;
|
2023-09-24 13:13:39 -03:00
|
|
|
|
2024-12-06 20:59:49 -03:00
|
|
|
virtual String to_string(SerializationMode) const override;
|
2025-08-08 06:11:51 -03:00
|
|
|
virtual bool equals(StyleValue const& other) const override;
|
2023-03-24 12:17:11 -03:00
|
|
|
|
|
|
|
|
virtual void load_any_resources(DOM::Document&) override;
|
|
|
|
|
|
|
|
|
|
Optional<CSSPixels> natural_width() const override;
|
|
|
|
|
Optional<CSSPixels> natural_height() const override;
|
2023-12-27 19:51:00 -03:00
|
|
|
Optional<CSSPixelFraction> natural_aspect_ratio() const override;
|
2023-03-24 12:17:11 -03:00
|
|
|
|
2023-06-11 10:37:36 -03:00
|
|
|
virtual bool is_paintable() const override;
|
2025-07-31 18:07:26 -03:00
|
|
|
void paint(DisplayListRecordingContext& context, DevicePixelRect const& dest_rect, CSS::ImageRendering image_rendering) const override;
|
2023-03-24 12:17:11 -03:00
|
|
|
|
2024-01-01 09:48:53 -03:00
|
|
|
virtual Optional<Gfx::Color> color_if_single_pixel_bitmap() const override;
|
2024-07-23 09:36:28 -03:00
|
|
|
Gfx::ImmutableBitmap const* current_frame_bitmap(DevicePixelRect const& dest_rect) const;
|
2024-01-01 09:48:53 -03:00
|
|
|
|
2025-04-15 18:18:27 -03:00
|
|
|
mutable Function<void()> on_animate;
|
2023-03-24 12:17:11 -03:00
|
|
|
|
2024-11-14 12:01:23 -03:00
|
|
|
GC::Ptr<HTML::DecodedImageData> image_data() const;
|
2023-06-11 10:37:36 -03:00
|
|
|
|
2023-03-24 12:17:11 -03:00
|
|
|
private:
|
2025-07-27 10:55:16 -03:00
|
|
|
friend class Client;
|
|
|
|
|
|
2025-04-10 12:04:34 -03:00
|
|
|
ImageStyleValue(URL const&);
|
2023-03-24 12:17:11 -03:00
|
|
|
|
2025-07-27 10:55:16 -03:00
|
|
|
void register_client(Client&);
|
|
|
|
|
void unregister_client(Client&);
|
|
|
|
|
|
2025-04-10 12:04:34 -03:00
|
|
|
virtual void set_style_sheet(GC::Ptr<CSSStyleSheet>) override;
|
2025-08-08 06:11:51 -03:00
|
|
|
virtual ValueComparingNonnullRefPtr<StyleValue const> absolutized(CSSPixelRect const& viewport_rect, Length::FontMetrics const& font_metrics, Length::FontMetrics const& root_font_metrics) const override;
|
2023-03-24 12:17:11 -03:00
|
|
|
|
|
|
|
|
void animate();
|
2023-11-24 10:45:45 -03:00
|
|
|
Gfx::ImmutableBitmap const* bitmap(size_t frame_index, Gfx::IntSize = {}) const;
|
2023-03-24 12:17:11 -03:00
|
|
|
|
2025-04-10 12:04:34 -03:00
|
|
|
GC::Ptr<HTML::SharedResourceRequest> m_resource_request;
|
|
|
|
|
GC::Ptr<CSSStyleSheet> m_style_sheet;
|
|
|
|
|
|
|
|
|
|
URL m_url;
|
2023-03-24 12:17:11 -03:00
|
|
|
WeakPtr<DOM::Document> m_document;
|
|
|
|
|
|
|
|
|
|
size_t m_current_frame_index { 0 };
|
|
|
|
|
size_t m_loops_completed { 0 };
|
2024-11-14 12:01:23 -03:00
|
|
|
GC::Ptr<Platform::Timer> m_timer;
|
2025-07-27 10:55:16 -03:00
|
|
|
|
|
|
|
|
HashTable<Client*> m_clients;
|
2023-03-24 12:17:11 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|