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

LibWeb: Move image resource request out of ImageStyleValue constructor

This always felt awkward to me, and required a few other hacks to make
it work. Now, the request is only started when `load_bitmap()` is
called, which we do inside `NodeWithStyle::apply_style()`.
This commit is contained in:
Sam Atkins 2021-10-22 20:55:27 +01:00 committed by Andreas Kling
parent cf3c125e77
commit 0f393771b7
5 changed files with 17 additions and 9 deletions

View file

@ -367,13 +367,19 @@ Color IdentifierStyleValue::to_color(Layout::NodeWithStyle const& node) const
}
}
ImageStyleValue::ImageStyleValue(AK::URL const& url, DOM::Document* document)
ImageStyleValue::ImageStyleValue(AK::URL const& url)
: StyleValue(Type::Image)
, m_url(url)
, m_document(document)
{
// FIXME: This doesn't work right without a document.
auto request = LoadRequest::create_for_url_on_page(url, document ? document->page() : nullptr);
}
void ImageStyleValue::load_bitmap(DOM::Document& document)
{
if (m_bitmap)
return;
m_document = &document;
auto request = LoadRequest::create_for_url_on_page(m_url, document.page());
set_resource(ResourceLoader::the().load_resource(Resource::Type::Image, request));
}