2023-03-24 15:17:11 +00:00
|
|
|
/*
|
2024-10-04 13:19:50 +02:00
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <andreas@ladybird.org>
|
2023-03-24 15:17:11 +00:00
|
|
|
* Copyright (c) 2021, Tobias Christiansen <tobyase@serenityos.org>
|
|
|
|
* Copyright (c) 2021-2023, Sam Atkins <atkinssj@serenityos.org>
|
|
|
|
* Copyright (c) 2022-2023, MacDue <macdue@dueutil.tech>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
#include <LibGC/Root.h>
|
2023-09-24 18:13:39 +02:00
|
|
|
#include <LibJS/Heap/Cell.h>
|
2024-03-18 16:22:27 +13:00
|
|
|
#include <LibURL/URL.h>
|
2023-03-24 15:17:11 +00:00
|
|
|
#include <LibWeb/CSS/Enums.h>
|
2023-03-24 16:42:50 +00:00
|
|
|
#include <LibWeb/CSS/StyleValues/AbstractImageStyleValue.h>
|
2025-04-10 15:52:33 +01:00
|
|
|
#include <LibWeb/Forward.h>
|
2023-03-24 15:17:11 +00:00
|
|
|
|
|
|
|
namespace Web::CSS {
|
|
|
|
|
|
|
|
class ImageStyleValue final
|
|
|
|
: public AbstractImageStyleValue
|
2023-06-11 15:37:36 +02:00
|
|
|
, public Weakable<ImageStyleValue> {
|
2025-03-26 14:40:23 +00:00
|
|
|
|
|
|
|
using Base = AbstractImageStyleValue;
|
|
|
|
|
2023-03-24 15:17:11 +00:00
|
|
|
public:
|
2025-04-08 13:35:26 +01:00
|
|
|
static ValueComparingNonnullRefPtr<ImageStyleValue> create(::URL::URL const& url)
|
2023-05-05 15:02:03 +01:00
|
|
|
{
|
2023-08-19 14:00:10 +01:00
|
|
|
return adopt_ref(*new (nothrow) ImageStyleValue(url));
|
2023-05-05 15:02:03 +01:00
|
|
|
}
|
2024-06-16 10:38:35 +02:00
|
|
|
virtual ~ImageStyleValue() override;
|
2023-03-24 15:17:11 +00:00
|
|
|
|
2025-03-26 14:40:23 +00:00
|
|
|
virtual void visit_edges(JS::Cell::Visitor& visitor) const override;
|
2023-09-24 18:13:39 +02:00
|
|
|
|
2024-12-07 00:59:49 +01:00
|
|
|
virtual String to_string(SerializationMode) const override;
|
2024-08-14 11:10:54 +01:00
|
|
|
virtual bool equals(CSSStyleValue const& other) const override;
|
2023-03-24 15:17:11 +00:00
|
|
|
|
|
|
|
virtual void load_any_resources(DOM::Document&) override;
|
|
|
|
|
|
|
|
Optional<CSSPixels> natural_width() const override;
|
|
|
|
Optional<CSSPixels> natural_height() const override;
|
2023-12-27 23:51:00 +01:00
|
|
|
Optional<CSSPixelFraction> natural_aspect_ratio() const override;
|
2023-03-24 15:17:11 +00:00
|
|
|
|
2023-06-11 15:37:36 +02:00
|
|
|
virtual bool is_paintable() const override;
|
2024-08-06 15:26:47 +03:00
|
|
|
void paint(PaintContext& context, DevicePixelRect const& dest_rect, CSS::ImageRendering image_rendering) const override;
|
2023-03-24 15:17:11 +00:00
|
|
|
|
2024-01-01 13:48:53 +01:00
|
|
|
virtual Optional<Gfx::Color> color_if_single_pixel_bitmap() const override;
|
2024-07-23 15:36:28 +03:00
|
|
|
Gfx::ImmutableBitmap const* current_frame_bitmap(DevicePixelRect const& dest_rect) const;
|
2024-01-01 13:48:53 +01:00
|
|
|
|
2023-03-24 15:17:11 +00:00
|
|
|
Function<void()> on_animate;
|
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
GC::Ptr<HTML::DecodedImageData> image_data() const;
|
2023-06-11 15:37:36 +02:00
|
|
|
|
2023-03-24 15:17:11 +00:00
|
|
|
private:
|
2025-04-08 13:35:26 +01:00
|
|
|
ImageStyleValue(::URL::URL const&);
|
2023-03-24 15:17:11 +00:00
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
GC::Ptr<HTML::SharedResourceRequest> m_resource_request;
|
2023-03-24 15:17:11 +00:00
|
|
|
|
|
|
|
void animate();
|
2023-11-24 14:45:45 +01:00
|
|
|
Gfx::ImmutableBitmap const* bitmap(size_t frame_index, Gfx::IntSize = {}) const;
|
2023-03-24 15:17:11 +00:00
|
|
|
|
2025-04-08 13:35:26 +01:00
|
|
|
::URL::URL m_url;
|
2023-03-24 15:17:11 +00:00
|
|
|
WeakPtr<DOM::Document> m_document;
|
|
|
|
|
|
|
|
size_t m_current_frame_index { 0 };
|
|
|
|
size_t m_loops_completed { 0 };
|
2024-11-15 04:01:23 +13:00
|
|
|
GC::Ptr<Platform::Timer> m_timer;
|
2023-03-24 15:17:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|