diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp index 5e4af2e804..dbb89a9cb4 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp @@ -2273,7 +2273,7 @@ RefPtr Parser::parse_image_value(ParsingContext const& context, Styl { auto url = parse_url_function(context, component_value); if (url.has_value()) - return ImageStyleValue::create(url.value(), context.document()); + return ImageStyleValue::create(url.value()); // FIXME: Handle gradients. return {}; diff --git a/Userland/Libraries/LibWeb/CSS/StyleValue.cpp b/Userland/Libraries/LibWeb/CSS/StyleValue.cpp index d305d5577f..3bd88e87ed 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValue.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleValue.cpp @@ -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)); } diff --git a/Userland/Libraries/LibWeb/CSS/StyleValue.h b/Userland/Libraries/LibWeb/CSS/StyleValue.h index 55f44173b5..58dfc94903 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValue.h +++ b/Userland/Libraries/LibWeb/CSS/StyleValue.h @@ -891,15 +891,16 @@ class ImageStyleValue final : public StyleValue , public ImageResourceClient { public: - static NonnullRefPtr create(AK::URL const& url, DOM::Document* document) { return adopt_ref(*new ImageStyleValue(url, document)); } + static NonnullRefPtr create(AK::URL const& url) { return adopt_ref(*new ImageStyleValue(url)); } virtual ~ImageStyleValue() override { } String to_string() const override { return String::formatted("Image({})", m_url.to_string()); } - const Gfx::Bitmap* bitmap() const { return m_bitmap; } + void load_bitmap(DOM::Document& document); + Gfx::Bitmap const* bitmap() const { return m_bitmap; } private: - ImageStyleValue(AK::URL const&, DOM::Document*); + ImageStyleValue(AK::URL const&); // ^ResourceClient virtual void resource_did_load() override; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLBodyElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLBodyElement.cpp index abaf4ecee1..ca2c769f97 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLBodyElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLBodyElement.cpp @@ -55,7 +55,7 @@ void HTMLBodyElement::parse_attribute(const FlyString& name, const String& value if (color.has_value()) document().set_visited_link_color(color.value()); } else if (name.equals_ignoring_case("background")) { - m_background_style_value = CSS::ImageStyleValue::create(document().parse_url(value), &document()); + m_background_style_value = CSS::ImageStyleValue::create(document().parse_url(value)); } } diff --git a/Userland/Libraries/LibWeb/Layout/Node.cpp b/Userland/Libraries/LibWeb/Layout/Node.cpp index bcbf449d5c..755fa2c36a 100644 --- a/Userland/Libraries/LibWeb/Layout/Node.cpp +++ b/Userland/Libraries/LibWeb/Layout/Node.cpp @@ -218,6 +218,7 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& specified_style) auto bgimage = specified_style.property(CSS::PropertyID::BackgroundImage); if (bgimage.has_value() && bgimage.value()->is_image()) { m_background_image = bgimage.value()->as_image(); + m_background_image->load_bitmap(document()); } computed_values.set_box_sizing(specified_style.box_sizing());