Drag and Drop files in Collabora Office Desktop

Drag a document out of the file manager, drop it on the Collabora Office desktop app, and it opens. On Linux, Windows and macOS.

How it’s done

The whole window is one web view, and that web view takes any drag that lands on it. What the web content gets is the HTML5 drag payload, and that never includes where the file lives on disk. Opening a document needs the path, so on every platform the work had the same shape: catch the drop natively, before the web view swallows it, and find out which files it carried.

Linux

On Linux the web view is a QWebEngineView, so the three drag handlers can be overridden on our own subclass of it. A drag is accepted when it carries at least one local file. On the drop, the local paths are collected out of the drag data and handed to the same open-files code that the command line and the file dialog already use.

The Flatpak build then needed a second round. Inside the sandbox, the paths in a drag from outside are not paths the app is allowed to open. Such a drag instead carries a payload under the type application/vnd.portal.filetransfer, and that payload is a key rather than a file name. Calling RetrieveFiles on the org.freedesktop.portal.FileTransfer interface over D-Bus trades the key for a list of paths that are visible inside the sandbox. The plain local-file case stays as the fallback, so a single build serves both.

MacOS

macOS uses a WKWebView, which does its own drag and drop for the page. A subclass registers for the file URL drag type, and then has one question to answer on every drag: did this come from Finder, or from inside the document? A drag started in the page has a dragging source, a drag from Finder has none. The app takes the file drags that come from outside and passes everything else straight back to the base class, so dragging text or an image around inside a document behaves exactly as before. The files are opened through the shared document controller, which keeps the list of recent documents right and raises the window of a document that is already open instead of opening a second copy of it.

Windows

Windows was the awkward one, and Tor Lillqvist took it on. The WebView2 control hands the app neither the drop nor the paths of the files, so there is nothing to override. The two sides cooperate instead. The page watches for a drag that carries files and tells the app about it. The app then raises a transparent window, with a drop target of its own, over the web view, so the drop lands in the app rather than in the web content. That window goes away again as soon as the drag leaves or ends. Both drop targets are registered through RegisterDragDrop, which quietly does nothing until OLE is running, so the app now starts OLE alongside COM.

Letting the user know

None of this said anything while the drag was still in flight. The drag is caught natively, so the page never sees it and cannot react on its own. Mohit Marathe added a full-window overlay that the native drag handlers switch on and off through the page. It dims the window and shows a card in the middle while a file is held over it, it follows the light and dark theme, and it never takes pointer events, so it cannot get between the user and the content underneath.

Relavant commits: