ladybird/Userland/Libraries/LibWeb/Page/DragAndDropEventHandler.h
Timothy Flynn 541968b30d LibWeb+LibWebView+WebContent: Return a named enum from UI event handlers
UI event handlers currently return a boolean where false means the event
was cancelled by a script on the page, or otherwise dropped. It has been
a point of confusion for some time now, as it's not particularly clear
what should be returned in some special cases, or how the UI process
should handle the response.

This adds an enumeration with a few states that indicate exactly how the
WebContent process handled the event. This should remove all ambiguity,
and let us properly handle these states going forward.

There should be no behavior change with this patch. It's meant to only
introduce the enum, not change any of our decisions based on the result.
2024-09-12 17:38:36 -04:00

68 lines
2.8 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/Page/EventResult.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.is_null(); }
EventResult 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);
EventResult 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);
EventResult handle_drag_leave(JS::Realm&, CSSPixelPoint screen_position, CSSPixelPoint page_offset, CSSPixelPoint client_offset, CSSPixelPoint offset, unsigned button, unsigned buttons, unsigned modifiers);
EventResult 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,
};
EventResult 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();
RefPtr<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;
};
}