1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 11:38:11 +00:00

LibGUI: Add "drag enter" and "drag leave" events

These events allow widgets to react when a drag enters/leaves their
rectangle. The enter event carries position + mime type, while the
leave event has no information.
This commit is contained in:
Andreas Kling 2021-01-08 22:23:06 +01:00
parent 4728d0dd6a
commit 9acb72e804
7 changed files with 60 additions and 3 deletions

View file

@ -247,4 +247,27 @@ void Application::window_did_become_inactive(Badge<Window>, Window& window)
m_active_window = nullptr;
}
void Application::set_drag_hovered_widget_impl(Widget* widget, const Gfx::IntPoint& position, const String& mime_type)
{
if (widget == m_drag_hovered_widget)
return;
if (m_drag_hovered_widget) {
m_drag_hovered_widget->update();
Core::EventLoop::current().post_event(*m_drag_hovered_widget, make<Event>(Event::DragLeave));
}
m_drag_hovered_widget = widget;
if (m_drag_hovered_widget) {
m_drag_hovered_widget->update();
Core::EventLoop::current().post_event(*m_drag_hovered_widget, make<DragEvent>(Event::DragEnter, position, mime_type));
}
}
void Application::notify_drag_cancelled(Badge<WindowServerConnection>)
{
set_drag_hovered_widget_impl(nullptr);
}
}