1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 10:48:11 +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

@ -93,6 +93,9 @@ Application::Application(int argc, char** argv)
if (getenv("GUI_FOCUS_DEBUG"))
m_focus_debugging_enabled = true;
if (getenv("GUI_DND_DEBUG"))
m_dnd_debugging_enabled = true;
for (int i = 1; i < argc; i++) {
String arg(argv[i]);
m_args.append(move(arg));
@ -247,21 +250,36 @@ void Application::window_did_become_inactive(Badge<Window>, Window& window)
m_active_window = nullptr;
}
void Application::set_pending_drop_widget(Widget* widget)
{
if (m_pending_drop_widget == widget)
return;
if (m_pending_drop_widget)
m_pending_drop_widget->update();
m_pending_drop_widget = widget;
if (m_pending_drop_widget)
m_pending_drop_widget->update();
}
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));
Event leave_event(Event::DragLeave);
m_drag_hovered_widget->dispatch_event(leave_event, m_drag_hovered_widget->window());
}
set_pending_drop_widget(nullptr);
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));
DragEvent enter_event(Event::DragEnter, position, mime_type);
enter_event.ignore();
m_drag_hovered_widget->dispatch_event(enter_event, m_drag_hovered_widget->window());
if (enter_event.is_accepted())
set_pending_drop_widget(m_drag_hovered_widget);
}
}