1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-24 22:17:42 +00:00

LibGUI: Have widgets signal willingness to accept drops

If a widget accept()'s a "drag enter" event, that widget now becomes
the application-wide "pending drop" widget. That state is cleared if
the drag moves over another widget (or leaves the window entirely.)
This commit is contained in:
Andreas Kling 2021-01-09 00:11:17 +01:00
parent dbd090fd95
commit 3b94af2c07
5 changed files with 60 additions and 19 deletions

View file

@ -444,10 +444,18 @@ void Window::handle_drag_move_event(DragEvent& event)
if (!m_main_widget)
return;
auto result = m_main_widget->hit_test(event.position());
auto local_event = make<DragEvent>(static_cast<Event::Type>(event.type()), result.local_position, event.data_type());
ASSERT(result.widget);
Application::the()->set_drag_hovered_widget({}, result.widget, result.local_position, event.data_type());
return result.widget->dispatch_event(*local_event, this);
// NOTE: Setting the drag hovered widget may have executed arbitrary code, so re-check that the widget is still there.
if (!result.widget)
return;
if (result.widget->has_pending_drop()) {
DragEvent drag_move_event(static_cast<Event::Type>(event.type()), result.local_position, event.data_type());
result.widget->dispatch_event(drag_move_event, this);
}
}
void Window::handle_left_event()