2015-05-03 19:32:37 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 11:12:37 +00: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 12:07:27 +00:00
|
|
|
|
2014-02-27 10:51:13 +00:00
|
|
|
#include "mozilla/dom/DragEvent.h"
|
2018-03-20 04:16:06 +00:00
|
|
|
#include "mozilla/dom/MouseEventBinding.h"
|
2014-02-27 10:51:13 +00:00
|
|
|
#include "mozilla/MouseEvents.h"
|
2008-08-27 12:07:27 +00:00
|
|
|
#include "nsContentUtils.h"
|
2013-08-29 21:18:25 +00:00
|
|
|
#include "prtime.h"
|
2008-08-27 12:07:27 +00:00
|
|
|
|
2014-02-27 10:51:13 +00:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2013-10-01 07:23:02 +00:00
|
|
|
|
2014-02-27 10:51:13 +00:00
|
|
|
DragEvent::DragEvent(EventTarget* aOwner, nsPresContext* aPresContext,
|
|
|
|
WidgetDragEvent* aEvent)
|
2014-02-27 10:51:15 +00:00
|
|
|
: MouseEvent(
|
|
|
|
aOwner, aPresContext,
|
2015-08-28 23:58:26 +00:00
|
|
|
aEvent ? aEvent : new WidgetDragEvent(false, eVoidEvent, nullptr)) {
|
2008-08-27 12:07:27 +00:00
|
|
|
if (aEvent) {
|
2011-10-17 14:59:28 +00:00
|
|
|
mEventIsInternal = false;
|
2008-08-27 12:07:27 +00:00
|
|
|
} else {
|
2011-10-17 14:59:28 +00:00
|
|
|
mEventIsInternal = true;
|
2016-03-28 04:29:42 +00:00
|
|
|
mEvent->mTime = PR_Now();
|
2016-04-18 14:09:02 +00:00
|
|
|
mEvent->mRefPoint = LayoutDeviceIntPoint(0, 0);
|
2019-04-21 18:19:43 +00:00
|
|
|
mEvent->AsMouseEvent()->mInputSource =
|
2018-06-25 21:20:54 +00:00
|
|
|
MouseEvent_Binding::MOZ_SOURCE_UNKNOWN;
|
2008-08-27 12:07:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-27 10:51:13 +00:00
|
|
|
void DragEvent::InitDragEvent(const nsAString& aType, bool aCanBubble,
|
2017-11-06 22:52:14 +00:00
|
|
|
bool aCancelable, nsGlobalWindowInner* aView,
|
2014-02-27 10:51:13 +00:00
|
|
|
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,
|
2016-01-30 17:05:36 +00:00
|
|
|
DataTransfer* aDataTransfer) {
|
2016-10-30 19:30:06 +00:00
|
|
|
NS_ENSURE_TRUE_VOID(!mEvent->mFlags.mIsBeingDispatched);
|
|
|
|
|
2016-01-30 17:05:36 +00:00
|
|
|
MouseEvent::InitMouseEvent(aType, aCanBubble, aCancelable, aView, aDetail,
|
|
|
|
aScreenX, aScreenY, aClientX, aClientY, aCtrlKey,
|
|
|
|
aAltKey, aShiftKey, aMetaKey, aButton,
|
|
|
|
aRelatedTarget);
|
2016-08-22 12:13:57 +00:00
|
|
|
if (mEventIsInternal) {
|
2016-03-31 08:26:32 +00:00
|
|
|
mEvent->AsDragEvent()->mDataTransfer = aDataTransfer;
|
2014-02-27 03:23:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-27 10:51:13 +00:00
|
|
|
DataTransfer* DragEvent::GetDataTransfer() {
|
2008-08-27 12:07:27 +00: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 05:28:50 +00:00
|
|
|
if (!mEvent || mEvent->mClass != eDragEventClass) {
|
2009-06-24 17:12:33 +00:00
|
|
|
NS_WARNING("Tried to get dataTransfer from non-drag event!");
|
2013-04-18 23:13:35 +00:00
|
|
|
return nullptr;
|
2008-08-27 12:07:27 +00:00
|
|
|
}
|
|
|
|
|
2013-10-18 06:10:26 +00:00
|
|
|
WidgetDragEvent* dragEvent = mEvent->AsDragEvent();
|
2009-06-24 17:12:33 +00:00
|
|
|
// for synthetic events, just use the supplied data transfer object even if
|
|
|
|
// null
|
|
|
|
if (!mEventIsInternal) {
|
|
|
|
nsresult rv = nsContentUtils::SetDataTransferInEvent(dragEvent);
|
2013-04-18 23:13:35 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, nullptr);
|
2008-08-27 12:07:27 +00:00
|
|
|
}
|
|
|
|
|
2016-03-31 08:26:32 +00:00
|
|
|
return dragEvent->mDataTransfer;
|
2008-08-27 12:07:27 +00:00
|
|
|
}
|
|
|
|
|
2015-03-04 14:52:03 +00:00
|
|
|
// static
|
|
|
|
already_AddRefed<DragEvent> DragEvent::Constructor(const GlobalObject& aGlobal,
|
|
|
|
const nsAString& aType,
|
|
|
|
const DragEventInit& aParam,
|
|
|
|
ErrorResult& aRv) {
|
|
|
|
nsCOMPtr<EventTarget> t = do_QueryInterface(aGlobal.GetAsSupports());
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<DragEvent> e = new DragEvent(t, nullptr, nullptr);
|
2015-03-04 14:52:03 +00:00
|
|
|
bool trusted = e->Init(t);
|
2016-01-30 17:05:36 +00:00
|
|
|
e->InitDragEvent(aType, aParam.mBubbles, aParam.mCancelable, aParam.mView,
|
|
|
|
aParam.mDetail, aParam.mScreenX, aParam.mScreenY,
|
|
|
|
aParam.mClientX, aParam.mClientY, aParam.mCtrlKey,
|
|
|
|
aParam.mAltKey, aParam.mShiftKey, aParam.mMetaKey,
|
|
|
|
aParam.mButton, aParam.mRelatedTarget, aParam.mDataTransfer);
|
2015-05-19 20:26:02 +00:00
|
|
|
e->InitializeExtraMouseEventDictionaryMembers(aParam);
|
2015-03-04 14:52:03 +00:00
|
|
|
e->SetTrusted(trusted);
|
2016-08-31 03:16:11 +00:00
|
|
|
e->SetComposed(aParam.mComposed);
|
2015-03-04 14:52:03 +00:00
|
|
|
return e.forget();
|
|
|
|
}
|
|
|
|
|
2014-02-27 10:51:13 +00:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
2015-08-12 11:39:31 +00:00
|
|
|
already_AddRefed<DragEvent> NS_NewDOMDragEvent(EventTarget* aOwner,
|
2014-02-27 10:51:13 +00:00
|
|
|
nsPresContext* aPresContext,
|
2017-07-06 12:00:35 +00:00
|
|
|
WidgetDragEvent* aEvent) {
|
2015-08-12 11:39:31 +00:00
|
|
|
RefPtr<DragEvent> event = new DragEvent(aOwner, aPresContext, aEvent);
|
|
|
|
return event.forget();
|
2008-08-27 12:07:27 +00:00
|
|
|
}
|