1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 21:57:43 +00:00

LibWeb: Piggyback on HTML::ImageRequest in CSS ImageStyleValue

This is all ad-hoc since no spec currently exists for this behavior.
Basically, ImageStyleValue now uses ImageRequest for fetching and
decoding of images.

This already leads to visible improvements on many websites.
This commit is contained in:
Andreas Kling 2023-06-11 15:37:36 +02:00
parent f70d3faa0f
commit 680fc3f90a
2 changed files with 72 additions and 40 deletions

View file

@ -12,13 +12,12 @@
#include <AK/URL.h>
#include <LibWeb/CSS/Enums.h>
#include <LibWeb/CSS/StyleValues/AbstractImageStyleValue.h>
#include <LibWeb/Loader/ImageResource.h>
namespace Web::CSS {
class ImageStyleValue final
: public AbstractImageStyleValue
, public ImageResourceClient {
, public Weakable<ImageStyleValue> {
public:
static ErrorOr<ValueComparingNonnullRefPtr<ImageStyleValue>> create(AK::URL const& url)
{
@ -34,19 +33,20 @@ public:
Optional<CSSPixels> natural_width() const override;
Optional<CSSPixels> natural_height() const override;
bool is_paintable() const override { return bitmap(0) != nullptr; }
virtual bool is_paintable() const override;
void paint(PaintContext& context, DevicePixelRect const& dest_rect, CSS::ImageRendering image_rendering) const override;
Function<void()> on_animate;
RefPtr<HTML::DecodedImageData const> image_data() const;
private:
ImageStyleValue(AK::URL const&);
// ^ResourceClient
virtual void resource_did_load() override;
RefPtr<HTML::ImageRequest> m_image_request;
void animate();
Gfx::Bitmap const* bitmap(size_t index) const;
Gfx::Bitmap const* bitmap(size_t frame_index, Gfx::IntSize = {}) const;
AK::URL m_url;
WeakPtr<DOM::Document> m_document;