1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 22:27:35 +00:00

LibWeb: Port ImageStyleValue to the ResourceClient interface

This commit is contained in:
Andreas Kling 2020-06-02 13:51:30 +02:00
parent ca8398bc19
commit f3799b501e
2 changed files with 33 additions and 22 deletions

View file

@ -31,8 +31,9 @@
#include <LibWeb/CSS/StyleValue.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/Frame.h>
#include <LibWeb/PageView.h>
#include <LibWeb/Loader/LoadRequest.h>
#include <LibWeb/Loader/ResourceLoader.h>
#include <LibWeb/PageView.h>
namespace Web {
@ -290,17 +291,21 @@ ImageStyleValue::ImageStyleValue(const URL& url, Document& document)
, m_url(url)
, m_document(document.make_weak_ptr())
{
NonnullRefPtr<ImageStyleValue> protector(*this);
ResourceLoader::the().load(url, [this, protector](auto& data, auto&) {
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(data.data(), data.size());
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({});
});
}
}

View file

@ -32,10 +32,11 @@
#include <AK/StringView.h>
#include <AK/URL.h>
#include <AK/WeakPtr.h>
#include <LibGfx/Color.h>
#include <LibGfx/Bitmap.h>
#include <LibGfx/Color.h>
#include <LibWeb/CSS/Length.h>
#include <LibWeb/CSS/PropertyID.h>
#include <LibWeb/Loader/Resource.h>
namespace Web {
@ -299,7 +300,9 @@ private:
CSS::ValueID m_id { CSS::ValueID::Invalid };
};
class ImageStyleValue final : public StyleValue {
class ImageStyleValue final
: public StyleValue
, public ResourceClient {
public:
static NonnullRefPtr<ImageStyleValue> create(const URL& url, Document& document) { return adopt(*new ImageStyleValue(url, document)); }
virtual ~ImageStyleValue() override { }
@ -311,6 +314,9 @@ public:
private:
ImageStyleValue(const URL&, Document&);
// ^ResourceClient
virtual void resource_did_load() override;
URL m_url;
WeakPtr<Document> m_document;
RefPtr<Gfx::Bitmap> m_bitmap;