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>
|
|
|
|
|
* 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-14 12:01:23 -03:00
|
|
|
#include <LibGC/Root.h>
|
2023-09-24 13:13:39 -03:00
|
|
|
#include <LibJS/Heap/Cell.h>
|
2024-03-18 00:22:27 -03:00
|
|
|
#include <LibURL/URL.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>
|
2024-08-03 00:27:08 -03:00
|
|
|
#include <LibWeb/HTML/SharedResourceRequest.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> {
|
2023-03-24 12:17:11 -03:00
|
|
|
public:
|
2024-03-18 00:22:27 -03:00
|
|
|
static ValueComparingNonnullRefPtr<ImageStyleValue> create(URL::URL const& url)
|
2023-05-05 11:02:03 -03:00
|
|
|
{
|
2023-08-19 10:00:10 -03:00
|
|
|
return adopt_ref(*new (nothrow) ImageStyleValue(url));
|
2023-05-05 11:02:03 -03:00
|
|
|
}
|
2024-06-16 05:38:35 -03:00
|
|
|
virtual ~ImageStyleValue() override;
|
2023-03-24 12:17:11 -03:00
|
|
|
|
2024-10-30 05:37:08 -03:00
|
|
|
void visit_edges(JS::Cell::Visitor& visitor) const;
|
2023-09-24 13:13:39 -03:00
|
|
|
|
2024-12-06 20:59:49 -03:00
|
|
|
virtual String to_string(SerializationMode) const override;
|
2024-08-14 07:10:54 -03:00
|
|
|
virtual bool equals(CSSStyleValue 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;
|
2024-08-06 09:26:47 -03:00
|
|
|
void paint(PaintContext& 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
|
|
|
|
2023-03-24 12:17:11 -03:00
|
|
|
Function<void()> on_animate;
|
|
|
|
|
|
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:
|
2024-03-18 00:22:27 -03:00
|
|
|
ImageStyleValue(URL::URL const&);
|
2023-03-24 12:17:11 -03:00
|
|
|
|
2024-11-14 12:01:23 -03:00
|
|
|
GC::Ptr<HTML::SharedResourceRequest> m_resource_request;
|
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
|
|
|
|
2024-03-18 00:22:27 -03:00
|
|
|
URL::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;
|
2023-03-24 12:17:11 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|