| 
									
										
										
										
											2024-03-13 15:35:39 -04:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Copyright (c) 2024, Tim Flynn <trflynn89@serenityos.org> | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <LibJS/Forward.h>
 | 
					
						
							|  |  |  | #include <LibWeb/Bindings/PlatformObject.h>
 | 
					
						
							| 
									
										
										
										
											2024-08-16 13:40:56 -04:00
										 |  |  | #include <LibWeb/HTML/DragDataStore.h>
 | 
					
						
							| 
									
										
										
										
											2024-03-13 15:35:39 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace Web::HTML { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-16 13:40:56 -04:00
										 |  |  | #define ENUMERATE_DATA_TRANSFER_EFFECTS        \
 | 
					
						
							|  |  |  |     __ENUMERATE_DATA_TRANSFER_EFFECT(none)     \ | 
					
						
							|  |  |  |     __ENUMERATE_DATA_TRANSFER_EFFECT(copy)     \ | 
					
						
							|  |  |  |     __ENUMERATE_DATA_TRANSFER_EFFECT(copyLink) \ | 
					
						
							|  |  |  |     __ENUMERATE_DATA_TRANSFER_EFFECT(copyMove) \ | 
					
						
							|  |  |  |     __ENUMERATE_DATA_TRANSFER_EFFECT(link)     \ | 
					
						
							|  |  |  |     __ENUMERATE_DATA_TRANSFER_EFFECT(linkMove) \ | 
					
						
							|  |  |  |     __ENUMERATE_DATA_TRANSFER_EFFECT(move)     \ | 
					
						
							|  |  |  |     __ENUMERATE_DATA_TRANSFER_EFFECT(all)      \ | 
					
						
							|  |  |  |     __ENUMERATE_DATA_TRANSFER_EFFECT(uninitialized) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace DataTransferEffect { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define __ENUMERATE_DATA_TRANSFER_EFFECT(name) extern FlyString name;
 | 
					
						
							|  |  |  | ENUMERATE_DATA_TRANSFER_EFFECTS | 
					
						
							|  |  |  | #undef __ENUMERATE_DATA_TRANSFER_EFFECT
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // https://html.spec.whatwg.org/multipage/dnd.html#the-datatransfer-interface
 | 
					
						
							| 
									
										
										
										
											2024-03-13 15:35:39 -04:00
										 |  |  | class DataTransfer : public Bindings::PlatformObject { | 
					
						
							|  |  |  |     WEB_PLATFORM_OBJECT(DataTransfer, Bindings::PlatformObject); | 
					
						
							| 
									
										
										
										
											2024-11-15 04:01:23 +13:00
										 |  |  |     GC_DECLARE_ALLOCATOR(DataTransfer); | 
					
						
							| 
									
										
										
										
											2024-03-13 15:35:39 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | public: | 
					
						
							| 
									
										
										
										
											2024-11-15 04:01:23 +13:00
										 |  |  |     static GC::Ref<DataTransfer> create(JS::Realm&, NonnullRefPtr<DragDataStore>); | 
					
						
							|  |  |  |     static GC::Ref<DataTransfer> construct_impl(JS::Realm&); | 
					
						
							| 
									
										
										
										
											2024-03-13 15:35:39 -04:00
										 |  |  |     virtual ~DataTransfer() override; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-16 13:40:56 -04:00
										 |  |  |     FlyString const& drop_effect() const { return m_drop_effect; } | 
					
						
							|  |  |  |     void set_drop_effect(String const&); | 
					
						
							|  |  |  |     void set_drop_effect(FlyString); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     FlyString const& effect_allowed() const { return m_effect_allowed; } | 
					
						
							|  |  |  |     void set_effect_allowed(String const&); | 
					
						
							|  |  |  |     void set_effect_allowed(FlyString); | 
					
						
							|  |  |  |     void set_effect_allowed_internal(FlyString); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-15 04:01:23 +13:00
										 |  |  |     GC::Ref<DataTransferItemList> items(); | 
					
						
							| 
									
										
										
										
											2024-08-20 18:44:22 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-17 14:23:13 -04:00
										 |  |  |     ReadonlySpan<String> types() const; | 
					
						
							| 
									
										
										
										
											2024-08-20 18:29:00 -04:00
										 |  |  |     String get_data(String const& format) const; | 
					
						
							| 
									
										
										
										
											2024-11-15 04:01:23 +13:00
										 |  |  |     GC::Ref<FileAPI::FileList> files() const; | 
					
						
							| 
									
										
										
										
											2024-08-17 14:44:26 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-21 09:35:25 -04:00
										 |  |  |     Optional<DragDataStore::Mode> mode() const; | 
					
						
							| 
									
										
										
										
											2024-08-17 14:23:13 -04:00
										 |  |  |     void disassociate_with_drag_data_store(); | 
					
						
							| 
									
										
										
										
											2024-08-16 13:40:56 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-15 04:01:23 +13:00
										 |  |  |     GC::Ref<DataTransferItem> add_item(DragDataStoreItem item); | 
					
						
							| 
									
										
										
										
											2024-08-21 09:35:25 -04:00
										 |  |  |     bool contains_item_with_type(DragDataStoreItem::Kind, String const& type) const; | 
					
						
							| 
									
										
										
										
											2024-11-15 04:01:23 +13:00
										 |  |  |     GC::Ref<DataTransferItem> item(size_t index) const; | 
					
						
							| 
									
										
										
										
											2024-08-21 10:24:45 -04:00
										 |  |  |     DragDataStoreItem const& drag_data(size_t index) const; | 
					
						
							| 
									
										
										
										
											2024-08-21 09:45:04 -04:00
										 |  |  |     size_t length() const; | 
					
						
							| 
									
										
										
										
											2024-08-21 09:35:25 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-13 15:35:39 -04:00
										 |  |  | private: | 
					
						
							| 
									
										
										
										
											2024-08-21 06:50:22 -04:00
										 |  |  |     DataTransfer(JS::Realm&, NonnullRefPtr<DragDataStore>); | 
					
						
							| 
									
										
										
										
											2024-03-13 15:35:39 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     virtual void initialize(JS::Realm&) override; | 
					
						
							| 
									
										
										
										
											2024-08-20 18:44:22 -04:00
										 |  |  |     virtual void visit_edges(JS::Cell::Visitor&) override; | 
					
						
							| 
									
										
										
										
											2024-08-16 13:40:56 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-17 14:23:13 -04:00
										 |  |  |     void update_data_transfer_types_list(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-16 13:40:56 -04:00
										 |  |  |     // https://html.spec.whatwg.org/multipage/dnd.html#dom-datatransfer-dropeffect
 | 
					
						
							|  |  |  |     FlyString m_drop_effect { DataTransferEffect::none }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // https://html.spec.whatwg.org/multipage/dnd.html#dom-datatransfer-effectallowed
 | 
					
						
							|  |  |  |     FlyString m_effect_allowed { DataTransferEffect::none }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-20 18:44:22 -04:00
										 |  |  |     // https://html.spec.whatwg.org/multipage/dnd.html#dom-datatransfer-items
 | 
					
						
							| 
									
										
										
										
											2024-11-15 04:01:23 +13:00
										 |  |  |     GC::Ptr<DataTransferItemList> m_items; | 
					
						
							|  |  |  |     Vector<GC::Ref<DataTransferItem>> m_item_list; | 
					
						
							| 
									
										
										
										
											2024-08-20 18:44:22 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-17 14:23:13 -04:00
										 |  |  |     // https://html.spec.whatwg.org/multipage/dnd.html#concept-datatransfer-types
 | 
					
						
							|  |  |  |     Vector<String> m_types; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-16 13:40:56 -04:00
										 |  |  |     // https://html.spec.whatwg.org/multipage/dnd.html#the-datatransfer-interface:drag-data-store-3
 | 
					
						
							| 
									
										
										
										
											2024-08-21 06:39:02 -04:00
										 |  |  |     RefPtr<DragDataStore> m_associated_drag_data_store; | 
					
						
							| 
									
										
										
										
											2024-03-13 15:35:39 -04:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |