2008-08-27 16:07:27 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
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/. */
|
2008-08-27 16:07:27 +04:00
|
|
|
|
2014-02-27 14:51:13 +04:00
|
|
|
#include "mozilla/dom/DragEvent.h"
|
|
|
|
#include "mozilla/MouseEvents.h"
|
2008-08-27 16:07:27 +04:00
|
|
|
#include "nsContentUtils.h"
|
2013-08-30 01:18:25 +04:00
|
|
|
#include "prtime.h"
|
2008-08-27 16:07:27 +04:00
|
|
|
|
2014-02-27 14:51:13 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2013-10-01 11:23:02 +04:00
|
|
|
|
2014-02-27 14:51:13 +04:00
|
|
|
DragEvent::DragEvent(EventTarget* aOwner,
|
|
|
|
nsPresContext* aPresContext,
|
|
|
|
WidgetDragEvent* aEvent)
|
2014-02-27 14:51:15 +04:00
|
|
|
: MouseEvent(aOwner, aPresContext,
|
|
|
|
aEvent ? aEvent : new WidgetDragEvent(false, 0, nullptr))
|
2008-08-27 16:07:27 +04:00
|
|
|
{
|
|
|
|
if (aEvent) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mEventIsInternal = false;
|
2008-08-27 16:07:27 +04:00
|
|
|
}
|
|
|
|
else {
|
2011-10-17 18:59:28 +04:00
|
|
|
mEventIsInternal = true;
|
2008-08-27 16:07:27 +04:00
|
|
|
mEvent->time = PR_Now();
|
|
|
|
mEvent->refPoint.x = mEvent->refPoint.y = 0;
|
2013-10-22 12:55:20 +04:00
|
|
|
mEvent->AsMouseEvent()->inputSource = nsIDOMMouseEvent::MOZ_SOURCE_UNKNOWN;
|
2008-08-27 16:07:27 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-27 14:51:15 +04:00
|
|
|
NS_IMPL_ADDREF_INHERITED(DragEvent, MouseEvent)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(DragEvent, MouseEvent)
|
2008-08-27 16:07:27 +04:00
|
|
|
|
2014-02-27 14:51:13 +04:00
|
|
|
NS_INTERFACE_MAP_BEGIN(DragEvent)
|
2008-08-27 16:07:27 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMDragEvent)
|
2014-02-27 14:51:15 +04:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(MouseEvent)
|
2008-08-27 16:07:27 +04:00
|
|
|
|
2014-02-27 07:23:31 +04:00
|
|
|
void
|
2014-02-27 14:51:13 +04:00
|
|
|
DragEvent::InitDragEvent(const nsAString& aType,
|
|
|
|
bool aCanBubble,
|
|
|
|
bool aCancelable,
|
|
|
|
nsIDOMWindow* aView,
|
|
|
|
int32_t aDetail,
|
|
|
|
int32_t aScreenX,
|
|
|
|
int32_t aScreenY,
|
|
|
|
int32_t aClientX,
|
|
|
|
int32_t aClientY,
|
|
|
|
bool aCtrlKey,
|
|
|
|
bool aAltKey,
|
|
|
|
bool aShiftKey,
|
|
|
|
bool aMetaKey,
|
|
|
|
uint16_t aButton,
|
|
|
|
EventTarget* aRelatedTarget,
|
|
|
|
DataTransfer* aDataTransfer,
|
|
|
|
ErrorResult& aError)
|
2014-02-27 07:23:31 +04:00
|
|
|
{
|
|
|
|
aError =
|
2014-02-27 14:51:15 +04:00
|
|
|
MouseEvent::InitMouseEvent(aType, aCanBubble, aCancelable,
|
|
|
|
aView, aDetail, aScreenX, aScreenY,
|
|
|
|
aClientX, aClientY, aCtrlKey, aAltKey,
|
|
|
|
aShiftKey, aMetaKey, aButton, aRelatedTarget);
|
2014-02-27 07:23:31 +04:00
|
|
|
if (aError.Failed()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mEventIsInternal && mEvent) {
|
|
|
|
mEvent->AsDragEvent()->dataTransfer = aDataTransfer;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-27 16:07:27 +04:00
|
|
|
NS_IMETHODIMP
|
2014-02-27 14:51:13 +04:00
|
|
|
DragEvent::InitDragEvent(const nsAString& aType,
|
|
|
|
bool aCanBubble,
|
|
|
|
bool aCancelable,
|
|
|
|
nsIDOMWindow* aView,
|
|
|
|
int32_t aDetail,
|
|
|
|
int32_t aScreenX,
|
|
|
|
int32_t aScreenY,
|
|
|
|
int32_t aClientX,
|
|
|
|
int32_t aClientY,
|
|
|
|
bool aCtrlKey,
|
|
|
|
bool aAltKey,
|
|
|
|
bool aShiftKey,
|
|
|
|
bool aMetaKey,
|
|
|
|
uint16_t aButton,
|
|
|
|
nsIDOMEventTarget* aRelatedTarget,
|
|
|
|
nsIDOMDataTransfer* aDataTransfer)
|
2008-08-27 16:07:27 +04:00
|
|
|
{
|
2014-02-27 07:23:31 +04:00
|
|
|
nsCOMPtr<DataTransfer> dataTransfer = do_QueryInterface(aDataTransfer);
|
|
|
|
|
2014-02-27 14:51:15 +04:00
|
|
|
nsresult rv =
|
|
|
|
MouseEvent::InitMouseEvent(aType, aCanBubble, aCancelable, aView, aDetail,
|
|
|
|
aScreenX, aScreenY, aClientX, aClientY,
|
|
|
|
aCtrlKey, aAltKey, aShiftKey, aMetaKey, aButton,
|
|
|
|
aRelatedTarget);
|
2008-08-27 16:07:27 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (mEventIsInternal && mEvent) {
|
2014-02-27 07:23:31 +04:00
|
|
|
mEvent->AsDragEvent()->dataTransfer = dataTransfer;
|
2008-08-27 16:07:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-02-27 14:51:13 +04:00
|
|
|
DragEvent::GetDataTransfer(nsIDOMDataTransfer** aDataTransfer)
|
2013-04-19 03:13:35 +04:00
|
|
|
{
|
|
|
|
NS_IF_ADDREF(*aDataTransfer = GetDataTransfer());
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-02-27 07:23:31 +04:00
|
|
|
DataTransfer*
|
2014-02-27 14:51:13 +04:00
|
|
|
DragEvent::GetDataTransfer()
|
2008-08-27 16:07:27 +04: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.
|
2014-08-04 09:28:46 +04:00
|
|
|
if (!mEvent || mEvent->mClass != NS_DRAG_EVENT) {
|
2009-06-24 21:12:33 +04:00
|
|
|
NS_WARNING("Tried to get dataTransfer from non-drag event!");
|
2013-04-19 03:13:35 +04:00
|
|
|
return nullptr;
|
2008-08-27 16:07:27 +04:00
|
|
|
}
|
|
|
|
|
2013-10-18 10:10:26 +04:00
|
|
|
WidgetDragEvent* dragEvent = mEvent->AsDragEvent();
|
2009-06-24 21:12:33 +04:00
|
|
|
// for synthetic events, just use the supplied data transfer object even if null
|
|
|
|
if (!mEventIsInternal) {
|
|
|
|
nsresult rv = nsContentUtils::SetDataTransferInEvent(dragEvent);
|
2013-04-19 03:13:35 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, nullptr);
|
2008-08-27 16:07:27 +04:00
|
|
|
}
|
|
|
|
|
2013-04-19 03:13:35 +04:00
|
|
|
return dragEvent->dataTransfer;
|
2008-08-27 16:07:27 +04:00
|
|
|
}
|
|
|
|
|
2014-02-27 14:51:13 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
NS_NewDOMDragEvent(nsIDOMEvent** aInstancePtrResult,
|
|
|
|
EventTarget* aOwner,
|
|
|
|
nsPresContext* aPresContext,
|
|
|
|
WidgetDragEvent* aEvent)
|
2008-08-27 16:07:27 +04:00
|
|
|
{
|
2014-02-27 14:51:13 +04:00
|
|
|
DragEvent* event = new DragEvent(aOwner, aPresContext, aEvent);
|
2008-08-27 16:07:27 +04:00
|
|
|
return CallQueryInterface(event, aInstancePtrResult);
|
|
|
|
}
|