2022-10-03 21:10:39 -06:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2022, Andrew Kaster <akaster@serenityos.org>
|
2023-02-28 00:05:39 +00:00
|
|
|
* Copyright (c) 2023, Luke Wilde <lukew@serenityos.org>
|
2022-10-03 21:10:39 -06:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AK/Vector.h>
|
2024-11-15 04:01:23 +13:00
|
|
|
#include <LibGC/Ptr.h>
|
2024-01-09 16:05:03 -07:00
|
|
|
#include <LibWeb/Bindings/PlatformObject.h>
|
2022-10-03 21:10:39 -06:00
|
|
|
#include <LibWeb/FileAPI/File.h>
|
2024-02-26 18:54:36 +01:00
|
|
|
#include <LibWeb/WebIDL/Types.h>
|
2022-10-03 21:10:39 -06:00
|
|
|
|
|
|
|
namespace Web::FileAPI {
|
|
|
|
|
2024-03-18 21:58:25 +01:00
|
|
|
class FileList
|
|
|
|
: public Bindings::PlatformObject
|
|
|
|
, public Bindings::Serializable {
|
2024-01-09 16:05:03 -07:00
|
|
|
WEB_PLATFORM_OBJECT(FileList, Bindings::PlatformObject);
|
2024-11-15 04:01:23 +13:00
|
|
|
GC_DECLARE_ALLOCATOR(FileList);
|
2022-10-03 21:10:39 -06:00
|
|
|
|
|
|
|
public:
|
2024-11-15 04:01:23 +13:00
|
|
|
[[nodiscard]] static GC::Ref<FileList> create(JS::Realm&);
|
2024-03-18 21:58:25 +01:00
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
void add_file(GC::Ref<File> file) { m_files.append(file); }
|
2024-08-18 10:48:22 -04:00
|
|
|
|
2022-10-03 21:10:39 -06:00
|
|
|
virtual ~FileList() override;
|
|
|
|
|
|
|
|
// https://w3c.github.io/FileAPI/#dfn-length
|
2024-02-26 18:54:36 +01:00
|
|
|
WebIDL::UnsignedLong length() const { return m_files.size(); }
|
2022-10-03 21:10:39 -06:00
|
|
|
|
2023-02-25 10:44:51 -07:00
|
|
|
// https://w3c.github.io/FileAPI/#dfn-item
|
|
|
|
File* item(size_t index)
|
|
|
|
{
|
|
|
|
return index < m_files.size() ? m_files[index].ptr() : nullptr;
|
|
|
|
}
|
|
|
|
|
2022-10-03 21:10:39 -06:00
|
|
|
// https://w3c.github.io/FileAPI/#dfn-item
|
|
|
|
File const* item(size_t index) const
|
|
|
|
{
|
|
|
|
return index < m_files.size() ? m_files[index].ptr() : nullptr;
|
|
|
|
}
|
|
|
|
|
2024-07-25 18:15:51 +12:00
|
|
|
virtual Optional<JS::Value> item_value(size_t index) const override;
|
2022-10-03 21:10:39 -06:00
|
|
|
|
2024-03-18 21:58:25 +01:00
|
|
|
virtual StringView interface_name() const override { return "FileList"sv; }
|
|
|
|
virtual WebIDL::ExceptionOr<void> serialization_steps(HTML::SerializationRecord& serialized, bool for_storage, HTML::SerializationMemory&) override;
|
|
|
|
virtual WebIDL::ExceptionOr<void> deserialization_steps(ReadonlySpan<u32> const& serialized, size_t& position, HTML::DeserializationMemory&) override;
|
|
|
|
|
2022-10-03 21:10:39 -06:00
|
|
|
private:
|
2024-03-18 21:58:25 +01:00
|
|
|
explicit FileList(JS::Realm&);
|
2022-10-03 21:10:39 -06:00
|
|
|
|
2023-08-07 08:41:28 +02:00
|
|
|
virtual void initialize(JS::Realm&) override;
|
2022-10-03 21:10:39 -06:00
|
|
|
virtual void visit_edges(Cell::Visitor&) override;
|
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
Vector<GC::Ref<File>> m_files;
|
2022-10-03 21:10:39 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|