diff --git a/Userland/Applications/3DFileViewer/main.cpp b/Userland/Applications/3DFileViewer/main.cpp index 38db0042761..a048d2d9299 100644 --- a/Userland/Applications/3DFileViewer/main.cpp +++ b/Userland/Applications/3DFileViewer/main.cpp @@ -131,8 +131,7 @@ private: void GLContextWidget::drag_enter_event(GUI::DragEvent& event) { - auto const& mime_types = event.mime_types(); - if (mime_types.contains_slow("text/uri-list"sv)) + if (event.mime_data().has_urls()) event.accept(); } diff --git a/Userland/Applications/FontEditor/MainWidget.cpp b/Userland/Applications/FontEditor/MainWidget.cpp index d973bd1a97f..7ad30b4e1fc 100644 --- a/Userland/Applications/FontEditor/MainWidget.cpp +++ b/Userland/Applications/FontEditor/MainWidget.cpp @@ -992,8 +992,7 @@ void MainWidget::update_preview() void MainWidget::drag_enter_event(GUI::DragEvent& event) { - auto const& mime_types = event.mime_types(); - if (mime_types.contains_slow("text/uri-list"sv)) + if (event.mime_data().has_urls()) event.accept(); } diff --git a/Userland/Applications/HexEditor/HexEditorWidget.cpp b/Userland/Applications/HexEditor/HexEditorWidget.cpp index 8be9005c90c..6a0c9ffe2b5 100644 --- a/Userland/Applications/HexEditor/HexEditorWidget.cpp +++ b/Userland/Applications/HexEditor/HexEditorWidget.cpp @@ -833,8 +833,7 @@ void HexEditorWidget::set_value_inspector_visible(bool visible) void HexEditorWidget::drag_enter_event(GUI::DragEvent& event) { - auto const& mime_types = event.mime_types(); - if (mime_types.contains_slow("text/uri-list"sv)) + if (event.mime_data().has_urls()) event.accept(); } diff --git a/Userland/Applications/ImageViewer/ViewWidget.cpp b/Userland/Applications/ImageViewer/ViewWidget.cpp index bcdb2755f27..94b23d55020 100644 --- a/Userland/Applications/ImageViewer/ViewWidget.cpp +++ b/Userland/Applications/ImageViewer/ViewWidget.cpp @@ -283,8 +283,7 @@ ErrorOr ViewWidget::try_open_file(String const& path, Core::File& file) void ViewWidget::drag_enter_event(GUI::DragEvent& event) { - auto const& mime_types = event.mime_types(); - if (mime_types.contains_slow("text/uri-list"sv)) + if (event.mime_data().has_urls()) event.accept(); } diff --git a/Userland/Applications/PDFViewer/PDFViewerWidget.cpp b/Userland/Applications/PDFViewer/PDFViewerWidget.cpp index f0b61c1d4a0..6402f2f7521 100644 --- a/Userland/Applications/PDFViewer/PDFViewerWidget.cpp +++ b/Userland/Applications/PDFViewer/PDFViewerWidget.cpp @@ -523,8 +523,7 @@ PDF::PDFErrorOr PDFViewerWidget::try_open_file(StringView path, NonnullOwn void PDFViewerWidget::drag_enter_event(GUI::DragEvent& event) { - auto const& mime_types = event.mime_types(); - if (mime_types.contains_slow("text/uri-list"sv)) + if (event.mime_data().has_urls()) event.accept(); } diff --git a/Userland/Applications/PixelPaint/MainWidget.cpp b/Userland/Applications/PixelPaint/MainWidget.cpp index f0a415e314b..7deaad4716d 100644 --- a/Userland/Applications/PixelPaint/MainWidget.cpp +++ b/Userland/Applications/PixelPaint/MainWidget.cpp @@ -1492,8 +1492,7 @@ ImageEditor& MainWidget::create_new_editor(NonnullRefPtr image) void MainWidget::drag_enter_event(GUI::DragEvent& event) { - auto const& mime_types = event.mime_types(); - if (mime_types.contains_slow("text/uri-list"sv)) + if (event.mime_data().has_urls()) event.accept(); } diff --git a/Userland/Applications/Presenter/PresenterWidget.cpp b/Userland/Applications/Presenter/PresenterWidget.cpp index b7b2981b8ba..cf6380dea38 100644 --- a/Userland/Applications/Presenter/PresenterWidget.cpp +++ b/Userland/Applications/Presenter/PresenterWidget.cpp @@ -205,8 +205,7 @@ void PresenterWidget::second_paint_event(GUI::PaintEvent& event) void PresenterWidget::drag_enter_event(GUI::DragEvent& event) { - auto const& mime_types = event.mime_types(); - if (mime_types.contains_slow("text/uri-list"sv)) + if (event.mime_data().has_urls()) event.accept(); } diff --git a/Userland/Applications/SoundPlayer/SoundPlayerWidget.cpp b/Userland/Applications/SoundPlayer/SoundPlayerWidget.cpp index 2b20af6f802..d13af63600f 100644 --- a/Userland/Applications/SoundPlayer/SoundPlayerWidget.cpp +++ b/Userland/Applications/SoundPlayer/SoundPlayerWidget.cpp @@ -147,8 +147,7 @@ void SoundPlayerWidget::set_nonlinear_volume_slider(bool nonlinear) void SoundPlayerWidget::drag_enter_event(GUI::DragEvent& event) { - auto const& mime_types = event.mime_types(); - if (mime_types.contains_slow("text/uri-list"sv)) + if (event.mime_data().has_urls()) event.accept(); } diff --git a/Userland/Applications/TextEditor/MainWidget.cpp b/Userland/Applications/TextEditor/MainWidget.cpp index a93da249be4..d64f15b103c 100644 --- a/Userland/Applications/TextEditor/MainWidget.cpp +++ b/Userland/Applications/TextEditor/MainWidget.cpp @@ -835,8 +835,7 @@ bool MainWidget::request_close() void MainWidget::drag_enter_event(GUI::DragEvent& event) { - auto const& mime_types = event.mime_types(); - if (mime_types.contains_slow("text/uri-list"sv)) + if (event.mime_data().has_urls()) event.accept(); } diff --git a/Userland/Applications/ThemeEditor/MainWidget.cpp b/Userland/Applications/ThemeEditor/MainWidget.cpp index 386b7e45098..5a2a1859b32 100644 --- a/Userland/Applications/ThemeEditor/MainWidget.cpp +++ b/Userland/Applications/ThemeEditor/MainWidget.cpp @@ -682,8 +682,7 @@ ErrorOr MainWidget::load_from_file(ByteString const& filename, NonnullOwnP void MainWidget::drag_enter_event(GUI::DragEvent& event) { - auto const& mime_types = event.mime_types(); - if (mime_types.contains_slow("text/uri-list"sv)) + if (event.mime_data().has_urls()) event.accept(); } diff --git a/Userland/DevTools/GMLPlayground/MainWidget.cpp b/Userland/DevTools/GMLPlayground/MainWidget.cpp index 9b286d60e7f..3a53c1e2b6d 100644 --- a/Userland/DevTools/GMLPlayground/MainWidget.cpp +++ b/Userland/DevTools/GMLPlayground/MainWidget.cpp @@ -320,8 +320,7 @@ GUI::Window::CloseRequestDecision MainWidget::request_close() void MainWidget::drag_enter_event(GUI::DragEvent& event) { - auto const& mime_types = event.mime_types(); - if (mime_types.contains_slow("text/uri-list"sv)) + if (event.mime_data().has_urls()) event.accept(); } diff --git a/Userland/DevTools/HackStudio/Editor.cpp b/Userland/DevTools/HackStudio/Editor.cpp index bc3d9c9f51a..73bee0144ed 100644 --- a/Userland/DevTools/HackStudio/Editor.cpp +++ b/Userland/DevTools/HackStudio/Editor.cpp @@ -346,8 +346,7 @@ void Editor::mousedown_event(GUI::MouseEvent& event) void Editor::drag_enter_event(GUI::DragEvent& event) { - auto const& mime_types = event.mime_types(); - if (mime_types.contains_slow("text/uri-list"sv)) + if (event.mime_data().has_urls()) event.accept(); } diff --git a/Userland/DevTools/SQLStudio/MainWidget.cpp b/Userland/DevTools/SQLStudio/MainWidget.cpp index fe844c13a91..d46f4fa1b9d 100644 --- a/Userland/DevTools/SQLStudio/MainWidget.cpp +++ b/Userland/DevTools/SQLStudio/MainWidget.cpp @@ -463,8 +463,7 @@ void MainWidget::update_editor_actions(ScriptEditor* editor) void MainWidget::drag_enter_event(GUI::DragEvent& event) { - auto const& mime_types = event.mime_types(); - if (mime_types.contains_slow("text/uri-list"sv)) + if (event.mime_data().has_urls()) event.accept(); } diff --git a/Userland/Libraries/LibGUI/AbstractView.cpp b/Userland/Libraries/LibGUI/AbstractView.cpp index fe60e404fc6..fe6ede99348 100644 --- a/Userland/Libraries/LibGUI/AbstractView.cpp +++ b/Userland/Libraries/LibGUI/AbstractView.cpp @@ -791,7 +791,7 @@ void AbstractView::drag_enter_event(DragEvent& event) // We might be able to reduce event traffic by communicating the set of drag-accepting // rects in this widget to the windowing system somehow. event.accept(); - dbgln_if(DRAG_DEBUG, "accepting drag of {}", event.mime_types()); + dbgln_if(DRAG_DEBUG, "accepting drag of {}", event.mime_data().formats()); } void AbstractView::drag_move_event(DragEvent& event) @@ -801,7 +801,7 @@ void AbstractView::drag_move_event(DragEvent& event) auto index = index_at_event_position(event.position()); ModelIndex new_drop_candidate_index; - bool acceptable = model()->accepts_drag(index, event.mime_types()); + bool acceptable = model()->accepts_drag(index, event.mime_data()); if (acceptable && index.is_valid()) new_drop_candidate_index = index; diff --git a/Userland/Libraries/LibGUI/Application.cpp b/Userland/Libraries/LibGUI/Application.cpp index eeb785cb5ba..211c35ff1c9 100644 --- a/Userland/Libraries/LibGUI/Application.cpp +++ b/Userland/Libraries/LibGUI/Application.cpp @@ -283,7 +283,7 @@ void Application::set_pending_drop_widget(Widget* widget) m_pending_drop_widget->update(); } -void Application::set_drag_hovered_widget_impl(Widget* widget, Gfx::IntPoint position, Vector mime_types) +void Application::set_drag_hovered_widget_impl(Widget* widget, Gfx::IntPoint position, Optional drag_event) { if (widget == m_drag_hovered_widget) return; @@ -296,8 +296,8 @@ void Application::set_drag_hovered_widget_impl(Widget* widget, Gfx::IntPoint pos set_pending_drop_widget(nullptr); m_drag_hovered_widget = widget; - if (m_drag_hovered_widget) { - DragEvent enter_event(Event::DragEnter, position, move(mime_types)); + if (m_drag_hovered_widget && drag_event.has_value()) { + DragEvent enter_event(Event::DragEnter, position, drag_event->button(), drag_event->buttons(), drag_event->modifiers(), drag_event->text(), drag_event->mime_data()); enter_event.ignore(); m_drag_hovered_widget->dispatch_event(enter_event, m_drag_hovered_widget->window()); if (enter_event.is_accepted()) diff --git a/Userland/Libraries/LibGUI/Application.h b/Userland/Libraries/LibGUI/Application.h index 9e951d3fc5b..8594404abe2 100644 --- a/Userland/Libraries/LibGUI/Application.h +++ b/Userland/Libraries/LibGUI/Application.h @@ -78,9 +78,9 @@ public: Widget* pending_drop_widget() { return m_pending_drop_widget.ptr(); } Widget const* pending_drop_widget() const { return m_pending_drop_widget.ptr(); } - void set_drag_hovered_widget(Badge, Widget* widget, Gfx::IntPoint position = {}, Vector mime_types = {}) + void set_drag_hovered_widget(Badge, Widget* widget, Gfx::IntPoint position = {}, Optional drag_event = {}) { - set_drag_hovered_widget_impl(widget, position, move(mime_types)); + set_drag_hovered_widget_impl(widget, position, move(drag_event)); } void notify_drag_cancelled(Badge); @@ -106,7 +106,7 @@ private: void request_tooltip_show(); void tooltip_hide_timer_did_fire(); - void set_drag_hovered_widget_impl(Widget*, Gfx::IntPoint = {}, Vector = {}); + void set_drag_hovered_widget_impl(Widget*, Gfx::IntPoint = {}, Optional = {}); void set_pending_drop_widget(Widget*); OwnPtr m_event_loop; diff --git a/Userland/Libraries/LibGUI/ConnectionToWindowServer.cpp b/Userland/Libraries/LibGUI/ConnectionToWindowServer.cpp index d30324c7b42..1cda0e70c39 100644 --- a/Userland/Libraries/LibGUI/ConnectionToWindowServer.cpp +++ b/Userland/Libraries/LibGUI/ConnectionToWindowServer.cpp @@ -259,14 +259,10 @@ void ConnectionToWindowServer::mouse_up(i32 window_id, Gfx::IntPoint mouse_posit Core::EventLoop::current().post_event(*window, make(Event::MouseUp, mouse_position, buttons, to_mouse_button(button), modifiers, wheel_delta_x, wheel_delta_y, wheel_raw_delta_x, wheel_raw_delta_y)); } -void ConnectionToWindowServer::mouse_move(i32 window_id, Gfx::IntPoint mouse_position, u32 button, u32 buttons, u32 modifiers, i32 wheel_delta_x, i32 wheel_delta_y, i32 wheel_raw_delta_x, i32 wheel_raw_delta_y, bool is_drag, Vector const& mime_types) +void ConnectionToWindowServer::mouse_move(i32 window_id, Gfx::IntPoint mouse_position, u32 button, u32 buttons, u32 modifiers, i32 wheel_delta_x, i32 wheel_delta_y, i32 wheel_raw_delta_x, i32 wheel_raw_delta_y) { - if (auto* window = Window::from_window_id(window_id)) { - if (is_drag) - Core::EventLoop::current().post_event(*window, make(Event::DragMove, mouse_position, mime_types)); - else - Core::EventLoop::current().post_event(*window, make(Event::MouseMove, mouse_position, buttons, to_mouse_button(button), modifiers, wheel_delta_x, wheel_delta_y, wheel_raw_delta_x, wheel_raw_delta_y)); - } + if (auto* window = Window::from_window_id(window_id)) + Core::EventLoop::current().post_event(*window, make(Event::MouseMove, mouse_position, buttons, to_mouse_button(button), modifiers, wheel_delta_x, wheel_delta_y, wheel_raw_delta_x, wheel_raw_delta_y)); } void ConnectionToWindowServer::mouse_double_click(i32 window_id, Gfx::IntPoint mouse_position, u32 button, u32 buttons, u32 modifiers, i32 wheel_delta_x, i32 wheel_delta_y, i32 wheel_raw_delta_x, i32 wheel_raw_delta_y) @@ -349,12 +345,16 @@ void ConnectionToWindowServer::applet_area_rect_changed(Gfx::IntRect const& rect }); } -void ConnectionToWindowServer::drag_dropped(i32 window_id, Gfx::IntPoint mouse_position, ByteString const& text, HashMap const& mime_data) +void ConnectionToWindowServer::drag_moved(i32 window_id, Gfx::IntPoint mouse_position, u32 button, u32 buttons, u32 modifiers, ByteString const& text, HashMap const& mime_data) { - if (auto* window = Window::from_window_id(window_id)) { - auto mime_data_obj = Core::MimeData::construct(mime_data); - Core::EventLoop::current().post_event(*window, make(mouse_position, text, mime_data_obj)); - } + if (auto* window = Window::from_window_id(window_id)) + Core::EventLoop::current().post_event(*window, make(Event::Type::DragMove, mouse_position, to_mouse_button(button), buttons, modifiers, text, Core::MimeData::construct(mime_data))); +} + +void ConnectionToWindowServer::drag_dropped(i32 window_id, Gfx::IntPoint mouse_position, u32 button, u32 buttons, u32 modifiers, ByteString const& text, HashMap const& mime_data) +{ + if (auto* window = Window::from_window_id(window_id)) + Core::EventLoop::current().post_event(*window, make(Event::Type::Drop, mouse_position, to_mouse_button(button), buttons, modifiers, text, Core::MimeData::construct(mime_data))); } void ConnectionToWindowServer::drag_accepted() diff --git a/Userland/Libraries/LibGUI/ConnectionToWindowServer.h b/Userland/Libraries/LibGUI/ConnectionToWindowServer.h index 6aee8540fdf..9c55085680a 100644 --- a/Userland/Libraries/LibGUI/ConnectionToWindowServer.h +++ b/Userland/Libraries/LibGUI/ConnectionToWindowServer.h @@ -26,7 +26,7 @@ private: virtual void fast_greet(Vector const&, u32, u32, u32, Core::AnonymousBuffer const&, ByteString const&, ByteString const&, ByteString const&, Vector const&, i32) override; virtual void paint(i32, Gfx::IntSize, Vector const&) override; - virtual void mouse_move(i32, Gfx::IntPoint, u32, u32, u32, i32, i32, i32, i32, bool, Vector const&) override; + virtual void mouse_move(i32, Gfx::IntPoint, u32, u32, u32, i32, i32, i32, i32) override; virtual void mouse_down(i32, Gfx::IntPoint, u32, u32, u32, i32, i32, i32, i32) override; virtual void mouse_double_click(i32, Gfx::IntPoint, u32, u32, u32, i32, i32, i32, i32) override; virtual void mouse_up(i32, Gfx::IntPoint, u32, u32, u32, i32, i32, i32, i32) override; @@ -48,7 +48,8 @@ private: virtual void menu_visibility_did_change(i32, bool) override; virtual void screen_rects_changed(Vector const&, u32, u32, u32) override; virtual void applet_area_rect_changed(Gfx::IntRect const&) override; - virtual void drag_dropped(i32, Gfx::IntPoint, ByteString const&, HashMap const&) override; + virtual void drag_moved(i32, Gfx::IntPoint, u32 button, u32 buttons, u32 modifiers, ByteString const&, HashMap const&) override; + virtual void drag_dropped(i32, Gfx::IntPoint, u32 button, u32 buttons, u32 modifiers, ByteString const&, HashMap const&) override; virtual void drag_accepted() override; virtual void drag_cancelled() override; virtual void update_system_theme(Core::AnonymousBuffer const&) override; diff --git a/Userland/Libraries/LibGUI/Event.cpp b/Userland/Libraries/LibGUI/Event.cpp index ddeb8b9ddb8..09623741028 100644 --- a/Userland/Libraries/LibGUI/Event.cpp +++ b/Userland/Libraries/LibGUI/Event.cpp @@ -12,9 +12,12 @@ namespace GUI { -DropEvent::DropEvent(Gfx::IntPoint position, ByteString const& text, NonnullRefPtr mime_data) - : Event(Event::Drop) +DropEvent::DropEvent(Type type, Gfx::IntPoint position, MouseButton button, u32 buttons, u32 modifiers, ByteString const& text, NonnullRefPtr mime_data) + : Event(type) , m_position(position) + , m_button(button) + , m_buttons(buttons) + , m_modifiers(modifiers) , m_text(text) , m_mime_data(move(mime_data)) { @@ -22,6 +25,13 @@ DropEvent::DropEvent(Gfx::IntPoint position, ByteString const& text, NonnullRefP DropEvent::~DropEvent() = default; +DragEvent::DragEvent(Type type, Gfx::IntPoint position, MouseButton button, u32 buttons, u32 modifiers, ByteString const& text, NonnullRefPtr mime_data) + : DropEvent(type, position, button, buttons, modifiers, text, move(mime_data)) +{ +} + +DragEvent::~DragEvent() = default; + ByteString KeyEvent::to_byte_string() const { Vector parts; diff --git a/Userland/Libraries/LibGUI/Event.h b/Userland/Libraries/LibGUI/Event.h index df41e8c1402..0b8167a84cc 100644 --- a/Userland/Libraries/LibGUI/Event.h +++ b/Userland/Libraries/LibGUI/Event.h @@ -482,39 +482,33 @@ private: int m_wheel_raw_delta_y { 0 }; }; -class DragEvent final : public Event { +class DropEvent : public Event { public: - DragEvent(Type type, Gfx::IntPoint position, Vector mime_types) - : Event(type) - , m_position(position) - , m_mime_types(move(mime_types)) - { - } - - Gfx::IntPoint position() const { return m_position; } - Vector const& mime_types() const { return m_mime_types; } - -private: - Gfx::IntPoint m_position; - Vector m_mime_types; -}; - -class DropEvent final : public Event { -public: - DropEvent(Gfx::IntPoint, ByteString const& text, NonnullRefPtr mime_data); - + DropEvent(Type type, Gfx::IntPoint, MouseButton button, u32 buttons, u32 modifiers, ByteString const& text, NonnullRefPtr mime_data); ~DropEvent(); Gfx::IntPoint position() const { return m_position; } + MouseButton button() const { return m_button; } + unsigned buttons() const { return m_buttons; } + unsigned modifiers() const { return m_modifiers; } ByteString const& text() const { return m_text; } Core::MimeData const& mime_data() const { return m_mime_data; } private: Gfx::IntPoint m_position; + MouseButton m_button { MouseButton::None }; + unsigned m_buttons { 0 }; + unsigned m_modifiers { 0 }; ByteString m_text; NonnullRefPtr m_mime_data; }; +class DragEvent final : public DropEvent { +public: + DragEvent(Type type, Gfx::IntPoint, MouseButton button, u32 buttons, u32 modifiers, ByteString const& text, NonnullRefPtr mime_data); + ~DragEvent(); +}; + class ThemeChangeEvent final : public Event { public: ThemeChangeEvent() diff --git a/Userland/Libraries/LibGUI/FileSystemModel.cpp b/Userland/Libraries/LibGUI/FileSystemModel.cpp index aab7209f8a8..190702fe00c 100644 --- a/Userland/Libraries/LibGUI/FileSystemModel.cpp +++ b/Userland/Libraries/LibGUI/FileSystemModel.cpp @@ -855,9 +855,9 @@ ErrorOr FileSystemModel::column_name(int column) const VERIFY_NOT_REACHED(); } -bool FileSystemModel::accepts_drag(ModelIndex const& index, Vector const& mime_types) const +bool FileSystemModel::accepts_drag(ModelIndex const& index, Core::MimeData const& mime_data) const { - if (!mime_types.contains_slow("text/uri-list"sv)) + if (!mime_data.has_urls()) return false; if (!index.is_valid()) diff --git a/Userland/Libraries/LibGUI/FileSystemModel.h b/Userland/Libraries/LibGUI/FileSystemModel.h index 53fb64be23c..4058b7e4d44 100644 --- a/Userland/Libraries/LibGUI/FileSystemModel.h +++ b/Userland/Libraries/LibGUI/FileSystemModel.h @@ -133,7 +133,7 @@ public: virtual ModelIndex parent_index(ModelIndex const&) const override; virtual ModelIndex index(int row, int column = 0, ModelIndex const& parent = ModelIndex()) const override; virtual StringView drag_data_type() const override { return "text/uri-list"sv; } - virtual bool accepts_drag(ModelIndex const&, Vector const& mime_types) const override; + virtual bool accepts_drag(ModelIndex const&, Core::MimeData const&) const override; virtual bool is_column_sortable(int column_index) const override { return column_index != Column::Icon; } virtual bool is_editable(ModelIndex const&) const override; virtual bool is_searchable() const override { return true; } diff --git a/Userland/Libraries/LibGUI/Model.cpp b/Userland/Libraries/LibGUI/Model.cpp index e0671a7a73d..e0a7446cd6a 100644 --- a/Userland/Libraries/LibGUI/Model.cpp +++ b/Userland/Libraries/LibGUI/Model.cpp @@ -63,7 +63,7 @@ ModelIndex Model::index(int row, int column, ModelIndex const&) const return create_index(row, column); } -bool Model::accepts_drag(ModelIndex const&, Vector const&) const +bool Model::accepts_drag(ModelIndex const&, Core::MimeData const&) const { return false; } diff --git a/Userland/Libraries/LibGUI/Model.h b/Userland/Libraries/LibGUI/Model.h index f9477a3a43b..5792f0529e2 100644 --- a/Userland/Libraries/LibGUI/Model.h +++ b/Userland/Libraries/LibGUI/Model.h @@ -81,7 +81,7 @@ public: virtual bool is_searchable() const { return false; } virtual void set_data(ModelIndex const&, Variant const&) { } virtual int tree_column() const { return 0; } - virtual bool accepts_drag(ModelIndex const&, Vector const& mime_types) const; + virtual bool accepts_drag(ModelIndex const&, Core::MimeData const&) const; virtual Vector matches(StringView, unsigned = MatchesFlag::AllMatching, ModelIndex const& = ModelIndex()) { return {}; } virtual bool is_column_sortable([[maybe_unused]] int column_index) const { return true; } diff --git a/Userland/Libraries/LibGUI/PathBreadcrumbbar.cpp b/Userland/Libraries/LibGUI/PathBreadcrumbbar.cpp index 1779f050c3a..b6bf9633124 100644 --- a/Userland/Libraries/LibGUI/PathBreadcrumbbar.cpp +++ b/Userland/Libraries/LibGUI/PathBreadcrumbbar.cpp @@ -69,7 +69,7 @@ PathBreadcrumbbar::PathBreadcrumbbar(NonnullRefPtr location_text_b }; m_breadcrumbbar->on_segment_drag_enter = [&](size_t, GUI::DragEvent& event) { - if (event.mime_types().contains_slow("text/uri-list"sv)) + if (event.mime_data().has_urls()) event.accept(); }; diff --git a/Userland/Libraries/LibGUI/SortingProxyModel.cpp b/Userland/Libraries/LibGUI/SortingProxyModel.cpp index cd6c48d835b..946e0ce9d2f 100644 --- a/Userland/Libraries/LibGUI/SortingProxyModel.cpp +++ b/Userland/Libraries/LibGUI/SortingProxyModel.cpp @@ -49,9 +49,9 @@ void SortingProxyModel::model_did_update(unsigned flags) update_sort(flags); } -bool SortingProxyModel::accepts_drag(ModelIndex const& proxy_index, Vector const& mime_types) const +bool SortingProxyModel::accepts_drag(ModelIndex const& proxy_index, Core::MimeData const& mime_data) const { - return source().accepts_drag(map_to_source(proxy_index), mime_types); + return source().accepts_drag(map_to_source(proxy_index), mime_data); } int SortingProxyModel::row_count(ModelIndex const& proxy_index) const diff --git a/Userland/Libraries/LibGUI/SortingProxyModel.h b/Userland/Libraries/LibGUI/SortingProxyModel.h index 82eec947bbb..fcdc38489ad 100644 --- a/Userland/Libraries/LibGUI/SortingProxyModel.h +++ b/Userland/Libraries/LibGUI/SortingProxyModel.h @@ -34,7 +34,7 @@ public: virtual bool is_searchable() const override; virtual void set_data(ModelIndex const&, Variant const&) override; virtual Vector matches(StringView, unsigned = MatchesFlag::AllMatching, ModelIndex const& = ModelIndex()) override; - virtual bool accepts_drag(ModelIndex const&, Vector const& mime_types) const override; + virtual bool accepts_drag(ModelIndex const&, Core::MimeData const&) const override; virtual bool is_column_sortable(int column_index) const override; diff --git a/Userland/Libraries/LibGUI/Widget.cpp b/Userland/Libraries/LibGUI/Widget.cpp index e2ebc4b556e..6e0a0493f36 100644 --- a/Userland/Libraries/LibGUI/Widget.cpp +++ b/Userland/Libraries/LibGUI/Widget.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -532,9 +533,7 @@ void Widget::drag_move_event(DragEvent&) void Widget::drag_enter_event(DragEvent& event) { - StringBuilder builder; - builder.join(',', event.mime_types()); - dbgln_if(DRAG_DEBUG, "{} {:p} DRAG ENTER @ {}, {}", class_name(), this, event.position(), builder.string_view()); + dbgln_if(DRAG_DEBUG, "{} {:p} DRAG ENTER @ {}, {}", class_name(), this, event.position(), event.mime_data().formats()); } void Widget::drag_leave_event(Event&) diff --git a/Userland/Libraries/LibGUI/Window.cpp b/Userland/Libraries/LibGUI/Window.cpp index f67e4a51daf..91a7966d822 100644 --- a/Userland/Libraries/LibGUI/Window.cpp +++ b/Userland/Libraries/LibGUI/Window.cpp @@ -432,7 +432,7 @@ void Window::handle_drop_event(DropEvent& event) if (!m_main_widget) return; auto result = m_main_widget->hit_test(event.position()); - auto local_event = make(result.local_position, event.text(), event.mime_data()); + auto local_event = make(Event::Type::Drop, result.local_position, event.button(), event.buttons(), event.modifiers(), event.text(), event.mime_data()); VERIFY(result.widget); result.widget->dispatch_event(*local_event, this); @@ -766,14 +766,14 @@ void Window::handle_drag_move_event(DragEvent& event) auto result = m_main_widget->hit_test(event.position()); VERIFY(result.widget); - Application::the()->set_drag_hovered_widget({}, result.widget, result.local_position, event.mime_types()); + Application::the()->set_drag_hovered_widget({}, result.widget, result.local_position, event); // 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()), result.local_position, event.mime_types()); + DragEvent drag_move_event(static_cast(event.type()), result.local_position, event.button(), event.buttons(), event.modifiers(), event.text(), event.mime_data()); result.widget->dispatch_event(drag_move_event, this); } } diff --git a/Userland/Libraries/LibVT/TerminalWidget.cpp b/Userland/Libraries/LibVT/TerminalWidget.cpp index 76889bd8fe1..d048767094a 100644 --- a/Userland/Libraries/LibVT/TerminalWidget.cpp +++ b/Userland/Libraries/LibVT/TerminalWidget.cpp @@ -1199,8 +1199,7 @@ void TerminalWidget::context_menu_event(GUI::ContextMenuEvent& event) void TerminalWidget::drag_enter_event(GUI::DragEvent& event) { - auto const& mime_types = event.mime_types(); - if (mime_types.contains_slow("text/plain"sv) || mime_types.contains_slow("text/uri-list"sv)) + if (event.mime_data().has_text() || event.mime_data().has_urls()) event.accept(); } diff --git a/Userland/Services/Taskbar/QuickLaunchWidget.cpp b/Userland/Services/Taskbar/QuickLaunchWidget.cpp index 07eb710d708..4b1d8544161 100644 --- a/Userland/Services/Taskbar/QuickLaunchWidget.cpp +++ b/Userland/Services/Taskbar/QuickLaunchWidget.cpp @@ -152,8 +152,7 @@ void QuickLaunchWidget::config_string_did_change(StringView domain, StringView g void QuickLaunchWidget::drag_enter_event(GUI::DragEvent& event) { - auto const& mime_types = event.mime_types(); - if (mime_types.contains_slow("text/uri-list"sv)) + if (event.mime_data().has_urls()) event.accept(); } diff --git a/Userland/Services/WindowServer/ConnectionFromClient.cpp b/Userland/Services/WindowServer/ConnectionFromClient.cpp index f40bf874a9f..2cd57337a1f 100644 --- a/Userland/Services/WindowServer/ConnectionFromClient.cpp +++ b/Userland/Services/WindowServer/ConnectionFromClient.cpp @@ -5,6 +5,7 @@ */ #include +#include #include #include #include diff --git a/Userland/Services/WindowServer/Event.h b/Userland/Services/WindowServer/Event.h index d2acd738562..42d490da74c 100644 --- a/Userland/Services/WindowServer/Event.h +++ b/Userland/Services/WindowServer/Event.h @@ -9,7 +9,6 @@ #include #include #include -#include #include #include #include @@ -115,17 +114,6 @@ public: int wheel_delta_y() const { return m_wheel_delta_y; } int wheel_raw_delta_x() const { return m_wheel_raw_delta_x; } int wheel_raw_delta_y() const { return m_wheel_raw_delta_y; } - bool is_drag() const { return m_drag; } - - Vector mime_types() const - { - if (!m_mime_data) - return {}; - return m_mime_data->formats(); - } - - void set_drag(bool b) { m_drag = b; } - void set_mime_data(Core::MimeData const& mime_data) { m_mime_data = mime_data; } MouseEvent translated(Gfx::IntPoint delta) const { @@ -143,8 +131,6 @@ private: int m_wheel_delta_y { 0 }; int m_wheel_raw_delta_x { 0 }; int m_wheel_raw_delta_y { 0 }; - bool m_drag { false }; - RefPtr m_mime_data; }; class ResizeEvent final : public Event { diff --git a/Userland/Services/WindowServer/Screen.cpp b/Userland/Services/WindowServer/Screen.cpp index 9f29402f838..92ef11d9eb4 100644 --- a/Userland/Services/WindowServer/Screen.cpp +++ b/Userland/Services/WindowServer/Screen.cpp @@ -438,10 +438,9 @@ void ScreenInput::on_receive_mouse_data(MousePacket const& packet) post_mousedown_or_mouseup_if_needed(MouseButton::Middle); post_mousedown_or_mouseup_if_needed(MouseButton::Backward); post_mousedown_or_mouseup_if_needed(MouseButton::Forward); + if (m_cursor_location != prev_location) { auto message = make(Event::MouseMove, m_cursor_location, buttons, MouseButton::None, m_modifiers); - if (WindowManager::the().dnd_client()) - message->set_mime_data(WindowManager::the().dnd_mime_data()); Core::EventLoop::current().post_event(WindowManager::the(), move(message)); } diff --git a/Userland/Services/WindowServer/Window.cpp b/Userland/Services/WindowServer/Window.cpp index 8812bd867d1..ad4e1f34644 100644 --- a/Userland/Services/WindowServer/Window.cpp +++ b/Userland/Services/WindowServer/Window.cpp @@ -209,7 +209,7 @@ void Window::handle_mouse_event(MouseEvent const& event) switch (event.type()) { case Event::MouseMove: - m_client->async_mouse_move(m_window_id, event.position(), (u32)event.button(), event.buttons(), event.modifiers(), event.wheel_delta_x(), event.wheel_delta_y(), event.wheel_raw_delta_x(), event.wheel_raw_delta_y(), event.is_drag(), event.mime_types()); + m_client->async_mouse_move(m_window_id, event.position(), (u32)event.button(), event.buttons(), event.modifiers(), event.wheel_delta_x(), event.wheel_delta_y(), event.wheel_raw_delta_x(), event.wheel_raw_delta_y()); break; case Event::MouseDown: m_client->async_mouse_down(m_window_id, event.position(), (u32)event.button(), event.buttons(), event.modifiers(), event.wheel_delta_x(), event.wheel_delta_y(), event.wheel_raw_delta_x(), event.wheel_raw_delta_y()); diff --git a/Userland/Services/WindowServer/WindowClient.ipc b/Userland/Services/WindowServer/WindowClient.ipc index 2fa60b095d3..f72138f9b78 100644 --- a/Userland/Services/WindowServer/WindowClient.ipc +++ b/Userland/Services/WindowServer/WindowClient.ipc @@ -6,7 +6,7 @@ endpoint WindowClient fast_greet(Vector screen_rects, u32 main_screen_index, u32 workspace_rows, u32 workspace_columns, Core::AnonymousBuffer theme_buffer, ByteString default_font_query, ByteString fixed_width_font_query, ByteString window_title_font_query, Vector effects, i32 client_id) =| paint(i32 window_id, Gfx::IntSize window_size, Vector rects) =| - mouse_move(i32 window_id, Gfx::IntPoint mouse_position, u32 button, u32 buttons, u32 modifiers, i32 wheel_delta_x, i32 wheel_delta_y, i32 wheel_raw_delta_x, i32 wheel_raw_delta_y, bool is_drag, Vector mime_types) =| + mouse_move(i32 window_id, Gfx::IntPoint mouse_position, u32 button, u32 buttons, u32 modifiers, i32 wheel_delta_x, i32 wheel_delta_y, i32 wheel_raw_delta_x, i32 wheel_raw_delta_y) =| mouse_down(i32 window_id, Gfx::IntPoint mouse_position, u32 button, u32 buttons, u32 modifiers, i32 wheel_delta_x, i32 wheel_delta_y, i32 wheel_raw_delta_x, i32 wheel_raw_delta_y) =| mouse_double_click(i32 window_id, Gfx::IntPoint mouse_position, u32 button, u32 buttons, u32 modifiers, i32 wheel_delta_x, i32 wheel_delta_y, i32 wheel_raw_delta_x, i32 wheel_raw_delta_y) =| mouse_up(i32 window_id, Gfx::IntPoint mouse_position, u32 button, u32 buttons, u32 modifiers, i32 wheel_delta_x, i32 wheel_delta_y, i32 wheel_raw_delta_x, i32 wheel_raw_delta_y) =| @@ -36,7 +36,8 @@ endpoint WindowClient drag_accepted() =| drag_cancelled() =| - drag_dropped(i32 window_id, Gfx::IntPoint mouse_position, [UTF8] ByteString text, HashMap mime_data) =| + drag_moved(i32 window_id, Gfx::IntPoint mouse_position, u32 button, u32 buttons, u32 modifiers, [UTF8] ByteString text, HashMap mime_data) =| + drag_dropped(i32 window_id, Gfx::IntPoint mouse_position, u32 button, u32 buttons, u32 modifiers, [UTF8] ByteString text, HashMap mime_data) =| update_system_theme(Core::AnonymousBuffer theme_buffer) =| update_system_fonts(ByteString default_font_query, ByteString fixed_width_font_query, ByteString window_title_font_query) =| diff --git a/Userland/Services/WindowServer/WindowManager.cpp b/Userland/Services/WindowServer/WindowManager.cpp index 6709369305c..30cefc40097 100644 --- a/Userland/Services/WindowServer/WindowManager.cpp +++ b/Userland/Services/WindowServer/WindowManager.cpp @@ -1110,38 +1110,48 @@ bool WindowManager::process_ongoing_drag(MouseEvent& event) if (!m_dnd_client) return false; + auto send_dnd_event = [&](auto callback) { + auto* window = hovered_window(); + if (!window || !window->client()) + return false; + + auto translated_event = event.translated(-window->position()); + auto mime_data = m_dnd_mime_data->all_data().clone(); + + // If the mime data is so large that it causes memory troubles, we should silently drop the drag'n'drop request entirely. + if (mime_data.is_error()) { + dbgln("Drag and drop mimetype data nearly caused OOM and was dropped: {}", mime_data.release_error()); + return false; + } + + callback(*window, translated_event.position(), mime_data.release_value()); + return true; + }; + if (event.type() == Event::MouseMove) { m_dnd_overlay->cursor_moved(); // We didn't let go of the drag yet, see if we should send some drag move events.. - if (auto* window = hovered_window()) { - event.set_drag(true); - event.set_mime_data(*m_dnd_mime_data); - deliver_mouse_event(*window, event); - } else { + auto event_sent = send_dnd_event([&](auto& window, auto event_position, auto mime_data) { + window.client()->async_drag_moved(window.window_id(), event_position, event.button(), event.buttons(), event.modifiers(), m_dnd_text, move(mime_data)); + }); + + if (!event_sent) set_accepts_drag(false); - } } - if (!(event.type() == Event::MouseUp && event.button() == MouseButton::Primary)) - return true; + if (event.type() == Event::MouseUp && event.button() == MouseButton::Primary) { + auto event_sent = send_dnd_event([&](auto& window, auto event_position, auto mime_data) { + m_dnd_client->async_drag_accepted(); + window.client()->async_drag_dropped(window.window_id(), event_position, event.button(), event.buttons(), event.modifiers(), m_dnd_text, move(mime_data)); + }); - if (auto* window = hovered_window()) { - m_dnd_client->async_drag_accepted(); - if (window->client()) { - auto translated_event = event.translated(-window->position()); - auto copied_mime_data_or_error = m_dnd_mime_data->all_data().clone(); - // If the mime data is so large that it causes memory troubles, we should silently drop the drag'n'drop request entirely. - if (copied_mime_data_or_error.is_error()) - dbgln("Drag and drop mimetype data nearly caused OOM and was dropped: {}", copied_mime_data_or_error.release_error()); - else - window->client()->async_drag_dropped(window->window_id(), translated_event.position(), m_dnd_text, copied_mime_data_or_error.release_value()); - } - } else { - m_dnd_client->async_drag_cancelled(); + if (!event_sent) + m_dnd_client->async_drag_cancelled(); + + end_dnd_drag(); } - end_dnd_drag(); return true; }