mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
LibWeb: Begin implementing the drag data store
This commit is contained in:
parent
dcb76572e4
commit
9e98e63559
Notes:
github-actions[bot]
2024-08-19 11:30:55 +00:00
Author: https://github.com/trflynn89 Commit: https://github.com/LadybirdBrowser/ladybird/commit/9e98e63559e Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1111
4 changed files with 108 additions and 0 deletions
|
@ -284,6 +284,7 @@ set(SOURCES
|
|||
HTML/DOMParser.cpp
|
||||
HTML/DOMStringList.cpp
|
||||
HTML/DOMStringMap.cpp
|
||||
HTML/DragDataStore.cpp
|
||||
HTML/DragEvent.cpp
|
||||
HTML/ElementInternals.cpp
|
||||
HTML/EmbedderPolicy.cpp
|
||||
|
|
|
@ -360,6 +360,7 @@ class DocumentState;
|
|||
class DOMParser;
|
||||
class DOMStringList;
|
||||
class DOMStringMap;
|
||||
class DragDataStore;
|
||||
class DragEvent;
|
||||
class ElementInternals;
|
||||
struct EmbedderPolicy;
|
||||
|
|
29
Userland/Libraries/LibWeb/HTML/DragDataStore.cpp
Normal file
29
Userland/Libraries/LibWeb/HTML/DragDataStore.cpp
Normal file
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* Copyright (c) 2024, Tim Flynn <trflynn89@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibWeb/HTML/DataTransfer.h>
|
||||
#include <LibWeb/HTML/DragDataStore.h>
|
||||
|
||||
namespace Web::HTML {
|
||||
|
||||
DragDataStore::DragDataStore()
|
||||
: m_allowed_effects_state(DataTransferEffect::uninitialized)
|
||||
{
|
||||
}
|
||||
|
||||
DragDataStore::~DragDataStore() = default;
|
||||
|
||||
bool DragDataStore::has_text_item() const
|
||||
{
|
||||
for (auto const& item : m_item_list) {
|
||||
if (item.kind == DragDataStoreItem::Kind::Text && item.type_string == "text/plain"sv)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
77
Userland/Libraries/LibWeb/HTML/DragDataStore.h
Normal file
77
Userland/Libraries/LibWeb/HTML/DragDataStore.h
Normal file
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
* 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>
|
||||
#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
|
||||
class DragDataStore {
|
||||
public:
|
||||
enum class Mode {
|
||||
ReadWrite,
|
||||
ReadOnly,
|
||||
Protected,
|
||||
};
|
||||
|
||||
DragDataStore();
|
||||
~DragDataStore();
|
||||
|
||||
void add_item(DragDataStoreItem item) { m_item_list.append(move(item)); }
|
||||
ReadonlySpan<DragDataStoreItem> item_list() const { return m_item_list; }
|
||||
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:
|
||||
// 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;
|
||||
};
|
||||
|
||||
}
|
Loading…
Reference in a new issue