2008-08-27 05:07:27 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07: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/. */
|
2008-08-27 05:07:27 -07:00
|
|
|
|
|
|
|
#include "nsDOMDragEvent.h"
|
|
|
|
#include "nsContentUtils.h"
|
2013-08-29 14:18:25 -07:00
|
|
|
#include "nsIDOMDataTransfer.h"
|
|
|
|
#include "prtime.h"
|
2013-09-25 04:21:18 -07:00
|
|
|
#include "mozilla/MouseEvents.h"
|
2008-08-27 05:07:27 -07:00
|
|
|
|
2013-10-01 00:23:02 -07:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2013-03-09 03:34:29 -08:00
|
|
|
nsDOMDragEvent::nsDOMDragEvent(mozilla::dom::EventTarget* aOwner,
|
|
|
|
nsPresContext* aPresContext,
|
2013-10-01 00:23:02 -07:00
|
|
|
WidgetInputEvent* aEvent)
|
2013-03-09 03:34:29 -08:00
|
|
|
: nsDOMMouseEvent(aOwner, aPresContext, aEvent ? aEvent :
|
2012-07-30 07:20:58 -07:00
|
|
|
new nsDragEvent(false, 0, nullptr))
|
2008-08-27 05:07:27 -07:00
|
|
|
{
|
|
|
|
if (aEvent) {
|
2011-10-17 07:59:28 -07:00
|
|
|
mEventIsInternal = false;
|
2008-08-27 05:07:27 -07:00
|
|
|
}
|
|
|
|
else {
|
2011-10-17 07:59:28 -07:00
|
|
|
mEventIsInternal = true;
|
2008-08-27 05:07:27 -07:00
|
|
|
mEvent->time = PR_Now();
|
|
|
|
mEvent->refPoint.x = mEvent->refPoint.y = 0;
|
2011-08-26 00:43:56 -07:00
|
|
|
static_cast<nsMouseEvent*>(mEvent)->inputSource = nsIDOMMouseEvent::MOZ_SOURCE_UNKNOWN;
|
2008-08-27 05:07:27 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDOMDragEvent::~nsDOMDragEvent()
|
|
|
|
{
|
|
|
|
if (mEventIsInternal) {
|
|
|
|
if (mEvent->eventStructType == NS_DRAG_EVENT)
|
|
|
|
delete static_cast<nsDragEvent*>(mEvent);
|
2012-07-30 07:20:58 -07:00
|
|
|
mEvent = nullptr;
|
2008-08-27 05:07:27 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF_INHERITED(nsDOMDragEvent, nsDOMMouseEvent)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(nsDOMDragEvent, nsDOMMouseEvent)
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN(nsDOMDragEvent)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMDragEvent)
|
|
|
|
NS_INTERFACE_MAP_END_INHERITING(nsDOMMouseEvent)
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMDragEvent::InitDragEvent(const nsAString & aType,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aCanBubble, bool aCancelable,
|
2012-08-22 08:56:38 -07:00
|
|
|
nsIDOMWindow* aView, int32_t aDetail,
|
|
|
|
int32_t aScreenX, int32_t aScreenY,
|
|
|
|
int32_t aClientX, int32_t aClientY,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aCtrlKey, bool aAltKey, bool aShiftKey,
|
2012-08-22 08:56:38 -07:00
|
|
|
bool aMetaKey, uint16_t aButton,
|
2008-12-19 06:58:47 -08:00
|
|
|
nsIDOMEventTarget *aRelatedTarget,
|
2008-08-27 05:07:27 -07:00
|
|
|
nsIDOMDataTransfer* aDataTransfer)
|
|
|
|
{
|
2008-12-19 06:58:47 -08:00
|
|
|
nsresult rv = nsDOMMouseEvent::InitMouseEvent(aType, aCanBubble, aCancelable,
|
|
|
|
aView, aDetail, aScreenX, aScreenY, aClientX, aClientY,
|
|
|
|
aCtrlKey, aAltKey, aShiftKey, aMetaKey, aButton,
|
|
|
|
aRelatedTarget);
|
2008-08-27 05:07:27 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (mEventIsInternal && mEvent) {
|
|
|
|
nsDragEvent* dragEvent = static_cast<nsDragEvent*>(mEvent);
|
|
|
|
dragEvent->dataTransfer = aDataTransfer;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMDragEvent::GetDataTransfer(nsIDOMDataTransfer** aDataTransfer)
|
2013-04-18 16:13:35 -07:00
|
|
|
{
|
|
|
|
NS_IF_ADDREF(*aDataTransfer = GetDataTransfer());
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIDOMDataTransfer*
|
|
|
|
nsDOMDragEvent::GetDataTransfer()
|
2008-08-27 05:07:27 -07:00
|
|
|
{
|
|
|
|
// the dataTransfer field of the event caches the DataTransfer associated
|
|
|
|
// with the drag. It is initialized when an attempt is made to retrieve it
|
|
|
|
// rather that when the event is created to avoid duplicating the data when
|
|
|
|
// no listener ever uses it.
|
2009-06-24 10:12:33 -07:00
|
|
|
if (!mEvent || mEvent->eventStructType != NS_DRAG_EVENT) {
|
|
|
|
NS_WARNING("Tried to get dataTransfer from non-drag event!");
|
2013-04-18 16:13:35 -07:00
|
|
|
return nullptr;
|
2008-08-27 05:07:27 -07:00
|
|
|
}
|
|
|
|
|
2009-06-24 10:12:33 -07:00
|
|
|
nsDragEvent* dragEvent = static_cast<nsDragEvent*>(mEvent);
|
|
|
|
// for synthetic events, just use the supplied data transfer object even if null
|
|
|
|
if (!mEventIsInternal) {
|
|
|
|
nsresult rv = nsContentUtils::SetDataTransferInEvent(dragEvent);
|
2013-04-18 16:13:35 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, nullptr);
|
2008-08-27 05:07:27 -07:00
|
|
|
}
|
|
|
|
|
2013-04-18 16:13:35 -07:00
|
|
|
return dragEvent->dataTransfer;
|
2008-08-27 05:07:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult NS_NewDOMDragEvent(nsIDOMEvent** aInstancePtrResult,
|
2013-03-09 03:34:29 -08:00
|
|
|
mozilla::dom::EventTarget* aOwner,
|
2008-08-27 05:07:27 -07:00
|
|
|
nsPresContext* aPresContext,
|
|
|
|
nsDragEvent *aEvent)
|
|
|
|
{
|
2013-03-09 03:34:29 -08:00
|
|
|
nsDOMDragEvent* event = new nsDOMDragEvent(aOwner, aPresContext, aEvent);
|
2008-08-27 05:07:27 -07:00
|
|
|
return CallQueryInterface(event, aInstancePtrResult);
|
|
|
|
}
|