1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 08:48:11 +00:00

LibWeb: Split out image loading logic from HTMLImageElement

Since more DOM nodes are going to want to load images (<object>, ...)
this patch splits out the image loading logic into an ImageLoader class
and then HTMLImageElement simply has an ImageLoader.

LayoutImage is then given a const ImageLoader& at construction and can
then provide layout and rendering for many kinds of DOM nodes.
This commit is contained in:
Andreas Kling 2020-06-13 22:22:54 +02:00
parent d6d248c328
commit 95d70addd8
7 changed files with 246 additions and 101 deletions

View file

@ -27,18 +27,17 @@
#pragma once
#include <AK/ByteBuffer.h>
#include <AK/OwnPtr.h>
#include <LibCore/Forward.h>
#include <LibGfx/Forward.h>
#include <LibWeb/DOM/HTMLElement.h>
#include <LibWeb/Loader/ImageResource.h>
#include <LibWeb/Loader/ImageLoader.h>
namespace Web {
class LayoutDocument;
class HTMLImageElement final
: public HTMLElement
, public ImageResourceClient {
class HTMLImageElement final : public HTMLElement {
public:
using WrapperType = Bindings::HTMLImageElementWrapper;
@ -53,30 +52,20 @@ public:
int preferred_height() const;
const Gfx::Bitmap* bitmap() const;
const Gfx::ImageDecoder* image_decoder() const { return m_image_decoder; }
const Gfx::ImageDecoder* image_decoder() const;
void set_visible_in_viewport(Badge<LayoutDocument>, bool);
private:
// ^ImageResource
virtual void resource_did_load() override;
virtual void resource_did_fail() override;
virtual void resource_did_replace_decoder() override;
virtual bool is_visible_in_viewport() const override { return m_visible_in_viewport; }
void load_image(const String& src);
void animate();
virtual RefPtr<LayoutNode> create_layout_node(const StyleProperties* parent_style) const override;
RefPtr<Gfx::ImageDecoder> m_image_decoder;
ImageLoader m_image_loader;
size_t m_current_frame_index { 0 };
size_t m_loops_completed { 0 };
NonnullRefPtr<Core::Timer> m_timer;
bool m_visible_in_viewport { false };
};
template<>