mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 09:48:11 +00:00
LibWeb: Start fleshing out HTML "image requests" and "image data"
This patch adds HTML::ImageRequest and HTML::DecodedImageData. The latter had to use a different name than "ImageData", as there is already an IDL-exposed ImageData class in HTML.
This commit is contained in:
parent
420952a433
commit
596eabe9e6
6 changed files with 281 additions and 0 deletions
44
Userland/Libraries/LibWeb/HTML/DecodedImageData.h
Normal file
44
Userland/Libraries/LibWeb/HTML/DecodedImageData.h
Normal file
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* Copyright (c) 2023, Andreas Kling <kling@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/RefCounted.h>
|
||||
#include <LibGfx/Forward.h>
|
||||
#include <LibJS/Heap/Cell.h>
|
||||
|
||||
namespace Web::HTML {
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/images.html#img-req-data
|
||||
class DecodedImageData final : public RefCounted<DecodedImageData> {
|
||||
public:
|
||||
struct Frame {
|
||||
RefPtr<Gfx::Bitmap const> bitmap;
|
||||
int duration { 0 };
|
||||
};
|
||||
|
||||
static ErrorOr<NonnullRefPtr<DecodedImageData>> create(Vector<Frame>&&, size_t loop_count, bool animated);
|
||||
~DecodedImageData();
|
||||
|
||||
RefPtr<Gfx::Bitmap const> bitmap(size_t frame_index) const;
|
||||
int frame_duration(size_t frame_index) const;
|
||||
|
||||
size_t frame_count() const { return m_frames.size(); }
|
||||
size_t loop_count() const { return m_loop_count; }
|
||||
bool is_animated() const { return m_animated; }
|
||||
|
||||
Optional<int> natural_width() const;
|
||||
Optional<int> natural_height() const;
|
||||
|
||||
private:
|
||||
DecodedImageData(Vector<Frame>&&, size_t loop_count, bool animated);
|
||||
|
||||
Vector<Frame> m_frames;
|
||||
size_t m_loop_count { 0 };
|
||||
bool m_animated { false };
|
||||
};
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue