| 
									
										
										
										
											2024-08-16 13:31:42 -04:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Copyright (c) 2024, Tim Flynn <trflynn89@serenityos.org> | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <AK/ByteBuffer.h>
 | 
					
						
							|  |  |  | #include <AK/ByteString.h>
 | 
					
						
							|  |  |  | #include <AK/FlyString.h>
 | 
					
						
							| 
									
										
										
										
											2024-08-21 06:39:02 -04:00
										 |  |  | #include <AK/NonnullRefPtr.h>
 | 
					
						
							|  |  |  | #include <AK/RefCounted.h>
 | 
					
						
							| 
									
										
										
										
											2024-08-16 13:31:42 -04:00
										 |  |  | #include <AK/String.h>
 | 
					
						
							|  |  |  | #include <AK/Vector.h>
 | 
					
						
							|  |  |  | #include <LibGfx/Bitmap.h>
 | 
					
						
							|  |  |  | #include <LibGfx/Point.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace Web::HTML { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | struct DragDataStoreItem { | 
					
						
							|  |  |  |     enum class Kind { | 
					
						
							|  |  |  |         Text, | 
					
						
							|  |  |  |         File, | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // https://html.spec.whatwg.org/multipage/dnd.html#the-drag-data-item-kind
 | 
					
						
							|  |  |  |     Kind kind { Kind::Text }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // https://html.spec.whatwg.org/multipage/dnd.html#the-drag-data-item-type-string
 | 
					
						
							|  |  |  |     String type_string; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ByteBuffer data; | 
					
						
							|  |  |  |     ByteString file_name; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // https://html.spec.whatwg.org/multipage/dnd.html#drag-data-store
 | 
					
						
							| 
									
										
										
										
											2024-08-21 06:39:02 -04:00
										 |  |  | class DragDataStore : public RefCounted<DragDataStore> { | 
					
						
							| 
									
										
										
										
											2024-08-16 13:31:42 -04:00
										 |  |  | public: | 
					
						
							|  |  |  |     enum class Mode { | 
					
						
							|  |  |  |         ReadWrite, | 
					
						
							|  |  |  |         ReadOnly, | 
					
						
							|  |  |  |         Protected, | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-21 06:39:02 -04:00
										 |  |  |     static NonnullRefPtr<DragDataStore> create(); | 
					
						
							| 
									
										
										
										
											2024-08-16 13:31:42 -04:00
										 |  |  |     ~DragDataStore(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     void add_item(DragDataStoreItem item) { m_item_list.append(move(item)); } | 
					
						
							|  |  |  |     ReadonlySpan<DragDataStoreItem> item_list() const { return m_item_list; } | 
					
						
							| 
									
										
										
										
											2024-08-21 09:45:04 -04:00
										 |  |  |     size_t size() const { return m_item_list.size(); } | 
					
						
							| 
									
										
										
										
											2024-08-16 13:31:42 -04:00
										 |  |  |     bool has_text_item() const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     Mode mode() const { return m_mode; } | 
					
						
							|  |  |  |     void set_mode(Mode mode) { m_mode = mode; } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     FlyString allowed_effects_state() const { return m_allowed_effects_state; } | 
					
						
							|  |  |  |     void set_allowed_effects_state(FlyString allowed_effects_state) { m_allowed_effects_state = move(allowed_effects_state); } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							| 
									
										
										
										
											2024-08-21 06:39:02 -04:00
										 |  |  |     DragDataStore(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-16 13:31:42 -04:00
										 |  |  |     // https://html.spec.whatwg.org/multipage/dnd.html#drag-data-store-item-list
 | 
					
						
							|  |  |  |     Vector<DragDataStoreItem> m_item_list; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // https://html.spec.whatwg.org/multipage/dnd.html#drag-data-store-default-feedback
 | 
					
						
							|  |  |  |     String m_default_feedback; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // https://html.spec.whatwg.org/multipage/dnd.html#drag-data-store-bitmap
 | 
					
						
							|  |  |  |     RefPtr<Gfx::Bitmap> m_bitmap; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // https://html.spec.whatwg.org/multipage/dnd.html#drag-data-store-hot-spot-coordinate
 | 
					
						
							|  |  |  |     Gfx::IntPoint m_hot_spot_coordinate; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // https://html.spec.whatwg.org/multipage/dnd.html#drag-data-store-mode
 | 
					
						
							|  |  |  |     Mode m_mode { Mode::Protected }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // https://html.spec.whatwg.org/multipage/dnd.html#drag-data-store-allowed-effects-state
 | 
					
						
							|  |  |  |     FlyString m_allowed_effects_state; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |