2015-05-03 22:32:37 +03: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 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"
|
2018-03-20 07:16:06 +03:00
|
|
|
#include "mozilla/dom/MouseEventBinding.h"
|
2014-02-27 14:51:13 +04:00
|
|
|
#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,
|
2015-08-29 02:58:26 +03:00
|
|
|
aEvent ? aEvent : new WidgetDragEvent(false, eVoidEvent, 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;
|
2016-03-28 07:29:42 +03:00
|
|
|
mEvent->mTime = PR_Now();
|
2016-04-18 17:09:02 +03:00
|
|
|
mEvent->mRefPoint = LayoutDeviceIntPoint(0, 0);
|
2019-04-21 21:19:43 +03:00
|
|
|
mEvent->AsMouseEvent()->mInputSource =
|
2018-06-26 00:20:54 +03:00
|
|
|
MouseEvent_Binding::MOZ_SOURCE_UNKNOWN;
|
2008-08-27 16:07:27 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-27 14:51:13 +04:00
|
|
|
void DragEvent::InitDragEvent(const nsAString& aType, bool aCanBubble,
|
2017-11-07 01:52:14 +03:00
|
|
|
bool aCancelable, nsGlobalWindowInner* aView,
|
2014-02-27 14:51:13 +04: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 20:05:36 +03:00
|
|
|
DataTransfer* aDataTransfer) {
|
2016-10-30 22:30:06 +03:00
|
|
|
NS_ENSURE_TRUE_VOID(!mEvent->mFlags.mIsBeingDispatched);
|
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
MouseEvent::InitMouseEvent(aType, aCanBubble, aCancelable, aView, aDetail,
|
|
|
|
aScreenX, aScreenY, aClientX, aClientY, aCtrlKey,
|
|
|
|
aAltKey, aShiftKey, aMetaKey, aButton,
|
|
|
|
aRelatedTarget);
|
2016-08-22 15:13:57 +03:00
|
|
|
if (mEventIsInternal) {
|
2016-03-31 11:26:32 +03:00
|
|
|
mEvent->AsDragEvent()->mDataTransfer = aDataTransfer;
|
2014-02-27 07:23:31 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-27 14:51:13 +04:00
|
|
|
DataTransfer* 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:50 +04:00
|
|
|
if (!mEvent || mEvent->mClass != eDragEventClass) {
|
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
|
|
|
}
|
|
|
|
|
2016-03-31 11:26:32 +03:00
|
|
|
return dragEvent->mDataTransfer;
|
2008-08-27 16:07:27 +04:00
|
|
|
}
|
|
|
|
|
2015-03-04 17:52:03 +03:00
|
|
|
// static
|
2019-09-11 17:35:28 +03:00
|
|
|
already_AddRefed<DragEvent> DragEvent::Constructor(
|
|
|
|
const GlobalObject& aGlobal, const nsAString& aType,
|
|
|
|
const DragEventInit& aParam) {
|
2015-03-04 17:52:03 +03:00
|
|
|
nsCOMPtr<EventTarget> t = do_QueryInterface(aGlobal.GetAsSupports());
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DragEvent> e = new DragEvent(t, nullptr, nullptr);
|
2015-03-04 17:52:03 +03:00
|
|
|
bool trusted = e->Init(t);
|
2016-01-30 20:05:36 +03: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 23:26:02 +03:00
|
|
|
e->InitializeExtraMouseEventDictionaryMembers(aParam);
|
2015-03-04 17:52:03 +03:00
|
|
|
e->SetTrusted(trusted);
|
2016-08-31 06:16:11 +03:00
|
|
|
e->SetComposed(aParam.mComposed);
|
2015-03-04 17:52:03 +03:00
|
|
|
return e.forget();
|
|
|
|
}
|
|
|
|
|
2014-02-27 14:51:13 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
2015-08-12 14:39:31 +03:00
|
|
|
already_AddRefed<DragEvent> NS_NewDOMDragEvent(EventTarget* aOwner,
|
2014-02-27 14:51:13 +04:00
|
|
|
nsPresContext* aPresContext,
|
2017-07-06 15:00:35 +03:00
|
|
|
WidgetDragEvent* aEvent) {
|
2015-08-12 14:39:31 +03:00
|
|
|
RefPtr<DragEvent> event = new DragEvent(aOwner, aPresContext, aEvent);
|
|
|
|
return event.forget();
|
2008-08-27 16:07:27 +04:00
|
|
|
}
|