ladybird/Userland/Libraries/LibWeb/Page/DragAndDropEventHandler.h
Timothy Flynn e8a1b89447 LibWeb: Begin implementing the drag-and-drop processing model
The drag-and-drop processing model allows for users to drag around
either elements within the DOM or objects completely outside the DOM.
This drag event can either end without action (via cancellation or user
input), or in a drop event, where the dragged object is dropped onto
another element within the DOM.

The processing model is rather large. This implements enough of it to
allow the UI process to specifically handle dragging objects outside of
the DOM onto the DOM. For example, dragging an image from the OS file
manager onto a file-upload input element. This does not implement the
ability to drag DOM elements.
2024-08-19 13:29:19 +02:00

67 lines
2.7 KiB
C++

/*
* Copyright (c) 2024, Tim Flynn <trflynn89@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibJS/Heap/Cell.h>
#include <LibJS/Heap/GCPtr.h>
#include <LibWeb/Forward.h>
#include <LibWeb/HTML/DragDataStore.h>
#include <LibWeb/PixelUnits.h>
namespace Web {
class DragAndDropEventHandler {
public:
void visit_edges(JS::Cell::Visitor& visitor) const;
bool has_ongoing_drag_and_drop_operation() const { return m_drag_data_store.has_value(); }
bool handle_drag_start(JS::Realm&, CSSPixelPoint screen_position, CSSPixelPoint page_offset, CSSPixelPoint client_offset, CSSPixelPoint offset, unsigned button, unsigned buttons, unsigned modifiers, Vector<HTML::SelectedFile> files);
bool handle_drag_move(JS::Realm&, JS::NonnullGCPtr<DOM::Document>, JS::NonnullGCPtr<DOM::Node>, CSSPixelPoint screen_position, CSSPixelPoint page_offset, CSSPixelPoint client_offset, CSSPixelPoint offset, unsigned button, unsigned buttons, unsigned modifiers);
bool handle_drag_leave(JS::Realm&, CSSPixelPoint screen_position, CSSPixelPoint page_offset, CSSPixelPoint client_offset, CSSPixelPoint offset, unsigned button, unsigned buttons, unsigned modifiers);
bool handle_drop(JS::Realm&, CSSPixelPoint screen_position, CSSPixelPoint page_offset, CSSPixelPoint client_offset, CSSPixelPoint offset, unsigned button, unsigned buttons, unsigned modifiers);
private:
enum class Cancelled {
No,
Yes,
};
bool handle_drag_end(JS::Realm&, Cancelled, CSSPixelPoint screen_position, CSSPixelPoint page_offset, CSSPixelPoint client_offset, CSSPixelPoint offset, unsigned button, unsigned buttons, unsigned modifiers);
JS::NonnullGCPtr<HTML::DragEvent> fire_a_drag_and_drop_event(
JS::Realm&,
JS::GCPtr<DOM::EventTarget> target,
FlyString const& name,
CSSPixelPoint screen_position,
CSSPixelPoint page_offset,
CSSPixelPoint client_offset,
CSSPixelPoint offset,
unsigned button,
unsigned buttons,
unsigned modifiers,
JS::GCPtr<DOM::EventTarget> related_target = nullptr);
bool allow_text_drop(JS::NonnullGCPtr<DOM::Node>) const;
void reset();
Optional<HTML::DragDataStore> m_drag_data_store;
// https://html.spec.whatwg.org/multipage/dnd.html#source-node
JS::GCPtr<DOM::EventTarget> m_source_node;
// https://html.spec.whatwg.org/multipage/dnd.html#immediate-user-selection
JS::GCPtr<DOM::Node> m_immediate_user_selection;
// https://html.spec.whatwg.org/multipage/dnd.html#current-target-element
JS::GCPtr<DOM::Node> m_current_target_element;
// https://html.spec.whatwg.org/multipage/dnd.html#current-drag-operation
FlyString m_current_drag_operation;
};
}