DataTransfer.h 3.1 KB

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