/src/serenity/Userland/Libraries/LibWeb/HTML/DragDataStore.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 <AK/ByteBuffer.h> |
10 | | #include <AK/ByteString.h> |
11 | | #include <AK/FlyString.h> |
12 | | #include <AK/NonnullRefPtr.h> |
13 | | #include <AK/RefCounted.h> |
14 | | #include <AK/String.h> |
15 | | #include <AK/Vector.h> |
16 | | #include <LibGfx/Bitmap.h> |
17 | | #include <LibGfx/Point.h> |
18 | | |
19 | | namespace Web::HTML { |
20 | | |
21 | | struct DragDataStoreItem { |
22 | | enum class Kind { |
23 | | Text, |
24 | | File, |
25 | | }; |
26 | | |
27 | | // https://html.spec.whatwg.org/multipage/dnd.html#the-drag-data-item-kind |
28 | | Kind kind { Kind::Text }; |
29 | | |
30 | | // https://html.spec.whatwg.org/multipage/dnd.html#the-drag-data-item-type-string |
31 | | String type_string; |
32 | | |
33 | | ByteBuffer data; |
34 | | ByteString file_name; |
35 | | }; |
36 | | |
37 | | // https://html.spec.whatwg.org/multipage/dnd.html#drag-data-store |
38 | | class DragDataStore : public RefCounted<DragDataStore> { |
39 | | public: |
40 | | enum class Mode { |
41 | | ReadWrite, |
42 | | ReadOnly, |
43 | | Protected, |
44 | | }; |
45 | | |
46 | | static NonnullRefPtr<DragDataStore> create(); |
47 | | ~DragDataStore(); |
48 | | |
49 | 0 | void add_item(DragDataStoreItem item) { m_item_list.append(move(item)); } |
50 | 0 | ReadonlySpan<DragDataStoreItem> item_list() const { return m_item_list; } |
51 | 0 | size_t size() const { return m_item_list.size(); } |
52 | | bool has_text_item() const; |
53 | | |
54 | 0 | Mode mode() const { return m_mode; } |
55 | 0 | void set_mode(Mode mode) { m_mode = mode; } |
56 | | |
57 | 0 | FlyString allowed_effects_state() const { return m_allowed_effects_state; } |
58 | 0 | void set_allowed_effects_state(FlyString allowed_effects_state) { m_allowed_effects_state = move(allowed_effects_state); } |
59 | | |
60 | | private: |
61 | | DragDataStore(); |
62 | | |
63 | | // https://html.spec.whatwg.org/multipage/dnd.html#drag-data-store-item-list |
64 | | Vector<DragDataStoreItem> m_item_list; |
65 | | |
66 | | // https://html.spec.whatwg.org/multipage/dnd.html#drag-data-store-default-feedback |
67 | | String m_default_feedback; |
68 | | |
69 | | // https://html.spec.whatwg.org/multipage/dnd.html#drag-data-store-bitmap |
70 | | RefPtr<Gfx::Bitmap> m_bitmap; |
71 | | |
72 | | // https://html.spec.whatwg.org/multipage/dnd.html#drag-data-store-hot-spot-coordinate |
73 | | Gfx::IntPoint m_hot_spot_coordinate; |
74 | | |
75 | | // https://html.spec.whatwg.org/multipage/dnd.html#drag-data-store-mode |
76 | | Mode m_mode { Mode::Protected }; |
77 | | |
78 | | // https://html.spec.whatwg.org/multipage/dnd.html#drag-data-store-allowed-effects-state |
79 | | FlyString m_allowed_effects_state; |
80 | | }; |
81 | | |
82 | | } |