mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 21:57:43 +00:00
LibWeb: Port ImageStyleValue to the ResourceClient interface
This commit is contained in:
parent
ca8398bc19
commit
f3799b501e
2 changed files with 33 additions and 22 deletions
|
@ -31,8 +31,9 @@
|
||||||
#include <LibWeb/CSS/StyleValue.h>
|
#include <LibWeb/CSS/StyleValue.h>
|
||||||
#include <LibWeb/DOM/Document.h>
|
#include <LibWeb/DOM/Document.h>
|
||||||
#include <LibWeb/Frame.h>
|
#include <LibWeb/Frame.h>
|
||||||
#include <LibWeb/PageView.h>
|
#include <LibWeb/Loader/LoadRequest.h>
|
||||||
#include <LibWeb/Loader/ResourceLoader.h>
|
#include <LibWeb/Loader/ResourceLoader.h>
|
||||||
|
#include <LibWeb/PageView.h>
|
||||||
|
|
||||||
namespace Web {
|
namespace Web {
|
||||||
|
|
||||||
|
@ -290,17 +291,21 @@ ImageStyleValue::ImageStyleValue(const URL& url, Document& document)
|
||||||
, m_url(url)
|
, m_url(url)
|
||||||
, m_document(document.make_weak_ptr())
|
, m_document(document.make_weak_ptr())
|
||||||
{
|
{
|
||||||
NonnullRefPtr<ImageStyleValue> protector(*this);
|
LoadRequest request;
|
||||||
ResourceLoader::the().load(url, [this, protector](auto& data, auto&) {
|
request.set_url(url);
|
||||||
if (!m_document)
|
set_resource(ResourceLoader::the().load_resource(request));
|
||||||
return;
|
}
|
||||||
m_bitmap = Gfx::load_png_from_memory(data.data(), data.size());
|
|
||||||
if (!m_bitmap)
|
void ImageStyleValue::resource_did_load()
|
||||||
return;
|
{
|
||||||
// FIXME: Do less than a full repaint if possible?
|
if (!m_document)
|
||||||
if (m_document->frame())
|
return;
|
||||||
m_document->frame()->set_needs_display({});
|
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({});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,10 +32,11 @@
|
||||||
#include <AK/StringView.h>
|
#include <AK/StringView.h>
|
||||||
#include <AK/URL.h>
|
#include <AK/URL.h>
|
||||||
#include <AK/WeakPtr.h>
|
#include <AK/WeakPtr.h>
|
||||||
#include <LibGfx/Color.h>
|
|
||||||
#include <LibGfx/Bitmap.h>
|
#include <LibGfx/Bitmap.h>
|
||||||
|
#include <LibGfx/Color.h>
|
||||||
#include <LibWeb/CSS/Length.h>
|
#include <LibWeb/CSS/Length.h>
|
||||||
#include <LibWeb/CSS/PropertyID.h>
|
#include <LibWeb/CSS/PropertyID.h>
|
||||||
|
#include <LibWeb/Loader/Resource.h>
|
||||||
|
|
||||||
namespace Web {
|
namespace Web {
|
||||||
|
|
||||||
|
@ -162,7 +163,7 @@ public:
|
||||||
{
|
{
|
||||||
return adopt(*new StringStyleValue(string));
|
return adopt(*new StringStyleValue(string));
|
||||||
}
|
}
|
||||||
virtual ~StringStyleValue() override {}
|
virtual ~StringStyleValue() override { }
|
||||||
|
|
||||||
String to_string() const override { return m_string; }
|
String to_string() const override { return m_string; }
|
||||||
|
|
||||||
|
@ -182,7 +183,7 @@ public:
|
||||||
{
|
{
|
||||||
return adopt(*new LengthStyleValue(length));
|
return adopt(*new LengthStyleValue(length));
|
||||||
}
|
}
|
||||||
virtual ~LengthStyleValue() override {}
|
virtual ~LengthStyleValue() override { }
|
||||||
|
|
||||||
virtual String to_string() const override { return m_length.to_string(); }
|
virtual String to_string() const override { return m_length.to_string(); }
|
||||||
virtual Length to_length() const override { return m_length; }
|
virtual Length to_length() const override { return m_length; }
|
||||||
|
@ -207,7 +208,7 @@ public:
|
||||||
{
|
{
|
||||||
return adopt(*new PercentageStyleValue(percentage));
|
return adopt(*new PercentageStyleValue(percentage));
|
||||||
}
|
}
|
||||||
virtual ~PercentageStyleValue() override {}
|
virtual ~PercentageStyleValue() override { }
|
||||||
|
|
||||||
virtual String to_string() const override { return String::format("%g%%", m_percentage); }
|
virtual String to_string() const override { return String::format("%g%%", m_percentage); }
|
||||||
|
|
||||||
|
@ -229,7 +230,7 @@ private:
|
||||||
class InitialStyleValue final : public StyleValue {
|
class InitialStyleValue final : public StyleValue {
|
||||||
public:
|
public:
|
||||||
static NonnullRefPtr<InitialStyleValue> create() { return adopt(*new InitialStyleValue); }
|
static NonnullRefPtr<InitialStyleValue> create() { return adopt(*new InitialStyleValue); }
|
||||||
virtual ~InitialStyleValue() override {}
|
virtual ~InitialStyleValue() override { }
|
||||||
|
|
||||||
String to_string() const override { return "initial"; }
|
String to_string() const override { return "initial"; }
|
||||||
|
|
||||||
|
@ -243,7 +244,7 @@ private:
|
||||||
class InheritStyleValue final : public StyleValue {
|
class InheritStyleValue final : public StyleValue {
|
||||||
public:
|
public:
|
||||||
static NonnullRefPtr<InheritStyleValue> create() { return adopt(*new InheritStyleValue); }
|
static NonnullRefPtr<InheritStyleValue> create() { return adopt(*new InheritStyleValue); }
|
||||||
virtual ~InheritStyleValue() override {}
|
virtual ~InheritStyleValue() override { }
|
||||||
|
|
||||||
String to_string() const override { return "inherit"; }
|
String to_string() const override { return "inherit"; }
|
||||||
|
|
||||||
|
@ -260,7 +261,7 @@ public:
|
||||||
{
|
{
|
||||||
return adopt(*new ColorStyleValue(color));
|
return adopt(*new ColorStyleValue(color));
|
||||||
}
|
}
|
||||||
virtual ~ColorStyleValue() override {}
|
virtual ~ColorStyleValue() override { }
|
||||||
|
|
||||||
Color color() const { return m_color; }
|
Color color() const { return m_color; }
|
||||||
String to_string() const override { return m_color.to_string(); }
|
String to_string() const override { return m_color.to_string(); }
|
||||||
|
@ -282,7 +283,7 @@ public:
|
||||||
{
|
{
|
||||||
return adopt(*new IdentifierStyleValue(id));
|
return adopt(*new IdentifierStyleValue(id));
|
||||||
}
|
}
|
||||||
virtual ~IdentifierStyleValue() override {}
|
virtual ~IdentifierStyleValue() override { }
|
||||||
|
|
||||||
CSS::ValueID id() const { return m_id; }
|
CSS::ValueID id() const { return m_id; }
|
||||||
|
|
||||||
|
@ -299,10 +300,12 @@ private:
|
||||||
CSS::ValueID m_id { CSS::ValueID::Invalid };
|
CSS::ValueID m_id { CSS::ValueID::Invalid };
|
||||||
};
|
};
|
||||||
|
|
||||||
class ImageStyleValue final : public StyleValue {
|
class ImageStyleValue final
|
||||||
|
: public StyleValue
|
||||||
|
, public ResourceClient {
|
||||||
public:
|
public:
|
||||||
static NonnullRefPtr<ImageStyleValue> create(const URL& url, Document& document) { return adopt(*new ImageStyleValue(url, document)); }
|
static NonnullRefPtr<ImageStyleValue> 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()); }
|
String to_string() const override { return String::format("Image{%s}", m_url.to_string().characters()); }
|
||||||
|
|
||||||
|
@ -311,6 +314,9 @@ public:
|
||||||
private:
|
private:
|
||||||
ImageStyleValue(const URL&, Document&);
|
ImageStyleValue(const URL&, Document&);
|
||||||
|
|
||||||
|
// ^ResourceClient
|
||||||
|
virtual void resource_did_load() override;
|
||||||
|
|
||||||
URL m_url;
|
URL m_url;
|
||||||
WeakPtr<Document> m_document;
|
WeakPtr<Document> m_document;
|
||||||
RefPtr<Gfx::Bitmap> m_bitmap;
|
RefPtr<Gfx::Bitmap> m_bitmap;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue