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
|
|
|
|
|
|
|
#ifndef nsDragService_h__
|
|
|
|
#define nsDragService_h__
|
|
|
|
|
2016-04-19 23:51:25 +03:00
|
|
|
#include "mozilla/RefPtr.h"
|
2002-08-12 01:47:14 +04:00
|
|
|
#include "nsBaseDragService.h"
|
2003-10-30 04:48:41 +03:00
|
|
|
#include "nsIObserver.h"
|
2013-09-25 00:45:13 +04:00
|
|
|
#include "nsAutoRef.h"
|
2002-08-12 01:47:14 +04:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2012-04-19 10:18:31 +04:00
|
|
|
class nsWindow;
|
2018-04-05 17:16:43 +03:00
|
|
|
class nsWaylandDragContext;
|
2012-04-19 10:18:31 +04:00
|
|
|
|
2014-01-29 04:10:33 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace gfx {
|
|
|
|
class SourceSurface;
|
|
|
|
}
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2012-04-19 10:18:31 +04:00
|
|
|
#ifndef HAVE_NSGOBJECTREFTRAITS
|
|
|
|
# define HAVE_NSGOBJECTREFTRAITS
|
|
|
|
template <class T>
|
|
|
|
class nsGObjectRefTraits : public nsPointerRefTraits<T> {
|
|
|
|
public:
|
|
|
|
static void Release(T *aPtr) { g_object_unref(aPtr); }
|
|
|
|
static void AddRef(T *aPtr) { g_object_ref(aPtr); }
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef HAVE_NSAUTOREFTRAITS_GTKWIDGET
|
|
|
|
# define HAVE_NSAUTOREFTRAITS_GTKWIDGET
|
|
|
|
template <>
|
|
|
|
class nsAutoRefTraits<GtkWidget> : public nsGObjectRefTraits<GtkWidget> {};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef HAVE_NSAUTOREFTRAITS_GDKDRAGCONTEXT
|
|
|
|
# define HAVE_NSAUTOREFTRAITS_GDKDRAGCONTEXT
|
|
|
|
template <>
|
|
|
|
class nsAutoRefTraits<GdkDragContext>
|
|
|
|
: public nsGObjectRefTraits<GdkDragContext> {};
|
|
|
|
#endif
|
2002-08-12 01:47:14 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Native GTK DragService wrapper
|
|
|
|
*/
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class nsDragService final : public nsBaseDragService, public nsIObserver {
|
2002-08-12 01:47:14 +04:00
|
|
|
public:
|
|
|
|
nsDragService();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2002-08-12 01:47:14 +04:00
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2003-10-30 04:48:41 +03:00
|
|
|
NS_DECL_NSIOBSERVER
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-10-21 12:16:40 +03:00
|
|
|
// nsBaseDragService
|
2016-10-18 21:56:20 +03:00
|
|
|
virtual nsresult InvokeDragSessionImpl(
|
|
|
|
nsIArray *anArrayTransferables,
|
2018-08-07 16:32:08 +03:00
|
|
|
const mozilla::Maybe<mozilla::CSSIntRegion> &aRegion,
|
2015-10-21 12:16:40 +03:00
|
|
|
uint32_t aActionType) override;
|
2002-08-12 01:47:14 +04:00
|
|
|
// nsIDragService
|
2019-01-04 06:16:46 +03:00
|
|
|
NS_IMETHOD InvokeDragSession(nsINode *aDOMNode, nsIPrincipal *aPrincipal,
|
2016-10-18 21:56:20 +03:00
|
|
|
nsIArray *anArrayTransferables,
|
2015-08-10 22:56:47 +03:00
|
|
|
uint32_t aActionType,
|
|
|
|
nsContentPolicyType aContentPolicyType) override;
|
2015-03-21 19:28:04 +03:00
|
|
|
NS_IMETHOD StartDragSession() override;
|
2017-02-17 06:29:42 +03:00
|
|
|
NS_IMETHOD EndDragSession(bool aDoneDrag, uint32_t aKeyModifiers) override;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2002-08-12 01:47:14 +04:00
|
|
|
// nsIDragSession
|
2015-03-21 19:28:04 +03:00
|
|
|
NS_IMETHOD SetCanDrop(bool aCanDrop) override;
|
|
|
|
NS_IMETHOD GetCanDrop(bool *aCanDrop) override;
|
|
|
|
NS_IMETHOD GetNumDropItems(uint32_t *aNumItems) override;
|
2002-08-12 01:47:14 +04:00
|
|
|
NS_IMETHOD GetData(nsITransferable *aTransferable,
|
2015-03-21 19:28:04 +03:00
|
|
|
uint32_t aItemIndex) override;
|
2015-01-21 00:39:44 +03:00
|
|
|
NS_IMETHOD IsDataFlavorSupported(const char *aDataFlavor,
|
2015-03-21 19:28:04 +03:00
|
|
|
bool *_retval) override;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-04-08 21:48:11 +03:00
|
|
|
NS_IMETHOD UpdateDragEffect() override;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-04-19 10:18:31 +04:00
|
|
|
// Methods called from nsWindow to handle responding to GTK drag
|
|
|
|
// destination signals
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-03-17 02:20:18 +03:00
|
|
|
static already_AddRefed<nsDragService> GetInstance();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-04-19 10:18:31 +04:00
|
|
|
void TargetDataReceived(GtkWidget *aWidget, GdkDragContext *aContext, gint aX,
|
2002-08-12 01:47:14 +04:00
|
|
|
gint aY, GtkSelectionData *aSelection_data,
|
|
|
|
guint aInfo, guint32 aTime);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-04-19 10:18:31 +04:00
|
|
|
gboolean ScheduleMotionEvent(nsWindow *aWindow, GdkDragContext *aDragContext,
|
2018-04-05 17:16:43 +03:00
|
|
|
nsWaylandDragContext *aPendingWaylandDragContext,
|
2015-10-26 23:33:13 +03:00
|
|
|
mozilla::LayoutDeviceIntPoint aWindowPoint,
|
2012-04-19 10:18:31 +04:00
|
|
|
guint aTime);
|
|
|
|
void ScheduleLeaveEvent();
|
|
|
|
gboolean ScheduleDropEvent(nsWindow *aWindow, GdkDragContext *aDragContext,
|
2018-04-05 17:16:43 +03:00
|
|
|
nsWaylandDragContext *aPendingWaylandDragContext,
|
2015-10-26 23:33:13 +03:00
|
|
|
mozilla::LayoutDeviceIntPoint aWindowPoint,
|
2012-04-19 10:18:31 +04:00
|
|
|
guint aTime);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-04-19 10:18:31 +04:00
|
|
|
nsWindow *GetMostRecentDestWindow() {
|
|
|
|
return mScheduledTask == eDragTaskNone ? mTargetWindow : mPendingWindow;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2009-06-20 05:38:27 +04:00
|
|
|
// END PUBLIC API
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2009-06-20 05:38:27 +04:00
|
|
|
// These methods are public only so that they can be called from functions
|
|
|
|
// with C calling conventions. They are called for drags started with the
|
|
|
|
// invisible widget.
|
|
|
|
void SourceEndDragSession(GdkDragContext *aContext, gint aResult);
|
2002-08-12 01:47:14 +04:00
|
|
|
void SourceDataGet(GtkWidget *widget, GdkDragContext *context,
|
|
|
|
GtkSelectionData *selection_data, guint32 aTime);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-10-04 13:31:45 +03:00
|
|
|
void SourceBeginDrag(GdkDragContext *aContext);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2011-07-04 18:39:08 +04:00
|
|
|
// set the drag icon during drag-begin
|
|
|
|
void SetDragIcon(GdkDragContext *aContext);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-07-09 01:23:18 +04:00
|
|
|
protected:
|
|
|
|
virtual ~nsDragService();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2002-08-12 01:47:14 +04:00
|
|
|
private:
|
2012-04-19 10:18:31 +04:00
|
|
|
// mScheduledTask indicates what signal has been received from GTK and
|
|
|
|
// so what needs to be dispatched when the scheduled task is run. It is
|
|
|
|
// eDragTaskNone when there is no task scheduled (but the
|
|
|
|
// previous task may still not have finished running).
|
|
|
|
enum DragTask {
|
|
|
|
eDragTaskNone,
|
|
|
|
eDragTaskMotion,
|
|
|
|
eDragTaskLeave,
|
2012-04-19 10:18:31 +04:00
|
|
|
eDragTaskDrop,
|
|
|
|
eDragTaskSourceEnd
|
2012-04-19 10:18:31 +04:00
|
|
|
};
|
|
|
|
DragTask mScheduledTask;
|
|
|
|
// mTaskSource is the GSource id for the task that is either scheduled
|
|
|
|
// or currently running. It is 0 if no task is scheduled or running.
|
|
|
|
guint mTaskSource;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-04-19 10:18:31 +04:00
|
|
|
// target/destination side vars
|
|
|
|
// These variables keep track of the state of the current drag.
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-04-19 10:18:31 +04:00
|
|
|
// mPendingWindow, mPendingWindowPoint, mPendingDragContext, and
|
|
|
|
// mPendingTime, carry information from the GTK signal that will be used
|
|
|
|
// when the scheduled task is run. mPendingWindow and mPendingDragContext
|
2013-10-08 22:47:37 +04:00
|
|
|
// will be nullptr if the scheduled task is eDragTaskLeave.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsWindow> mPendingWindow;
|
2015-10-26 23:33:13 +03:00
|
|
|
mozilla::LayoutDeviceIntPoint mPendingWindowPoint;
|
2012-04-19 10:18:31 +04:00
|
|
|
nsCountedRef<GdkDragContext> mPendingDragContext;
|
2018-04-05 17:16:43 +03:00
|
|
|
#ifdef MOZ_WAYLAND
|
|
|
|
RefPtr<nsWaylandDragContext> mPendingWaylandDragContext;
|
|
|
|
#endif
|
2012-04-19 10:18:31 +04:00
|
|
|
guint mPendingTime;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-04-19 10:18:31 +04:00
|
|
|
// mTargetWindow and mTargetWindowPoint record the position of the last
|
|
|
|
// eDragTaskMotion or eDragTaskDrop task that was run or is still running.
|
|
|
|
// mTargetWindow is cleared once the drag has completed or left.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsWindow> mTargetWindow;
|
2015-10-26 23:33:13 +03:00
|
|
|
mozilla::LayoutDeviceIntPoint mTargetWindowPoint;
|
2012-04-19 10:18:31 +04:00
|
|
|
// mTargetWidget and mTargetDragContext are set only while dispatching
|
|
|
|
// motion or drop events. mTime records the corresponding timestamp.
|
|
|
|
nsCountedRef<GtkWidget> mTargetWidget;
|
|
|
|
nsCountedRef<GdkDragContext> mTargetDragContext;
|
2018-04-05 17:16:43 +03:00
|
|
|
#ifdef MOZ_WAYLAND
|
|
|
|
RefPtr<nsWaylandDragContext> mTargetWaylandDragContext;
|
|
|
|
#endif
|
2015-04-08 21:48:11 +03:00
|
|
|
// mTargetDragContextForRemote is set while waiting for a reply from
|
|
|
|
// a child process.
|
|
|
|
nsCountedRef<GdkDragContext> mTargetDragContextForRemote;
|
2018-04-05 17:16:43 +03:00
|
|
|
#ifdef MOZ_WAYLAND
|
|
|
|
RefPtr<nsWaylandDragContext> mTargetWaylandDragContextForRemote;
|
|
|
|
#endif
|
2002-08-12 01:47:14 +04:00
|
|
|
guint mTargetTime;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2002-08-12 01:47:14 +04:00
|
|
|
// is it OK to drop on us?
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mCanDrop;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2002-08-12 01:47:14 +04:00
|
|
|
// have we received our drag data?
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mTargetDragDataReceived;
|
2002-08-12 01:47:14 +04:00
|
|
|
// last data received and its length
|
|
|
|
void *mTargetDragData;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mTargetDragDataLen;
|
2002-08-12 01:47:14 +04:00
|
|
|
// is the current target drag context contain a list?
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsTargetContextList(void);
|
2002-08-12 01:47:14 +04:00
|
|
|
// this will get the native data from the last target given a
|
|
|
|
// specific flavor
|
|
|
|
void GetTargetDragData(GdkAtom aFlavor);
|
|
|
|
// this will reset all of the target vars
|
|
|
|
void TargetResetData(void);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2002-08-12 01:47:14 +04:00
|
|
|
// source side vars
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2002-08-12 01:47:14 +04:00
|
|
|
// the source of our drags
|
|
|
|
GtkWidget *mHiddenWidget;
|
|
|
|
// our source data items
|
2016-10-18 21:56:20 +03:00
|
|
|
nsCOMPtr<nsIArray> mSourceDataItems;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2002-08-12 01:47:14 +04:00
|
|
|
// get a list of the sources in gtk's format
|
|
|
|
GtkTargetList *GetSourceList(void);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2008-06-18 13:20:29 +04:00
|
|
|
// attempts to create a semi-transparent drag image. Returns TRUE if
|
|
|
|
// successful, FALSE if not
|
2014-01-29 04:10:33 +04:00
|
|
|
bool SetAlphaPixmap(SourceSurface *aPixbuf, GdkDragContext *aContext,
|
|
|
|
int32_t aXOffset, int32_t aYOffset,
|
2016-10-19 22:01:39 +03:00
|
|
|
const mozilla::LayoutDeviceIntRect &dragRect);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-04-19 10:18:31 +04:00
|
|
|
gboolean Schedule(DragTask aTask, nsWindow *aWindow,
|
|
|
|
GdkDragContext *aDragContext,
|
2018-04-05 17:16:43 +03:00
|
|
|
nsWaylandDragContext *aPendingWaylandDragContext,
|
2015-10-26 23:33:13 +03:00
|
|
|
mozilla::LayoutDeviceIntPoint aWindowPoint, guint aTime);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-04-19 10:18:31 +04:00
|
|
|
// Callback for g_idle_add_full() to run mScheduledTask.
|
|
|
|
static gboolean TaskDispatchCallback(gpointer data);
|
|
|
|
gboolean RunScheduledTask();
|
2012-04-19 10:18:31 +04:00
|
|
|
void UpdateDragAction();
|
2012-04-19 10:18:31 +04:00
|
|
|
void DispatchMotionEvents();
|
2015-04-08 21:48:11 +03:00
|
|
|
void ReplyToDragMotion(GdkDragContext *aDragContext);
|
2018-04-05 17:16:43 +03:00
|
|
|
#ifdef MOZ_WAYLAND
|
|
|
|
void ReplyToDragMotion(nsWaylandDragContext *aDragContext);
|
|
|
|
#endif
|
2012-04-19 10:18:31 +04:00
|
|
|
gboolean DispatchDropEvent();
|
2017-02-17 06:29:42 +03:00
|
|
|
static uint32_t GetCurrentModifiers();
|
2002-08-12 01:47:14 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // nsDragService_h__
|