/src/serenity/Userland/Libraries/LibWeb/HTML/DataTransfer.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (c) 2024, Tim Flynn <trflynn89@serenityos.org> |
3 | | * |
4 | | * SPDX-License-Identifier: BSD-2-Clause |
5 | | */ |
6 | | |
7 | | #pragma once |
8 | | |
9 | | #include <LibJS/Forward.h> |
10 | | #include <LibWeb/Bindings/PlatformObject.h> |
11 | | #include <LibWeb/HTML/DragDataStore.h> |
12 | | |
13 | | namespace Web::HTML { |
14 | | |
15 | | #define ENUMERATE_DATA_TRANSFER_EFFECTS \ |
16 | | __ENUMERATE_DATA_TRANSFER_EFFECT(none) \ |
17 | | __ENUMERATE_DATA_TRANSFER_EFFECT(copy) \ |
18 | | __ENUMERATE_DATA_TRANSFER_EFFECT(copyLink) \ |
19 | | __ENUMERATE_DATA_TRANSFER_EFFECT(copyMove) \ |
20 | | __ENUMERATE_DATA_TRANSFER_EFFECT(link) \ |
21 | | __ENUMERATE_DATA_TRANSFER_EFFECT(linkMove) \ |
22 | | __ENUMERATE_DATA_TRANSFER_EFFECT(move) \ |
23 | | __ENUMERATE_DATA_TRANSFER_EFFECT(all) \ |
24 | | __ENUMERATE_DATA_TRANSFER_EFFECT(uninitialized) |
25 | | |
26 | | namespace DataTransferEffect { |
27 | | |
28 | | #define __ENUMERATE_DATA_TRANSFER_EFFECT(name) extern FlyString name; |
29 | | ENUMERATE_DATA_TRANSFER_EFFECTS |
30 | | #undef __ENUMERATE_DATA_TRANSFER_EFFECT |
31 | | |
32 | | } |
33 | | |
34 | | // https://html.spec.whatwg.org/multipage/dnd.html#the-datatransfer-interface |
35 | | class DataTransfer : public Bindings::PlatformObject { |
36 | | WEB_PLATFORM_OBJECT(DataTransfer, Bindings::PlatformObject); |
37 | | JS_DECLARE_ALLOCATOR(DataTransfer); |
38 | | |
39 | | public: |
40 | | static JS::NonnullGCPtr<DataTransfer> create(JS::Realm&, NonnullRefPtr<DragDataStore>); |
41 | | static JS::NonnullGCPtr<DataTransfer> construct_impl(JS::Realm&); |
42 | | virtual ~DataTransfer() override; |
43 | | |
44 | 0 | FlyString const& drop_effect() const { return m_drop_effect; } |
45 | | void set_drop_effect(String const&); |
46 | | void set_drop_effect(FlyString); |
47 | | |
48 | 0 | FlyString const& effect_allowed() const { return m_effect_allowed; } |
49 | | void set_effect_allowed(String const&); |
50 | | void set_effect_allowed(FlyString); |
51 | | void set_effect_allowed_internal(FlyString); |
52 | | |
53 | | JS::NonnullGCPtr<DataTransferItemList> items(); |
54 | | |
55 | | ReadonlySpan<String> types() const; |
56 | | String get_data(String const& format) const; |
57 | | JS::NonnullGCPtr<FileAPI::FileList> files() const; |
58 | | |
59 | | Optional<DragDataStore::Mode> mode() const; |
60 | | void disassociate_with_drag_data_store(); |
61 | | |
62 | | JS::NonnullGCPtr<DataTransferItem> add_item(DragDataStoreItem item); |
63 | | bool contains_item_with_type(DragDataStoreItem::Kind, String const& type) const; |
64 | | JS::NonnullGCPtr<DataTransferItem> item(size_t index) const; |
65 | | DragDataStoreItem const& drag_data(size_t index) const; |
66 | | size_t length() const; |
67 | | |
68 | | private: |
69 | | DataTransfer(JS::Realm&, NonnullRefPtr<DragDataStore>); |
70 | | |
71 | | virtual void initialize(JS::Realm&) override; |
72 | | virtual void visit_edges(JS::Cell::Visitor&) override; |
73 | | |
74 | | void update_data_transfer_types_list(); |
75 | | |
76 | | // https://html.spec.whatwg.org/multipage/dnd.html#dom-datatransfer-dropeffect |
77 | | FlyString m_drop_effect { DataTransferEffect::none }; |
78 | | |
79 | | // https://html.spec.whatwg.org/multipage/dnd.html#dom-datatransfer-effectallowed |
80 | | FlyString m_effect_allowed { DataTransferEffect::none }; |
81 | | |
82 | | // https://html.spec.whatwg.org/multipage/dnd.html#dom-datatransfer-items |
83 | | JS::GCPtr<DataTransferItemList> m_items; |
84 | | Vector<JS::NonnullGCPtr<DataTransferItem>> m_item_list; |
85 | | |
86 | | // https://html.spec.whatwg.org/multipage/dnd.html#concept-datatransfer-types |
87 | | Vector<String> m_types; |
88 | | |
89 | | // https://html.spec.whatwg.org/multipage/dnd.html#the-datatransfer-interface:drag-data-store-3 |
90 | | RefPtr<DragDataStore> m_associated_drag_data_store; |
91 | | }; |
92 | | |
93 | | } |