/* * Copyright (c) 2024, Feng Yu * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include #include #include namespace Web::Clipboard { constexpr auto WEB_CUSTOM_FORMAT_PREFIX = "web "sv; inline constexpr Array MANDATORY_DATA_TYPES = { "text/plain"sv, "text/html"sv, "image/png"sv }; struct ClipboardItemOptions { Bindings::PresentationStyle presentation_style { Bindings::PresentationStyle::Unspecified }; }; // https://w3c.github.io/clipboard-apis/#clipboard-item-interface class ClipboardItem : public Bindings::PlatformObject { WEB_PLATFORM_OBJECT(ClipboardItem, Bindings::PlatformObject); GC_DECLARE_ALLOCATOR(ClipboardItem); public: struct Representation { String mime_type; // The MIME type (e.g., "text/plain"). bool is_custom; // Whether this is a web custom format. GC::Ref data; // The actual data for this representation. }; static WebIDL::ExceptionOr> construct_impl(JS::Realm&, OrderedHashMap> const& items, ClipboardItemOptions const& options = {}); virtual ~ClipboardItem() override; Bindings::PresentationStyle presentation_style() const { return m_presentation_style; } Vector const& types() const { return m_types; } WebIDL::ExceptionOr> get_type(String const& type); static bool supports(JS::VM&, String const& type); private: ClipboardItem(JS::Realm&); virtual void initialize(JS::Realm&) override; virtual void visit_edges(Cell::Visitor&) override; Bindings::PresentationStyle m_presentation_style; Vector m_types; Vector m_representations; }; }