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 "nsIServiceManager.h"
|
|
|
|
#include "nsGUIEvent.h"
|
|
|
|
#include "nsContentUtils.h"
|
|
|
|
#include "nsDOMDataTransfer.h"
|
|
|
|
#include "nsIDragService.h"
|
2012-07-20 09:42:08 -07:00
|
|
|
#include "nsDOMClassInfoID.h"
|
2008-08-27 05:07:27 -07:00
|
|
|
|
|
|
|
nsDOMDragEvent::nsDOMDragEvent(nsPresContext* aPresContext,
|
|
|
|
nsInputEvent* aEvent)
|
|
|
|
: nsDOMMouseEvent(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)
|
|
|
|
|
2010-01-12 05:08:43 -08:00
|
|
|
DOMCI_DATA(DragEvent, nsDOMDragEvent)
|
|
|
|
|
2008-08-27 05:07:27 -07:00
|
|
|
NS_INTERFACE_MAP_BEGIN(nsDOMDragEvent)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMDragEvent)
|
2010-03-17 08:09:05 -07:00
|
|
|
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(DragEvent)
|
2008-08-27 05:07:27 -07:00
|
|
|
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)
|
|
|
|
{
|
|
|
|
// 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.
|
2012-07-30 07:20:58 -07:00
|
|
|
*aDataTransfer = nullptr;
|
2008-08-27 05:07:27 -07:00
|
|
|
|
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!");
|
2008-08-27 05:07:27 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2008-08-27 05:07:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IF_ADDREF(*aDataTransfer = dragEvent->dataTransfer);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult NS_NewDOMDragEvent(nsIDOMEvent** aInstancePtrResult,
|
|
|
|
nsPresContext* aPresContext,
|
|
|
|
nsDragEvent *aEvent)
|
|
|
|
{
|
|
|
|
nsDOMDragEvent* event = new nsDOMDragEvent(aPresContext, aEvent);
|
|
|
|
return CallQueryInterface(event, aInstancePtrResult);
|
|
|
|
}
|