DragDataStore.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * Copyright (c) 2024, Tim Flynn <trflynn89@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/ByteBuffer.h>
  8. #include <AK/ByteString.h>
  9. #include <AK/FlyString.h>
  10. #include <AK/NonnullRefPtr.h>
  11. #include <AK/RefCounted.h>
  12. #include <AK/String.h>
  13. #include <AK/Vector.h>
  14. #include <LibGfx/Bitmap.h>
  15. #include <LibGfx/Point.h>
  16. namespace Web::HTML {
  17. struct DragDataStoreItem {
  18. enum class Kind {
  19. Text,
  20. File,
  21. };
  22. // https://html.spec.whatwg.org/multipage/dnd.html#the-drag-data-item-kind
  23. Kind kind { Kind::Text };
  24. // https://html.spec.whatwg.org/multipage/dnd.html#the-drag-data-item-type-string
  25. String type_string;
  26. ByteBuffer data;
  27. ByteString file_name;
  28. };
  29. // https://html.spec.whatwg.org/multipage/dnd.html#drag-data-store
  30. class DragDataStore : public RefCounted<DragDataStore> {
  31. public:
  32. enum class Mode {
  33. ReadWrite,
  34. ReadOnly,
  35. Protected,
  36. };
  37. static NonnullRefPtr<DragDataStore> create();
  38. ~DragDataStore();
  39. void add_item(DragDataStoreItem item) { m_item_list.append(move(item)); }
  40. ReadonlySpan<DragDataStoreItem> item_list() const { return m_item_list; }
  41. size_t size() const { return m_item_list.size(); }
  42. bool has_text_item() const;
  43. Mode mode() const { return m_mode; }
  44. void set_mode(Mode mode) { m_mode = mode; }
  45. FlyString allowed_effects_state() const { return m_allowed_effects_state; }
  46. void set_allowed_effects_state(FlyString allowed_effects_state) { m_allowed_effects_state = move(allowed_effects_state); }
  47. private:
  48. DragDataStore();
  49. // https://html.spec.whatwg.org/multipage/dnd.html#drag-data-store-item-list
  50. Vector<DragDataStoreItem> m_item_list;
  51. // https://html.spec.whatwg.org/multipage/dnd.html#drag-data-store-default-feedback
  52. String m_default_feedback;
  53. // https://html.spec.whatwg.org/multipage/dnd.html#drag-data-store-bitmap
  54. RefPtr<Gfx::Bitmap> m_bitmap;
  55. // https://html.spec.whatwg.org/multipage/dnd.html#drag-data-store-hot-spot-coordinate
  56. Gfx::IntPoint m_hot_spot_coordinate;
  57. // https://html.spec.whatwg.org/multipage/dnd.html#drag-data-store-mode
  58. Mode m_mode { Mode::Protected };
  59. // https://html.spec.whatwg.org/multipage/dnd.html#drag-data-store-allowed-effects-state
  60. FlyString m_allowed_effects_state;
  61. };
  62. }