2018-11-30 22:52:05 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2018-11-30 18:39:55 +03:00
|
|
|
/* vim: set ts=4 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2002-08-12 01:47:14 +04:00
|
|
|
|
|
|
|
#include "nsDragService.h"
|
2016-10-16 22:43:56 +03:00
|
|
|
#include "nsArrayUtils.h"
|
2003-10-30 04:48:41 +03:00
|
|
|
#include "nsIObserverService.h"
|
2002-08-12 01:47:14 +04:00
|
|
|
#include "nsWidgetsCID.h"
|
2003-02-17 21:50:01 +03:00
|
|
|
#include "nsWindow.h"
|
2018-10-04 13:31:45 +03:00
|
|
|
#include "nsSystemInfo.h"
|
2002-09-04 03:36:13 +04:00
|
|
|
#include "nsXPCOM.h"
|
2002-08-12 01:47:14 +04:00
|
|
|
#include "nsISupportsPrimitives.h"
|
2008-12-06 19:27:53 +03:00
|
|
|
#include "nsIIOService.h"
|
|
|
|
#include "nsIFileURL.h"
|
|
|
|
#include "nsNetUtil.h"
|
2015-05-19 21:15:34 +03:00
|
|
|
#include "mozilla/Logging.h"
|
2009-02-23 04:05:24 +03:00
|
|
|
#include "nsTArray.h"
|
2002-08-12 01:47:14 +04:00
|
|
|
#include "nsPrimitiveHelpers.h"
|
|
|
|
#include "prtime.h"
|
|
|
|
#include "prthread.h"
|
2015-07-28 14:13:00 +03:00
|
|
|
#include <dlfcn.h>
|
2009-01-03 10:37:52 +03:00
|
|
|
#include <gtk/gtk.h>
|
2002-08-12 01:47:14 +04:00
|
|
|
#include <gdk/gdkx.h>
|
|
|
|
#include "nsCRT.h"
|
2013-10-22 17:27:35 +04:00
|
|
|
#include "mozilla/BasicEvents.h"
|
Bug 560095 - Use mozilla::services::GetObserverService(). r=biesi,dveditz,gavin,josh,jst,mrbkap,roc,sdwilsh,shaver,sicking,smontagu,surkov
2010-04-29 20:59:13 +04:00
|
|
|
#include "mozilla/Services.h"
|
2017-03-17 02:20:18 +03:00
|
|
|
#include "mozilla/ClearOnShutdown.h"
|
2019-03-29 18:12:47 +03:00
|
|
|
#include "mozilla/PresShell.h"
|
2002-08-12 01:47:14 +04:00
|
|
|
|
2008-06-18 13:20:29 +04:00
|
|
|
#include "gfxXlibSurface.h"
|
|
|
|
#include "gfxContext.h"
|
2007-03-20 15:14:52 +03:00
|
|
|
#include "nsImageToPixbuf.h"
|
2008-01-09 01:03:53 +03:00
|
|
|
#include "nsPresContext.h"
|
2013-10-02 20:47:07 +04:00
|
|
|
#include "nsIContent.h"
|
2019-01-02 16:05:23 +03:00
|
|
|
#include "mozilla/dom/Document.h"
|
2013-01-05 07:12:24 +04:00
|
|
|
#include "nsViewManager.h"
|
2011-04-26 05:37:20 +04:00
|
|
|
#include "nsIFrame.h"
|
2013-06-22 17:39:43 +04:00
|
|
|
#include "nsGtkUtils.h"
|
2017-02-17 06:29:42 +03:00
|
|
|
#include "nsGtkKeyUtils.h"
|
2014-01-29 04:10:33 +04:00
|
|
|
#include "mozilla/gfx/2D.h"
|
|
|
|
#include "gfxPlatform.h"
|
2017-03-09 14:29:44 +03:00
|
|
|
#include "ScreenHelperGTK.h"
|
2016-10-18 21:56:20 +03:00
|
|
|
#include "nsArrayUtils.h"
|
2018-04-05 17:16:43 +03:00
|
|
|
#ifdef MOZ_WAYLAND
|
|
|
|
# include "nsClipboardWayland.h"
|
2020-04-09 17:18:41 +03:00
|
|
|
# include "gfxPlatformGtk.h"
|
2018-04-05 17:16:43 +03:00
|
|
|
#endif
|
2014-01-29 04:10:33 +04:00
|
|
|
|
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::gfx;
|
2002-08-12 01:47:14 +04:00
|
|
|
|
2018-10-04 13:31:45 +03:00
|
|
|
#define NS_SYSTEMINFO_CONTRACTID "@mozilla.org/system-info;1"
|
|
|
|
|
2008-06-18 13:20:29 +04:00
|
|
|
// This sets how opaque the drag image is
|
|
|
|
#define DRAG_IMAGE_ALPHA_LEVEL 0.5
|
|
|
|
|
2009-06-20 05:38:27 +04:00
|
|
|
// These values are copied from GtkDragResult (rather than using GtkDragResult
|
|
|
|
// directly) so that this code can be compiled against versions of GTK+ that
|
|
|
|
// do not have GtkDragResult.
|
|
|
|
// GtkDragResult is available from GTK+ version 2.12.
|
2020-04-09 17:18:41 +03:00
|
|
|
enum {
|
|
|
|
MOZ_GTK_DRAG_RESULT_SUCCESS,
|
|
|
|
MOZ_GTK_DRAG_RESULT_NO_TARGET,
|
|
|
|
MOZ_GTK_DRAG_RESULT_USER_CANCELLED,
|
|
|
|
MOZ_GTK_DRAG_RESULT_TIMEOUT_EXPIRED,
|
|
|
|
MOZ_GTK_DRAG_RESULT_GRAB_BROKEN,
|
|
|
|
MOZ_GTK_DRAG_RESULT_ERROR
|
|
|
|
};
|
2009-06-20 05:38:27 +04:00
|
|
|
|
2016-05-18 22:55:42 +03:00
|
|
|
static LazyLogModule sDragLm("nsDragService");
|
2012-05-03 10:24:20 +04:00
|
|
|
|
|
|
|
// data used for synthetic periodic motion events sent to the source widget
|
|
|
|
// grabbing real events for the drag.
|
2011-01-27 04:58:55 +03:00
|
|
|
static guint sMotionEventTimerID;
|
2012-05-03 10:24:20 +04:00
|
|
|
static GdkEvent* sMotionEvent;
|
|
|
|
static GtkWidget* sGrabWidget;
|
2002-08-12 01:47:14 +04:00
|
|
|
|
|
|
|
static const char gMimeListType[] = "application/x-moz-internal-item-list";
|
|
|
|
static const char gMozUrlType[] = "_NETSCAPE_URL";
|
|
|
|
static const char gTextUriListType[] = "text/uri-list";
|
2009-09-15 11:04:54 +04:00
|
|
|
static const char gTextPlainUTF8Type[] = "text/plain;charset=utf-8";
|
2018-10-04 13:31:45 +03:00
|
|
|
static const char gXdndDirectSaveType[] = "XdndDirectSave0";
|
2020-04-09 17:18:41 +03:00
|
|
|
static const char gTabDropType[] = "application/x-moz-tabbrowser-tab";
|
2002-08-12 01:47:14 +04:00
|
|
|
|
2011-07-04 18:39:08 +04:00
|
|
|
static void invisibleSourceDragBegin(GtkWidget* aWidget,
|
|
|
|
GdkDragContext* aContext, gpointer aData);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2002-08-12 01:47:14 +04:00
|
|
|
static void invisibleSourceDragEnd(GtkWidget* aWidget, GdkDragContext* aContext,
|
|
|
|
gpointer aData);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2009-06-20 05:38:27 +04:00
|
|
|
static gboolean invisibleSourceDragFailed(GtkWidget* aWidget,
|
|
|
|
GdkDragContext* aContext,
|
|
|
|
gint aResult, gpointer aData);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2002-08-12 01:47:14 +04:00
|
|
|
static void invisibleSourceDragDataGet(GtkWidget* aWidget,
|
|
|
|
GdkDragContext* aContext,
|
|
|
|
GtkSelectionData* aSelectionData,
|
|
|
|
guint aInfo, guint32 aTime,
|
|
|
|
gpointer aData);
|
|
|
|
|
|
|
|
nsDragService::nsDragService()
|
2012-05-10 05:00:05 +04:00
|
|
|
: mScheduledTask(eDragTaskNone),
|
|
|
|
mTaskSource(0)
|
2018-04-05 17:16:43 +03:00
|
|
|
#ifdef MOZ_WAYLAND
|
|
|
|
,
|
|
|
|
mPendingWaylandDragContext(nullptr),
|
|
|
|
mTargetWaylandDragContext(nullptr)
|
|
|
|
#endif
|
2002-08-12 01:47:14 +04:00
|
|
|
{
|
2003-10-30 04:48:41 +03:00
|
|
|
// We have to destroy the hidden widget before the event loop stops
|
|
|
|
// running.
|
|
|
|
nsCOMPtr<nsIObserverService> obsServ =
|
Bug 560095 - Use mozilla::services::GetObserverService(). r=biesi,dveditz,gavin,josh,jst,mrbkap,roc,sdwilsh,shaver,sicking,smontagu,surkov
2010-04-29 20:59:13 +04:00
|
|
|
mozilla::services::GetObserverService();
|
2011-10-03 11:56:21 +04:00
|
|
|
obsServ->AddObserver(this, "quit-application", false);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2002-08-12 01:47:14 +04:00
|
|
|
// our hidden source widget
|
2015-06-17 13:20:00 +03:00
|
|
|
// Using an offscreen window works around bug 983843.
|
|
|
|
mHiddenWidget = gtk_offscreen_window_new();
|
2002-08-12 01:47:14 +04:00
|
|
|
// make sure that the widget is realized so that
|
|
|
|
// we can use it as a drag source.
|
|
|
|
gtk_widget_realize(mHiddenWidget);
|
|
|
|
// hook up our internal signals so that we can get some feedback
|
|
|
|
// from our drag source
|
2011-07-04 18:39:08 +04:00
|
|
|
g_signal_connect(mHiddenWidget, "drag_begin",
|
|
|
|
G_CALLBACK(invisibleSourceDragBegin), this);
|
2011-05-16 13:07:37 +04:00
|
|
|
g_signal_connect(mHiddenWidget, "drag_data_get",
|
2009-02-02 20:49:58 +03:00
|
|
|
G_CALLBACK(invisibleSourceDragDataGet), this);
|
2011-05-16 13:07:37 +04:00
|
|
|
g_signal_connect(mHiddenWidget, "drag_end",
|
2009-02-02 20:49:58 +03:00
|
|
|
G_CALLBACK(invisibleSourceDragEnd), this);
|
2009-06-20 05:38:27 +04:00
|
|
|
// drag-failed is available from GTK+ version 2.12
|
|
|
|
guint dragFailedID =
|
|
|
|
g_signal_lookup("drag-failed", G_TYPE_FROM_INSTANCE(mHiddenWidget));
|
|
|
|
if (dragFailedID) {
|
|
|
|
g_signal_connect_closure_by_id(
|
|
|
|
mHiddenWidget, dragFailedID, 0,
|
|
|
|
g_cclosure_new(G_CALLBACK(invisibleSourceDragFailed), this, nullptr),
|
|
|
|
FALSE);
|
|
|
|
}
|
2002-08-12 01:47:14 +04:00
|
|
|
|
|
|
|
// set up our logging module
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(sDragLm, LogLevel::Debug, ("nsDragService::nsDragService"));
|
2011-10-03 11:56:21 +04:00
|
|
|
mCanDrop = false;
|
|
|
|
mTargetDragDataReceived = false;
|
2002-08-12 01:47:14 +04:00
|
|
|
mTargetDragData = 0;
|
|
|
|
mTargetDragDataLen = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDragService::~nsDragService() {
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(sDragLm, LogLevel::Debug, ("nsDragService::~nsDragService"));
|
2012-04-19 10:18:31 +04:00
|
|
|
if (mTaskSource) g_source_remove(mTaskSource);
|
2003-10-30 04:48:41 +03:00
|
|
|
}
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED(nsDragService, nsBaseDragService, nsIObserver)
|
2007-08-07 19:18:36 +04:00
|
|
|
|
2017-03-17 02:20:18 +03:00
|
|
|
mozilla::StaticRefPtr<nsDragService> sDragServiceInstance;
|
2019-02-26 01:13:48 +03:00
|
|
|
/* static */
|
|
|
|
already_AddRefed<nsDragService> nsDragService::GetInstance() {
|
2017-03-17 02:20:18 +03:00
|
|
|
if (gfxPlatform::IsHeadless()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
if (!sDragServiceInstance) {
|
|
|
|
sDragServiceInstance = new nsDragService();
|
|
|
|
ClearOnShutdown(&sDragServiceInstance);
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<nsDragService> service = sDragServiceInstance.get();
|
|
|
|
return service.forget();
|
2012-04-19 10:18:31 +04:00
|
|
|
}
|
|
|
|
|
2003-10-30 04:48:41 +03:00
|
|
|
// nsIObserver
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDragService::Observe(nsISupports* aSubject, const char* aTopic,
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t* aData) {
|
2003-10-30 04:48:41 +03:00
|
|
|
if (!nsCRT::strcmp(aTopic, "quit-application")) {
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(sDragLm, LogLevel::Debug,
|
2003-10-30 04:48:41 +03:00
|
|
|
("nsDragService::Observe(\"quit-application\")"));
|
2006-06-22 18:36:11 +04:00
|
|
|
if (mHiddenWidget) {
|
|
|
|
gtk_widget_destroy(mHiddenWidget);
|
|
|
|
mHiddenWidget = 0;
|
|
|
|
}
|
2002-08-12 01:47:14 +04:00
|
|
|
TargetResetData();
|
2003-10-30 04:48:41 +03:00
|
|
|
} else {
|
2018-06-18 08:43:11 +03:00
|
|
|
MOZ_ASSERT_UNREACHABLE("unexpected topic");
|
2003-10-30 04:48:41 +03:00
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
2002-08-12 01:47:14 +04:00
|
|
|
}
|
|
|
|
|
2011-01-27 04:58:55 +03:00
|
|
|
// Support for periodic drag events
|
|
|
|
|
|
|
|
// http://www.whatwg.org/specs/web-apps/current-work/multipage/dnd.html#drag-and-drop-processing-model
|
|
|
|
// and the Xdnd protocol both recommend that drag events are sent periodically,
|
|
|
|
// but GTK does not normally provide this.
|
|
|
|
//
|
|
|
|
// Here GTK is periodically stimulated by copies of the most recent mouse
|
|
|
|
// motion events so as to send drag position messages to the destination when
|
|
|
|
// appropriate (after it has received a status event from the previous
|
|
|
|
// message).
|
|
|
|
//
|
|
|
|
// (If events were sent only on the destination side then the destination
|
|
|
|
// would have no message to which it could reply with a drag status. Without
|
|
|
|
// sending a drag status to the source, the destination would not be able to
|
|
|
|
// change its feedback re whether it could accept the drop, and so the
|
|
|
|
// source's behavior on drop will not be consistent.)
|
|
|
|
|
|
|
|
static gboolean DispatchMotionEventCopy(gpointer aData) {
|
2012-05-03 10:24:20 +04:00
|
|
|
// Clear the timer id before OnSourceGrabEventAfter is called during event
|
|
|
|
// dispatch.
|
2011-01-27 04:58:55 +03:00
|
|
|
sMotionEventTimerID = 0;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-05-03 10:24:20 +04:00
|
|
|
GdkEvent* event = sMotionEvent;
|
2013-10-08 22:47:37 +04:00
|
|
|
sMotionEvent = nullptr;
|
2011-01-27 04:58:55 +03:00
|
|
|
// If there is no longer a grab on the widget, then the drag is over and
|
|
|
|
// there is no need to continue drag motion.
|
2012-05-03 10:24:20 +04:00
|
|
|
if (gtk_widget_has_grab(sGrabWidget)) {
|
|
|
|
gtk_propagate_event(sGrabWidget, event);
|
2011-01-27 04:58:55 +03:00
|
|
|
}
|
2012-05-03 10:24:20 +04:00
|
|
|
gdk_event_free(event);
|
2011-01-27 04:58:55 +03:00
|
|
|
|
|
|
|
// Cancel this timer;
|
|
|
|
// We've already started another if the motion event was dispatched.
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void OnSourceGrabEventAfter(GtkWidget* widget, GdkEvent* event,
|
|
|
|
gpointer user_data) {
|
2012-04-17 05:00:25 +04:00
|
|
|
// If there is no longer a grab on the widget, then the drag motion is
|
|
|
|
// over (though the data may not be fetched yet).
|
2012-05-03 10:24:20 +04:00
|
|
|
if (!gtk_widget_has_grab(sGrabWidget)) return;
|
2012-04-17 05:00:25 +04:00
|
|
|
|
2012-05-03 10:24:20 +04:00
|
|
|
if (event->type == GDK_MOTION_NOTIFY) {
|
|
|
|
if (sMotionEvent) {
|
2013-01-11 03:29:05 +04:00
|
|
|
gdk_event_free(sMotionEvent);
|
2012-05-03 10:24:20 +04:00
|
|
|
}
|
|
|
|
sMotionEvent = gdk_event_copy(event);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-05-03 10:24:20 +04:00
|
|
|
// Update the cursor position. The last of these recorded gets used for
|
2015-09-02 09:08:02 +03:00
|
|
|
// the eDragEnd event.
|
2012-05-03 10:24:20 +04:00
|
|
|
nsDragService* dragService = static_cast<nsDragService*>(user_data);
|
2019-12-03 17:03:01 +03:00
|
|
|
gint scale = mozilla::widget::ScreenHelperGTK::GetGTKMonitorScaleFactor();
|
2016-07-26 17:48:30 +03:00
|
|
|
auto p = LayoutDeviceIntPoint::Round(event->motion.x_root * scale,
|
|
|
|
event->motion.y_root * scale);
|
2015-10-26 23:33:13 +03:00
|
|
|
dragService->SetDragEndPoint(p);
|
2012-05-03 10:24:20 +04:00
|
|
|
} else if (sMotionEvent &&
|
2013-01-11 03:29:05 +04:00
|
|
|
(event->type == GDK_KEY_PRESS || event->type == GDK_KEY_RELEASE)) {
|
|
|
|
// Update modifier state from key events.
|
2012-05-03 10:24:20 +04:00
|
|
|
sMotionEvent->motion.state = event->key.state;
|
2018-11-30 13:46:48 +03:00
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
2012-04-17 05:00:25 +04:00
|
|
|
|
2012-05-03 10:24:20 +04:00
|
|
|
if (sMotionEventTimerID) {
|
|
|
|
g_source_remove(sMotionEventTimerID);
|
|
|
|
}
|
2011-01-27 04:58:55 +03:00
|
|
|
|
|
|
|
// G_PRIORITY_DEFAULT_IDLE is lower priority than GDK's redraw idle source
|
|
|
|
// and lower than GTK's idle source that sends drag position messages after
|
|
|
|
// motion-notify signals.
|
|
|
|
//
|
|
|
|
// http://www.whatwg.org/specs/web-apps/current-work/multipage/dnd.html#drag-and-drop-processing-model
|
|
|
|
// recommends an interval of 350ms +/- 200ms.
|
|
|
|
sMotionEventTimerID = g_timeout_add_full(
|
2013-10-08 22:47:37 +04:00
|
|
|
G_PRIORITY_DEFAULT_IDLE, 350, DispatchMotionEventCopy, nullptr, nullptr);
|
2011-01-27 04:58:55 +03:00
|
|
|
}
|
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
static GtkWindow* GetGtkWindow(dom::Document* aDocument) {
|
2018-05-11 20:46:15 +03:00
|
|
|
if (!aDocument) return nullptr;
|
2012-05-03 10:23:59 +04:00
|
|
|
|
2019-03-29 18:12:47 +03:00
|
|
|
PresShell* presShell = aDocument->GetPresShell();
|
|
|
|
if (!presShell) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2012-05-03 10:23:59 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsViewManager> vm = presShell->GetViewManager();
|
2013-10-08 22:47:37 +04:00
|
|
|
if (!vm) return nullptr;
|
2012-05-03 10:23:59 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIWidget> widget;
|
|
|
|
vm->GetRootWidget(getter_AddRefs(widget));
|
2013-10-08 22:47:37 +04:00
|
|
|
if (!widget) return nullptr;
|
2012-05-03 10:23:59 +04:00
|
|
|
|
|
|
|
GtkWidget* gtkWidget =
|
|
|
|
static_cast<nsWindow*>(widget.get())->GetMozContainerWidget();
|
2013-10-08 22:47:37 +04:00
|
|
|
if (!gtkWidget) return nullptr;
|
2012-05-03 10:23:59 +04:00
|
|
|
|
2013-10-08 22:47:37 +04:00
|
|
|
GtkWidget* toplevel = nullptr;
|
2012-05-03 10:23:59 +04:00
|
|
|
toplevel = gtk_widget_get_toplevel(gtkWidget);
|
|
|
|
if (!GTK_IS_WINDOW(toplevel)) return nullptr;
|
|
|
|
|
|
|
|
return GTK_WINDOW(toplevel);
|
2017-12-19 13:38:59 +03:00
|
|
|
}
|
2012-05-03 10:23:59 +04:00
|
|
|
|
2002-08-12 01:47:14 +04:00
|
|
|
// nsIDragService
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2018-05-30 05:58:48 +03:00
|
|
|
nsDragService::InvokeDragSession(
|
2019-08-20 15:43:02 +03:00
|
|
|
nsINode* aDOMNode, nsIPrincipal* aPrincipal, nsIContentSecurityPolicy* aCsp,
|
|
|
|
nsIArray* aArrayTransferables, uint32_t aActionType,
|
2015-08-10 22:56:47 +03:00
|
|
|
nsContentPolicyType aContentPolicyType = nsIContentPolicy::TYPE_OTHER) {
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(sDragLm, LogLevel::Debug, ("nsDragService::InvokeDragSession"));
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-04-19 10:18:31 +04:00
|
|
|
// If the previous source drag has not yet completed, signal handlers need
|
2012-05-03 10:24:20 +04:00
|
|
|
// to be removed from sGrabWidget and dragend needs to be dispatched to
|
2012-04-19 10:18:31 +04:00
|
|
|
// the source node, but we can't call EndDragSession yet because we don't
|
|
|
|
// know whether or not the drag succeeded.
|
|
|
|
if (mSourceNode) return NS_ERROR_NOT_AVAILABLE;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2019-08-20 15:43:02 +03:00
|
|
|
return nsBaseDragService::InvokeDragSession(aDOMNode, aPrincipal, aCsp,
|
2018-02-09 04:43:53 +03:00
|
|
|
aArrayTransferables, aActionType,
|
2015-08-10 22:56:47 +03:00
|
|
|
aContentPolicyType);
|
2015-10-21 12:16:40 +03:00
|
|
|
}
|
2008-03-19 23:18:41 +03:00
|
|
|
|
2015-10-21 12:16:40 +03:00
|
|
|
// nsBaseDragService
|
2016-10-18 21:56:20 +03:00
|
|
|
nsresult nsDragService::InvokeDragSessionImpl(
|
2018-08-07 16:32:08 +03:00
|
|
|
nsIArray* aArrayTransferables, const Maybe<CSSIntRegion>& aRegion,
|
2015-10-21 12:16:40 +03:00
|
|
|
uint32_t aActionType) {
|
2002-08-12 01:47:14 +04:00
|
|
|
// make sure that we have an array of transferables to use
|
|
|
|
if (!aArrayTransferables) return NS_ERROR_INVALID_ARG;
|
|
|
|
// set our reference to the transferables. this will also addref
|
|
|
|
// the transferables since we're going to hang onto this beyond the
|
|
|
|
// length of this call
|
|
|
|
mSourceDataItems = aArrayTransferables;
|
|
|
|
// get the list of items we offer for drags
|
2009-02-20 07:39:59 +03:00
|
|
|
GtkTargetList* sourceList = GetSourceList();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2009-02-20 07:39:59 +03:00
|
|
|
if (!sourceList) return NS_OK;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2009-02-20 07:39:59 +03:00
|
|
|
// save our action type
|
|
|
|
GdkDragAction action = GDK_ACTION_DEFAULT;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2009-02-20 07:39:59 +03:00
|
|
|
if (aActionType & DRAGDROP_ACTION_COPY)
|
|
|
|
action = (GdkDragAction)(action | GDK_ACTION_COPY);
|
|
|
|
if (aActionType & DRAGDROP_ACTION_MOVE)
|
|
|
|
action = (GdkDragAction)(action | GDK_ACTION_MOVE);
|
|
|
|
if (aActionType & DRAGDROP_ACTION_LINK)
|
|
|
|
action = (GdkDragAction)(action | GDK_ACTION_LINK);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-02-02 06:12:26 +04:00
|
|
|
// Create a fake event for the drag so we can pass the time (so to speak).
|
|
|
|
// If we don't do this, then, when the timestamp for the pending button
|
|
|
|
// release event is used for the ungrab, the ungrab can fail due to the
|
|
|
|
// timestamp being _earlier_ than CurrentTime.
|
2009-02-20 07:39:59 +03:00
|
|
|
GdkEvent event;
|
|
|
|
memset(&event, 0, sizeof(GdkEvent));
|
|
|
|
event.type = GDK_BUTTON_PRESS;
|
2012-09-14 05:56:59 +04:00
|
|
|
event.button.window = gtk_widget_get_window(mHiddenWidget);
|
2012-02-14 00:19:59 +04:00
|
|
|
event.button.time = nsWindow::GetLastUserInputTime();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-05-03 10:23:59 +04:00
|
|
|
// Put the drag widget in the window group of the source node so that the
|
|
|
|
// gtk_grab_add during gtk_drag_begin is effective.
|
2013-10-08 22:47:37 +04:00
|
|
|
// gtk_window_get_group(nullptr) returns the default window group.
|
2012-05-03 10:23:59 +04:00
|
|
|
GtkWindowGroup* window_group =
|
|
|
|
gtk_window_get_group(GetGtkWindow(mSourceDocument));
|
|
|
|
gtk_window_group_add_window(window_group, GTK_WINDOW(mHiddenWidget));
|
|
|
|
|
2012-09-14 05:56:59 +04:00
|
|
|
// Get device for event source
|
|
|
|
GdkDisplay* display = gdk_display_get_default();
|
|
|
|
GdkDeviceManager* device_manager = gdk_display_get_device_manager(display);
|
|
|
|
event.button.device = gdk_device_manager_get_client_pointer(device_manager);
|
2018-01-09 13:51:07 +03:00
|
|
|
|
2009-02-20 07:39:59 +03:00
|
|
|
// start our drag.
|
|
|
|
GdkDragContext* context =
|
|
|
|
gtk_drag_begin(mHiddenWidget, sourceList, action, 1, &event);
|
|
|
|
|
2015-10-21 12:16:40 +03:00
|
|
|
nsresult rv;
|
2011-07-04 18:39:08 +04:00
|
|
|
if (context) {
|
2012-02-02 06:10:43 +04:00
|
|
|
StartDragSession();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2011-01-27 04:58:55 +03:00
|
|
|
// GTK uses another hidden window for receiving mouse events.
|
2012-05-03 10:24:20 +04:00
|
|
|
sGrabWidget = gtk_window_group_get_current_grab(window_group);
|
|
|
|
if (sGrabWidget) {
|
|
|
|
g_object_ref(sGrabWidget);
|
|
|
|
// Only motion and key events are required but connect to
|
2011-01-27 04:58:55 +03:00
|
|
|
// "event-after" as this is never blocked by other handlers.
|
2012-05-03 10:24:20 +04:00
|
|
|
g_signal_connect(sGrabWidget, "event-after",
|
2012-04-17 05:00:25 +04:00
|
|
|
G_CALLBACK(OnSourceGrabEventAfter), this);
|
2011-07-04 18:39:08 +04:00
|
|
|
}
|
2012-04-17 05:00:25 +04:00
|
|
|
// We don't have a drag end point yet.
|
2015-10-26 23:33:13 +03:00
|
|
|
mEndDragPoint = LayoutDeviceIntPoint(-1, -1);
|
2015-10-21 12:16:40 +03:00
|
|
|
rv = NS_OK;
|
2018-11-30 13:46:48 +03:00
|
|
|
} else {
|
2011-07-04 18:39:08 +04:00
|
|
|
rv = NS_ERROR_FAILURE;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2002-08-12 01:47:14 +04:00
|
|
|
|
2009-02-20 07:39:59 +03:00
|
|
|
gtk_target_list_unref(sourceList);
|
|
|
|
|
|
|
|
return rv;
|
2002-08-12 01:47:14 +04:00
|
|
|
}
|
|
|
|
|
2014-01-29 04:10:33 +04:00
|
|
|
bool nsDragService::SetAlphaPixmap(SourceSurface* aSurface,
|
|
|
|
GdkDragContext* aContext, int32_t aXOffset,
|
|
|
|
int32_t aYOffset,
|
2016-10-19 22:01:39 +03:00
|
|
|
const LayoutDeviceIntRect& dragRect) {
|
2008-06-18 13:20:29 +04:00
|
|
|
GdkScreen* screen = gtk_widget_get_screen(mHiddenWidget);
|
|
|
|
|
|
|
|
// Transparent drag icons need, like a lot of transparency-related things,
|
|
|
|
// a compositing X window manager
|
|
|
|
if (!gdk_screen_is_composited(screen)) return false;
|
|
|
|
|
2015-07-28 14:13:00 +03:00
|
|
|
#ifdef cairo_image_surface_create
|
|
|
|
# error "Looks like we're including Mozilla's cairo instead of system cairo"
|
|
|
|
#endif
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-07-28 14:13:00 +03:00
|
|
|
// TODO: grab X11 pixmap or image data instead of expensive readback.
|
|
|
|
cairo_surface_t* surf = cairo_image_surface_create(
|
|
|
|
CAIRO_FORMAT_ARGB32, dragRect.width, dragRect.height);
|
|
|
|
if (!surf) return false;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-08-12 00:54:08 +03:00
|
|
|
RefPtr<DrawTarget> dt = gfxPlatform::CreateDrawTargetForData(
|
|
|
|
cairo_image_surface_get_data(surf),
|
2016-10-19 22:01:39 +03:00
|
|
|
nsIntSize(dragRect.width, dragRect.height),
|
2015-07-28 14:13:00 +03:00
|
|
|
cairo_image_surface_get_stride(surf), SurfaceFormat::B8G8R8A8);
|
|
|
|
if (!dt) return false;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-07-28 14:13:00 +03:00
|
|
|
dt->ClearRect(Rect(0, 0, dragRect.width, dragRect.height));
|
|
|
|
dt->DrawSurface(
|
|
|
|
aSurface, Rect(0, 0, dragRect.width, dragRect.height),
|
|
|
|
Rect(0, 0, dragRect.width, dragRect.height), DrawSurfaceOptions(),
|
|
|
|
DrawOptions(DRAG_IMAGE_ALPHA_LEVEL, CompositionOp::OP_SOURCE));
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-07-28 14:13:00 +03:00
|
|
|
cairo_surface_mark_dirty(surf);
|
|
|
|
cairo_surface_set_device_offset(surf, -aXOffset, -aYOffset);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-07-28 14:13:00 +03:00
|
|
|
// Ensure that the surface is drawn at the correct scale on HiDPI displays.
|
|
|
|
static auto sCairoSurfaceSetDeviceScalePtr =
|
|
|
|
(void (*)(cairo_surface_t*, double, double))dlsym(
|
|
|
|
RTLD_DEFAULT, "cairo_surface_set_device_scale");
|
|
|
|
if (sCairoSurfaceSetDeviceScalePtr) {
|
2019-12-03 17:03:01 +03:00
|
|
|
gint scale = mozilla::widget::ScreenHelperGTK::GetGTKMonitorScaleFactor();
|
2015-07-28 14:13:00 +03:00
|
|
|
sCairoSurfaceSetDeviceScalePtr(surf, scale, scale);
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_drag_set_icon_surface(aContext, surf);
|
|
|
|
cairo_surface_destroy(surf);
|
|
|
|
return true;
|
2008-06-18 13:20:29 +04:00
|
|
|
}
|
|
|
|
|
2002-08-12 01:47:14 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDragService::StartDragSession() {
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(sDragLm, LogLevel::Debug, ("nsDragService::StartDragSession"));
|
2002-08-12 01:47:14 +04:00
|
|
|
return nsBaseDragService::StartDragSession();
|
|
|
|
}
|
2017-12-19 13:38:59 +03:00
|
|
|
|
2002-08-12 01:47:14 +04:00
|
|
|
NS_IMETHODIMP
|
2017-02-17 06:29:42 +03:00
|
|
|
nsDragService::EndDragSession(bool aDoneDrag, uint32_t aKeyModifiers) {
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(sDragLm, LogLevel::Debug,
|
|
|
|
("nsDragService::EndDragSession %d", aDoneDrag));
|
2011-01-27 04:58:55 +03:00
|
|
|
|
2012-05-03 10:24:20 +04:00
|
|
|
if (sGrabWidget) {
|
|
|
|
g_signal_handlers_disconnect_by_func(
|
2012-04-17 05:00:25 +04:00
|
|
|
sGrabWidget, FuncToGpointer(OnSourceGrabEventAfter), this);
|
2012-05-03 10:24:20 +04:00
|
|
|
g_object_unref(sGrabWidget);
|
2013-10-08 22:47:37 +04:00
|
|
|
sGrabWidget = nullptr;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2011-01-27 04:58:55 +03:00
|
|
|
if (sMotionEventTimerID) {
|
|
|
|
g_source_remove(sMotionEventTimerID);
|
|
|
|
sMotionEventTimerID = 0;
|
|
|
|
}
|
2012-05-03 10:24:20 +04:00
|
|
|
if (sMotionEvent) {
|
|
|
|
gdk_event_free(sMotionEvent);
|
2013-10-08 22:47:37 +04:00
|
|
|
sMotionEvent = nullptr;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
}
|
2011-01-27 04:58:55 +03:00
|
|
|
|
2002-08-12 01:47:14 +04:00
|
|
|
// unset our drag action
|
|
|
|
SetDragAction(DRAGDROP_ACTION_NONE);
|
2017-12-19 13:38:59 +03:00
|
|
|
|
2015-04-08 21:48:11 +03:00
|
|
|
// We're done with the drag context.
|
|
|
|
mTargetDragContextForRemote = nullptr;
|
2018-04-05 17:16:43 +03:00
|
|
|
#ifdef MOZ_WAYLAND
|
|
|
|
mTargetWaylandDragContextForRemote = nullptr;
|
|
|
|
#endif
|
2015-04-08 21:48:11 +03:00
|
|
|
|
2017-02-17 06:29:42 +03:00
|
|
|
return nsBaseDragService::EndDragSession(aDoneDrag, aKeyModifiers);
|
2002-08-12 01:47:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// nsIDragSession
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsDragService::SetCanDrop(bool aCanDrop) {
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(sDragLm, LogLevel::Debug, ("nsDragService::SetCanDrop %d", aCanDrop));
|
2002-08-12 01:47:14 +04:00
|
|
|
mCanDrop = aCanDrop;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsDragService::GetCanDrop(bool* aCanDrop) {
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(sDragLm, LogLevel::Debug, ("nsDragService::GetCanDrop"));
|
2002-08-12 01:47:14 +04:00
|
|
|
*aCanDrop = mCanDrop;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-10-14 15:28:50 +03:00
|
|
|
static void UTF16ToNewUTF8(const char16_t* aUTF16, uint32_t aUTF16Len,
|
|
|
|
char** aUTF8, uint32_t* aUTF8Len) {
|
|
|
|
nsDependentSubstring utf16(aUTF16, aUTF16Len);
|
|
|
|
*aUTF8 = ToNewUTF8String(utf16, aUTF8Len);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void UTF8ToNewUTF16(const char* aUTF8, uint32_t aUTF8Len,
|
|
|
|
char16_t** aUTF16, uint32_t* aUTF16Len) {
|
|
|
|
nsDependentCSubstring utf8(aUTF8, aUTF8Len);
|
|
|
|
*aUTF16 = UTF8ToNewUnicode(utf8, aUTF16Len);
|
|
|
|
}
|
|
|
|
|
2002-08-12 01:47:14 +04:00
|
|
|
// count the number of URIs in some text/uri-list format data.
|
|
|
|
static uint32_t CountTextUriListItems(const char* data, uint32_t datalen) {
|
|
|
|
const char* p = data;
|
|
|
|
const char* endPtr = p + datalen;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t count = 0;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2002-08-12 01:47:14 +04:00
|
|
|
while (p < endPtr) {
|
|
|
|
// skip whitespace (if any)
|
|
|
|
while (p < endPtr && *p != '\0' && isspace(*p)) p++;
|
|
|
|
// if we aren't at the end of the line ...
|
|
|
|
if (p != endPtr && *p != '\0' && *p != '\n' && *p != '\r') count++;
|
|
|
|
// skip to the end of the line
|
|
|
|
while (p < endPtr && *p != '\0' && *p != '\n') p++;
|
|
|
|
p++; // skip the actual newline as well.
|
|
|
|
}
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
// extract an item from text/uri-list formatted data and convert it to
|
|
|
|
// unicode.
|
|
|
|
static void GetTextUriListItem(const char* data, uint32_t datalen,
|
2014-01-04 19:02:17 +04:00
|
|
|
uint32_t aItemIndex, char16_t** convertedText,
|
2015-10-14 15:28:50 +03:00
|
|
|
uint32_t* convertedTextLen) {
|
2002-08-12 01:47:14 +04:00
|
|
|
const char* p = data;
|
|
|
|
const char* endPtr = p + datalen;
|
|
|
|
unsigned int count = 0;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
*convertedText = nullptr;
|
2002-08-12 01:47:14 +04:00
|
|
|
while (p < endPtr) {
|
|
|
|
// skip whitespace (if any)
|
|
|
|
while (p < endPtr && *p != '\0' && isspace(*p)) p++;
|
|
|
|
// if we aren't at the end of the line, we have a url
|
|
|
|
if (p != endPtr && *p != '\0' && *p != '\n' && *p != '\r') count++;
|
|
|
|
// this is the item we are after ...
|
|
|
|
if (aItemIndex + 1 == count) {
|
|
|
|
const char* q = p;
|
|
|
|
while (q < endPtr && *q != '\0' && *q != '\n' && *q != '\r') q++;
|
2015-10-14 15:28:50 +03:00
|
|
|
UTF8ToNewUTF16(p, q - p, convertedText, convertedTextLen);
|
2002-08-12 01:47:14 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
// skip to the end of the line
|
|
|
|
while (p < endPtr && *p != '\0' && *p != '\n') p++;
|
|
|
|
p++; // skip the actual newline as well.
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2002-08-12 01:47:14 +04:00
|
|
|
|
|
|
|
// didn't find the desired item, so just pass the whole lot
|
|
|
|
if (!*convertedText) {
|
2015-10-14 15:28:50 +03:00
|
|
|
UTF8ToNewUTF16(data, datalen, convertedText, convertedTextLen);
|
2002-08-12 01:47:14 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsDragService::GetNumDropItems(uint32_t* aNumItems) {
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(sDragLm, LogLevel::Debug, ("nsDragService::GetNumDropItems"));
|
2012-04-17 05:00:26 +04:00
|
|
|
|
|
|
|
if (!mTargetWidget) {
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(sDragLm, LogLevel::Debug, ("*** warning: GetNumDropItems \
|
2012-04-17 05:00:26 +04:00
|
|
|
called without a valid target widget!\n"));
|
|
|
|
*aNumItems = 0;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isList = IsTargetContextList();
|
2002-08-12 01:47:14 +04:00
|
|
|
if (isList)
|
2016-10-18 21:56:20 +03:00
|
|
|
mSourceDataItems->GetLength(aNumItems);
|
2002-08-12 01:47:14 +04:00
|
|
|
else {
|
|
|
|
GdkAtom gdkFlavor = gdk_atom_intern(gTextUriListType, FALSE);
|
|
|
|
GetTargetDragData(gdkFlavor);
|
|
|
|
if (mTargetDragData) {
|
2007-07-08 11:08:04 +04:00
|
|
|
const char* data = reinterpret_cast<char*>(mTargetDragData);
|
2002-08-12 01:47:14 +04:00
|
|
|
*aNumItems = CountTextUriListItems(data, mTargetDragDataLen);
|
|
|
|
} else
|
|
|
|
*aNumItems = 1;
|
|
|
|
}
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(sDragLm, LogLevel::Debug, ("%d items", *aNumItems));
|
2002-08-12 01:47:14 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDragService::GetData(nsITransferable* aTransferable, uint32_t aItemIndex) {
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(sDragLm, LogLevel::Debug, ("nsDragService::GetData %d", aItemIndex));
|
2002-08-12 01:47:14 +04:00
|
|
|
|
|
|
|
// make sure that we have a transferable
|
|
|
|
if (!aTransferable) return NS_ERROR_INVALID_ARG;
|
|
|
|
|
2012-04-17 05:00:26 +04:00
|
|
|
if (!mTargetWidget) {
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(sDragLm, LogLevel::Debug, ("*** warning: GetData \
|
2012-04-17 05:00:26 +04:00
|
|
|
called without a valid target widget!\n"));
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2002-08-12 01:47:14 +04:00
|
|
|
// get flavor list that includes all acceptable flavors (including
|
2018-10-10 23:25:54 +03:00
|
|
|
// ones obtained through conversion).
|
|
|
|
nsTArray<nsCString> flavors;
|
|
|
|
nsresult rv = aTransferable->FlavorsTransferableCanImport(flavors);
|
2002-08-12 01:47:14 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
// check to see if this is an internal list
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isList = IsTargetContextList();
|
2002-08-12 01:47:14 +04:00
|
|
|
|
|
|
|
if (isList) {
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(sDragLm, LogLevel::Debug, ("it's a list..."));
|
2002-08-12 01:47:14 +04:00
|
|
|
// find a matching flavor
|
2018-10-10 23:25:54 +03:00
|
|
|
for (uint32_t i = 0; i < flavors.Length(); ++i) {
|
|
|
|
nsCString& flavorStr = flavors[i];
|
|
|
|
MOZ_LOG(sDragLm, LogLevel::Debug, ("flavor is %s\n", flavorStr.get()));
|
|
|
|
// get the item with the right index
|
|
|
|
nsCOMPtr<nsITransferable> item =
|
|
|
|
do_QueryElementAt(mSourceDataItems, aItemIndex);
|
2007-07-12 21:20:21 +04:00
|
|
|
if (!item) continue;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-10-10 23:25:54 +03:00
|
|
|
nsCOMPtr<nsISupports> data;
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(sDragLm, LogLevel::Debug,
|
2018-10-10 23:25:54 +03:00
|
|
|
("trying to get transfer data for %s\n", flavorStr.get()));
|
|
|
|
rv = item->GetTransferData(flavorStr.get(), getter_AddRefs(data));
|
|
|
|
if (NS_FAILED(rv)) {
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(sDragLm, LogLevel::Debug, ("failed.\n"));
|
2007-07-12 21:20:21 +04:00
|
|
|
continue;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(sDragLm, LogLevel::Debug, ("succeeded.\n"));
|
2018-10-10 23:25:54 +03:00
|
|
|
rv = aTransferable->SetTransferData(flavorStr.get(), data);
|
2007-07-12 21:20:21 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
2018-10-10 23:25:54 +03:00
|
|
|
MOZ_LOG(sDragLm, LogLevel::Debug,
|
2007-07-12 21:20:21 +04:00
|
|
|
("fail to set transfer data into transferable!\n"));
|
|
|
|
continue;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2007-07-12 21:20:21 +04:00
|
|
|
// ok, we got the data
|
|
|
|
return NS_OK;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2002-08-12 01:47:14 +04:00
|
|
|
// if we got this far, we failed
|
|
|
|
return NS_ERROR_FAILURE;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2002-08-12 01:47:14 +04:00
|
|
|
// Now walk down the list of flavors. When we find one that is
|
|
|
|
// actually present, copy out the data into the transferable in that
|
|
|
|
// format. SetTransferData() implicitly handles conversions.
|
2018-10-10 23:25:54 +03:00
|
|
|
for (uint32_t i = 0; i < flavors.Length(); ++i) {
|
|
|
|
nsCString& flavorStr = flavors[i];
|
|
|
|
GdkAtom gdkFlavor = gdk_atom_intern(flavorStr.get(), FALSE);
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(sDragLm, LogLevel::Debug,
|
2018-10-10 23:25:54 +03:00
|
|
|
("looking for data in type %s, gdk flavor %p\n", flavorStr.get(),
|
|
|
|
gdkFlavor));
|
|
|
|
bool dataFound = false;
|
|
|
|
if (gdkFlavor) {
|
|
|
|
GetTargetDragData(gdkFlavor);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2018-10-10 23:25:54 +03:00
|
|
|
if (mTargetDragData) {
|
|
|
|
MOZ_LOG(sDragLm, LogLevel::Debug, ("dataFound = true\n"));
|
|
|
|
dataFound = true;
|
2018-11-30 13:46:48 +03:00
|
|
|
} else {
|
2018-10-10 23:25:54 +03:00
|
|
|
MOZ_LOG(sDragLm, LogLevel::Debug, ("dataFound = false\n"));
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-10-10 23:25:54 +03:00
|
|
|
// Dragging and dropping from the file manager would cause us
|
|
|
|
// to parse the source text as a nsIFile URL.
|
|
|
|
if (flavorStr.EqualsLiteral(kFileMime)) {
|
|
|
|
gdkFlavor = gdk_atom_intern(kTextMime, FALSE);
|
|
|
|
GetTargetDragData(gdkFlavor);
|
|
|
|
if (!mTargetDragData) {
|
|
|
|
gdkFlavor = gdk_atom_intern(gTextUriListType, FALSE);
|
|
|
|
GetTargetDragData(gdkFlavor);
|
|
|
|
}
|
|
|
|
if (mTargetDragData) {
|
|
|
|
const char* text = static_cast<char*>(mTargetDragData);
|
|
|
|
char16_t* convertedText = nullptr;
|
|
|
|
uint32_t convertedTextLen = 0;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-10-10 23:25:54 +03:00
|
|
|
GetTextUriListItem(text, mTargetDragDataLen, aItemIndex,
|
|
|
|
&convertedText, &convertedTextLen);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-10-10 23:25:54 +03:00
|
|
|
if (convertedText) {
|
|
|
|
nsCOMPtr<nsIIOService> ioService = do_GetIOService(&rv);
|
|
|
|
nsCOMPtr<nsIURI> fileURI;
|
|
|
|
rv = ioService->NewURI(NS_ConvertUTF16toUTF8(convertedText),
|
|
|
|
nullptr, nullptr, getter_AddRefs(fileURI));
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
nsCOMPtr<nsIFileURL> fileURL = do_QueryInterface(fileURI, &rv);
|
2008-04-17 00:29:06 +04:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2018-10-10 23:25:54 +03:00
|
|
|
nsCOMPtr<nsIFile> file;
|
|
|
|
rv = fileURL->GetFile(getter_AddRefs(file));
|
2008-12-06 19:27:53 +03:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2018-10-10 23:25:54 +03:00
|
|
|
// The common wrapping code at the end of
|
|
|
|
// this function assumes the data is text
|
|
|
|
// and calls text-specific operations.
|
|
|
|
// Make a secret hideout here for nsIFile
|
|
|
|
// objects and return early.
|
2018-11-20 20:00:09 +03:00
|
|
|
aTransferable->SetTransferData(flavorStr.get(), file);
|
2018-10-10 23:25:54 +03:00
|
|
|
g_free(convertedText);
|
|
|
|
return NS_OK;
|
2008-03-08 12:56:44 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2018-10-10 23:25:54 +03:00
|
|
|
}
|
|
|
|
g_free(convertedText);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2007-07-12 21:20:21 +04:00
|
|
|
continue;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
}
|
2008-03-08 12:56:44 +03:00
|
|
|
|
2018-10-10 23:25:54 +03:00
|
|
|
// if we are looking for text/unicode and we fail to find it
|
|
|
|
// on the clipboard first, try again with text/plain. If that
|
|
|
|
// is present, convert it to unicode.
|
|
|
|
if (flavorStr.EqualsLiteral(kUnicodeMime)) {
|
|
|
|
MOZ_LOG(sDragLm, LogLevel::Debug,
|
|
|
|
("we were looking for text/unicode... \
|
|
|
|
trying with text/plain;charset=utf-8\n"));
|
|
|
|
gdkFlavor = gdk_atom_intern(gTextPlainUTF8Type, FALSE);
|
|
|
|
GetTargetDragData(gdkFlavor);
|
|
|
|
if (mTargetDragData) {
|
|
|
|
MOZ_LOG(sDragLm, LogLevel::Debug, ("Got textplain data\n"));
|
|
|
|
const char* castedText = reinterpret_cast<char*>(mTargetDragData);
|
|
|
|
char16_t* convertedText = nullptr;
|
|
|
|
NS_ConvertUTF8toUTF16 ucs2string(castedText, mTargetDragDataLen);
|
2020-05-17 09:58:48 +03:00
|
|
|
convertedText = ToNewUnicode(ucs2string, mozilla::fallible);
|
2018-10-10 23:25:54 +03:00
|
|
|
if (convertedText) {
|
|
|
|
MOZ_LOG(sDragLm, LogLevel::Debug,
|
|
|
|
("successfully converted plain text \
|
|
|
|
to unicode.\n"));
|
|
|
|
// out with the old, in with the new
|
|
|
|
g_free(mTargetDragData);
|
|
|
|
mTargetDragData = convertedText;
|
|
|
|
mTargetDragDataLen = ucs2string.Length() * 2;
|
|
|
|
dataFound = true;
|
|
|
|
} // if plain text data on clipboard
|
|
|
|
} else {
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(sDragLm, LogLevel::Debug,
|
2002-08-12 01:47:14 +04:00
|
|
|
("we were looking for text/unicode... \
|
2018-10-10 23:25:54 +03:00
|
|
|
trying again with text/plain\n"));
|
|
|
|
gdkFlavor = gdk_atom_intern(kTextMime, FALSE);
|
2002-08-12 01:47:14 +04:00
|
|
|
GetTargetDragData(gdkFlavor);
|
|
|
|
if (mTargetDragData) {
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(sDragLm, LogLevel::Debug, ("Got textplain data\n"));
|
2007-07-08 11:08:04 +04:00
|
|
|
const char* castedText = reinterpret_cast<char*>(mTargetDragData);
|
2014-01-04 19:02:17 +04:00
|
|
|
char16_t* convertedText = nullptr;
|
2018-10-10 23:25:54 +03:00
|
|
|
uint32_t convertedTextLen = 0;
|
|
|
|
UTF8ToNewUTF16(castedText, mTargetDragDataLen, &convertedText,
|
|
|
|
&convertedTextLen);
|
2002-08-12 01:47:14 +04:00
|
|
|
if (convertedText) {
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(sDragLm, LogLevel::Debug,
|
2002-08-12 01:47:14 +04:00
|
|
|
("successfully converted plain text \
|
|
|
|
to unicode.\n"));
|
|
|
|
// out with the old, in with the new
|
|
|
|
g_free(mTargetDragData);
|
|
|
|
mTargetDragData = convertedText;
|
2018-10-10 23:25:54 +03:00
|
|
|
mTargetDragDataLen = convertedTextLen * 2;
|
2011-10-03 11:56:21 +04:00
|
|
|
dataFound = true;
|
2002-08-12 01:47:14 +04:00
|
|
|
} // if plain text data on clipboard
|
2018-10-10 23:25:54 +03:00
|
|
|
} // if plain text flavor present
|
|
|
|
} // if plain text charset=utf-8 flavor present
|
|
|
|
} // if looking for text/unicode
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-10-10 23:25:54 +03:00
|
|
|
// if we are looking for text/x-moz-url and we failed to find
|
|
|
|
// it on the clipboard, try again with text/uri-list, and then
|
|
|
|
// _NETSCAPE_URL
|
|
|
|
if (flavorStr.EqualsLiteral(kURLMime)) {
|
|
|
|
MOZ_LOG(sDragLm, LogLevel::Debug,
|
|
|
|
("we were looking for text/x-moz-url...\
|
|
|
|
trying again with text/uri-list\n"));
|
|
|
|
gdkFlavor = gdk_atom_intern(gTextUriListType, FALSE);
|
|
|
|
GetTargetDragData(gdkFlavor);
|
|
|
|
if (mTargetDragData) {
|
|
|
|
MOZ_LOG(sDragLm, LogLevel::Debug, ("Got text/uri-list data\n"));
|
|
|
|
const char* data = reinterpret_cast<char*>(mTargetDragData);
|
|
|
|
char16_t* convertedText = nullptr;
|
|
|
|
uint32_t convertedTextLen = 0;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-10-10 23:25:54 +03:00
|
|
|
GetTextUriListItem(data, mTargetDragDataLen, aItemIndex,
|
|
|
|
&convertedText, &convertedTextLen);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-10-10 23:25:54 +03:00
|
|
|
if (convertedText) {
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(sDragLm, LogLevel::Debug, ("successfully converted \
|
2018-10-10 23:25:54 +03:00
|
|
|
_NETSCAPE_URL to unicode.\n"));
|
|
|
|
// out with the old, in with the new
|
|
|
|
g_free(mTargetDragData);
|
|
|
|
mTargetDragData = convertedText;
|
|
|
|
mTargetDragDataLen = convertedTextLen * 2;
|
|
|
|
dataFound = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
MOZ_LOG(sDragLm, LogLevel::Debug,
|
|
|
|
("failed to get text/uri-list data\n"));
|
|
|
|
}
|
|
|
|
if (!dataFound) {
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(sDragLm, LogLevel::Debug,
|
2002-08-12 01:47:14 +04:00
|
|
|
("we were looking for text/x-moz-url...\
|
2018-10-10 23:25:54 +03:00
|
|
|
trying again with _NETSCAP_URL\n"));
|
|
|
|
gdkFlavor = gdk_atom_intern(gMozUrlType, FALSE);
|
2002-08-12 01:47:14 +04:00
|
|
|
GetTargetDragData(gdkFlavor);
|
|
|
|
if (mTargetDragData) {
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(sDragLm, LogLevel::Debug, ("Got _NETSCAPE_URL data\n"));
|
2018-10-10 23:25:54 +03:00
|
|
|
const char* castedText = reinterpret_cast<char*>(mTargetDragData);
|
2014-01-04 19:02:17 +04:00
|
|
|
char16_t* convertedText = nullptr;
|
2015-10-14 15:28:50 +03:00
|
|
|
uint32_t convertedTextLen = 0;
|
2018-10-10 23:25:54 +03:00
|
|
|
UTF8ToNewUTF16(castedText, mTargetDragDataLen, &convertedText,
|
|
|
|
&convertedTextLen);
|
2002-08-12 01:47:14 +04:00
|
|
|
if (convertedText) {
|
2018-10-10 23:25:54 +03:00
|
|
|
MOZ_LOG(sDragLm, LogLevel::Debug,
|
|
|
|
("successfully converted _NETSCAPE_URL \
|
|
|
|
to unicode.\n"));
|
2002-08-12 01:47:14 +04:00
|
|
|
// out with the old, in with the new
|
|
|
|
g_free(mTargetDragData);
|
|
|
|
mTargetDragData = convertedText;
|
|
|
|
mTargetDragDataLen = convertedTextLen * 2;
|
2011-10-03 11:56:21 +04:00
|
|
|
dataFound = true;
|
2018-10-10 23:25:54 +03:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
MOZ_LOG(sDragLm, LogLevel::Debug,
|
|
|
|
("failed to get _NETSCAPE_URL data\n"));
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2018-10-10 23:25:54 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2018-10-10 23:25:54 +03:00
|
|
|
} // else we try one last ditch effort to find our data
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-10-10 23:25:54 +03:00
|
|
|
if (dataFound) {
|
|
|
|
if (!flavorStr.EqualsLiteral(kCustomTypesMime)) {
|
|
|
|
// the DOM only wants LF, so convert from MacOS line endings
|
|
|
|
// to DOM line endings.
|
|
|
|
nsLinebreakHelpers::ConvertPlatformToDOMLinebreaks(
|
2018-04-05 17:16:43 +03:00
|
|
|
flavorStr, &mTargetDragData,
|
2018-10-10 23:25:54 +03:00
|
|
|
reinterpret_cast<int*>(&mTargetDragDataLen));
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2018-10-10 23:25:54 +03:00
|
|
|
// put it into the transferable.
|
|
|
|
nsCOMPtr<nsISupports> genericDataWrapper;
|
|
|
|
nsPrimitiveHelpers::CreatePrimitiveForData(
|
2012-09-18 03:05:05 +04:00
|
|
|
flavorStr, mTargetDragData, mTargetDragDataLen,
|
2018-10-10 23:25:54 +03:00
|
|
|
getter_AddRefs(genericDataWrapper));
|
2018-11-20 20:00:09 +03:00
|
|
|
aTransferable->SetTransferData(flavorStr.get(), genericDataWrapper);
|
2018-10-10 23:25:54 +03:00
|
|
|
// we found one, get out of this loop!
|
|
|
|
MOZ_LOG(sDragLm, LogLevel::Debug, ("dataFound and converted!\n"));
|
2018-11-30 13:46:48 +03:00
|
|
|
break;
|
2018-10-10 23:25:54 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2002-08-12 01:47:14 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDragService::IsDataFlavorSupported(const char* aDataFlavor, bool* _retval) {
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(sDragLm, LogLevel::Debug,
|
|
|
|
("nsDragService::IsDataFlavorSupported %s", aDataFlavor));
|
2002-08-12 01:47:14 +04:00
|
|
|
if (!_retval) return NS_ERROR_INVALID_ARG;
|
|
|
|
|
|
|
|
// set this to no by default
|
2011-10-03 11:56:21 +04:00
|
|
|
*_retval = false;
|
2002-08-12 01:47:14 +04:00
|
|
|
|
|
|
|
// check to make sure that we have a drag object set, here
|
2012-04-17 05:00:26 +04:00
|
|
|
if (!mTargetWidget) {
|
2002-08-12 01:47:14 +04:00
|
|
|
MOZ_LOG(sDragLm, LogLevel::Debug, ("*** warning: IsDataFlavorSupported \
|
2012-04-17 05:00:26 +04:00
|
|
|
called without a valid target widget!\n"));
|
2002-08-12 01:47:14 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check to see if the target context is a list.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isList = IsTargetContextList();
|
2002-08-12 01:47:14 +04:00
|
|
|
// if it is, just look in the internal data since we are the source
|
|
|
|
// for it.
|
|
|
|
if (isList) {
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(sDragLm, LogLevel::Debug, ("It's a list.."));
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t numDragItems = 0;
|
2002-08-12 01:47:14 +04:00
|
|
|
// if we don't have mDataItems we didn't start this drag so it's
|
|
|
|
// an external client trying to fool us.
|
|
|
|
if (!mSourceDataItems) return NS_OK;
|
2016-10-18 21:56:20 +03:00
|
|
|
mSourceDataItems->GetLength(&numDragItems);
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t itemIndex = 0; itemIndex < numDragItems; ++itemIndex) {
|
2016-10-18 21:56:20 +03:00
|
|
|
nsCOMPtr<nsITransferable> currItem =
|
|
|
|
do_QueryElementAt(mSourceDataItems, itemIndex);
|
2002-08-12 01:47:14 +04:00
|
|
|
if (currItem) {
|
2018-10-10 23:25:54 +03:00
|
|
|
nsTArray<nsCString> flavors;
|
|
|
|
currItem->FlavorsTransferableCanExport(flavors);
|
|
|
|
for (uint32_t i = 0; i < flavors.Length(); ++i) {
|
|
|
|
MOZ_LOG(sDragLm, LogLevel::Debug,
|
|
|
|
("checking %s against %s\n", flavors[i].get(), aDataFlavor));
|
|
|
|
if (flavors[i].Equals(aDataFlavor)) {
|
|
|
|
MOZ_LOG(sDragLm, LogLevel::Debug, ("boioioioiooioioioing!\n"));
|
|
|
|
*_retval = true;
|
2002-08-12 01:47:14 +04:00
|
|
|
}
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2002-08-12 01:47:14 +04:00
|
|
|
}
|
|
|
|
return NS_OK;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2002-08-12 01:47:14 +04:00
|
|
|
|
|
|
|
// check the target context vs. this flavor, one at a time
|
2018-04-05 17:16:43 +03:00
|
|
|
GList* tmp = nullptr;
|
|
|
|
if (mTargetDragContext) {
|
|
|
|
tmp = gdk_drag_context_list_targets(mTargetDragContext);
|
|
|
|
}
|
|
|
|
#ifdef MOZ_WAYLAND
|
2018-05-24 12:51:17 +03:00
|
|
|
else if (mTargetWaylandDragContext) {
|
2018-04-05 17:16:43 +03:00
|
|
|
tmp = mTargetWaylandDragContext->GetTargets();
|
|
|
|
}
|
|
|
|
GList* tmp_head = tmp;
|
2018-05-24 12:51:17 +03:00
|
|
|
#endif
|
2018-04-05 17:16:43 +03:00
|
|
|
|
|
|
|
for (; tmp; tmp = tmp->next) {
|
2008-01-05 08:43:22 +03:00
|
|
|
/* Bug 331198 */
|
|
|
|
GdkAtom atom = GDK_POINTER_TO_ATOM(tmp->data);
|
2013-10-08 22:47:37 +04:00
|
|
|
gchar* name = nullptr;
|
2002-08-12 01:47:14 +04:00
|
|
|
name = gdk_atom_name(atom);
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(sDragLm, LogLevel::Debug,
|
2002-08-12 01:47:14 +04:00
|
|
|
("checking %s against %s\n", name, aDataFlavor));
|
2009-11-25 01:25:42 +03:00
|
|
|
if (name && (strcmp(name, aDataFlavor) == 0)) {
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(sDragLm, LogLevel::Debug, ("good!\n"));
|
2011-10-03 11:56:21 +04:00
|
|
|
*_retval = true;
|
2002-08-12 01:47:14 +04:00
|
|
|
}
|
|
|
|
// check for automatic text/uri-list -> text/x-moz-url mapping
|
2009-11-25 01:25:42 +03:00
|
|
|
if (!*_retval && name && (strcmp(name, gTextUriListType) == 0) &&
|
2013-07-01 19:24:42 +04:00
|
|
|
(strcmp(aDataFlavor, kURLMime) == 0 ||
|
|
|
|
strcmp(aDataFlavor, kFileMime) == 0)) {
|
2002-08-12 01:47:14 +04:00
|
|
|
MOZ_LOG(sDragLm, LogLevel::Debug, ("good! ( it's text/uri-list and \
|
|
|
|
we're checking against text/x-moz-url )\n"));
|
2011-10-03 11:56:21 +04:00
|
|
|
*_retval = true;
|
2002-08-12 01:47:14 +04:00
|
|
|
}
|
|
|
|
// check for automatic _NETSCAPE_URL -> text/x-moz-url mapping
|
2009-11-25 01:25:42 +03:00
|
|
|
if (!*_retval && name && (strcmp(name, gMozUrlType) == 0) &&
|
|
|
|
(strcmp(aDataFlavor, kURLMime) == 0)) {
|
2002-08-12 01:47:14 +04:00
|
|
|
MOZ_LOG(sDragLm, LogLevel::Debug, ("good! ( it's _NETSCAPE_URL and \
|
|
|
|
we're checking against text/x-moz-url )\n"));
|
2011-10-03 11:56:21 +04:00
|
|
|
*_retval = true;
|
2002-08-12 01:47:14 +04:00
|
|
|
}
|
|
|
|
// check for auto text/plain -> text/unicode mapping
|
2009-11-25 01:25:42 +03:00
|
|
|
if (!*_retval && name && (strcmp(name, kTextMime) == 0) &&
|
|
|
|
((strcmp(aDataFlavor, kUnicodeMime) == 0) ||
|
|
|
|
(strcmp(aDataFlavor, kFileMime) == 0))) {
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(sDragLm, LogLevel::Debug,
|
2002-08-12 01:47:14 +04:00
|
|
|
("good! ( it's text plain and we're checking \
|
2008-03-08 12:56:44 +03:00
|
|
|
against text/unicode or application/x-moz-file)\n"));
|
2011-10-03 11:56:21 +04:00
|
|
|
*_retval = true;
|
2002-08-12 01:47:14 +04:00
|
|
|
}
|
|
|
|
g_free(name);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2018-04-05 17:16:43 +03:00
|
|
|
|
2018-05-24 12:51:17 +03:00
|
|
|
#ifdef MOZ_WAYLAND
|
2018-04-05 17:16:43 +03:00
|
|
|
// mTargetWaylandDragContext->GetTargets allocates the list
|
|
|
|
// so we need to free it here.
|
2018-05-24 12:51:17 +03:00
|
|
|
if (!mTargetDragContext && tmp_head) {
|
2018-04-05 17:16:43 +03:00
|
|
|
g_list_free(tmp_head);
|
|
|
|
}
|
2018-05-24 12:51:17 +03:00
|
|
|
#endif
|
2018-04-05 17:16:43 +03:00
|
|
|
|
2002-08-12 01:47:14 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-04-08 21:48:11 +03:00
|
|
|
void nsDragService::ReplyToDragMotion(GdkDragContext* aDragContext) {
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(sDragLm, LogLevel::Debug,
|
2012-04-19 10:18:31 +04:00
|
|
|
("nsDragService::ReplyToDragMotion %d", mCanDrop));
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-04-19 10:18:31 +04:00
|
|
|
GdkDragAction action = (GdkDragAction)0;
|
2002-08-12 01:47:14 +04:00
|
|
|
if (mCanDrop) {
|
|
|
|
// notify the dragger if we can drop
|
|
|
|
switch (mDragAction) {
|
|
|
|
case DRAGDROP_ACTION_COPY:
|
|
|
|
action = GDK_ACTION_COPY;
|
|
|
|
break;
|
|
|
|
case DRAGDROP_ACTION_LINK:
|
|
|
|
action = GDK_ACTION_LINK;
|
|
|
|
break;
|
2015-04-08 21:48:11 +03:00
|
|
|
case DRAGDROP_ACTION_NONE:
|
|
|
|
action = (GdkDragAction)0;
|
|
|
|
break;
|
2002-08-12 01:47:14 +04:00
|
|
|
default:
|
|
|
|
action = GDK_ACTION_MOVE;
|
|
|
|
break;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2002-08-12 01:47:14 +04:00
|
|
|
|
2015-04-08 21:48:11 +03:00
|
|
|
gdk_drag_status(aDragContext, action, mTargetTime);
|
2002-08-12 01:47:14 +04:00
|
|
|
}
|
|
|
|
|
2018-04-05 17:16:43 +03:00
|
|
|
#ifdef MOZ_WAYLAND
|
|
|
|
void nsDragService::ReplyToDragMotion(nsWaylandDragContext* aDragContext) {
|
|
|
|
MOZ_LOG(sDragLm, LogLevel::Debug,
|
|
|
|
("nsDragService::ReplyToDragMotion %d", mCanDrop));
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-04-05 17:16:43 +03:00
|
|
|
GdkDragAction action = (GdkDragAction)0;
|
|
|
|
if (mCanDrop) {
|
|
|
|
// notify the dragger if we can drop
|
|
|
|
switch (mDragAction) {
|
|
|
|
case DRAGDROP_ACTION_COPY:
|
|
|
|
action = GDK_ACTION_COPY;
|
|
|
|
break;
|
|
|
|
case DRAGDROP_ACTION_LINK:
|
|
|
|
action = GDK_ACTION_LINK;
|
|
|
|
break;
|
|
|
|
case DRAGDROP_ACTION_NONE:
|
|
|
|
action = (GdkDragAction)0;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
action = GDK_ACTION_MOVE;
|
|
|
|
break;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2018-04-05 17:16:43 +03:00
|
|
|
|
|
|
|
aDragContext->SetDragStatus(action);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2002-08-12 01:47:14 +04:00
|
|
|
void nsDragService::TargetDataReceived(GtkWidget* aWidget,
|
|
|
|
GdkDragContext* aContext, gint aX,
|
|
|
|
gint aY,
|
|
|
|
GtkSelectionData* aSelectionData,
|
|
|
|
guint aInfo, guint32 aTime) {
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(sDragLm, LogLevel::Debug, ("nsDragService::TargetDataReceived"));
|
2002-08-12 01:47:14 +04:00
|
|
|
TargetResetData();
|
2011-10-03 11:56:21 +04:00
|
|
|
mTargetDragDataReceived = true;
|
2012-09-18 03:05:05 +04:00
|
|
|
gint len = gtk_selection_data_get_length(aSelectionData);
|
|
|
|
const guchar* data = gtk_selection_data_get_data(aSelectionData);
|
|
|
|
if (len > 0 && data) {
|
|
|
|
mTargetDragDataLen = len;
|
2002-08-12 01:47:14 +04:00
|
|
|
mTargetDragData = g_malloc(mTargetDragDataLen);
|
2012-09-18 03:05:05 +04:00
|
|
|
memcpy(mTargetDragData, data, mTargetDragDataLen);
|
2002-08-12 01:47:14 +04:00
|
|
|
} else {
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(sDragLm, LogLevel::Debug,
|
2002-08-12 01:47:14 +04:00
|
|
|
("Failed to get data. selection data len was %d\n",
|
2012-09-14 05:56:59 +04:00
|
|
|
mTargetDragDataLen));
|
2002-08-12 01:47:14 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool nsDragService::IsTargetContextList(void) {
|
2011-09-29 10:19:26 +04:00
|
|
|
bool retval = false;
|
2002-08-12 01:47:14 +04:00
|
|
|
|
2013-10-08 22:47:37 +04:00
|
|
|
// gMimeListType drags only work for drags within a single process. The
|
|
|
|
// gtk_drag_get_source_widget() function will return nullptr if the source
|
|
|
|
// of the drag is another app, so we use it to check if a gMimeListType
|
|
|
|
// drop will work or not.
|
2020-06-23 15:03:53 +03:00
|
|
|
if (mTargetDragContext &&
|
|
|
|
gtk_drag_get_source_widget(mTargetDragContext) == nullptr) {
|
|
|
|
return retval;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2020-06-23 15:03:53 +03:00
|
|
|
GList* tmp = nullptr;
|
|
|
|
if (mTargetDragContext) {
|
|
|
|
tmp = gdk_drag_context_list_targets(mTargetDragContext);
|
|
|
|
}
|
|
|
|
#ifdef MOZ_WAYLAND
|
|
|
|
GList* tmp_head = nullptr;
|
|
|
|
if (mTargetWaylandDragContext) {
|
|
|
|
tmp_head = tmp = mTargetWaylandDragContext->GetTargets();
|
|
|
|
}
|
|
|
|
#endif
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2002-08-12 01:47:14 +04:00
|
|
|
// walk the list of context targets and see if one of them is a list
|
|
|
|
// of items.
|
2020-06-23 15:03:53 +03:00
|
|
|
for (; tmp; tmp = tmp->next) {
|
2008-01-05 08:43:22 +03:00
|
|
|
/* Bug 331198 */
|
|
|
|
GdkAtom atom = GDK_POINTER_TO_ATOM(tmp->data);
|
2013-10-08 22:47:37 +04:00
|
|
|
gchar* name = nullptr;
|
2002-08-12 01:47:14 +04:00
|
|
|
name = gdk_atom_name(atom);
|
2009-11-27 03:20:27 +03:00
|
|
|
if (name && strcmp(name, gMimeListType) == 0) retval = true;
|
2002-08-12 01:47:14 +04:00
|
|
|
g_free(name);
|
|
|
|
if (retval) break;
|
|
|
|
}
|
2020-06-23 15:03:53 +03:00
|
|
|
|
|
|
|
#ifdef MOZ_WAYLAND
|
|
|
|
// mTargetWaylandDragContext->GetTargets allocates the list
|
|
|
|
// so we need to free it here.
|
|
|
|
if (mTargetWaylandDragContext && tmp_head) {
|
|
|
|
g_list_free(tmp_head);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2002-08-12 01:47:14 +04:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2005-11-26 00:57:13 +03:00
|
|
|
// Maximum time to wait for a "drag_received" arrived, in microseconds
|
2002-08-12 01:47:14 +04:00
|
|
|
#define NS_DND_TIMEOUT 500000
|
|
|
|
|
|
|
|
void nsDragService::GetTargetDragData(GdkAtom aFlavor) {
|
2016-12-16 06:16:31 +03:00
|
|
|
MOZ_LOG(sDragLm, LogLevel::Debug, ("getting data flavor %p\n", aFlavor));
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(sDragLm, LogLevel::Debug,
|
|
|
|
("mLastWidget is %p and mLastContext is %p\n", mTargetWidget.get(),
|
2012-04-19 10:18:31 +04:00
|
|
|
mTargetDragContext.get()));
|
2002-08-12 01:47:14 +04:00
|
|
|
// reset our target data areas
|
|
|
|
TargetResetData();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-04-05 17:16:43 +03:00
|
|
|
if (mTargetDragContext) {
|
|
|
|
gtk_drag_get_data(mTargetWidget, mTargetDragContext, aFlavor, mTargetTime);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-04-05 17:16:43 +03:00
|
|
|
MOZ_LOG(sDragLm, LogLevel::Debug, ("about to start inner iteration."));
|
|
|
|
PRTime entryTime = PR_Now();
|
|
|
|
while (!mTargetDragDataReceived && mDoingDrag) {
|
|
|
|
// check the number of iterations
|
|
|
|
MOZ_LOG(sDragLm, LogLevel::Debug, ("doing iteration...\n"));
|
|
|
|
PR_Sleep(20 * PR_TicksPerSecond() / 1000); /* sleep for 20 ms/iteration */
|
|
|
|
if (PR_Now() - entryTime > NS_DND_TIMEOUT) break;
|
|
|
|
gtk_main_iteration();
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2018-04-05 17:16:43 +03:00
|
|
|
#ifdef MOZ_WAYLAND
|
|
|
|
else {
|
|
|
|
mTargetDragData = mTargetWaylandDragContext->GetData(gdk_atom_name(aFlavor),
|
|
|
|
&mTargetDragDataLen);
|
|
|
|
mTargetDragDataReceived = true;
|
2002-08-12 01:47:14 +04:00
|
|
|
}
|
2018-04-05 17:16:43 +03:00
|
|
|
#endif
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(sDragLm, LogLevel::Debug, ("finished inner iteration\n"));
|
2002-08-12 01:47:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsDragService::TargetResetData(void) {
|
2011-10-03 11:56:21 +04:00
|
|
|
mTargetDragDataReceived = false;
|
2002-08-12 01:47:14 +04:00
|
|
|
// make sure to free old data if we have to
|
2011-05-11 17:12:26 +04:00
|
|
|
g_free(mTargetDragData);
|
2002-08-12 01:47:14 +04:00
|
|
|
mTargetDragData = 0;
|
|
|
|
mTargetDragDataLen = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
GtkTargetList* nsDragService::GetSourceList(void) {
|
|
|
|
if (!mSourceDataItems) return nullptr;
|
2009-02-23 04:05:24 +03:00
|
|
|
nsTArray<GtkTargetEntry*> targetArray;
|
2002-08-12 01:47:14 +04:00
|
|
|
GtkTargetEntry* targets;
|
|
|
|
GtkTargetList* targetList = 0;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t targetCount = 0;
|
2002-08-12 01:47:14 +04:00
|
|
|
unsigned int numDragItems = 0;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-10-18 21:56:20 +03:00
|
|
|
mSourceDataItems->GetLength(&numDragItems);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2002-08-12 01:47:14 +04:00
|
|
|
// Check to see if we're dragging > 1 item.
|
|
|
|
if (numDragItems > 1) {
|
|
|
|
// as the Xdnd protocol only supports a single item (or is it just
|
|
|
|
// gtk's implementation?), we don't advertise all flavours listed
|
|
|
|
// in the nsITransferable.
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2002-08-12 01:47:14 +04:00
|
|
|
// the application/x-moz-internal-item-list format, which preserves
|
|
|
|
// all information for drags within the same mozilla instance.
|
|
|
|
GtkTargetEntry* listTarget =
|
|
|
|
(GtkTargetEntry*)g_malloc(sizeof(GtkTargetEntry));
|
|
|
|
listTarget->target = g_strdup(gMimeListType);
|
|
|
|
listTarget->flags = 0;
|
|
|
|
MOZ_LOG(sDragLm, LogLevel::Debug,
|
2005-06-03 14:26:28 +04:00
|
|
|
("automatically adding target %s\n", listTarget->target));
|
|
|
|
targetArray.AppendElement(listTarget);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2002-08-12 01:47:14 +04:00
|
|
|
// check what flavours are supported so we can decide what other
|
|
|
|
// targets to advertise.
|
|
|
|
nsCOMPtr<nsITransferable> currItem = do_QueryElementAt(mSourceDataItems, 0);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2002-08-12 01:47:14 +04:00
|
|
|
if (currItem) {
|
|
|
|
nsTArray<nsCString> flavors;
|
2018-10-10 23:25:54 +03:00
|
|
|
currItem->FlavorsTransferableCanExport(flavors);
|
2002-08-12 01:47:14 +04:00
|
|
|
for (uint32_t i = 0; i < flavors.Length(); ++i) {
|
|
|
|
// check if text/x-moz-url is supported.
|
2018-10-10 23:25:54 +03:00
|
|
|
// If so, advertise
|
|
|
|
// text/uri-list.
|
2002-08-12 01:47:14 +04:00
|
|
|
if (flavors[i].EqualsLiteral(kURLMime)) {
|
|
|
|
listTarget = (GtkTargetEntry*)g_malloc(sizeof(GtkTargetEntry));
|
2018-10-10 23:25:54 +03:00
|
|
|
listTarget->target = g_strdup(gTextUriListType);
|
2002-08-12 01:47:14 +04:00
|
|
|
listTarget->flags = 0;
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(sDragLm, LogLevel::Debug,
|
2013-02-04 08:50:21 +04:00
|
|
|
("automatically adding target %s\n", listTarget->target));
|
2002-08-12 01:47:14 +04:00
|
|
|
targetArray.AppendElement(listTarget);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
}
|
2002-08-12 01:47:14 +04:00
|
|
|
} // if item is a transferable
|
|
|
|
} else if (numDragItems == 1) {
|
2018-10-29 00:05:15 +03:00
|
|
|
nsCOMPtr<nsITransferable> currItem = do_QueryElementAt(mSourceDataItems, 0);
|
2002-08-12 01:47:14 +04:00
|
|
|
if (currItem) {
|
2018-10-10 23:25:54 +03:00
|
|
|
nsTArray<nsCString> flavors;
|
|
|
|
currItem->FlavorsTransferableCanExport(flavors);
|
|
|
|
for (uint32_t i = 0; i < flavors.Length(); ++i) {
|
|
|
|
nsCString& flavorStr = flavors[i];
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2002-08-12 01:47:14 +04:00
|
|
|
GtkTargetEntry* target =
|
|
|
|
(GtkTargetEntry*)g_malloc(sizeof(GtkTargetEntry));
|
|
|
|
target->target = g_strdup(flavorStr.get());
|
|
|
|
target->flags = 0;
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(sDragLm, LogLevel::Debug,
|
2013-02-04 08:50:21 +04:00
|
|
|
("adding target %s\n", target->target));
|
2018-10-10 23:25:54 +03:00
|
|
|
targetArray.AppendElement(target);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2002-08-12 01:47:14 +04:00
|
|
|
// If there is a file, add the text/uri-list type.
|
2018-10-10 23:25:54 +03:00
|
|
|
if (flavorStr.EqualsLiteral(kFileMime)) {
|
|
|
|
GtkTargetEntry* urilistTarget =
|
|
|
|
(GtkTargetEntry*)g_malloc(sizeof(GtkTargetEntry));
|
|
|
|
urilistTarget->target = g_strdup(gTextUriListType);
|
|
|
|
urilistTarget->flags = 0;
|
|
|
|
MOZ_LOG(sDragLm, LogLevel::Debug,
|
|
|
|
("automatically adding target %s\n", urilistTarget->target));
|
|
|
|
targetArray.AppendElement(urilistTarget);
|
|
|
|
}
|
2002-08-12 01:47:14 +04:00
|
|
|
// Check to see if this is text/unicode.
|
|
|
|
// If it is, add text/plain
|
|
|
|
// since we automatically support text/plain
|
2009-02-23 04:05:24 +03:00
|
|
|
// if we support text/unicode.
|
|
|
|
else if (flavorStr.EqualsLiteral(kUnicodeMime)) {
|
|
|
|
GtkTargetEntry* plainUTF8Target =
|
2002-08-12 01:47:14 +04:00
|
|
|
(GtkTargetEntry*)g_malloc(sizeof(GtkTargetEntry));
|
2012-08-22 19:56:38 +04:00
|
|
|
plainUTF8Target->target = g_strdup(gTextPlainUTF8Type);
|
2002-08-12 01:47:14 +04:00
|
|
|
plainUTF8Target->flags = 0;
|
|
|
|
MOZ_LOG(
|
|
|
|
sDragLm, LogLevel::Debug,
|
|
|
|
("automatically adding target %s\n", plainUTF8Target->target));
|
|
|
|
targetArray.AppendElement(plainUTF8Target);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-10-10 23:25:54 +03:00
|
|
|
GtkTargetEntry* plainTarget =
|
2002-08-12 01:47:14 +04:00
|
|
|
(GtkTargetEntry*)g_malloc(sizeof(GtkTargetEntry));
|
|
|
|
plainTarget->target = g_strdup(kTextMime);
|
2018-10-10 23:25:54 +03:00
|
|
|
plainTarget->flags = 0;
|
2002-08-12 01:47:14 +04:00
|
|
|
MOZ_LOG(sDragLm, LogLevel::Debug,
|
|
|
|
("automatically adding target %s\n", plainTarget->target));
|
2009-02-23 04:05:24 +03:00
|
|
|
targetArray.AppendElement(plainTarget);
|
2002-08-12 01:47:14 +04:00
|
|
|
}
|
|
|
|
// Check to see if this is the x-moz-url type.
|
|
|
|
// If it is, add _NETSCAPE_URL
|
2018-10-10 23:25:54 +03:00
|
|
|
// this is a type used by everybody.
|
2002-08-12 01:47:14 +04:00
|
|
|
else if (flavorStr.EqualsLiteral(kURLMime)) {
|
|
|
|
GtkTargetEntry* urlTarget =
|
|
|
|
(GtkTargetEntry*)g_malloc(sizeof(GtkTargetEntry));
|
|
|
|
urlTarget->target = g_strdup(gMozUrlType);
|
2018-10-10 23:25:54 +03:00
|
|
|
urlTarget->flags = 0;
|
2002-08-12 01:47:14 +04:00
|
|
|
MOZ_LOG(sDragLm, LogLevel::Debug,
|
|
|
|
("automatically adding target %s\n", urlTarget->target));
|
2009-02-23 04:05:24 +03:00
|
|
|
targetArray.AppendElement(urlTarget);
|
2002-08-12 01:47:14 +04:00
|
|
|
}
|
2018-10-10 23:25:54 +03:00
|
|
|
// XdndDirectSave
|
|
|
|
else if (flavorStr.EqualsLiteral(kFilePromiseMime)) {
|
|
|
|
GtkTargetEntry* directsaveTarget =
|
2002-08-12 01:47:14 +04:00
|
|
|
(GtkTargetEntry*)g_malloc(sizeof(GtkTargetEntry));
|
|
|
|
directsaveTarget->target = g_strdup(gXdndDirectSaveType);
|
2018-10-10 23:25:54 +03:00
|
|
|
directsaveTarget->flags = 0;
|
2018-11-30 13:46:48 +03:00
|
|
|
MOZ_LOG(
|
2015-06-04 01:25:57 +03:00
|
|
|
sDragLm, LogLevel::Debug,
|
2018-10-10 23:25:54 +03:00
|
|
|
("automatically adding target %s\n", directsaveTarget->target));
|
|
|
|
targetArray.AppendElement(directsaveTarget);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
}
|
2002-08-12 01:47:14 +04:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2012-04-19 10:18:31 +04:00
|
|
|
// get all the elements that we created.
|
2002-08-12 01:47:14 +04:00
|
|
|
targetCount = targetArray.Length();
|
|
|
|
if (targetCount) {
|
|
|
|
// allocate space to create the list of valid targets
|
|
|
|
targets = (GtkTargetEntry*)g_malloc(sizeof(GtkTargetEntry) * targetCount);
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t targetIndex;
|
|
|
|
for (targetIndex = 0; targetIndex < targetCount; ++targetIndex) {
|
2002-08-12 01:47:14 +04:00
|
|
|
GtkTargetEntry* disEntry = targetArray.ElementAt(targetIndex);
|
|
|
|
// this is a string reference but it will be freed later.
|
|
|
|
targets[targetIndex].target = disEntry->target;
|
|
|
|
targets[targetIndex].flags = disEntry->flags;
|
2013-02-04 08:50:21 +04:00
|
|
|
targets[targetIndex].info = 0;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2002-08-12 01:47:14 +04:00
|
|
|
targetList = gtk_target_list_new(targets, targetCount);
|
|
|
|
// clean up the target list
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t cleanIndex = 0; cleanIndex < targetCount; ++cleanIndex) {
|
2009-02-23 04:05:24 +03:00
|
|
|
GtkTargetEntry* thisTarget = targetArray.ElementAt(cleanIndex);
|
2002-08-12 01:47:14 +04:00
|
|
|
g_free(thisTarget->target);
|
|
|
|
g_free(thisTarget);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2002-08-12 01:47:14 +04:00
|
|
|
g_free(targets);
|
2019-10-08 00:01:57 +03:00
|
|
|
} else {
|
|
|
|
// We need to create a dummy target list to be able initialize dnd.
|
|
|
|
targetList = gtk_target_list_new(nullptr, 0);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2002-08-12 01:47:14 +04:00
|
|
|
return targetList;
|
|
|
|
}
|
|
|
|
|
2009-06-20 05:38:27 +04:00
|
|
|
void nsDragService::SourceEndDragSession(GdkDragContext* aContext,
|
|
|
|
gint aResult) {
|
2020-04-09 17:18:41 +03:00
|
|
|
MOZ_LOG(sDragLm, LogLevel::Debug,
|
|
|
|
("SourceEndDragSession result %d\n", aResult));
|
|
|
|
|
2002-08-12 01:47:14 +04:00
|
|
|
// this just releases the list of data items that we provide
|
2012-07-30 18:20:58 +04:00
|
|
|
mSourceDataItems = nullptr;
|
2009-06-15 04:48:52 +04:00
|
|
|
|
2018-10-04 13:31:45 +03:00
|
|
|
// Remove this property, if it exists, to satisfy the Direct Save Protocol.
|
|
|
|
GdkAtom property = gdk_atom_intern(gXdndDirectSaveType, FALSE);
|
|
|
|
gdk_property_delete(gdk_drag_context_get_source_window(aContext), property);
|
|
|
|
|
2012-04-19 10:18:31 +04:00
|
|
|
if (!mDoingDrag || mScheduledTask == eDragTaskSourceEnd)
|
|
|
|
// EndDragSession() was already called on drop
|
|
|
|
// or SourceEndDragSession on drag-failed
|
|
|
|
return;
|
2009-06-20 05:38:27 +04:00
|
|
|
|
2012-04-17 05:00:25 +04:00
|
|
|
if (mEndDragPoint.x < 0) {
|
|
|
|
// We don't have a drag end point, so guess
|
|
|
|
gint x, y;
|
|
|
|
GdkDisplay* display = gdk_display_get_default();
|
|
|
|
if (display) {
|
2019-12-03 17:03:01 +03:00
|
|
|
gint scale = mozilla::widget::ScreenHelperGTK::GetGTKMonitorScaleFactor();
|
2013-10-08 22:47:37 +04:00
|
|
|
gdk_display_get_pointer(display, nullptr, &x, &y, nullptr);
|
2015-10-26 23:33:13 +03:00
|
|
|
SetDragEndPoint(LayoutDeviceIntPoint(x * scale, y * scale));
|
2020-04-09 17:18:41 +03:00
|
|
|
MOZ_LOG(sDragLm, LogLevel::Debug,
|
|
|
|
("guess drag end point %d %d\n", x * scale, y * scale));
|
2009-06-20 05:38:27 +04:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2009-06-15 04:48:52 +04:00
|
|
|
|
|
|
|
// Either the drag was aborted or the drop occurred outside the app.
|
|
|
|
// The dropEffect of mDataTransfer is not updated for motion outside the
|
|
|
|
// app, but is needed for the dragend event, so set it now.
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t dropEffect;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2009-06-20 05:38:27 +04:00
|
|
|
if (aResult == MOZ_GTK_DRAG_RESULT_SUCCESS) {
|
|
|
|
// With GTK+ versions 2.10.x and prior the drag may have been
|
|
|
|
// cancelled (but no drag-failed signal would have been sent).
|
2013-10-08 22:47:37 +04:00
|
|
|
// aContext->dest_window will be non-nullptr only if the drop was
|
|
|
|
// sent.
|
2012-09-14 05:56:59 +04:00
|
|
|
GdkDragAction action = gdk_drag_context_get_dest_window(aContext)
|
|
|
|
? gdk_drag_context_get_actions(aContext)
|
|
|
|
: (GdkDragAction)0;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2009-06-20 05:38:27 +04:00
|
|
|
// Only one bit of action should be set, but, just in case someone
|
|
|
|
// does something funny, erring away from MOVE, and not recording
|
|
|
|
// unusual action combinations as NONE.
|
|
|
|
if (!action)
|
|
|
|
dropEffect = DRAGDROP_ACTION_NONE;
|
|
|
|
else if (action & GDK_ACTION_COPY)
|
|
|
|
dropEffect = DRAGDROP_ACTION_COPY;
|
|
|
|
else if (action & GDK_ACTION_LINK)
|
|
|
|
dropEffect = DRAGDROP_ACTION_LINK;
|
|
|
|
else if (action & GDK_ACTION_MOVE)
|
|
|
|
dropEffect = DRAGDROP_ACTION_MOVE;
|
|
|
|
else
|
|
|
|
dropEffect = DRAGDROP_ACTION_COPY;
|
|
|
|
|
|
|
|
} else {
|
2009-06-15 04:48:52 +04:00
|
|
|
dropEffect = DRAGDROP_ACTION_NONE;
|
2009-06-20 05:38:27 +04:00
|
|
|
|
2020-04-09 17:18:41 +03:00
|
|
|
bool isWaylandTabDrop = false;
|
|
|
|
#ifdef MOZ_WAYLAND
|
|
|
|
// Bug 1527976. Wayland protocol does not have any way how to handle
|
|
|
|
// MOZ_GTK_DRAG_RESULT_NO_TARGET drop result so consider all tab
|
|
|
|
// drops as not cancelled on wayland.
|
|
|
|
if (gfxPlatformGtk::GetPlatform()->IsWaylandDisplay() &&
|
|
|
|
aResult == MOZ_GTK_DRAG_RESULT_ERROR) {
|
|
|
|
for (GList* tmp = gdk_drag_context_list_targets(aContext); tmp;
|
|
|
|
tmp = tmp->next) {
|
|
|
|
GdkAtom atom = GDK_POINTER_TO_ATOM(tmp->data);
|
|
|
|
gchar* name = gdk_atom_name(atom);
|
|
|
|
if (name && (strcmp(name, gTabDropType) == 0)) {
|
|
|
|
isWaylandTabDrop = true;
|
2020-05-06 18:02:25 +03:00
|
|
|
MOZ_LOG(sDragLm, LogLevel::Debug, ("is wayland tab drop\n"));
|
2020-04-09 17:18:41 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if (aResult != MOZ_GTK_DRAG_RESULT_NO_TARGET && !isWaylandTabDrop) {
|
2020-05-06 18:02:25 +03:00
|
|
|
MOZ_LOG(sDragLm, LogLevel::Debug, ("drop is user chancelled\n"));
|
2011-10-03 11:56:21 +04:00
|
|
|
mUserCancelled = true;
|
2009-06-20 05:38:27 +04:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2009-06-20 05:38:27 +04:00
|
|
|
|
2012-02-07 22:02:32 +04:00
|
|
|
if (mDataTransfer) {
|
|
|
|
mDataTransfer->SetDropEffectInt(dropEffect);
|
2009-06-15 04:48:52 +04:00
|
|
|
}
|
2005-03-16 03:40:21 +03:00
|
|
|
|
2012-04-19 10:18:31 +04:00
|
|
|
// Schedule the appropriate drag end dom events.
|
2018-04-05 17:16:43 +03:00
|
|
|
Schedule(eDragTaskSourceEnd, nullptr, nullptr, nullptr,
|
|
|
|
LayoutDeviceIntPoint(), 0);
|
2002-08-12 01:47:14 +04:00
|
|
|
}
|
|
|
|
|
2018-10-29 00:05:15 +03:00
|
|
|
static void CreateURIList(nsIArray* aItems, nsACString& aURIList) {
|
|
|
|
uint32_t length = 0;
|
|
|
|
aItems->GetLength(&length);
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < length; ++i) {
|
|
|
|
nsCOMPtr<nsITransferable> item = do_QueryElementAt(aItems, i);
|
|
|
|
if (!item) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> data;
|
2018-11-20 19:59:56 +03:00
|
|
|
nsresult rv = item->GetTransferData(kURLMime, getter_AddRefs(data));
|
2018-10-29 00:05:15 +03:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
nsCOMPtr<nsISupportsString> string = do_QueryInterface(data);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-10-29 00:05:15 +03:00
|
|
|
nsAutoString text;
|
|
|
|
if (string) {
|
|
|
|
string->GetData(text);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2018-10-29 00:05:15 +03:00
|
|
|
// text/x-moz-url is of form url + "\n" + title.
|
|
|
|
// We just want the url.
|
|
|
|
int32_t separatorPos = text.FindChar(u'\n');
|
|
|
|
if (separatorPos >= 0) {
|
|
|
|
text.Truncate(separatorPos);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2018-10-29 00:05:15 +03:00
|
|
|
AppendUTF16toUTF8(text, aURIList);
|
|
|
|
aURIList.AppendLiteral("\r\n");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// There is no URI available. If there is a file available, create
|
|
|
|
// a URI from the file.
|
2018-11-20 19:59:56 +03:00
|
|
|
rv = item->GetTransferData(kFileMime, getter_AddRefs(data));
|
2018-10-29 00:05:15 +03:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
if (nsCOMPtr<nsIFile> file = do_QueryInterface(data)) {
|
|
|
|
nsCOMPtr<nsIURI> fileURI;
|
|
|
|
NS_NewFileURI(getter_AddRefs(fileURI), file);
|
|
|
|
if (fileURI) {
|
|
|
|
nsAutoCString spec;
|
|
|
|
fileURI->GetSpec(spec);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-10-29 00:05:15 +03:00
|
|
|
aURIList.Append(spec);
|
|
|
|
aURIList.AppendLiteral("\r\n");
|
2002-08-12 01:47:14 +04:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2002-08-12 01:47:14 +04:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2002-08-12 01:47:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsDragService::SourceDataGet(GtkWidget* aWidget, GdkDragContext* aContext,
|
|
|
|
GtkSelectionData* aSelectionData,
|
|
|
|
guint32 aTime) {
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(sDragLm, LogLevel::Debug, ("nsDragService::SourceDataGet"));
|
2013-02-04 08:50:21 +04:00
|
|
|
GdkAtom target = gtk_selection_data_get_target(aSelectionData);
|
2020-02-25 23:09:29 +03:00
|
|
|
gchar* typeName = gdk_atom_name(target);
|
2002-08-12 01:47:14 +04:00
|
|
|
if (!typeName) {
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(sDragLm, LogLevel::Debug, ("failed to get atom name.\n"));
|
2018-11-30 13:46:48 +03:00
|
|
|
return;
|
|
|
|
}
|
2002-08-12 01:47:14 +04:00
|
|
|
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(sDragLm, LogLevel::Debug, ("Type is %s\n", typeName));
|
2020-02-25 23:09:29 +03:00
|
|
|
auto freeTypeName = mozilla::MakeScopeExit([&] { g_free(typeName); });
|
2013-02-04 08:50:21 +04:00
|
|
|
// check to make sure that we have data items to return.
|
2002-08-12 01:47:14 +04:00
|
|
|
if (!mSourceDataItems) {
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(sDragLm, LogLevel::Debug, ("Failed to get our data items\n"));
|
2002-08-12 01:47:14 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-02-25 23:09:29 +03:00
|
|
|
nsDependentCSubstring mimeFlavor(typeName, strlen(typeName));
|
2015-06-04 01:25:57 +03:00
|
|
|
nsCOMPtr<nsITransferable> item;
|
|
|
|
item = do_QueryElementAt(mSourceDataItems, 0);
|
|
|
|
if (item) {
|
2017-08-21 13:01:27 +03:00
|
|
|
// if someone was asking for text/plain, lookup unicode instead so
|
|
|
|
// we can convert it.
|
|
|
|
bool needToDoConversionToPlainText = false;
|
2013-08-22 14:31:48 +04:00
|
|
|
const char* actualFlavor;
|
|
|
|
if (mimeFlavor.EqualsLiteral(kTextMime) ||
|
|
|
|
mimeFlavor.EqualsLiteral(gTextPlainUTF8Type)) {
|
2015-06-04 01:25:57 +03:00
|
|
|
actualFlavor = kUnicodeMime;
|
|
|
|
needToDoConversionToPlainText = true;
|
2002-08-12 01:47:14 +04:00
|
|
|
}
|
|
|
|
// if someone was asking for _NETSCAPE_URL we need to convert to
|
|
|
|
// plain text but we also need to look for x-moz-url
|
2017-08-21 13:01:27 +03:00
|
|
|
else if (mimeFlavor.EqualsLiteral(gMozUrlType)) {
|
2002-08-12 01:47:14 +04:00
|
|
|
actualFlavor = kURLMime;
|
2011-10-03 11:56:21 +04:00
|
|
|
needToDoConversionToPlainText = true;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2007-04-11 13:06:02 +04:00
|
|
|
// if someone was asking for text/uri-list we need to convert to
|
|
|
|
// plain text.
|
2017-08-21 13:01:27 +03:00
|
|
|
else if (mimeFlavor.EqualsLiteral(gTextUriListType)) {
|
2007-04-11 13:06:02 +04:00
|
|
|
actualFlavor = gTextUriListType;
|
2011-10-03 11:56:21 +04:00
|
|
|
needToDoConversionToPlainText = true;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2018-10-04 13:31:45 +03:00
|
|
|
// Someone is asking for the special Direct Save Protocol type.
|
|
|
|
else if (mimeFlavor.EqualsLiteral(gXdndDirectSaveType)) {
|
|
|
|
// Indicate failure by default.
|
|
|
|
gtk_selection_data_set(aSelectionData, target, 8, (guchar*)"E", 1);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-10-04 13:31:45 +03:00
|
|
|
GdkAtom property = gdk_atom_intern(gXdndDirectSaveType, FALSE);
|
|
|
|
GdkAtom type = gdk_atom_intern(kTextMime, FALSE);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-10-04 13:31:45 +03:00
|
|
|
guchar* data;
|
|
|
|
gint length;
|
|
|
|
if (!gdk_property_get(gdk_drag_context_get_source_window(aContext),
|
|
|
|
property, type, 0, INT32_MAX, FALSE, nullptr,
|
|
|
|
nullptr, &length, &data)) {
|
2018-11-30 13:46:48 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-10-04 13:31:45 +03:00
|
|
|
// Zero-terminate the string.
|
|
|
|
data = (guchar*)g_realloc(data, length + 1);
|
|
|
|
if (!data) return;
|
|
|
|
data[length] = '\0';
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-10-04 13:31:45 +03:00
|
|
|
gchar* hostname;
|
|
|
|
char* gfullpath =
|
|
|
|
g_filename_from_uri((const gchar*)data, &hostname, nullptr);
|
|
|
|
g_free(data);
|
|
|
|
if (!gfullpath) return;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-10-04 13:31:45 +03:00
|
|
|
nsCString fullpath(gfullpath);
|
|
|
|
g_free(gfullpath);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-10-10 23:25:54 +03:00
|
|
|
MOZ_LOG(sDragLm, LogLevel::Debug,
|
2018-10-04 13:31:45 +03:00
|
|
|
("XdndDirectSave filepath is %s\n", fullpath.get()));
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-10-04 13:31:45 +03:00
|
|
|
// If there is no hostname in the URI, NULL will be stored.
|
|
|
|
// We should not accept uris with from a different host.
|
|
|
|
if (hostname) {
|
|
|
|
nsCOMPtr<nsIPropertyBag2> infoService =
|
|
|
|
do_GetService(NS_SYSTEMINFO_CONTRACTID);
|
|
|
|
if (!infoService) return;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-10-04 13:31:45 +03:00
|
|
|
nsAutoCString host;
|
2020-07-01 11:29:29 +03:00
|
|
|
if (NS_SUCCEEDED(
|
|
|
|
infoService->GetPropertyAsACString(u"host"_ns, host))) {
|
2018-10-04 13:31:45 +03:00
|
|
|
if (!host.Equals(hostname)) {
|
2018-10-10 23:25:54 +03:00
|
|
|
MOZ_LOG(sDragLm, LogLevel::Debug,
|
2018-10-04 13:31:45 +03:00
|
|
|
("ignored drag because of different host.\n"));
|
2002-08-12 01:47:14 +04:00
|
|
|
|
|
|
|
// Special error code "F" for this case.
|
|
|
|
gtk_selection_data_set(aSelectionData, target, 8, (guchar*)"F", 1);
|
|
|
|
g_free(hostname);
|
|
|
|
return;
|
|
|
|
}
|
2007-04-11 13:06:02 +04:00
|
|
|
}
|
2018-10-04 13:31:45 +03:00
|
|
|
|
|
|
|
g_free(hostname);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIFile> file;
|
|
|
|
if (NS_FAILED(
|
|
|
|
NS_NewNativeLocalFile(fullpath, false, getter_AddRefs(file)))) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We have to split the path into a directory and filename,
|
|
|
|
// because our internal file-promise API is based on these.
|
|
|
|
|
2018-11-20 20:00:09 +03:00
|
|
|
nsCOMPtr<nsIFile> directory;
|
|
|
|
file->GetParent(getter_AddRefs(directory));
|
2018-10-04 13:31:45 +03:00
|
|
|
|
|
|
|
item->SetTransferData(kFilePromiseDirectoryMime, directory);
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupportsString> filenamePrimitive =
|
|
|
|
do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID);
|
|
|
|
if (!filenamePrimitive) return;
|
|
|
|
|
2018-11-20 20:00:09 +03:00
|
|
|
nsAutoString leafName;
|
|
|
|
file->GetLeafName(leafName);
|
|
|
|
filenamePrimitive->SetData(leafName);
|
2018-10-04 13:31:45 +03:00
|
|
|
|
2002-08-12 01:47:14 +04:00
|
|
|
item->SetTransferData(kFilePromiseDestFilename, filenamePrimitive);
|
2018-10-04 13:31:45 +03:00
|
|
|
|
|
|
|
// Request a different type in GetTransferData.
|
|
|
|
actualFlavor = kFilePromiseMime;
|
2018-11-30 13:46:48 +03:00
|
|
|
} else {
|
2020-02-25 23:09:29 +03:00
|
|
|
actualFlavor = typeName;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2002-08-12 01:47:14 +04:00
|
|
|
nsresult rv;
|
2018-10-29 00:05:15 +03:00
|
|
|
nsCOMPtr<nsISupports> data;
|
2018-11-20 19:59:56 +03:00
|
|
|
rv = item->GetTransferData(actualFlavor, getter_AddRefs(data));
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-10-04 13:31:45 +03:00
|
|
|
if (strcmp(actualFlavor, kFilePromiseMime) == 0) {
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
// Indicate success.
|
|
|
|
gtk_selection_data_set(aSelectionData, target, 8, (guchar*)"S", 1);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-08-12 01:47:14 +04:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2018-11-09 16:24:28 +03:00
|
|
|
void* tmpData = nullptr;
|
|
|
|
uint32_t tmpDataLen = 0;
|
2017-08-21 13:01:27 +03:00
|
|
|
nsPrimitiveHelpers::CreateDataFromPrimitive(
|
2018-11-09 16:24:28 +03:00
|
|
|
nsDependentCString(actualFlavor), data, &tmpData, &tmpDataLen);
|
2002-08-12 01:47:14 +04:00
|
|
|
// if required, do the extra work to convert unicode to plain
|
|
|
|
// text and replace the output values with the plain text.
|
|
|
|
if (needToDoConversionToPlainText) {
|
2012-07-30 18:20:58 +04:00
|
|
|
char* plainTextData = nullptr;
|
2015-10-14 15:28:50 +03:00
|
|
|
char16_t* castedUnicode = reinterpret_cast<char16_t*>(tmpData);
|
2002-08-12 01:47:14 +04:00
|
|
|
uint32_t plainTextLen = 0;
|
|
|
|
UTF16ToNewUTF8(castedUnicode, tmpDataLen / 2, &plainTextData,
|
2015-10-14 15:28:50 +03:00
|
|
|
&plainTextLen);
|
2002-08-12 01:47:14 +04:00
|
|
|
if (tmpData) {
|
|
|
|
// this was not allocated using glib
|
|
|
|
free(tmpData);
|
2013-02-04 08:50:21 +04:00
|
|
|
tmpData = plainTextData;
|
2018-10-29 00:05:15 +03:00
|
|
|
tmpDataLen = plainTextLen;
|
2002-08-12 01:47:14 +04:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2002-08-12 01:47:14 +04:00
|
|
|
if (tmpData) {
|
|
|
|
// this copies the data
|
2018-10-04 13:31:45 +03:00
|
|
|
gtk_selection_data_set(aSelectionData, target, 8, (guchar*)tmpData,
|
2002-08-12 01:47:14 +04:00
|
|
|
tmpDataLen);
|
|
|
|
// this wasn't allocated with glib
|
|
|
|
free(tmpData);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
} else {
|
2017-08-21 13:01:27 +03:00
|
|
|
if (mimeFlavor.EqualsLiteral(gTextUriListType)) {
|
2007-04-11 13:06:02 +04:00
|
|
|
// fall back for text/uri-list
|
2018-10-29 00:05:15 +03:00
|
|
|
nsAutoCString list;
|
|
|
|
CreateURIList(mSourceDataItems, list);
|
2018-10-04 13:31:45 +03:00
|
|
|
gtk_selection_data_set(aSelectionData, target, 8, (guchar*)list.get(),
|
2018-10-29 00:05:15 +03:00
|
|
|
list.Length());
|
2018-11-30 13:46:48 +03:00
|
|
|
return;
|
|
|
|
}
|
2002-08-12 01:47:14 +04:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2002-08-12 01:47:14 +04:00
|
|
|
}
|
|
|
|
|
2018-10-04 13:31:45 +03:00
|
|
|
void nsDragService::SourceBeginDrag(GdkDragContext* aContext) {
|
|
|
|
nsCOMPtr<nsITransferable> transferable =
|
|
|
|
do_QueryElementAt(mSourceDataItems, 0);
|
|
|
|
if (!transferable) return;
|
|
|
|
|
2018-10-10 23:25:54 +03:00
|
|
|
nsTArray<nsCString> flavors;
|
|
|
|
nsresult rv = transferable->FlavorsTransferableCanImport(flavors);
|
2018-10-04 13:31:45 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, );
|
|
|
|
|
2018-10-10 23:25:54 +03:00
|
|
|
for (uint32_t i = 0; i < flavors.Length(); ++i) {
|
|
|
|
if (flavors[i].EqualsLiteral(kFilePromiseDestFilename)) {
|
2018-10-04 13:31:45 +03:00
|
|
|
nsCOMPtr<nsISupports> data;
|
2019-01-04 19:16:59 +03:00
|
|
|
rv = transferable->GetTransferData(kFilePromiseDestFilename,
|
|
|
|
getter_AddRefs(data));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-10-04 13:31:45 +03:00
|
|
|
nsCOMPtr<nsISupportsString> fileName = do_QueryInterface(data);
|
2019-01-04 19:16:59 +03:00
|
|
|
if (!fileName) {
|
|
|
|
return;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-10-04 13:31:45 +03:00
|
|
|
nsAutoString fileNameStr;
|
|
|
|
fileName->GetData(fileNameStr);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-10-04 13:31:45 +03:00
|
|
|
nsCString fileNameCStr;
|
|
|
|
CopyUTF16toUTF8(fileNameStr, fileNameCStr);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-10-04 13:31:45 +03:00
|
|
|
GdkAtom property = gdk_atom_intern(gXdndDirectSaveType, FALSE);
|
|
|
|
GdkAtom type = gdk_atom_intern(kTextMime, FALSE);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-10-04 13:31:45 +03:00
|
|
|
gdk_property_change(gdk_drag_context_get_source_window(aContext),
|
|
|
|
property, type, 8, GDK_PROP_MODE_REPLACE,
|
|
|
|
(const guchar*)fileNameCStr.get(),
|
|
|
|
fileNameCStr.Length());
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2018-10-04 13:31:45 +03:00
|
|
|
}
|
|
|
|
|
2011-07-04 18:39:08 +04:00
|
|
|
void nsDragService::SetDragIcon(GdkDragContext* aContext) {
|
2011-04-26 05:37:20 +04:00
|
|
|
if (!mHasImage && !mSelection) return;
|
|
|
|
|
2016-10-19 22:01:39 +03:00
|
|
|
LayoutDeviceIntRect dragRect;
|
2011-07-04 18:39:08 +04:00
|
|
|
nsPresContext* pc;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<SourceSurface> surface;
|
2018-08-07 16:32:08 +03:00
|
|
|
DrawDrag(mSourceNode, mRegion, mScreenPosition, &dragRect, &surface, &pc);
|
2011-04-26 05:37:20 +04:00
|
|
|
if (!pc) return;
|
2011-07-04 18:39:08 +04:00
|
|
|
|
2016-10-19 22:01:39 +03:00
|
|
|
LayoutDeviceIntPoint screenPoint =
|
|
|
|
ConvertToUnscaledDevPixels(pc, mScreenPosition);
|
|
|
|
int32_t offsetX = screenPoint.x - dragRect.x;
|
|
|
|
int32_t offsetY = screenPoint.y - dragRect.y;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2011-04-26 05:37:20 +04:00
|
|
|
// If a popup is set as the drag image, use its widget. Otherwise, use
|
|
|
|
// the surface that DrawDrag created.
|
2016-04-26 05:04:55 +03:00
|
|
|
//
|
|
|
|
// XXX: Disable drag popups on GTK 3.19.4 and above: see bug 1264454.
|
|
|
|
// Fix this once a new GTK version ships that does not destroy our
|
|
|
|
// widget in gtk_drag_set_icon_widget.
|
|
|
|
if (mDragPopup && gtk_check_version(3, 19, 4)) {
|
2012-07-30 18:20:58 +04:00
|
|
|
GtkWidget* gtkWidget = nullptr;
|
2011-04-26 05:37:20 +04:00
|
|
|
nsIFrame* frame = mDragPopup->GetPrimaryFrame();
|
|
|
|
if (frame) {
|
|
|
|
// DrawDrag ensured that this is a popup frame.
|
|
|
|
nsCOMPtr<nsIWidget> widget = frame->GetNearestWidget();
|
|
|
|
if (widget) {
|
|
|
|
gtkWidget = (GtkWidget*)widget->GetNativeData(NS_NATIVE_SHELLWIDGET);
|
|
|
|
if (gtkWidget) {
|
|
|
|
OpenDragPopup();
|
|
|
|
gtk_drag_set_icon_widget(aContext, gtkWidget, offsetX, offsetY);
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2011-04-26 05:37:20 +04:00
|
|
|
}
|
|
|
|
} else if (surface) {
|
2011-07-04 18:39:08 +04:00
|
|
|
if (!SetAlphaPixmap(surface, aContext, offsetX, offsetY, dragRect)) {
|
2014-01-29 04:10:33 +04:00
|
|
|
GdkPixbuf* dragPixbuf = nsImageToPixbuf::SourceSurfaceToPixbuf(
|
|
|
|
surface, dragRect.width, dragRect.height);
|
2011-07-04 18:39:08 +04:00
|
|
|
if (dragPixbuf) {
|
|
|
|
gtk_drag_set_icon_pixbuf(aContext, dragPixbuf, offsetX, offsetY);
|
|
|
|
g_object_unref(dragPixbuf);
|
|
|
|
}
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2011-07-04 18:39:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void invisibleSourceDragBegin(GtkWidget* aWidget,
|
|
|
|
GdkDragContext* aContext, gpointer aData) {
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(sDragLm, LogLevel::Debug, ("invisibleSourceDragBegin"));
|
2011-07-04 18:39:08 +04:00
|
|
|
nsDragService* dragService = (nsDragService*)aData;
|
|
|
|
|
2018-10-04 13:31:45 +03:00
|
|
|
dragService->SourceBeginDrag(aContext);
|
2011-07-04 18:39:08 +04:00
|
|
|
dragService->SetDragIcon(aContext);
|
|
|
|
}
|
|
|
|
|
2002-08-12 01:47:14 +04:00
|
|
|
static void invisibleSourceDragDataGet(GtkWidget* aWidget,
|
|
|
|
GdkDragContext* aContext,
|
|
|
|
GtkSelectionData* aSelectionData,
|
|
|
|
guint aInfo, guint32 aTime,
|
|
|
|
gpointer aData) {
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(sDragLm, LogLevel::Debug, ("invisibleSourceDragDataGet"));
|
2002-08-12 01:47:14 +04:00
|
|
|
nsDragService* dragService = (nsDragService*)aData;
|
|
|
|
dragService->SourceDataGet(aWidget, aContext, aSelectionData, aTime);
|
|
|
|
}
|
|
|
|
|
2009-06-20 05:38:27 +04:00
|
|
|
static gboolean invisibleSourceDragFailed(GtkWidget* aWidget,
|
|
|
|
GdkDragContext* aContext,
|
|
|
|
gint aResult, gpointer aData) {
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(sDragLm, LogLevel::Debug, ("invisibleSourceDragFailed %i", aResult));
|
2009-06-20 05:38:27 +04:00
|
|
|
nsDragService* dragService = (nsDragService*)aData;
|
|
|
|
// End the drag session now (rather than waiting for the drag-end signal)
|
|
|
|
// so that operations performed on dropEffect == none can start immediately
|
|
|
|
// rather than waiting for the drag-failed animation to finish.
|
|
|
|
dragService->SourceEndDragSession(aContext, aResult);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2009-06-20 05:38:27 +04:00
|
|
|
// We should return TRUE to disable the drag-failed animation iff the
|
|
|
|
// source performed an operation when dropEffect was none, but the handler
|
|
|
|
// of the dragend DOM event doesn't provide this information.
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2002-08-12 01:47:14 +04:00
|
|
|
static void invisibleSourceDragEnd(GtkWidget* aWidget, GdkDragContext* aContext,
|
|
|
|
gpointer aData) {
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(sDragLm, LogLevel::Debug, ("invisibleSourceDragEnd"));
|
2002-08-12 01:47:14 +04:00
|
|
|
nsDragService* dragService = (nsDragService*)aData;
|
2009-04-16 19:58:23 +04:00
|
|
|
|
2002-08-12 01:47:14 +04:00
|
|
|
// The drag has ended. Release the hostages!
|
2009-06-20 05:38:27 +04:00
|
|
|
dragService->SourceEndDragSession(aContext, MOZ_GTK_DRAG_RESULT_SUCCESS);
|
2002-08-12 01:47:14 +04:00
|
|
|
}
|
|
|
|
|
2012-04-19 10:18:31 +04:00
|
|
|
// The following methods handle responding to GTK drag signals and
|
2012-04-19 10:18:31 +04:00
|
|
|
// tracking state between these signals.
|
|
|
|
//
|
|
|
|
// In general, GTK does not expect us to run the event loop while handling its
|
2012-04-19 10:18:31 +04:00
|
|
|
// drag signals, however our drag event handlers may run the
|
2012-04-19 10:18:31 +04:00
|
|
|
// event loop, most often to fetch information about the drag data.
|
2017-12-19 13:38:59 +03:00
|
|
|
//
|
2012-04-19 10:18:31 +04:00
|
|
|
// GTK, for example, uses the return value from drag-motion signals to
|
|
|
|
// determine whether drag-leave signals should be sent. If an event loop is
|
|
|
|
// run during drag-motion the XdndLeave message can get processed but when GTK
|
|
|
|
// receives the message it does not yet know that it needs to send the
|
|
|
|
// drag-leave signal to our widget.
|
|
|
|
//
|
|
|
|
// After a drag-drop signal, we need to reply with gtk_drag_finish().
|
|
|
|
// However, gtk_drag_finish should happen after the drag-drop signal handler
|
|
|
|
// returns so that when the Motif drag protocol is used, the
|
|
|
|
// XmTRANSFER_SUCCESS during gtk_drag_finish is sent after the XmDROP_START
|
|
|
|
// reply sent on return from the drag-drop signal handler.
|
|
|
|
//
|
2012-04-19 10:18:31 +04:00
|
|
|
// Similarly drag-end for a successful drag and drag-failed are not good
|
|
|
|
// times to run a nested event loop as gtk_drag_drop_finished() and
|
|
|
|
// gtk_drag_source_info_destroy() don't gtk_drag_clear_source_info() or remove
|
|
|
|
// drop_timeout until after at least the first of these signals is sent.
|
|
|
|
// Processing other events (e.g. a slow GDK_DROP_FINISHED reply, or the drop
|
|
|
|
// timeout) could cause gtk_drag_drop_finished to be called again with the
|
|
|
|
// same GtkDragSourceInfo, which won't like being destroyed twice.
|
|
|
|
//
|
2012-04-19 10:18:31 +04:00
|
|
|
// Therefore we reply to the signals immediately and schedule a task to
|
|
|
|
// dispatch the Gecko events, which may run the event loop.
|
|
|
|
//
|
|
|
|
// Action in response to drag-leave signals is also delayed until the event
|
|
|
|
// loop runs again so that we find out whether a drag-drop signal follows.
|
|
|
|
//
|
|
|
|
// A single task is scheduled to manage responses to all three GTK signals.
|
|
|
|
// If further signals are received while the task is scheduled, the scheduled
|
|
|
|
// response is updated, sometimes effectively compressing successive signals.
|
|
|
|
//
|
|
|
|
// No Gecko drag events are dispatched (during nested event loops) while other
|
|
|
|
// Gecko drag events are in flight. This helps event handlers that may not
|
|
|
|
// expect nested events, while accessing an event's dataTransfer for example.
|
|
|
|
|
|
|
|
gboolean nsDragService::ScheduleMotionEvent(
|
|
|
|
nsWindow* aWindow, GdkDragContext* aDragContext,
|
2018-04-05 17:16:43 +03:00
|
|
|
nsWaylandDragContext* aWaylandDragContext,
|
2015-10-26 23:33:13 +03:00
|
|
|
LayoutDeviceIntPoint aWindowPoint, guint aTime) {
|
2018-04-05 17:16:43 +03:00
|
|
|
if (aDragContext && mScheduledTask == eDragTaskMotion) {
|
2012-04-19 10:18:31 +04:00
|
|
|
// The drag source has sent another motion message before we've
|
|
|
|
// replied to the previous. That shouldn't happen with Xdnd. The
|
|
|
|
// spec for Motif drags is less clear, but we'll just update the
|
|
|
|
// scheduled task with the new position reply only to the most
|
|
|
|
// recent message.
|
|
|
|
NS_WARNING("Drag Motion message received before previous reply was sent");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returning TRUE means we'll reply with a status message, unless we first
|
|
|
|
// get a leave.
|
2018-04-05 17:16:43 +03:00
|
|
|
return Schedule(eDragTaskMotion, aWindow, aDragContext, aWaylandDragContext,
|
2012-04-19 10:18:31 +04:00
|
|
|
aWindowPoint, aTime);
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsDragService::ScheduleLeaveEvent() {
|
|
|
|
// We don't know at this stage whether a drop signal will immediately
|
|
|
|
// follow. If the drop signal gets sent it will happen before we return
|
|
|
|
// to the main loop and the scheduled leave task will be replaced.
|
2018-04-05 17:16:43 +03:00
|
|
|
if (!Schedule(eDragTaskLeave, nullptr, nullptr, nullptr,
|
|
|
|
LayoutDeviceIntPoint(), 0)) {
|
2012-04-19 10:18:31 +04:00
|
|
|
NS_WARNING("Drag leave after drop");
|
2017-12-19 13:38:59 +03:00
|
|
|
}
|
2012-04-19 10:18:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean nsDragService::ScheduleDropEvent(
|
|
|
|
nsWindow* aWindow, GdkDragContext* aDragContext,
|
2018-04-05 17:16:43 +03:00
|
|
|
nsWaylandDragContext* aWaylandDragContext,
|
2015-10-26 23:33:13 +03:00
|
|
|
LayoutDeviceIntPoint aWindowPoint, guint aTime) {
|
2018-04-05 17:16:43 +03:00
|
|
|
if (!Schedule(eDragTaskDrop, aWindow, aDragContext, aWaylandDragContext,
|
|
|
|
aWindowPoint, aTime)) {
|
2012-04-19 10:18:31 +04:00
|
|
|
NS_WARNING("Additional drag drop ignored");
|
2017-12-19 13:38:59 +03:00
|
|
|
return FALSE;
|
2012-04-19 10:18:31 +04:00
|
|
|
}
|
|
|
|
|
2015-10-26 23:33:13 +03:00
|
|
|
SetDragEndPoint(aWindowPoint + aWindow->WidgetToScreenOffset());
|
2012-04-19 10:18:31 +04:00
|
|
|
|
|
|
|
// We'll reply with gtk_drag_finish().
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean nsDragService::Schedule(DragTask aTask, nsWindow* aWindow,
|
|
|
|
GdkDragContext* aDragContext,
|
2018-04-05 17:16:43 +03:00
|
|
|
nsWaylandDragContext* aWaylandDragContext,
|
2015-10-26 23:33:13 +03:00
|
|
|
LayoutDeviceIntPoint aWindowPoint,
|
|
|
|
guint aTime) {
|
2012-04-19 10:18:31 +04:00
|
|
|
// If there is an existing leave or motion task scheduled, then that
|
|
|
|
// will be replaced. When the new task is run, it will dispatch
|
|
|
|
// any necessary leave or motion events.
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-04-19 10:18:31 +04:00
|
|
|
// If aTask is eDragTaskSourceEnd, then it will replace even a scheduled
|
|
|
|
// drop event (which could happen if the drop event has not been processed
|
|
|
|
// within the allowed time). Otherwise, if we haven't yet run a scheduled
|
|
|
|
// drop or end task, just say that we are not ready to receive another
|
|
|
|
// drop.
|
|
|
|
if (mScheduledTask == eDragTaskSourceEnd ||
|
|
|
|
(mScheduledTask == eDragTaskDrop && aTask != eDragTaskSourceEnd))
|
|
|
|
return FALSE;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-04-19 10:18:31 +04:00
|
|
|
mScheduledTask = aTask;
|
|
|
|
mPendingWindow = aWindow;
|
|
|
|
mPendingDragContext = aDragContext;
|
2018-04-05 17:16:43 +03:00
|
|
|
#ifdef MOZ_WAYLAND
|
|
|
|
mPendingWaylandDragContext = aWaylandDragContext;
|
|
|
|
#endif
|
2012-04-19 10:18:31 +04:00
|
|
|
mPendingWindowPoint = aWindowPoint;
|
|
|
|
mPendingTime = aTime;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-04-19 10:18:31 +04:00
|
|
|
if (!mTaskSource) {
|
|
|
|
// High priority is used here because the native events involved have
|
|
|
|
// already waited at default priority. Perhaps a lower than default
|
|
|
|
// priority could be used for motion tasks because there is a chance
|
|
|
|
// that a leave or drop is waiting, but managing different priorities
|
|
|
|
// may not be worth the effort. Motion tasks shouldn't queue up as
|
|
|
|
// they should be throttled based on replies.
|
2013-10-08 22:47:37 +04:00
|
|
|
mTaskSource =
|
|
|
|
g_idle_add_full(G_PRIORITY_HIGH, TaskDispatchCallback, this, nullptr);
|
2012-04-19 10:18:31 +04:00
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean nsDragService::TaskDispatchCallback(gpointer data) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsDragService> dragService = static_cast<nsDragService*>(data);
|
2012-04-19 10:18:31 +04:00
|
|
|
return dragService->RunScheduledTask();
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean nsDragService::RunScheduledTask() {
|
|
|
|
if (mTargetWindow && mTargetWindow != mPendingWindow) {
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(sDragLm, LogLevel::Debug,
|
2012-04-19 10:18:31 +04:00
|
|
|
("nsDragService: dispatch drag leave (%p)\n", mTargetWindow.get()));
|
2015-09-02 09:08:02 +03:00
|
|
|
mTargetWindow->DispatchDragEvent(eDragExit, mTargetWindowPoint, 0);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-04-19 10:18:31 +04:00
|
|
|
if (!mSourceNode) {
|
|
|
|
// The drag that was initiated in a different app. End the drag
|
|
|
|
// session, since we're done with it for now (until the user drags
|
|
|
|
// back into this app).
|
2017-02-17 06:29:42 +03:00
|
|
|
EndDragSession(false, GetCurrentModifiers());
|
2012-04-19 10:18:31 +04:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2012-04-19 10:18:31 +04:00
|
|
|
|
|
|
|
// It is possible that the pending state has been updated during dispatch
|
|
|
|
// of the leave event. That's fine.
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-04-19 10:18:31 +04:00
|
|
|
// Now we collect the pending state because, from this point on, we want
|
|
|
|
// to use the same state for all events dispatched. All state is updated
|
|
|
|
// so that when other tasks are scheduled during dispatch here, this
|
|
|
|
// task is considered to have already been run.
|
|
|
|
bool positionHasChanged = mPendingWindow != mTargetWindow ||
|
|
|
|
mPendingWindowPoint != mTargetWindowPoint;
|
|
|
|
DragTask task = mScheduledTask;
|
|
|
|
mScheduledTask = eDragTaskNone;
|
2020-02-13 17:38:48 +03:00
|
|
|
mTargetWindow = std::move(mPendingWindow);
|
2012-04-19 10:18:31 +04:00
|
|
|
mTargetWindowPoint = mPendingWindowPoint;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-04-19 10:18:31 +04:00
|
|
|
if (task == eDragTaskLeave || task == eDragTaskSourceEnd) {
|
|
|
|
if (task == eDragTaskSourceEnd) {
|
|
|
|
// Dispatch drag end events.
|
2017-02-17 06:29:42 +03:00
|
|
|
EndDragSession(true, GetCurrentModifiers());
|
2012-04-19 10:18:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Nothing more to do
|
|
|
|
// Returning false removes the task source from the event loop.
|
|
|
|
mTaskSource = 0;
|
|
|
|
return FALSE;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2012-04-19 10:18:31 +04:00
|
|
|
// This may be the start of a destination drag session.
|
|
|
|
StartDragSession();
|
|
|
|
|
2013-10-08 22:47:37 +04:00
|
|
|
// mTargetWidget may be nullptr if the window has been destroyed.
|
2012-04-19 10:18:31 +04:00
|
|
|
// (The leave event is not scheduled if a drop task is still scheduled.)
|
|
|
|
// We still reply appropriately to indicate that the drop will or didn't
|
2017-12-19 13:38:59 +03:00
|
|
|
// succeeed.
|
2012-04-19 10:18:31 +04:00
|
|
|
mTargetWidget = mTargetWindow->GetMozContainerWidget();
|
2018-05-24 12:51:17 +03:00
|
|
|
mTargetDragContext.steal(mPendingDragContext);
|
2018-04-05 17:16:43 +03:00
|
|
|
#ifdef MOZ_WAYLAND
|
2020-02-13 17:38:48 +03:00
|
|
|
mTargetWaylandDragContext = std::move(mPendingWaylandDragContext);
|
2018-04-05 17:16:43 +03:00
|
|
|
#endif
|
2012-04-19 10:18:31 +04:00
|
|
|
mTargetTime = mPendingTime;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-04-19 10:18:31 +04:00
|
|
|
// http://www.whatwg.org/specs/web-apps/current-work/multipage/dnd.html#drag-and-drop-processing-model
|
|
|
|
// (as at 27 December 2010) indicates that a "drop" event should only be
|
|
|
|
// fired (at the current target element) if the current drag operation is
|
|
|
|
// not none. The current drag operation will only be set to a non-none
|
|
|
|
// value during a "dragover" event.
|
|
|
|
//
|
|
|
|
// If the user has ended the drag before any dragover events have been
|
|
|
|
// sent, then the spec recommends skipping the drop (because the current
|
|
|
|
// drag operation is none). However, here we assume that, by releasing
|
|
|
|
// the mouse button, the user has indicated that they want to drop, so we
|
|
|
|
// proceed with the drop where possible.
|
|
|
|
//
|
|
|
|
// In order to make the events appear to content in the same way as if the
|
|
|
|
// spec is being followed we make sure to dispatch a "dragover" event with
|
|
|
|
// appropriate coordinates and check canDrop before the "drop" event.
|
|
|
|
//
|
|
|
|
// When the Xdnd protocol is used for source/destination communication (as
|
|
|
|
// should be the case with GTK source applications) a dragover event
|
|
|
|
// should have already been sent during the drag-motion signal, which
|
|
|
|
// would have already been received because XdndDrop messages do not
|
|
|
|
// contain a position. However, we can't assume the same when the Motif
|
|
|
|
// protocol is used.
|
|
|
|
if (task == eDragTaskMotion || positionHasChanged) {
|
2012-04-19 10:18:31 +04:00
|
|
|
UpdateDragAction();
|
2015-04-08 21:48:11 +03:00
|
|
|
TakeDragEventDispatchedToChildProcess(); // Clear the old value.
|
2012-04-19 10:18:31 +04:00
|
|
|
DispatchMotionEvents();
|
2012-04-19 10:18:31 +04:00
|
|
|
if (task == eDragTaskMotion) {
|
2015-04-08 21:48:11 +03:00
|
|
|
if (TakeDragEventDispatchedToChildProcess()) {
|
|
|
|
mTargetDragContextForRemote = mTargetDragContext;
|
2018-04-05 17:16:43 +03:00
|
|
|
#ifdef MOZ_WAYLAND
|
|
|
|
mTargetWaylandDragContextForRemote = mTargetWaylandDragContext;
|
|
|
|
#endif
|
2015-04-08 21:48:11 +03:00
|
|
|
} else {
|
|
|
|
// Reply to tell the source whether we can drop and what
|
|
|
|
// action would be taken.
|
2018-04-05 17:16:43 +03:00
|
|
|
if (mTargetDragContext) {
|
|
|
|
ReplyToDragMotion(mTargetDragContext);
|
|
|
|
}
|
|
|
|
#ifdef MOZ_WAYLAND
|
2018-05-24 12:51:17 +03:00
|
|
|
else if (mTargetWaylandDragContext) {
|
2018-04-05 17:16:43 +03:00
|
|
|
ReplyToDragMotion(mTargetWaylandDragContext);
|
2012-04-19 10:18:31 +04:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
#endif
|
|
|
|
}
|
2012-04-19 10:18:31 +04:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2012-04-19 10:18:31 +04:00
|
|
|
|
|
|
|
if (task == eDragTaskDrop) {
|
2012-04-19 10:18:31 +04:00
|
|
|
gboolean success = DispatchDropEvent();
|
2012-04-19 10:18:31 +04:00
|
|
|
|
|
|
|
// Perhaps we should set the del parameter to TRUE when the drag
|
|
|
|
// action is move, but we don't know whether the data was successfully
|
|
|
|
// transferred.
|
|
|
|
if (mTargetDragContext) {
|
2017-02-17 06:29:42 +03:00
|
|
|
gtk_drag_finish(mTargetDragContext, success,
|
|
|
|
/* del = */ FALSE, mTargetTime);
|
2012-04-19 10:18:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// This drag is over, so clear out our reference to the previous
|
|
|
|
// window.
|
2012-07-30 18:20:58 +04:00
|
|
|
mTargetWindow = nullptr;
|
2011-01-27 04:58:55 +03:00
|
|
|
// Make sure to end the drag session. If this drag started in a
|
2012-04-19 10:18:31 +04:00
|
|
|
// different app, we won't get a drag_end signal to end it from.
|
2017-02-17 06:29:42 +03:00
|
|
|
EndDragSession(true, GetCurrentModifiers());
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2012-04-19 10:18:31 +04:00
|
|
|
// We're done with the drag context.
|
2013-10-08 22:47:37 +04:00
|
|
|
mTargetWidget = nullptr;
|
|
|
|
mTargetDragContext = nullptr;
|
2018-04-05 17:16:43 +03:00
|
|
|
#ifdef MOZ_WAYLAND
|
|
|
|
mTargetWaylandDragContext = nullptr;
|
|
|
|
#endif
|
2012-04-19 10:18:31 +04:00
|
|
|
|
|
|
|
// If we got another drag signal while running the sheduled task, that
|
|
|
|
// must have happened while running a nested event loop. Leave the task
|
|
|
|
// source on the event loop.
|
|
|
|
if (mScheduledTask != eDragTaskNone) return TRUE;
|
|
|
|
|
|
|
|
// We have no task scheduled.
|
|
|
|
// Returning false removes the task source from the event loop.
|
|
|
|
mTaskSource = 0;
|
|
|
|
return FALSE;
|
|
|
|
}
|
2012-04-19 10:18:31 +04:00
|
|
|
|
2012-04-19 10:18:31 +04:00
|
|
|
// This will update the drag action based on the information in the
|
|
|
|
// drag context. Gtk gets this from a combination of the key settings
|
|
|
|
// and what the source is offering.
|
|
|
|
|
|
|
|
void nsDragService::UpdateDragAction() {
|
|
|
|
// This doesn't look right. dragSession.dragAction is used by
|
|
|
|
// nsContentUtils::SetDataTransferInEvent() to set the initial
|
|
|
|
// dataTransfer.dropEffect, so GdkDragContext::suggested_action would be
|
|
|
|
// more appropriate. GdkDragContext::actions should be used to set
|
|
|
|
// dataTransfer.effectAllowed, which doesn't currently happen with
|
|
|
|
// external sources.
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-04-19 10:18:31 +04:00
|
|
|
// default is to do nothing
|
|
|
|
int action = nsIDragService::DRAGDROP_ACTION_NONE;
|
2018-04-05 17:16:43 +03:00
|
|
|
GdkDragAction gdkAction = GDK_ACTION_DEFAULT;
|
|
|
|
if (mTargetDragContext) {
|
|
|
|
gdkAction = gdk_drag_context_get_actions(mTargetDragContext);
|
|
|
|
}
|
|
|
|
#ifdef MOZ_WAYLAND
|
2018-05-24 12:51:17 +03:00
|
|
|
else if (mTargetWaylandDragContext) {
|
2020-01-31 14:37:34 +03:00
|
|
|
gdkAction = mTargetWaylandDragContext->GetAvailableDragActions();
|
2018-04-05 17:16:43 +03:00
|
|
|
}
|
|
|
|
#endif
|
2012-04-19 10:18:31 +04:00
|
|
|
|
|
|
|
// set the default just in case nothing matches below
|
|
|
|
if (gdkAction & GDK_ACTION_DEFAULT)
|
|
|
|
action = nsIDragService::DRAGDROP_ACTION_MOVE;
|
|
|
|
|
|
|
|
// first check to see if move is set
|
|
|
|
if (gdkAction & GDK_ACTION_MOVE)
|
|
|
|
action = nsIDragService::DRAGDROP_ACTION_MOVE;
|
|
|
|
|
|
|
|
// then fall to the others
|
|
|
|
else if (gdkAction & GDK_ACTION_LINK)
|
|
|
|
action = nsIDragService::DRAGDROP_ACTION_LINK;
|
|
|
|
|
|
|
|
// copy is ctrl
|
|
|
|
else if (gdkAction & GDK_ACTION_COPY)
|
|
|
|
action = nsIDragService::DRAGDROP_ACTION_COPY;
|
|
|
|
|
|
|
|
// update the drag information
|
|
|
|
SetDragAction(action);
|
|
|
|
}
|
|
|
|
|
2015-04-08 21:48:11 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDragService::UpdateDragEffect() {
|
|
|
|
if (mTargetDragContextForRemote) {
|
|
|
|
ReplyToDragMotion(mTargetDragContextForRemote);
|
|
|
|
mTargetDragContextForRemote = nullptr;
|
|
|
|
}
|
2018-04-05 17:16:43 +03:00
|
|
|
#ifdef MOZ_WAYLAND
|
|
|
|
else if (mTargetWaylandDragContextForRemote) {
|
|
|
|
ReplyToDragMotion(mTargetWaylandDragContextForRemote);
|
|
|
|
mTargetWaylandDragContextForRemote = nullptr;
|
|
|
|
}
|
|
|
|
#endif
|
2015-04-08 21:48:11 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-04-19 10:18:31 +04:00
|
|
|
void nsDragService::DispatchMotionEvents() {
|
|
|
|
mCanDrop = false;
|
|
|
|
|
2017-02-17 06:29:42 +03:00
|
|
|
FireDragEventAtSource(eDrag, GetCurrentModifiers());
|
2012-04-19 10:18:31 +04:00
|
|
|
|
2015-09-02 09:08:02 +03:00
|
|
|
mTargetWindow->DispatchDragEvent(eDragOver, mTargetWindowPoint, mTargetTime);
|
2012-04-19 10:18:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Returns true if the drop was successful
|
|
|
|
gboolean nsDragService::DispatchDropEvent() {
|
|
|
|
// We need to check IsDestroyed here because the nsRefPtr
|
|
|
|
// only protects this from being deleted, it does NOT protect
|
|
|
|
// against nsView::~nsView() calling Destroy() on it, bug 378273.
|
|
|
|
if (mTargetWindow->IsDestroyed()) return FALSE;
|
|
|
|
|
2015-09-02 09:08:02 +03:00
|
|
|
EventMessage msg = mCanDrop ? eDrop : eDragExit;
|
2012-04-19 10:18:31 +04:00
|
|
|
|
|
|
|
mTargetWindow->DispatchDragEvent(msg, mTargetWindowPoint, mTargetTime);
|
|
|
|
|
|
|
|
return mCanDrop;
|
|
|
|
}
|
2017-02-17 06:29:42 +03:00
|
|
|
|
2019-02-26 01:13:48 +03:00
|
|
|
/* static */
|
|
|
|
uint32_t nsDragService::GetCurrentModifiers() {
|
2017-02-17 06:29:42 +03:00
|
|
|
return mozilla::widget::KeymapWrapper::ComputeCurrentKeyModifiers();
|
|
|
|
}
|