mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-09 17:49:40 +00:00
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.
This commit is contained in:
parent
a64d182583
commit
541968b30d
Notes:
github-actions[bot]
2024-09-12 21:39:29 +00:00
Author: https://github.com/trflynn89
Commit: 541968b30d
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1383
Reviewed-by: https://github.com/awesomekling ✅
15 changed files with 200 additions and 161 deletions
|
@ -23,7 +23,7 @@ void DragAndDropEventHandler::visit_edges(JS::Cell::Visitor& visitor) const
|
|||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/dnd.html#drag-and-drop-processing-model
|
||||
bool DragAndDropEventHandler::handle_drag_start(
|
||||
EventResult DragAndDropEventHandler::handle_drag_start(
|
||||
JS::Realm& realm,
|
||||
CSSPixelPoint screen_position,
|
||||
CSSPixelPoint page_offset,
|
||||
|
@ -154,7 +154,7 @@ bool DragAndDropEventHandler::handle_drag_start(
|
|||
// If the event is canceled, then the drag-and-drop operation should not occur; return.
|
||||
if (drag_event->cancelled()) {
|
||||
reset();
|
||||
return false;
|
||||
return EventResult::Cancelled;
|
||||
}
|
||||
|
||||
// FIXME: 10. Fire a pointer event at the source node named pointercancel, and fire any other follow-up events as
|
||||
|
@ -169,11 +169,11 @@ bool DragAndDropEventHandler::handle_drag_start(
|
|||
// as distances in CSS pixels from the left side and from the top side of the image respectively.
|
||||
// 2. The drag data store default feedback.
|
||||
|
||||
return true;
|
||||
return EventResult::Handled;
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/dnd.html#drag-and-drop-processing-model:queue-a-task
|
||||
bool DragAndDropEventHandler::handle_drag_move(
|
||||
EventResult DragAndDropEventHandler::handle_drag_move(
|
||||
JS::Realm& realm,
|
||||
JS::NonnullGCPtr<DOM::Document> document,
|
||||
JS::NonnullGCPtr<DOM::Node> node,
|
||||
|
@ -186,7 +186,7 @@ bool DragAndDropEventHandler::handle_drag_move(
|
|||
unsigned modifiers)
|
||||
{
|
||||
if (!has_ongoing_drag_and_drop_operation())
|
||||
return false;
|
||||
return EventResult::Cancelled;
|
||||
|
||||
auto fire_a_drag_and_drop_event = [&](JS::GCPtr<DOM::EventTarget> target, FlyString const& name, JS::GCPtr<DOM::EventTarget> related_target = nullptr) {
|
||||
return this->fire_a_drag_and_drop_event(realm, target, name, screen_position, page_offset, client_offset, offset, button, buttons, modifiers, related_target);
|
||||
|
@ -320,10 +320,10 @@ bool DragAndDropEventHandler::handle_drag_move(
|
|||
if (drag_event->cancelled())
|
||||
return handle_drag_end(realm, Cancelled::Yes, screen_position, page_offset, client_offset, offset, button, buttons, modifiers);
|
||||
|
||||
return true;
|
||||
return EventResult::Handled;
|
||||
}
|
||||
|
||||
bool DragAndDropEventHandler::handle_drag_leave(
|
||||
EventResult DragAndDropEventHandler::handle_drag_leave(
|
||||
JS::Realm& realm,
|
||||
CSSPixelPoint screen_position,
|
||||
CSSPixelPoint page_offset,
|
||||
|
@ -336,7 +336,7 @@ bool DragAndDropEventHandler::handle_drag_leave(
|
|||
return handle_drag_end(realm, Cancelled::Yes, screen_position, page_offset, client_offset, offset, button, buttons, modifiers);
|
||||
}
|
||||
|
||||
bool DragAndDropEventHandler::handle_drop(
|
||||
EventResult DragAndDropEventHandler::handle_drop(
|
||||
JS::Realm& realm,
|
||||
CSSPixelPoint screen_position,
|
||||
CSSPixelPoint page_offset,
|
||||
|
@ -350,7 +350,7 @@ bool DragAndDropEventHandler::handle_drop(
|
|||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/dnd.html#drag-and-drop-processing-model:event-dnd-drag-3
|
||||
bool DragAndDropEventHandler::handle_drag_end(
|
||||
EventResult DragAndDropEventHandler::handle_drag_end(
|
||||
JS::Realm& realm,
|
||||
Cancelled cancelled,
|
||||
CSSPixelPoint screen_position,
|
||||
|
@ -362,7 +362,7 @@ bool DragAndDropEventHandler::handle_drag_end(
|
|||
unsigned modifiers)
|
||||
{
|
||||
if (!has_ongoing_drag_and_drop_operation())
|
||||
return false;
|
||||
return EventResult::Cancelled;
|
||||
|
||||
auto fire_a_drag_and_drop_event = [&](JS::GCPtr<DOM::EventTarget> target, FlyString const& name, JS::GCPtr<DOM::EventTarget> related_target = nullptr) {
|
||||
return this->fire_a_drag_and_drop_event(realm, target, name, screen_position, page_offset, client_offset, offset, button, buttons, modifiers, related_target);
|
||||
|
@ -456,7 +456,7 @@ bool DragAndDropEventHandler::handle_drag_end(
|
|||
else if (!dropped || m_current_drag_operation == HTML::DataTransferEffect::none) {
|
||||
// The drag was canceled. If the platform conventions dictate that this be represented to the user (e.g. by
|
||||
// animating the dragged selection going back to the source of the drag-and-drop operation), then do so.
|
||||
return false;
|
||||
return EventResult::Cancelled;
|
||||
}
|
||||
// -> Otherwise
|
||||
else {
|
||||
|
@ -464,7 +464,7 @@ bool DragAndDropEventHandler::handle_drag_end(
|
|||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
return EventResult::Handled;
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/dnd.html#fire-a-dnd-event
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue