mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-23 04:55:15 +00:00
LibWeb: Port ImageStyleValue to the ResourceClient interface
This commit is contained in:
parent
ca8398bc19
commit
f3799b501e
Notes:
sideshowbarker
2024-07-19 05:53:30 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/f3799b501eb
2 changed files with 33 additions and 22 deletions
|
@ -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&) {
|
||||
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({});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
||||
|
@ -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<InitialStyleValue> 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<InheritStyleValue> 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<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()); }
|
||||
|
||||
|
@ -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;
|
||||
|
|
Loading…
Add table
Reference in a new issue