diff --git a/Libraries/LibWeb/CSS/StyleValue.cpp b/Libraries/LibWeb/CSS/StyleValue.cpp index 9f6101f1f3..8414a1280c 100644 --- a/Libraries/LibWeb/CSS/StyleValue.cpp +++ b/Libraries/LibWeb/CSS/StyleValue.cpp @@ -31,8 +31,9 @@ #include #include #include -#include +#include #include +#include namespace Web { @@ -290,17 +291,21 @@ ImageStyleValue::ImageStyleValue(const URL& url, Document& document) , m_url(url) , m_document(document.make_weak_ptr()) { - NonnullRefPtr protector(*this); - ResourceLoader::the().load(url, [this, protector](auto& data, auto&) { - if (!m_document) - return; - m_bitmap = Gfx::load_png_from_memory(data.data(), data.size()); - if (!m_bitmap) - return; - // FIXME: Do less than a full repaint if possible? - if (m_document->frame()) - m_document->frame()->set_needs_display({}); - }); + LoadRequest request; + request.set_url(url); + set_resource(ResourceLoader::the().load_resource(request)); +} + +void ImageStyleValue::resource_did_load() +{ + if (!m_document) + return; + m_bitmap = Gfx::load_png_from_memory(resource()->encoded_data().data(), resource()->encoded_data().size()); + if (!m_bitmap) + return; + // FIXME: Do less than a full repaint if possible? + if (m_document->frame()) + m_document->frame()->set_needs_display({}); } } diff --git a/Libraries/LibWeb/CSS/StyleValue.h b/Libraries/LibWeb/CSS/StyleValue.h index e269441ec0..a2c4d09420 100644 --- a/Libraries/LibWeb/CSS/StyleValue.h +++ b/Libraries/LibWeb/CSS/StyleValue.h @@ -32,10 +32,11 @@ #include #include #include -#include #include +#include #include #include +#include namespace Web { @@ -162,7 +163,7 @@ public: { return adopt(*new StringStyleValue(string)); } - virtual ~StringStyleValue() override {} + virtual ~StringStyleValue() override { } String to_string() const override { return m_string; } @@ -182,7 +183,7 @@ public: { return adopt(*new LengthStyleValue(length)); } - virtual ~LengthStyleValue() override {} + virtual ~LengthStyleValue() override { } virtual String to_string() const override { return m_length.to_string(); } virtual Length to_length() const override { return m_length; } @@ -207,7 +208,7 @@ public: { return adopt(*new PercentageStyleValue(percentage)); } - virtual ~PercentageStyleValue() override {} + virtual ~PercentageStyleValue() override { } virtual String to_string() const override { return String::format("%g%%", m_percentage); } @@ -229,7 +230,7 @@ private: class InitialStyleValue final : public StyleValue { public: static NonnullRefPtr create() { return adopt(*new InitialStyleValue); } - virtual ~InitialStyleValue() override {} + virtual ~InitialStyleValue() override { } String to_string() const override { return "initial"; } @@ -243,7 +244,7 @@ private: class InheritStyleValue final : public StyleValue { public: static NonnullRefPtr create() { return adopt(*new InheritStyleValue); } - virtual ~InheritStyleValue() override {} + virtual ~InheritStyleValue() override { } String to_string() const override { return "inherit"; } @@ -260,7 +261,7 @@ public: { return adopt(*new ColorStyleValue(color)); } - virtual ~ColorStyleValue() override {} + virtual ~ColorStyleValue() override { } Color color() const { return m_color; } String to_string() const override { return m_color.to_string(); } @@ -282,7 +283,7 @@ public: { return adopt(*new IdentifierStyleValue(id)); } - virtual ~IdentifierStyleValue() override {} + virtual ~IdentifierStyleValue() override { } CSS::ValueID id() const { return m_id; } @@ -299,10 +300,12 @@ private: CSS::ValueID m_id { CSS::ValueID::Invalid }; }; -class ImageStyleValue final : public StyleValue { +class ImageStyleValue final + : public StyleValue + , public ResourceClient { public: static NonnullRefPtr create(const URL& url, Document& document) { return adopt(*new ImageStyleValue(url, document)); } - virtual ~ImageStyleValue() override {} + virtual ~ImageStyleValue() override { } String to_string() const override { return String::format("Image{%s}", m_url.to_string().characters()); } @@ -311,6 +314,9 @@ public: private: ImageStyleValue(const URL&, Document&); + // ^ResourceClient + virtual void resource_did_load() override; + URL m_url; WeakPtr m_document; RefPtr m_bitmap;